From ee11b630680fefc547854c70d12de96091b42537 Mon Sep 17 00:00:00 2001
From: fanhuitong <981964879@qq.com>
Date: Thu, 3 Jun 2021 17:41:52 +0800
Subject: [PATCH] =?UTF-8?q?version:2.1.0=20update:=20fix:=E6=9B=B4?=
=?UTF-8?q?=E6=8D=A2=E5=BA=94=E7=94=A8=E4=B9=8B=E5=90=8E=E5=88=A0=E9=99=A4?=
=?UTF-8?q?=E5=8E=9F=E6=9D=A5=E7=9A=84=E5=BA=94=E7=94=A8=EF=BC=8C=E5=8A=A0?=
=?UTF-8?q?=E5=85=A5=E8=8E=B7=E5=8F=96=E5=93=A6log=E7=9A=84=E6=9C=8D?=
=?UTF-8?q?=E5=8A=A1=EF=BC=8C=E4=BF=AE=E5=A4=8D=E7=A6=81=E6=AD=A2=E5=8D=87?=
=?UTF-8?q?=E7=BA=A7=E7=9A=84=E5=BA=94=E7=94=A8=E4=B9=9F=E4=BC=9A=E8=A2=AB?=
=?UTF-8?q?=E5=8D=B8=E8=BD=BD=20add:?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/build.gradle | 16 +-
app/src/main/AndroidManifest.xml | 139 ++++------
.../myappstore/activity/HomeActivity.java | 57 +++-
.../myappstore/activity/MainPresenter.java | 3 +-
.../myappstore/base/BaseApplication.java | 3 +-
.../myappstore/bean/UploadAppInfo.java | 18 +-
.../myappstore/network/HTTPInterface.java | 11 +-
.../myappstore/receiver/BootReceiver.java | 3 +-
.../myappstore/receiver/MyJPushReceiver.java | 121 ++++-----
.../myappstore/receiver/NewAppReceiver.java | 18 +-
.../myappstore/server/DiscardServer.java | 2 +-
.../myappstore/server/GuardService.java | 118 ++------
.../myappstore/server/LogcatService.java | 251 ++++++++++++++++++
.../myappstore/server/StepService.java | 4 +-
.../mjsheng/myappstore/utils/ApkUtils.java | 99 ++++---
.../mjsheng/myappstore/utils/JGYUtils.java | 146 +++++++++-
.../myappstore/utils/ServiceAliveUtils.java | 18 +-
.../com/mjsheng/myappstore/utils/Utils.java | 30 +--
.../main/res/layout-land/activity_home.xml | 19 ++
.../main/res/layout-port/activity_home.xml | 22 +-
20 files changed, 732 insertions(+), 366 deletions(-)
create mode 100644 app/src/main/java/com/mjsheng/myappstore/server/LogcatService.java
diff --git a/app/build.gradle b/app/build.gradle
index 5418ffc..9f85a51 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -41,9 +41,9 @@ android {
//新平台正式
newly {
flavorDimensions "default"
- versionCode 509
+ versionCode 510
//versionCode 1037
- versionName "2.0.9"
+ versionName "2.1.0"
/*********************************极光推送************************************/
manifestPlaceholders = [
JPUSH_PKGNAME: "com.jiaoguanyi.appstore",
@@ -168,22 +168,22 @@ android {
buildTypes {
zhanRuiRelease.initWith(release)
zhanRuiRelease {
- buildConfigField "String", "platform", '"ZhanRui"'
- signingConfig signingConfigs.zhanRui
manifestPlaceholders = [
AMAP_KEY: "546eb5646a65ac6a5b7d1c7456466e05"
]
+ buildConfigField "String", "platform", '"ZhanRui"'
+ signingConfig signingConfigs.zhanRui
}
zhanRuiDebug.initWith(debug)
zhanRuiDebug {
+ manifestPlaceholders = [
+ AMAP_KEY: "546eb5646a65ac6a5b7d1c7456466e05"
+ ]
versionNameSuffix "-debug"
buildConfigField "String", "platform", '"ZhanRui"'
debuggable true
signingConfig signingConfigs.zhanRui
- manifestPlaceholders = [
- AMAP_KEY: "546eb5646a65ac6a5b7d1c7456466e05"
- ]
}
debug {
@@ -229,7 +229,7 @@ android {
variant.outputs.each { output ->
def outputFile = ""
if (outputFile != null) {
- def fileName = "${appName()}-${variant.versionCode}-V${variant.versionName}-${releaseTime()}-${productFlavors[0].name}-${buildType.name}.apk"
+ def fileName = "${appName()}-${variant.versionCode}-V${variant.versionName}-${releaseTime()}-${buildType.name}.apk"
output.outputFileName = fileName
}
}
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 9493d38..397a091 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -25,20 +25,17 @@
-
-
+
+
-
-
+
-
-
+ tools:ignore="ProtectedPermissions" />
-
+ android:maxSdkVersion="23" />
-
-
-
-
+
+
@@ -78,14 +72,12 @@
-
-
-
-
+
+
+
-
-
-
+
+
@@ -104,26 +99,27 @@
-
-
-
-
+
+
+
+
+
+
-
-
+ android:launchMode="singleTop" />
+
@@ -133,16 +129,13 @@
-
-
-
-
-
-
-
-
+
+
+
+
+
@@ -155,11 +148,11 @@
@@ -188,8 +181,7 @@
-
-
+
@@ -201,7 +193,7 @@
@@ -218,8 +210,7 @@
-
-
+
@@ -241,15 +232,13 @@
-
-
+
-
+ tools:replace="android:exported" />
-
-
+
-
-
+
-
+ tools:replace="android:authorities" />
-
-
+
-
+ tools:replace="android:authorities" />
-
-
+
-
+ android:exported="false" />
-
-
+
-
-
+
@@ -366,9 +346,8 @@
-
-
-
+
+
@@ -378,20 +357,18 @@
-
+ android:value="developer-default" />
-
+ android:value="${JPUSH_APPKEY}" />
-
+ android:value="${AMAP_KEY}" />
+
diff --git a/app/src/main/java/com/mjsheng/myappstore/activity/HomeActivity.java b/app/src/main/java/com/mjsheng/myappstore/activity/HomeActivity.java
index d0aba9b..ce28b66 100644
--- a/app/src/main/java/com/mjsheng/myappstore/activity/HomeActivity.java
+++ b/app/src/main/java/com/mjsheng/myappstore/activity/HomeActivity.java
@@ -2,10 +2,10 @@ package com.mjsheng.myappstore.activity;
import android.annotation.SuppressLint;
import android.app.StatusBarManager;
+import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
-import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.provider.Settings;
@@ -13,26 +13,55 @@ import android.util.Log;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
+import android.widget.Button;
import androidx.appcompat.app.AppCompatActivity;
import com.mjsheng.myappstore.BuildConfig;
import com.mjsheng.myappstore.R;
import com.lzy.okgo.model.HttpHeaders;
-import com.mjsheng.myappstore.utils.CacheUtils;
+import com.mjsheng.myappstore.server.LogcatService;
+import com.mjsheng.myappstore.utils.ServiceAliveUtils;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
public class HomeActivity extends AppCompatActivity {
private static String TAG = HomeActivity.class.getSimpleName();
+ private Button bt_log;
+ private Button bt_stop;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
+ if (BuildConfig.DEBUG) {
+ bt_log = findViewById(R.id.bt_log);
+ bt_log.setVisibility(View.VISIBLE);
+ bt_log.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ if (!ServiceAliveUtils.isServiceAlive(HomeActivity.this, LogcatService.class.getName())) {
+ startService(new Intent(HomeActivity.this, LogcatService.class));
+ }
+ Intent intent = new Intent(LogcatService.LOGCAT_START_ACTION);
+ sendBroadcast(intent);
+ }
+ });
+ bt_stop = findViewById(R.id.bt_stop);
+ bt_stop.setVisibility(View.VISIBLE);
+ bt_stop.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ if (!ServiceAliveUtils.isServiceAlive(HomeActivity.this, LogcatService.class.getName())) {
+ startService(new Intent(HomeActivity.this, LogcatService.class));
+ }
+ Intent intent = new Intent(LogcatService.LOGCAT_STOP_ACTION);
+ sendBroadcast(intent);
+ }
+ });
+ debugTest();
+// return;
+ }
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
@@ -40,27 +69,31 @@ public class HomeActivity extends AppCompatActivity {
finish();
}
}, 2000);
-
- if (BuildConfig.DEBUG) {
- DebugTest();
- }
}
- private void DebugTest() {
+ private void debugTest() {
// Utils.getHardware(this);
// setWebView();
// hideStatusBar();
Log.e(TAG, "DebugTest: " + HttpHeaders.getUserAgent());
// boolean qch_force_app = Settings.System.putString(getContentResolver(), "qch_launcher_icon_app", "");
- Log.e(TAG, "DebugTest: " + Settings.System.getString(getContentResolver(), "qch_launcher_icon_app"));
+ Log.e(TAG, "DebugTest: qch_launcher_icon_app:" + Settings.System.getString(getContentResolver(), "qch_launcher_icon_app"));
Log.e(TAG, "DebugTest: qch_hide_NavigationBar: " + Settings.System.getString(getContentResolver(), "qch_hide_NavigationBar"));
+ String only_jgy_shortcut_list = Settings.System.getString(getContentResolver(), "only_jgy_shortcut_list");
+ Log.e(TAG, "debugTest: only_jgy_shortcut_list:" + only_jgy_shortcut_list);
+ String qch_app_forbid = Settings.System.getString(getContentResolver(), "qch_app_forbid");
+ Log.e(TAG, "debugTest: qch_app_forbid:" + qch_app_forbid);
+
// try {
// new CacheUtils().cleanApplicationUserData(HomeActivity.this, "com.android.launcher3");
// } catch (Exception e) {
// e.printStackTrace();
// Log.e(TAG, "DebugTest: " + e.getMessage());
// }
- }
+// ActivityManager mAm = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
+// mAm.killBackgroundProcesses("com.android.documentsui");
+ }
+
@SuppressLint("NewApi")
private void hideStatusBar() {
diff --git a/app/src/main/java/com/mjsheng/myappstore/activity/MainPresenter.java b/app/src/main/java/com/mjsheng/myappstore/activity/MainPresenter.java
index 9d7ff0e..2a7b4a2 100644
--- a/app/src/main/java/com/mjsheng/myappstore/activity/MainPresenter.java
+++ b/app/src/main/java/com/mjsheng/myappstore/activity/MainPresenter.java
@@ -740,8 +740,7 @@ public class MainPresenter implements MainContact.Presenter {
// if (null != batchList && batchList.size() > 1) {
// Log.e("getDeviceBatch", "onNext: " + "deleteOtherApp");
// if (!BuildConfig.DEBUG) {
- //暂时屏蔽
-// JGYUtils.getInstance().deleteOtherApp(packageList);
+ JGYUtils.getInstance().deleteOtherApp();
// }
// } else {
// Log.e("getDeviceBatch", "批次为空");
diff --git a/app/src/main/java/com/mjsheng/myappstore/base/BaseApplication.java b/app/src/main/java/com/mjsheng/myappstore/base/BaseApplication.java
index 253f440..73bf575 100644
--- a/app/src/main/java/com/mjsheng/myappstore/base/BaseApplication.java
+++ b/app/src/main/java/com/mjsheng/myappstore/base/BaseApplication.java
@@ -27,6 +27,7 @@ import com.mjsheng.myappstore.network.HTTPInterface;
import com.mjsheng.myappstore.network.URLAddress;
import com.mjsheng.myappstore.statistics.AppInformation;
import com.mjsheng.myappstore.statistics.StatisticsInfo;
+import com.mjsheng.myappstore.utils.ApkUtils;
import com.mjsheng.myappstore.utils.JGYUtils;
import com.mjsheng.myappstore.utils.SystemUtils;
import com.mjsheng.myappstore.utils.ToastUtil;
@@ -421,7 +422,7 @@ public class BaseApplication extends MultiDexApplication {
list = statisticsInfo.getShowList();
if (list != null && list.size() > 0) {
for (AppInformation appInformation : list) {
- if (!Utils.isSystemApp(getAppContext(), appInformation.getPackageName())) {
+ if (!ApkUtils.isSystemApp(getAppContext(), appInformation.getPackageName())) {
localAppList.add(appInformation);
}
}
diff --git a/app/src/main/java/com/mjsheng/myappstore/bean/UploadAppInfo.java b/app/src/main/java/com/mjsheng/myappstore/bean/UploadAppInfo.java
index 396b6e2..82dfaf3 100644
--- a/app/src/main/java/com/mjsheng/myappstore/bean/UploadAppInfo.java
+++ b/app/src/main/java/com/mjsheng/myappstore/bean/UploadAppInfo.java
@@ -13,7 +13,7 @@ public class UploadAppInfo {
private String install_time;
private String versionCode;
private int state;
- private int id;
+// private int id;
String versionName;
public String getPackage_name() {
@@ -32,13 +32,13 @@ public class UploadAppInfo {
this.app_name = app_name;
}
- public int getId() {
- return id;
- }
-
- public void setId(int id) {
- this.id = id;
- }
+// public int getId() {
+// return id;
+// }
+//
+// public void setId(int id) {
+// this.id = id;
+// }
public String getInstall_time() {
return install_time;
@@ -78,7 +78,7 @@ public class UploadAppInfo {
"package_name='" + package_name + '\'' +
", app_name='" + app_name + '\'' +
", install_time=" + install_time +
- ", id=" + id +
+// ", id=" + id +
'}';
}
}
diff --git a/app/src/main/java/com/mjsheng/myappstore/network/HTTPInterface.java b/app/src/main/java/com/mjsheng/myappstore/network/HTTPInterface.java
index 931d868..cf8cc8d 100644
--- a/app/src/main/java/com/mjsheng/myappstore/network/HTTPInterface.java
+++ b/app/src/main/java/com/mjsheng/myappstore/network/HTTPInterface.java
@@ -1106,14 +1106,15 @@ public class HTTPInterface {
int code = jsonObject.get("code").getAsInt();
if (code == 200) {
String data = jsonObject.get("data").getAsJsonObject().get("result").getAsString();
- //开机图标
+ //开机图标 只记录后台传的包名
boolean write = Settings.System.putString(context.getContentResolver(), "only_jgy_shortcut_list", data);
Log.e(TAG, "onNext: only_jgy_shortcut_list: " + write);
JGYUtils.getInstance().writeAppPackageList(context, data);
} else {
- boolean write = Settings.System.putString(context.getContentResolver(), "only_jgy_shortcut_list", "");
- Settings.System.putString(context.getContentResolver(), "qch_app_forbid", " ");
- Log.e(TAG, "onNext: only_jgy_shortcut_list: " + write);
+ //为错误的时候不删除
+// boolean write = Settings.System.putString(context.getContentResolver(), "only_jgy_shortcut_list", "");
+// Settings.System.putString(context.getContentResolver(), "qch_app_forbid", " ");
+// Log.e(TAG, "onNext: only_jgy_shortcut_list: " + write);
Log.e("getAppLimit", "onNext: " + bodyString);
}
} catch (IOException e) {
@@ -1134,6 +1135,4 @@ public class HTTPInterface {
}
});
}
-
-
}
\ No newline at end of file
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 60bade7..3b028e8 100644
--- a/app/src/main/java/com/mjsheng/myappstore/receiver/BootReceiver.java
+++ b/app/src/main/java/com/mjsheng/myappstore/receiver/BootReceiver.java
@@ -7,8 +7,8 @@ import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
-import com.mjsheng.myappstore.network.HTTPInterface;
import com.mjsheng.myappstore.server.GuardService;
+import com.mjsheng.myappstore.server.LogcatService;
import com.mjsheng.myappstore.server.MainService;
import com.mjsheng.myappstore.server.StepService;
@@ -62,5 +62,6 @@ public class BootReceiver extends BroadcastReceiver {
context.startService(new Intent(context, MainService.class));
context.startService(new Intent(context, StepService.class));
context.startService(new Intent(context, GuardService.class));
+ context.startService(new Intent(context, LogcatService.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 5daf723..a75d8cb 100644
--- a/app/src/main/java/com/mjsheng/myappstore/receiver/MyJPushReceiver.java
+++ b/app/src/main/java/com/mjsheng/myappstore/receiver/MyJPushReceiver.java
@@ -1,7 +1,6 @@
package com.mjsheng.myappstore.receiver;
import android.annotation.SuppressLint;
-import android.app.ActivityManager;
import android.bluetooth.BluetoothAdapter;
import android.content.BroadcastReceiver;
import android.content.Context;
@@ -44,12 +43,10 @@ import com.mjsheng.myappstore.utils.MySQLData;
import com.mjsheng.myappstore.utils.SPUtils;
import com.mjsheng.myappstore.utils.SaveListUtils;
import com.mjsheng.myappstore.utils.ServiceAliveUtils;
-import com.mjsheng.myappstore.utils.SysSettingUtils;
import com.mjsheng.myappstore.utils.Utils;
import java.io.File;
import java.io.IOException;
-import java.lang.reflect.Method;
import cn.jpush.android.api.JPushInterface;
import io.reactivex.Observable;
@@ -197,7 +194,7 @@ public class MyJPushReceiver extends BroadcastReceiver {
SaveListUtils.sendForceAPP(mContext);
ApkUtils.UninstallAPP(mContext, title);
}
- getAppLimitApi();
+ HTTPInterface.getAppLimit(context);
HTTPInterface.getNetAndLaunchSetting(mContext);
break;
case MSG_SETTING:
@@ -224,7 +221,7 @@ public class MyJPushReceiver extends BroadcastReceiver {
break;
case MSG_INSTALL:
// mContext.sendBroadcast(new Intent("android.intent.action.MASTER_CLEAR"));
- getAppLimitApi();
+ HTTPInterface.getAppLimit(context);
doDownloadAndInstall(extras);
HTTPInterface.setHideDesktopIcon(mContext);
break;
@@ -288,7 +285,7 @@ public class MyJPushReceiver extends BroadcastReceiver {
setDisableSlideList(extras);
break;
case UPDATE_INFO:
- getAppLimitApi();
+ HTTPInterface.getAppLimit(context);
break;
case SN_SCREENSHOT:
screenshot(extras);
@@ -335,7 +332,7 @@ public class MyJPushReceiver extends BroadcastReceiver {
case KILL_SERVER:
JSONObject killJSONObject = JSON.parseObject(extras);
String packages = killJSONObject.getString("package_name");
- killBackgroundProcesses(context, packages);
+ JGYUtils.getInstance().killBackgroundProcesses(context, packages);
break;
case TIME_CONTROL:
getTimeControl(context, extras);
@@ -366,7 +363,7 @@ public class MyJPushReceiver extends BroadcastReceiver {
}
private void setLock_screen(int state, Context context, String name) {
- if (ServiceAliveUtils.isServiceAlice(context)) {
+ if (ServiceAliveUtils.isServiceAlive(context)) {
context.startService(new Intent(context, MainService.class));
}
Intent intent = new Intent();
@@ -379,31 +376,6 @@ public class MyJPushReceiver extends BroadcastReceiver {
context.sendBroadcast(intent);
}
- public void killBackgroundProcesses(Context context, String processName) {
- // mIsScanning = true;
- ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
- String packageName = null;
- try {
- if (processName.indexOf(":") == -1) {
- packageName = processName;
- } else {
- packageName = processName.split(":")[0];
- }
-
- activityManager.killBackgroundProcesses(packageName);
-
- //
- Method forceStopPackage = activityManager.getClass()
- .getDeclaredMethod("forceStopPackage", String.class);
- forceStopPackage.setAccessible(true);
- forceStopPackage.invoke(activityManager, packageName);
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- }
-
-
private BluetoothAdapter mBluetoothAdapter;
private void SettingSysData(String extras) {
@@ -675,13 +647,14 @@ public class MyJPushReceiver extends BroadcastReceiver {
e.printStackTrace();
}
if (packageInfo == null) {
- Log.e(TAG, "doDownloadAndInstall: "+ app_package + "未安装");
+ Log.e(TAG, "doDownloadAndInstall: " + app_package + "未安装");
if (!SaveListUtils.isDownLoading(app_url)) {
// Aria.download(this)
// .load(app_url)
// .setFilePath(PathUtils.getExternalDownloadsPath() + "/jgy/" + EncryptUtils.encryptMD5ToString(s) + ".apk", true)
// .setExtendField(packageObj.toJSONString())
// .create();
+ Log.e(TAG, "doDownloadAndInstall: " + app_package + "开始下载");
Utils.ariaDownload(mContext, app_url, packageObj);
}
} else {
@@ -701,50 +674,50 @@ public class MyJPushReceiver extends BroadcastReceiver {
Utils.ariaDownload(mContext, app_url, packageObj);
}
- }else {
- Log.e(TAG, "doDownloadAndInstall: "+ app_package + "已安装最新版");
+ } else {
+ Log.e(TAG, "doDownloadAndInstall: " + app_package + "已安装最新版");
}
}
}
- private void getAppLimitApi() {
- NetInterfaceManager.getAppLimitApi()
- .getAppLimitApi(NetInterfaceManager.HTTP_KEY, Utils.getSerial())
- .subscribeOn(Schedulers.io())
- .observeOn(AndroidSchedulers.mainThread())
- .subscribe(new Observer() {
- @Override
- public void onComplete() {
- }
-
- @Override
- public void onError(Throwable param1Throwable) {
- Log.e(TAG, "getAppLimitApi=onError:");
- }
-
- @Override
- public void onNext(ResponseBody param1ResponseBody) {
- try {
- String str2 = param1ResponseBody.string();
- Log.e(TAG, str2);
- JSONObject jSONObject = JSON.parseObject(str2);
- JSONObject data = jSONObject.getJSONObject("data");
- String result = "";
- if (data != null) {
- result = data.getString("result");
- }
- JGYUtils.getInstance().writeAppPackageList(mContext, result);
- } catch (IOException e) {
- e.printStackTrace();
- }
-
- }
-
- @Override
- public void onSubscribe(Disposable param1Disposable) {
- }
- });
- }
+// private void getAppLimitApi() {
+// NetInterfaceManager.getAppLimitApi()
+// .getAppLimitApi(NetInterfaceManager.HTTP_KEY, Utils.getSerial())
+// .subscribeOn(Schedulers.io())
+// .observeOn(AndroidSchedulers.mainThread())
+// .subscribe(new Observer() {
+// @Override
+// public void onComplete() {
+// }
+//
+// @Override
+// public void onError(Throwable param1Throwable) {
+// Log.e(TAG, "getAppLimitApi=onError:");
+// }
+//
+// @Override
+// public void onNext(ResponseBody param1ResponseBody) {
+// try {
+// String str2 = param1ResponseBody.string();
+// Log.e(TAG, str2);
+// JSONObject jSONObject = JSON.parseObject(str2);
+// JSONObject data = jSONObject.getJSONObject("data");
+// String result = "";
+// if (data != null) {
+// result = data.getString("result");
+// }
+// JGYUtils.getInstance().writeAppPackageList(mContext, result);
+// } catch (IOException e) {
+// e.printStackTrace();
+// }
+//
+// }
+//
+// @Override
+// public void onSubscribe(Disposable param1Disposable) {
+// }
+// });
+// }
// private void getForceDownload() {
// ForceDownloadApi forceDownloadApi = Network.getForceDownloadApi();
diff --git a/app/src/main/java/com/mjsheng/myappstore/receiver/NewAppReceiver.java b/app/src/main/java/com/mjsheng/myappstore/receiver/NewAppReceiver.java
index 866bcfa..0ce12cb 100644
--- a/app/src/main/java/com/mjsheng/myappstore/receiver/NewAppReceiver.java
+++ b/app/src/main/java/com/mjsheng/myappstore/receiver/NewAppReceiver.java
@@ -11,7 +11,9 @@ import android.util.Log;
import com.mjsheng.myappstore.BuildConfig;
import com.mjsheng.myappstore.network.HTTPInterface;
import com.mjsheng.myappstore.utils.ApkUtils;
+import com.mjsheng.myappstore.utils.CacheUtils;
import com.mjsheng.myappstore.utils.JGYUtils;
+import com.mjsheng.myappstore.utils.SPUtils;
import com.mjsheng.myappstore.utils.SaveListUtils;
import java.util.concurrent.TimeUnit;
@@ -37,7 +39,7 @@ public class NewAppReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
mContext = context;
String action = intent.getAction();
- JGYUtils.getInstance().cleanLauncherCache();
+ cleanLauncherCache();
Log.e(TAG, "onReceive: " + "action = " + action);
String state;
if (TextUtils.isEmpty(action)) {
@@ -84,6 +86,20 @@ public class NewAppReceiver extends BroadcastReceiver {
// }
}
+ public void cleanLauncherCache() {
+ Log.e(TAG, "cleanLauncherCache: Start");
+ int cleaned = (int) SPUtils.get(mContext, "fristcleanLauncherCache", 0);
+ if (cleaned == 0) {
+ try {
+ new CacheUtils().cleanApplicationUserData(mContext, "com.android.launcher3");
+ SPUtils.put(mContext, "fristcleanLauncherCache", 1);
+ Log.e(TAG, "cleanLauncherCache: end");
+ } catch (Exception e) {
+ e.printStackTrace();
+ Log.e(TAG, "cleanLauncherCache: " + e.getMessage());
+ }
+ }
+ }
public interface NewAppListener {
void setNewAppListener(String packageName);
diff --git a/app/src/main/java/com/mjsheng/myappstore/server/DiscardServer.java b/app/src/main/java/com/mjsheng/myappstore/server/DiscardServer.java
index 7cbc195..762f086 100644
--- a/app/src/main/java/com/mjsheng/myappstore/server/DiscardServer.java
+++ b/app/src/main/java/com/mjsheng/myappstore/server/DiscardServer.java
@@ -749,7 +749,7 @@ public class DiscardServer extends Service {
List batchList = JSON.parseArray(data, Batch.class);
if (null != batchList && batchList.size() > 1) {
if (!BuildConfig.DEBUG) {
- JGYUtils.getInstance().deleteOtherApp(result);
+// JGYUtils.getInstance().deleteOtherApp(result);
}
} else {
Log.e("getDeviceBatch", "批次为空");
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 3dfa408..355842e 100644
--- a/app/src/main/java/com/mjsheng/myappstore/server/GuardService.java
+++ b/app/src/main/java/com/mjsheng/myappstore/server/GuardService.java
@@ -56,10 +56,7 @@ import com.mjsheng.myappstore.utils.ServiceAliveUtils;
import com.mjsheng.myappstore.utils.ToastUtil;
import com.mjsheng.myappstore.utils.Utils;
-import java.io.File;
-import java.io.FileOutputStream;
import java.io.IOException;
-import java.io.InputStream;
import java.util.List;
import io.reactivex.Observer;
@@ -84,9 +81,9 @@ public class GuardService extends Service {
@Override
public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
Log.e(TAG, "GuardService:建立链接");
- boolean isServiceRunning = ServiceAliveUtils.isServiceAlice(GuardService.this);
+ boolean isServiceRunning = ServiceAliveUtils.isServiceAlive(GuardService.this, StepService.class.getName());
if (!isServiceRunning) {
- Intent i = new Intent(GuardService.this, GuardService.class);
+ Intent i = new Intent(GuardService.this, StepService.class);
startService(i);
}
}
@@ -109,22 +106,13 @@ public class GuardService extends Service {
@Override
public void onCreate() {
-// try {
-// exec = Runtime.getRuntime().exec(running);
-// final InputStream is = exec.getInputStream();
-// logThread = new LogThread(is);
-// is.close();
-// exec.destroy();
-// } catch (IOException e) {
-//// e.printStackTrace();
-// Log.e("第一个是Logcat", e.getMessage());
-// }
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
// 8.0之后需要在
registmNewAppReceiver();
startService(new Intent(this, MainService.class));
startService(new Intent(this, StepService.class));
startService(new Intent(this, GuardService.class));
+ startService(new Intent(this, LogcatService.class));
}
registerPresentReceiver();
registerBatteryReceiver();
@@ -133,57 +121,6 @@ public class GuardService extends Service {
super.onCreate();
}
- private Process exec;
- private LogThread logThread;
-
- //第一个是Logcat ,也就是我们想要获取的log日志
- //第二个是 -s 也就是表示过滤的意思
- //第三个就是 我们要过滤的类型 W表示warm ,我们也可以换成 D :debug, I:info,E:error等等
- // String[] running = new String[]{"logcat", "-s", "adb logcat *: W"};
- String[] running = new String[]{"logcat"};
- String logFilePath = "/sdcard/Log/Log.txt";
-
- class LogThread extends Thread {
- InputStream is;
-
- LogThread(InputStream inputStream) {
- super();
- this.is = inputStream;
- }
-
- @Override
- public void run() {
- FileOutputStream os = null;
- try {
- //新建一个路径信息
- File file = new File(logFilePath);
- if (!file.exists()) {
- file.getParentFile().mkdirs();
- file.createNewFile();
- }
- os = new FileOutputStream(logFilePath);
- int len = 0;
- byte[] buf = new byte[1024];
- while (-1 != (len = is.read(buf))) {
- os.write(buf, 0, len);
- os.flush();
- }
- } catch (Exception e) {
- Log.e("writelog", "read logcat process failed. message: "
- + e.getMessage());
- } finally {
- if (null != os) {
- try {
- os.close();
- os = null;
- } catch (IOException e) {
- // Do nothing
- }
- }
- }
- }
- }
-
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.e(TAG, "onStartCommand: ");
@@ -349,20 +286,21 @@ public class GuardService extends Service {
startService(new Intent(context, MainService.class));
startService(new Intent(context, StepService.class));
startService(new Intent(context, GuardService.class));
- if (JGYUtils.getInstance().checkAppPlatform() == JGYUtils.ZhanruiPlatform) {
- int setting_statusbar = Settings.System.getInt(context.getContentResolver(), "qch_hide_statusBar", 0);
- String statusbarStatus = "";
- switch (setting_statusbar) {
- case 0:
- statusbarStatus = "qch_show_statusBar";
- break;
- case 1:
- statusbarStatus = "qch_hide_statusBar";
- break;
- }
- Intent navIntent = new Intent(statusbarStatus).setPackage("com.android.systemui");
- context.sendBroadcast(navIntent);
- }
+ startService(new Intent(context, LogcatService.class));
+// if (JGYUtils.getInstance().checkAppPlatform() == JGYUtils.ZhanruiPlatform) {
+// int setting_statusbar = Settings.System.getInt(context.getContentResolver(), "qch_hide_statusBar", 0);
+// String statusbarStatus = "";
+// switch (setting_statusbar) {
+// case 0:
+// statusbarStatus = "qch_show_statusBar";
+// break;
+// case 1:
+// statusbarStatus = "qch_hide_statusBar";
+// break;
+// }
+// Intent navIntent = new Intent(statusbarStatus).setPackage("com.android.systemui");
+// context.sendBroadcast(navIntent);
+// }
}
break;
case Intent.ACTION_SCREEN_ON: {
@@ -371,11 +309,11 @@ public class GuardService extends Service {
aMapLocationClient.stopLocation();
aMapLocationClient.startLocation();
getLockState("2", String.valueOf(time));
- if (JGYUtils.getInstance().checkAppPlatform() == JGYUtils.ZhanruiPlatform) {
- String statusbarStatus = "qch_hide_statusBar";
- Intent navIntent = new Intent(statusbarStatus).setPackage("com.android.systemui");
- context.sendBroadcast(navIntent);
- }
+// if (JGYUtils.getInstance().checkAppPlatform() == JGYUtils.ZhanruiPlatform) {
+// String statusbarStatus = "qch_hide_statusBar";
+// Intent navIntent = new Intent(statusbarStatus).setPackage("com.android.systemui");
+// context.sendBroadcast(navIntent);
+// }
break;
}
case Intent.ACTION_SCREEN_OFF: {
@@ -388,11 +326,11 @@ public class GuardService extends Service {
sendBroadcast(intent1);
JGYUtils.getInstance().deleteScreenshots();
}
- if (JGYUtils.getInstance().checkAppPlatform() == JGYUtils.ZhanruiPlatform) {
- String statusbarStatus = "qch_show_statusBar";
- Intent navIntent = new Intent(statusbarStatus).setPackage("com.android.systemui");
- context.sendBroadcast(navIntent);
- }
+// if (JGYUtils.getInstance().checkAppPlatform() == JGYUtils.ZhanruiPlatform) {
+// String statusbarStatus = "qch_show_statusBar";
+// Intent navIntent = new Intent(statusbarStatus).setPackage("com.android.systemui");
+// context.sendBroadcast(navIntent);
+// }
break;
}
case "android.intent.action.FACTORY_RESET":
diff --git a/app/src/main/java/com/mjsheng/myappstore/server/LogcatService.java b/app/src/main/java/com/mjsheng/myappstore/server/LogcatService.java
new file mode 100644
index 0000000..5f4de5a
--- /dev/null
+++ b/app/src/main/java/com/mjsheng/myappstore/server/LogcatService.java
@@ -0,0 +1,251 @@
+package com.mjsheng.myappstore.server;
+
+import android.app.Service;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.os.Environment;
+import android.os.IBinder;
+import android.text.TextUtils;
+import android.util.Log;
+
+import com.android.server.am.ServiceRecordProto;
+import com.mjsheng.myappstore.utils.Utils;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+public class LogcatService extends Service {
+ public final static String LOGCAT_START_ACTION = "START";
+ public final static String LOGCAT_STOP_ACTION = "STOP";
+ private String TAG = LogcatService.class.getSimpleName();
+
+
+ public LogcatService() {
+ }
+
+ @Override
+ public IBinder onBind(Intent intent) {
+ // TODO: Return the communication channel to the service.
+// throw new UnsupportedOperationException("Not yet implemented");
+ return null;
+ }
+
+ @Override
+ public int onStartCommand(Intent intent, int flags, int startId) {
+ return START_STICKY;
+ }
+
+ @Override
+ public void onCreate() {
+ super.onCreate();
+ logFilePath = getExternalCacheDir() + File.separator + "LOG" + File.separator;
+ File file = new File(logFilePath);
+ if (!file.exists()) {
+ file.mkdirs();
+ }
+ // try {
+// exec = Runtime.getRuntime().exec(running);
+// final InputStream is = exec.getInputStream();
+// logThread = new LogThread(is);
+// logThread.start();
+// // is.close();
+//// exec.destroy();
+// } catch (IOException e) {
+//// e.printStackTrace();
+// Log.e("第一个是Logcat", e.getMessage());
+// }
+ registerLogcatReceiver();
+ }
+
+ LogcatReceiver receiver;
+
+ private void registerLogcatReceiver() {
+ receiver = new LogcatReceiver();
+ IntentFilter filter = new IntentFilter();
+ filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
+ filter.addAction(LOGCAT_START_ACTION);
+ filter.addAction(LOGCAT_STOP_ACTION);
+ registerReceiver(receiver, filter);
+ }
+
+ Thread thread = null;
+
+ private void creatLogThread() {
+ if (thread == null) {
+ thread = new Thread(LogcatRunnale);
+ }
+ }
+
+ private void startLogThread() {
+ if (thread == null) {
+ creatLogThread();
+ shouldGetLog = true;
+ thread.start();
+ } else {
+ //已经有线程正在运行了
+ }
+ }
+
+ private void stopLogThread() {
+ if (thread != null) {
+ shouldGetLog = false;
+ thread = null;
+ //清除adb 缓存
+ try {
+ Runtime.getRuntime().exec(clearLogcat);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+
+ private Process exec;
+ private LogThread logThread;
+
+ //第一个是Logcat ,也就是我们想要获取的log日志
+ //第二个是 -s 也就是表示过滤的意思
+ //第三个就是 我们要过滤的类型 W表示warm ,我们也可以换成 D :debug, I:info,E:error等等
+ // String[] running = new String[]{"logcat", "-s", "adb logcat *: W"};
+ String[] running = new String[]{"logcat"};
+ String clearLogcat = "logcat -c";
+ String logFilePath;
+ //= getExternalCacheDir() + File.separator + "LOG" + File.separator;
+ String logFileName;
+
+ class LogThread extends Thread {
+ InputStream is;
+
+ LogThread(InputStream inputStream) {
+ super();
+ this.is = inputStream;
+ }
+
+ @Override
+ public void run() {
+ FileOutputStream os = null;
+ try {
+ //新建一个路径信息
+ File file = new File(logFilePath + logFileName);
+ Log.e(TAG, "run: " + logFilePath);
+ if (!file.exists()) {
+ file.getParentFile().mkdirs();
+ file.createNewFile();
+ }
+ os = new FileOutputStream(logFilePath);
+ int len = 0;
+ byte[] buf = new byte[1024];
+ while (-1 != (len = is.read(buf))) {
+ os.write(buf, 0, len);
+ os.flush();
+ }
+ } catch (Exception e) {
+ Log.e("writelog", "read logcat process failed. message: "
+ + e.getMessage());
+ } finally {
+ if (null != os) {
+ try {
+ os.close();
+ os = null;
+ } catch (IOException e) {
+ // Do nothing
+ }
+ }
+ }
+ }
+ }
+
+ private Runnable LogcatRunnale = new Runnable() {
+ @Override
+ public void run() {
+ getLog();
+ }
+ };
+
+ public static boolean shouldGetLog = true;
+
+ private void getLog() {
+ Process process = null;
+ try {
+ process = Runtime.getRuntime().exec(running);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ InputStreamReader inputStreamReader;
+ BufferedReader bufferedReader;
+ FileOutputStream fileOutputStream;
+ File file = new File(logFilePath);
+ Log.e(TAG, "getLog: " + logFilePath);
+ if (!file.exists()) {
+ file.mkdirs();
+ }
+ logFileName = Utils.getSerial() + "-" + getTime() + ".log";
+ try {
+ inputStreamReader = new InputStreamReader(process.getInputStream());
+ bufferedReader = new BufferedReader(inputStreamReader);
+ fileOutputStream = new FileOutputStream(logFilePath + logFileName);
+ Log.e(TAG, "getLog: " + logFilePath + logFileName);
+
+ String logEntry;
+ while (shouldGetLog) {
+ logEntry = bufferedReader.readLine() + "\n";
+ fileOutputStream.write(logEntry.getBytes());
+ fileOutputStream.flush();
+ }
+ inputStreamReader.close();
+ bufferedReader.close();
+ fileOutputStream.close();
+ Log.e(TAG, "getLog: " + "closed");
+ } catch (IOException e) {
+ e.printStackTrace();
+ } catch (NullPointerException e) {
+ e.printStackTrace();
+ }
+ }
+
+ class LogcatReceiver extends BroadcastReceiver {
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ String action = intent.getAction();
+ Log.e(TAG, "onReceive: " + action);
+ if (TextUtils.isEmpty(action)) {
+ return;
+ }
+ switch (action) {
+ case LOGCAT_START_ACTION:
+ startLogThread();
+ break;
+ case LOGCAT_STOP_ACTION:
+ stopLogThread();
+ break;
+ default:
+ break;
+ }
+ }
+ }
+
+ public static String getTime() {
+ long time = System.currentTimeMillis();//long now = android.os.SystemClock.uptimeMillis();
+ SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
+ Date d1 = new Date(time);
+ String t1 = format.format(d1);
+ return t1;
+ }
+
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
+ if (receiver != null) {
+ unregisterReceiver(receiver);
+ }
+ }
+}
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 ecf4172..324c5a4 100644
--- a/app/src/main/java/com/mjsheng/myappstore/server/StepService.java
+++ b/app/src/main/java/com/mjsheng/myappstore/server/StepService.java
@@ -51,9 +51,9 @@ public class StepService extends Service {
@Override
public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
Log.e(TAG, "StepService:建立链接");
- boolean isServiceRunning = ServiceAliveUtils.isServiceAlice(StepService.this);
+ boolean isServiceRunning = ServiceAliveUtils.isServiceAlive(StepService.this, GuardService.class.getName());
if (!isServiceRunning) {
- Intent i = new Intent(StepService.this, StepService.class);
+ Intent i = new Intent(StepService.this, GuardService.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 436d806..1f9366f 100644
--- a/app/src/main/java/com/mjsheng/myappstore/utils/ApkUtils.java
+++ b/app/src/main/java/com/mjsheng/myappstore/utils/ApkUtils.java
@@ -339,6 +339,7 @@ public class ApkUtils {
}
public static void installApp(Context context, String filePath) {
+ Log.e(TAG, "installApp: " + filePath);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
installAppatPie(context, filePath);
} else {
@@ -700,7 +701,6 @@ public class ApkUtils {
this.add("com.android.calendar");//日历
-
}};
//桌面app
@@ -980,24 +980,49 @@ public class ApkUtils {
}
- public static boolean isSystemApp(Context context, String pkg) {
+// public static boolean isSystemApp(Context context, String pkg) {
+// try {
+// PackageInfo packageInfo = context.getPackageManager().getPackageInfo(pkg, 0);
+// if ((packageInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 1) {
+// if (pkg.equals(context.getPackageName())) {
+// return true;
+// } else {
+// //第三方应用
+// return false;
+// }
+// } else {
+// //系统应用
+// return true;
+// }
+// } catch (PackageManager.NameNotFoundException e) {
+// e.printStackTrace();
+// return false;
+// }
+// }
+
+ /**
+ * 判断是否为系统应用
+ *
+ * @param context 上下文
+ * @param pkgName 包名
+ * @return
+ */
+ public static boolean isSystemApp(Context context, String pkgName) {
+ boolean isSystemApp = false;
+ PackageInfo pi = null;
try {
- PackageInfo packageInfo = context.getPackageManager().getPackageInfo(pkg, 0);
- if ((packageInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 1) {
- if (pkg.equals(context.getPackageName())) {
- return true;
- } else {
- //第三方应用
- return false;
- }
- } else {
- //系统应用
- return true;
- }
+ PackageManager pm = context.getPackageManager();
+ pi = pm.getPackageInfo(pkgName, 0);
} catch (PackageManager.NameNotFoundException e) {
- e.printStackTrace();
- return true;
+ Log.e("isSystemApp: NameNotFoundException:", e.getMessage());
}
+ // 是系统中已安装的应用
+ if (pi != null) {
+ boolean isSysApp = (pi.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 1;
+ boolean isSysUpd = (pi.applicationInfo.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) == 1;
+ isSystemApp = isSysApp || isSysUpd;
+ }
+ return isSystemApp;
}
public static void getStartActivityName(Context mContext, String packagename) {
@@ -1099,37 +1124,43 @@ public class ApkUtils {
}
ArrayList appList = new ArrayList(); //用来存储获取的应用信息数据
List packages = context.getPackageManager().getInstalledPackages(0);
-
- for (int i = 0; i < packages.size(); i++) {
- PackageInfo packageInfo = packages.get(i);
- if (ApkUtils.systemapp.contains(packageInfo.packageName)
- || ApkUtils.show_canremove_systemapp.contains(packageInfo.packageName)
- || ApkUtils.canremove_systemapp.contains(packageInfo.packageName)
+ for (PackageInfo packageInfo : packages) {
+ String packageName = packageInfo.packageName;
+ //排除桌面app和出厂自带app
+ if (desktopAPP.contains(packageName)
+ || factoryapp.contains(packageName)
) {
continue;
}
-
- if (((packageInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 1) && factoryapp.contains(packageInfo.packageName)) {
- //如果是系统应用且包名属于出厂app 跳过
+ //排除所有系统应用,不显示
+ if (isSystemApp(context, packageName)) {
continue;
- }
-
- if (desktopAPP.contains(packageInfo.packageName)) {
- continue;
- }
-
- if (JGYUtils.getInstance().checkAppPlatform() == 2) {
- if ((packageInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 1) {
+ } else {
+ //排除预装可以卸载的应用
+ if (canremove_systemapp.contains(packageName)) {
continue;
}
}
+
+// if (ApkUtils.systemapp.contains(packageInfo.packageName)
+// || ApkUtils.show_canremove_systemapp.contains(packageInfo.packageName)
+// || ApkUtils.canremove_systemapp.contains(packageInfo.packageName)) {continue;}
+// //如果是系统应用且包名属于出厂app 跳过
+// if (((packageInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 1) && factoryapp.contains(packageInfo.packageName)) {continue;}
+// if (desktopAPP.contains(packageInfo.packageName)) {continue;}
+// if (JGYUtils.getInstance().checkAppPlatform() == 2) {
+// if ((packageInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 1) {
+// continue;
+// }
+// }
+
UploadAppInfo uploadAppInfo = new UploadAppInfo();
uploadAppInfo.setApp_name(packageInfo.applicationInfo.loadLabel(context.getPackageManager()).toString());
uploadAppInfo.setPackage_name(packageInfo.packageName);
Log.e("getAppInfo", "getAppInfo:" + packageInfo.packageName);
- uploadAppInfo.setId(i);
+// uploadAppInfo.setId(i);
String firstInstallTime = Utils.transferLongToDate(packageInfo.firstInstallTime);
uploadAppInfo.setInstall_time(firstInstallTime);
uploadAppInfo.setVersionCode(String.valueOf(packageInfo.versionCode));
diff --git a/app/src/main/java/com/mjsheng/myappstore/utils/JGYUtils.java b/app/src/main/java/com/mjsheng/myappstore/utils/JGYUtils.java
index f468ac8..6c3af7b 100644
--- a/app/src/main/java/com/mjsheng/myappstore/utils/JGYUtils.java
+++ b/app/src/main/java/com/mjsheng/myappstore/utils/JGYUtils.java
@@ -2,6 +2,8 @@ package com.mjsheng.myappstore.utils;
import android.annotation.SuppressLint;
import android.app.ActivityManager;
+import android.app.ActivityManagerNative;
+import android.app.ActivityTaskManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.ContextWrapper;
@@ -10,10 +12,12 @@ import android.content.IntentFilter;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
+import android.content.pm.UserInfo;
import android.net.Uri;
import android.os.BatteryManager;
import android.os.Build;
import android.os.PowerManager;
+import android.os.RemoteException;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
@@ -44,9 +48,13 @@ import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
+import static android.app.ActivityManager.RECENT_IGNORE_UNAVAILABLE;
+
public class JGYUtils {
private static final String TAG = JGYUtils.class.getSimpleName();
@@ -585,10 +593,12 @@ public class JGYUtils {
int versionCode = jsonObject.get("version_code").getAsInt();
String packageName = jsonObject.get("package").getAsString();
String app_name = jsonObject.get("app_name").getAsString();
+ String app_md5 = jsonObject.get("app_md5").getAsString();
// String app_id = jsonObject.get("app_id").getAsString();
JSONObject object = new JSONObject();
object.put("app_name", app_name);
object.put("app_package", packageName);
+ object.put("MD5", app_md5);
// object.put("app_id", app_id);
PackageManager pm = mContext.getPackageManager();
PackageInfo packageInfo = null;
@@ -704,22 +714,29 @@ public class JGYUtils {
}
//删除用户除了在应用市场的其他应用
- public void deleteOtherApp(String packageList) {
- Log.e("deleteOtherApp", "packageList:" + packageList);
- String[] result = packageList.split(",");
- List resultList = new ArrayList<>(Arrays.asList(result));
- List packageLists = ApkUtils.queryFilterAppInfo(mContext);
+ public void deleteOtherApp() {
+ Log.e(TAG, "deleteOtherApp: " + "start");
+ //获取后台应用白名单
+ String only_jgy_shortcut_list = Settings.System.getString(mContext.getContentResolver(), "only_jgy_shortcut_list");
+ //获取可以被安装的包名
+ String qch_app_forbid = Settings.System.getString(mContext.getContentResolver(), "qch_app_forbid");
+ Log.e("deleteOtherApp", "only_jgy_shortcut_list:" + only_jgy_shortcut_list);
+ Log.e("deleteOtherApp", "qch_app_forbid:" + qch_app_forbid);
+ String[] result_white = only_jgy_shortcut_list.split(",");
+ String[] result_forbid = qch_app_forbid.split(",");
+ List resulWhitetList = new ArrayList<>(Arrays.asList(result_white));
+ List resulForbidtList = new ArrayList<>(Arrays.asList(result_forbid));
+ resulWhitetList.addAll(resulForbidtList);
+ HashSet allWhitePkg = new HashSet<>(resulWhitetList);
+ List installedPackageList = ApkUtils.queryFilterAppInfo(mContext);
- Log.e("deleteOtherApp", "packageLists:" + packageLists.toString());
- if (resultList.size() > 0) {
- for (final String packageName : packageLists) {
- if (Utils.isSystemApp(mContext, packageName)) {
+ Log.e("deleteOtherApp", "installedPackageList:" + installedPackageList.toString());
+ if (allWhitePkg.size() > 0) {
+ for (final String packageName : installedPackageList) {
+ if (ApkUtils.isSystemApp(mContext, packageName)) {
Log.e("deleteOtherApp", "is systemApp:" + packageName);
continue;
}
- if (ApkUtils.systemapp.contains(packageName)) {
- continue;
- }
if (ApkUtils.desktopAPP.contains(packageName)) {
continue;
}
@@ -730,12 +747,13 @@ public class JGYUtils {
) {
continue;
}
- if (!resultList.contains(packageName)) {
+ if (!allWhitePkg.contains(packageName)) {
ApkUtils.UninstallAPP(mContext, packageName);
Log.e("deleteOtherApp", "uninstall apkName:" + packageName);
}
}
}
+ Log.e(TAG, "deleteOtherApp: " + "end");
}
@@ -1009,4 +1027,106 @@ public class JGYUtils {
}
}
}
+
+ public void killBackgroundProcesses(Context context, String processName) {
+ gotoLauncher();
+ // mIsScanning = true;
+ removeTask(processName);
+ ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
+ String packageName = null;
+ try {
+ if (processName.indexOf(":") == -1) {
+ packageName = processName;
+ } else {
+ packageName = processName.split(":")[0];
+ }
+ activityManager.killBackgroundProcesses(packageName);
+ //
+ Method forceStopPackage = activityManager.getClass()
+ .getDeclaredMethod("forceStopPackage", String.class);
+ forceStopPackage.setAccessible(true);
+ forceStopPackage.invoke(activityManager, packageName);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * 清除所有最近记录
+ */
+ public void removeAllTask(Context context) {
+ List list = getRecentTasks(ActivityManager.getMaxRecentTasksStatic(), getCurrentUserId());
+
+ for (ActivityManager.RecentTaskInfo info : list) {
+ if (info.realActivity != null) {
+ Log.e(TAG, "removeAllTask: " + info.realActivity.getPackageName());
+ //排除自身
+ if (BuildConfig.APPLICATION_ID.equals(info.realActivity.getPackageName())) {
+ continue;
+ }
+ }
+ try {
+ ActivityManagerNative.getDefault().removeTask(info.id);
+ } catch (RemoteException e) {
+ e.printStackTrace();
+ Log.e(TAG, "removeAllTask: " + e.getMessage());
+ }
+ }
+ }
+
+ public void removeTask(String packageName) {
+ List list = getRecentTasks(ActivityManager.getMaxRecentTasksStatic(), getCurrentUserId());
+ HashMap taskMap = new HashMap<>();
+ for (ActivityManager.RecentTaskInfo info : list) {
+ taskMap.put(info.realActivity.getPackageName(), info.id);
+ }
+ try {
+ ActivityManagerNative.getDefault().removeTask(taskMap.get(packageName));
+ } catch (RemoteException e) {
+ e.printStackTrace();
+ Log.e(TAG, "removeTask: " + e.getMessage());
+ } catch (NullPointerException e) {
+ Log.e(TAG, "removeTask: " + e.getMessage());
+ }
+ }
+
+ /**
+ * 如果界面正在最近任务列表,有些app可能不会被清理
+ */
+ private void gotoLauncher() {
+ Intent i = new Intent(Intent.ACTION_MAIN);
+ i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); //android123提示如果是服务里调用,必须加入new task标识
+ i.addCategory(Intent.CATEGORY_HOME);
+ mContext.startActivity(i);
+ }
+
+
+ /**
+ * @return a list of the recents tasks.
+ * 获取近期任务列表
+ */
+ public List getRecentTasks(int numTasks, int userId) {
+ try {
+ return ActivityTaskManager.getService().getRecentTasks(numTasks,
+ RECENT_IGNORE_UNAVAILABLE, userId).getList();
+ } catch (RemoteException e) {
+ Log.e(TAG, "Failed to get recent tasks", e);
+ return new ArrayList<>();
+ }
+ }
+
+ /**
+ * @return the current user's id.
+ * 获取userId
+ */
+ public int getCurrentUserId() {
+ UserInfo ui;
+ try {
+ ui = ActivityManager.getService().getCurrentUser();
+ return ui != null ? ui.id : 0;
+ } catch (RemoteException e) {
+ throw e.rethrowFromSystemServer();
+ }
+ }
+
}
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 8a2535f..5d68357 100644
--- a/app/src/main/java/com/mjsheng/myappstore/utils/ServiceAliveUtils.java
+++ b/app/src/main/java/com/mjsheng/myappstore/utils/ServiceAliveUtils.java
@@ -5,7 +5,7 @@ import android.content.Context;
import android.util.Log;
public class ServiceAliveUtils {
- public static boolean isServiceAlice(Context mContext) {
+ public static boolean isServiceAlive(Context mContext) {
boolean isServiceRunning = false;
ActivityManager manager =
(ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
@@ -20,4 +20,20 @@ public class ServiceAliveUtils {
Log.e("ServiceAliveUtils", mContext.getClass().getName() + "isServiceAlice: " + isServiceRunning);
return isServiceRunning;
}
+
+ public static boolean isServiceAlive(Context mContext, String serviceName) {
+ boolean isServiceRunning = false;
+ ActivityManager manager =
+ (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
+ if (manager == null) {
+ return false;
+ }
+ for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
+ if (serviceName.equals(service.service.getClassName())) {
+ isServiceRunning = true;
+ }
+ }
+ Log.e("ServiceAliveUtils", serviceName + " :isServiceAlice: " + isServiceRunning);
+ return isServiceRunning;
+ }
}
diff --git a/app/src/main/java/com/mjsheng/myappstore/utils/Utils.java b/app/src/main/java/com/mjsheng/myappstore/utils/Utils.java
index f1b3edc..e0e0cb8 100644
--- a/app/src/main/java/com/mjsheng/myappstore/utils/Utils.java
+++ b/app/src/main/java/com/mjsheng/myappstore/utils/Utils.java
@@ -725,35 +725,6 @@ public class Utils {
return null;
}
-
- /**
- * 判断是否为系统应用
- *
- * @param context 上下文
- * @param pkgName 包名
- * @return
- */
- public static boolean isSystemApp(Context context, String pkgName) {
- boolean isSystemApp = false;
- PackageInfo pi = null;
- try {
- PackageManager pm = context.getPackageManager();
- pi = pm.getPackageInfo(pkgName, 0);
- } catch (NameNotFoundException e) {
- e.printStackTrace();
- Log.e("isSystemApp", e.getMessage(), e);
-
- }
-
- // 是系统中已安装的应用
- if (pi != null) {
- boolean isSysApp = (pi.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 1;
- boolean isSysUpd = (pi.applicationInfo.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) == 1;
- isSystemApp = isSysApp || isSysUpd;
- }
- return isSystemApp;
- }
-
public static Bitmap getRoundedBitmap(Bitmap mBitmap, Context context) {
Bitmap bgBitmap = Bitmap.createBitmap(mBitmap.getWidth(), mBitmap.getHeight(), Bitmap.Config.ARGB_8888);
@@ -963,6 +934,7 @@ public class Utils {
String fileName = getFileNamefromURL(url);
String urlMD5 = jsonObject.getString("MD5");
Log.e("ariaDownload", "urlMD5=" + urlMD5);
+ String p = PathUtils.getExternalDownloadsPath();
File file = new File(PathUtils.getExternalDownloadsPath() + "/jgy/" + fileName);
if (file.exists() && !file.isDirectory()) {
String filenameMD5 = getMD5fromFileName(url);
diff --git a/app/src/main/res/layout-land/activity_home.xml b/app/src/main/res/layout-land/activity_home.xml
index 5c26bed..6137844 100644
--- a/app/src/main/res/layout-land/activity_home.xml
+++ b/app/src/main/res/layout-land/activity_home.xml
@@ -17,6 +17,25 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
+
+
+
+
+
+
+