version:1.1

fix:
add:应用使用数据统计
This commit is contained in:
2021-12-25 16:54:44 +08:00
parent 88f65afb48
commit 71e5516ab8
159 changed files with 1671 additions and 3312 deletions

View File

@@ -0,0 +1,89 @@
package com.uiui.sn.manager;
import android.content.Context;
import android.util.Log;
import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationClient;
import com.amap.api.location.AMapLocationClientOption;
import com.amap.api.location.AMapLocationListener;
import com.uiui.sn.utils.SPUtils;
public class AmapManager {
private static AmapManager sInstance;
private Context mContext;
public static AMapLocationClient locationClient = null;
private String TAG = AmapManager.class.getSimpleName();
private AmapManager(Context context) {
this.mContext = context;
}
public static void init(Context context) {
if (sInstance == null) {
sInstance = new AmapManager(context);
}
}
public static AmapManager getInstance() {
if (sInstance == null) {
throw new IllegalStateException("You must be init AmapManager first");
}
return sInstance;
}
public AMapLocationClient getLocationClient() {
if (null == locationClient) {
initAmap();
}
return locationClient;
}
public void initAmap() {
locationClient = new AMapLocationClient(mContext);
AMapLocationClientOption option = new AMapLocationClientOption();
option.setLocationPurpose(AMapLocationClientOption.AMapLocationPurpose.SignIn);
option.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
option.setNeedAddress(true);
//获取一次定位结果:
//该方法默认为false。
option.setOnceLocation(true);
//获取最近3s内精度最高的一次定位结果
//设置setOnceLocationLatest(boolean b)接口为true启动定位时SDK会返回最近3s内精度最高的一次定位结果。
// 如果设置其为truesetOnceLocation(boolean b)接口也会被设置为true反之不会默认为false。
option.setOnceLocationLatest(true);
locationClient.setLocationOption(option);
//设置定位模式为AMapLocationMode.Hight_Accuracy高精度模式。
//设置定位监听
locationClient.setLocationListener(new AMapLocationListener() {
@Override
public void onLocationChanged(AMapLocation aMapLocation) {
StringBuilder sb = new StringBuilder();
//errCode等于0代表定位成功其他的为定位失败具体的可以参照官网定位错误码说明
if (aMapLocation.getErrorCode() == 0) {
Log.e(TAG, "onLocationChanged: " + "定位成功");
Log.e(TAG, "onLocationChanged: " + aMapLocation.getAddress());
sb.append(aMapLocation.getAddress()).append("\n");
SPUtils.put(mContext, "AmapAddress", aMapLocation.getAddress());
SPUtils.put(mContext, "longitude", aMapLocation.getLongitude());
SPUtils.put(mContext, "latitude", aMapLocation.getLatitude());
} else {
//定位失败
sb.append("定位失败" + "\n");
Log.e(TAG, "onLocationChanged: " + "定位失败");
SPUtils.put(mContext, "AmapError", String.valueOf(aMapLocation.getErrorInfo()));
}
Log.e(TAG, (String) SPUtils.get(mContext, "AmapAddress", "-"));
Log.e(TAG, (String) SPUtils.get(mContext, "AmapError", "-"));
Log.e(TAG, "amap: " + sb.toString());
}
});
//设置场景模式后最好调用一次stop再调用start以保证场景模式生效
locationClient.stopLocation();
locationClient.startLocation();
Log.e(TAG, "initAmap: " + "startLocation");
}
}

View File

