Files
CubeAoleyunSN/app/src/main/java/com/aoleyun/sn/utils/SysSettingUtils.java

1113 lines
49 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package com.aoleyun.sn.utils;
import android.annotation.SuppressLint;
import android.app.StatusBarManager;
import android.bluetooth.BluetoothAdapter;
import android.content.Context;
import android.content.Intent;
import android.cube.SuperPower;
import android.os.Build;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
import com.aoleyun.sn.BuildConfig;
import com.aoleyun.sn.activity.main.MainActivity;
import com.aoleyun.sn.bean.SnSetting;
import com.aoleyun.sn.comm.CommonConfig;
import com.aoleyun.sn.comm.JGYActions;
import com.aoleyun.sn.gson.GsonUtils;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.hjq.toast.Toaster;
import com.tencent.mmkv.MMKV;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
public class SysSettingUtils {
private static final String TAG = SysSettingUtils.class.getSimpleName();
public SysSettingUtils() {
}
public SysSettingUtils(Context context) {
}
private static int changeNum(int status) {
return status == 0 ? 1 : 0;
}
public static void setSystemSetting(Context context, String jsonObj) {
if (null == context) {
throw new RuntimeException("Context it's null");
}
JsonObject jsonObject = GsonUtils.getJsonObject(jsonObj);
setPhoneList(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);
String navJsonString = jsonObject.get("setting_nav").getAsString();
JsonObject navJson = JsonParser.parseString(navJsonString).getAsJsonObject();
SPUtils.put(context, JGYActions.ACTION_STATUSBAR_STATUS, navJsonString);
setStatusBar(context, navJson);
setBrowserInput(context, jsonObject);
// TODO: 2022/4/11 不是酷比定制的会报错,无法抛出异常
setUSBstate(context, jsonObject);
setAdminApp(context, jsonObject);
setSystemAppDisable(context, jsonObject);
setNotification(context, jsonObject);
setPanelShow(context, jsonObject);
}
/**
* @param context 关闭所有功能
*/
public static void setDisableSetting(Context context) {
Toaster.debugShow("关闭所有功能");
Log.e("setDisableSetting", "Close all settings: ");
setPhoneList(context, 1);
setUSBstate(context, 1);
if (JGYUtils.getInstance().getAppPlatform().equals(JGYUtils.YXPD1TAG)
|| JGYUtils.getInstance().getAppPlatform().equals(JGYUtils.C2Tag)
) {
setBluetooth(context, 0);
} else {
setBluetooth(context, 1);
}
setHotspot(context, 1);
setBar(context, 1);
setCamera(context, 1);
setTF(context, 1);
setIcon(context, 0);
setWallpaper(context, 0);
setCanReset(context, 0);
setAutoTime(context, 1);
setBrowserInput(context, 1);
if (!BuildConfig.DEBUG) {
// JGYUtils.getInstance().setDeveloperOptions(0);
}
setStatusBar(context, 1);
setAdminApp(context, 1);
setSystemAppDisable(context, 0);
setNotification(context, 0);
}
/**
* @param context 开启所有功能
*/
public static void setEnableSetting(Context context) {
Toaster.debugShow("打开所有功能");
setPhoneList(context, 0);
if (JGYUtils.C2Tag.equalsIgnoreCase(JGYUtils.getInstance().getAppPlatform())) {
openMtp(context);
}
// setUSBstate(context, 0);
setBluetooth(context, 0);
setHotspot(context, 0);
setBar(context, 0);
setCamera(context, 0);
setTF(context, 0);
setIcon(context, 0);
setWallpaper(context, 0);
setCanReset(context, 0);
setAutoTime(context, 0);
setBrowserInput(context, 0);
// JGYUtils.getInstance().setDeveloperOptions(1);
setStatusBar(context, 0);
setAdminApp(context, 0);
setSystemAppDisable(context, 0);
setNotification(context, 1);
}
private static void openMtp(Context context) {
String usbStatus = CommonConfig.AOLE_ACTION_USB_USB_MTP;
Intent usbIntent = new Intent(usbStatus);
context.sendBroadcast(usbIntent);
}
private static void setPhoneList(Context context, int state) {
try {
//设置电话功能,电话白名单
boolean qch_call_forbid = Settings.System.putInt(context.getContentResolver(), "qch_call_forbid", state);
Log.e(TAG, "qch_call_forbid:" + qch_call_forbid);
boolean aole_white_list_on = Settings.System.putInt(context.getContentResolver(), 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(context.getContentResolver(), 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);
boolean aole_sdcard_forbid_on = Settings.System.putInt(context.getContentResolver(), 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());
}
}
private static void setPhoneList(Context context, JsonObject jsonObject) {
try {
//设置电话功能,电话白名单
//电话通话开关
int setting_call = changeNum(jsonObject.get("setting_call").getAsInt());
boolean qch_call_forbid = Settings.System.putInt(context.getContentResolver(), "qch_call_forbid", setting_call);
Log.e(TAG, "qch_call_forbid:" + qch_call_forbid);
//电话白名单开关
int setting_phone = changeNum(jsonObject.get("setting_phone").getAsInt());
boolean aole_white_list_on = Settings.System.putInt(context.getContentResolver(), CommonConfig.AOLE_ACTION_WHITE_LIST_ON, setting_phone);
Log.e(TAG, "aole_white_list_on:" + aole_white_list_on);
//白名单列表
if (setting_phone == 1) {
boolean aole_white_list_Array = Settings.System.putString(context.getContentResolver(), CommonConfig.AOLE_ACTION_WHITE_LIST_ARRAY, "empty");
// 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);
} else {
String setting_phones = jsonObject.get("setting_phones").getAsString();
boolean aole_white_list_Array = Settings.System.putString(context.getContentResolver(), CommonConfig.AOLE_ACTION_WHITE_LIST_ARRAY, setting_phones);
// 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 + "---" + setting_phones);
}
//存储卡
int setting_memory = changeNum(jsonObject.get("setting_memory").getAsInt());
JGYUtils.getInstance().setSDOTGEnable(setting_memory == 0);
boolean aole_sdcard_forbid_on = Settings.System.putInt(context.getContentResolver(), CommonConfig.AOLE_ACTION_SDCARD_FORBID_ON, setting_memory);
Log.e(TAG, "aole_sdcard_forbid_on:" + aole_sdcard_forbid_on);
} catch (Exception e) {
Log.e(TAG, "setPhoneList: " + e.getMessage());
}
}
private static void setUSBstate(Context context, int state) {
//USB数据功能管控
//仅充电usb_charge
//MTP模式usb_mtp
//Midi模式usb_midi
if (!BuildConfig.DEBUG) {
try {
String oldUsb = Settings.System.getString(context.getContentResolver(), "aole_usb_choose");
if ("usb_charge".equals(oldUsb)) {
Log.e(TAG, "setUSBstate: oldUsb = " + oldUsb + " no changed , skip");
return;
}
boolean aole_usb_choose = Settings.System.putString(context.getContentResolver(), "aole_usb_choose", "usb_charge");
Log.e(TAG, "aole_usb_choose:" + aole_usb_choose);
String usbStatus = CommonConfig.AOLE_ACTION_USB_USB_CHARGE;
if (JGYUtils.getInstance().checkAppPlatform() == JGYUtils.AH6016Platform) {
usbStatus = CommonConfig.AOLE_ACTION_USB_USB_MTP;
}
Intent usbIntent = new Intent(usbStatus);
if (JGYUtils.getInstance().checkAppPlatform() == JGYUtils.TeclastP20sPlatform
|| JGYUtils.getInstance().checkAppPlatform() == JGYUtils.AH6016Platform
) {
usbIntent.setPackage("com.android.settings");
}
context.sendBroadcast(usbIntent);
SuperPower mService = (SuperPower) context.getSystemService("mdm");
mService.setUsbDataDisabled(true);
} catch (NoClassDefFoundError | Exception e) {
Log.e(TAG, "setUSBstate: " + e.getMessage());
}
}
}
private static void setUSBstate(Context context, JsonObject jsonObject) {
//USB数据功能管控
//仅充电usb_charge
//MTP模式usb_mtp
//Midi模式usb_midi
String setting_usb = jsonObject.get("setting_usb").getAsString();
String oldUsb = Settings.System.getString(context.getContentResolver(), "aole_usb_choose");
if (setting_usb.equals(oldUsb)) {
Log.e(TAG, "setUSBstate: oldUsb = " + oldUsb + " no changed , skip");
return;
}
if (!BuildConfig.DEBUG) {
if (JGYUtils.isCubeDevice()) {
SuperPower mService = (SuperPower) context.getSystemService("mdm");
switch (setting_usb) {
case "usb_charge":
mService.setUsbDataDisabled(true);
break;
case "usb_mtp":
mService.setUsbDataDisabled(false);
break;
default:
}
} else {
boolean aole_usb_choose = Settings.System.putString(context.getContentResolver(), "aole_usb_choose", setting_usb);
Log.e("setUSBstate", "aole_usb_choose: " + aole_usb_choose);
String usbStatus;
switch (setting_usb) {
default:
case "usb_charge":
usbStatus = CommonConfig.AOLE_ACTION_USB_USB_CHARGE;
JGYUtils.getInstance().setMtpEnable(false);
break;
case "usb_mtp":
usbStatus = CommonConfig.AOLE_ACTION_USB_USB_MTP;
JGYUtils.getInstance().setMtpEnable(true);
break;
case "usb_midi":
usbStatus = CommonConfig.AOLE_ACTION_USB_USB_MIDI;
JGYUtils.getInstance().setMtpEnable(false);
break;
}
Intent usbIntent = new Intent(usbStatus);
if (JGYUtils.getInstance().checkAppPlatform() == JGYUtils.TeclastP20sPlatform
|| JGYUtils.getInstance().checkAppPlatform() == JGYUtils.AH6016Platform
) {
usbIntent.setPackage("com.android.settings");
}
context.sendBroadcast(usbIntent);
}
}
}
/**
* @param context
* @param state 1关闭 0打开
*/
private static void setBluetoothTransmission(Context context, int state) {
Log.e(TAG, "setBluetoothTransmission: setting_bluetooth = " + state);
int old_setting_bluetooth = Settings.System.getInt(context.getContentResolver(), CommonConfig.AOLE_ACTION_BT_FORBID_ON, 1);
if (old_setting_bluetooth != state) {
Settings.System.putInt(context.getContentResolver(), CommonConfig.AOLE_ACTION_BT_FORBID_ON, state);
} else {
Log.e(TAG, "setBluetoothTransmission: setting_bluetooth no changed");
}
}
/**
* @param context
* @param state 1关闭 0打开
*/
private static void setBluetooth(Context context, int state) {
Log.e(TAG, "setBluetooth: state = " + state);
MMKV mmkv = MMKV.mmkvWithID(CommonConfig.MMKV_ID, MMKV.MULTI_PROCESS_MODE);
int old_setting_bht = Settings.System.getInt(context.getContentResolver(), CommonConfig.AOLE_ACTION_BHT_FORBID_ON, 1);
int old_setting_bluetooth = Settings.System.getInt(context.getContentResolver(), CommonConfig.AOLE_ACTION_BT_FORBID_ON, 1);
int old_setting_bhtvideo = mmkv.decodeInt(CommonConfig.AOLE_ACTION_BHTVIDEO_FORBID_ON, 1);
if (old_setting_bht != state) {
if (state == 1) {//总开关关闭
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
mBluetoothAdapter.disable();
}
Settings.System.putInt(context.getContentResolver(), CommonConfig.AOLE_ACTION_BHT_FORBID_ON, state);
} else {
Log.e(TAG, "setBluetooth: setting_bht no changed");
}
if (old_setting_bluetooth != state) {
Settings.System.putInt(context.getContentResolver(), CommonConfig.AOLE_ACTION_BT_FORBID_ON, state);
} else {
Log.e(TAG, "setBluetooth: setting_bluetooth no changed");
}
if (old_setting_bhtvideo != state) {
mmkv.encode(CommonConfig.AOLE_ACTION_BHTVIDEO_FORBID_ON, state);
if (state == 1) {
Settings.System.putString(context.getContentResolver(), CommonConfig.AOLE_ACTION_BHTVIDEO_FORBID_ON, "Empty");
}
} else {
Log.e(TAG, "setBluetooth: setting_bhtvideo no changed");
}
JGYUtils.getInstance().setBluetoothEnable(state == 0);
}
/**
* @param context
* @param jsonObject 1关闭 0打开
*/
private static void setBluetooth(Context context, JsonObject jsonObject) {
MMKV mmkv = MMKV.mmkvWithID(CommonConfig.MMKV_ID, MMKV.MULTI_PROCESS_MODE);
//需要转换
//总开关
int setting_bht = changeNum(jsonObject.get("setting_bht").getAsInt());
Log.e(TAG, "setBluetooth: setting_bht = " + setting_bht);
//蓝牙数据功能管控
int setting_bluetooth = changeNum(jsonObject.get("setting_bluetooth").getAsInt());
Log.e(TAG, "setBluetooth: setting_bluetooth = " + setting_bluetooth);
//蓝牙音频功能管控
int setting_bhtvideo = changeNum(jsonObject.get("setting_bhtvideo").getAsInt());
Log.e(TAG, "setBluetooth: setting_bhtvideo = " + setting_bhtvideo);
int old_setting_bht = Settings.System.getInt(context.getContentResolver(), CommonConfig.AOLE_ACTION_BHT_FORBID_ON, 1);
int old_setting_bluetooth = Settings.System.getInt(context.getContentResolver(), CommonConfig.AOLE_ACTION_BT_FORBID_ON, 1);
int old_setting_bhtvideo = mmkv.decodeInt(CommonConfig.AOLE_ACTION_BHTVIDEO_FORBID_ON, 1);
if (old_setting_bht != setting_bht) {
if (setting_bht == 1) {//总开关关闭
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
mBluetoothAdapter.disable();
}
Settings.System.putInt(context.getContentResolver(), CommonConfig.AOLE_ACTION_BHT_FORBID_ON, setting_bht);
} else {
Log.e(TAG, "setBluetooth: setting_bht no changed");
}
if (old_setting_bluetooth != setting_bluetooth) {
Settings.System.putInt(context.getContentResolver(), CommonConfig.AOLE_ACTION_BT_FORBID_ON, setting_bluetooth);
} else {
Log.e(TAG, "setBluetooth: setting_bluetooth no changed");
}
if (old_setting_bhtvideo != setting_bhtvideo) {
mmkv.encode(CommonConfig.AOLE_ACTION_BHTVIDEO_FORBID_ON, setting_bhtvideo);
if (setting_bhtvideo == 0) {
if (jsonObject.get("setting_context").isJsonNull()) {
String setting_context = jsonObject.get("setting_context").getAsString();
if (null != setting_context && !"".equals(setting_context) && !" ".equals(setting_context) && !"null".equals(setting_context)) {
Log.e(TAG, "setting_context:" + setting_context);
Settings.System.putString(context.getContentResolver(), CommonConfig.AOLE_ACTION_BHTVIDEO_FORBID_ON, setting_context);
} else {
Settings.System.putString(context.getContentResolver(), CommonConfig.AOLE_ACTION_BHTVIDEO_FORBID_ON, "Empty");
}
}
} else if (setting_bhtvideo == 1) {
Settings.System.putString(context.getContentResolver(), CommonConfig.AOLE_ACTION_BHTVIDEO_FORBID_ON, "Empty");
}
} else {
Log.e(TAG, "setBluetooth: setting_bhtvideo no changed");
}
JGYUtils.getInstance().setBluetoothEnable(setting_bht == 0);
}
private static void setHotspot(Context context, int state) {
try {
Intent intent = new Intent();
intent.setAction("qch_hotspot_close");
intent.setPackage("com.android.settings");
context.sendStickyBroadcast(intent);
boolean aole_hotspot_forbid_on = Settings.System.putInt(context.getContentResolver(), 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 static void setHotspot(Context context, JsonObject jsonObject) {
try {
int setting_hotspot = changeNum(jsonObject.get("setting_hotspot").getAsInt());//热点
if (setting_hotspot == 1) {
Intent intent = new Intent();
intent.setAction("qch_hotspot_close");
intent.setPackage("com.android.settings");
context.sendStickyBroadcast(intent);
}
boolean aole_hotspot_forbid_on = Settings.System.putInt(context.getContentResolver(), CommonConfig.AOLE_ACTION_HOTSPOT_FORBID_ON, setting_hotspot);
Log.e(TAG, "aole_hotspot_forbid_on---------" + setting_hotspot);
Log.e(TAG, "aole_hotspot_forbid_on---------" + aole_hotspot_forbid_on);
} catch (Exception e) {
Log.e(TAG, "setHotspot: " + e.getMessage());
}
}
private static void setBar(Context context, int state) {
//系统导航条显示开关
int setting_navigation = 0;
//写入到系统不涉及任何管控,因为之前调用会频繁隐藏显示
boolean aole_hide_NavigationBar = Settings.System.putInt(context.getContentResolver(), CommonConfig.AOLE_ACTION_HIDE_NAVIGATION_BAR, setting_navigation);
Log.e(TAG, "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:
}
Intent navIntent = new Intent(navigationStatus);
// Intent navIntent = new Intent(navigationStatus).setPackage("com.android.systemui");
context.sendBroadcast(navIntent);
//状态栏显示开关
int setting_statusbar = 0;
int oldNum = Settings.System.getInt(context.getContentResolver(), CommonConfig.AOLE_ACTION_HIDE_STATUS_BAR, 0);
if (oldNum != setting_statusbar) {
//写入到系统不涉及任何管控,因为之前调用会频繁隐藏显示
boolean aole_hide_statusBar = Settings.System.putInt(context.getContentResolver(), CommonConfig.AOLE_ACTION_HIDE_STATUS_BAR, setting_statusbar);
Log.e(TAG, "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);
// Intent statusIntent = new Intent(statusbarStatus).setPackage("com.android.systemui");
context.sendBroadcast(statusIntent);
}
}
private static void setBar(Context context, JsonObject jsonObject) {
//系统导航条显示开关
int setting_navigation = changeNum(jsonObject.get("setting_navigation").getAsInt());
//写入到系统不涉及任何管控,因为之前调用会频繁隐藏显示
boolean aole_hide_NavigationBar = Settings.System.putInt(context.getContentResolver(), CommonConfig.AOLE_ACTION_HIDE_NAVIGATION_BAR, setting_navigation);
Log.e(TAG, "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:
}
// Intent navIntent = new Intent(navigationStatus).setPackage("com.android.systemui");
Intent navIntent = new Intent(navigationStatus);
context.sendBroadcast(navIntent);
//状态栏显示开关
int setting_statusbar = changeNum(jsonObject.get("setting_statusbar").getAsInt());
// int oldNum = Settings.System.getInt(context.getContentResolver(), CommonConfig.AOLE_ACTION_HIDE_STATUS_BAR, 0);
// if (oldNum != setting_statusbar) {
//写入到系统不涉及任何管控,因为之前调用会频繁隐藏显示
boolean aole_hide_statusBar = Settings.System.putInt(context.getContentResolver(), CommonConfig.AOLE_ACTION_HIDE_STATUS_BAR, setting_statusbar);
Log.e(TAG, "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);
// Intent statusIntent = new Intent(statusbarStatus).setPackage("com.android.systemui");
context.sendBroadcast(statusIntent);
// }
}
private static void setCamera(Context context, int state) {
try {
//摄像头开关
boolean qch_app_camera = Settings.System.putInt(context.getContentResolver(), "qch_app_camera", 0);
Log.e(TAG, "qch_app_camera1:" + state);
// ApkUtils.hideSystemSettingAPP(context, "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");
context.sendBroadcast(cameraIntent);
} catch (Exception e) {
Log.e(TAG, "setCamera: " + e.getMessage());
}
}
private static void setCamera(Context context, JsonObject jsonObject) {
try {
//摄像头开关
int setting_camera = changeNum(jsonObject.get("setting_camera").getAsInt());
Settings.System.putInt(context.getContentResolver(), "qch_app_camera", setting_camera);
Log.e(TAG, "qch_app_camera2:" + setting_camera);
// ApkUtils.hideSystemSettingAPP(context, "com.mediatek.camera");
Log.e(TAG, "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");
context.sendBroadcast(cameraIntent);
JGYUtils.getInstance().setCameraEnable(setting_camera == 1);
} catch (Exception e) {
Log.e(TAG, "setCamera: " + e.getMessage());
}
}
private static void setTF(Context context, int state) {
try {
//tfmedia开关
// int setting_tfmedia = 1;
boolean qch_tfmedia_forbid = Settings.System.putInt(context.getContentResolver(), "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");
context.sendBroadcast(tfmediaIntent);
if (state == 1) {
boolean qch_tfmedia_filetypes = Settings.System.putString(context.getContentResolver(), "qch_tfmedia_filetypes", "Empty");//影音管控
Log.e(TAG, "qch_tfmedia_filetypes:" + qch_tfmedia_filetypes);
} else {
Settings.System.putInt(context.getContentResolver(), "qch_tfmedia_forbid", 0);
}
} catch (Exception e) {
Log.e(TAG, "setTF: " + e.getMessage());
}
}
/**
* @param context
* @param jsonObject tfmedia开关
*/
private static void setTF(Context context, JsonObject jsonObject) {
try {
int setting_tfmedia = jsonObject.get("setting_tfmedia").getAsInt();
// if (JGYUtils.isOfficialVersion() ) {
// setting_tfmedia = changeNum(setting_tfmedia);
// }
boolean qch_tfmedia_forbid = Settings.System.putInt(context.getContentResolver(),
"qch_tfmedia_forbid", setting_tfmedia);
Log.e(TAG, "setting_tfmedia---------" + qch_tfmedia_forbid);
String tfmediaStatus = "";
switch (setting_tfmedia) {
case 0:
Log.e(TAG, "setting_tfmedia: " + "打开");
tfmediaStatus = "qch_tfmedia_open";
break;
case 1:
Log.e(TAG, "setting_tfmedia: " + "禁止");
tfmediaStatus = "qch_tfmedia_forbid";
break;
}
Intent tfmediaIntent = new Intent(tfmediaStatus).setPackage("com.android.settings");
context.sendBroadcast(tfmediaIntent);
if (setting_tfmedia == 1) {
JsonArray jSONArray = jsonObject.get("setting_tfmedia_format").getAsJsonArray();
StringBuffer stringBuffer = new StringBuffer();
for (int i = 0; i < jSONArray.size(); i++) {
stringBuffer.append(jSONArray.get(i).toString());
stringBuffer.append(",");
}
stringBuffer.deleteCharAt(stringBuffer.length() - 1);
Settings.System.putString(context.getContentResolver(), "qch_tfmedia_filetypes", stringBuffer.toString());//影音管控
Log.e(TAG, "qch_tfmedia_filetypes---------" + stringBuffer.toString());
} else {
Settings.System.putInt(context.getContentResolver(), "qch_tfmedia_forbid", 0);
}
} catch (Exception e) {
Log.e(TAG, "setTF: " + e.getMessage());
}
}
private static void setIcon(Context context, int state) {
}
private static void setIcon(Context context, JsonObject jsonObject) {
}
private static void setWallpaper(Context context, int state) {
//壁纸
// int wallpaper = 1;
Settings.System.putInt(context.getContentResolver(), "qch_app_wallpaper", state);
Log.e(TAG, "qch_app_wallpaper" + state);
}
private static void setCanReset(Context context, int state) {
Log.e(TAG, "setCanReset: state = " + state);
Settings.System.putInt(context.getContentResolver(), CommonConfig.AOLE_ACTION_RESTORE_FORBID_ON, state);
//默认打开
}
//aole_restore_forbid_on=1禁止恢复出厂设置
//aole_restore_forbid_on=0允许恢复出厂设置
private static void setCanReset(Context context, JsonObject jsonObject) {
int mode = jsonObject.get("qch_restore").getAsInt();
Log.e(TAG, "setCanReset: mode = " + mode);
if (mode == 1) {
Settings.System.putInt(context.getContentResolver(), CommonConfig.AOLE_ACTION_RESTORE_FORBID_ON, 0);
} else {
Settings.System.putInt(context.getContentResolver(), CommonConfig.AOLE_ACTION_RESTORE_FORBID_ON, 1);
}
}
//系统默认“使用网络提供时间”且不可点击
//后台设置“使用网络提供时间”:
//Intent intent32 = new Intent();
//intent32.setAction("qch_autotime_network");
//intent32.setPackage("com.android.settings");
//sendBroadcast(intent32);
//后台设置“使用GPS提供时间”
//Intent intent33 = new Intent();
//intent33.setAction("qch_autotime_gps");
//intent33.setPackage("com.android.settings");
//sendBroadcast(intent33);
//后台设置“关闭”(可以手动修改日期和时间)
//Intent intent34 = new Intent();
//intent34.setAction("qch_autotime_off");
//intent34.setPackage("com.android.settings");
//sendBroadcast(intent34);
private static void setAutoTime(Context context, JsonObject jsonObject) {
String autoTime = jsonObject.get("setting_autotime").getAsString();
String action = "qch_autotime_network";
if (TextUtils.isEmpty(autoTime)) {
action = "qch_autotime_network";
} else {
switch (autoTime) {
case "autotime_network":
action = "qch_autotime_network";
break;
case "autotime_gps":
action = "qch_autotime_gps";
break;
case "autotime_off":
action = "qch_autotime_off";
break;
default:
action = "qch_autotime_network";
break;
}
}
Log.e(TAG, "setAutoTime: " + "action=" + action);
Intent intent = new Intent();
intent.setAction(action);
intent.setPackage("com.android.settings");
context.sendBroadcast(intent);
}
private static void setAutoTime(Context context, int state) {
Log.e(TAG, "setAutoTime: " + "default");
Intent intent = new Intent();
intent.setAction("qch_autotime_network");
intent.setPackage("com.android.settings");
context.sendBroadcast(intent);
}
@SuppressLint("NewApi")
public static void setStatusBar(Context context, JsonObject jsonObject) {
Log.e(TAG, "setStatusBar: " + jsonObject.toString());
if (null != jsonObject) {
int whole = jsonObject.get("whole").getAsInt();
if (whole == 1) {
setStatusBar(context, 0);
} else {
List<Integer> disableWhat = new ArrayList<>();
int home = jsonObject.get("home").getAsInt();
if (home == 0) {
disableWhat.add(StatusBarManager.DISABLE_HOME);
}
int returnKey = jsonObject.get("returnKey").getAsInt();
if (returnKey == 0) {
disableWhat.add(StatusBarManager.DISABLE_BACK);
}
int taskbar = jsonObject.get("taskbar").getAsInt();
if (taskbar == 0) {
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);
}
}
}
@SuppressLint("NewApi")
private static void setStatusBar(Context context, int state) {
Log.e(TAG, "setStatusBar: " + "default");
StatusBarManager mStatusBarManager = (StatusBarManager) context.getSystemService(Context.STATUS_BAR_SERVICE);
mStatusBarManager.disable(StatusBarManager.DISABLE_BACK | StatusBarManager.DISABLE_RECENT | StatusBarManager.DISABLE_HOME);
mStatusBarManager.disable(StatusBarManager.DISABLE_NONE);//显示隐藏的虚拟按键
}
/**
* 设置浏览器禁止输入
*
* @param context
* @param jsonObject
*/
private static void setBrowserInput(Context context, JsonObject jsonObject) {
int state = 1;
try {
state = jsonObject.get("setting_browserInput").getAsInt();
Log.e(TAG, "setBrowserInput: setting_browserInput = " + state);
String json = jsonObject.get("setting_browserInput").getAsString();
if (TextUtils.isEmpty(json)) {
state = 1;
}
} catch (Exception e) {
Log.e(TAG, "setBrowserInput: e: " + e.getMessage());
}
Log.e(TAG, "setBrowserInput: " + state);
//后台没有这个选项默认打开
if (state == 0) {
Settings.System.putInt(context.getContentResolver(), "qch_Browser_input", 1);
} else {
Settings.System.putInt(context.getContentResolver(), "qch_Browser_input", 0);
}
try {
int is_browser_network;
if (TextUtils.isEmpty(jsonObject.get("is_browser_network").getAsString())) {
is_browser_network = 0;
} else {
is_browser_network = jsonObject.get("is_browser_network").getAsInt();
}
Log.e(TAG, "setBrowserInput: is_browser_network = " + is_browser_network);
Settings.Global.putInt(context.getContentResolver(), "is_browser_network", is_browser_network);
} catch (Exception e) {
Log.e(TAG, "setBrowserInput: e: " + e.getMessage());
}
}
/**
* 置浏览器禁止输入,默认打开
*
* @param context
* @param state
*/
private static void setBrowserInput(Context context, int state) {
Settings.System.putInt(context.getContentResolver(), "qch_Browser_input", 0);
Settings.Global.putInt(context.getContentResolver(), "is_browser_network", changeNum(state));
}
private static void setAdminApp(Context context, JsonObject jsonObject) {
JsonElement appInstall = jsonObject.get("is_app_install");
if (appInstall != null) {
int is_app_install = appInstall.getAsInt();
Log.e(TAG, "setAdminApp: is_app_install = " + is_app_install);
Settings.System.putInt(context.getContentResolver(), CommonConfig.AOLE_APP_ALLOW_INSTALL, is_app_install);
} else {
Settings.System.putInt(context.getContentResolver(), CommonConfig.AOLE_APP_ALLOW_INSTALL, 0);
}
JsonElement adminApp = jsonObject.get("is_admin_app");
if (adminApp != null) {
int is_admin_app = adminApp.getAsInt();
Log.e(TAG, "setAdminApp: is_admin_app = " + is_admin_app);
Settings.Global.putInt(context.getContentResolver(), "is_admin_app", is_admin_app);
} else {
Settings.Global.putInt(context.getContentResolver(), "is_admin_app", 0);
}
JsonElement appCategory = jsonObject.get("admin_app_category");
if (appCategory != null && !appCategory.isJsonNull()) {
String admin_app_category = appCategory.getAsString();
Settings.Global.putString(context.getContentResolver(), "admin_app_category", admin_app_category);
} else {
Settings.Global.putString(context.getContentResolver(), "admin_app_category", "");
}
}
private static void setAdminApp(Context context, int state) {
Log.e(TAG, "setAdminApp: state = " + state);
Settings.System.putInt(context.getContentResolver(), CommonConfig.AOLE_APP_ALLOW_INSTALL, changeNum(state));
Settings.Global.putInt(context.getContentResolver(), "is_admin_app", changeNum(state));
}
private static void setSystemAppDisable(Context context, JsonObject jsonObject) {
JsonElement pictureCategory = jsonObject.get("setting_picture");
if (pictureCategory != null && !pictureCategory.isJsonNull()) {
int setting_picture = pictureCategory.getAsInt();
Settings.System.putInt(context.getContentResolver(), "qch_app_gallery", changeNum(setting_picture));
} else {
Settings.System.putInt(context.getContentResolver(), "qch_app_gallery", 0);
}
JsonElement fileCategory = jsonObject.get("setting_file");
if (fileCategory != null && !fileCategory.isJsonNull()) {
int setting_file = fileCategory.getAsInt();
Settings.System.putInt(context.getContentResolver(), "qch_app_filemanager", changeNum(setting_file));
} else {
Settings.System.putInt(context.getContentResolver(), "qch_app_filemanager", 0);
}
JsonElement clockCategory = jsonObject.get("setting_clock");
if (clockCategory != null && !clockCategory.isJsonNull()) {
int setting_clock = clockCategory.getAsInt();
Settings.System.putInt(context.getContentResolver(), "qch_app_deskclock", changeNum(setting_clock));
} else {
Settings.System.putInt(context.getContentResolver(), "qch_app_deskclock", 0);
}
JsonElement musicCategory = jsonObject.get("setting_music");
if (musicCategory != null && !musicCategory.isJsonNull()) {
int setting_music = musicCategory.getAsInt();
Settings.System.putInt(context.getContentResolver(), "qch_app_music", changeNum(setting_music));
} else {
Settings.System.putInt(context.getContentResolver(), "qch_app_music", 0);
}
JsonElement recordCategory = jsonObject.get("setting_recording");
if (recordCategory != null && !recordCategory.isJsonNull()) {
int setting_recording = recordCategory.getAsInt();
Settings.System.putInt(context.getContentResolver(), "qch_app_soundrecorder", changeNum(setting_recording));
} else {
Settings.System.putInt(context.getContentResolver(), "qch_app_soundrecorder", 0);
}
JsonElement browserCategory = jsonObject.get("setting_browser");
if (browserCategory != null && !browserCategory.isJsonNull()) {
int setting_browser = browserCategory.getAsInt();
Settings.System.putInt(context.getContentResolver(), "qch_app_browser", changeNum(setting_browser));
} else {
Settings.System.putInt(context.getContentResolver(), "qch_app_browser", 0);
}
JsonElement smsCategory = jsonObject.get("setting_sms");
if (smsCategory != null && !smsCategory.isJsonNull()) {
int setting_sms = smsCategory.getAsInt();
Settings.System.putInt(context.getContentResolver(), "qch_app_sms", changeNum(setting_sms));
} else {
Settings.System.putInt(context.getContentResolver(), "qch_app_sms", 0);
}
}
/**
* @param context
* @param status 0打开 1关闭
*/
private static void setSystemAppDisable(Context context, int status) {
Settings.System.putInt(context.getContentResolver(), "qch_app_gallery", status);
Settings.System.putInt(context.getContentResolver(), "qch_app_filemanager", status);
Settings.System.putInt(context.getContentResolver(), "qch_app_deskclock", status);
Settings.System.putInt(context.getContentResolver(), "qch_app_music", status);
Settings.System.putInt(context.getContentResolver(), "qch_app_soundrecorder", status);
Settings.System.putInt(context.getContentResolver(), "qch_app_browser", status);
Settings.System.putInt(context.getContentResolver(), "qch_app_sms", status);
}
public static void setSnSetting(Context context, SnSetting snSetting) {
if (snSetting != null) {
int is_timecontrol = snSetting.getIs_timecontrol();
if (is_timecontrol == 0) {
TimeUtils.setEmpty(context);
TimeUtils.ContralTime c = TimeUtils.getDefaltContralTime(context);
if (null != c) {
Log.e("getTimeControl", c.toString());
}
} else {
String start_time = snSetting.getTimecontrol_start();
String end_time = snSetting.getTimecontrol_end();
TimeUtils.ContralTime c = TimeUtils.String2ContralTime(context, start_time + "-" + end_time);
if (null != c) {
Log.e("getTimeControl", "OK:" + c.toString());
}
}
int is_storeinstall = snSetting.getIs_storeinstall();
Settings.System.putInt(context.getContentResolver(), CommonConfig.AOLE_APP_ALLOW_INSTALL, is_storeinstall);
int is_usb = snSetting.getIs_usb();
setUsb(context, is_usb);
int is_bluetooth_file = snSetting.getIs_bluetooth_file();
setBluetoothTransmission(context, changeNum(is_bluetooth_file));
int is_developer = snSetting.getIs_developer();
JGYUtils.getInstance().setDeveloperOptions(is_developer);
int is_restore = snSetting.getIs_restore();
setCanReset(context, changeNum(is_restore));
int is_topbar = snSetting.getIs_topbar();
setActionBar(context, changeNum(is_topbar));
int is_bottombar = snSetting.getIs_bottombar();
setNavigationBar(context, changeNum(is_bottombar));
int is_memory_card = snSetting.getIs_memory_card();
setTF(context, changeNum(is_memory_card));
} else {
TimeUtils.setEmpty(context);
TimeUtils.ContralTime c = TimeUtils.getDefaltContralTime(context);
if (null != c) {
Log.e("getTimeControl", c.toString());
}
Settings.Global.putInt(context.getContentResolver(), CommonConfig.AOLE_APP_ALLOW_INSTALL, 1);
setUsb(context, 0);
setBluetoothTransmission(context, 0);
// JGYUtils.getInstance().setDeveloperOptions(0);
setCanReset(context, 0);
setActionBar(context, 0);
setNavigationBar(context, 0);
setTF(context, 0);
}
}
private static void setActionBar(Context context, int status) {
//状态栏显示开关
int oldNum = Settings.System.getInt(context.getContentResolver(), CommonConfig.AOLE_ACTION_HIDE_STATUS_BAR, 0);
if (oldNum != status) {
//写入到系统不涉及任何管控,因为之前调用会频繁隐藏显示
boolean aole_hide_statusBar = Settings.System.putInt(context.getContentResolver(), CommonConfig.AOLE_ACTION_HIDE_STATUS_BAR, status);
Log.e(TAG, "aole_hide_statusBar: " + aole_hide_statusBar);
String statusbarStatus = "";
switch (status) {
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);
// Intent statusIntent = new Intent(statusbarStatus).setPackage("com.android.systemui");
context.sendBroadcast(statusIntent);
}
}
private static void setNavigationBar(Context context, int status) {
//写入到系统不涉及任何管控,因为之前调用会频繁隐藏显示
boolean aole_hide_NavigationBar = Settings.System.putInt(context.getContentResolver(), CommonConfig.AOLE_ACTION_HIDE_NAVIGATION_BAR, status);
Log.e(TAG, "aole_hide_NavigationBar---------" + aole_hide_NavigationBar);
String navigationStatus = "";
switch (status) {
case 0:
navigationStatus = CommonConfig.AOLE_ACTION_SHOW_NAVIGATION_BAR;
break;
case 1:
navigationStatus = CommonConfig.AOLE_ACTION_HIDE_NAVIGATION_BAR;
break;
default:
}
Intent navIntent = new Intent(navigationStatus);
// Intent navIntent = new Intent(navigationStatus).setPackage("com.android.systemui");
context.sendBroadcast(navIntent);
}
private static void setUsb(Context context, int status) {
Log.e(TAG, "setUsb: " + status);
MMKV mmkv = MMKV.mmkvWithID(CommonConfig.MMKV_ID, MMKV.MULTI_PROCESS_MODE);
int oldStatus = mmkv.decodeInt(CommonConfig.AOLE_ACTION_USB_CODE, 0);
if (oldStatus == status) {
Log.e(TAG, "setUsb: oldStatus = " + oldStatus + " no changed");
return;
}
mmkv.encode(CommonConfig.AOLE_ACTION_USB_CODE, status);
//USB数据功能管控
//仅充电usb_charge
//MTP模式usb_mtp
//Midi模式usb_midi
if (JGYUtils.isCubeDevice()) {
SuperPower mService = (SuperPower) context.getSystemService("mdm");
switch (status) {
case 0:
mService.setUsbDataDisabled(true);
break;
case 1:
mService.setUsbDataDisabled(false);
break;
default:
}
} else {
String usbStatus;
switch (status) {
default:
case 0:
usbStatus = CommonConfig.AOLE_ACTION_USB_USB_CHARGE;
JGYUtils.getInstance().setMtpEnable(false);
break;
case 1:
usbStatus = CommonConfig.AOLE_ACTION_USB_USB_MTP;
JGYUtils.getInstance().setMtpEnable(true);
break;
case 2:
usbStatus = CommonConfig.AOLE_ACTION_USB_USB_MIDI;
JGYUtils.getInstance().setMtpEnable(false);
break;
}
Intent usbIntent = new Intent(usbStatus);
if (JGYUtils.getInstance().checkAppPlatform() == JGYUtils.TeclastP20sPlatform
|| JGYUtils.getInstance().checkAppPlatform() == JGYUtils.AH6016Platform
) {
usbIntent.setPackage("com.android.settings");
}
context.sendBroadcast(usbIntent);
}
}
public static void setNotification(Context context, JsonObject jsonObject) {
if (jsonObject.get("is_notification") != null) {
int status = jsonObject.get("is_notification").getAsInt();
Log.e(TAG, "setNotification: status = " + status);
setNotification(context, status);
} else {
Log.e(TAG, "setNotification: JsonElement not found");
}
}
/**
* @param context
* @param status 字段is notification 1开启 0 关闭
*/
public static void setNotification(Context context, int status) {
Intent intent = new Intent();
switch (status) {
default:
case 1:
intent.setAction("aole_show_appinfo");
break;
case 0:
intent.setAction("aole_hide_appinfo");
break;
}
context.sendBroadcast(intent);
}
private static void setPanelShow(Context context, JsonObject jsonObject) {
JsonElement jsonElement = jsonObject.get("is_control_show");
if (jsonElement != null && !jsonElement.isJsonNull()) {
int is_control_show = jsonElement.getAsInt();
Intent intent = new Intent();
switch (is_control_show) {
case 1:
intent.setAction(MainActivity.PANEL_SHOW);
break;
case 0:
default:
intent.setAction(MainActivity.PANEL_HIDE);
break;
}
context.sendBroadcast(intent);
}
}
}