Files
FLYSN/app/src/main/java/com/uiui/sn/tpush/MessageReceiver.java
2022-09-26 21:01:55 +08:00

1557 lines
68 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.uiui.sn.tpush;
import android.annotation.SuppressLint;
import android.bluetooth.BluetoothAdapter;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.media.AudioManager;
import android.net.ConnectivityManager;
import android.os.Build;
import android.os.Handler;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.WindowManager;
import android.widget.Toast;
import com.android.internal.view.RotationPolicy;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.tencent.android.tpush.NotificationAction;
import com.tencent.android.tpush.XGPushBaseReceiver;
import com.tencent.android.tpush.XGPushClickedResult;
import com.tencent.android.tpush.XGPushRegisterResult;
import com.tencent.android.tpush.XGPushShowedResult;
import com.tencent.android.tpush.XGPushTextMessage;
import com.uiui.sn.R;
import com.uiui.sn.bean.BaseResponse;
import com.uiui.sn.config.CommonConfig;
import com.uiui.sn.dialog.CustomDialog;
import com.uiui.sn.disklrucache.CacheHelper;
import com.uiui.sn.manager.ControlManager;
import com.uiui.sn.manager.ControlPanelManager;
import com.uiui.sn.manager.DeviceManager;
import com.uiui.sn.network.NetInterfaceManager;
import com.uiui.sn.receiver.BootReceiver;
import com.uiui.sn.service.ManagerService;
import com.uiui.sn.service.main.MainService;
import com.uiui.sn.tpush.common.NotificationService;
import com.uiui.sn.tpush.po.XGNotification;
import com.uiui.sn.utils.ApkUtils;
import com.uiui.sn.utils.CacheUtils;
import com.uiui.sn.utils.CmdUtil;
import com.uiui.sn.gson.GsonUtils;
import com.uiui.sn.utils.FileUtils;
import com.uiui.sn.utils.JGYUtils;
import com.uiui.sn.utils.SPUtils;
import com.uiui.sn.utils.ServiceAliveUtils;
import com.uiui.sn.utils.ToastUtil;
import com.uiui.sn.utils.Utils;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.lang.reflect.Method;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.annotations.NonNull;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.core.ObservableEmitter;
import io.reactivex.rxjava3.core.ObservableOnSubscribe;
import io.reactivex.rxjava3.core.ObservableSource;
import io.reactivex.rxjava3.core.Observer;
import io.reactivex.rxjava3.disposables.Disposable;
import io.reactivex.rxjava3.functions.Consumer;
import io.reactivex.rxjava3.functions.Function;
import io.reactivex.rxjava3.schedulers.Schedulers;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;
import static com.uiui.sn.service.ManagerService.LOCK_STATE;
public class MessageReceiver extends XGPushBaseReceiver {
public static final String UPDATE_LISTVIEW_ACTION = "com.qq.xgdemo.activity.UPDATE_LISTVIEW";
public static final String TEST_ACTION = "com.qq.xgdemo.activity.TEST_ACTION";
public static final String LogTag = "xg.test";
private static final String TAG = MessageReceiver.class.getSimpleName();
private Context mContext;
private ContentResolver mResolver;
private PackageManager mPackageManager;
private CacheHelper mCacheHelper;
/**
* 消息透传处理
*
* @param context
* @param message 解析自定义的 JSON
*/
@Override
public void onTextMessage(Context context, XGPushTextMessage message) {
this.mContext = context;
this.mResolver = context.getContentResolver();
this.mPackageManager = context.getPackageManager();
this.mCacheHelper = new CacheHelper(context);
String text = "收到消息:" + message.toString();
// 获取自定义key-value
String customContent = message.getCustomContent();
if (customContent != null && customContent.length() != 0) {
JsonObject obj = JsonParser.parseString(customContent).getAsJsonObject();
// key1为前台配置的key
if (!TextUtils.isEmpty(obj.get("key").getAsString())) {
String value = obj.get("key").getAsString();
Log.d(LogTag, "get custom value:" + value);
}
// ...
}
// APP自主处理消息的过程...
Log.e(LogTag, text);
show(context, text);
processCustomMessage(context, message);
}
/**
* 通知展示
*
* @param context
* @param notifiShowedRlt 包含通知的内容
*/
@Override
public void onNotificationShowedResult(Context context, XGPushShowedResult notifiShowedRlt) {
if (context == null || notifiShowedRlt == null) {
return;
}
XGNotification notific = new XGNotification();
notific.setMsg_id(notifiShowedRlt.getMsgId());
notific.setTitle(notifiShowedRlt.getTitle());
notific.setContent(notifiShowedRlt.getContent());
// notificationActionType==1为Activity2为url3为intent
notific.setNotificationActionType(notifiShowedRlt
.getNotificationActionType());
// Activity,url,intent都可以通过getActivity()获得
notific.setActivity(notifiShowedRlt.getActivity());
notific.setUpdate_time(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
.format(Calendar.getInstance().getTime()));
NotificationService.getInstance(context).save(notific);
Intent testIntent = new Intent(TEST_ACTION);
if (notifiShowedRlt.getTitle().equals(Constants.LOCAL_NOTIFICATION_TITLE)) {
testIntent.putExtra("step", Constants.TEST_LOCAL_NOTIFICATION);
} else {
testIntent.putExtra("step", Constants.TEST_NOTIFICATION);
}
context.sendBroadcast(testIntent);
Intent viewIntent = new Intent(UPDATE_LISTVIEW_ACTION);
context.sendBroadcast(viewIntent);
show(context, "您有1条新消息, " + "通知被展示 " + notifiShowedRlt.toString());
Log.d(LogTag, "您有1条新消息, " + "通知被展示 " + notifiShowedRlt.toString() + ", PushChannel:" + notifiShowedRlt.getPushChannel());
}
/**
* 注册回调
*
* @param context
* @param errorCode 0 为成功,其它为错误码
*/
@Override
public void onRegisterResult(Context context, int errorCode, XGPushRegisterResult message) {
if (context == null || message == null) {
return;
}
String text = "";
if (errorCode == XGPushBaseReceiver.SUCCESS) {
// 在这里拿token
String token = message.getToken();
text = "注册成功1. token" + token;
} else {
text = message + "注册失败,错误码:" + errorCode;
}
Log.d(LogTag, text);
show(context, text);
}
/**
* 反注册回调
*
* @param context
* @param errorCode 0 为成功,其它为错误码
*/
@Override
public void onUnregisterResult(Context context, int errorCode) {
if (context == null) {
return;
}
String text = "";
if (errorCode == XGPushBaseReceiver.SUCCESS) {
text = "反注册成功";
} else {
text = "反注册失败" + errorCode;
}
Log.d(LogTag, text);
show(context, text);
}
/**
* 设置标签回调
*
* @param context
* @param errorCode 0 为成功,其它为错误码
* @param tagName 设置的 TAG
*/
@Override
public void onSetTagResult(Context context, int errorCode, String tagName) {
if (context == null) {
return;
}
String text = "";
if (errorCode == XGPushBaseReceiver.SUCCESS) {
text = "\"" + tagName + "\"设置成功";
} else {
text = "\"" + tagName + "\"设置失败,错误码:" + errorCode;
}
Log.d(LogTag, text);
show(context, text);
Intent testIntent = new Intent(TEST_ACTION);
testIntent.putExtra("step", Constants.TEST_SET_TAG);
context.sendBroadcast(testIntent);
}
/**
* 删除标签的回调
*
* @param context
* @param errorCode 0 为成功,其它为错误码
* @param tagName 设置的 TAG
*/
@Override
public void onDeleteTagResult(Context context, int errorCode, String tagName) {
if (context == null) {
return;
}
String text = "";
if (errorCode == XGPushBaseReceiver.SUCCESS) {
text = "\"" + tagName + "\"删除成功";
} else {
text = "\"" + tagName + "\"删除失败,错误码:" + errorCode;
}
Log.d(LogTag, text);
show(context, text);
Intent testIntent = new Intent(TEST_ACTION);
testIntent.putExtra("step", Constants.TEST_DEL_TAG);
context.sendBroadcast(testIntent);
}
/**
* 设置账号回调
*
* @param context
* @param errorCode 0 为成功,其它为错误码
* @param account 设置的账号
*/
@Override
public void onSetAccountResult(Context context, int errorCode, String account) {
Intent testIntent = new Intent(TEST_ACTION);
testIntent.putExtra("step", Constants.TEST_SET_ACCOUNT);
context.sendBroadcast(testIntent);
}
/**
* 删除账号回调
*
* @param context
* @param errorCode 0 为成功,其它为错误码
* @param account 设置的账号
*/
@Override
public void onDeleteAccountResult(Context context, int errorCode, String account) {
Intent testIntent = new Intent(TEST_ACTION);
testIntent.putExtra("step", Constants.TEST_DEL_ACCOUNT);
context.sendBroadcast(testIntent);
}
@Override
public void onSetAttributeResult(Context context, int i, String s) {
}
@Override
public void onDeleteAttributeResult(Context context, int i, String s) {
}
@Override
public void onQueryTagsResult(Context context, int errorCode, String data, String operateName) {
Log.i(LogTag, "action - onQueryTagsResult, errorCode:" + errorCode + ", operateName:" + operateName + ", data: " + data);
}
/**
* 通知点击回调 actionType=1为该消息被清除actionType=0为该消息被点击
*
* @param context
* @param message 包含被点击通知的内容
*/
@Override
public void onNotificationClickedResult(Context context, XGPushClickedResult message) {
if (context == null || message == null) {
return;
}
String text = "";
if (message.getActionType() == NotificationAction.clicked.getType()) {
// 通知在通知栏被点击啦。。。。。
// APP自己处理点击的相关动作
// 这个动作可以在activity的onResume也能监听请看第3点相关内容
text = "通知被打开 :" + message;
} else if (message.getActionType() == NotificationAction.delete.getType()) {
// 通知被清除啦。。。。
// APP自己处理通知被清除后的相关动作
text = "通知被清除 :" + message;
}
Toast.makeText(context, "广播接收到通知被点击:" + message.toString(),
Toast.LENGTH_SHORT).show();
// 获取自定义key-value
String customContent = message.getCustomContent();
if (customContent != null && customContent.length() != 0) {
JsonObject obj = JsonParser.parseString(customContent).getAsJsonObject();
// key1为前台配置的key
if (!TextUtils.isEmpty(obj.get("key").getAsString())) {
String value = obj.get("key").getAsString();
Log.d(LogTag, "get custom value:" + value);
}
// ...
}
// APP自主处理的过程。。。
Log.d(LogTag, text);
show(context, text);
}
private void show(Context context, String text) {
// Toast.makeText(context, text, Toast.LENGTH_SHORT).show();
}
//定义接收极光推送消息的类型。
//1.获取设备在线信息
private static final String JIGUANG_GET_DRIVELINE = "1";
// 2.获取当前正在运行得应用和电量
private static final String JIGUANG_GET_STARTTIME = "2";
// 3.数据线传输管控
private static final String JIGUANG_USB_STATE = "3";
// 4.TF卡管控
private static final String JIGUANG_TFCARD_STATE = "4";
// 5.蓝牙管控
private static final String JIGUANG_BLUETOOTH_STATE = "5";
// 6.浏览器上网管控
private static final String JIGUANG_BROWSER_URLPATH = "6";
// 7.应用联网管控
private static final String JIGUANG_APP_NETWORKSTATE = "7";
// 8.应用锁管控
private static final String JIGUANG_APP_LOCKEDSTATE = "8";
// 9.强制安装应用
private static final String JIGUANG_FORCE_INSTALLAPK = "9";
// 10.强制卸载应用
private static final String JIGUANG_FORCE_UNINSTALLAPK = "10";
// 11.绑定设备
private static final String JIGUANG_BIND_DEVIVES = "11";
//12.影音格式管控
private static final String JIGUANG_TFMEDIA = "12";
//13.摄像头管控
private static final String JIGUANG_CAMRERA = "13";
//14.电话管控管控
private static final String JIGUANG_PHONE = "14";
//15.禁止升级
private static final String JIGUANG_DISABLE_UPDATAE = "15";
//16.app内部网址管控
private static final String JIGUANG_APP_WEBSITE = "16";
//设备恢复出厂设置
private static final String JIGUANG_RESET_DEVICES = "17";
//浏览器书签
private static final String JIGUANG_BROWSER_LABEL = "18";
//APP联网自启管控
private static final String JIGUANG_APP_NET_AUTO = "19";
//系统管控
private static final String JIGUANG_SYSTEM_SETTING = "21";
//重启
private static final String JIGUANG_REBOOT_DEVICES = "22";
//获取app管控设置
private static final String JIGUANG_APP_SETTING = "23";
//强制停止应用
private static final String JIGUANG_FORCE_KILL = "24";
//锁屏
private static final String JIGUANG_LOCK_SCREEN = "25";
//截图
private static final String JIGUANG_SNAPSHOT = "26";
//时间管控
private static final String JIGUANG_TIME_CONTROL = "27";
//热点管控
private static final String JIGUANG_HOTSPOT_CONTROL = "29";
//禁止恢复出厂设置
private static final String JIGUANG_RESTORE_CONTROL = "30";
//浏览器禁止输入
private static final String JIGUANG_BROWSER_CONTROL = "32";
//开发人员选项
private static final String JIGUANG_DEVELOPER_CONTROL = "33";
//清除应用缓存
private static final String JIGUANG_CLEAN_APP_CACHE = "34";
//几个桌面图标
private static final String JIGUANG_APP_RECORDER = "35";
private static final String JIGUANG_APP_FILE_MANAGER = "36";
private static final String JIGUANG_APP_GALLERY = "37";
private static final String JIGUANG_APP_MUSIC = "38";
private static final String JIGUANG_APP_BROWSER = "43";
//搜题开关
private static final String JIGUANG_SEARCH_TOPIC = "39";
//电话白名单推送
private static final String JIGUANG_PHONE_LIST = "40";
//调整套餐
private static final String JIGUANG_CHANGE_COMBO = "41";
//取消所有套餐
private static final String JIGUANG_CANCEL_COMBO = "42";
//升级套餐
private static final String JIGUANG_UPGRADE_COMBO = "44";
//设备授权和解除
private static final String JIGUANG_BIND_UNBIND = "45";
//飞行模式
private static final String JIGUANG_FLIGHT_MODE = "47";
//勿扰模式
private static final String JIGUANG_NOTDISTURB_MODE = "48";
//定位
private static final String JIGUANG_LOCATION = "49";
//充电提醒
private static final String JIGUANG_CHARGING_REMINDER = "50";
//音量调节
private static final String JIGUANG_VOLUME = "52";
//亮度调节
private static final String JIGUANG_LUMINANCE = "53";
//字体大小调节
private static final String JIGUANG_TYPEFACE = "54";
//自动旋转
private static final String JIGUANG_SCREEN_ROTATION = "55";
//WiFi设置
private static final String JIGUANG_WIFI_SET = "56";
//闹钟
private static final String JIGUANG_ALARM_CLOCK = "57";
//应用白名单
private static final String JIGUANG_APP_WHITELIST = "58";
//隐藏图标
private static final String JIGUANG_HIDE_APPICON = "59";
//优化内存
private static final String JIGUANG_KILL_APP = "60";
//SOS联系人
private static final String JIGUANG_SOS_PHONENUM = "61";
//重新安装应用
private static final String JIGUANG_REINSTALL_APP = "62";
//显示所有的admin应用
private static final String JIGUANG_ADMIN_APP = "63";
/*投屏开关*/
private static final String SCRENN_SHARED = "74";
/*移动热点开关*/
private static final String HOT_SPOT = "75";
/*桌面默认应用*/
private static final String ACTION_DEFAULT_DESKTOP = "76";
/*浏览器默认应用*/
private static final String ACTION_DEFAULT_BRPWSER = "77";
/*输入法默认应用*/
private static final String ACTION_DEFAULT_INPUT_METHOD = "78";
/*家长管控开关*/
private static final String ACTION_PARENTAL_CONTROL = "79";
/*整机管控配置*/
private static final String ACTION_WHOLE_MACHINE_QUOTA = "80";
/*APP管控配置*/
private static final String ACTION_APP_CONTROL = "81";
/*更新白名单*/
private static final String UPDATE_WHITE_LIST = "83";
/*一键断网*/
private static final String ACTION_DISABLE_NETWORK = "85";
private void processCustomMessage(Context context, XGPushTextMessage message) {
if (context == null || message == null) {
return;
}
String title = message.getTitle();
String content = message.getContent();
JsonObject extrasJson = JsonParser.parseString(content).getAsJsonObject();
String extras = "";
if (extrasJson.get("extras") != null) {
extras = extrasJson.get("extras").toString();
}
switch (title) {
case JIGUANG_GET_DRIVELINE:
ToastUtil.debugShow("收到推送消息: 获取在线信息");
// NetInterfaceManager.getInstance().getDriveState(member_id, sn_id);
break;
case JIGUANG_GET_STARTTIME:
ToastUtil.debugShow("收到推送消息: 获取运行应用");
sendStartTime(context, extras);
break;
case JIGUANG_USB_STATE:
ToastUtil.debugShow("收到推送消息: USB连接模式管控");
setUsbStatus(context, extras);
break;
case JIGUANG_TFCARD_STATE:
ToastUtil.debugShow("收到推送消息: TF卡管控");
setTfcardState(context, extras);
break;
case JIGUANG_BLUETOOTH_STATE:
ToastUtil.debugShow("收到推送消息: 蓝牙管控");
setBluetoothState(context, extras);
break;
case JIGUANG_BROWSER_URLPATH:
ToastUtil.debugShow("收到推送消息: 浏览器上网管控");
// setBrowserUrlpath(context, extras);
try {
new CacheUtils().cleanApplicationUserData(context, "com.android.browser");
} catch (Exception e) {
e.printStackTrace();
}
Handler.getMain().postDelayed(new Runnable() {
@Override
public void run() {
NetInterfaceManager.getInstance().setBrowserWhiteList();
}
}, 2000);
break;
case JIGUANG_APP_NETWORKSTATE:
ToastUtil.debugShow("收到推送消息: 应用联网管控");
setAppNetworkstate(context, extras);
Handler.getMain().postDelayed(new Runnable() {
@Override
public void run() {
NetInterfaceManager.getInstance().getAppInside();
}
}, 2000);
break;
case JIGUANG_APP_LOCKEDSTATE:
ToastUtil.debugShow("收到推送消息: 应用锁管控");
setAppLockedstate(context, extras);
break;
case JIGUANG_FORCE_INSTALLAPK:
ToastUtil.debugShow("收到推送消息: 强制安装应用");
NetInterfaceManager.getInstance().getAllappPackage();
NetInterfaceManager.getInstance().getOverallApp();
intallApk(context, extras);
break;
case JIGUANG_FORCE_UNINSTALLAPK:
ToastUtil.debugShow("收到推送消息: 强制卸载应用");
unintallApk(context, extras);
break;
case JIGUANG_BIND_DEVIVES:
ToastUtil.debugShow("收到推送消息: 绑定设备");
bindService(context, extras);
break;
case JIGUANG_TFMEDIA:
ToastUtil.debugShow("收到推送消息: 影音格式管控");
setTFmedia(context, extras);
break;
case JIGUANG_CAMRERA:
ToastUtil.debugShow("收到推送消息: 摄像头管控");
setCameta(context, extras);
JGYUtils.getInstance().updateForbidList();
break;
case JIGUANG_PHONE:
ToastUtil.debugShow("收到推送消息: 电话管控");
setPhone(extras);
break;
case JIGUANG_DISABLE_UPDATAE:
ToastUtil.debugShow("收到推送消息: 禁止升级");
setAppUpdate(context, extras);
break;
case JIGUANG_APP_WEBSITE:
ToastUtil.debugShow("收到推送消息: app内部网址管控");
// NetInterfaceManager.getInstance().getAppJump(context);
break;
case JIGUANG_REBOOT_DEVICES:
ToastUtil.debugShow("收到推送消息: 重启");
DeviceManager.rebootDevices();
break;
case JIGUANG_APP_NET_AUTO:
ToastUtil.debugShow("收到推送消息: APP联网自启管控");
Handler.getMain().postDelayed(() -> NetInterfaceManager.getInstance().getAllappPackage(), 2000);
break;
case JIGUANG_BROWSER_LABEL:
ToastUtil.debugShow("收到推送消息: 浏览器书签");
try {
new CacheUtils().cleanApplicationUserData(context, "com.android.browser");
} catch (Exception e) {
e.printStackTrace();
}
//延时2秒执行以防收到推送数据库还没有生效
Handler.getMain().postDelayed(new Runnable() {
@Override
public void run() {
NetInterfaceManager.getInstance().getBrowserWhiteList();
NetInterfaceManager.getInstance().getBrowserLabel();
}
}, 2000);
break;
case JIGUANG_SYSTEM_SETTING:
ToastUtil.debugShow("收到推送消息: 系统管控");
// ControlManager.getInstance().setSystemSetting(extras);
MainService.getPresenter().getSystemSettings();
// if ("com.jiaoguanyi.os".equals(ForegroundAppUtil.getForegroundPackageName(context))) {
// JGYUtils.getInstance().killBackgroundProcesses(context, "com.jiaoguanyi.os");
// Intent intent = context.getPackageManager().getLaunchIntentForPackage("com.jiaoguanyi.os");
// intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// context.startActivity(intent);
// } else {
// JGYUtils.getInstance().killBackgroundProcesses(context, "com.jiaoguanyi.os");
// }
break;
case JIGUANG_RESET_DEVICES:
ToastUtil.debugShow("收到推送消息: 设备恢复出厂设置");
try {
mCacheHelper.delete();
} catch (IOException e) {
e.printStackTrace();
}
DeviceManager.doMasterClear();
break;
case JIGUANG_APP_SETTING:
ToastUtil.debugShow("收到推送消息: 获取app管控设置");
Handler.getMain().postDelayed(() -> NetInterfaceManager.getInstance().getAllappPackage(), 2000);
break;
case JIGUANG_FORCE_KILL:
ToastUtil.debugShow("收到推送消息: 强制停止应用");
JsonObject killJSONObject = GsonUtils.getJsonObject(extras);
String packages = killJSONObject.get("app_package").getAsString();
JGYUtils.getInstance().killBackgroundProcesses(packages);
JGYUtils.getInstance().gotoLauncher();
Log.e(TAG, extras);
break;
case JIGUANG_LOCK_SCREEN:
ToastUtil.debugShow("收到推送消息: 锁屏");
setLock_screen(context, extras);
Log.e(TAG, extras);
break;
case JIGUANG_SNAPSHOT:
ToastUtil.debugShow("收到推送消息: 截图");
doscreenshot(context);
Log.e(TAG, extras);
break;
case JIGUANG_TIME_CONTROL:
ToastUtil.debugShow("收到推送消息: 时间管控");
timeControl(context, extras);
break;
case JIGUANG_HOTSPOT_CONTROL:
ToastUtil.debugShow("收到推送消息: 热点管控");
setHotspot(context, extras);
break;
case JIGUANG_RESTORE_CONTROL:
ToastUtil.debugShow("收到推送消息: 恢复出厂设置管控");
setRestore(context, extras);
break;
case JIGUANG_BROWSER_CONTROL:
ToastUtil.debugShow("收到推送消息: 浏览器禁止输入");
setBrowserInput(context, extras);
break;
case JIGUANG_DEVELOPER_CONTROL:
ToastUtil.debugShow("收到推送消息: 开发人员选项");
ControlManager.getInstance().setDeveloperOptions(extras);
break;
case JIGUANG_CLEAN_APP_CACHE:
ToastUtil.debugShow("收到推送消息: 清除应用缓存");
cleanAppCache(context, extras);
break;
case JIGUANG_APP_RECORDER:
case JIGUANG_APP_FILE_MANAGER:
case JIGUANG_APP_GALLERY:
case JIGUANG_APP_MUSIC:
ToastUtil.debugShow("收到推送消息: 系统APP管控");
hideDesktopIcon();
break;
case JIGUANG_SEARCH_TOPIC:
ToastUtil.debugShow("收到推送消息: 搜题开关");
searchTopic(context, extras);
break;
case JIGUANG_PHONE_LIST:
ToastUtil.debugShow("收到推送消息: 电话白名单管控");
setPhone(extras);
break;
case JIGUANG_CHANGE_COMBO:
ToastUtil.debugShow("更换套餐");
break;
case JIGUANG_CANCEL_COMBO:
ToastUtil.debugShow("取消套餐");
break;
case JIGUANG_UPGRADE_COMBO:
ToastUtil.debugShow("升级套餐");
case JIGUANG_APP_BROWSER:
ToastUtil.debugShow("收到推送消息: 系统APP管控");
Log.e(TAG, "processCustomMessage: " + extras);
hideDesktopIcon();
break;
case JIGUANG_BIND_UNBIND:
ToastUtil.debugShow("老师授权/取消授权");
MainService.getPresenter().getAllApp();
MainService.getPresenter().getForceInstall();
try {
mCacheHelper.delete();
} catch (IOException e) {
e.printStackTrace();
}
DeviceManager.doMasterClear();
break;
case JIGUANG_FLIGHT_MODE:
break;
case JIGUANG_NOTDISTURB_MODE:
ToastUtil.debugShow("收到推送消息: 设置勿扰模式");
setZenMode(context, extras);
break;
case JIGUANG_LOCATION:
ToastUtil.debugShow("收到推送消息: 定位设置");
break;
case JIGUANG_CHARGING_REMINDER:
break;
case JIGUANG_VOLUME:
ToastUtil.debugShow("收到推送消息: 设置音量");
setVolume(context, extras);
break;
case JIGUANG_LUMINANCE:
ToastUtil.debugShow("收到推送消息: 设置屏幕亮度");
setScreenBrightness(context, extras);
break;
case JIGUANG_TYPEFACE:
ToastUtil.debugShow("收到推送消息: 设置字体大小");
setFontSize(context, extras);
break;
case JIGUANG_SCREEN_ROTATION:
ToastUtil.debugShow("收到推送消息: 设置自动旋转");
setRotationLock(context, extras);
break;
case JIGUANG_WIFI_SET:
break;
case JIGUANG_ALARM_CLOCK:
setAlarmCLock(context, extras);
break;
case JIGUANG_APP_WHITELIST:
break;
case JIGUANG_HIDE_APPICON:
break;
case JIGUANG_KILL_APP:
ToastUtil.debugShow("收到推送消息: 内存优化");
Utils.killBackgroundApp(context);
break;
case JIGUANG_SOS_PHONENUM:
setSOSPhoneNumber(context, extras);
break;
case JIGUANG_REINSTALL_APP:
reinstallApp(context, extras);
break;
case JIGUANG_ADMIN_APP:
setAdminApp(context, extras);
break;
case SCRENN_SHARED:
ToastUtil.debugShow("收到推送消息: 投屏开关");
break;
case HOT_SPOT:
ToastUtil.debugShow("收到推送消息: 热点开关");
setHotPoint(context, extras);
break;
case ACTION_DEFAULT_DESKTOP:
setDefaultDesktop(context, extras);
break;
case ACTION_DEFAULT_BRPWSER:
setDefaultBrowser(context, extras);
break;
case ACTION_DEFAULT_INPUT_METHOD:
setDefaultInputMethod(context, extras);
break;
case ACTION_PARENTAL_CONTROL:
NetInterfaceManager.getInstance().getSystemSettings();
break;
case ACTION_WHOLE_MACHINE_QUOTA:
NetInterfaceManager.getInstance().getAppTimeControl();
NetInterfaceManager.getInstance().getSnTimeControl();
break;
case ACTION_APP_CONTROL:
NetInterfaceManager.getInstance().getAppTimeControl();
break;
case UPDATE_WHITE_LIST:
NetInterfaceManager.getInstance().getAllappPackage();
break;
case ACTION_DISABLE_NETWORK:
ToastUtil.debugShow("收到推送消息: 一键断网");
oneKeyNetwork(context, extras);
break;
default:
}
}
private void setAdminApp(Context context, String extras) {
JsonObject jsonObject = GsonUtils.getJsonObject(extras);
int setting_admin_app = jsonObject.get("setting_admin_app").getAsInt();
Settings.System.putInt(context.getContentResolver(), "setting_admin_app", setting_admin_app);
}
private void setZenMode(Context context, String extras) {
JsonObject jsonObject = GsonUtils.getJsonObject(extras);
int setting_disturbance = jsonObject.get("setting_disturbance").getAsInt();
}
private void setRotationLock(Context context, String extras) {
JsonObject jsonObject = GsonUtils.getJsonObject(extras);
int setting_rotation = jsonObject.get("setting_rotation").getAsInt();
RotationPolicy.setRotationLock(context, setting_rotation == 0);
}
private void setScreenBrightness(Context context, String extras) {
JsonObject jsonObject = GsonUtils.getJsonObject(extras);
int setting_luminance = jsonObject.get("setting_luminance").getAsInt();
Settings.System.putInt(context.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE, Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL);
int Scrern_brightness = (int) ((1.0 * 255 / 100) * setting_luminance);
Settings.System.putInt(context.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, Scrern_brightness);
}
private float[] mValues;
/**
* Index of the entry corresponding to current value of the settings.
*/
protected int mCurrentIndex;
/**
* List of entries corresponding the settings being set.
*/
protected List<String> mEntries;
private void setFontSize(Context context, String extras) {
JsonObject jsonObject = GsonUtils.getJsonObject(extras);
String setting_typeface = jsonObject.get("setting_typeface").getAsString();
final Resources res = context.getResources();
mEntries = Arrays.asList(res.getStringArray(R.array.entries_font_size));
final String[] strEntryValues = res.getStringArray(R.array.entryvalues_font_size);
mValues = new float[strEntryValues.length];
for (int i = 0; i < strEntryValues.length; ++i) {
mValues[i] = Float.parseFloat(strEntryValues[i]);
}
mCurrentIndex = mEntries.indexOf(setting_typeface);
if (mCurrentIndex == -1) {
return;
}
Settings.System.putFloat(context.getContentResolver(), Settings.System.FONT_SCALE, mValues[mCurrentIndex]);
}
private void setVolume(Context context, String extras) {
JsonObject jsonObject = GsonUtils.getJsonObject(extras);
int setting_volume = jsonObject.get("setting_volume").getAsInt();
//获取系统的Audio管理者
AudioManager mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
//最大音量
int maxVolume = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
//当前音量
// int currentVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
int currentVolume = (int) ((1.0f * maxVolume / 100) * setting_volume);
mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, currentVolume, 0);
}
private int changeNum(int paramInt) {
return paramInt == 1 ? 0 : 1;
}
synchronized private void sendStartTime(Context context, String jsonString) {
NetInterfaceManager.getInstance().updateAdminInfo();
NetInterfaceManager.getInstance().sendRunningApp();
NetInterfaceManager.getInstance().SendAppInstallInfo();
if (JGYUtils.getInstance().isScreenOn()) {
NetInterfaceManager.getInstance().screenshot();
}
}
synchronized private void setUsbStatus(Context context, String jsonString) {
if (!TextUtils.isEmpty(jsonString)) {
JsonObject jsonObject = GsonUtils.getJsonObject(jsonString);
String setting_usb = jsonObject.get("setting_usb").getAsString();
ControlManager.getInstance().setUSBstate(setting_usb);
} else {
ToastUtil.debugShow("setUsbState jsonString is NULL");
}
}
synchronized private void setTfcardState(Context context, String jsonString) {
if (!TextUtils.isEmpty(jsonString)) {
JsonObject extra = GsonUtils.getJsonObject(jsonString);
int is_tf = extra.get("setting_memory").getAsInt();
boolean aole_sdcard_forbid_on = Settings.System.putInt(context.getContentResolver(), CommonConfig.AOLE_ACTION_SDCARD_FORBID_ON, changeNum(is_tf));
if (aole_sdcard_forbid_on) {
Log.e("setTfcardState:", Settings.System.getString(context.getContentResolver(), CommonConfig.AOLE_ACTION_SDCARD_FORBID_ON));
} else {
ToastUtil.debugShow("setTfcardState failed,state:" + is_tf);
}
} else {
ToastUtil.debugShow("setTfcardState jsonString is NULL");
}
}
private BluetoothAdapter mBluetoothAdapter;
synchronized private void setBluetoothState(Context context, String jsonString) {
if (!TextUtils.isEmpty(jsonString)) {
if (null == mBluetoothAdapter) {
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();//获取默认蓝牙适配器
}
JsonObject extra = GsonUtils.getJsonObject(jsonString);
int is_bluetooth = changeNum(extra.get("setting_bht").getAsInt());
Log.e(TAG, "aole_bht_forbid_on: " + is_bluetooth);
try {
//写入系统数据库
boolean aole_bht_forbid_on = Settings.System.putInt(context.getContentResolver(), CommonConfig.AOLE_ACTION_BHT_FORBID_ON, is_bluetooth);
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, is_bluetooth);
//设置关闭时关闭蓝牙
mBluetoothAdapter.disable();
}
} catch (Exception e) {
Log.e(TAG, "setBluetooth: " + e.getMessage());
}
} else {
ToastUtil.debugShow("setBluetoothState jsonString is NULL");
}
}
synchronized private void setAppNetworkstate(Context context, String jsonString) {
if (!TextUtils.isEmpty(jsonString)) {
JsonObject extra = GsonUtils.getJsonObject(jsonString);
String package0 = extra.get("package0").getAsString();
String package1 = extra.get("package1").getAsString();
if (package0.length() != 0) {
boolean aole_network_allow = Settings.System.putString(context.getContentResolver(), CommonConfig.AOLE_ACTION_NETWORK_ALLOW, package0);
Log.e("fht", "aole_network_allow::" + aole_network_allow + ":" + Settings.System.getString(context.getContentResolver(), CommonConfig.AOLE_ACTION_NETWORK_ALLOW));
} else {
boolean aole_network_allow = Settings.System.putString(context.getContentResolver(), CommonConfig.AOLE_ACTION_NETWORK_ALLOW, "");
Log.e("fht", "aole_network_allow::" + aole_network_allow + ":" + Settings.System.getString(context.getContentResolver(), CommonConfig.AOLE_ACTION_NETWORK_ALLOW));
}
if (package1.length() != 0) {
boolean aole_network_disallow = Settings.System.putString(context.getContentResolver(), CommonConfig.AOLE_ACTION_NETWORK_DISALLOW, package1);
Log.e("fht", "aole_network_disallow::" + aole_network_disallow + ":" + Settings.System.getString(context.getContentResolver(), CommonConfig.AOLE_ACTION_NETWORK_DISALLOW));
} else {
boolean aole_network_disallow = Settings.System.putString(context.getContentResolver(), CommonConfig.AOLE_ACTION_NETWORK_DISALLOW, "");
Log.e("fht", "aole_network_disallow::" + aole_network_disallow + ":" + Settings.System.getString(context.getContentResolver(), CommonConfig.AOLE_ACTION_NETWORK_DISALLOW));
}
} else {
ToastUtil.debugShow("setAppNetworkstate jsonString is NULL");
}
}
synchronized private void setAppLockedstate(Context context, String jsonString) {
if (!TextUtils.isEmpty(jsonString)) {
JsonObject extra = GsonUtils.getJsonObject(jsonString);
String packageName = extra.get("package").getAsString();
int is_lock = extra.get("is_lock").getAsInt();
ToastUtil.debugShow("收到应用锁管控消息:包名" + packageName + "is_lock_state:" + is_lock);
PackageManager pm = context.getPackageManager();
//后台为0可能传过来null
if (is_lock == 1) {
pm.setApplicationEnabledSetting(packageName, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, 0);
} else {
pm.setApplicationEnabledSetting(packageName, PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, 0);
}
} else {
ToastUtil.debugShow("setAppLockedstate jsonString is NULL");
}
}
private void intallApk(Context context, String jsonString) {
if (TextUtils.isEmpty(jsonString)) {
return;
}
JsonObject extra = GsonUtils.getJsonObject(jsonString);
String packages = extra.get("package").getAsString();
ToastUtil.debugShow("收到应用安装消息:包名" + packages);
String url = extra.get("url").getAsString();
if (TextUtils.isEmpty(url)) {
return;
}
long app_version_code = extra.get("app_version_code").getAsLong();
PackageInfo info = null;
PackageManager pm = context.getPackageManager();
try {
info = pm.getPackageInfo(packages, 0);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
if (null != info) {
long appVersionCode;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
appVersionCode = info.getLongVersionCode();
} else {
appVersionCode = info.versionCode;
}
if (appVersionCode < app_version_code) {
Log.e(TAG, "intallApk: " + "need to upgrade");
FileUtils.ariaDownload(context, url, extra);
} else
Log.e(TAG, "intallApk: " + "it's up to date , no need upgrade");
} else {
Log.e(TAG, "intallApk: " + "not installed , upgrade");
FileUtils.ariaDownload(context, url, extra);
}
}
synchronized private void unintallApk(Context context, String jsonString) {
int sn_id = (int) SPUtils.get(context, "sn_id", -1);
JsonObject object = GsonUtils.getJsonObject(jsonString);
String packageName = object.get("app_package").getAsString();
// 台电设备不删除无法静默卸载
removeForceSettings(context, packageName);
ToastUtil.debugShow("收到应用卸载消息:包名" + packageName);
if (!"".equals(packageName) && !packageName.equals(context.getApplicationContext().getPackageName())) {
if (!ApkUtils.isAvailable(context.getApplicationContext(), packageName)) {
// NetInterfaceManager.getInstance().setAppuninstallInfo(sn_id, packageName);
} else {
ApkUtils.uninstallApp(context, packageName);
}
}
}
private boolean removeForceSettings(Context context, String pkg) {
String force_app = Settings.System.getString(context.getContentResolver(), CommonConfig.AOLE_ACTION_FORCE_APP);
if (!TextUtils.isEmpty(force_app)) {
Set<String> appSet = new HashSet<>(new ArrayList<>(Arrays.asList(force_app.split(","))));
appSet.remove(pkg);
return Settings.System.putString(context.getContentResolver(), CommonConfig.AOLE_ACTION_FORCE_APP, String.join(",", appSet));
}
return true;
}
private Disposable subscribe;
private long cutdownTime = 30;
private CustomDialog dialog;
synchronized void bindService(final Context context, String jsonString) {
ToastUtil.debugShow("收到绑定设备请求");
JsonObject object = GsonUtils.getJsonObject(jsonString);
String userName = object.get("member_name").getAsString();
final String id = object.get("id").getAsString();
String phoneNum = object.get("member_phone").getAsString();
dialog = new CustomDialog(context);
subscribe = Observable.interval(1, TimeUnit.SECONDS)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Consumer<Long>() {
@Override
public void accept(Long aLong) throws Exception {
// Log.e("TAG", "倒计时:" + aLong);
if (aLong < cutdownTime && !subscribe.isDisposed()) {
dialog.setNegtiveText("拒绝" + "(" + (cutdownTime - aLong) + ")");
} else {
bind(context, id, 0);
dialog.dismiss();
subscribe.dispose();
subscribe = null;
}
}
});
dialog.setMessage(phoneNum + "的用户请求绑定你的平板")
.setTitle("绑定请求")
.setPositive("允许")
.setNegtive("拒绝")
// .setSingle(true)
.setOnClickBottomListener(new CustomDialog.OnClickBottomListener() {
@Override
public void onPositiveClick() {
bind(context, id, 1);
dialog.dismiss();
subscribe.dispose();
subscribe = null;
}
@Override
public void onNegtiveClick() {
bind(context, id, 0);
ToastUtil.show("设备取消绑定");
dialog.dismiss();
subscribe.dispose();
subscribe = null;
}
});
dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
dialog.show();
dialog.getWindow().setGravity(Gravity.CENTER);
dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
// new CountDownTimer(30000, 1000) {
// @Override
// public void onTick(long l) {
// String value = String.valueOf((int) (l / 1000));
// dialog.setNegtiveText("拒绝" + "(" + value + ")");
// }
//
// @Override
// public void onFinish() {
// bind(context, id, 0);
// dialog.dismiss();
// }
// }.start();
}
synchronized private void bind(final Context context, String id, int type) {
NetInterfaceManager.getInstance()
.getbindDevicesControl()
.getBindDevices(Utils.getSerial(), id, type)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<BaseResponse>() {
@Override
public void onSubscribe(@NonNull Disposable d) {
Log.e("bind", "onSubscribe: ");
}
@Override
public void onNext(@NonNull BaseResponse baseResponse) {
int code = baseResponse.code;
Log.e("bind", "onNext: " + baseResponse);
String msg = baseResponse.msg;
// Log.e("bind", baseResponse.toString());
if (code == 200) {
ToastUtil.show("绑定成功");
} else if (code == 301) {
ToastUtil.show(msg);
}
}
@Override
public void onError(@NonNull Throwable e) {
Log.e("bind", "onError: " + e.getMessage());
onComplete();
}
@Override
public void onComplete() {
Log.e("bind", "onComplete: ");
MainService.getPresenter().getSnInfo();
}
});
}
String tftype = ".png,.bmp,.jpg,.mpo,.jpeg,.gif,.tif,.tiff,.dib,.jpe,.jfif,.psd,.pdd,.rle,.dcm,.dic,.dc3,.eps,.iff,.tdi,.jpf,.jpx,.jp2,.j2c,.jpc,.jps,.j2k,.pcx,.pdp,.raw,.pns,.aac,.ac3,.aiff,.amr,.ape,.au,.fla,.flac,.imy,.m4r,.mid,.mka,.mmf,.mp2,.mp3,.mxmf,.ogg,.ra,.ts,.wma,.wv,.xmf,.m4a,.wav,.3gpp,.mp4,.3gp,.as,.asf,.avi,.dat,.f4v,.flv,.mkv,.mov,.mpg,.rmvb,.swf,.trp,.vob,.webm,.wmv,.navi,.video,.ram,.qsv,.xv,.rm,.vcd,.svcd,.mlv,.mpe,.mpeg,.m2v,.iso,.html,.htm,.txt,.xls,.doc,.docx,.docm,.pdf,.xps,.dot,.dotx,.dotm,.mht,.mhtml,.rft,.xml,.xlsx,.xlsm,.xlsb,.xltx,.xltm,.xlt,.wps,.wpt,.rtf,.et,.ett,.dps,.dpt,.wpp,.ppt,.pptx,.pptm,.pps,.pot,.potm,.ppsx,.ppsm,.odp";
@SuppressLint("NewApi")
private void setTFmedia(Context context, String jsonString) {
JsonObject jsonObject = GsonUtils.getJsonObject(jsonString);
//影音管控开关
int setting_tfmedia = jsonObject.get("setting_tfmedia").getAsInt();
Log.e("SystemSetting", "qch_tfmedia_forbid---------" + setting_tfmedia);
if (setting_tfmedia == 1) {
Settings.System.putInt(context.getContentResolver(), "qch_tfmedia_forbid", 0);
} else {
String s = Settings.System.getString(context.getContentResolver(), "qch_tfmedia_filetypes");//影音管控
Log.e("SystemSetting", "qch_tfmedia_filetypes old" + s);
Settings.System.putInt(context.getContentResolver(), "qch_tfmedia_forbid", 1);
String setting_tfmedia_format = jsonObject.get("setting_tfmedia_format").getAsString();
HashSet<String> types = new HashSet<>(Arrays.asList(setting_tfmedia_format.split(",")));
types.removeIf(TextUtils::isEmpty);
boolean b = Settings.System.putString(context.getContentResolver(), "qch_tfmedia_filetypes", String.join(",", types));//影音管控
Log.e("SystemSetting", "qch_tfmedia_filetypes---------" + b + ":" + types);
}
}
private void setCameta(Context context, String jsonString) {
JsonObject jsonObject = GsonUtils.getJsonObject(jsonString);
//摄像头开关
int setting_camera = changeNum(jsonObject.get("setting_camera").getAsInt());
Settings.System.putInt(context.getContentResolver(), "qch_app_camera", setting_camera);
ApkUtils.hideSystemSettingAPP(context, "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;
default:
cameraStatus = "qch_camera_forbid";
break;
}
Intent cameraIntent = new Intent(cameraStatus).setPackage("com.android.settings");
context.sendBroadcast(cameraIntent);
}
private void setPhone(String jsonString) {
NetInterfaceManager.getInstance().getSystemSettings();
}
@SuppressLint("NewApi")
private void setAppUpdate(Context context, String jsonString) {
JsonObject jsonObject = GsonUtils.getJsonObject(jsonString);
String is_upgrade = jsonObject.get("is_upgrade").getAsString();
String packageName = jsonObject.get("package").getAsString();
String nowApplist = Settings.System.getString(context.getContentResolver(), CommonConfig.AOLE_ACTION_APP_FORBID);
List<String> applist = new ArrayList<>(Arrays.asList(nowApplist.split(",")));
if ("0".equals(is_upgrade)) {
if (applist.contains(packageName)) {
applist.remove(packageName);
} else {
Log.e("setAppUpdate", "app已经存在");
}
} else if ("1".equals(is_upgrade)) {
if (!applist.contains(packageName)) {
applist.add(packageName);
}
}
Settings.System.putString(context.getContentResolver(), CommonConfig.AOLE_ACTION_APP_FORBID, String.join(",", applist));
Log.e("setAppUpdate", Settings.System.getString(context.getContentResolver(), CommonConfig.AOLE_ACTION_APP_FORBID));
}
private void setLock_screen(Context context, String jsonString) {
int type = 0;
JsonObject jSONObject = GsonUtils.getJsonObject(jsonString);
type = jSONObject.get("type").getAsInt();
if (!ServiceAliveUtils.isServiceAlice(context, ManagerService.class.getName())) {
context.startService(new Intent(context, ManagerService.class));
}
Intent intent = new Intent();
// intent.putExtra("name", name);
SPUtils.put(context, LOCK_STATE, type);
if (1 == type) {
intent.setAction(ManagerService.ACTION_LOCK);
} else if (0 == type) {
intent.setAction(ManagerService.ACTION_UNLOCK);
}
context.sendBroadcast(intent);
}
private static Observable<Integer> getScreenshot(Context context, String filePath) {
Observable<Integer> screenshotObservable = Observable.create(new ObservableOnSubscribe<Integer>() {
@Override
public void subscribe(ObservableEmitter<Integer> e) {
int code = CmdUtil.execute("screencap -p " + filePath).code;
e.onNext(code);
e.onComplete();
}
}).subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());
return screenshotObservable;
}
private static Observable<BaseResponse> getSendFile(String path, MultipartBody.Part body) {
return NetInterfaceManager.getInstance()
.getUploadScreenshotControl()
.uploadScreenshot(Utils.getSerial(), body)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread());
}
public static void doscreenshot(Context context) {
String path = context.getExternalFilesDir("db").getAbsolutePath();
String filePath = path + File.separator + Utils.getSerial() + ".png";
getScreenshot(context, filePath).concatMap(new Function<Integer, ObservableSource<BaseResponse>>() {
@Override
public ObservableSource<BaseResponse> apply(Integer integer) throws Exception {
if (integer != 0) {
throw new FileNotFoundException();
}
File file = new File(filePath);
if (!file.exists()) {
throw new FileNotFoundException(filePath);
}
// Bitmap bitmap = BitmapFactory.decodeFile(filePath);
// if (bitmap.getWidth() < bitmap.getHeight()) {
// bitmap = ImageUtils.rotate(bitmap, -90, bitmap.getWidth(), bitmap.getHeight());
// }
// ByteArrayOutputStream baos = new ByteArrayOutputStream();
// bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
// file.createNewFile();
// FileOutputStream fos = new FileOutputStream(file);
// InputStream is = new ByteArrayInputStream(baos.toByteArray());
// int x;
// byte[] b = new byte[1024 * 100];
// while ((x = is.read(b)) != -1) {
// fos.write(b, 0, x);
// }
// fos.close();
MediaType mediaType = MediaType.Companion.parse("image/png");
RequestBody requestBody = RequestBody.Companion.create(file, mediaType);
MultipartBody.Part body = MultipartBody.Part.createFormData("file", file.getName(), requestBody);
return getSendFile(filePath, body);
}
}).subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<BaseResponse>() {
@Override
public void onSubscribe(Disposable d) {
Log.e("screenshot", "onSubscribe: ");
}
@Override
public void onNext(BaseResponse baseResponse) {
Log.e("screenshot", "onNext: " + baseResponse);
}
@Override
public void onError(Throwable e) {
Log.e("screenshot", "onError: " + e.getMessage());
onComplete();
}
@Override
public void onComplete() {
Log.e("screenshot", "onComplete: ");
}
});
}
/**
* 实时获取电量
*/
public static int getSystemBattery(Context context) {
int level = 0;
Intent batteryInfoIntent = context.getApplicationContext().registerReceiver(null,
new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
level = batteryInfoIntent.getIntExtra("level", 0);
int batterySum = batteryInfoIntent.getIntExtra("scale", 100);
int percentBattery = 100 * level / batterySum;
Log.i("getSystemBattery", "level = " + level);
Log.i("getSystemBattery", "batterySum = " + batterySum);
Log.i("getSystemBattery", "percent is " + percentBattery + "%");
return percentBattery;
}
synchronized private void setBrowserUrlpath(Context context, String jsonString) {
if (!TextUtils.isEmpty(jsonString)) {
JsonObject extra = GsonUtils.getJsonObject(jsonString);
String white = extra.get("white").getAsString();
if (white != null && !"".equals(white)) {
boolean whiteList = Settings.System.putString(context.getContentResolver(), "DeselectBrowserArray", white);
Log.e("SystemSetting", "setBrowserList-whiteList" + whiteList + ":" + white);
} else {
Settings.System.putString(context.getContentResolver(), "DeselectBrowserArray", " ");
}
Log.e("whiteList", Settings.System.getString(context.getContentResolver(), "DeselectBrowserArray"));
String black = extra.get("black").getAsString();
if (black != null && !"".equals(black)) {
boolean blackList = Settings.System.putString(context.getContentResolver(), "qch_webblack_url", black);
Log.e("SystemSetting", "setBrowserList-blackList" + blackList + ":" + black);
} else {
Settings.System.putString(context.getContentResolver(), "qch_webblack_url", " ");
}
Log.e("blackList", Settings.System.getString(context.getContentResolver(), "qch_webblack_url"));
} else {
boolean setBrowserUrlpath = Settings.System.putString(context.getContentResolver(), "DeselectBrowserArray", "");
ToastUtil.debugShow("setBrowserUrlpath jsonString is NULL,set default: " + setBrowserUrlpath);
}
}
private void timeControl(Context context, String jsonString) {
NetInterfaceManager.getInstance().getTimeControl();
}
/**
* @param context
* @param jsonString 设置热点开关
*/
private void setHotspot(Context context, String jsonString) {
JsonObject jsonObject = GsonUtils.getJsonObject(jsonString);
int setting_hotspot = changeNum(jsonObject.get("setting_hotspot").getAsInt());//热点
try {
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("SystemSetting", "aole_hotspot_forbid_on---------" + setting_hotspot);
Log.e("SystemSetting", "aole_hotspot_forbid_on---------" + aole_hotspot_forbid_on);
} catch (Exception e) {
Log.e(TAG, "setHotspot: " + e.getMessage());
}
}
private void setRestore(Context context, String jsonString) {
JsonObject jsonObject = GsonUtils.getJsonObject(jsonString);
int mode = jsonObject.get("qch_restore").getAsInt();
boolean aole_restore_forbid_on = Settings.System.putInt(context.getContentResolver(), CommonConfig.AOLE_ACTION_RESTORE_FORBID_ON, changeNum(mode));
Log.e(TAG, "aole_restore_forbid_on:" + aole_restore_forbid_on);
}
private void setBrowserInput(Context context, String jsonString) {
JsonObject jsonObject = GsonUtils.getJsonObject(jsonString);
int setting_browserInput = changeNum(jsonObject.get("setting_browserInput").getAsInt());
Settings.System.putInt(context.getContentResolver(), "qch_Browser_input", setting_browserInput);
}
private void setDeveloper(Context context, String jsonString) {
JsonObject jsonObject = GsonUtils.getJsonObject(jsonString);
int dev_mode = changeNum(jsonObject.get("dev_mode").getAsInt());
Log.e(TAG, "getDeveloper: " + dev_mode);
if (!DeviceManager.isDebugMode()) {
Settings.System.putInt(context.getContentResolver(), CommonConfig.AOLE_ACTION_DEVELOPER_OPTIONS, dev_mode);
if (dev_mode == 1) {
Intent intent = new Intent();
intent.setAction("qch_developeroptions_close");
intent.setPackage("com.android.settings");
context.sendBroadcast(intent);
Log.e(TAG, "getDeveloper: " + "关闭开发者模式");
ToastUtil.debugShow("关闭开发者模式");
} else {
Log.e(TAG, "getDeveloper: " + "打开开发者模式");
ToastUtil.debugShow("打开开发者模式");
}
}
}
private void cleanAppCache(Context context, String jsonString) {
JsonObject jsonObject = GsonUtils.getJsonObject(jsonString);
String pkg = jsonObject.get("package").getAsString();
if (TextUtils.isEmpty(pkg)) {
Log.e(TAG, "cleanAppCache: pkg is null");
return;
}
try {
new CacheUtils().cleanApplicationUserData(context, pkg);
} catch (Exception e) {
e.printStackTrace();
Log.e(TAG, "cleanAppCache: " + e.getMessage());
}
}
private void hideDesktopIcon() {
NetInterfaceManager.getInstance().getSystemSettings();
}
private void searchTopic(Context context, String jsonString) {
Log.e(TAG, "searchTopic: " + jsonString);
JsonObject jsonObject = GsonUtils.getJsonObject(jsonString);
int search_topic = jsonObject.get("search_topic").getAsInt();
Log.e(TAG, "searchTopic: put = " + SPUtils.put(context, "search_topic", search_topic));
JGYUtils.getInstance().updateForbidList();
}
private void setAlarmCLock(Context context, String ex) {
Intent bootIntent = new Intent(BootReceiver.BOOT_COMPLETED);
bootIntent.setComponent(new ComponentName("com.uiui.os", "com.uiui.os.receiver.BootReceiver"));
context.sendBroadcast(bootIntent);
}
private void setSOSPhoneNumber(Context context, String extras) {
JsonObject jsonObject = GsonUtils.getJsonObject(extras);
String setting_sos = jsonObject.get("setting_sos").getAsString();
Settings.System.putString(context.getContentResolver(), "setting_sos", setting_sos);
Intent intent = new Intent("setting_sos");
intent.putExtra("setting_sos", setting_sos);
intent.setPackage("com.uiui.os");
context.sendBroadcast(intent);
}
private void reinstallApp(Context context, String extras) {
JsonObject jsonObject = GsonUtils.getJsonObject(extras);
String packages = jsonObject.get("package").getAsString();
String app_url = jsonObject.get("app_url").getAsString();
}
/**
* @param context
* @param jsonString 设置热点开关
*/
private void setHotPoint(Context context, String jsonString) {
JsonObject jsonObject = GsonUtils.getJsonObject(jsonString);
int setting_hotspot = changeNum(jsonObject.get("hot_point").getAsInt());//热点
try {
if (setting_hotspot == 1) {
Intent intent = new Intent();
intent.setAction("aole_hotspot_close");
intent.setPackage("com.android.settings");
context.sendStickyBroadcast(intent);
stopTethering(context);
}
boolean aole_hotspot_forbid_on = Settings.System.putInt(context.getContentResolver(), CommonConfig.AOLE_ACTION_HOTSPOT_FORBID_ON, setting_hotspot);
Log.e("setHotPoint", "aole_hotspot_forbid_on: " + setting_hotspot);
Log.e("setHotPoint", "aole_hotspot_forbid_on: " + aole_hotspot_forbid_on);
} catch (Exception e) {
Log.e(TAG, "setHotPoint: " + e.getMessage());
}
}
/**
* android8.0以上关闭手机热点
*/
private static void stopTethering(Context context) {
ConnectivityManager connectivityManager = ((ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE));
try {
Method stopTethering = connectivityManager.getClass().getDeclaredMethod("stopTethering", int.class);
stopTethering.invoke(connectivityManager, 0);
} catch (Exception e) {
Log.e(TAG, "关闭热点失败");
e.printStackTrace();
}
}
private void setDefaultDesktop(Context context, String extras) {
JsonObject jsonObject = GsonUtils.getJsonObject(extras);
JsonElement jsonElement = jsonObject.get("desktop_app");
if (jsonElement != null) {
String packeges = jsonElement.getAsString();
JGYUtils.getInstance().setDefaultDesktop(packeges);
} else {
}
}
private void setDefaultBrowser(Context context, String extras) {
JsonObject jsonObject = GsonUtils.getJsonObject(extras);
JsonElement jsonElement = jsonObject.get("browser_app");
if (jsonElement != null) {
String packeges = jsonElement.getAsString();
JGYUtils.getInstance().setDefaultBrowser(packeges);
} else {
Log.e(TAG, "setDefaultBrowser: packeges is NULL");
}
}
private void setDefaultInputMethod(Context context, String extras) {
JsonObject jsonObject = GsonUtils.getJsonObject(extras);
String packeges = jsonObject.get("typewriting_app").getAsString();
JGYUtils.getInstance().setDefaultInputMethod(packeges);
}
private void oneKeyNetwork(Context context, String extras) {
JsonObject jsonObject = GsonUtils.getJsonObject(extras);
int is_network = jsonObject.get("is_network").getAsInt();
if (is_network == 1) {
JGYUtils.getInstance().oneKeyDisconnection();
} else {
JGYUtils.getInstance().restorrNetwork();
}
}
}