@@ -0,0 +1,656 @@
package com.uiui.sn.manager;
import android.annotation.SuppressLint;
import android.bluetooth.BluetoothAdapter;
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.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.uiui.sn.bean.zuoye.SystemSettings;
import com.uiui.sn.utils.ApkUtils;
import com.uiui.sn.utils.JGYUtils;
import com.uiui.sn.utils.SPUtils;
import com.uiui.sn.utils.ToastUtil;
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 ControlManager(Context mContext) {
this.mContext = mContext;
}
public static void init(Context mContext) {
if (sInstance == null) {
sInstance = new ControlManager(mContext);
}
}
public static ControlManager getInstance() {
if (sInstance == null) {
throw new IllegalStateException("You must be init ControlUtils first");
}
return sInstance;
}
private static int changeNum(int status) {
return status == 0 ? 1 : 0;
}
public void setSystemSetting(Context context, String jsonString) {
if (TextUtils.isEmpty(jsonString)) {
return;
}
SystemSettings settings = JSON.parseObject(jsonString, SystemSettings.class);
if (null != settings) {
setUSBstate(context, settings);
setPhoneList(context, settings);
setBluetooth(context, settings);
setHotspot(context, settings);
setBar(context, settings);
setCamera(context, settings);
setTF(context, settings);
setIcon(context, settings);
setCanReset(context, jsonString);
setDeveloperOptions(context, jsonString);
setSearchTopic(context, jsonString);
JGYUtils.getInstance().updateForbidList();
}
}
/**
* 关闭所有功能
*/
public void setDisableSetting() {
Log.e("setDisableSetting", "Close all settings: ");
setUSBstate(1);
setPhoneList(1);
setBluetooth(1);
setHotspot(1);
setCamera(1);
setTF(1);
setIcon(1);
setWallpaper(0);
setCanReset(1);
setBrowserInput(1);
if (!DeviceManager.isDebugMode()) {
setDeveloperOptions(1);
}
setSearchTopic(0);
}
/**
* usb连接模式管控
*
* @param mContext
* @param settings
*/
private static void setUSBstate(Context mContext, 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 = JGYUtils.putString(mContext.getContentResolver(), "qch_usb_choose", setting_usb);
Log.e("SystemSetting", "qch_usb_choose:" + qch_usb_choose);
String usbStatus = "";
switch (setting_usb) {
case "usb_charge":
usbStatus = "qch_action_usb_usb_charge";
break;
case "usb_mtp":
usbStatus = "qch_action_usb_usb_mtp";
break;
// case "usb_midi":
// usbStatus = "qch_action_usb_usb_midi";
// break;
default:
usbStatus = "qch_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());
}
}
}
/**
* 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(mContext.getContentResolver(), "qch_usb_choose", "usb_charge");
Log.e(TAG, "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);
} catch (Exception e) {
Log.e(TAG, "setUSBstate: " + e.getMessage());
}
}
}
private static void setPhoneList(Context mContext, SystemSettings settings) {
//设置电话功能,电话白名单
int setting_call = changeNum(settings.getSetting_call());
boolean qch_call_forbid = JGYUtils.putInt(mContext.getContentResolver(), "qch_call_forbid", setting_call);
Log.e("SystemSetting", "qch_call_forbid: " + setting_call);
int setting_phone = changeNum(settings.getSetting_phone());
boolean qch_white_list_on = JGYUtils.putInt(mContext.getContentResolver(), "qch_white_list_on", setting_phone);
Log.e("SystemSetting", "qch_white_list_on: " + setting_phone);
String setting_phones = settings.getSetting_phones();
boolean qch_white_list_Array = JGYUtils.putString(mContext.getContentResolver(), "qch_white_list_Array", setting_phones);
Log.e("SystemSetting", "qch_white_list_Array: " + qch_white_list_Array + "=" + setting_phones);
int setting_memory = changeNum(settings.getSetting_memory());
boolean qch_sdcard_forbid_on = JGYUtils.putInt(mContext.getContentResolver(), "qch_sdcard_forbid_on", setting_memory);
Log.e("SystemSetting", "qch_sdcard_forbid_on: " + setting_memory);
}
private void setPhoneList(int state) {
try {
//设置电话功能,电话白名单
boolean qch_call_forbid = Settings.System.putInt(mContext.getContentResolver(), "qch_call_forbid", state);
Log.e(TAG, "qch_call_forbid:" + qch_call_forbid);
boolean qch_white_list_on = Settings.System.putInt(mContext.getContentResolver(), "qch_white_list_on", state);
Log.e(TAG, "qch_white_list_on:" + qch_white_list_on);
boolean qch_white_list_Array = Settings.System.putString(mContext.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(TAG, "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);
Log.e(TAG, "qch_sdcard_forbid_on:" + qch_sdcard_forbid_on);
} catch (Exception e) {
Log.e(TAG, "setPhoneList: " + e.getMessage());
}
}
private static void setBluetooth(Context mContext, 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 qch_bht_forbid_on = JGYUtils.putInt(mContext.getContentResolver(), "qch_bht_forbid_on", setting_bht);
//写入系统数据库
Log.e("SystemSetting", "qch_bht_forbid_on:" + qch_bht_forbid_on);
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (qch_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);
JGYUtils.putString(mContext.getContentResolver(), "qch_bhtvideo_forbid_on", setting_context);
} else {
JGYUtils.putString(mContext.getContentResolver(), "qch_bhtvideo_forbid_on", "Empty");
}
} else if (setting_bhtvideo == 1) {
JGYUtils.putString(mContext.getContentResolver(), "qch_bhtvideo_forbid_on", "Empty");
}
JGYUtils.putInt(mContext.getContentResolver(), "qch_bt_forbid_on", setting_bluetooth);
} else {
mBluetoothAdapter.disable();
//设置关闭时关闭蓝牙
}
}
} catch (Exception e) {
Log.e(TAG, "setBluetooth: " + e.getMessage());
}
}
private void setBluetooth(int state) {
try {
boolean qch_bht_forbid_on = Settings.System.putInt(mContext.getContentResolver(), "qch_bht_forbid_on", state);
//写入系统数据库
Log.e(TAG, "qch_bht_forbid_on:" + qch_bht_forbid_on);
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (qch_bht_forbid_on) {
//成功
if (null == mBluetoothAdapter) {
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
//获取默认蓝牙适配器
}
//蓝牙总开关开启
Settings.System.putString(mContext.getContentResolver(), "qch_bhtvideo_forbid_on", "Empty");
Settings.System.putInt(mContext.getContentResolver(), "qch_bt_forbid_on", state);
mBluetoothAdapter.disable();
//设置关闭时关闭蓝牙
}
} catch (Exception e) {
Log.e(TAG, "setBluetooth: " + e.getMessage());
}
}
private static void setHotspot(Context mContext, 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 qch_hotspot_forbid_on = JGYUtils.putInt(mContext.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) {
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 qch_hotspot_forbid_on = Settings.System.putInt(mContext.getContentResolver(), "qch_hotspot_forbid_on", state);
Log.e(TAG, "qch_hotspot_forbid_on:" + qch_hotspot_forbid_on);
} catch (Exception e) {
Log.e(TAG, "setHotspot: " + e.getMessage());
}
}
private static void setBar(Context mContext, SystemSettings settings) {
//系统导航条显示开关
int setting_navigation = changeNum(settings.getSetting_navigation());
boolean qch_hide_navigationBar = JGYUtils.putInt(mContext.getContentResolver(), "qch_hide_NavigationBar", setting_navigation);
Log.e("SystemSetting", "qch_hide_navigationBar:" + qch_hide_navigationBar);
String navigationStatus = "";
switch (setting_navigation) {
case 0:
navigationStatus = "qch_show_NavigationBar";
break;
case 1:
navigationStatus = "qch_hide_NavigationBar";
break;
}
Intent navIntent = new Intent(navigationStatus).setPackage("com.android.systemui");
mContext.sendBroadcast(navIntent);
//状态栏显示开关
int setting_statusbar = changeNum(settings.getSetting_statusbar());
int oldNum = JGYUtils.getInt(mContext.getContentResolver(), "qch_hide_statusBar", 0);
if (oldNum != setting_statusbar) {
boolean qch_hide_statusBar = JGYUtils.putInt(mContext.getContentResolver(), "qch_hide_statusBar", setting_statusbar);
Log.e("SystemSetting", "qch_hide_statusBar:" + qch_hide_statusBar);
String statusbarStatus = "";
switch (setting_statusbar) {
case 0:
statusbarStatus = "qch_show_statusBar";
break;
case 1:
statusbarStatus = "qch_hide_statusBar";
break;
}
Intent statusIntent = new Intent(statusbarStatus).setPackage("com.android.systemui");
mContext.sendBroadcast(statusIntent);
}
}
private static void setCamera(Context mContext, SystemSettings settings) {
try {
//摄像头开关
int setting_camera = changeNum(settings.getSetting_camera());
JGYUtils.putInt(mContext.getContentResolver(), "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(mContext.getContentResolver(), "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 static void setTF(Context mContext, SystemSettings settings) {
//tfmedia开关
int setting_tfmedia = changeNum(settings.getSetting_tfmedia());
boolean qch_tfmedia_forbid = JGYUtils.putInt(mContext.getContentResolver(), "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)) {
JGYUtils.putString(mContext.getContentResolver(), "qch_tfmedia_filetypes", "");//影音管控
} else {
HashSet<String> types = new HashSet<>(Arrays.asList(qch_tfmedia_filetypes.split(",")));
types.removeIf(new Predicate<String>() {
@Override
public boolean test(String s) {
return TextUtils.isEmpty(s);
}
});
String typesString = String.join(",", types);
JGYUtils.putString(mContext.getContentResolver(), "qch_tfmedia_filetypes", typesString);//影音管控
Log.e("SystemSetting", "qch_tfmedia_filetypes :" + typesString);
}
} else {
JGYUtils.putInt(mContext.getContentResolver(), "qch_tfmedia_forbid", 0);
}
}
private void setTF(int state) {
try {
//tfmedia开关
// int setting_tfmedia = 1;
boolean qch_tfmedia_forbid = Settings.System.putInt(mContext.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");
mContext.sendBroadcast(tfmediaIntent);
if (state == 1) {
boolean qch_tfmedia_filetypes = Settings.System.putString(mContext.getContentResolver(), "qch_tfmedia_filetypes", "Empty");//影音管控
Log.e(TAG, "qch_tfmedia_filetypes:" + qch_tfmedia_filetypes);
} else {
Settings.System.putInt(mContext.getContentResolver(), "qch_tfmedia_forbid", 0);
}
} catch (Exception e) {
Log.e(TAG, "setTF: " + e.getMessage());
}
}
private static void setIcon(Context mContext, SystemSettings settings) {
try {
//added:2019.12.6
//设置5个app的开关
//时钟
int deskclock = changeNum(settings.getSetting_clock());
JGYUtils.putInt(mContext.getContentResolver(), "qch_app_deskclock", deskclock);
ApkUtils.hideSystemSettingAPP(mContext, "com.android.deskclock");
Log.e("SystemSetting", "qch_app_deskclock:" + deskclock);
//录音机
int soundrecorder = changeNum(settings.getSetting_recording());
JGYUtils.putInt(mContext.getContentResolver(), "qch_app_soundrecorder", soundrecorder);
ApkUtils.hideSystemSettingAPP(mContext, "com.android.soundrecorder");
Log.e("SystemSetting", "qch_app_soundrecorder:" + soundrecorder);
//音乐
int music = changeNum(settings.getSetting_music());
JGYUtils.putInt(mContext.getContentResolver(), "qch_app_music", music);
ApkUtils.hideSystemSettingAPP(mContext, "com.android.music");
Log.e("SystemSetting", "qch_app_music:" + music);
//图库
int gallery = changeNum(settings.getSetting_picture());
JGYUtils.putInt(mContext.getContentResolver(), "qch_app_gallery", gallery);
ApkUtils.hideSystemSettingAPP(mContext, "com.android.gallery3d");
Log.e("SystemSetting", "qch_app_gallery:" + gallery);
//壁纸
int wallpaper = changeNum(settings.getSetting_wallpaper());
JGYUtils.putInt(mContext.getContentResolver(), "qch_app_wallpaper", wallpaper);
Log.e("SystemSetting", "qch_app_wallpaper:" + wallpaper);
//文件管理器
int filemanager = changeNum(settings.getSetting_file());
JGYUtils.putInt(mContext.getContentResolver(), "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());
JGYUtils.putInt(mContext.getContentResolver(), "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(mContext.getContentResolver(), "qch_app_deskclock", state);
ApkUtils.hideSystemSettingAPP(mContext, "com.android.deskclock");
Log.e(TAG, "qch_app_deskclock" + state);
//录音机
// int soundrecorder = 1;
Settings.System.putInt(mContext.getContentResolver(), "qch_app_soundrecorder", state);
ApkUtils.hideSystemSettingAPP(mContext, "com.android.soundrecorder");
Log.e(TAG, "qch_app_soundrecorder" + state);
//音乐
// int music = 1;
Settings.System.putInt(mContext.getContentResolver(), "qch_app_music", state);
ApkUtils.hideSystemSettingAPP(mContext, "com.android.music");
Log.e(TAG, "qch_app_music" + state);
//图库
// int gallery = 1;
Settings.System.putInt(mContext.getContentResolver(), "qch_app_gallery", state);
ApkUtils.hideSystemSettingAPP(mContext, "com.android.gallery3d");
Log.e(TAG, "qch_app_gallery" + state);
//文件管理器
// int filemanager = 1;
Settings.System.putInt(mContext.getContentResolver(), "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(mContext.getContentResolver(), "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(mContext.getContentResolver(), "qch_app_wallpaper", state);
Log.e(TAG, "qch_app_wallpaper" + state);
}
private static void setCanReset(Context context, String jsonString) {
JSONObject jsonObject = JSON.parseObject(jsonString);
int mode = jsonObject.getIntValue("qch_restore");
if (mode == 1) {
Settings.System.putInt(context.getContentResolver(), "qch_restore_forbid_on", 0);
} else {
Settings.System.putInt(context.getContentResolver(), "qch_restore_forbid_on", 1);
}
Log.e(TAG, "qch_restore_forbid_on:" + mode);
}
private void setCanReset(int state) {
boolean qch_restore_forbid_on = Settings.System.putInt(mContext.getContentResolver(), "qch_restore_forbid_on", 0);
Log.e(TAG, "qch_restore_forbid_on:" + qch_restore_forbid_on);
//默认打开
}
/**
* 置浏览器禁止输入,默认打开
*
* @param state
*/
private void setBrowserInput(int state) {
Settings.System.putInt(mContext.getContentResolver(), "qch_Browser_input", 0);
}
public void setDeveloperOptions(Context context, String jsonString) {
JSONObject jsonObject = JSON.parseObject(jsonString);
int dev_mode = changeNum(jsonObject.getIntValue("dev_mode"));
Log.e(TAG, "getDeveloper: " + dev_mode);
if (!DeviceManager.isDebugMode()) {
JGYUtils.putInt(context.getContentResolver(), "qch_Developeroptions", dev_mode);
if (dev_mode == 1) {
Intent intent = new Intent();
intent.setAction("qch_developeroptions_close");
intent.setPackage("com.android.settings");
context.sendBroadcast(intent);
Log.e(TAG, "getDeveloper: " + "关闭开发者模式");
ToastUtil.debugShow("关闭开发者模式");
} else {
Log.e(TAG, "getDeveloper: " + "打开开发者模式");
ToastUtil.debugShow("打开开发者模式");
}
}
}
public void setDeveloperOptions(int state) {
Log.e(TAG, "getDeveloper: " + state);
if (!DeviceManager.isDebugMode()) {
Settings.System.putInt(mContext.getContentResolver(), "qch_Developeroptions", state);
if (state == 1) {
Intent intent = new Intent();
intent.setAction("qch_developeroptions_close");
intent.setPackage("com.android.settings");
mContext.sendBroadcast(intent);
Log.e(TAG, "getDeveloper: " + "关闭开发者模式");
} else {
Log.e(TAG, "getDeveloper: " + "打开开发者模式");
// ToastUtil.show("打开开发者模式");
}
}
}
public void setSearchTopic(Context context, String jsonString) {
JSONObject jsonObject = JSON.parseObject(jsonString);
int mode = jsonObject.getIntValue("search_topic");
SPUtils.put(context, "search_topic", mode);
Log.e(TAG, "search_topic:" + mode);
}
public void setSearchTopic(int state) {
SPUtils.put(mContext, "search_topic", state);
Log.e(TAG, "search_topic:" + state);
}
/**
* 开机管控usb
*/
public void setDefaultUSBstate() {
//USB数据功能管控
//仅充电usb_charge
//MTP模式usb_mtp
//Midi模式usb_midi
String setting_usb = JGYUtils.getString(mContext.getContentResolver(), "qch_usb_choose");
Log.e("SystemSetting", "setting_usb:" + setting_usb);
String usbStatus = "";
if (TextUtils.isEmpty(setting_usb)) {
usbStatus = "qch_action_usb_usb_charge";
} else {
if (!DeviceManager.isDebugMode()) {
switch (setting_usb) {
case "usb_charge":
usbStatus = "qch_action_usb_usb_charge";
break;
case "usb_mtp":
usbStatus = "qch_action_usb_usb_mtp";
break;
// case "usb_midi":
// usbStatus = "qch_action_usb_usb_midi";
// break;
default:
usbStatus = "qch_action_usb_usb_charge";
break;
}
}
}
Intent usbIntent = new Intent(usbStatus).setPackage("com.android.settings");
mContext.sendBroadcast(usbIntent);
}
}

