From 780fb8561b5d699b049ecda13eafd1ea60078cfe Mon Sep 17 00:00:00 2001 From: Administrator <981964879@qq.com> Date: Mon, 15 Jun 2020 18:17:38 +0800 Subject: [PATCH] =?UTF-8?q?update:2020.06.15=20fix:=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E6=8E=A8=E9=80=81=E4=B9=9F=E8=83=BD=E5=88=A0=E9=99=A4=E5=BA=94?= =?UTF-8?q?=E7=94=A8=20add:=E6=B2=A1=E6=9C=89=E9=94=81=E5=AE=9A=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=E4=B8=8D=E5=88=9D=E5=A7=8B=E5=8C=96=E6=9E=81=E5=85=89?= =?UTF-8?q?=E6=8E=A8=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 4 +- .../com/mjsheng/myappstore/MyApplication.java | 14 +- .../myappstore/activity/MainActivity.java | 29 +- .../myappstore/network/HTTPInterface.java | 1 + .../myappstore/receiver/MyJPushReceiver.java | 263 +++++++++--------- .../myappstore/server/InitJpushServer.java | 67 +++-- .../mjsheng/myappstore/utils/ApkUtils.java | 35 ++- .../main/res/layout-land/activity_main.xml | 205 +++++++------- .../main/res/layout-port/activity_main.xml | 211 +++++++------- 9 files changed, 438 insertions(+), 391 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 23a4b0e..95181fb 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -15,8 +15,8 @@ android { minSdkVersion 20 targetSdkVersion 29 - versionCode 145 - versionName "3.0.2"//测试jiaoguanyi.cn + versionCode 147 + versionName "3.0.4"//测试jiaoguanyi.cn // versionCode 129 // versionName "2.0.0.9"// 正式jiaoguanyi.com 双数正式 单数测试 multiDexEnabled true diff --git a/app/src/main/java/com/mjsheng/myappstore/MyApplication.java b/app/src/main/java/com/mjsheng/myappstore/MyApplication.java index 8c0455b..ff12bd3 100644 --- a/app/src/main/java/com/mjsheng/myappstore/MyApplication.java +++ b/app/src/main/java/com/mjsheng/myappstore/MyApplication.java @@ -128,10 +128,10 @@ public class MyApplication extends MultiDexApplication { JPushInterface.setDebugMode(true); JPushInterface.requestPermission(this); // 初始化 JPush - JPushInterface.init(this); - + //JPushInterface.init(this); + //解锁设备不需要初始化 context = getApplicationContext(); -// Thread.setDefaultUncaughtExceptionHandler(this); + //Thread.setDefaultUncaughtExceptionHandler(this); mDateFormat = new SimpleDateFormat("HH:mm"); initOKHttp(); @@ -220,7 +220,6 @@ public class MyApplication extends MultiDexApplication { } - public void onTagOperatorResult(JPushMessage jPushMessage) { if (jPushMessage == null) { return; @@ -547,14 +546,9 @@ public class MyApplication extends MultiDexApplication { localAppList.add(appInformation); } } - - } else { - } - - } synchronized public void getWhitePackageList() { @@ -583,8 +577,6 @@ public class MyApplication extends MultiDexApplication { super.onError(call, response, e); } }); - - } private void writeAppPackageList(String result) { 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 3667387..53cf8bb 100644 --- a/app/src/main/java/com/mjsheng/myappstore/activity/MainActivity.java +++ b/app/src/main/java/com/mjsheng/myappstore/activity/MainActivity.java @@ -142,6 +142,7 @@ public class MainActivity extends AppCompatActivity { private int DeviceInfo; private RelativeLayout checkupdate; private ImageView back; + private RelativeLayout layout_class, layout_number, layout_name; //jiguang public static boolean isForeground = false; //for receive customer msg from jpush server @@ -151,6 +152,7 @@ public class MainActivity extends AppCompatActivity { public static final String KEY_MESSAGE = "message"; public static final String KEY_EXTRAS = "extras"; + public void registerMessageReceiver() { mMessageReceiver = new MessageReceiver(); IntentFilter filter = new IntentFilter(); @@ -308,7 +310,6 @@ public class MainActivity extends AppCompatActivity { callback = new ToastCallback(this); initView(); - timerImitate(); initData(); downloadManager = DownloadService.getDownloadManager(); @@ -386,6 +387,10 @@ public class MainActivity extends AppCompatActivity { lazyExit(); } }); + + layout_class = findViewById(R.id.layout_class); + layout_number = findViewById(R.id.layout_number); + layout_name = findViewById(R.id.layout_name); } final static int COUNTS = 5;// 点击次数 @@ -409,10 +414,8 @@ public class MainActivity extends AppCompatActivity { Log.e("mjhsneg", "gagagag--------------------------" + Utils.getSerial()); getLockedState(); // MyApplication.getInstance().getWhitePackageList(); - initJpush();//初始化极光推送 - HTTPInterface.setJpushTags(this); + // update();//接口更新app - sendMACaddress(); checkUpdate();//更新app Log.e("mac", com.blankj.utilcode.util.DeviceUtils.getMacAddress()); @@ -570,9 +573,13 @@ public class MainActivity extends AppCompatActivity { Log.e("ttlocked2", "DeselectBrowserArray---------" + a); String b = Settings.System.getString(getApplicationContext().getContentResolver(), "qch_webblack_url"); Log.e("ttlocked2", "qch_webblack_url---------" + b); - + HTTPInterface.setJpushTags(MainActivity.this); + sendMACaddress(); + timerImitate(); lazyLoading(); } + } else if (code == -300) { + ApkUtils.uninstallAllApp(MainActivity.this); } } @@ -642,16 +649,19 @@ public class MainActivity extends AppCompatActivity { if (null != info) { if (info.getBatch().equals("")) { tv_class.setText("暂无信息"); + layout_class.setVisibility(View.GONE); } else { tv_class.setText(info.getBatch()); } if (info.getSno().equals("")) { tv_number.setText("暂无信息"); + layout_number.setVisibility(View.GONE); } else { tv_number.setText(info.getSno()); } if (info.getRealname().equals("")) { tv_name.setText("暂无信息"); + layout_name.setVisibility(View.GONE); } else { tv_name.setText(info.getRealname()); } @@ -661,6 +671,9 @@ public class MainActivity extends AppCompatActivity { tv_class.setText("暂无信息"); tv_number.setText("暂无信息"); tv_name.setText("暂无信息"); + layout_class.setVisibility(View.GONE); + layout_number.setVisibility(View.GONE); + layout_name.setVisibility(View.GONE); break; } @@ -918,6 +931,7 @@ public class MainActivity extends AppCompatActivity { private void initJpush() { + JPushInterface.init(this); onTagAliasAction(7); String rid = JPushInterface.getRegistrationID(getApplicationContext()); if (!rid.isEmpty()) { @@ -962,7 +976,7 @@ public class MainActivity extends AppCompatActivity { @Override public void call(Long aLong) { Log.e("JPushInterface", "JPushInterface重新加载"); - initJpush(); + initJpush();//初始化极光推送 HTTPInterface.setJpushTags(MainActivity.this); } }); @@ -996,7 +1010,7 @@ public class MainActivity extends AppCompatActivity { } } - private void getAppLimitApi() { + private void getAppLimitApi() { AppLimitApi appLimitApi = Network.getAppLimitApi(); appLimitApi.getAppLimitApi(Configure.HTTP_KEY, Utils.getSerial()) .subscribeOn(Schedulers.io()) @@ -1463,6 +1477,7 @@ public class MainActivity extends AppCompatActivity { MyApplication.getInstance().setFinished(true); if (!net_ok.equals("")) { String[] nots = net_ok.split(","); + Settings.System.putString(getContentResolver(), "qch_jgy_network_allow", net_ok); Log.e("fht", "not::" + net_ok); } 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 62810d3..c260ab2 100644 --- a/app/src/main/java/com/mjsheng/myappstore/network/HTTPInterface.java +++ b/app/src/main/java/com/mjsheng/myappstore/network/HTTPInterface.java @@ -714,6 +714,7 @@ public class HTTPInterface { MyApplication.getInstance().setFinished(true); if (!net_ok.equals("")) { String[] nots = net_ok.split(","); + Settings.System.putString(context.getContentResolver(), "qch_jgy_network_allow", net_ok); Log.e("fht", "not::" + net_ok); } 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 2954f3a..e3d0f34 100644 --- a/app/src/main/java/com/mjsheng/myappstore/receiver/MyJPushReceiver.java +++ b/app/src/main/java/com/mjsheng/myappstore/receiver/MyJPushReceiver.java @@ -52,28 +52,26 @@ import okhttp3.ResponseBody; public class MyJPushReceiver extends BroadcastReceiver { private static final String TAG = "MyJPushReceiver"; - private final String ACTION_HrReceiver_JGY = "qch_jgy_network_allow"; - private final String ACTION_HrReceiver_JGY_DIS = "qch_jgy_network_disallow"; - private final String MSG_APPID = "5"; - - private final String MSG_BROWSER = "4"; - private final String MSG_DELETE = "1"; - private final String MSG_INSTALL = "9"; + private final String MSG_SETTING = "2"; - private final String MSG_LOCK = "10";//解锁 + private final String MSG_BROWSER = "4"; + + private final String MSG_APPID = "5"; private final String MSG_NET_CONTROL = "6"; private final String MSG_POWER_ON = "7"; - private final String MSG_RESET = "8";//加锁 + private final String MSG_RESET = "8";//重置 - private final String MSG_SETTING = "2"; + private final String MSG_INSTALL = "9"; + + private final String MSG_LOCK = "10";//解锁 private final String MSG_CAMERA = "11"; @@ -81,7 +79,7 @@ public class MyJPushReceiver extends BroadcastReceiver { private final String GET_APP_USEDTIME = "13"; - private final String GET_FORCEDOWNLOADURL = "14"; + private final String GET_FORCEDOWNLOADURL = "14";//强制下载 private final String SET_HOMEPAG_TAG = "15";//主页和书签管控 @@ -93,9 +91,126 @@ public class MyJPushReceiver extends BroadcastReceiver { private final String DISABLE_APP_SLIDE = "19";//禁止滑动 - private Context mContext; + private int changeNum(int paramInt) { + switch (paramInt) { + default: + return 1; + case 0: + return 1; + case 1: + break; + } + return 0; + } + + private void processCustomMessage(final Context context, Bundle bundle) { + String message = bundle.getString(JPushInterface.EXTRA_MESSAGE); + String title = bundle.getString(JPushInterface.EXTRA_TITLE); + String type = bundle.getString(JPushInterface.EXTRA_CONTENT_TYPE); + String extras = bundle.getString(JPushInterface.EXTRA_EXTRA); + String package_name = bundle.getString("package_name"); + + LogUtils.e("mjsheng", "message::" + message + "--type::" + type + "--title::" + title + "--extras::" + extras); +// ToastUtils.showShort("message::" + message + "--type::" + type + "--title::" + title + "--extras::" + extras + "---package_name:" + package_name); +// Toast.makeText(context, "message::" + message + "--type::" + type + "--title::" + title + "--extras::" + extras + "---package_name:" + package_name, Toast.LENGTH_SHORT).show(); + switch (message) { + case MSG_DELETE: + if (!TextUtils.isEmpty(title)) { + if (SaveListUtils.getlist().contains(title)) { + SaveListUtils.getlist().remove(title); + } + SaveListUtils.sendForceAPP(mContext); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + ApkUtils.uninstall(mContext, title); + } else { + ApkUtils.deleteApkInSilence(title); + } + } + getAppLimitApi(); + HTTPInterface.getNetAndLaunchSetting(mContext); + break; + case MSG_SETTING: + if (!TextUtils.isEmpty(extras)) { + SettingSysData(extras); + Log.e(TAG, "title--------" + extras); + } + // getSystemSetting(); + break; + case MSG_BROWSER: + getDeselectBrowerID(); + break; + case MSG_APPID: + getDeselectID(); + break; + case MSG_NET_CONTROL: + settingNetControl(extras); + break; + case MSG_POWER_ON: + settingPowerOn(extras); + break; + case MSG_RESET: + Utils.doMasterClear(mContext); + break; + case MSG_INSTALL: + // mContext.sendBroadcast(new Intent("android.intent.action.MASTER_CLEAR")); + getAppLimitApi(); + doDownloadAndInstall(extras); + HTTPInterface.setHideDesktopIcon(mContext); + break; + case MSG_LOCK: + settingLock(extras); + break; + case MSG_CAMERA: + settingCamera(extras); + break; + case MSG_ONEPACKAGES: + if (MyApplication.getInstance().isFinished()) { + settingOneNet(extras); + } + break; + case GET_APP_USEDTIME: + com.alibaba.fastjson.JSONObject jsonObject = JSON.parseObject(extras); + String random = jsonObject.getString("random"); + String sendType = jsonObject.getString("type"); + MyApplication.sendAppUsedTime(random, sendType); + break; + case GET_FORCEDOWNLOADURL: + com.alibaba.fastjson.JSONObject URI = JSON.parseObject(extras); + String versionCode = URI.getString("version_code"); + String url = URI.getString("url"); + com.alibaba.fastjson.JSONObject packageObj = new com.alibaba.fastjson.JSONObject(); + packageObj.put("app_name", "教管易"); + packageObj.put("app_package", "com.jiaoguanyi.store"); + Aria.download(this) + .load(url) //读取下载地址 + .setFilePath(PathUtils.getExternalDownloadsPath() + "/ygj/" + EncryptUtils.encryptMD5ToString("com.jiaoguanyi.store") + ".apk", true) + .setExtendField(packageObj.toJSONString()) + .create(); //启动下载} + + break; + case SET_HOMEPAG_TAG: + setHomepagtag(extras); + break; + + case APP_WEBSITE: + setAPPinsideWebsite(extras); + break; + case DISABLE_APPUPDATE: + Log.e("fht", extras); + setDisableUpdateList(extras); + break; + case HIDE_DESKTOP_ICON: + HTTPInterface.setHideDesktopIcon(context); + break; + case DISABLE_APP_SLIDE: + setDisableSlideList(extras); + break; + } + } + private void SettingSysData(String extras) { try { JSONObject data = new JSONObject(extras); @@ -282,18 +397,6 @@ public class MyJPushReceiver extends BroadcastReceiver { } } - private int changeNum(int paramInt) { - switch (paramInt) { - default: - return 1; - case 0: - return 1; - case 1: - break; - } - return 0; - } - private void doDownloadAndInstall(String s) { if (TextUtils.isEmpty(s)) { Log.e("mjsheng", "doDownloadAndInstall extras is null"); @@ -517,112 +620,6 @@ public class MyJPushReceiver extends BroadcastReceiver { return stringBuilder.toString(); } - private void processCustomMessage(final Context context, Bundle bundle) { - String message = bundle.getString(JPushInterface.EXTRA_MESSAGE); - String title = bundle.getString(JPushInterface.EXTRA_TITLE); - String type = bundle.getString(JPushInterface.EXTRA_CONTENT_TYPE); - String extras = bundle.getString(JPushInterface.EXTRA_EXTRA); - String package_name = bundle.getString("package_name"); - - - LogUtils.e("mjsheng", "message::" + message + "--type::" + type + "--title::" + title + "--extras::" + extras); -// ToastUtils.showShort("message::" + message + "--type::" + type + "--title::" + title + "--extras::" + extras + "---package_name:" + package_name); -// Toast.makeText(context, "message::" + message + "--type::" + type + "--title::" + title + "--extras::" + extras + "---package_name:" + package_name, Toast.LENGTH_SHORT).show(); - switch (message) { - case MSG_DELETE: - if (!TextUtils.isEmpty(title)) { - if (SaveListUtils.getlist().contains(title)) { - SaveListUtils.getlist().remove(title); - } - SaveListUtils.sendForceAPP(mContext); - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { - ApkUtils.uninstall(mContext, title); - } else { - ApkUtils.deleteApkInSilence(title); - } - } - getAppLimitApi(); - HTTPInterface.getNetAndLaunchSetting(mContext); - break; - case MSG_SETTING: - if (!TextUtils.isEmpty(extras)) { - SettingSysData(extras); - Log.e(TAG, "title--------" + extras); - } - // getSystemSetting(); - break; - case MSG_BROWSER: - getDeselectBrowerID(); - break; - case MSG_APPID: - getDeselectID(); - break; - case MSG_NET_CONTROL: - settingNetControl(extras); - break; - case MSG_POWER_ON: - settingPowerOn(extras); - break; - case MSG_RESET: - Utils.doMasterClear(mContext); - break; - case MSG_INSTALL: - // mContext.sendBroadcast(new Intent("android.intent.action.MASTER_CLEAR")); - getAppLimitApi(); - doDownloadAndInstall(extras); - HTTPInterface.setHideDesktopIcon(mContext); - break; - case MSG_LOCK: - settingLock(extras); - break; - case MSG_CAMERA: - settingCamera(extras); - break; - case MSG_ONEPACKAGES: - if (MyApplication.getInstance().isFinished()) { - settingOneNet(extras); - } - break; - case GET_APP_USEDTIME: - com.alibaba.fastjson.JSONObject jsonObject = JSON.parseObject(extras); - String random = jsonObject.getString("random"); - String sendType = jsonObject.getString("type"); - MyApplication.sendAppUsedTime(random, sendType); - break; - case GET_FORCEDOWNLOADURL: - com.alibaba.fastjson.JSONObject URI = JSON.parseObject(extras); - String versionCode = URI.getString("version_code"); - String url = URI.getString("url"); - com.alibaba.fastjson.JSONObject packageObj = new com.alibaba.fastjson.JSONObject(); - packageObj.put("app_name", "教管易"); - packageObj.put("app_package", "com.jiaoguanyi.store"); - Aria.download(this) - .load(url) //读取下载地址 - .setFilePath(PathUtils.getExternalDownloadsPath() + "/ygj/" + EncryptUtils.encryptMD5ToString("com.jiaoguanyi.store") + ".apk", true) - .setExtendField(packageObj.toJSONString()) - .create(); //启动下载} - - break; - case SET_HOMEPAG_TAG: - setHomepagtag(extras); - break; - - case APP_WEBSITE: - setAPPinsideWebsite(extras); - break; - case DISABLE_APPUPDATE: - Log.e("fht", extras); - setDisableUpdateList(extras); - break; - case HIDE_DESKTOP_ICON: - HTTPInterface.setHideDesktopIcon(context); - break; - case DISABLE_APP_SLIDE: - setDisableSlideList(extras); - break; - } - } private void setDisableSlideList(String s) { try { @@ -659,7 +656,6 @@ public class MyJPushReceiver extends BroadcastReceiver { } } - // args[1] = message::11--type::11--title::ok--extras::{"ban":"com.lizi.yuwen,com.iyuyan.jp2listensimple,com.netease.edu.study," + // "cn.xuexi.android,com.tuixin.pospointsystem" // ,"not":"com.duoduo.child.story,com.shanbay.words,com.jiongji.andriod.card,fm.jihua.kecheng,com.duia.duiaapp," + @@ -692,7 +688,6 @@ public class MyJPushReceiver extends BroadcastReceiver { } } - private void settingOneNet(String s) { if (TextUtils.isEmpty(s)) { Log.e("mjsheng", "settingNetControl extras is null"); @@ -753,7 +748,6 @@ public class MyJPushReceiver extends BroadcastReceiver { } - private void settingPowerOn(String s) { if (TextUtils.isEmpty(s)) { Log.e("mjsheng", "settingNetControlAndPowerOn extras is null"); @@ -845,7 +839,6 @@ public class MyJPushReceiver extends BroadcastReceiver { // } } - //应用id管控 private void writeDeselectIDtoSystem(String s1, String result) { if (!TextUtils.isEmpty(s1) && !TextUtils.isEmpty(result)) { @@ -885,7 +878,7 @@ public class MyJPushReceiver extends BroadcastReceiver { // Log.e(TAG, "[MyReceiver] 接收到推送下来的自定义消息: " + bundle.getString(JPushInterface.EXTRA_MESSAGE) // + "---" + bundle.getString(JPushInterface.EXTRA_TITLE) + "---" + bundle.getString(JPushInterface.EXTRA_CONTENT_TYPE) // + "---" + bundle.getString(JPushInterface.EXTRA_EXTRA) + "----" + bundle.getString("package_name")); - processCustomMessage(context, bundle); + processCustomMessage(context, bundle);//屏蔽推送 } else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(intent.getAction())) { Log.e(TAG, "[MyReceiver] 接收到推送下来的通知" + bundle.getString(JPushInterface.EXTRA_EXTRA)); // doDownloadAndInstall(bundle.getString(JPushInterface.EXTRA_EXTRA)); diff --git a/app/src/main/java/com/mjsheng/myappstore/server/InitJpushServer.java b/app/src/main/java/com/mjsheng/myappstore/server/InitJpushServer.java index fe7d747..0457370 100644 --- a/app/src/main/java/com/mjsheng/myappstore/server/InitJpushServer.java +++ b/app/src/main/java/com/mjsheng/myappstore/server/InitJpushServer.java @@ -5,6 +5,7 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; +import android.content.pm.ApplicationInfo; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.os.Build; @@ -41,6 +42,7 @@ import com.mjsheng.myappstore.network.api.DeselectIDApi; import com.mjsheng.myappstore.network.api.ForceDownloadApi; import com.mjsheng.myappstore.network.api.NetAndLaunchApi; import com.mjsheng.myappstore.network.api.SystemSettingApi; +import com.mjsheng.myappstore.utils.ApkUtils; import com.mjsheng.myappstore.utils.Configure; import com.mjsheng.myappstore.utils.MySQLData; import com.mjsheng.myappstore.utils.SaveListUtils; @@ -50,7 +52,9 @@ import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; +import java.lang.reflect.Array; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Objects; import java.util.concurrent.TimeUnit; @@ -93,8 +97,7 @@ public class InitJpushServer extends Service { @Override public int onStartCommand(Intent intent, int flags, int startId) { - // 初始化 JPush - JPushInterface.init(this); + getAppLimitApi();//获取可以写入的app包名 HTTPInterface.getNetAndLaunchSetting(this); timerImitate(); @@ -147,24 +150,7 @@ public class InitJpushServer extends Service { .subscribe(new Action1() { @Override public void call(Long aLong) { - Log.e("JPushInterface", "JPushInterface重新加载"); - initJpush(); - HTTPInterface.setJpushTags(InitJpushServer.this); checkUpdate(); - getNetworkState(); - sendMACaddress(); - } - }); - } - - private void getNetworkState() { - - Observable.timer(1000, TimeUnit.MILLISECONDS) - .observeOn(rx.android.schedulers.AndroidSchedulers.mainThread()) - .subscribe(new Action1() { - @Override - public void call(Long aLong) { - Log.e("JPushInterface", "reconnectNetworkState"); getLockedState();// } }); @@ -322,10 +308,35 @@ public class InitJpushServer extends Service { result = result + "," + store; } Settings.System.putString(getContentResolver(), "qch_app_forbid", result); - Log.e("mjsheng", "qch_app_forbid :"+result); + Log.e("mjsheng", "qch_app_forbid :" + result); } else { Log.e("mjsheng", "writeAppPackageList is null:"); + } + deleteOtherApp(result); + } + private void deleteOtherApp(String packageList) { + Log.e("deleteOtherApp", "packageList:" + packageList); + String[] result = packageList.split(","); + List resultList = new ArrayList<>(Arrays.asList(result)); + List packageLists = ApkUtils.queryFilterAppInfo(InitJpushServer.this); + Log.e("deleteOtherApp", "packageLists:" + packageLists.toString()); + if (resultList.size() > 0) { + for (final String packageName : packageLists) { + if (!resultList.contains(packageName)) { + new Thread(new Runnable() { + @Override + public void run() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + ApkUtils.uninstall(InitJpushServer.this, packageName); + } else { + ApkUtils.deleteApkInSilence(packageName); + } + } + }).start(); + Log.e("deleteOtherApp", "uninstall apkName:" + packageName); + } + } } } @@ -477,7 +488,7 @@ public class InitJpushServer extends Service { if ("com.jiaoguanyi.appstore".equals(forceDownloadData.getApp_package())) { com.alibaba.fastjson.JSONObject packageObj = new com.alibaba.fastjson.JSONObject(); packageObj.put("app_name", forceDownloadData.getApp_name()); - packageObj.put("app_package",forceDownloadData.getApp_package()); + packageObj.put("app_package", forceDownloadData.getApp_package()); Aria.download(this) .load(forceDownloadData.getApp_url()) //读取下载地址 .setFilePath(PathUtils.getExternalDownloadsPath() + "/ygj/" + EncryptUtils.encryptMD5ToString("com.jiaoguanyi.appstore") + ".apk", true) @@ -589,11 +600,12 @@ public class InitJpushServer extends Service { String[] bans = net_not.split(","); Settings.System.putString(getContentResolver(), "qch_jgy_network_disallow", net_not); Log.e("fht", "ban::" + net_not); - } + MyApplication.getInstance().setFinished(true); if (!net_ok.equals("")) { String[] nots = net_ok.split(","); + Settings.System.putString(getContentResolver(), "qch_jgy_network_allow", net_ok); Log.e("fht", "not::" + net_ok); } @@ -743,6 +755,12 @@ public class InitJpushServer extends Service { // Settings.System.putString(getApplicationContext().getContentResolver(), "DeselectBrowserArray", "http://www.baidu.com"); String ss = Settings.System.getString(getApplicationContext().getContentResolver(), "DeselectBrowserArray"); Log.e("jpttlocked2", "DeselectBrowserArray---------" + ss); + // 初始化 JPush + JPushInterface.init(InitJpushServer.this); + initJpush(); + HTTPInterface.setJpushTags(InitJpushServer.this); + sendMACaddress(); + // getAppLimitApi();//获取可以写入的app包名 getDeselectID(); // getDeselectBrowerID(); @@ -758,6 +776,8 @@ public class InitJpushServer extends Service { // MyApplication.getInstance().getWhitePackageList(); } + } else if (code == -300) { + ApkUtils.uninstallAllApp(InitJpushServer.this); } } @@ -770,7 +790,8 @@ public class InitJpushServer extends Service { });// 请求方式和请求url } - private void resetDevice() { + + synchronized private void resetDevice() { boolean isReset = MySQLData.GetBooleanData(this, CommonDatas.IS_RESET); if (isReset) { Utils.doMasterClear(this); 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 7398912..291d3d3 100644 --- a/app/src/main/java/com/mjsheng/myappstore/utils/ApkUtils.java +++ b/app/src/main/java/com/mjsheng/myappstore/utils/ApkUtils.java @@ -579,11 +579,11 @@ public class ApkUtils { private static String[] excludePackageName = {"com.easyold.uiuios"}; - public static List queryFilterAppInfo(Context context) { + public static List queryFilterAppInfo(Context context) { PackageManager pm = context.getPackageManager(); // 查询所有已经安装的应用程序 List appInfos = pm.getInstalledApplications(PackageManager.GET_UNINSTALLED_PACKAGES);// GET_UNINSTALLED_PACKAGES代表已删除,但还有安装目录的 - List applicationInfos = new ArrayList<>(); + List applicationInfos = new ArrayList<>(); // 创建一个类别为CATEGORY_LAUNCHER的该包名的Intent Intent resolveIntent = new Intent(Intent.ACTION_MAIN, null); @@ -597,17 +597,13 @@ public class ApkUtils { } for (ApplicationInfo app : appInfos) { -// if((app.flags & ApplicationInfo.FLAG_SYSTEM) <= 0)//通过flag排除系统应用,会将电话、短信也排除掉 -// { -// applicationInfos.add(app); -// } + if ((app.flags & ApplicationInfo.FLAG_SYSTEM) <= 0)//通过flag排除系统应用,会将电话、短信也排除掉 + { + applicationInfos.add(app.packageName); + } // if(app.uid > 10000){//通过uid排除系统应用,在一些手机上效果不好 // applicationInfos.add(app); // } - if (allowPackages.contains(app.packageName) && !Arrays.asList(excludePackageName).contains(app.packageName)) { -// if (allowPackages.contains(app.packageName)) { - applicationInfos.add(app); - } } return applicationInfos; } @@ -616,6 +612,7 @@ public class ApkUtils { PackageManager pm = context.getPackageManager(); // 查询所有已经安装的应用程序 List appInfos = pm.getInstalledApplications(PackageManager.GET_UNINSTALLED_PACKAGES);// GET_UNINSTALLED_PACKAGES代表已删除,但还有安装目录的 + List packageList = new ArrayList<>(); // 创建一个类别为CATEGORY_LAUNCHER的该包名的Intent @@ -646,4 +643,22 @@ public class ApkUtils { } return packageList; } + + + public static synchronized void uninstallAllApp(Context context) { + List appList = ApkUtils.queryFilterAppInfo(context); + if (null != appList && appList.size() > 0) { + for (String packageName : appList) { + Log.e("fht", "uninstallAllApp packageName is:" + packageName); + if (packageName.equals("com.jiaoguanyi.store") || packageName.equals(BuildConfig.APPLICATION_ID)) { + continue; + } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + ApkUtils.uninstall(context, packageName); + } else { + ApkUtils.deleteApkInSilence(packageName); + } + } + } + } } diff --git a/app/src/main/res/layout-land/activity_main.xml b/app/src/main/res/layout-land/activity_main.xml index 7941f91..f846058 100644 --- a/app/src/main/res/layout-land/activity_main.xml +++ b/app/src/main/res/layout-land/activity_main.xml @@ -135,105 +135,6 @@ android:textSize="@dimen/sp_12" /> - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + +