1.4.0429 修改一键加速界面,去掉ToastUtil,对接权限和通知

This commit is contained in:
2024-05-08 14:33:06 +08:00
parent 08f5867864
commit 004de0cc2e
32 changed files with 885 additions and 527 deletions

View File

@@ -20,9 +20,12 @@ 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 {
@@ -62,13 +65,15 @@ public class SysSettingUtils {
// TODO: 2022/4/11 不是酷比定制的会报错,无法抛出异常
setUSBstate(context, jsonObject);
setAdminApp(context, jsonObject);
setSystemAppDisable(context, jsonObject);
setNotification(context, jsonObject);
}
/**
* @param context 关闭所有功能
*/
public static void setDisableSetting(Context context) {
ToastUtil.debugShow("关闭所有功能");
Toaster.debugShow("关闭所有功能");
Log.e("setDisableSetting", "Close all settings: ");
setPhoneList(context, 1);
setUSBstate(context, 1);
@@ -87,17 +92,19 @@ public class SysSettingUtils {
setAutoTime(context, 1);
setBrowserInput(context, 1);
if (!BuildConfig.DEBUG) {
JGYUtils.getInstance().setDeveloperOptions(1);
// JGYUtils.getInstance().setDeveloperOptions(0);
}
setStatusBar(context, 1);
setAdminApp(context, 1);
setSystemAppDisable(context, 0);
setNotification(context, 0);
}
/**
* @param context 开启所有功能
*/
public static void setEnableSetting(Context context) {
ToastUtil.debugShow("打开所有功能");
Toaster.debugShow("打开所有功能");
setPhoneList(context, 0);
if (JGYUtils.C2Tag.equalsIgnoreCase(JGYUtils.getInstance().getAppPlatform())) {
openMtp(context);
@@ -113,9 +120,11 @@ public class SysSettingUtils {
setCanReset(context, 0);
setAutoTime(context, 0);
setBrowserInput(context, 0);
JGYUtils.getInstance().setDeveloperOptions(0);
// JGYUtils.getInstance().setDeveloperOptions(1);
setStatusBar(context, 0);
setAdminApp(context, 0);
setSystemAppDisable(context, 0);
setNotification(context, 1);
}
private static void openMtp(Context context) {
@@ -183,6 +192,11 @@ public class SysSettingUtils {
//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;
@@ -211,6 +225,11 @@ public class SysSettingUtils {
//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");
@@ -253,71 +272,117 @@ public class SysSettingUtils {
}
}
private static void setBluetooth(Context context, int state) {
try {
boolean aole_bht_forbid_on = Settings.System.putInt(context.getContentResolver(), 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(context.getContentResolver(), CommonConfig.AOLE_ACTION_BHTVIDEO_FORBID_ON, "Empty");
Settings.System.putInt(context.getContentResolver(), CommonConfig.AOLE_ACTION_BT_FORBID_ON, state);
mBluetoothAdapter.disable();
//设置关闭时关闭蓝牙
}
} catch (Exception e) {
Log.e(TAG, "setBluetooth: " + e.getMessage());
/**
* @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");
}
}
private static void setBluetooth(Context context, JsonObject jsonObject) {
try {
//蓝牙开关
int setting_bht = changeNum(jsonObject.get("setting_bht").getAsInt());
//总开关
int setting_bhtvideo = changeNum(jsonObject.get("setting_bhtvideo").getAsInt());
//蓝牙音频开关
int setting_bluetooth = changeNum(jsonObject.get("setting_bluetooth").getAsInt());
//蓝牙传输开关
boolean aole_bht_forbid_on = Settings.System.putInt(context.getContentResolver(), CommonConfig.AOLE_ACTION_BHT_FORBID_ON, setting_bht);
/**
* @param context
* @param state 1关闭 0打开
*/
private static void setBluetooth(Context context, int state) {
Log.e(TAG, "setBluetooth: state = " + 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();
//获取默认蓝牙适配器
}
if (setting_bht == 0) {
//蓝牙总开关开启
String setting_context = jsonObject.get("setting_context").getAsString();
if (setting_bhtvideo == 0) {
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");
}
Settings.System.putInt(context.getContentResolver(), CommonConfig.AOLE_ACTION_BT_FORBID_ON, setting_bluetooth);
} else {
mBluetoothAdapter.disable();
//设置关闭时关闭蓝牙
}
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();
}
JGYUtils.getInstance().setBluetoothEnable(setting_bht == 1);
} catch (Exception e) {
Log.e(TAG, "setBluetooth: " + e.getMessage());
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 == 1);
}
/**
* @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);
String setting_context = jsonObject.get("setting_context").getAsString();
if (setting_bhtvideo == 0) {
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 == 1);
}
private static void setHotspot(Context context, int state) {
@@ -562,92 +627,11 @@ public class SysSettingUtils {
}
private static void setIcon(Context context, int state) {
try {
//设置5个app的开关
//时钟
// int deskclock = 1;
Settings.System.putInt(context.getContentResolver(), "qch_app_deskclock", state);
ApkUtils.hideSystemSettingAPP(context, "com.android.deskclock");
Log.e(TAG, "qch_app_deskclock" + state);
//录音机
// int soundrecorder = 1;
Settings.System.putInt(context.getContentResolver(), "qch_app_soundrecorder", state);
ApkUtils.hideSystemSettingAPP(context, "com.android.soundrecorder");
Log.e(TAG, "qch_app_soundrecorder" + state);
//音乐
// int music = 1;
Settings.System.putInt(context.getContentResolver(), "qch_app_music", state);
ApkUtils.hideSystemSettingAPP(context, "com.android.music");
Log.e(TAG, "qch_app_music" + state);
//图库
// int gallery = 1;
Settings.System.putInt(context.getContentResolver(), "qch_app_gallery", state);
ApkUtils.hideSystemSettingAPP(context, "com.android.gallery3d");
Log.e(TAG, "qch_app_gallery" + state);
//文件管理器
// int filemanager = 1;
Settings.System.putInt(context.getContentResolver(), "qch_app_filemanager", state);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
ApkUtils.hideSystemSettingAPP(context, "com.mediatek.filemanager");
} else {
ApkUtils.hideSystemSettingAPP(context, "com.android.documentsui");
}
Log.e(TAG, "qch_app_filemanager" + state);
Settings.System.putInt(context.getContentResolver(), "qch_app_browser", state);
Log.e(TAG, "qch_app_browser" + state);
} catch (Exception e) {
Log.e(TAG, "setIcon: " + e.getMessage());
}
}
private static void setIcon(Context context, JsonObject jsonObject) {
try {
//added:2019.12.6
//设置5个app的开关
//时钟
int deskclock = changeNum(jsonObject.get("setting_clock").getAsInt());
Settings.System.putInt(context.getContentResolver(), "qch_app_deskclock", deskclock);
ApkUtils.hideSystemSettingAPP(context, "com.android.deskclock");
Log.e(TAG, "qch_app_deskclock" + deskclock);
//录音机
int soundrecorder = changeNum(jsonObject.get("setting_recording").getAsInt());
Settings.System.putInt(context.getContentResolver(), "qch_app_soundrecorder", soundrecorder);
ApkUtils.hideSystemSettingAPP(context, "com.android.soundrecorder");
Log.e(TAG, "qch_app_soundrecorder" + soundrecorder);
//音乐
int music = changeNum(jsonObject.get("setting_music").getAsInt());
Settings.System.putInt(context.getContentResolver(), "qch_app_music", music);
ApkUtils.hideSystemSettingAPP(context, "com.android.music");
Log.e(TAG, "qch_app_music" + music);
//图库
int gallery = changeNum(jsonObject.get("setting_picture").getAsInt());
Settings.System.putInt(context.getContentResolver(), "qch_app_gallery", gallery);
ApkUtils.hideSystemSettingAPP(context, "com.android.gallery3d");
Log.e(TAG, "qch_app_gallery" + gallery);
//壁纸
int wallpaper = changeNum(jsonObject.get("setting_wallpaper").getAsInt());
setWallpaper(context, wallpaper);
//文件管理器
int filemanager = changeNum(jsonObject.get("setting_file").getAsInt());
Settings.System.putInt(context.getContentResolver(), "qch_app_filemanager", filemanager);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
ApkUtils.hideSystemSettingAPP(context, "com.mediatek.filemanager");
} else {
ApkUtils.hideSystemSettingAPP(context, "com.android.documentsui");
}
Log.e(TAG, "qch_app_filemanager" + filemanager);
//浏览器
int browser = changeNum(jsonObject.get("setting_browser").getAsInt());
Settings.System.putInt(context.getContentResolver(), "qch_app_browser", browser);
Log.e(TAG, "qch_app_browser" + browser);
//短信
int setting_sms = changeNum(jsonObject.get("setting_sms").getAsInt());
Settings.System.putInt(context.getContentResolver(), "qch_app_sms", setting_sms);
Log.e(TAG, "qch_app_sms" + setting_sms);
} catch (Exception e) {
Log.e(TAG, "setIcon: " + e.getMessage());
}
}
private static void setWallpaper(Context context, int state) {
@@ -847,6 +831,7 @@ public class SysSettingUtils {
} else {
Settings.Global.putString(context.getContentResolver(), "admin_app_category", "");
}
}
private static void setAdminApp(Context context, int state) {
@@ -855,6 +840,78 @@ public class SysSettingUtils {
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) {
@@ -878,9 +935,9 @@ public class SysSettingUtils {
int is_usb = snSetting.getIs_usb();
setUsb(context, is_usb);
int is_bluetooth_file = snSetting.getIs_bluetooth_file();
setBluetooth(context, changeNum(is_bluetooth_file));
setBluetoothTransmission(context, changeNum(is_bluetooth_file));
int is_developer = snSetting.getIs_developer();
JGYUtils.getInstance().setDeveloperOptions(changeNum(is_developer));
JGYUtils.getInstance().setDeveloperOptions(is_developer);
int is_restore = snSetting.getIs_restore();
setCanReset(context, changeNum(is_restore));
int is_topbar = snSetting.getIs_topbar();
@@ -898,11 +955,8 @@ public class SysSettingUtils {
}
Settings.Global.putInt(context.getContentResolver(), CommonConfig.AOLE_APP_ALLOW_INSTALL, 1);
setUsb(context, 0);
setBluetooth(context, 0);
int status = Settings.System.getInt(context.getContentResolver(), CommonConfig.AOLE_ACTION_DEVELOPER_OPTIONS, 1);
if (status != 0) {
JGYUtils.getInstance().setDeveloperOptions(1);
}
setBluetoothTransmission(context, 0);
JGYUtils.getInstance().setDeveloperOptions(0);
setCanReset(context, 0);
setActionBar(context, 0);
setNavigationBar(context, 0);
@@ -954,6 +1008,15 @@ public class SysSettingUtils {
}
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
@@ -996,5 +1059,31 @@ public class SysSettingUtils {
}
}
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);
}
}