View File

@@ -0,0 +1,80 @@
package com.uiui.sn.manager;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import com.uiui.sn.BuildConfig;
import com.uiui.sn.utils.SPUtils;
import com.uiui.sn.utils.ToastUtil;
public class DeviceManager {
private static final String TAG = DeviceManager.class.getSimpleName();
@SuppressLint("StaticFieldLeak")
private static DeviceManager sInstance;
@SuppressLint("StaticFieldLeak")
private static Context mContext;
private DeviceManager(Context context) {
mContext = context;
}
public static void init(Context mContext) {
if (sInstance == null) {
sInstance = new DeviceManager(mContext);
}
}
public static DeviceManager getInstance() {
if (sInstance == null) {
throw new IllegalStateException("You must be init ControlUtils first");
}
return sInstance;
}
/**
* @return 是否为debug模式
*/
public static boolean isDebugMode() {
return BuildConfig.DEBUG || (boolean) SPUtils.get(mContext, "EnableDebug", false);
}
/**
* 重启设备
*/
public static void rebootDevices() {
if (isDebugMode()) {
ToastUtil.show("收到重启设备推送消息");
return;
}
Intent iReboot = new Intent(Intent.ACTION_REBOOT);
iReboot.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.startActivity(iReboot);
}
/**
* 重置,恢复出厂设置
*/
synchronized public static void doMasterClear() {
if (isDebugMode()) {
ToastUtil.show("收到重置设备推送消息");
return;
}
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N_MR1) {
Intent intent = new Intent("android.intent.action.FACTORY_RESET");
intent.setPackage("android");
intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
intent.putExtra("android.intent.extra.REASON", "MasterClearConfirm");
intent.putExtra("android.intent.extra.WIPE_EXTERNAL_STORAGE", false);
intent.putExtra("com.android.internal.intent.extra.WIPE_ESIMS", false);
mContext.sendBroadcast(intent);
} else {
Intent intent = new Intent("android.intent.action.MASTER_CLEAR");
// intent.setPackage("com.android.settings");
mContext.sendBroadcast(intent);
}
}
}

