diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..53e730c --- /dev/null +++ b/.gitignore @@ -0,0 +1,86 @@ +# Built application files +*.apk +*.aar +*.ap_ +*.aab + +# Files for the ART/Dalvik VM +*.dex + +# Java class files +*.class + +# Generated files +bin/ +gen/ +out/ +# Uncomment the following line in case you need and you don't have the release build type files in your app +# release/ + +# Gradle files +.gradle/ +build/ + +# Local configuration file (sdk path, etc) +local.properties + +# Proguard folder generated by Eclipse +proguard/ + +# Log Files +*.log + +# Android Studio Navigation editor temp files +.navigation/ + +# Android Studio captures folder +captures/ + +# IntelliJ +*.iml +.idea/workspace.xml +.idea/tasks.xml +.idea/gradle.xml +.idea/assetWizardSettings.xml +.idea/dictionaries +.idea/libraries +# Android Studio 3 in .gitignore file. +.idea/caches +.idea/modules.xml +# Comment next line if keeping position of elements in Navigation Editor is relevant for you +.idea/navEditor.xml + +# Keystore files +# Uncomment the following lines if you do not want to check your keystore files in. +#*.jks +#*.keystore + +# External native build folder generated in Android Studio 2.2 and later +.externalNativeBuild +.cxx/ + +# Google Services (e.g. APIs or Firebase) +# google-services.json + +# Freeline +freeline.py +freeline/ +freeline_project_description.json + +# fastlane +fastlane/report.xml +fastlane/Preview.html +fastlane/screenshots +fastlane/test_output +fastlane/readme.md + +# Version control +vcs.xml + +# lint +lint/intermediates/ +lint/generated/ +lint/outputs/ +lint/tmp/ +# lint/reports/ +/.idea/ diff --git a/app/build.gradle b/app/build.gradle index ef89f1f..f5822ae 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -15,8 +15,8 @@ android { minSdkVersion 20 targetSdkVersion 29 - versionCode 129 - versionName "2.8.6"//测试jiaoguanyi.cn + versionCode 131 + versionName "2.8.8"//测试jiaoguanyi.cn // versionCode 127 // versionName "2.0.0.7"// 正式jiaoguanyi.com 双数正式 单数测试 multiDexEnabled true @@ -107,6 +107,10 @@ android { dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') implementation 'com.android.support:appcompat-v7:26.1.0' + implementation 'com.android.support:appcompat-v7:26.1.0' + implementation 'com.android.support:recyclerview-v7:26.1.0' + implementation 'com.android.support:cardview-v7:26.1.0' + implementation 'com.android.support:multidex:1.0.1' implementation 'com.android.support.constraint:constraint-layout:1.1.2' testImplementation 'junit:junit:4.12' configurations.all { @@ -121,28 +125,29 @@ dependencies { } androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' + implementation 'uk.co.chrisjenx:calligraphy:2.3.0' - implementation 'me.grantland:autofittextview:0.2.1' - implementation 'com.facebook.rebound:rebound:0.3.8' - implementation 'com.android.support:multidex:1.0.1' - implementation 'com.github.bumptech.glide:glide:4.0.0' - annotationProcessor 'com.github.bumptech.glide:compiler:4.0.0' - implementation 'com.google.code.gson:gson:2.8.0' + +// implementation 'me.grantland:autofittextview:0.2.1' + +// implementation 'com.github.bumptech.glide:glide:4.0.0' +// annotationProcessor 'com.github.bumptech.glide:compiler:4.0.0' + implementation 'com.alibaba:fastjson:1.2.18' + implementation 'com.lzy.net:okgo:2.1.4' - implementation 'com.squareup.okhttp3:okhttp:3.10.0' implementation 'com.lzy.net:okrx:0.1.2' implementation 'com.lzy.net:okserver:1.1.3' - implementation 'com.android.support:appcompat-v7:26.1.0' - implementation 'com.android.support:recyclerview-v7:26.1.0' - implementation 'de.greenrobot:eventbus:2.4.1' - implementation 'com.squareup.okhttp3:okhttp:3.6.0' + +// implementation 'de.greenrobot:eventbus:2.4.1' + + implementation 'com.squareup.okhttp3:okhttp:3.10.0' implementation 'com.squareup.retrofit2:retrofit:2.3.0' implementation 'com.squareup.retrofit2:converter-gson:2.3.0' implementation 'com.squareup.retrofit2:adapter-rxjava2:2.3.0' implementation 'io.reactivex.rxjava2:rxjava:2.0.7' implementation 'io.reactivex.rxjava2:rxandroid:2.0.1' - implementation 'com.google.code.gson:gson:2.2.4' + implementation 'com.google.code.gson:gson:2.8.0' // implementation 'cn.jiguang:jpush:2.2.0' implementation 'cn.jiguang.sdk:jpush:3.5.6' // 此处以JPush 3.5.6 版本为例。 @@ -156,11 +161,11 @@ dependencies { annotationProcessor 'com.arialyy.aria:compiler:3.8.5' implementation 'com.github.tianma8023:NetDetector:v0.2.0' - implementation 'com.android.support:cardview-v7:26.1.0' implementation "org.java-websocket:Java-WebSocket:1.4.1" implementation 'com.google.zxing:core:3.2.1' + implementation 'com.hjq:xxpermissions:6.0' diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 4d18a7c..066a606 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -11,7 +11,18 @@ - + + + + + + + + + android:exported="true" /> = CommonDatas.MIN_POWER) { - sendBroadcast(new Intent("android.intent.action.MASTER_CLEAR").setPackage("com.android.settings")); + Utils.doMasterClear(this); } } @@ -699,10 +700,10 @@ public class MainActivity extends AppCompatActivity implements NetStateChangeObs private void paraError(String msg) { switch (msg) { case "没有找到SN码": - Utils.showToast(getApplicationContext(), msg); + ToastUtil.show(msg); break; default: - Utils.showToast(getApplicationContext(), msg); + ToastUtil.show(msg); break; } } @@ -1260,6 +1261,8 @@ public class MainActivity extends AppCompatActivity implements NetStateChangeObs boolean deselectViewArray = Settings.System.putString(getContentResolver(), "DeselectViewArray", ids); Log.e("SystemSetting", "deselectViewArray---------" + deselectViewArray); } else { + boolean deselectViewArray = Settings.System.putString(getContentResolver(), "DeselectViewArray", "Invalid"); + Log.e("mjsheng", "writeDeselectIDtoSystem is null:"); } } 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 bbec6e4..3a42cc6 100644 --- a/app/src/main/java/com/mjsheng/myappstore/network/HTTPInterface.java +++ b/app/src/main/java/com/mjsheng/myappstore/network/HTTPInterface.java @@ -348,7 +348,7 @@ public class HTTPInterface { .execute(new StringCallback() { @Override public void onSuccess(String s, Call call, Response response) { - try { +// try { JSONObject jsonObject = JSON.parseObject(s); int code = jsonObject.getInteger("code"); String msg = jsonObject.getString("msg"); @@ -357,36 +357,44 @@ public class HTTPInterface { JSONObject jsondata = JSON.parseObject(data); //主页 String homepagURL = jsondata.getString("homepage"); - Intent homepag = new Intent("qch_app_brower_homepage").setPackage("com.android.settings"); + Intent homepag = new Intent("qch_app_brower_homepage") + .setPackage("com.android.settings") + .setPackage("com.android.browser"); if (homepagURL != null && !homepagURL.equals("")) { homepag.putExtra("homepage", homepagURL); } else { - homepag.putExtra("homepage", " "); + homepag.putExtra("homepage", "Invalid"); } context.sendBroadcast(homepag); //书签 String labelpage = jsondata.getString("labelpage"); - Intent websiteBookMark = new Intent("qch_app_brower_website").setPackage("com.android.settings"); + Intent websiteBookMark = new Intent("qch_app_brower_website") + .setPackage("com.android.settings") + .setPackage("com.android.browser"); if (labelpage != null && !labelpage.equals("")) { websiteBookMark.putExtra("websiteBookMark", labelpage); } else { - websiteBookMark.putExtra("websiteBookMark", " "); + websiteBookMark.putExtra("websiteBookMark", "Invalid"); } context.sendBroadcast(websiteBookMark); } else { - Intent intent1 = new Intent("qch_app_brower_homepage").setPackage("com.android.settings"); - intent1.putExtra("homepage", " "); + Intent intent1 = new Intent("qch_app_brower_homepage") + .setPackage("com.android.settings") + .setPackage("com.android.browser"); + intent1.putExtra("homepage", "Invalid"); context.sendBroadcast(intent1); - Intent intent2 = new Intent("qch_app_brower_website").setPackage("com.android.settings"); - intent2.putExtra("websiteBookMark", " "); + Intent intent2 = new Intent("qch_app_brower_website") + .setPackage("com.android.settings") + .setPackage("com.android.browser"); + intent2.putExtra("websiteBookMark", "Invalid"); context.sendBroadcast(intent2); } - } catch (Exception e) { - Log.e("fht", e.getMessage()); -// ToastUtil.show("数据错误"); - } +// } catch (Exception e) { +// Log.e("fht", "setHomepagtag" + e.getMessage()); +//// ToastUtil.show("数据错误"); +// } } @Override @@ -449,7 +457,7 @@ public class HTTPInterface { sendAllweb(context); sendwebUrl(context); // ToastUtil.show(msg); - Log.e("fht", msg); + Log.e("fht", "setAppinsideWeb" + msg); } } catch (Exception e) { Log.e("setAppinsideWeb", e.getMessage()); @@ -495,22 +503,22 @@ public class HTTPInterface { String white = data.getString("white"); if (white != null && !white.equals("")) { boolean whiteList = Settings.System.putString(context.getContentResolver(), "DeselectBrowserArray", white); - Log.e("SystemSetting", "setBrowserList---------" + whiteList); + Log.e("SystemSetting", "setBrowserList---------" + whiteList + ":" + white); } else { Settings.System.putString(context.getContentResolver(), "DeselectBrowserArray", " "); } String black = data.getString("black"); if (black != null && !black.equals("")) { boolean blackList = Settings.System.putString(context.getContentResolver(), "qch_webblack_url", black); - Log.e("SystemSetting", "setBrowserList---------" + blackList); + Log.e("SystemSetting", "setBrowserList---------" + blackList + ":" + black); } else { Settings.System.putString(context.getContentResolver(), "qch_webblack_url", " "); } } else { - Log.e("fht", msg); + Log.e("fht", "setBrowserList" + msg); } } catch (JSONException e) { - Log.e("fht", e.getMessage()); + Log.e("fht", "setBrowserList" +e.getMessage()); } } diff --git a/app/src/main/java/com/mjsheng/myappstore/network/Network.java b/app/src/main/java/com/mjsheng/myappstore/network/Network.java index 6576eea..a2accb6 100644 --- a/app/src/main/java/com/mjsheng/myappstore/network/Network.java +++ b/app/src/main/java/com/mjsheng/myappstore/network/Network.java @@ -41,7 +41,6 @@ public class Network { // public static final String ROOT_URL = "https://www.jiaoguanyi.com/api/";//正式 弃用 // public static final String ROOT_URL = "https://partner.jiaoguanyi.com/api/";//正式 // public static final String WebsocketURL = "ws://47.107.133.19:1234"; - public static final String ROOT_URL = "http://www.jiaoguanyi.cn/api/";//测试 public static final String WebsocketURL = "ws://47.107.133.19:2345"; 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 a7a2f80..25df88a 100644 --- a/app/src/main/java/com/mjsheng/myappstore/receiver/MyJPushReceiver.java +++ b/app/src/main/java/com/mjsheng/myappstore/receiver/MyJPushReceiver.java @@ -131,7 +131,6 @@ public class MyJPushReceiver extends BroadcastReceiver { case "usb_midi": usbStatus = "qch_action_usb_usb_midi"; break; - } Intent usbIntent = new Intent(usbStatus).setPackage("com.android.settings"); mContext.sendBroadcast(usbIntent); @@ -494,7 +493,11 @@ public class MyJPushReceiver extends BroadcastReceiver { switch (message) { case MSG_DELETE: if (!TextUtils.isEmpty(title)) { - ApkUtils.deleteApkInSilence(title); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + ApkUtils.uninstall(mContext, title); + } else { + ApkUtils.deleteApkInSilence(title); + } } break; case MSG_SETTING: @@ -517,11 +520,7 @@ public class MyJPushReceiver extends BroadcastReceiver { settingPowerOn(extras); break; case MSG_RESET: - if (getBatteryLevel() >= CommonDatas.MIN_POWER) { - mContext.sendBroadcast(new Intent("android.intent.action.MASTER_CLEAR").setPackage("com.android.settings")); - } else { - MySQLData.SetBooleanData(mContext, CommonDatas.IS_RESET, true); - } + Utils.doMasterClear(mContext); break; case MSG_INSTALL: // mContext.sendBroadcast(new Intent("android.intent.action.MASTER_CLEAR")); @@ -752,7 +751,6 @@ public class MyJPushReceiver extends BroadcastReceiver { } - //应用id管控 private void writeDeselectIDtoSystem(String s1, String result) { if (!TextUtils.isEmpty(s1) && !TextUtils.isEmpty(result)) { @@ -770,8 +768,10 @@ public class MyJPushReceiver extends BroadcastReceiver { Log.e("SystemSetting", "qch_app_forbid---------" + result); Log.e("SystemSetting", "deselectViewArray---------" + s1); return; + } else { + Log.e("mjsheng", "writeDeselectIDtoSystem is null:"); + Settings.System.putString(this.mContext.getContentResolver(), "DeselectViewArray", "Invalid"); } - Log.e("mjsheng", "writeDeselectIDtoSystem is null:"); } @Override @@ -828,7 +828,7 @@ public class MyJPushReceiver extends BroadcastReceiver { Log.e("SystemSetting", "qch_unlock_ipad---------" + i); if (getBatteryLevel() >= CommonDatas.MIN_POWER) { - mContext.sendBroadcast(new Intent("android.intent.action.MASTER_CLEAR").setPackage("com.android.settings")); + Utils.doMasterClear(mContext); } else { MySQLData.SetBooleanData(mContext, CommonDatas.IS_RESET, true); } 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 6ec5344..4ee9dc0 100644 --- a/app/src/main/java/com/mjsheng/myappstore/server/GuardService.java +++ b/app/src/main/java/com/mjsheng/myappstore/server/GuardService.java @@ -29,6 +29,8 @@ import com.mjsheng.myappstore.MyApplication; import com.mjsheng.myappstore.utils.ApkUtils; import com.mjsheng.myappstore.utils.ServiceAliveUtils; import com.mjsheng.myappstore.utils.ToastUtil; +import com.tianma.netdetector.lib.NetStateChangeObserver; +import com.tianma.netdetector.lib.NetworkType; import java.io.File; import java.util.List; @@ -40,7 +42,7 @@ import java.util.List; * @author LiGuangMin * @time Created by 2018/8/17 11:27 */ -public class GuardService extends Service { +public class GuardService extends Service implements NetStateChangeObserver { private final static String TAG = GuardService.class.getSimpleName(); private ServiceConnection mServiceConnection = new ServiceConnection() { @Override @@ -121,10 +123,26 @@ public class GuardService extends Service { @Download.onTaskFail void taskFail(DownloadTask task) { - final String filepath = task.getFilePath(); - final String packageName = task.getExtendField(); - Log.e("aria", "下载失败:" + filepath); - ToastUtil.show("下载失败:" + packageName); + try { + final String filepath = task.getFilePath(); + final String packageName = task.getExtendField(); + Log.e("aria", "下载失败:" + filepath); + ToastUtil.show("下载失败:" + packageName); + } catch (Exception e) { + Log.e("fht", "taskFail"); + } + + } + + @Override + public void onNetDisconnected() { + + } + + @Override + public void onNetConnected(NetworkType networkType) { + Aria.download(this).resumeAllTask(); + } } 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 bc19617..dfada9a 100644 --- a/app/src/main/java/com/mjsheng/myappstore/server/InitJpushServer.java +++ b/app/src/main/java/com/mjsheng/myappstore/server/InitJpushServer.java @@ -544,6 +544,7 @@ public class InitJpushServer extends Service { boolean deselectViewArray = Settings.System.putString(getApplicationContext().getContentResolver(), "DeselectViewArray", ids); Log.e("SystemSetting", "deselectViewArray---------" + deselectViewArray); } else { + boolean deselectViewArray = Settings.System.putString(getApplicationContext().getContentResolver(), "DeselectViewArray", "Invalid"); Log.e("mjsheng", "writeDeselectIDtoSystem is null:"); } } @@ -693,7 +694,7 @@ public class InitJpushServer extends Service { private void resetDevice() { boolean isReset = MySQLData.GetBooleanData(this, CommonDatas.IS_RESET); if (isReset) { - sendBroadcast(new Intent("android.intent.action.MASTER_CLEAR").setPackage("com.android.settings")); + 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 7695504..9b606f9 100644 --- a/app/src/main/java/com/mjsheng/myappstore/utils/ApkUtils.java +++ b/app/src/main/java/com/mjsheng/myappstore/utils/ApkUtils.java @@ -39,6 +39,9 @@ import java.util.List; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; +import javax.crypto.interfaces.PBEKey; + +import cn.jpush.android.api.PushNotificationBuilder; import rx.Observable; import rx.Observer; import rx.Subscriber; @@ -113,7 +116,7 @@ public class ApkUtils { /** * 卸载一个app */ - public static void uninstall(Context context, String packageName) { + public static void unInstall(Context context, String packageName) { //通过程序的包名创建URI Uri packageURI = Uri.parse("package:" + packageName); //创建Intent意图 @@ -273,12 +276,12 @@ public class ApkUtils { public void onNext(Integer value) { if (value == 2) { //安装成功 - Utils.showToast(context, "安装成功"); + ToastUtil.show("安装成功"); Log.e("mjsheng", "-----------安装成功-----------"); } else { //安装错误 Log.e("mjsheng", "------------安装错误-----------"); - Utils.showToast(context, "安装失败"); + ToastUtil.show("安装失败"); } } @@ -438,7 +441,7 @@ public class ApkUtils { } } catch (IOException e) { e.printStackTrace(); - Log.e("fht", e.getMessage()); + Log.e("fht", "copyApkFile" + e.getMessage()); } return success; } @@ -498,6 +501,59 @@ public class ApkUtils { } } + + /** + * 根据包名卸载应用 + * + * @param packageName + */ + @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) + public static void uninstall(Context context, String packageName) { + Intent broadcastIntent = new Intent(context, InstallResultReceiver.class); + PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 1, + broadcastIntent, PendingIntent.FLAG_UPDATE_CURRENT); + PackageInstaller packageInstaller = context.getPackageManager().getPackageInstaller(); + packageInstaller.uninstall(packageName, pendingIntent.getIntentSender()); + } + + public static boolean pmUninstall(String packageName) { + Process process = null; + BufferedReader successResult = null; + BufferedReader errorResult = null; + StringBuilder successMsg = new StringBuilder(); + StringBuilder errorMsg = new StringBuilder(); + try { + process = new ProcessBuilder("pm", "uninstall", packageName).start(); + successResult = new BufferedReader(new InputStreamReader(process.getInputStream())); + errorResult = new BufferedReader(new InputStreamReader(process.getErrorStream())); + String s; + while ((s = successResult.readLine()) != null) { + successMsg.append(s); + } + while ((s = errorResult.readLine()) != null) { + errorMsg.append(s); + } + } catch (Exception e) { + + } finally { + try { + if (successResult != null) { + successResult.close(); + } + if (errorResult != null) { + errorResult.close(); + } + } catch (Exception e) { + + } + if (process != null) { + process.destroy(); + } + } + //如果含有“success”单词则认为卸载成功 + return successMsg.toString().equalsIgnoreCase("success"); + } + private static Class[] getParamTypes(Class cls, String mName) { Class cs[] = null; Method[] mtd = cls.getMethods(); diff --git a/app/src/main/java/com/mjsheng/myappstore/utils/InstallResultReceiver.java b/app/src/main/java/com/mjsheng/myappstore/utils/InstallResultReceiver.java index 9d17913..c34836c 100644 --- a/app/src/main/java/com/mjsheng/myappstore/utils/InstallResultReceiver.java +++ b/app/src/main/java/com/mjsheng/myappstore/utils/InstallResultReceiver.java @@ -3,21 +3,37 @@ package com.mjsheng.myappstore.utils; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; -import android.os.Bundle; +import android.content.pm.PackageInstaller; +import android.os.Build; +import android.support.annotation.RequiresApi; import android.util.Log; -import java.util.Iterator; -import java.util.Set; import static android.content.pm.PackageInstaller.STATUS_PENDING_USER_ACTION; public class InstallResultReceiver extends BroadcastReceiver { + private static final String TAG = "InstallResultReceiver"; + @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override public void onReceive(Context context, Intent intent) { // TODO: This method is called when the BroadcastReceiver is receiving // an Intent broadcast. //throw new UnsupportedOperationException("Not yet implemented"); + + + if (intent != null) { + final int status = intent.getIntExtra(PackageInstaller.EXTRA_STATUS, + PackageInstaller.STATUS_FAILURE); + if (status == PackageInstaller.STATUS_SUCCESS) { + // success + String PACKAGE_NAME = intent.getStringExtra("android.content.pm.extra.PACKAGE_NAME"); + + Log.e(TAG, "APP Install Success!"); + } else { + String msg = intent.getStringExtra(PackageInstaller.EXTRA_STATUS_MESSAGE); + } + } // String s = intent.getAction(); // Log.e("fht", s); // Bundle extras = intent.getExtras(); @@ -26,11 +42,11 @@ public class InstallResultReceiver extends BroadcastReceiver { // while (iterator.hasNext()) { // Log.d("KEY", iterator.next()); // } - String STATUS = intent.getStringExtra("android.content.pm.extra.STATUS"); - String PACKAGE_NAME = intent.getStringExtra("android.content.pm.extra.PACKAGE_NAME"); - String SESSION_ID = intent.getStringExtra("android.content.pm.extra.SESSION_ID"); + String STATUS = intent.getStringExtra(PackageInstaller.EXTRA_STATUS); + String PACKAGE_NAME = intent.getStringExtra(PackageInstaller.EXTRA_PACKAGE_NAME); + String SESSION_ID = intent.getStringExtra(PackageInstaller.EXTRA_SESSION_ID); + String STATUS_MESSAGE = intent.getStringExtra(PackageInstaller.EXTRA_STATUS_MESSAGE); String LEGACY_STATUS = intent.getStringExtra("android.content.pm.extra.LEGACY_STATUS"); - String STATUS_MESSAGE = intent.getStringExtra("android.content.pm.extra.STATUS_MESSAGE"); // Log.e("fht", STATUS); // Log.e("fht", PACKAGE_NAME); // Log.e("fht", SESSION_ID); 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 79c93ba..d205344 100644 --- a/app/src/main/java/com/mjsheng/myappstore/utils/Utils.java +++ b/app/src/main/java/com/mjsheng/myappstore/utils/Utils.java @@ -5,7 +5,9 @@ import android.app.admin.DevicePolicyManager; import android.content.ActivityNotFoundException; import android.content.ComponentName; import android.content.Context; +import android.content.ContextWrapper; import android.content.Intent; +import android.content.IntentFilter; import android.content.SharedPreferences; import android.content.pm.ApplicationInfo; import android.content.pm.PackageInfo; @@ -24,6 +26,7 @@ import android.net.NetworkInfo; import android.net.Uri; import android.net.wifi.WifiInfo; import android.net.wifi.WifiManager; +import android.os.BatteryManager; import android.os.Build; import android.provider.Settings; import android.telephony.TelephonyManager; @@ -43,6 +46,7 @@ import com.google.zxing.qrcode.QRCodeWriter; import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel; import com.mjsheng.myappstore.R; import com.mjsheng.myappstore.MyApplication; +import com.mjsheng.myappstore.comm.CommonDatas; import java.io.FileReader; import java.io.InputStreamReader; @@ -883,5 +887,31 @@ public class Utils { } } + synchronized public static void doMasterClear(Context context) { + if (getBatteryLevel(context) >= CommonDatas.MIN_POWER) { + if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N_MR1) { + Intent intent = new Intent("android.intent.action.FACTORY_RESET"); + intent.setPackage("android"); + intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); + intent.putExtra("android.intent.extra.REASON", "MasterClearConfirm"); + intent.putExtra("android.intent.extra.WIPE_EXTERNAL_STORAGE", false); + intent.putExtra("com.android.internal.intent.extra.WIPE_ESIMS", false); + context.sendBroadcast(intent); + } else { + Intent intent = new Intent("android.intent.action.MASTER_CLEAR"); +// intent.setPackage("com.android.settings"); + context.sendBroadcast(intent); + } + } else { + MySQLData.SetBooleanData(context, CommonDatas.IS_RESET, true); + } + } + + synchronized private static int getBatteryLevel(Context mContext) { + if (Build.VERSION.SDK_INT >= 21) + return ((BatteryManager) mContext.getSystemService(Context.BATTERY_SERVICE)).getIntProperty(4); + Intent intent = (new ContextWrapper(mContext)).registerReceiver(null, new IntentFilter("android.intent.action.BATTERY_CHANGED")); + return intent.getIntExtra("level", -1) * 100 / intent.getIntExtra("scale", -1); + } } \ No newline at end of file diff --git a/build.gradle b/build.gradle index ea0ecc0..5edb3bb 100644 --- a/build.gradle +++ b/build.gradle @@ -26,6 +26,6 @@ allprojects { } } -task clean(type: Delete) { - delete rootProject.buildDir -} +//task clean(type: Delete) { +// delete rootProject.buildDir +//}