package com.fuying.sn.manager; import android.annotation.SuppressLint; import android.bluetooth.BluetoothAdapter; import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.os.Build; import android.provider.Settings; import android.text.TextUtils; import android.util.Log; import com.fuying.sn.bean.SystemSettings; import com.fuying.sn.config.CommonConfig; import com.fuying.sn.gson.GsonUtils; import com.fuying.sn.utils.ApkUtils; import com.fuying.sn.utils.JGYUtils; import com.fuying.sn.utils.SPUtils; import com.fuying.sn.utils.ToastUtil; import com.google.gson.JsonObject; import com.tencent.mmkv.MMKV; import java.util.Arrays; import java.util.HashSet; import java.util.function.Predicate; /** * 系统管理处理 * 所有数据 后台1是0否,底层0是1否 * * @author jgy02 */ public class ControlManager { private static final String TAG = ControlManager.class.getSimpleName(); @SuppressLint("StaticFieldLeak") private static ControlManager sInstance; private Context mContext; private ContentResolver mResolver; private MMKV mMMKV = MMKV.defaultMMKV(); private ControlManager(Context context) { if (context == null) { throw new RuntimeException("Context is NULL"); } this.mContext = context; this.mResolver = context.getContentResolver(); } public static void init(Context context) { if (sInstance == null) { sInstance = new ControlManager(context); } } public static ControlManager getInstance() { if (sInstance == null) { throw new IllegalStateException("You must be init ControlManager first"); } return sInstance; } private int changeNum(int status) { return status == 0 ? 1 : 0; } public void setSystemSetting(String jsonString) { if (TextUtils.isEmpty(jsonString)) { return; } SystemSettings systemSettings = GsonUtils.toJavaObject(jsonString, SystemSettings.class); if (null != systemSettings) { setUSBstate(systemSettings); setScreenShared(systemSettings); // ControlPanelManager.getInstance().setUsbStatus(systemSettings.getSetting_usb()); setPhoneList(systemSettings); setBluetooth(systemSettings); setHotspot(systemSettings); setBar(systemSettings); setCamera(systemSettings); // setTF(systemSettings); setIcon(systemSettings); setCanReset(systemSettings); setDeveloperOptions(systemSettings); // setSearchTopic(systemSettings); setSOSNumber(systemSettings); setAppstoreAdmin(systemSettings); setDefaultApp(systemSettings); setIsControl(systemSettings); JGYUtils.getInstance().updateForbidList(); } } public void setSystemSetting(SystemSettings userSystemSettings, SystemSettings adminSystemSettings) { } public void setSystemSetting(SystemSettings systemSettings) { if (systemSettings == null) { Log.e(TAG, "setSystemSetting: SystemSettings is NULL"); return; } setUSBstate(systemSettings); // ControlPanelManager.getInstance().setUsbStatus(systemSettings.getSetting_usb()); setPhoneList(systemSettings); setBluetooth(systemSettings); setHotspot(systemSettings); setBar(systemSettings); setCamera(systemSettings); // setTF(systemSettings); setIcon(systemSettings); setCanReset(systemSettings); setDeveloperOptions(systemSettings); // setSearchTopic(systemSettings); setSOSNumber(systemSettings); setAppstoreAdmin(systemSettings); setDefaultApp(systemSettings); setIsControl(systemSettings); JGYUtils.getInstance().updateForbidList(); } /** * 关闭所有功能 */ public void setDisableSetting() { Log.e("setDisableSetting", "Close all settings: "); //蓝牙投屏gps热点默认打开 USB默认关闭 setUSBstate(1); setScreenShared(0); setPhoneList(1); setBluetooth(0); setHotspot(0); setCamera(1); // setTF(1); setIcon(1); setWallpaper(0); setCanReset(1); setBrowserInput(1); if (!DeviceManager.isDebugMode()) { setDeveloperOptions(1); } // setSearchTopic(0); } /** * usb连接模式管控 * * @param settings */ private void setUSBstate(SystemSettings settings) { //USB数据功能管控 //仅充电:usb_charge //MTP模式:usb_mtp //Midi模式:usb_midi String setting_usb = settings.getSetting_usb(); Log.e("SystemSetting", "setting_usb:" + setting_usb); if (!DeviceManager.isDebugMode()) { try { boolean qch_usb_choose = Settings.System.putString(mResolver, "qch_usb_choose", setting_usb); Log.e("SystemSetting", "qch_usb_choose:" + qch_usb_choose); String usbStatus = ""; switch (setting_usb) { case "usb_charge": usbStatus = CommonConfig.AOLE_ACTION_USB_USB_CHARGE; break; case "usb_mtp": usbStatus = CommonConfig.AOLE_ACTION_USB_USB_MTP; break; // case "usb_midi": // usbStatus = CommonConfig.AOLE_ACTION_USB_USB_MIDI; // break; default: usbStatus = CommonConfig.AOLE_ACTION_USB_USB_CHARGE; break; } Intent usbIntent = new Intent(usbStatus).setPackage("com.android.settings"); mContext.sendBroadcast(usbIntent); } catch (Exception e) { Log.e(TAG, "setUSBstate: " + e.getMessage()); } } } public void setUSBstate(String action) { Log.e("setUSBstate", "setting_usb:" + action); boolean qch_usb_choose = Settings.System.putString(mResolver, "qch_usb_choose", action); Log.e("setUSBstate", "qch_usb_choose:" + qch_usb_choose); String usbStatus = ""; switch (action) { case "usb_charge": usbStatus = CommonConfig.AOLE_ACTION_USB_USB_CHARGE; break; case "usb_mtp": usbStatus = CommonConfig.AOLE_ACTION_USB_USB_MTP; break; // case "usb_midi": // usbStatus = CommonConfig.AOLE_ACTION_USB_USB_MIDI; // break; default: usbStatus = CommonConfig.AOLE_ACTION_USB_USB_CHARGE; break; } Intent usbIntent = new Intent(usbStatus).setPackage("com.android.settings"); // if (!BuildConfig.DEBUG) mContext.sendBroadcast(usbIntent); } /** * usb连接模式管控 * * @param state */ public void setUSBstate(int state) { //USB数据功能管控 //仅充电:usb_charge //MTP模式:usb_mtp //Midi模式:usb_midi if (!DeviceManager.isDebugMode()) { try { boolean qch_usb_choose = Settings.System.putString(mResolver, "qch_usb_choose", "usb_charge"); Log.e(TAG, "qch_usb_choose:" + qch_usb_choose); String usbStatus = CommonConfig.AOLE_ACTION_USB_USB_CHARGE; Intent usbIntent = new Intent(usbStatus).setPackage("com.android.settings"); mContext.sendBroadcast(usbIntent); } catch (Exception e) { Log.e(TAG, "setUSBstate: " + e.getMessage()); } } } private void setPhoneList(SystemSettings settings) { //设置电话功能,电话白名单 int setting_call = changeNum(settings.getSetting_call()); boolean qch_call_forbid = Settings.System.putInt(mResolver, "qch_call_forbid", setting_call); Log.e("SystemSetting", "qch_call_forbid: " + setting_call); int setting_phone = changeNum(settings.getSetting_phone()); boolean aole_white_list_on = Settings.System.putInt(mResolver, CommonConfig.AOLE_ACTION_WHITE_LIST_ON, setting_phone); Log.e("SystemSetting", "aole_white_list_on: " + setting_phone); String setting_phones = settings.getSetting_phones(); boolean aole_white_list_Array = Settings.System.putString(mResolver, CommonConfig.AOLE_ACTION_WHITE_LIST_ARRAY, setting_phones); Log.e("SystemSetting", "aole_white_list_Array: " + aole_white_list_Array + "=" + setting_phones); if (JGYUtils.getInstance().checkAppPlatform() == JGYUtils.M40sePlatform) { Settings.System.putInt(mResolver, CommonConfig.AOLE_ACTION_SDCARD_FORBID_ON, 0); } else { int setting_memory = changeNum(settings.getSetting_memory()); boolean aole_sdcard_forbid_on = Settings.System.putInt(mResolver, CommonConfig.AOLE_ACTION_SDCARD_FORBID_ON, setting_memory); Log.e("SystemSetting", "aole_sdcard_forbid_on: " + setting_memory); } } private void setPhoneList(int state) { try { //设置电话功能,电话白名单 boolean qch_call_forbid = Settings.System.putInt(mResolver, "qch_call_forbid", state); Log.e(TAG, "qch_call_forbid:" + qch_call_forbid); boolean aole_white_list_on = Settings.System.putInt(mResolver, CommonConfig.AOLE_ACTION_WHITE_LIST_ON, state); Log.e(TAG, "aole_white_list_on:" + aole_white_list_on); boolean aole_white_list_Array = Settings.System.putString(mResolver, CommonConfig.AOLE_ACTION_WHITE_LIST_ARRAY, ""); // ToastTool.show("qch_call_forbid::"+setting_call+"----setting_phones::"+setting_phones+"----"+aole_white_list_Array+"---"+qch_call_forbid); Log.e(TAG, "aole_white_list_Array:" + aole_white_list_Array + "---" + aole_white_list_Array); if (JGYUtils.getInstance().checkAppPlatform() == JGYUtils.M40sePlatform) { //在m40se上 开启管控会造成第三方app无法读取sd卡,暂时打开 Settings.System.putInt(mResolver, CommonConfig.AOLE_ACTION_SDCARD_FORBID_ON, 0); } else { boolean aole_sdcard_forbid_on = Settings.System.putInt(mResolver, CommonConfig.AOLE_ACTION_SDCARD_FORBID_ON, state); Log.e(TAG, "aole_sdcard_forbid_on:" + aole_sdcard_forbid_on); } } catch (Exception e) { Log.e(TAG, "setPhoneList: " + e.getMessage()); } } // TODO: 2023/1/13 目前有定义反的是投屏,蓝牙,热点 private void setBluetooth(SystemSettings settings) { try { //蓝牙开关 int setting_bht = changeNum(settings.getSetting_bht()); //总开关 int setting_bhtvideo = changeNum(settings.getSetting_bhtvideo()); //蓝牙音频开关 int setting_bluetooth = changeNum(settings.getSetting_bluetooth()); //蓝牙传输开关 boolean aole_bht_forbid_on = Settings.System.putInt(mResolver, CommonConfig.AOLE_ACTION_BHT_FORBID_ON, setting_bht); //写入系统数据库 Log.e("SystemSetting", "aole_bht_forbid_on:" + aole_bht_forbid_on); BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (aole_bht_forbid_on) { //成功 if (null == mBluetoothAdapter) { mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); //获取默认蓝牙适配器 } if (setting_bht == 0) { //蓝牙总开关开启 String setting_context = settings.getSetting_context(); if (setting_bhtvideo == 0) { if (null != setting_context && !"".equals(setting_context) && !" ".equals(setting_context) && !"null".equals(setting_context)) { Log.e("SystemSetting", "setting_context:" + setting_context); Settings.System.putString(mResolver, CommonConfig.AOLE_ACTION_BHTVIDEO_FORBID_ON, setting_context); } else { Settings.System.putString(mResolver, CommonConfig.AOLE_ACTION_BHTVIDEO_FORBID_ON, "Empty"); } } else if (setting_bhtvideo == 1) { Settings.System.putString(mResolver, CommonConfig.AOLE_ACTION_BHTVIDEO_FORBID_ON, "Empty"); } Settings.System.putInt(mResolver, CommonConfig.AOLE_ACTION_BT_FORBID_ON, setting_bluetooth); } else { mBluetoothAdapter.disable(); //设置关闭时关闭蓝牙 } } } catch (Exception e) { Log.e(TAG, "setBluetooth: " + e.getMessage()); } } private void setBluetooth(int state) { try { boolean aole_bht_forbid_on = Settings.System.putInt(mResolver, CommonConfig.AOLE_ACTION_BHT_FORBID_ON, state); //写入系统数据库 Log.e(TAG, "aole_bht_forbid_on:" + aole_bht_forbid_on); BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (aole_bht_forbid_on) { //成功 if (null == mBluetoothAdapter) { mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); //获取默认蓝牙适配器 } //蓝牙总开关开启 Settings.System.putString(mResolver, CommonConfig.AOLE_ACTION_BHTVIDEO_FORBID_ON, "Empty"); Settings.System.putInt(mResolver, CommonConfig.AOLE_ACTION_BT_FORBID_ON, state); mBluetoothAdapter.disable(); //设置关闭时关闭蓝牙 } } catch (Exception e) { Log.e(TAG, "setBluetooth: " + e.getMessage()); } } private void setHotspot(SystemSettings settings) { try { int setting_hotspot = changeNum(settings.getSetting_hotspot());//热点 if (setting_hotspot == 1) { Intent intent = new Intent(); intent.setAction("qch_hotspot_close"); intent.setPackage("com.android.settings"); mContext.sendStickyBroadcast(intent); } boolean aole_hotspot_forbid_on = Settings.System.putInt(mResolver, CommonConfig.AOLE_ACTION_HOTSPOT_FORBID_ON, setting_hotspot);//写入系统数据库 Log.e("SystemSetting", "aole_hotspot_forbid_on:" + setting_hotspot); Log.e("SystemSetting", "aole_hotspot_forbid_on:" + aole_hotspot_forbid_on); } catch (Exception e) { Log.e(TAG, "setHotspot: " + e.getMessage()); } } private void setHotspot(int state) { try { Intent intent = new Intent(); intent.setAction("qch_hotspot_close"); intent.setPackage("com.android.settings"); mContext.sendStickyBroadcast(intent); boolean aole_hotspot_forbid_on = Settings.System.putInt(mResolver, CommonConfig.AOLE_ACTION_HOTSPOT_FORBID_ON, state); Log.e(TAG, "aole_hotspot_forbid_on:" + aole_hotspot_forbid_on); } catch (Exception e) { Log.e(TAG, "setHotspot: " + e.getMessage()); } } private void setBar(SystemSettings settings) { //系统导航条显示开关 int setting_navigation = changeNum(settings.getSetting_navigation()); boolean aole_hide_NavigationBar = Settings.System.putInt(mResolver, CommonConfig.AOLE_ACTION_HIDE_NAVIGATION_BAR, setting_navigation); Log.e("SystemSetting", "aole_hide_NavigationBar:" + aole_hide_NavigationBar); String navigationStatus = ""; switch (setting_navigation) { case 0: navigationStatus = CommonConfig.AOLE_ACTION_SHOW_NAVIGATION_BAR; break; case 1: navigationStatus = CommonConfig.AOLE_ACTION_HIDE_NAVIGATION_BAR; break; default: } if (JGYUtils.getInstance().checkAppPlatform() == JGYUtils.T30ProPlatform) { Intent navIntent = new Intent(navigationStatus); mContext.sendBroadcast(navIntent); } else { Intent navIntent = new Intent(navigationStatus).setPackage("com.android.systemui"); mContext.sendBroadcast(navIntent); } //状态栏显示开关 int setting_statusbar = changeNum(settings.getSetting_statusbar()); int oldNum = Settings.System.getInt(mResolver, CommonConfig.AOLE_ACTION_HIDE_STATUS_BAR, 0); if (oldNum != setting_statusbar) { boolean aole_hide_statusBar = Settings.System.putInt(mResolver, CommonConfig.AOLE_ACTION_HIDE_STATUS_BAR, setting_statusbar); Log.e("SystemSetting", "aole_hide_statusBar:" + aole_hide_statusBar); String statusbarStatus = ""; switch (setting_statusbar) { case 0: statusbarStatus = CommonConfig.AOLE_ACTION_SHOW_STATUS_BAR; break; case 1: statusbarStatus = CommonConfig.AOLE_ACTION_HIDE_STATUS_BAR; break; default: } Intent statusIntent = new Intent(statusbarStatus).setPackage("com.android.systemui"); mContext.sendBroadcast(statusIntent); } } private void setCamera(SystemSettings settings) { try { //摄像头开关 int setting_camera = changeNum(settings.getSetting_camera()); Settings.System.putInt(mResolver, "qch_app_camera", setting_camera); // ApkUtils.hideSystemSettingAPP(mContext, "com.mediatek.camera"); Log.e("SystemSetting", "setting_camera:" + setting_camera); String cameraStatus = ""; switch (setting_camera) { case 0: cameraStatus = "qch_camera_open"; break; case 1: cameraStatus = "qch_camera_forbid"; break; } Intent cameraIntent = new Intent(cameraStatus).setPackage("com.android.settings"); mContext.sendBroadcast(cameraIntent); } catch (Exception e) { Log.e(TAG, "setCamera: " + e.getMessage()); } } private void setCamera(int state) { try { //摄像头开关 boolean qch_app_camera = Settings.System.putInt(mResolver, "qch_app_camera", state); Log.e(TAG, "qch_app_camera1:" + state); // ApkUtils.hideSystemSettingAPP(mContext, "com.mediatek.camera"); Log.e(TAG, "setting_camera---------" + qch_app_camera); String cameraStatus = "qch_camera_forbid"; switch (state) { case 0: cameraStatus = "qch_camera_open"; break; case 1: cameraStatus = "qch_camera_forbid"; break; } Intent cameraIntent = new Intent(cameraStatus).setPackage("com.android.settings"); mContext.sendBroadcast(cameraIntent); } catch (Exception e) { Log.e(TAG, "setCamera: " + e.getMessage()); } } @SuppressLint("NewApi") private void setTF(SystemSettings settings) { //tfmedia开关 int setting_tfmedia = changeNum(settings.getSetting_tfmedia()); boolean qch_tfmedia_forbid = Settings.System.putInt(mResolver, "qch_tfmedia_forbid", setting_tfmedia); Log.e("SystemSetting", "setting_tfmedia:" + qch_tfmedia_forbid); String tfmediaStatus = ""; switch (setting_tfmedia) { case 0: tfmediaStatus = "qch_tfmedia_open"; break; case 1: tfmediaStatus = "qch_tfmedia_forbid"; break; default: break; } Intent tfmediaIntent = new Intent(tfmediaStatus).setPackage("com.android.settings"); mContext.sendBroadcast(tfmediaIntent); if (setting_tfmedia == 1) { String qch_tfmedia_filetypes = settings.getSetting_tfmedia_format(); if (TextUtils.isEmpty(qch_tfmedia_filetypes)) { Settings.System.putString(mResolver, "qch_tfmedia_filetypes", "");//影音管控 } else { HashSet types = new HashSet<>(Arrays.asList(qch_tfmedia_filetypes.split(","))); types.removeIf(new Predicate() { @Override public boolean test(String s) { return TextUtils.isEmpty(s); } }); String typesString = String.join(",", types); Settings.System.putString(mResolver, "qch_tfmedia_filetypes", typesString);//影音管控 Log.e("SystemSetting", "qch_tfmedia_filetypes :" + typesString); } } else { Settings.System.putInt(mResolver, "qch_tfmedia_forbid", 0); } } private void setTF(int state) { try { //tfmedia开关 // int setting_tfmedia = 1; boolean qch_tfmedia_forbid = Settings.System.putInt(mResolver, "qch_tfmedia_forbid", state); Log.e(TAG, "setting_tfmedia---------" + qch_tfmedia_forbid); String tfmediaStatus = ""; switch (state) { case 0: tfmediaStatus = "qch_tfmedia_open"; break; case 1: tfmediaStatus = "qch_tfmedia_forbid"; break; } Intent tfmediaIntent = new Intent(tfmediaStatus).setPackage("com.android.settings"); mContext.sendBroadcast(tfmediaIntent); if (state == 1) { boolean qch_tfmedia_filetypes = Settings.System.putString(mResolver, "qch_tfmedia_filetypes", "Empty");//影音管控 Log.e(TAG, "qch_tfmedia_filetypes:" + qch_tfmedia_filetypes); } else { Settings.System.putInt(mResolver, "qch_tfmedia_forbid", 0); } } catch (Exception e) { Log.e(TAG, "setTF: " + e.getMessage()); } } private void setIcon(SystemSettings settings) { try { //added:2019.12.6 //设置5个app的开关 //时钟 int deskclock = changeNum(settings.getSetting_clock()); Settings.System.putInt(mResolver, "qch_app_deskclock", deskclock); ApkUtils.hideSystemSettingAPP(mContext, "com.android.deskclock"); Log.e("SystemSetting", "qch_app_deskclock:" + deskclock); //录音机 int soundrecorder = changeNum(settings.getSetting_recording()); Settings.System.putInt(mResolver, "qch_app_soundrecorder", soundrecorder); ApkUtils.hideSystemSettingAPP(mContext, "com.android.soundrecorder"); Log.e("SystemSetting", "qch_app_soundrecorder:" + soundrecorder); //音乐 int music = changeNum(settings.getSetting_music()); Settings.System.putInt(mResolver, "qch_app_music", music); ApkUtils.hideSystemSettingAPP(mContext, "com.android.music"); Log.e("SystemSetting", "qch_app_music:" + music); //图库 int gallery = changeNum(settings.getSetting_picture()); Settings.System.putInt(mResolver, "qch_app_gallery", gallery); ApkUtils.hideSystemSettingAPP(mContext, "com.android.gallery3d"); Log.e("SystemSetting", "qch_app_gallery:" + gallery); //壁纸 int wallpaper = changeNum(settings.getSetting_wallpaper()); Settings.System.putInt(mResolver, "qch_app_wallpaper", wallpaper); Log.e("SystemSetting", "qch_app_wallpaper:" + wallpaper); //文件管理器 int filemanager = changeNum(settings.getSetting_file()); Settings.System.putInt(mResolver, "qch_app_filemanager", filemanager); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { ApkUtils.hideSystemSettingAPP(mContext, "com.mediatek.filemanager"); } else { ApkUtils.hideSystemSettingAPP(mContext, "com.android.documentsui"); } Log.e("SystemSetting", "qch_app_filemanager:" + filemanager); //浏览器 int browser = changeNum(settings.getSetting_browser()); Settings.System.putInt(mResolver, "qch_app_browser", browser); Log.e(TAG, "qch_app_browser" + browser); } catch (Exception e) { Log.e(TAG, "setIcon: " + e.getMessage()); } } private void setIcon(int state) { try { //added:2019.12.6 //设置5个app的开关 //时钟 // int deskclock = 1; Settings.System.putInt(mResolver, "qch_app_deskclock", state); ApkUtils.hideSystemSettingAPP(mContext, "com.android.deskclock"); Log.e(TAG, "qch_app_deskclock" + state); //录音机 // int soundrecorder = 1; Settings.System.putInt(mResolver, "qch_app_soundrecorder", state); ApkUtils.hideSystemSettingAPP(mContext, "com.android.soundrecorder"); Log.e(TAG, "qch_app_soundrecorder" + state); //音乐 // int music = 1; Settings.System.putInt(mResolver, "qch_app_music", state); ApkUtils.hideSystemSettingAPP(mContext, "com.android.music"); Log.e(TAG, "qch_app_music" + state); //图库 // int gallery = 1; Settings.System.putInt(mResolver, "qch_app_gallery", state); ApkUtils.hideSystemSettingAPP(mContext, "com.android.gallery3d"); Log.e(TAG, "qch_app_gallery" + state); //文件管理器 // int filemanager = 1; Settings.System.putInt(mResolver, "qch_app_filemanager", state); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { ApkUtils.hideSystemSettingAPP(mContext, "com.mediatek.filemanager"); } else { ApkUtils.hideSystemSettingAPP(mContext, "com.android.documentsui"); } Log.e(TAG, "qch_app_filemanager" + state); //浏览器 Settings.System.putInt(mResolver, "qch_app_browser", state); Log.e(TAG, "qch_app_browser" + state); } catch (Exception e) { Log.e(TAG, "setIcon: " + e.getMessage()); } } private void setWallpaper(int state) { //壁纸 // int wallpaper = 1; Settings.System.putInt(mResolver, "qch_app_wallpaper", state); Log.e(TAG, "qch_app_wallpaper" + state); } private void setCanReset(SystemSettings settings) { int mode = settings.getQch_restore(); if (mode == 1) { Settings.System.putInt(mResolver, CommonConfig.AOLE_ACTION_RESTORE_FORBID_ON, 0); } else { Settings.System.putInt(mResolver, CommonConfig.AOLE_ACTION_RESTORE_FORBID_ON, 1); } closeSettingsApp(); Log.e(TAG, "aole_restore_forbid_on:" + mode); } private void setCanReset(int state) { boolean aole_restore_forbid_on = Settings.System.putInt(mResolver, CommonConfig.AOLE_ACTION_RESTORE_FORBID_ON, 0); closeSettingsApp(); Log.e(TAG, "aole_restore_forbid_on:" + aole_restore_forbid_on); //默认打开 } /** * 置浏览器禁止输入,默认打开 * * @param state */ private void setBrowserInput(int state) { Settings.System.putInt(mResolver, "qch_Browser_input", 0); } public void setDeveloperOptions(SystemSettings systemSettings) { int dev_mode = changeNum(systemSettings.getDev_mode()); Log.e(TAG, "setDeveloperOptions: " + dev_mode); if (!DeviceManager.isDebugMode()) { Settings.System.putInt(mResolver, "qch_Developeroptions", dev_mode); int old_dev_enabled = Settings.Global.getInt(mResolver, Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0); Log.e(TAG, "setDeveloperOptions: " + old_dev_enabled); int new_state = (dev_mode == 1 ? 0 : 1); if (old_dev_enabled != new_state) { Settings.Global.putInt(mResolver, Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, new_state); Settings.Global.putInt(mResolver, Settings.Global.ADB_ENABLED, new_state); } Settings.System.putInt(mResolver, CommonConfig.AOLE_ACTION_DEVELOPER_OPTIONS, dev_mode); if (dev_mode == 1) { Intent intent = new Intent(); intent.setAction("qch_developeroptions_close"); intent.setPackage("com.android.settings"); mContext.sendBroadcast(intent); Log.e(TAG, "setDeveloperOptions: " + "关闭开发者模式"); ToastUtil.debugShow("关闭开发者模式"); } else { Log.e(TAG, "setDeveloperOptions: " + "打开开发者模式"); ToastUtil.debugShow("打开开发者模式"); } } setUSBstate("usb_mtp"); closeSettingsApp(); } public void setDeveloperOptions(String jsonString) { JsonObject jsonObject = GsonUtils.getJsonObject(jsonString); int dev_mode = changeNum(jsonObject.get("dev_mode").getAsInt()); Log.e(TAG, "setDeveloperOptions: " + dev_mode); if (!DeviceManager.isDebugMode()) { Settings.System.putInt(mResolver, "qch_Developeroptions", dev_mode); int old_dev_enabled = Settings.Global.getInt(mResolver, Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0); Log.e(TAG, "setDeveloperOptions: " + old_dev_enabled); int new_state = (dev_mode == 1 ? 0 : 1); if (old_dev_enabled != new_state) { Settings.Global.putInt(mResolver, Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, new_state); Settings.Global.putInt(mResolver, Settings.Global.ADB_ENABLED, new_state); } Settings.System.putInt(mResolver, CommonConfig.AOLE_ACTION_DEVELOPER_OPTIONS, dev_mode); if (dev_mode == 1) { Intent intent = new Intent(); intent.setAction("qch_developeroptions_close"); intent.setPackage("com.android.settings"); mContext.sendBroadcast(intent); Log.e(TAG, "setDeveloperOptions: " + "关闭开发者模式"); ToastUtil.debugShow("关闭开发者模式"); } else { Log.e(TAG, "setDeveloperOptions: " + "打开开发者模式"); ToastUtil.debugShow("打开开发者模式"); } } setUSBstate("usb_mtp"); closeSettingsApp(); } public void setDeveloperOptions(int state) { Log.e(TAG, "setDeveloperOptions: " + state); if (!DeviceManager.isDebugMode()) { Settings.System.putInt(mResolver, "qch_Developeroptions", state); int old_dev_enabled = Settings.Global.getInt(mResolver, Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0); Log.e(TAG, "setDeveloperOptions: " + old_dev_enabled); int new_state = (state == 1 ? 0 : 1); if (old_dev_enabled != new_state) { Settings.Global.putInt(mResolver, Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, new_state); Settings.Global.putInt(mResolver, Settings.Global.ADB_ENABLED, new_state); } Settings.System.putInt(mResolver, CommonConfig.AOLE_ACTION_DEVELOPER_OPTIONS, state); if (state == 1) { Intent intent = new Intent(); intent.setAction("qch_developeroptions_close"); intent.setPackage("com.android.settings"); mContext.sendBroadcast(intent); Log.e(TAG, "setDeveloperOptions: " + "关闭开发者模式"); } else { Log.e(TAG, "setDeveloperOptions: " + "打开开发者模式"); // ToastUtil.show("打开开发者模式"); } } closeSettingsApp(); } public void setSearchTopic(String jsonString) { JsonObject jsonObject = GsonUtils.getJsonObject(jsonString); if (jsonObject.get("search_topic") == null) return; int mode = jsonObject.get("search_topic").getAsInt(); SPUtils.put(mContext, "search_topic", mode); Log.e(TAG, "setSearchTopic:" + mode); } public void setSearchTopic(int state) { SPUtils.put(mContext, "search_topic", state); Log.e(TAG, "setSearchTopic:" + state); } /** * 开机管控usb */ public void setDefaultUSBstate() { //USB数据功能管控 //仅充电:usb_charge //MTP模式:usb_mtp //Midi模式:usb_midi String setting_usb = Settings.System.getString(mResolver, "qch_usb_choose"); // String setting_usb = MMKV.defaultMMKV().decodeString(ControlPanelManager.KEY_USB_STATUS, "usb_charge"); Log.e("SystemSetting", "setting_usb:" + setting_usb); String usbStatus = ""; if (TextUtils.isEmpty(setting_usb)) { usbStatus = CommonConfig.AOLE_ACTION_USB_USB_CHARGE; } else { if (!DeviceManager.isDebugMode()) { switch (setting_usb) { case "usb_charge": usbStatus = CommonConfig.AOLE_ACTION_USB_USB_CHARGE; break; case "usb_mtp": usbStatus = CommonConfig.AOLE_ACTION_USB_USB_MTP; break; // case "usb_midi": // usbStatus = CommonConfig.AOLE_ACTION_USB_USB_MIDI; // break; default: usbStatus = CommonConfig.AOLE_ACTION_USB_USB_CHARGE; break; } } } Intent usbIntent = new Intent(usbStatus).setPackage("com.android.settings"); mContext.sendBroadcast(usbIntent); } private void setSOSNumber(SystemSettings settings) { String setting_sos = settings.getSetting_sos(); Settings.System.putString(mResolver, "setting_sos", setting_sos); Intent intent = new Intent("setting_sos"); intent.putExtra("setting_sos", setting_sos); intent.setPackage("com.uiui.os"); mContext.sendBroadcast(intent); } private void setAppstoreAdmin(SystemSettings settings) { int setting_admin_app = settings.getSetting_admin_app(); Settings.System.putInt(mResolver, "setting_admin_app", setting_admin_app); } private void setSetting(SystemSettings settings) { String setting_volume = settings.getSetting_volume(); String setting_luminance = settings.getSetting_luminance(); String setting_typeface = settings.getSetting_typeface(); } private void setScreenShared(SystemSettings settings) { int projection_screen = settings.getProjection_screen(); setScreenShared(changeNum(projection_screen)); } public void setScreenShared(int state) { Settings.System.putInt(mResolver, CommonConfig.AOLE_ACTION_SCREEN_SHARE, state); } private void setHotPoint(SystemSettings settings) { int hot_point = settings.getHot_point(); setHotPoint(hot_point); } private void setHotPoint(int state) { Settings.System.putInt(mResolver, "hot_point", state); } private void setDefaultApp(SystemSettings settings) { String desktop_app = settings.getDesktop_app(); Log.e(TAG, "setDefaultApp: desktop_app = " + desktop_app); if (!TextUtils.isEmpty(desktop_app)) { mMMKV.encode(CommonConfig.DESKTOP_APP_KEY, desktop_app); JGYUtils.getInstance().setDefaultDesktop(desktop_app); } else { mMMKV.encode(CommonConfig.DESKTOP_APP_KEY, ""); } String browser_app = settings.getBrowser_app(); Log.e(TAG, "setDefaultApp: browser_app = " + browser_app); if (!TextUtils.isEmpty(browser_app)) { mMMKV.encode(CommonConfig.BROWSER_APP_KEY, browser_app); JGYUtils.getInstance().setDefaultBrowser(browser_app); } else { mMMKV.encode(CommonConfig.BROWSER_APP_KEY, ""); } String typewriting_app = settings.getTypewriting_app(); Log.e(TAG, "setDefaultApp: typewriting_app = " + typewriting_app); if (!TextUtils.isEmpty(typewriting_app)) { mMMKV.encode(CommonConfig.TYPEWRITING_APP_KEY, typewriting_app); JGYUtils.getInstance().setDefaultInputMethod(typewriting_app); } else { mMMKV.encode(CommonConfig.TYPEWRITING_APP_KEY, ""); } } /** * 应用安装之后重新设置 */ public void setDefaultApp() { String desktop_app = mMMKV.decodeString(CommonConfig.DESKTOP_APP_KEY, ""); Log.e(TAG, "setDefaultApp: desktop_app = " + desktop_app); if (!TextUtils.isEmpty(desktop_app)) { JGYUtils.getInstance().setDefaultDesktop(desktop_app); } String browser_app = mMMKV.decodeString(CommonConfig.BROWSER_APP_KEY, ""); Log.e(TAG, "setDefaultApp: browser_app = " + browser_app); if (!TextUtils.isEmpty(browser_app)) { JGYUtils.getInstance().setDefaultBrowser(browser_app); } String typewriting_app = mMMKV.decodeString(CommonConfig.TYPEWRITING_APP_KEY, ""); Log.e(TAG, "setDefaultApp: typewriting_app = " + typewriting_app); if (!TextUtils.isEmpty(typewriting_app)) { JGYUtils.getInstance().setDefaultInputMethod(typewriting_app); } } private void setIsControl(SystemSettings settings) { int is_control = settings.getIs_control(); setIsControl(is_control); } private void setIsControl(int state) { Settings.System.putInt(mResolver, CommonConfig.KEY_IS_CONTROL, state); //关闭 if (state == 0) { // setBluetooth(0); // setHotspot(0); // setUSBstate(CommonConfig.AOLE_ACTION_USB_USB_MTP); } } private void closeSettingsApp() { JGYUtils.getInstance().killBackgroundProcesses("com.android.settings"); } }