From d3b6bf3bed9c502388777c001948da2554e2d0ae Mon Sep 17 00:00:00 2001
From: FHT <981964879@qq.com>
Date: Wed, 17 Mar 2021 17:04:40 +0800
Subject: [PATCH] =?UTF-8?q?version:=20update:2021.03.17=20fix:=E6=9B=B4?=
=?UTF-8?q?=E6=94=B9=E8=8E=B7=E5=8F=96=E6=8E=A5=E5=8F=A3=E7=9A=84=E8=A7=A6?=
=?UTF-8?q?=E5=8F=91=E6=9D=A1=E4=BB=B6=EF=BC=8C=E7=BD=91=E7=BB=9C=E8=AE=BF?=
=?UTF-8?q?=E9=97=AE=E5=A4=B1=E8=B4=A5=E6=97=B6=E4=BD=BF=E7=94=A8=E6=9C=AC?=
=?UTF-8?q?=E5=9C=B0=E7=9A=84=E6=95=B0=E6=8D=AE=20add:?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/build.gradle | 4 +-
app/src/main/AndroidManifest.xml | 3 +-
.../com/mjsheng/myappstore/MyApplication.java | 205 +++++++++++++-----
.../myappstore/activity/MainActivity.java | 1 +
.../myappstore/receiver/BootReceiver.java | 11 +-
.../myappstore/receiver/MyJPushReceiver.java | 2 +-
.../myappstore/server/GuardService.java | 2 +-
.../myappstore/server/StepService.java | 2 +-
.../mjsheng/myappstore/utils/ApkUtils.java | 4 +-
.../myappstore/utils/NetworkUtils.java | 29 +++
.../myappstore/utils/ServiceAliveUtils.java | 9 +-
.../mjsheng/myappstore/utils/SystemUtils.java | 24 ++
12 files changed, 220 insertions(+), 76 deletions(-)
create mode 100644 app/src/main/java/com/mjsheng/myappstore/utils/NetworkUtils.java
create mode 100644 app/src/main/java/com/mjsheng/myappstore/utils/SystemUtils.java
diff --git a/app/build.gradle b/app/build.gradle
index 530f33e..284ac92 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -41,8 +41,8 @@ android {
productFlavors {
official {
flavorDimensions "default"
- versionCode 1032
- versionName "2.0.3.2"// 正式jiaoguanyi.com 双数正式 单数测试
+ versionCode 1033
+ versionName "2.0.3.3"// 正式jiaoguanyi.com 双数正式 单数测试
/*********************************极光推送************************************/
manifestPlaceholders = [
JPUSH_PKGNAME: "com.jiaoguanyi.appstore",
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 75957a9..fe8a7fa 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -3,8 +3,6 @@
xmlns:tools="http://schemas.android.com/tools"
package="com.mjsheng.myappstore"
android:sharedUserId="android.uid.system">
-
-
@@ -42,6 +40,7 @@
+
diff --git a/app/src/main/java/com/mjsheng/myappstore/MyApplication.java b/app/src/main/java/com/mjsheng/myappstore/MyApplication.java
index cb000a6..cc999aa 100644
--- a/app/src/main/java/com/mjsheng/myappstore/MyApplication.java
+++ b/app/src/main/java/com/mjsheng/myappstore/MyApplication.java
@@ -2,18 +2,23 @@ package com.mjsheng.myappstore;
import android.app.Activity;
import android.content.BroadcastReceiver;
-import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Configuration;
import android.net.Uri;
+import android.net.wifi.WifiManager;
+import android.nfc.Tag;
+import android.os.BatteryManager;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.os.PowerManager;
+import android.os.Process;
import android.provider.Settings;
+
import androidx.multidex.MultiDexApplication;
+
import android.text.TextUtils;
import android.util.Log;
@@ -40,7 +45,6 @@ import com.mjsheng.myappstore.jpush.TagAliasOperatorHelper;
import com.mjsheng.myappstore.network.HTTPInterface;
import com.mjsheng.myappstore.network.Network;
import com.mjsheng.myappstore.network.api.newapi.GetLockState;
-import com.mjsheng.myappstore.receiver.BootReceiver;
import com.mjsheng.myappstore.receiver.NewAppReceiver;
import com.mjsheng.myappstore.server.GuardService;
import com.mjsheng.myappstore.server.InitJpushServer;
@@ -48,7 +52,9 @@ import com.mjsheng.myappstore.server.MyDownloadService;
import com.mjsheng.myappstore.server.StepService;
import com.mjsheng.myappstore.utils.Configure;
import com.mjsheng.myappstore.utils.MySQLData;
+import com.mjsheng.myappstore.utils.NetworkUtils;
import com.mjsheng.myappstore.utils.SPUtils;
+import com.mjsheng.myappstore.utils.SystemUtils;
import com.mjsheng.myappstore.utils.ToastUtil;
import com.mjsheng.myappstore.utils.Utils;
import com.mjsheng.myappstore.utils.update.ToastTool;
@@ -91,9 +97,8 @@ import uk.co.chrisjenx.calligraphy.CalligraphyConfig;
//public class MyApplication extends MultiDexApplication implements Thread.UncaughtExceptionHandler {
public class MyApplication extends MultiDexApplication {
-
+ private final String TAG = MyApplication.class.getSimpleName();
public static String userName = null;
- private static final String TAG = "--MyApplication--";
public static Context context;
public static boolean LOOP_STOPING = false; //停止 循环
public static MainActivity mainActivity;
@@ -125,7 +130,12 @@ public class MyApplication extends MultiDexApplication {
@Override
public void onCreate() {
super.onCreate();
+ if (SystemUtils.IsMainProcessName(this, Process.myPid())) {
+ init();
+ }
+ }
+ private void init() {
Configuration config = getResources().getConfiguration();
int smallestScreenWidthDp = config.smallestScreenWidthDp;
Log.e("mjsheng", "smallestScreenWidthDp=" + smallestScreenWidthDp);
@@ -175,6 +185,8 @@ public class MyApplication extends MultiDexApplication {
startService(new Intent(this, MyDownloadService.class));
}
registerTimeReceiver();
+ registerBatteryReceiver();
+ registerNetworkReceiver();
//忽略电池优化
// ignoreBatteryOptimization(this);
@@ -230,7 +242,6 @@ public class MyApplication extends MultiDexApplication {
}
-
/**
* 忽略电池优化
*/
@@ -266,7 +277,7 @@ public class MyApplication extends MultiDexApplication {
//监听时间和日期变化
public void registerTimeReceiver() {
- receiver = new receiver();
+ screenReceiver = new ScreenReceiver();
IntentFilter filter = new IntentFilter();
filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
filter.addAction(Intent.ACTION_USER_PRESENT);
@@ -275,10 +286,10 @@ public class MyApplication extends MultiDexApplication {
filter.addAction(Intent.ACTION_USER_UNLOCKED);
filter.addAction("android.intent.action.FACTORY_RESET");
filter.addAction("android.intent.action.MASTER_CLEAR");
- registerReceiver(receiver, filter);
+ registerReceiver(screenReceiver, filter);
}
- private receiver receiver;
+ private ScreenReceiver screenReceiver;
Long time1 = 0L;
Long time2 = 0L;
@@ -286,12 +297,12 @@ public class MyApplication extends MultiDexApplication {
Long time3 = 0L;
Long time4 = 0L;
- public class receiver extends BroadcastReceiver {
+ public class ScreenReceiver extends BroadcastReceiver {
@Override
public void onReceive(final Context context, Intent intent) {
String action = intent.getAction();
- Log.e("fht", "receiver action:" + action);
+ Log.e(TAG, "action:" + action);
if (action.equals(Intent.ACTION_SCREEN_ON)) {
long time = System.currentTimeMillis();
if (null != locationClient) {
@@ -299,52 +310,55 @@ public class MyApplication extends MultiDexApplication {
locationClient.startLocation();
}
getLockState("2", String.valueOf(time));
- } else if (action.equals(Intent.ACTION_USER_PRESENT)) {
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
- /*在8.0以上 除了开机广播其他广播基本上没有用
- *当静默安装升级时,app不会被唤醒,只有通过显示广播唤醒
- * */
- mHandler.postDelayed(new Runnable() {
- @Override
- public void run() {
- Intent intent1 = new Intent(BootReceiver.BOOT_COMPLETED);
- intent1.setComponent(new ComponentName("com.jiaoguanyi.store", "com.mjsheng.myappstore.receiver.BootReceiver"));
- // 携带数据
-// intent1.putExtra("test", "我是来测 A 应用的Android 8.0 系统静态广播的测试数据");
- // 启动发送广播
- sendBroadcast(intent1);
-
- time2 = System.currentTimeMillis();
- if ((time2 - time1) > 60 * 1000) {
- //可能会多次触发,1分钟之内不执行
- //application中启动服务,startcommand执行会两次
- startService(new Intent(context, InitJpushServer.class));
- startService(new Intent(context, StepService.class));
- startService(new Intent(context, GuardService.class));
- time1 = time2;
- }
- }
- }, 5000);
-
- }
- } else if (action.equals(Intent.ACTION_SCREEN_OFF)) {
- mHandler.postDelayed(new Runnable() {
- @Override
- public void run() {
- long time = System.currentTimeMillis();
- getLockState("1", String.valueOf(time));
- if (time3 - System.currentTimeMillis() >= 10000) {
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
- Intent intent1 = new Intent(BootReceiver.BOOT_COMPLETED);
- intent1.setComponent(new ComponentName("com.jiaoguanyi.store", "com.mjsheng.myappstore.receiver.BootReceiver"));
- sendBroadcast(intent1);
- deleteScreenshots();
- }
- }
- time3 = System.currentTimeMillis();
- }
- }, 10000);
- } else if (action.equals("android.intent.action.FACTORY_RESET")
+ }
+// else if (action.equals(Intent.ACTION_USER_PRESENT)) {
+//// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+//// /*在8.0以上 除了开机广播其他广播基本上没有用
+//// *当静默安装升级时,app不会被唤醒,只有通过显示广播唤醒
+//// * */
+//// mHandler.postDelayed(new Runnable() {
+//// @Override
+//// public void run() {
+//// Intent intent1 = new Intent(BootReceiver.BOOT_COMPLETED);
+//// intent1.setComponent(new ComponentName("com.jiaoguanyi.store", "com.mjsheng.myappstore.receiver.BootReceiver"));
+//// // 携带数据
+////// intent1.putExtra("test", "我是来测 A 应用的Android 8.0 系统静态广播的测试数据");
+//// // 启动发送广播
+//// sendBroadcast(intent1);
+////
+//// time2 = System.currentTimeMillis();
+//// if ((time2 - time1) > 60 * 1000) {
+//// //可能会多次触发,1分钟之内不执行
+//// //application中启动服务,startcommand执行会两次
+//// startService(new Intent(context, InitJpushServer.class));
+//// startService(new Intent(context, StepService.class));
+//// startService(new Intent(context, GuardService.class));
+//// time1 = time2;
+//// }
+//// }
+//// }, 5000);
+////
+//// }
+//// }
+//// else if (action.equals(Intent.ACTION_SCREEN_OFF)) {
+//// mHandler.postDelayed(new Runnable() {
+//// @Override
+//// public void run() {
+//// long time = System.currentTimeMillis();
+//// getLockState("1", String.valueOf(time));
+//// if (time3 - System.currentTimeMillis() >= 10000) {
+//// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+//// Intent intent1 = new Intent(BootReceiver.BOOT_COMPLETED);
+//// intent1.setComponent(new ComponentName("com.jiaoguanyi.store", "com.mjsheng.myappstore.receiver.BootReceiver"));
+//// sendBroadcast(intent1);
+//// deleteScreenshots();
+//// }
+//// }
+//// time3 = System.currentTimeMillis();
+//// }
+//// }, 10000);
+//// }
+ else if (action.equals("android.intent.action.FACTORY_RESET")
|| action.equals("android.intent.action.MASTER_CLEAR")
//MASTER_CLEAR 7.0可以监听
|| action.equals("android.intent.action.MASTER_CLEAR_NOTIFICATION")
@@ -358,6 +372,83 @@ public class MyApplication extends MultiDexApplication {
}
+ private void registerBatteryReceiver() {
+ if (null == batteryReceiver) {
+ batteryReceiver = new BatteryReceiver();
+ }
+ IntentFilter filter = new IntentFilter();
+ filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
+ filter.addAction(Intent.ACTION_BATTERY_CHANGED);
+ filter.addAction(Intent.ACTION_BATTERY_LOW);
+ filter.addAction(Intent.ACTION_BATTERY_OKAY);
+ filter.addAction(Intent.ACTION_POWER_CONNECTED);
+ filter.addAction(Intent.ACTION_POWER_DISCONNECTED);
+ registerReceiver(batteryReceiver, filter);
+ }
+
+ BatteryReceiver batteryReceiver;
+
+ private class BatteryReceiver extends BroadcastReceiver {
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ String action = intent.getAction();
+ if (Intent.ACTION_BATTERY_CHANGED.equals(action)) {
+ // 当前电量
+ int level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 0);
+ // 最大电量
+ int scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, 0);
+ int elec = (level * 100) / scale;
+ Log.e(TAG, "electricity:=" + elec + "%");
+ if (elec == 80 || elec == 50 || elec == 30) {
+ startService(new Intent(getBaseContext(), InitJpushServer.class));
+ }
+ } else if (Intent.ACTION_POWER_CONNECTED.equals(action)
+ || Intent.ACTION_POWER_DISCONNECTED.equals(action)
+ || Intent.ACTION_BATTERY_LOW.equals(action)
+ || Intent.ACTION_BATTERY_OKAY.equals(action)
+ ) {
+ Log.e(TAG, action);
+ startService(new Intent(getBaseContext(), InitJpushServer.class));
+ }
+
+ }
+ }
+
+ private void registerNetworkReceiver() {
+ if (null == netReceiver) {
+ netReceiver = new NetworkStateReceiver();
+ }
+ IntentFilter filter = new IntentFilter();
+ filter.addAction("android.net.ethernet.ETHERNET_STATE_CHANGED");
+ filter.addAction("android.net.ethernet.STATE_CHANGE");
+ filter.addAction("android.net.conn.CONNECTIVITY_CHANGE");
+ filter.addAction("android.net.wifi.WIFI_STATE_CHANGED");
+ filter.addAction("android.net.wifi.STATE_CHANGE");
+ filter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
+ registerReceiver(netReceiver, filter);
+ }
+
+ private NetworkStateReceiver netReceiver;
+
+
+ public class NetworkStateReceiver extends BroadcastReceiver {
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ if (intent == null || intent.getAction() == null) {
+ Log.e(TAG, "NetworkStateReceiver: 异常");
+ return;
+ }
+ if (NetworkUtils.isConnected(getBaseContext())) {
+ Log.e(TAG, "NetworkStateReceiver: 网络连接成功");
+ startService(new Intent(getBaseContext(), InitJpushServer.class));
+ } else {
+ Log.e(TAG, "NetworkStateReceiver: 网络连接失败");
+ }
+ }
+ }
+
private void deleteScreenshots() {
Log.e("File", "deleteScreenshots");
String path = getExternalFilesDir("db").getAbsolutePath();
@@ -535,7 +626,7 @@ public class MyApplication extends MultiDexApplication {
}
}
- synchronized public static void setJpushAlias() {
+ synchronized public static void setJpushAlias() {
Log.e("jiguangInterface", "10s后重新设置alias");
Observable.timer(10000, TimeUnit.MILLISECONDS)
.observeOn(rx.android.schedulers.AndroidSchedulers.mainThread())
diff --git a/app/src/main/java/com/mjsheng/myappstore/activity/MainActivity.java b/app/src/main/java/com/mjsheng/myappstore/activity/MainActivity.java
index 2fa24cf..475c3e5 100644
--- a/app/src/main/java/com/mjsheng/myappstore/activity/MainActivity.java
+++ b/app/src/main/java/com/mjsheng/myappstore/activity/MainActivity.java
@@ -870,6 +870,7 @@ public class MainActivity extends AppCompatActivity implements AMapLocationListe
public void onError(Call call, Response response, Exception e) {
super.onError(call, response, e);
Log.e("onError", "error:" + e.getMessage());
+ handler.sendEmptyMessage(-2);
}
});// 请求方式和请求url
diff --git a/app/src/main/java/com/mjsheng/myappstore/receiver/BootReceiver.java b/app/src/main/java/com/mjsheng/myappstore/receiver/BootReceiver.java
index 5c39ce0..86b828d 100644
--- a/app/src/main/java/com/mjsheng/myappstore/receiver/BootReceiver.java
+++ b/app/src/main/java/com/mjsheng/myappstore/receiver/BootReceiver.java
@@ -12,11 +12,12 @@ import com.mjsheng.myappstore.server.MyDownloadService;
import com.mjsheng.myappstore.server.StepService;
public class BootReceiver extends BroadcastReceiver {
+ private String TAG = BootReceiver.class.getSimpleName();
public static final String BOOT_COMPLETED = "com.jiaoguanyi.appstore.intent.action.BOOT_COMPLETED";
@Override
public void onReceive(Context context, Intent intent) {
- Log.e("BootReceiver", intent.getAction());
+ Log.e(TAG, "action:" + intent.getAction());
if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) {
HTTPInterface.updateDeviceInfo(context);
startService(context);
@@ -31,7 +32,7 @@ public class BootReceiver extends BroadcastReceiver {
|| intent.getAction().equals("android.intent.action.USER_PRESENT")
|| intent.getAction().equals("android.intent.action.SCREEN_ON")
|| intent.getAction().equals("android.intent.action.SCREEN_OFF")
- //测试
+ //测试
// || intent.getAction().equals("android.hardware.usb.action.USB_ACCESSORY_ATTACHED")
// || intent.getAction().equals("android.hardware.usb.action.USB_ACCESSORY_DETACHED")
// || intent.getAction().equals("android.hardware.usb.action.USB_DEVICE_ATTACHED")
@@ -46,15 +47,15 @@ public class BootReceiver extends BroadcastReceiver {
) {
//除了USER_PRESENT应该都收不到
- Log.e("fht", "BootReceiver MSG:" + intent.getAction());
- startService(context);
+// Log.e("fht", "BootReceiver MSG:" + intent.getAction());
+// startService(context);
}
}
private void startService(Context context) {
- Intent intent=new Intent(context, InitJpushServer.class);
+ Intent intent = new Intent(context, InitJpushServer.class);
// intent.putExtra("boot","BOOT_COMPLETED");
context.startService(intent);
context.startService(new Intent(context, StepService.class));
diff --git a/app/src/main/java/com/mjsheng/myappstore/receiver/MyJPushReceiver.java b/app/src/main/java/com/mjsheng/myappstore/receiver/MyJPushReceiver.java
index f8a330c..9af5b33 100644
--- a/app/src/main/java/com/mjsheng/myappstore/receiver/MyJPushReceiver.java
+++ b/app/src/main/java/com/mjsheng/myappstore/receiver/MyJPushReceiver.java
@@ -363,7 +363,7 @@ public class MyJPushReceiver extends BroadcastReceiver {
}
private void setLock_screen(int state, Context context, String name) {
- if (ServiceAliveUtils.isServiceAlice()) {
+ if (ServiceAliveUtils.isServiceAlice(context)) {
context.startService(new Intent(context, InitJpushServer.class));
}
Intent intent = new Intent();
diff --git a/app/src/main/java/com/mjsheng/myappstore/server/GuardService.java b/app/src/main/java/com/mjsheng/myappstore/server/GuardService.java
index 74517a2..7da0ede 100644
--- a/app/src/main/java/com/mjsheng/myappstore/server/GuardService.java
+++ b/app/src/main/java/com/mjsheng/myappstore/server/GuardService.java
@@ -64,7 +64,7 @@ public class GuardService extends Service {
@Override
public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
LogUtils.e(TAG, "GuardService:建立链接");
- boolean isServiceRunning = ServiceAliveUtils.isServiceAlice();
+ boolean isServiceRunning = ServiceAliveUtils.isServiceAlice(GuardService.this);
if (!isServiceRunning) {
Intent i = new Intent(GuardService.this, MyDownloadService.class);
startService(i);
diff --git a/app/src/main/java/com/mjsheng/myappstore/server/StepService.java b/app/src/main/java/com/mjsheng/myappstore/server/StepService.java
index d404f10..66b666d 100644
--- a/app/src/main/java/com/mjsheng/myappstore/server/StepService.java
+++ b/app/src/main/java/com/mjsheng/myappstore/server/StepService.java
@@ -50,7 +50,7 @@ public class StepService extends Service {
@Override
public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
LogUtils.e(TAG, "StepService:建立链接");
- boolean isServiceRunning = ServiceAliveUtils.isServiceAlice();
+ boolean isServiceRunning = ServiceAliveUtils.isServiceAlice(StepService.this);
if (!isServiceRunning) {
Intent i = new Intent(StepService.this, MyDownloadService.class);
startService(i);
diff --git a/app/src/main/java/com/mjsheng/myappstore/utils/ApkUtils.java b/app/src/main/java/com/mjsheng/myappstore/utils/ApkUtils.java
index 89bd5d8..4a7456b 100644
--- a/app/src/main/java/com/mjsheng/myappstore/utils/ApkUtils.java
+++ b/app/src/main/java/com/mjsheng/myappstore/utils/ApkUtils.java
@@ -670,12 +670,12 @@ public class ApkUtils {
//10.0上日历和电子邮件是可卸载的
//7.0是系统应用
if (show_canremove_systemapp.contains(packageInfo.packageName)) {
- Logger.e("showAllAPP2", "packageName:" + packageInfo.packageName);
+// Logger.e("showAllAPP2", "packageName:" + packageInfo.packageName);
pm.setApplicationEnabledSetting(packageInfo.packageName, PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, 0);
}
}
} else {
- Logger.e("showAllAPP", "packageName:" + packageInfo.packageName);
+// Logger.e("showAllAPP", "packageName:" + packageInfo.packageName);
pm.setApplicationEnabledSetting(packageInfo.packageName, PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, 0);
hideSystemSettingAPP(context, packageInfo.packageName);
}
diff --git a/app/src/main/java/com/mjsheng/myappstore/utils/NetworkUtils.java b/app/src/main/java/com/mjsheng/myappstore/utils/NetworkUtils.java
new file mode 100644
index 0000000..00b8ae0
--- /dev/null
+++ b/app/src/main/java/com/mjsheng/myappstore/utils/NetworkUtils.java
@@ -0,0 +1,29 @@
+package com.mjsheng.myappstore.utils;
+
+
+import android.content.Context;
+import android.net.ConnectivityManager;
+import android.net.NetworkCapabilities;
+import android.net.NetworkInfo;
+import android.os.Build;
+import android.util.Log;
+
+public class NetworkUtils {
+ public static boolean isConnected(Context context) {
+ ConnectivityManager mConnectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
+ if (Build.VERSION.SDK_INT >= 23) {
+ //获取网络属性
+ NetworkCapabilities networkCapabilities = mConnectivityManager.getNetworkCapabilities(mConnectivityManager.getActiveNetwork());
+ if (networkCapabilities != null) {
+ Log.e("Avalible", "NetworkCapalbilities:" + networkCapabilities.toString());
+ return networkCapabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED);
+ }
+ } else {
+ NetworkInfo mNetworkInfo = mConnectivityManager.getActiveNetworkInfo();
+ if (mNetworkInfo != null) {
+ return mNetworkInfo.isConnected();
+ }
+ }
+ return false;
+ }
+}
diff --git a/app/src/main/java/com/mjsheng/myappstore/utils/ServiceAliveUtils.java b/app/src/main/java/com/mjsheng/myappstore/utils/ServiceAliveUtils.java
index 8abb708..d25496b 100644
--- a/app/src/main/java/com/mjsheng/myappstore/utils/ServiceAliveUtils.java
+++ b/app/src/main/java/com/mjsheng/myappstore/utils/ServiceAliveUtils.java
@@ -7,20 +7,19 @@ import android.util.Log;
import com.mjsheng.myappstore.MyApplication;
public class ServiceAliveUtils {
-
- public static boolean isServiceAlice() {
+ public static boolean isServiceAlice(Context mContext) {
boolean isServiceRunning = false;
ActivityManager manager =
- (ActivityManager) MyApplication.getAppContext().getSystemService(Context.ACTIVITY_SERVICE);
+ (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
if (manager == null) {
return false;
}
for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
- if ("com.mjsheng.myappstore.server.InitJpushServer".equals(service.service.getClassName())) {
+ if (mContext.getClass().getName().equals(service.service.getClassName())) {
isServiceRunning = true;
}
}
- Log.e("ServiceAliveUtils", "isServiceAlice: " + isServiceRunning);
+ Log.e("ServiceAliveUtils", mContext.getClass().getName() + "isServiceAlice: " + isServiceRunning);
return isServiceRunning;
}
}
diff --git a/app/src/main/java/com/mjsheng/myappstore/utils/SystemUtils.java b/app/src/main/java/com/mjsheng/myappstore/utils/SystemUtils.java
new file mode 100644
index 0000000..457c293
--- /dev/null
+++ b/app/src/main/java/com/mjsheng/myappstore/utils/SystemUtils.java
@@ -0,0 +1,24 @@
+package com.mjsheng.myappstore.utils;
+
+import android.app.ActivityManager;
+import android.content.Context;
+
+import java.util.List;
+
+public class SystemUtils {
+
+ public static boolean IsMainProcessName(Context cxt, int pid) {
+ String packageName = cxt.getPackageName();
+ ActivityManager am = (ActivityManager) cxt.getSystemService(Context.ACTIVITY_SERVICE);
+ List runningApps = am.getRunningAppProcesses();
+ if (runningApps == null) {
+ return false;
+ }
+ for (ActivityManager.RunningAppProcessInfo procInfo : runningApps) {
+ if (procInfo.pid == pid) {
+ return procInfo.processName.equals(packageName);
+ }
+ }
+ return false;
+ }
+}