View File

@@ -0,0 +1,43 @@
package com.uiui.sn.manager;
import android.content.Context;
import com.bumptech.glide.GlideBuilder;
import com.bumptech.glide.load.engine.cache.DiskLruCacheFactory;
import com.bumptech.glide.module.AppGlideModule;
import com.uiui.sn.utils.StorageUtils;
/**
* Created by Administrator on 2017/2/9.
*/
@com.bumptech.glide.annotation.GlideModule
public class MyGlideModule extends AppGlideModule {
@Override
public void applyOptions(final Context context, GlideBuilder builder) {
// 设置图片的显示格式 低内存时降低图片质量
// ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
// if (activityManager != null){
// ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo();
// activityManager.getMemoryInfo(memoryInfo);
// builder.setDecodeFormat(memoryInfo.lowMemory ? DecodeFormat.PREFER_RGB_565 : DecodeFormat.PREFER_ARGB_8888);
// }
// builder.setDecodeFormat(DecodeFormat.PREFER_RGB_565);
//设置磁盘缓存目录(和创建的缓存目录相同)
String downloadDirectoryPath = StorageUtils.getFileCache(context, "imageCache");
//设置缓存的大小为100M
int cacheSize = 100 * 1024 * 1024;
builder.setDiskCache(
new DiskLruCacheFactory(downloadDirectoryPath, cacheSize));
}
/**
* 清单解析的开启
*
* 这里不开启避免添加相同的modules两次
* @return
*/
@Override
public boolean isManifestParsingEnabled() {
return false;
}
}

