diff --git a/app/build.gradle b/app/build.gradle index 07d9a69..6c02781 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -191,7 +191,9 @@ android { } dependencies { - implementation fileTree(include: ['*.jar'], dir: 'libs') +// implementation fileTree(include: ['*.jar'], dir: 'libs') + compileOnly files('src/main/libs/classes.jar') + implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'androidx.recyclerview:recyclerview:1.1.0' implementation 'androidx.cardview:cardview:1.0.0' @@ -226,4 +228,27 @@ dependencies { annotationProcessor 'com.arialyy.aria:compiler:3.8.15' implementation 'com.amap.api:location:5.1.0' //高德地图定位 + implementation 'org.zeroturnaround:zt-zip:1.13' + //压缩文件解压 +} + +preBuild { + doLast { + def imlFile = file( project.name + ".iml") + println 'Change ' + project.name + '.iml order' + try { + def parsedXml = (new XmlParser()).parse(imlFile) + def jdkNode = parsedXml.component[1].orderEntry.find { it.'@type' == 'jdk' } + parsedXml.component[1].remove(jdkNode) + def sdkString = "Android API " + android.compileSdkVersion.substring("android-".length()) + " Platform" + println 'what' + sdkString + new Node(parsedXml.component[1], 'orderEntry', ['type': 'jdk', 'jdkName': sdkString, 'jdkType': 'Android SDK']) + groovy.xml.XmlUtil.serialize(parsedXml, new FileOutputStream(imlFile)) + } catch (FileNotFoundException e) { + // nop, iml not found + println "no iml found" + } + } + //https://www.pianshen.com/article/93481144911/ + //使用系统编译后的framework.jar } diff --git a/app/src/main/java/com/jiaoguanyi/appstore/activity/SplashActivity.java b/app/src/main/java/com/jiaoguanyi/appstore/activity/SplashActivity.java index 6e87e0c..c4b7a5a 100644 --- a/app/src/main/java/com/jiaoguanyi/appstore/activity/SplashActivity.java +++ b/app/src/main/java/com/jiaoguanyi/appstore/activity/SplashActivity.java @@ -1,5 +1,6 @@ package com.jiaoguanyi.appstore.activity; +import android.annotation.SuppressLint; import android.app.StatusBarManager; import android.content.Context; import android.content.Intent; @@ -51,8 +52,20 @@ public class SplashActivity extends AppCompatActivity { private void DebugTest() { // Utils.getHardware(this); - hookWebView(); - setWebView(); +// hookWebView(); +// setWebView(); +// hideStatusBar(); + } + + @SuppressLint("NewApi") + private void hideStatusBar() { + StatusBarManager mStatusBarManager = (StatusBarManager) getApplicationContext().getSystemService(Context.STATUS_BAR_SERVICE); + mStatusBarManager.disable(StatusBarManager.DISABLE_HOME);//隐藏home键 + mStatusBarManager.disable(StatusBarManager.DISABLE_BACK);//隐藏返回键 + mStatusBarManager.disable(StatusBarManager.DISABLE_RECENT | StatusBarManager.DISABLE_HOME); + mStatusBarManager.disable(StatusBarManager.DISABLE_BACK | StatusBarManager.DISABLE_RECENT | StatusBarManager.DISABLE_HOME); + mStatusBarManager.disable(StatusBarManager.DISABLE_RECENT);//隐藏recent键 + mStatusBarManager.disable(StatusBarManager.DISABLE_NONE);//显示隐藏的虚拟按键 } private void bootanimotion() { @@ -102,7 +115,8 @@ public class SplashActivity extends AppCompatActivity { } }); } - public static void hookWebView(){ + + public static void hookWebView() { int sdkInt = Build.VERSION.SDK_INT; try { Class factoryClass = Class.forName("android.webkit.WebViewFactory"); @@ -110,7 +124,7 @@ public class SplashActivity extends AppCompatActivity { field.setAccessible(true); Object sProviderInstance = field.get(null); if (sProviderInstance != null) { - Log.i(TAG,"sProviderInstance isn't null"); + Log.i(TAG, "sProviderInstance isn't null"); return; } @@ -120,7 +134,7 @@ public class SplashActivity extends AppCompatActivity { } else if (sdkInt == 22) { getProviderClassMethod = factoryClass.getDeclaredMethod("getFactoryClass"); } else { - Log.i(TAG,"Don't need to Hook WebView"); + Log.i(TAG, "Don't need to Hook WebView"); return; } getProviderClassMethod.setAccessible(true); @@ -128,7 +142,7 @@ public class SplashActivity extends AppCompatActivity { Class delegateClass = Class.forName("android.webkit.WebViewDelegate"); Constructor delegateConstructor = delegateClass.getDeclaredConstructor(); delegateConstructor.setAccessible(true); - if(sdkInt < 26){//低于Android O版本 + if (sdkInt < 26) {//低于Android O版本 Constructor providerConstructor = factoryProviderClass.getConstructor(delegateClass); if (providerConstructor != null) { providerConstructor.setAccessible(true); @@ -137,24 +151,24 @@ public class SplashActivity extends AppCompatActivity { } else { Field chromiumMethodName = factoryClass.getDeclaredField("CHROMIUM_WEBVIEW_FACTORY_METHOD"); chromiumMethodName.setAccessible(true); - String chromiumMethodNameStr = (String)chromiumMethodName.get(null); + String chromiumMethodNameStr = (String) chromiumMethodName.get(null); if (chromiumMethodNameStr == null) { chromiumMethodNameStr = "create"; } Method staticFactory = factoryProviderClass.getMethod(chromiumMethodNameStr, delegateClass); - if (staticFactory!=null){ + if (staticFactory != null) { sProviderInstance = staticFactory.invoke(null, delegateConstructor.newInstance()); } } - if (sProviderInstance != null){ + if (sProviderInstance != null) { field.set("sProviderInstance", sProviderInstance); - Log.i(TAG,"Hook success!"); + Log.i(TAG, "Hook success!"); } else { - Log.i(TAG,"Hook failed!"); + Log.i(TAG, "Hook failed!"); } } catch (Throwable e) { - Log.w(TAG,e); + Log.w(TAG, e); } } diff --git a/app/src/main/java/com/jiaoguanyi/appstore/base/BaseApplication.java b/app/src/main/java/com/jiaoguanyi/appstore/base/BaseApplication.java index b097cc2..6c7103b 100644 --- a/app/src/main/java/com/jiaoguanyi/appstore/base/BaseApplication.java +++ b/app/src/main/java/com/jiaoguanyi/appstore/base/BaseApplication.java @@ -23,6 +23,7 @@ import com.alibaba.fastjson.JSON; import com.amap.api.location.AMapLocationClient; import com.arialyy.aria.core.Aria; import com.arialyy.aria.core.download.DownloadEntity; +import com.jiaoguanyi.appstore.utils.XAPKUtils; import com.lzy.okgo.OkGo; import com.lzy.okgo.cache.CacheEntity; import com.lzy.okgo.cache.CacheMode; @@ -74,7 +75,7 @@ import rx.functions.Action1; */ //public class MyApplication extends MultiDexApplication implements Thread.UncaughtExceptionHandler { -public class BaseApplication extends MultiDexApplication{ +public class BaseApplication extends MultiDexApplication { private final String TAG = BaseApplication.class.getSimpleName(); public static Context context; @@ -106,6 +107,7 @@ public class BaseApplication extends MultiDexApplication{ private void init() { NetInterfaceManager.init(this); JGYUtils.init(this); + XAPKUtils.init(this); Configuration config = getResources().getConfiguration(); int smallestScreenWidthDp = config.smallestScreenWidthDp; Log.e("mjsheng", "smallestScreenWidthDp=" + smallestScreenWidthDp); diff --git a/app/src/main/java/com/jiaoguanyi/appstore/bean/Expansions.java b/app/src/main/java/com/jiaoguanyi/appstore/bean/Expansions.java new file mode 100644 index 0000000..27c66d2 --- /dev/null +++ b/app/src/main/java/com/jiaoguanyi/appstore/bean/Expansions.java @@ -0,0 +1,36 @@ +package com.jiaoguanyi.appstore.bean; + +import java.io.Serializable; + +public class Expansions implements Serializable { + private String file; + //包内文件地址 + private String install_location; + //安装位置 + private String install_path; + //安装地址 + + public String getFile() { + return file; + } + + public void setFile(String file) { + this.file = file; + } + + public String getInstall_location() { + return install_location; + } + + public void setInstall_location(String install_location) { + this.install_location = install_location; + } + + public String getInstall_path() { + return install_path; + } + + public void setInstall_path(String install_path) { + this.install_path = install_path; + } +} diff --git a/app/src/main/java/com/jiaoguanyi/appstore/bean/NewAppground.java b/app/src/main/java/com/jiaoguanyi/appstore/bean/NewAppground.java index ec24b8c..ae1b784 100644 --- a/app/src/main/java/com/jiaoguanyi/appstore/bean/NewAppground.java +++ b/app/src/main/java/com/jiaoguanyi/appstore/bean/NewAppground.java @@ -6,7 +6,8 @@ public class NewAppground implements Serializable { private static final long serialVersionUID = -2071117846816082338L; private String packages; private String address; - private String type; + private int type; + //type=1白 =0黑 public String getPackages() { return packages; @@ -24,11 +25,11 @@ public class NewAppground implements Serializable { this.address = address; } - public String getType() { + public int getType() { return type; } - public void setType(String type) { + public void setType(int type) { this.type = type; } } diff --git a/app/src/main/java/com/jiaoguanyi/appstore/bean/SplitApks.java b/app/src/main/java/com/jiaoguanyi/appstore/bean/SplitApks.java new file mode 100644 index 0000000..83c16ea --- /dev/null +++ b/app/src/main/java/com/jiaoguanyi/appstore/bean/SplitApks.java @@ -0,0 +1,24 @@ +package com.jiaoguanyi.appstore.bean; + +import java.io.Serializable; + +public class SplitApks implements Serializable { + private String file; + private String id; + + public String getFile() { + return file; + } + + public void setFile(String file) { + this.file = file; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } +} diff --git a/app/src/main/java/com/jiaoguanyi/appstore/server/GuardService.java b/app/src/main/java/com/jiaoguanyi/appstore/server/GuardService.java index 69e9349..778d73f 100644 --- a/app/src/main/java/com/jiaoguanyi/appstore/server/GuardService.java +++ b/app/src/main/java/com/jiaoguanyi/appstore/server/GuardService.java @@ -32,6 +32,7 @@ import com.arialyy.aria.core.Aria; import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.task.DownloadTask; import com.jiaoguanyi.appstore.utils.JGYUtils; +import com.jiaoguanyi.appstore.utils.XAPKUtils; import com.lzy.okgo.OkGo; import com.lzy.okgo.callback.StringCallback; import com.jiaoguanyi.appstore.KeepAliveConnection; @@ -114,7 +115,7 @@ public class GuardService extends Service { //第三个就是 我们要过滤的类型 W表示warm ,我们也可以换成 D :debug, I:info,E:error等等 // String[] running = new String[]{"logcat", "-s", "adb logcat *: W"}; String[] running = new String[]{"logcat"}; - String filePath = "/sdcard/Log/Log.txt"; + String logFilePath = "/sdcard/Log/Log.txt"; class LogThread extends Thread { InputStream is; @@ -129,12 +130,12 @@ public class GuardService extends Service { FileOutputStream os = null; try { //新建一个路径信息 - File file = new File(filePath); + File file = new File(logFilePath); if (!file.exists()) { file.getParentFile().mkdirs(); file.createNewFile(); } - os = new FileOutputStream(filePath); + os = new FileOutputStream(logFilePath); int len = 0; byte[] buf = new byte[1024]; while (-1 != (len = is.read(buf))) { @@ -285,7 +286,7 @@ public class GuardService extends Service { void taskComplete(DownloadTask task) { //在这里处理任务完成的状态 final String filepath = task.getFilePath(); - if (filepath.endsWith("apk")) { + if (filepath.endsWith(".apk")) { final String packageName = task.getExtendField(); Log.e("aria", "downloadPath::" + filepath); Log.e("aria", "extendField::" + packageName); @@ -342,9 +343,12 @@ public class GuardService extends Service { BaseApplication.getInstance().setDownloadState(false); Log.e("aria", "isDownloading=" + BaseApplication.getInstance().isDownloading()); } - } else if (filepath.endsWith("zip")) { + } else if (filepath.endsWith(".zip")) { Log.e("aria", "下载完成:" + task.getPercent() + ":" + task.getExtendField()); JGYUtils.getInstance().setBootanimation(task.getFilePath()); + } else if (filepath.endsWith(".xapk")) { + XAPKUtils.getInstance().installXAPK(filepath); + Log.e(TAG, "taskComplete: " + filepath); } } diff --git a/app/src/main/java/com/jiaoguanyi/appstore/server/StepService.java b/app/src/main/java/com/jiaoguanyi/appstore/server/StepService.java index a520849..d914c07 100644 --- a/app/src/main/java/com/jiaoguanyi/appstore/server/StepService.java +++ b/app/src/main/java/com/jiaoguanyi/appstore/server/StepService.java @@ -91,6 +91,7 @@ public class StepService extends Service { // Log.e("fht", e.getMessage()); // } //初始化websocket + Log.e(TAG, "onStartCommand: "); initSocketClient(); mHandler.postDelayed(heartBeatRunnable, HEART_BEAT_RATE);//开启心跳检测 bindService(new Intent(this, GuardService.class), mServiceConnection, Context.BIND_IMPORTANT); diff --git a/app/src/main/java/com/jiaoguanyi/appstore/utils/ApkUtils.java b/app/src/main/java/com/jiaoguanyi/appstore/utils/ApkUtils.java index 18c0b3c..8c3e19a 100644 --- a/app/src/main/java/com/jiaoguanyi/appstore/utils/ApkUtils.java +++ b/app/src/main/java/com/jiaoguanyi/appstore/utils/ApkUtils.java @@ -823,6 +823,8 @@ public class ApkUtils { this.add("com.android.theme.icon_pack.circular.android"); this.add("com.jiaoguanyi.appstore"); this.add("com.jiaoguanyi.store"); + this.add("com.example.eyeshielyplus"); + this.add("cn.com.bifa.eyeshiely"); }}; @@ -1118,7 +1120,6 @@ public class ApkUtils { Log.e("RemoveTask", "subscribe: " + "删除文件:" + entity.getFilePath()); Aria.download(this).load(id).cancel(true); } - } e.onComplete(); } @@ -1128,19 +1129,16 @@ public class ApkUtils { @Override public void onSubscribe(Disposable d) { Log.e("RemoveTask", "onSubscribe: "); - } @Override public void onNext(String s) { Log.e("RemoveTask", "onNext: "); - } @Override public void onError(Throwable e) { Log.e("RemoveTask", "onError: "); - } @Override diff --git a/app/src/main/java/com/jiaoguanyi/appstore/utils/FileUtils.java b/app/src/main/java/com/jiaoguanyi/appstore/utils/FileUtils.java new file mode 100644 index 0000000..c0bed50 --- /dev/null +++ b/app/src/main/java/com/jiaoguanyi/appstore/utils/FileUtils.java @@ -0,0 +1,12 @@ +package com.jiaoguanyi.appstore.utils; + +import java.io.File; + +public class FileUtils { + public static String getFileNoExName(String filePath) { + + String fileNameEx = filePath.substring(filePath.lastIndexOf(File.separator) + 1); + String fileName = fileNameEx.substring(0,fileNameEx.lastIndexOf(".")); + return fileName; + } +} diff --git a/app/src/main/java/com/jiaoguanyi/appstore/utils/JGYUtils.java b/app/src/main/java/com/jiaoguanyi/appstore/utils/JGYUtils.java index 8df86bb..0055d3e 100644 --- a/app/src/main/java/com/jiaoguanyi/appstore/utils/JGYUtils.java +++ b/app/src/main/java/com/jiaoguanyi/appstore/utils/JGYUtils.java @@ -283,13 +283,19 @@ public class JGYUtils { if (response.code == 200) { List appgrounds = response.data; if (appgrounds != null && appgrounds.size() > 0) { - String strings = ""; - String packageList = "";//单条管控名单 + StringBuilder strings = new StringBuilder(); + StringBuilder packageList = new StringBuilder();//单条管控名单 for (Appground appground : appgrounds) { if (TextUtils.isEmpty(appground.getAddress())) { - packageList += appground.getPackages() + ","; + if (packageList.length() > 0) { + packageList.append(","); + } + packageList.append(appground.getPackages()); } else { - strings += appground.toString() + ";"; + if (strings.length() > 0) { + strings.append(";"); + } + strings.append(appground.toString()); } } if (packageList.length() > 0) { @@ -299,7 +305,7 @@ public class JGYUtils { Log.e("setAppinsideWeb ", "packageList:" + packageList); Intent qch_app_website = new Intent("qch_app_website") .setPackage("com.android.settings"); - qch_app_website.putExtra("package_name", packageList); + qch_app_website.putExtra("package_name", packageList.toString()); mContext.sendBroadcast(qch_app_website); } else { sendAllweb(mContext); @@ -311,7 +317,7 @@ public class JGYUtils { Log.e("setAppinsideWeb ", "strings:" + strings); Intent intent = new Intent("qch_app_inside_website") .setPackage("com.android.settings"); - intent.putExtra("websitelist", strings); + intent.putExtra("websitelist", strings.toString()); mContext.sendBroadcast(intent); } else { sendwebUrl(mContext); @@ -329,40 +335,68 @@ public class JGYUtils { public void setNewAppinsideWeb(BaseResponse> response) { if (response.code == 200) { List appgrounds = response.data; + StringBuilder whiteList = new StringBuilder(); + StringBuilder blackList = new StringBuilder(); + StringBuilder packageList = new StringBuilder();//单条管控名单 if (appgrounds != null && appgrounds.size() > 0) { - String strings = ""; - String packageList = "";//单条管控名单 for (NewAppground appground : appgrounds) { - if (TextUtils.isEmpty(appground.getAddress())) { - packageList += appground.getPackages() + ","; + if (appground.getType() == 1) { + if (TextUtils.isEmpty(appground.getAddress())) { + return; + } else { + if (whiteList.length() > 0) { + whiteList.append(","); + } + whiteList.append(appground.getAddress()); + } } else { - strings += appground.toString() + ";"; + if (TextUtils.isEmpty(appground.getAddress())) { + if (packageList.length() > 0) { + packageList.append(","); + } + packageList.append(appground.getPackages()); + } else { + if (blackList.length() > 0) { + blackList.append(";"); + } + blackList.append(appground.toString()); + } } } + if (whiteList.length() > 0) { + Intent intent = new Intent(); + intent.setAction("黑名单key"); + intent.putExtra("package_name", "应用包名"); + intent.setPackage("com.android.settings"); + mContext.sendBroadcast(intent); + android.provider.Settings.System.putString(mContext.getContentResolver(), "黑名单网址key", "黑名单网址"); + } else { + + } + + //old if (packageList.length() > 0) { //app内所有的网页禁止 - //packageList = packageList.substring(0, packageList.length() - 1); - //去掉多余的, Log.e("setAppinsideWeb ", "packageList:" + packageList); Intent qch_app_website = new Intent("qch_app_website") .setPackage("com.android.settings"); - qch_app_website.putExtra("package_name", packageList); + qch_app_website.putExtra("package_name", packageList.toString()); mContext.sendBroadcast(qch_app_website); } else { sendAllweb(mContext); } - if (strings.length() > 0) { + if (blackList.length() > 0) { //app内单个网页地址禁止打开 - //strings = strings.substring(0, strings.length() - 1); - //去掉多余的; - Log.e("setAppinsideWeb ", "strings:" + strings); + Log.e("setAppinsideWeb ", "blackList:" + blackList); Intent intent = new Intent("qch_app_inside_website") .setPackage("com.android.settings"); - intent.putExtra("websitelist", strings); + intent.putExtra("websitelist", blackList.toString()); mContext.sendBroadcast(intent); } else { sendwebUrl(mContext); } + + } } else if (response.code == 400) { //列表为空的情况 diff --git a/app/src/main/java/com/jiaoguanyi/appstore/utils/JsonUtils.java b/app/src/main/java/com/jiaoguanyi/appstore/utils/JsonUtils.java new file mode 100644 index 0000000..fdc2861 --- /dev/null +++ b/app/src/main/java/com/jiaoguanyi/appstore/utils/JsonUtils.java @@ -0,0 +1,39 @@ +package com.jiaoguanyi.appstore.utils; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.Reader; +import java.nio.charset.StandardCharsets; + +public class JsonUtils { + /** + * 读取json文件,返回json串 + * @param fileName + * @return + */ + public static String readJsonFile(String fileName) { + String jsonStr = ""; + try { + File jsonFile = new File(fileName); + FileReader fileReader = new FileReader(jsonFile); + + Reader reader = new InputStreamReader(new FileInputStream(jsonFile), StandardCharsets.UTF_8); + int ch = 0; + StringBuffer sb = new StringBuffer(); + while ((ch = reader.read()) != -1) { + sb.append((char) ch); + } + fileReader.close(); + reader.close(); + jsonStr = sb.toString(); + return jsonStr; + } catch (IOException e) { + e.printStackTrace(); + return null; + } + } + +} diff --git a/app/src/main/java/com/jiaoguanyi/appstore/utils/SysSettingUtils.java b/app/src/main/java/com/jiaoguanyi/appstore/utils/SysSettingUtils.java index 70b2bba..3dde8aa 100644 --- a/app/src/main/java/com/jiaoguanyi/appstore/utils/SysSettingUtils.java +++ b/app/src/main/java/com/jiaoguanyi/appstore/utils/SysSettingUtils.java @@ -1,5 +1,6 @@ package com.jiaoguanyi.appstore.utils; +import android.app.StatusBarManager; import android.bluetooth.BluetoothAdapter; import android.content.Context; import android.content.Intent; @@ -13,6 +14,9 @@ import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.jiaoguanyi.appstore.BuildConfig; +import java.util.ArrayList; +import java.util.List; + public class SysSettingUtils { private static final String TAG = "SysSettingUtils"; @@ -29,21 +33,22 @@ public class SysSettingUtils { return status == 0 ? 1 : 0; } - public static void setSystemSetting(Context mContext, String jsonObj) { - if (null == mContext) { + public static void setSystemSetting(Context context, String jsonObj) { + if (null == context) { throw new RuntimeException("Context it's null"); } JSONObject jsonObject = JSON.parseObject(jsonObj); - setPhoneList(mContext, jsonObject); - setUSBstate(mContext, jsonObject); - setBluetooth(mContext, jsonObject); - setHotspot(mContext, jsonObject); - setBar(mContext, jsonObject); - setCamera(mContext, jsonObject); - setTF(mContext, jsonObject); - setIcon(mContext, jsonObject); - setCanReset(mContext, jsonObject); - setAutoTime(mContext, jsonObject); + setPhoneList(context, jsonObject); + setUSBstate(context, jsonObject); + setBluetooth(context, jsonObject); + setHotspot(context, jsonObject); + setBar(context, jsonObject); + setCamera(context, jsonObject); + setTF(context, jsonObject); + setIcon(context, jsonObject); + setCanReset(context, jsonObject); + setAutoTime(context, jsonObject); + setStatusBar(context, jsonObject); //otg开关 // int setting_otg = changeNum(jsonObject.getInteger("setting_otg")); // Log.e("SystemSetting", "setting_otg---------" + setting_otg); @@ -60,95 +65,95 @@ public class SysSettingUtils { // sendBroadcast(otgIntent); } - public static void setDisableSetting(Context mContext) { - setPhoneList(mContext,1); - setUSBstate(mContext,1); - setBluetooth(mContext,1); - setHotspot(mContext,1); - setBar(mContext,1); - setCamera(mContext,1); - setTF(mContext,1); - setIcon(mContext,1); - setCanReset(mContext,1); - setAutoTime(mContext,1); + public static void setDisableSetting(Context context) { + setPhoneList(context, 1); + setUSBstate(context, 1); + setBluetooth(context, 1); + setHotspot(context, 1); + setBar(context, 1); + setCamera(context, 1); + setTF(context, 1); + setIcon(context, 1); + setCanReset(context, 1); + setAutoTime(context, 1); } - public static void setEnableSetting(Context mContext) { - setPhoneList(mContext,0); -// setUSBstate(mContext,0); - setBluetooth(mContext,0); - setHotspot(mContext,0); - setBar(mContext,0); - setCamera(mContext,0); - setTF(mContext,0); - setIcon(mContext,0); - setCanReset(mContext,0); - setAutoTime(mContext,0); + public static void setEnableSetting(Context context) { + setPhoneList(context, 0); +// setUSBstate(context,0); + setBluetooth(context, 0); + setHotspot(context, 0); + setBar(context, 0); + setCamera(context, 0); + setTF(context, 0); + setIcon(context, 0); + setCanReset(context, 0); + setAutoTime(context, 0); } - private static void setPhoneList(Context mContext,int state) { + private static void setPhoneList(Context context, int state) { try { //设置电话功能,电话白名单 - boolean qch_call_forbid = Settings.System.putInt(mContext.getContentResolver(), "qch_call_forbid", state); + boolean qch_call_forbid = Settings.System.putInt(context.getContentResolver(), "qch_call_forbid", state); Log.e("SystemSetting", "qch_call_forbid:" + qch_call_forbid); - boolean qch_white_list_on = Settings.System.putInt(mContext.getContentResolver(), "qch_white_list_on", state); + boolean qch_white_list_on = Settings.System.putInt(context.getContentResolver(), "qch_white_list_on", state); Log.e("SystemSetting", "qch_white_list_on:" + qch_white_list_on); - boolean qch_white_list_Array = Settings.System.putString(mContext.getContentResolver(), "qch_white_list_Array", ""); + boolean qch_white_list_Array = Settings.System.putString(context.getContentResolver(), "qch_white_list_Array", ""); // ToastTool.show("qch_call_forbid::"+setting_call+"----setting_phones::"+setting_phones+"----"+qch_white_list_Array+"---"+qch_call_forbid); Log.e("SystemSetting", "qch_white_list_Array:" + qch_white_list_Array + "---" + qch_white_list_Array); - boolean qch_sdcard_forbid_on = Settings.System.putInt(mContext.getContentResolver(), "qch_sdcard_forbid_on", state); + boolean qch_sdcard_forbid_on = Settings.System.putInt(context.getContentResolver(), "qch_sdcard_forbid_on", state); Log.e("SystemSetting", "qch_sdcard_forbid_on:" + qch_sdcard_forbid_on); } catch (Exception e) { Log.e(TAG, "setPhoneList: " + e.getMessage()); } } - private static void setPhoneList(Context mContext, JSONObject jsonObject) { + private static void setPhoneList(Context context, JSONObject jsonObject) { try { //设置电话功能,电话白名单 int setting_call = changeNum(jsonObject.getInteger("setting_call")); - boolean qch_call_forbid = Settings.System.putInt(mContext.getContentResolver(), "qch_call_forbid", setting_call); + boolean qch_call_forbid = Settings.System.putInt(context.getContentResolver(), "qch_call_forbid", setting_call); Log.e("SystemSetting", "qch_call_forbid:" + qch_call_forbid); int setting_phone = changeNum(jsonObject.getInteger("setting_phone")); - boolean qch_white_list_on = Settings.System.putInt(mContext.getContentResolver(), "qch_white_list_on", setting_phone); + boolean qch_white_list_on = Settings.System.putInt(context.getContentResolver(), "qch_white_list_on", setting_phone); Log.e("SystemSetting", "qch_white_list_on:" + qch_white_list_on); String setting_phones = jsonObject.getString("setting_phones"); - boolean qch_white_list_Array = Settings.System.putString(mContext.getContentResolver(), "qch_white_list_Array", setting_phones); + boolean qch_white_list_Array = Settings.System.putString(context.getContentResolver(), "qch_white_list_Array", setting_phones); // ToastTool.show("qch_call_forbid::"+setting_call+"----setting_phones::"+setting_phones+"----"+qch_white_list_Array+"---"+qch_call_forbid); Log.e("SystemSetting", "qch_white_list_Array:" + qch_white_list_Array + "---" + setting_phones); int setting_memory = changeNum(jsonObject.getInteger("setting_memory")); - boolean qch_sdcard_forbid_on = Settings.System.putInt(mContext.getContentResolver(), "qch_sdcard_forbid_on", setting_memory); + boolean qch_sdcard_forbid_on = Settings.System.putInt(context.getContentResolver(), "qch_sdcard_forbid_on", setting_memory); Log.e("SystemSetting", "qch_sdcard_forbid_on:" + qch_sdcard_forbid_on); } catch (Exception e) { Log.e(TAG, "setPhoneList: " + e.getMessage()); } } - private static void setUSBstate(Context mContext,int state) { + private static void setUSBstate(Context context, int state) { //USB数据功能管控 //仅充电:usb_charge //MTP模式:usb_mtp //Midi模式:usb_midi if (!BuildConfig.DEBUG) { try { - boolean qch_usb_choose = Settings.System.putString(mContext.getContentResolver(), "qch_usb_choose", "usb_charge"); + boolean qch_usb_choose = Settings.System.putString(context.getContentResolver(), "qch_usb_choose", "usb_charge"); Log.e("SystemSetting", "qch_usb_choose:" + qch_usb_choose); String usbStatus = "qch_action_usb_usb_charge"; Intent usbIntent = new Intent(usbStatus).setPackage("com.android.settings"); - mContext.sendBroadcast(usbIntent); + context.sendBroadcast(usbIntent); } catch (Exception e) { Log.e(TAG, "setUSBstate: " + e.getMessage()); } } } - private static void setUSBstate(Context mContext, JSONObject jsonObject) { + private static void setUSBstate(Context context, JSONObject jsonObject) { //USB数据功能管控 //仅充电:usb_charge //MTP模式:usb_mtp @@ -156,7 +161,7 @@ public class SysSettingUtils { String setting_usb = jsonObject.getString("setting_usb"); if (!BuildConfig.DEBUG) { try { - boolean qch_usb_choose = Settings.System.putString(mContext.getContentResolver(), "qch_usb_choose", setting_usb); + boolean qch_usb_choose = Settings.System.putString(context.getContentResolver(), "qch_usb_choose", setting_usb); Log.e("SystemSetting", "qch_usb_choose---------" + qch_usb_choose); String usbStatus = ""; switch (setting_usb) { @@ -172,16 +177,16 @@ public class SysSettingUtils { } Intent usbIntent = new Intent(usbStatus).setPackage("com.android.settings"); - mContext.sendBroadcast(usbIntent); + context.sendBroadcast(usbIntent); } catch (Exception e) { Log.e(TAG, "setUSBstate: " + e.getMessage()); } } } - private static void setBluetooth(Context mContext,int state) { + private static void setBluetooth(Context context, int state) { try { - boolean qch_bht_forbid_on = Settings.System.putInt(mContext.getContentResolver(), "qch_bht_forbid_on", state); + boolean qch_bht_forbid_on = Settings.System.putInt(context.getContentResolver(), "qch_bht_forbid_on", state); //写入系统数据库 Log.e("SystemSetting", "qch_bht_forbid_on:" + qch_bht_forbid_on); BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); @@ -192,8 +197,8 @@ public class SysSettingUtils { //获取默认蓝牙适配器 } //蓝牙总开关开启 - Settings.System.putString(mContext.getContentResolver(), "qch_bhtvideo_forbid_on", "Empty"); - Settings.System.putInt(mContext.getContentResolver(), "qch_bt_forbid_on", state); + Settings.System.putString(context.getContentResolver(), "qch_bhtvideo_forbid_on", "Empty"); + Settings.System.putInt(context.getContentResolver(), "qch_bt_forbid_on", state); mBluetoothAdapter.disable(); //设置关闭时关闭蓝牙 } @@ -202,7 +207,7 @@ public class SysSettingUtils { } } - private static void setBluetooth(Context mContext, JSONObject jsonObject) { + private static void setBluetooth(Context context, JSONObject jsonObject) { try { //蓝牙开关 int setting_bht = changeNum(jsonObject.getInteger("setting_bht")); @@ -211,7 +216,7 @@ public class SysSettingUtils { //蓝牙音频开关 int setting_bluetooth = changeNum(jsonObject.getInteger("setting_bluetooth")); //蓝牙传输开关 - boolean qch_bht_forbid_on = Settings.System.putInt(mContext.getContentResolver(), "qch_bht_forbid_on", setting_bht); + boolean qch_bht_forbid_on = Settings.System.putInt(context.getContentResolver(), "qch_bht_forbid_on", setting_bht); //写入系统数据库 Log.e("SystemSetting", "qch_bht_forbid_on:" + qch_bht_forbid_on); BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); @@ -227,14 +232,14 @@ public class SysSettingUtils { if (setting_bhtvideo == 0) { if (null != setting_context && !setting_context.equals("") && !setting_context.equals(" ") && !setting_context.equals("null")) { Log.e("SystemSetting", "setting_context:" + setting_context); - Settings.System.putString(mContext.getContentResolver(), "qch_bhtvideo_forbid_on", setting_context); + Settings.System.putString(context.getContentResolver(), "qch_bhtvideo_forbid_on", setting_context); } else { - Settings.System.putString(mContext.getContentResolver(), "qch_bhtvideo_forbid_on", "Empty"); + Settings.System.putString(context.getContentResolver(), "qch_bhtvideo_forbid_on", "Empty"); } } else if (setting_bhtvideo == 1) { - Settings.System.putString(mContext.getContentResolver(), "qch_bhtvideo_forbid_on", "Empty"); + Settings.System.putString(context.getContentResolver(), "qch_bhtvideo_forbid_on", "Empty"); } - Settings.System.putInt(mContext.getContentResolver(), "qch_bt_forbid_on", setting_bluetooth); + Settings.System.putInt(context.getContentResolver(), "qch_bt_forbid_on", setting_bluetooth); } else { mBluetoothAdapter.disable(); //设置关闭时关闭蓝牙 @@ -245,29 +250,29 @@ public class SysSettingUtils { } } - private static void setHotspot(Context mContext,int state) { + private static void setHotspot(Context context, int state) { try { Intent intent = new Intent(); intent.setAction("qch_hotspot_close"); intent.setPackage("com.android.settings"); - mContext.sendStickyBroadcast(intent); - boolean qch_hotspot_forbid_on = Settings.System.putInt(mContext.getContentResolver(), "qch_hotspot_forbid_on", state);//写入系统数据库 + context.sendStickyBroadcast(intent); + boolean qch_hotspot_forbid_on = Settings.System.putInt(context.getContentResolver(), "qch_hotspot_forbid_on", state);//写入系统数据库 Log.e("SystemSetting", "qch_hotspot_forbid_on:" + qch_hotspot_forbid_on); } catch (Exception e) { Log.e(TAG, "setHotspot: " + e.getMessage()); } } - private static void setHotspot(Context mContext, JSONObject jsonObject) { + private static void setHotspot(Context context, JSONObject jsonObject) { try { int setting_hotspot = changeNum(jsonObject.getInteger("setting_hotspot"));//热点 if (setting_hotspot == 1) { Intent intent = new Intent(); intent.setAction("qch_hotspot_close"); intent.setPackage("com.android.settings"); - mContext.sendStickyBroadcast(intent); + context.sendStickyBroadcast(intent); } - boolean qch_hotspot_forbid_on = Settings.System.putInt(mContext.getContentResolver(), "qch_hotspot_forbid_on", setting_hotspot);//写入系统数据库 + boolean qch_hotspot_forbid_on = Settings.System.putInt(context.getContentResolver(), "qch_hotspot_forbid_on", setting_hotspot);//写入系统数据库 Log.e("SystemSetting", "qch_hotspot_forbid_on---------" + setting_hotspot); Log.e("SystemSetting", "qch_hotspot_forbid_on---------" + qch_hotspot_forbid_on); } catch (Exception e) { @@ -275,10 +280,10 @@ public class SysSettingUtils { } } - private static void setBar(Context mContext,int state) { + private static void setBar(Context context, int state) { //系统导航条显示开关 int setting_navigation = 0; - boolean qch_hide_navigationBar = Settings.System.putInt(mContext.getContentResolver(), "qch_hide_NavigationBar", setting_navigation); + boolean qch_hide_navigationBar = Settings.System.putInt(context.getContentResolver(), "qch_hide_NavigationBar", setting_navigation); Log.e("SystemSetting", "qch_hide_navigationBar---------" + qch_hide_navigationBar); String navigationStatus = ""; @@ -292,14 +297,14 @@ public class SysSettingUtils { } Intent navIntent = new Intent(navigationStatus).setPackage("com.android.systemui"); - mContext.sendBroadcast(navIntent); + context.sendBroadcast(navIntent); //状态栏显示开关 int setting_statusbar = 0; - int oldNum = Settings.System.getInt(mContext.getContentResolver(), "qch_hide_statusBar", 0); + int oldNum = Settings.System.getInt(context.getContentResolver(), "qch_hide_statusBar", 0); if (oldNum != setting_statusbar) { - boolean qch_hide_statusBar = Settings.System.putInt(mContext.getContentResolver(), "qch_hide_statusBar", setting_statusbar); + boolean qch_hide_statusBar = Settings.System.putInt(context.getContentResolver(), "qch_hide_statusBar", setting_statusbar); Log.e("SystemSetting", "qch_hide_statusBar---------" + qch_hide_statusBar); String statusbarStatus = ""; switch (setting_statusbar) { @@ -311,14 +316,14 @@ public class SysSettingUtils { break; } Intent statusIntent = new Intent(statusbarStatus).setPackage("com.android.systemui"); - mContext.sendBroadcast(statusIntent); + context.sendBroadcast(statusIntent); } } - private static void setBar(Context mContext, JSONObject jsonObject) { + private static void setBar(Context context, JSONObject jsonObject) { //系统导航条显示开关 int setting_navigation = changeNum(jsonObject.getInteger("setting_navigation")); - boolean qch_hide_navigationBar = Settings.System.putInt(mContext.getContentResolver(), "qch_hide_NavigationBar", setting_navigation); + boolean qch_hide_navigationBar = Settings.System.putInt(context.getContentResolver(), "qch_hide_NavigationBar", setting_navigation); Log.e("SystemSetting", "qch_hide_navigationBar---------" + qch_hide_navigationBar); String navigationStatus = ""; @@ -332,14 +337,14 @@ public class SysSettingUtils { } Intent navIntent = new Intent(navigationStatus).setPackage("com.android.systemui"); - mContext.sendBroadcast(navIntent); + context.sendBroadcast(navIntent); //状态栏显示开关 int setting_statusbar = changeNum(jsonObject.getInteger("setting_statusbar")); - int oldNum = Settings.System.getInt(mContext.getContentResolver(), "qch_hide_statusBar", 0); + int oldNum = Settings.System.getInt(context.getContentResolver(), "qch_hide_statusBar", 0); if (oldNum != setting_statusbar) { - boolean qch_hide_statusBar = Settings.System.putInt(mContext.getContentResolver(), "qch_hide_statusBar", setting_statusbar); + boolean qch_hide_statusBar = Settings.System.putInt(context.getContentResolver(), "qch_hide_statusBar", setting_statusbar); Log.e("SystemSetting", "qch_hide_statusBar---------" + qch_hide_statusBar); String statusbarStatus = ""; switch (setting_statusbar) { @@ -351,16 +356,16 @@ public class SysSettingUtils { break; } Intent statusIntent = new Intent(statusbarStatus).setPackage("com.android.systemui"); - mContext.sendBroadcast(statusIntent); + context.sendBroadcast(statusIntent); } } - private static void setCamera(Context mContext,int state) { + private static void setCamera(Context context, int state) { try { //摄像头开关 - boolean qch_app_camera = Settings.System.putInt(mContext.getContentResolver(), "qch_app_camera", state); + boolean qch_app_camera = Settings.System.putInt(context.getContentResolver(), "qch_app_camera", state); Log.e("SystemSetting", "qch_app_camera1:" + state); -// ApkUtils.hideSystemSettingAPP(mContext, "com.mediatek.camera"); +// ApkUtils.hideSystemSettingAPP(context, "com.mediatek.camera"); Log.e("SystemSetting", "setting_camera---------" + qch_app_camera); String cameraStatus = "qch_camera_forbid"; switch (state) { @@ -372,19 +377,19 @@ public class SysSettingUtils { break; } Intent cameraIntent = new Intent(cameraStatus).setPackage("com.android.settings"); - mContext.sendBroadcast(cameraIntent); + context.sendBroadcast(cameraIntent); } catch (Exception e) { Log.e(TAG, "setCamera: " + e.getMessage()); } } - private static void setCamera(Context mContext, JSONObject jsonObject) { + private static void setCamera(Context context, JSONObject jsonObject) { try { //摄像头开关 int setting_camera = changeNum(jsonObject.getInteger("setting_camera")); - Settings.System.putInt(mContext.getContentResolver(), "qch_app_camera", setting_camera); + Settings.System.putInt(context.getContentResolver(), "qch_app_camera", setting_camera); Log.e("SystemSetting", "qch_app_camera2:" + setting_camera); -// ApkUtils.hideSystemSettingAPP(mContext, "com.mediatek.camera"); +// ApkUtils.hideSystemSettingAPP(context, "com.mediatek.camera"); Log.e("SystemSetting", "setting_camera---------" + setting_camera); String cameraStatus = ""; switch (setting_camera) { @@ -396,17 +401,17 @@ public class SysSettingUtils { break; } Intent cameraIntent = new Intent(cameraStatus).setPackage("com.android.settings"); - mContext.sendBroadcast(cameraIntent); + context.sendBroadcast(cameraIntent); } catch (Exception e) { Log.e(TAG, "setCamera: " + e.getMessage()); } } - private static void setTF(Context mContext,int state) { + private static void setTF(Context context, int state) { try { //tfmedia开关 // int setting_tfmedia = 1; - boolean qch_tfmedia_forbid = Settings.System.putInt(mContext.getContentResolver(), "qch_tfmedia_forbid", state); + boolean qch_tfmedia_forbid = Settings.System.putInt(context.getContentResolver(), "qch_tfmedia_forbid", state); Log.e("SystemSetting", "setting_tfmedia---------" + qch_tfmedia_forbid); String tfmediaStatus = ""; switch (state) { @@ -418,23 +423,23 @@ public class SysSettingUtils { break; } Intent tfmediaIntent = new Intent(tfmediaStatus).setPackage("com.android.settings"); - mContext.sendBroadcast(tfmediaIntent); + context.sendBroadcast(tfmediaIntent); if (state == 1) { - boolean qch_tfmedia_filetypes = Settings.System.putString(mContext.getContentResolver(), "qch_tfmedia_filetypes", "Empty");//影音管控 + boolean qch_tfmedia_filetypes = Settings.System.putString(context.getContentResolver(), "qch_tfmedia_filetypes", "Empty");//影音管控 Log.e("SystemSetting", "qch_tfmedia_filetypes:" + qch_tfmedia_filetypes); } else { - Settings.System.putInt(mContext.getContentResolver(), "qch_tfmedia_forbid", 0); + Settings.System.putInt(context.getContentResolver(), "qch_tfmedia_forbid", 0); } } catch (Exception e) { Log.e(TAG, "setTF: " + e.getMessage()); } } - private static void setTF(Context mContext, JSONObject jsonObject) { + private static void setTF(Context context, JSONObject jsonObject) { try { //tfmedia开关 int setting_tfmedia = changeNum(jsonObject.getInteger("setting_tfmedia")); - boolean qch_tfmedia_forbid = Settings.System.putInt(mContext.getContentResolver(), + boolean qch_tfmedia_forbid = Settings.System.putInt(context.getContentResolver(), "qch_tfmedia_forbid", setting_tfmedia); Log.e("SystemSetting", "setting_tfmedia---------" + qch_tfmedia_forbid); String tfmediaStatus = ""; @@ -447,7 +452,7 @@ public class SysSettingUtils { break; } Intent tfmediaIntent = new Intent(tfmediaStatus).setPackage("com.android.settings"); - mContext.sendBroadcast(tfmediaIntent); + context.sendBroadcast(tfmediaIntent); if (setting_tfmedia == 1) { JSONArray jSONArray = null; jSONArray = jsonObject.getJSONArray("setting_tfmedia_format"); @@ -458,51 +463,51 @@ public class SysSettingUtils { stringBuffer.append(","); } stringBuffer.deleteCharAt(stringBuffer.length() - 1); - Settings.System.putString(mContext.getContentResolver(), "qch_tfmedia_filetypes", stringBuffer.toString());//影音管控 + Settings.System.putString(context.getContentResolver(), "qch_tfmedia_filetypes", stringBuffer.toString());//影音管控 Log.e("SystemSetting", "qch_tfmedia_filetypes---------" + stringBuffer.toString()); } else { - Settings.System.putInt(mContext.getContentResolver(), "qch_tfmedia_forbid", 0); + Settings.System.putInt(context.getContentResolver(), "qch_tfmedia_forbid", 0); } } catch (Exception e) { Log.e("SystemSetting", "setTF: " + e.getMessage()); } } - private static void setIcon(Context mContext,int state) { + private static void setIcon(Context context, int state) { try { //added:2019.12.6 //设置5个app的开关 //时钟 // int deskclock = 1; - Settings.System.putInt(mContext.getContentResolver(), "qch_app_deskclock", state); - ApkUtils.hideSystemSettingAPP(mContext, "com.android.deskclock"); + Settings.System.putInt(context.getContentResolver(), "qch_app_deskclock", state); + ApkUtils.hideSystemSettingAPP(context, "com.android.deskclock"); Log.e("SystemSetting", "qch_app_deskclock" + state); //录音机 // int soundrecorder = 1; - Settings.System.putInt(mContext.getContentResolver(), "qch_app_soundrecorder", state); - ApkUtils.hideSystemSettingAPP(mContext, "com.android.soundrecorder"); + Settings.System.putInt(context.getContentResolver(), "qch_app_soundrecorder", state); + ApkUtils.hideSystemSettingAPP(context, "com.android.soundrecorder"); Log.e("SystemSetting", "qch_app_soundrecorder" + state); //音乐 // int music = 1; - Settings.System.putInt(mContext.getContentResolver(), "qch_app_music", state); - ApkUtils.hideSystemSettingAPP(mContext, "com.android.music"); + Settings.System.putInt(context.getContentResolver(), "qch_app_music", state); + ApkUtils.hideSystemSettingAPP(context, "com.android.music"); Log.e("SystemSetting", "qch_app_music" + state); //图库 // int gallery = 1; - Settings.System.putInt(mContext.getContentResolver(), "qch_app_gallery", state); - ApkUtils.hideSystemSettingAPP(mContext, "com.android.gallery3d"); + Settings.System.putInt(context.getContentResolver(), "qch_app_gallery", state); + ApkUtils.hideSystemSettingAPP(context, "com.android.gallery3d"); Log.e("SystemSetting", "qch_app_gallery" + state); //壁纸 // int wallpaper = 1; - Settings.System.putInt(mContext.getContentResolver(), "qch_app_wallpaper", state); + Settings.System.putInt(context.getContentResolver(), "qch_app_wallpaper", state); Log.e("SystemSetting", "qch_app_wallpaper" + state); //文件管理器 // int filemanager = 1; - Settings.System.putInt(mContext.getContentResolver(), "qch_app_filemanager", state); + Settings.System.putInt(context.getContentResolver(), "qch_app_filemanager", state); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { - ApkUtils.hideSystemSettingAPP(mContext, "com.mediatek.filemanager"); + ApkUtils.hideSystemSettingAPP(context, "com.mediatek.filemanager"); } else { - ApkUtils.hideSystemSettingAPP(mContext, "com.android.documentsui"); + ApkUtils.hideSystemSettingAPP(context, "com.android.documentsui"); } Log.e("SystemSetting", "qch_app_filemanager" + state); } catch (Exception e) { @@ -510,41 +515,41 @@ public class SysSettingUtils { } } - private static void setIcon(Context mContext, JSONObject jsonObject) { + private static void setIcon(Context context, JSONObject jsonObject) { try { //added:2019.12.6 //设置5个app的开关 //时钟 int deskclock = changeNum(jsonObject.getInteger("setting_clock")); - Settings.System.putInt(mContext.getContentResolver(), "qch_app_deskclock", deskclock); - ApkUtils.hideSystemSettingAPP(mContext, "com.android.deskclock"); + Settings.System.putInt(context.getContentResolver(), "qch_app_deskclock", deskclock); + ApkUtils.hideSystemSettingAPP(context, "com.android.deskclock"); Log.e("SystemSetting", "qch_app_deskclock" + deskclock); //录音机 int soundrecorder = changeNum(jsonObject.getInteger("setting_recording")); - Settings.System.putInt(mContext.getContentResolver(), "qch_app_soundrecorder", soundrecorder); - ApkUtils.hideSystemSettingAPP(mContext, "com.android.soundrecorder"); + Settings.System.putInt(context.getContentResolver(), "qch_app_soundrecorder", soundrecorder); + ApkUtils.hideSystemSettingAPP(context, "com.android.soundrecorder"); Log.e("SystemSetting", "qch_app_soundrecorder" + soundrecorder); //音乐 int music = changeNum(jsonObject.getInteger("setting_music")); - Settings.System.putInt(mContext.getContentResolver(), "qch_app_music", music); - ApkUtils.hideSystemSettingAPP(mContext, "com.android.music"); + Settings.System.putInt(context.getContentResolver(), "qch_app_music", music); + ApkUtils.hideSystemSettingAPP(context, "com.android.music"); Log.e("SystemSetting", "qch_app_music" + music); //图库 int gallery = changeNum(jsonObject.getInteger("setting_picture")); - Settings.System.putInt(mContext.getContentResolver(), "qch_app_gallery", gallery); - ApkUtils.hideSystemSettingAPP(mContext, "com.android.gallery3d"); + Settings.System.putInt(context.getContentResolver(), "qch_app_gallery", gallery); + ApkUtils.hideSystemSettingAPP(context, "com.android.gallery3d"); Log.e("SystemSetting", "qch_app_gallery" + gallery); //壁纸 int wallpaper = changeNum(jsonObject.getInteger("setting_wallpaper")); - Settings.System.putInt(mContext.getContentResolver(), "qch_app_wallpaper", wallpaper); + Settings.System.putInt(context.getContentResolver(), "qch_app_wallpaper", wallpaper); Log.e("SystemSetting", "qch_app_wallpaper" + wallpaper); //文件管理器 int filemanager = changeNum(jsonObject.getInteger("setting_file")); - Settings.System.putInt(mContext.getContentResolver(), "qch_app_filemanager", filemanager); + Settings.System.putInt(context.getContentResolver(), "qch_app_filemanager", filemanager); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { - ApkUtils.hideSystemSettingAPP(mContext, "com.mediatek.filemanager"); + ApkUtils.hideSystemSettingAPP(context, "com.mediatek.filemanager"); } else { - ApkUtils.hideSystemSettingAPP(mContext, "com.android.documentsui"); + ApkUtils.hideSystemSettingAPP(context, "com.android.documentsui"); } Log.e("SystemSetting", "qch_app_filemanager" + filemanager); } catch (Exception e) { @@ -552,21 +557,21 @@ public class SysSettingUtils { } } - private static void setCanReset(Context mContext,int state) { - boolean qch_restore_forbid_on = Settings.System.putInt(mContext.getContentResolver(), "qch_restore_forbid_on", 0); + private static void setCanReset(Context context, int state) { + boolean qch_restore_forbid_on = Settings.System.putInt(context.getContentResolver(), "qch_restore_forbid_on", 0); Log.e("SystemSetting", "qch_restore_forbid_on:" + qch_restore_forbid_on); //默认打开 } //qch_restore_forbid_on=1,禁止恢复出厂设置 //qch_restore_forbid_on=0,允许恢复出厂设置 - private static void setCanReset(Context mContext, JSONObject jsonObject) { + private static void setCanReset(Context context, JSONObject jsonObject) { int mode = jsonObject.getInteger("qch_restore"); if (mode == 1) { - boolean qch_restore_forbid_on = Settings.System.putInt(mContext.getContentResolver(), "qch_restore_forbid_on", 0); + boolean qch_restore_forbid_on = Settings.System.putInt(context.getContentResolver(), "qch_restore_forbid_on", 0); Log.e("SystemSetting", "qch_restore_forbid_on:" + qch_restore_forbid_on); } else { - boolean qch_restore_forbid_on = Settings.System.putInt(mContext.getContentResolver(), "qch_restore_forbid_on", 1); + boolean qch_restore_forbid_on = Settings.System.putInt(context.getContentResolver(), "qch_restore_forbid_on", 1); Log.e("SystemSetting", "qch_restore_forbid_on:" + qch_restore_forbid_on); } } @@ -588,7 +593,7 @@ public class SysSettingUtils { //intent34.setPackage("com.android.settings"); //sendBroadcast(intent34); - private static void setAutoTime(Context mContext, JSONObject jsonObject) { + private static void setAutoTime(Context context, JSONObject jsonObject) { String autoTime = jsonObject.getString("setting_autotime"); String action = "qch_autotime_network"; if (TextUtils.isEmpty(autoTime)) { @@ -613,15 +618,55 @@ public class SysSettingUtils { Intent intent = new Intent(); intent.setAction(action); intent.setPackage("com.android.settings"); - mContext.sendBroadcast(intent); + context.sendBroadcast(intent); } - private static void setAutoTime(Context mContext,int state) { + private static void setAutoTime(Context context, int state) { Log.e("SystemSetting", "setAutoTime: " + "default"); Intent intent = new Intent(); intent.setAction("qch_autotime_network"); intent.setPackage("com.android.settings"); - mContext.sendBroadcast(intent); + context.sendBroadcast(intent); } + + private static void setStatusBar(Context context, JSONObject jsonObject) { + JSONObject navJson = jsonObject.getJSONObject("setting_nav"); + if (null != navJson) { + int whole = navJson.getInteger("whole"); + if (whole == 1) { + setStatusBar(context, 0); + } else { + List disableWhat = new ArrayList<>(); + int home = navJson.getInteger("home"); + if (home == 1) { + disableWhat.add(StatusBarManager.DISABLE_HOME); + } + int returnKey = navJson.getInteger("returnKey"); + if (returnKey == 1) { + disableWhat.add(StatusBarManager.DISABLE_BACK); + } + int taskbar = navJson.getInteger("taskbar"); + if (taskbar == 1) { + disableWhat.add(StatusBarManager.DISABLE_RECENT); + } + int what = 0; + for (Integer integer : disableWhat) { + if (what == 0) { + what = integer; + } + what |= integer; + } + StatusBarManager mStatusBarManager = (StatusBarManager) context.getSystemService(Context.STATUS_BAR_SERVICE); + mStatusBarManager.disable(what); + } + } + } + + private static void setStatusBar(Context context, int state) { + StatusBarManager mStatusBarManager = (StatusBarManager) context.getSystemService(Context.STATUS_BAR_SERVICE); + mStatusBarManager.disable(StatusBarManager.DISABLE_NONE);//显示隐藏的虚拟按键 + } + + } diff --git a/app/src/main/java/com/jiaoguanyi/appstore/utils/XAPKUtils.java b/app/src/main/java/com/jiaoguanyi/appstore/utils/XAPKUtils.java index 08c143d..a505312 100644 --- a/app/src/main/java/com/jiaoguanyi/appstore/utils/XAPKUtils.java +++ b/app/src/main/java/com/jiaoguanyi/appstore/utils/XAPKUtils.java @@ -1,4 +1,407 @@ package com.jiaoguanyi.appstore.utils; +import android.app.PendingIntent; +import android.content.Context; +import android.content.Intent; +import android.content.pm.PackageInstaller; +import android.os.Build; +import android.os.Environment; +import android.text.TextUtils; +import android.util.Log; + +import androidx.annotation.RequiresApi; + +import com.google.gson.Gson; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import com.google.gson.reflect.TypeToken; +import com.jiaoguanyi.appstore.bean.Expansions; +import com.jiaoguanyi.appstore.bean.SplitApks; + +import org.zeroturnaround.zip.ZipUtil; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.lang.reflect.Type; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.List; + +import io.reactivex.Observable; +import io.reactivex.ObservableEmitter; +import io.reactivex.ObservableOnSubscribe; +import io.reactivex.Observer; +import io.reactivex.android.schedulers.AndroidSchedulers; +import io.reactivex.disposables.Disposable; +import io.reactivex.schedulers.Schedulers; + +/** + * @author Administrator + */ public class XAPKUtils { + //https://my.oschina.net/fxc0719/blog/4445198 + //https://www.jianshu.com/p/cd10d5278ebf?utm_campaign=hugo + //https://www.jianshu.com/p/580b61ee7aee + + private static final String TAG = XAPKUtils.class.getSimpleName(); + private static XAPKUtils sInstance; + private Context mContext; + + private XAPKUtils(Context context) { + this.mContext = context; + } + + public static void init(Context context) { + if (sInstance == null) { + sInstance = new XAPKUtils(context); + } + } + + public static XAPKUtils getInstance() { + if (sInstance == null) { + throw new IllegalStateException("You must be init XAPKUtils first"); + } + return sInstance; + } + + public void installXAPK(String filePath) { + File file = new File(filePath); + if (file.exists() && file.isFile()) { + upzipXAPK(file); + } else { + Log.e(TAG, "installXAPK: " + "File not exists"); + + } + } + + private static String unpackPath; + private static long XAPKSize; + + private void upzipXAPK(File XAPKFile) { + Observable.create(new ObservableOnSubscribe() { + @Override + public void subscribe(ObservableEmitter emitter) throws Exception { + if (ZipUtil.containsEntry(XAPKFile, "manifest.json")) { + //判断json文件是否存在 + String dirName = FileUtils.getFileNoExName(XAPKFile.getAbsolutePath()); + unpackPath = XAPKFile.getParentFile().getAbsolutePath() + File.separator + dirName; + File unpackDir = new File(unpackPath); + ZipUtil.unpack(XAPKFile, unpackDir); + String jsonString = JsonUtils.readJsonFile(unpackDir.getAbsolutePath() + File.separator + "manifest.json"); + emitter.onNext(jsonString); + } else { + ToastUtil.show("读取XAPK配置文件失败"); + emitter.onComplete(); + } + } + }).subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(new Observer() { + @Override + public void onSubscribe(Disposable d) { + + } + + @Override + public void onNext(String s) { + JsonObject jsonObject = JsonParser.parseString(s).getAsJsonObject(); + XAPKSize = jsonObject.get("total_size").getAsLong(); + JsonElement split_configs_em = jsonObject.get("split_configs"); + //获取分割的配置 + JsonElement expansions_em = jsonObject.get("expansions"); + //获取OBB文件配置 + JsonElement split_apks_em = jsonObject.get("split_apks"); + readConfig(split_configs_em, expansions_em, split_apks_em); +// Log.e(TAG, "installXAPK: " + jsonString); + } + + @Override + public void onError(Throwable e) { + Log.e(TAG, "onError: " + e.getMessage()); + } + + @Override + public void onComplete() { + Log.e(TAG, "onComplete: "); + } + }); + } + + private void readConfig(JsonElement split_configs, JsonElement expansions, JsonElement split_apks) { + //没有split_configs只有单个apk,读取split_apks 的base字段的file文件 + //没有expansions 没有obb文件 + //split_apks应该是都会有的,包含一个base的json对象 + if (null != split_configs) { + getSplitConfigs(split_configs.getAsJsonArray()); + } else { + Log.e(TAG, "readConfig: " + "not found split_configs json data"); + } + + if (null != expansions) { + readOBBConfig(expansions.getAsJsonArray()); + } else { + Log.e(TAG, "readConfig: " + "not found expansions json data"); + } + + if (null != split_apks) { + getSplitApks(split_apks.getAsJsonArray()); + } else { + Log.e(TAG, "readConfig: " + "not found split_apks json data"); + } + + + } + + List configList = new ArrayList<>(); + + /** + * 获取分裂的配置文件 + * + * @param jsonArray + */ + private void getSplitConfigs(JsonArray jsonArray) { + Type type = new TypeToken>() { + }.getType(); + Gson gson = new Gson(); + configList = gson.fromJson(gson.toJson(jsonArray), type); +// StringBuilder configStringBuilder = new StringBuilder(); +// for (String config : configList) { +// if (configStringBuilder.length() > 0) { +// configStringBuilder.append(","); +// } +// configStringBuilder.append(config); +// } +// Log.e(TAG, "getSplitConfigs: " + configStringBuilder.toString()); + } + + /** + * 获取obb配置文件 + * + * @param jsonArray + */ + private void readOBBConfig(JsonArray jsonArray) { + if (TextUtils.isEmpty(unpackPath)) { + Log.e(TAG, "readOBBConfig: " + "unpack directory is empty"); + return; + } + Type type = new TypeToken>() { + }.getType(); + Gson gson = new Gson(); + List expansionsList = gson.fromJson(gson.toJson(jsonArray), type); + if (null != expansionsList && expansionsList.size() > 0) { + for (Expansions expansions : expansionsList) { + if (copyObbFile(expansions)) { + Log.e(TAG, "readOBBConfig: " + "success"); + } else { + Log.e(TAG, "readOBBConfig: " + "copy oob File failure"); + } + } + } + } + + + private boolean copyObbFile(Expansions expansions) { + String install_location = expansions.getInstall_location(); + //install_location 不清楚是否还有其他定义 + + String file = expansions.getFile(); + String install_path = expansions.getInstall_path(); + + if (TextUtils.isEmpty(file)) { + Log.e(TAG, "copyObbFile: " + "file path is empty"); + return false; + } else { + File localFile = new File(unpackPath + File.separator + file); + if (localFile.exists() && localFile.isFile()) { + File installFile = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + install_path); + Log.e(TAG, "copyObbFile: " + "localFile: " + localFile.getAbsolutePath()); + Log.e(TAG, "copyObbFile: " + "installFile: " + installFile.getAbsolutePath()); + try { + Path path = Paths.get(localFile.getAbsolutePath()); + Files.copy(path, new FileOutputStream(installFile)); + return true; + } catch (IOException e) { + Log.e(TAG, "copyObbFile: " + "IOException" + e.getMessage()); + e.printStackTrace(); + return false; + } + } else { + Log.e(TAG, "copyObbFile: " + "localFile: " + "File not exists"); + return false; + } + + } + } + + + /** + * 获取分裂的apk文件 + * + * @param jsonArray + */ + private void getSplitApks(JsonArray jsonArray) { + Type type = new TypeToken>() { + }.getType(); + Gson gson = new Gson(); + List splitApksList = gson.fromJson(gson.toJson(jsonArray), type); + getApkFilePath(configList, splitApksList); +// if (null != splitApksList && splitApksList.size() > 0) { +// for (SplitApks splitApks : splitApksList) { +// +// } +// } + } + + /** + * @param configList + * @param apkList configList 可以为空,为空解析split_apks对象中的base + * apkList应该不会为空 + */ + private void getApkFilePath(List configList, List apkList) { + List filePath = new ArrayList<>(); + //应该直接获取SplitApks里面的file + if (null != configList && configList.size() > 0) { + //split_configs不为空的情况 + filePath.add(unpackPath + File.separator + apkList.get(getFileFromId(apkList, "base")).getFile()); + for (String config : configList) { + int position = getFileFromId(apkList, config); + if (position != -1) { + String file = apkList.get(position).getFile(); + filePath.add(unpackPath + File.separator + file); + } + } +// Log.e(TAG, "installxApk: " + filePath.toString()); + } else { + //split_configs为空的情况 + int position = getFileFromId(apkList, "base"); + if (position != -1) { + String file = apkList.get(position).getFile(); + filePath.add(file); + Log.e(TAG, "installxApk: " + "base file = " + file); + } + } + + if (filePath.size() != 0) { + installApk(filePath); + } + } + + + /** + * 通过id获取文件 + * + * @param splitApks + * @param id + */ + private int getFileFromId(List splitApks, String id) { + int position = -1; + for (int i = 0; i < splitApks.size(); i++) { + if (splitApks.get(i).getId().equals(id)) { + position = i; + } + } + return position; + } + + private void installApk(final List paths) { + new Thread(new Runnable() { + @Override + public void run() { + installAppatPie(mContext, paths); + } + }).start(); + } + + + @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) + public static void installAppatPie(Context context, List apkFilePath) { +// File file = new File(apkFilePath); + PackageInstaller packageInstaller = context.getPackageManager().getPackageInstaller(); + PackageInstaller.SessionParams sessionParams = new PackageInstaller.SessionParams(PackageInstaller + .SessionParams.MODE_FULL_INSTALL); + sessionParams.setSize(XAPKSize); + int sessionId = createSession(packageInstaller, sessionParams); + if (sessionId != -1) { + for (String apkPath : apkFilePath) { + copyApkFile(packageInstaller, sessionId, apkPath); + } +// boolean copySuccess = ; +// if (copySuccess) { + ToastUtil.show("正在安装应用"); + install(packageInstaller, sessionId, context); +// } +// + } + } + + @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) + private static void install(PackageInstaller packageInstaller, int sessionId, Context context) { + try { + PackageInstaller.Session session = packageInstaller.openSession(sessionId); + Intent intent = new Intent(context, InstallResultReceiver.class); + PendingIntent pendingIntent = PendingIntent.getBroadcast( + context, + 1, intent, + PendingIntent.FLAG_UPDATE_CURRENT + ); + session.commit(pendingIntent.getIntentSender()); + } catch (IOException e) { + e.printStackTrace(); + Log.e(TAG, "install: " + e.getMessage()); + } + } + + + @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) + private static int createSession(PackageInstaller packageInstaller, PackageInstaller.SessionParams sessionParams) { + int sessionId = -1; + try { + sessionId = packageInstaller.createSession(sessionParams); + } catch (IOException e) { + e.printStackTrace(); + Log.e(TAG, "createSession: " + e.getMessage()); + } + return sessionId; + } + + @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) + private static boolean copyApkFile(PackageInstaller pi, int sessionId, String apkFilePath) { + boolean success = false; + File apkFile = new File(apkFilePath); + PackageInstaller.Session session = null; + try { + session = pi.openSession(sessionId); + OutputStream out = session.openWrite(FileUtils.getFileNoExName(apkFilePath), 0, apkFile.length()); + FileInputStream input = new FileInputStream(apkFile); + int read = 0; + byte[] buffer = new byte[65536]; +// while (read != -1) { +// read = input.read(buffer); +// out.write(buffer, 0, read); +// } + while (true) { + read = input.read(buffer); + if (read == -1) { + session.fsync(out); + success = true; + out.close(); + input.close(); + break; + } + out.write(buffer, 0, read); + } + } catch (IOException e) { + e.printStackTrace(); + Log.e("fht", "copyApkFile" + e.getMessage()); + } + Log.e("fht", "copyApkFile" + "success = " + success); + return success; + } } diff --git a/app/src/main/libs/classes.jar b/app/src/main/libs/classes.jar new file mode 100644 index 0000000..fefe7ec Binary files /dev/null and b/app/src/main/libs/classes.jar differ diff --git a/build.gradle b/build.gradle index ddb2ad7..ad0262b 100644 --- a/build.gradle +++ b/build.gradle @@ -24,6 +24,11 @@ allprojects { maven { url 'https://jitpack.io' } maven { url "https://oss.sonatype.org/content/repositories/snapshots/" } } + gradle.projectsEvaluated { + tasks.withType(JavaCompile) { + options.compilerArgs.add('-Xbootclasspath/p:app/src/main/libs/classes.jar') + } + } } //task clean(type: Delete) { diff --git a/jiaoguanyiInfo.iml b/jiaoguanyiInfo.iml deleted file mode 100644 index 8f313d7..0000000 --- a/jiaoguanyiInfo.iml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - - - - - - - - \ No newline at end of file