View File

@@ -0,0 +1,386 @@
package com.uiui.sn.manager;
import android.annotation.SuppressLint;
import android.content.Context;
import android.util.Log;
import com.uiui.sn.bean.zuoye.AppInfo;
import com.uiui.sn.bean.zuoye.AppStart;
import com.uiui.sn.bean.zuoye.BaseResponse;
import com.uiui.sn.bean.zuoye.Label;
import com.uiui.sn.bean.zuoye.UserAvatarInfo;
import com.uiui.sn.bean.zuoye.UserInfo;
import com.uiui.sn.bean.zuoye.browser.BrowserApiData;
import com.uiui.sn.network.UrlAddress;
import com.uiui.sn.network.api.APPJump;
import com.uiui.sn.network.api.AddAppInstall;
import com.uiui.sn.network.api.AppUsedApi;
import com.uiui.sn.network.api.BindDevices;
import com.uiui.sn.network.api.Browser;
import com.uiui.sn.network.api.BrowserLabel;
import com.uiui.sn.network.api.ForceInstall;
import com.uiui.sn.network.api.GetBatchApi;
import com.uiui.sn.network.api.GetControlScreenshotApi;
import com.uiui.sn.network.api.GetGuideApi;
import com.uiui.sn.network.api.GetSnUidApi;
import com.uiui.sn.network.api.NewestAppUpdate;
import com.uiui.sn.network.api.QRCodeApi;
import com.uiui.sn.network.api.QueryAllApp;
import com.uiui.sn.network.api.QueryAppInside;
import com.uiui.sn.network.api.QuerySnAppStart;
import com.uiui.sn.network.api.RunningApp;
import com.uiui.sn.network.api.SNInfoApi;
import com.uiui.sn.network.api.SaveSnUidApi;
import com.uiui.sn.network.api.ScreenLock;
import com.uiui.sn.network.api.ScreenState;
import com.uiui.sn.network.api.Setting;
import com.uiui.sn.network.api.TimeControl;
import com.uiui.sn.network.api.UpdateAdminSn;
import com.uiui.sn.network.api.UploadScreenshot;
import com.uiui.sn.network.api.UserInfoControl;
import com.uiui.sn.utils.MD5Util;
import com.uiui.sn.utils.Utils;
import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import okhttp3.Cache;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Protocol;
import okhttp3.Request;
import okhttp3.Response;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
public class NetInterfaceManager {
@SuppressLint("StaticFieldLeak")
private static NetInterfaceManager INSTANCE;
private Context mContext;
private Retrofit mRetrofit;
private OkHttpClient okHttpClient;
// private Retrofit mGankaoRetrofit;
private final ConcurrentHashMap<String, Long> requestIdsMap = new ConcurrentHashMap<>();
//超时时间
private static int timeOut = 5;
// 缓存文件最大限制大小20M
private static long cacheSize = 1024 * 1024 * 64;
public static final String CUSTOM_REPEAT_REQ_PROTOCOL = "MY_CUSTOM_REPEAT_REQ_PROTOCOL";
private NetInterfaceManager(Context context) {
mContext = context;
if (null == mRetrofit) {
if (okHttpClient == null) {
Interceptor myHttpInterceptor = new Interceptor() {
@NotNull
@Override
public Response intercept(@NotNull Chain chain) throws IOException {
Request request = chain.request();
String requestKey = MD5Util.getUpperMD5Str(request.method() + request.url().toString());
Response response = chain.proceed(request); //准备返回Response
synchronized (requestIdsMap) {
requestIdsMap.remove(requestKey); //在这里移除正常的请求登记
Log.e("REPEAT-REQUEST", "移除请求2:" + requestKey + " --- " + Thread.currentThread().getName() + " URL = " + request.url());
}
return response;
}
};
Interceptor mRequestInterceptor = new Interceptor() {
@NotNull
@Override
public Response intercept(@NotNull Chain chain) throws IOException {
Request request = chain.request();
//拦截处理重复的HTTP 请求,类似 防止快速点击按钮去重 可以不去处理了,全局统一处理
String requestKey = MD5Util.getUpperMD5Str(request.method() + request.url().toString());
synchronized (requestIdsMap) {
if (requestIdsMap.get(requestKey) == null) {
// Log.e("REPEAT-REQUEST", "intercept: " + requestIdsMap);
requestIdsMap.put(requestKey, System.currentTimeMillis());
Log.e("REPEAT-REQUEST", "注册请求:" + requestKey + " --- " + Thread.currentThread().getName() + " URL = " + request.url());
} else {
//如果是重复的请求,抛出一个自定义的错误,这个错误大家根据自己的业务定义吧
Log.e("REPEAT-REQUEST", "重复请求:" + requestKey + " --- " + Thread.currentThread().getName() + " URL = " + request.url());
return new Response.Builder()
.protocol(Protocol.get(CUSTOM_REPEAT_REQ_PROTOCOL))
.request(request) //multi thread
.build();
}
}
Response originalResponse = chain.proceed(request);
return originalResponse.newBuilder().build();
}
};
Interceptor interceptor = new Interceptor() {
@NotNull
@Override
public Response intercept(@NotNull Chain chain) throws IOException {
Request request = chain.request();
//相同的请求
String requestKey = MD5Util.getUpperMD5Str(request.method() + request.url().toString());
long time = System.currentTimeMillis();//请求时间
try {
if (requestIdsMap.size() > 0 && requestIdsMap.containsKey(requestKey)) {
Log.e("REPEAT-REQUEST", "重复请求:" + requestKey + " Method @" + request.method() + " --- " + " URL = " + request.url());
chain.call().cancel();
return new Response.Builder()
.protocol(Protocol.get(CUSTOM_REPEAT_REQ_PROTOCOL))
.request(request) //multi thread
.build();
}
requestIdsMap.put(requestKey, time);
Log.e("REPEAT-REQUEST", "注册请求:" + requestKey + " Method @" + request.method() + " --- " + " URL = " + request.url());
// Request.Builder builder = request.newBuilder();
// builder.addHeader("header", jsonObject.toString());
return chain.proceed(request);
} catch (IOException e) {
throw e;
} finally {
if (requestIdsMap.containsKey(requestKey) && requestIdsMap.containsValue(time)) {//请求任务完成删除map中的数据
requestIdsMap.remove(requestKey);
Log.e("REPEAT-REQUEST", "移除请求:" + requestKey + " Method @" + request.method() + " --- " + " URL = " + request.url());
}
}
}
};
//如果无法生存缓存文件目录,检测权限使用已经加上,检测手机是否把文件读写权限禁止了
OkHttpClient.Builder builder = new OkHttpClient.Builder();
builder.connectTimeout(timeOut, TimeUnit.SECONDS); // 设置连接超时时间
builder.writeTimeout(timeOut, TimeUnit.SECONDS);// 设置写入超时时间
builder.readTimeout(timeOut, TimeUnit.SECONDS);// 设置读取数据超时时间
builder.retryOnConnectionFailure(true);// 设置进行连接失败重试
builder.addInterceptor(interceptor);
// builder.addInterceptor(myHttpInterceptor);
// builder.addNetworkInterceptor(mRequestInterceptor);
// 设置缓存文件路径
String cacheDirectory = mContext.getExternalCacheDir().getAbsolutePath() + "/OkHttpCache";
Cache cache = new Cache(new File(cacheDirectory), cacheSize);
builder.cache(cache);// 设置缓存
okHttpClient = builder.build();
}
mRetrofit = new Retrofit.Builder()
.client(okHttpClient)
.baseUrl(UrlAddress.ROOT_URL)
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.build();
}
// if (null == mGankaoRetrofit) {
// mGankaoRetrofit = new Retrofit.Builder()
// .client(okHttpClient)
// .baseUrl(UrlAddress.GANKAN_ROOT_URL)
// .addConverterFactory(GsonConverterFactory.create())
// .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
// .build();
// }
}
public static void init(Context context) {
if (INSTANCE == null) {
INSTANCE = new NetInterfaceManager(context);
}
}
public static NetInterfaceManager getInstance() {
if (INSTANCE == null) {
throw new IllegalStateException("You must be init NetworkManager first");
}
return INSTANCE;
}
public OkHttpClient getOkHttpClient() {
return okHttpClient;
}
public Observable<BaseResponse<UserInfo>> getsnInfoControl() {
return mRetrofit.create(SNInfoApi.class)
.getsninfo(Utils.getSerial())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());
}
public Observable<BaseResponse> getsettingControl() {
return mRetrofit.create(Setting.class)
.getSetting(Utils.getSerial())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());
}
public Observable<BaseResponse<List<AppInfo>>> getForceInstallControl() {
return mRetrofit.create(ForceInstall.class)
.getForceInstall(Utils.getSerial())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());
}
public Observable<BaseResponse<BrowserApiData>> getBrowserControl() {
return mRetrofit.create(Browser.class)
.getBrowser(Utils.getSerial())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());
}
public Observable<BaseResponse<Label>> getLabelControl() {
return mRetrofit.create(BrowserLabel.class)
.getLabel(Utils.getSerial())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());
}
public Observable<BaseResponse<List<AppStart>>> getAppStartControl() {
return mRetrofit.create(QuerySnAppStart.class)
.getAppStatu(Utils.getSerial())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());
}
public Observable<BaseResponse<List<AppInfo>>> getQueryAllAppControl() {
return mRetrofit.create(QueryAllApp.class)
.getAllApp(Utils.getSerial())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());
}
public Observable<BaseResponse> getTimeControl() {
return mRetrofit.create(TimeControl.class)
.getTimeControl(Utils.getSerial())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());
}
public Observable<BaseResponse<UserAvatarInfo>> getUserAvatarInfoControl() {
return mRetrofit.create(UserInfoControl.class)
.getUserAvatarInfo(Utils.getSerial())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());
}
public Observable<BaseResponse> getRunningAppObservable(String json) {
return mRetrofit.create(RunningApp.class)
.sendAppInfo(Utils.getSerial(), json)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());
}
public Observable<BaseResponse> getQRCodeApiControl() {
return mRetrofit.create(QRCodeApi.class)
.getQRCodeApi()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());
}
public Observable<BaseResponse> getAppInsideControl() {
return mRetrofit.create(QueryAppInside.class)
.getAppInside(Utils.getSerial())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());
}
public Observable<BaseResponse> getGetGuideControl() {
return mRetrofit.create(GetGuideApi.class)
.getGuidePic(2)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());
}
public Observable<BaseResponse> getSnUidApiControl() {
return mRetrofit.create(GetSnUidApi.class)
.getSnUid(Utils.getSerial())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());
}
public Observable<BaseResponse> getBatchApiControl() {
return mRetrofit.create(GetBatchApi.class)
.getBatch(Utils.getSerial())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());
}
public BindDevices getbindDevicesControl() {
return mRetrofit.create(BindDevices.class);
}
public AddAppInstall getAddAppInstallControl() {
return mRetrofit.create(AddAppInstall.class);
}
public APPJump getAppJumpControl() {
return mRetrofit.create(APPJump.class);
}
public UpdateAdminSn getUpdateAdminSnControl() {
return mRetrofit.create(UpdateAdminSn.class);
}
public NewestAppUpdate getNewestAppUpdateControl() {
return mRetrofit.create(NewestAppUpdate.class);
}
public UploadScreenshot getUploadScreenshotControl() {
return mRetrofit.create(UploadScreenshot.class);
}
public ScreenLock getScreenLockControl() {
return mRetrofit.create(ScreenLock.class);
}
public ScreenState setScreen() {
return mRetrofit.create(ScreenState.class);
}
public SaveSnUidApi getSaveSnUidApiControl() {
return mRetrofit.create(SaveSnUidApi.class);
}
public AppUsedApi getAppUsedControl() {
return mRetrofit.create(AppUsedApi.class);
}
public GetControlScreenshotApi getControlScreenshotApi() {
return mRetrofit.create(GetControlScreenshotApi.class);
}
// //赶考
//
// public CreateUserApi getCreateUserControl() {
// return mGankaoRetrofit.create(CreateUserApi.class);
// }
//
// public ActiveUserApi getActiveUserControl() {
// return mGankaoRetrofit.create(ActiveUserApi.class);
// }
//
// public QueryProductApi getQueryProductControl() {
// return mGankaoRetrofit.create(QueryProductApi.class);
// }
//
// public QueryPowerUserListApi getQueryPowerUserListControl() {
// return mGankaoRetrofit.create(QueryPowerUserListApi.class);
// }
//
// public UserProductsApi getUserProductsControl() {
// return mGankaoRetrofit.create(UserProductsApi.class);
// }
//
// public CancelUserPowerApi getCancelUserPowerControl() {
// return mGankaoRetrofit.create(CancelUserPowerApi.class);
// }
//
// public UpgradeUserPowerApi getUpgradeUserPowerControl() {
// return mGankaoRetrofit.create(UpgradeUserPowerApi.class);
// }
}