Files
CubeAoleyunSN/app/src/main/java/com/aoleyun/sn/tpush/MessageReceiver.java
Godfather 61ef0d7bfa version:2.3
fix:增加上传日志功能,优化一键加速功能
update:
2022-02-11 09:53:30 +08:00

1334 lines
52 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package com.aoleyun.sn.tpush;
import android.annotation.SuppressLint;
import android.content.ContentResolver;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.os.BatteryManager;
import android.os.Build;
import android.os.Handler;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
import android.widget.Toast;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationClient;
import com.amap.api.location.AMapLocationListener;
import com.aoleyun.sn.R;
import com.aoleyun.sn.base.BaseApplication;
import com.aoleyun.sn.bean.BaseResponse;
import com.aoleyun.sn.bean.RemoteDebug;
import com.aoleyun.sn.bean.SnRunLog;
import com.aoleyun.sn.comm.CommonConfig;
import com.aoleyun.sn.comm.JGYActions;
import com.aoleyun.sn.manager.AmapManager;
import com.aoleyun.sn.network.HTTPInterface;
import com.aoleyun.sn.network.NetInterfaceManager;
import com.aoleyun.sn.rlog.LogDBManager;
import com.aoleyun.sn.service.main.MainService;
import com.aoleyun.sn.tpush.common.NotificationService;
import com.aoleyun.sn.tpush.po.XGNotification;
import com.aoleyun.sn.utils.ApkUtils;
import com.aoleyun.sn.utils.CacheUtils;
import com.aoleyun.sn.utils.CmdUtil;
import com.aoleyun.sn.utils.ForegroundAppUtil;
import com.aoleyun.sn.utils.JGYUtils;
import com.aoleyun.sn.utils.MySQLData;
import com.aoleyun.sn.utils.SPUtils;
import com.aoleyun.sn.utils.SaveListUtils;
import com.aoleyun.sn.utils.ServiceAliveUtils;
import com.aoleyun.sn.utils.ToastUtil;
import com.aoleyun.sn.utils.Utils;
import com.arialyy.aria.core.Aria;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.reflect.TypeToken;
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 java.io.File;
import java.lang.reflect.Type;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Calendar;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import io.reactivex.Observable;
import io.reactivex.ObservableEmitter;
import io.reactivex.ObservableOnSubscribe;
import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
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 final String MSG_DELETE = "1";
/*系统设置管控*/
private final String MSG_SETTING = "2";
/*浏览器网址管控*/
private final String MSG_BROWSER = "4";
/*app id管控*/
private final String MSG_APPID = "5";
/*应用联网管控*/
private final String MSG_NET_CONTROL = "6";
/*APP自启联网滑动管控*/
private final String MSG_POWER_ON = "7";
/*重置*/
private final String MSG_RESET = "8";
/*强制安装*/
private final String MSG_INSTALL = "9";
/*解锁*/
private final String MSG_LOCK = "10";
/*旧版相机管控*/
private final String MSG_CAMERA = "11";
private final String MSG_ONEPACKAGES = "12";
/*app使用时间*/
private final String GET_APP_USEDTIME = "13";
/*强制下载*/
private final String GET_FORCEDOWNLOADURL = "14";
/*主页和书签管控*/
private final String SET_HOMEPAG_TAG = "15";
/*app内网页管控*/
private final String APP_WEBSITE = "16";
/*禁止app升级*/
private final String DISABLE_APPUPDATE = "17";
/*隐藏桌面图标*/
private final String HIDE_DESKTOP_ICON = "18";
/*禁止滑动*/
private final String DISABLE_APP_SLIDE = "19";
/*更新引用白名单*/
private final String UPDATE_INFO = "20";
/*截图*/
private final String SN_SCREENSHOT = "21";
/*重启*/
private final String DEVICES_REBOOT = "22";
/*获取设备详细信息*/
private final String GET_DEVICES_INFO = "23";
/*霸屏*/
private final String LOCK_SCREEN = "24";
/*取消霸屏*/
private final String UNLOCK_SCREEN = "25";
/*结束进程*/
private final String KILL_SERVER = "26";
/*时间管控*/
private final String TIME_CONTROL = "27";
/*app霸屏*/
private final String TOP_APP = "28";
/*开机动画*/
private final String LOGO_IMG = "29";
/*默认应用*/
private final String DEFAULTP_APP = "30";
/*发出声音*/
private final String PLAY_SOUND = "31";
/*清除app数据*/
private final String CLEAN_APP_CACHE = "32";
/*开发人员选项*/
private final String DEVELOPER_OPTIONS = "33";
/*全局更新*/
private final String GLOBAL_UPDATE = "34";
/*电子书包激活码*/
private final String EBAG_CODE = "35";
/*更新白名单*/
private final String UPDATE_WHITELIST = "36";
/*更换批次不恢复出厂*/
private final String UPDATE_BATCH = "37";
/*添加wifi*/
private final String UPDATE_WIFI_PW = "38";
/*远程关机*/
private final String DEVICES_POWEROFF = "41";
/*远程log*/
private final String SN_RUN_LOG = "43";
/*自定义指令*/
private final String CUSTOM_ORDER = "44";
/*优化内存*/
private final String CLEAN_MEMORY = "47";
/*运行日志设置*/
private final String SN_LOG_SETTING = "48";
private Context mContext;
private ContentResolver mResolver;
private PackageManager mPackageManager;
/**
* 消息透传处理
*
* @param context
* @param message 解析自定义的 JSON
*/
@Override
public void onTextMessage(Context context, XGPushTextMessage message) {
this.mContext = context;
this.mResolver = context.getContentResolver();
this.mPackageManager = context.getPackageManager();
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();
}
private int changeNum(int paramInt) {
return paramInt == 0 ? 1 : 0;
}
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) {
default:
break;
case MSG_DELETE:
ToastUtil.betaShow("收到管控:应用删除");
if (!TextUtils.isEmpty(title)) {
if (SaveListUtils.getlist().contains(title)) {
SaveListUtils.getlist().remove(title);
}
SaveListUtils.sendForceAPP(mContext);
ApkUtils.UninstallAPP(mContext, title);
}
HTTPInterface.getAppLimit(mContext);
HTTPInterface.getNetAndLaunchSetting(mContext);
break;
case MSG_SETTING:
ToastUtil.betaShow("收到管控:系统设置");
if (!TextUtils.isEmpty(extras)) {
JGYUtils.getInstance().SettingSysData(extras);
}
break;
case MSG_BROWSER:
ToastUtil.betaShow("收到管控:浏览器网址管控");
getDeselectBrowerID();
break;
case MSG_APPID:
ToastUtil.betaShow("收到管控APP ID管控");
getDeselectID();
break;
case MSG_NET_CONTROL:
ToastUtil.betaShow("收到管控:应用联网管控");
settingNetControl(extras);
break;
case MSG_POWER_ON:
ToastUtil.betaShow("收到管控:应用自启管控");
settingPowerOn(extras);
break;
case MSG_RESET:
ToastUtil.betaShow("收到管控:设备重置");
Utils.doMasterClear(mContext);
break;
case MSG_INSTALL:
ToastUtil.betaShow("收到管控:应用安装");
HTTPInterface.getAppLimit(mContext);
doDownloadAndInstall(extras);
HTTPInterface.setHideDesktopIcon(mContext);
break;
case MSG_LOCK:
ToastUtil.betaShow("收到管控:设备锁定");
settingLock(extras);
break;
case MSG_CAMERA:
ToastUtil.betaShow("收到管控:相机管控");
settingCamera(extras);
break;
case MSG_ONEPACKAGES:
ToastUtil.betaShow("收到管控:");
if (BaseApplication.getInstance().isFinished()) {
settingOneNet(extras);
}
break;
case GET_APP_USEDTIME:
ToastUtil.betaShow("收到管控:获取应用使用时间");
JSONObject usedTimeJson = JSON.parseObject(extras);
String random = usedTimeJson.getString("random");
String sendType = usedTimeJson.getString("type");
BaseApplication.sendAppUsedTime(random, sendType);
break;
case GET_FORCEDOWNLOADURL:
ToastUtil.betaShow("收到管控:应用强制安装");
File file = new File(JGYUtils.getInstance().getDownLoadPath());
if (!file.exists()) {
file.mkdirs();
}
if (TextUtils.isEmpty(extras)) {
Log.e(TAG, "settingNetControl extras is null");
return;
}
JSONObject extra = JSON.parseObject(extras);
String app_name = extra.getString("app_name");
String app_package = extra.getString("package");
String url = extra.getString("url");
int versionCode = extra.getInteger("version_code");
String app_id = extra.getString("app_id");
JSONObject packageObj = new JSONObject();
packageObj.put("app_name", app_name);
packageObj.put("app_package", app_package);
packageObj.put("app_id", app_id);
Utils.ariaDownload(mContext, url, packageObj);
break;
case SET_HOMEPAG_TAG:
Handler.getMain().postDelayed(new Runnable() {
@Override
public void run() {
try {
new CacheUtils().cleanApplicationUserData(mContext, "com.android.browser");
} catch (Exception e) {
e.printStackTrace();
Log.e(TAG, "setHomepagtag: " + e.getMessage());
}
setHomepagtag();
ToastUtil.betaShow("收到管控:浏览器主页书签设置");
}
}, 2000);
break;
case APP_WEBSITE:
ToastUtil.betaShow("收到管控APP内部网页管控");
setAPPinsideWebsite(extras);
break;
case DISABLE_APPUPDATE:
ToastUtil.betaShow("收到管控:应用禁止更新设置");
setDisableUpdateList(extras);
break;
case HIDE_DESKTOP_ICON:
ToastUtil.betaShow("收到管控:隐藏应用设置");
Handler.getMain().postDelayed(() -> {
//后台发送时数据库未改变,有时候可能获取到的数据时上一次的
Log.e(TAG, "run: HIDE_DESKTOP_ICON ");
HTTPInterface.setHideDesktopIcon(mContext);
}, 2000);
break;
case DISABLE_APP_SLIDE:
ToastUtil.betaShow("收到管控:应用滑动设置");
setDisableSlideList(extras);
break;
case UPDATE_INFO:
ToastUtil.betaShow("收到管控:更新白名单");
HTTPInterface.getAppLimit(mContext);
break;
case SN_SCREENSHOT:
ToastUtil.betaShow("收到管控:设备截图");
screenshot(extras);
break;
case DEVICES_REBOOT:
ToastUtil.betaShow("收到管控:设备重启");
Utils.rebootDevices(mContext);
break;
case GET_DEVICES_INFO:
ToastUtil.betaShow("收到管控:获取设备信息");
if (MainService.mPresenter != null) {
MainService.mPresenter.getLockedState();
MainService.mPresenter.sendMACAddress();
Log.e(TAG, "mPresenter: " + "getLockedState");
} else {
Log.e(TAG, "mPresenter is NULL");
}
AMapLocationClient aMapLocationClient = AmapManager.getInstance().getLocationClient();
aMapLocationClient.stopLocation();
aMapLocationClient.startLocation();
aMapLocationClient.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");
SPUtils.put(mContext, "AmapError", String.valueOf(aMapLocation.getErrorCode()));
}
Log.e(TAG, (String) SPUtils.get(mContext, "AmapAddress", "-"));
Log.e(TAG, (String) SPUtils.get(mContext, "AmapError", "-"));
Log.e(TAG, "amap: " + sb.toString());
NetInterfaceManager.getInstance().updateDeviceInfo(new NetInterfaceManager.ObserverCallback() {
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onNext(BaseResponse response) {
}
@Override
public void onError(Throwable e) {
}
@Override
public void onComplete() {
}
});
}
});
break;
case LOCK_SCREEN:
ToastUtil.betaShow("收到管控:屏幕锁定");
JSONObject lockJSONObject = JSON.parseObject(extras);
String name = lockJSONObject.getString("name");
setLock_screen(1, name);
break;
case UNLOCK_SCREEN:
ToastUtil.betaShow("收到管控:屏幕解锁");
setLock_screen(0, "");
break;
case KILL_SERVER:
ToastUtil.betaShow("收到管控:停止应用");
JSONObject killJSONObject = JSON.parseObject(extras);
String packages = killJSONObject.getString("package_name");
JGYUtils.getInstance().killBackgroundProcesses(packages);
break;
case TIME_CONTROL:
ToastUtil.betaShow("收到管控:使用时间管控");
getTimeControl(extras);
break;
case TOP_APP:
ToastUtil.betaShow("收到管控:应用霸屏");
getTopApp(extras);
break;
case LOGO_IMG:
ToastUtil.betaShow("收到管控:开机动画设置");
setBootanimation(extras);
Log.e(TAG, "processCustomMessage: " + extras);
break;
case DEFAULTP_APP:
ToastUtil.betaShow("收到管控:");
setDefalutApp(extras);
break;
case PLAY_SOUND:
ToastUtil.betaShow("收到管控:查找设备");
playSound(extras);
break;
case CLEAN_APP_CACHE:
ToastUtil.betaShow("收到管控:应用缓存清除");
cleanCache(extras);
break;
case DEVELOPER_OPTIONS:
ToastUtil.betaShow("收到管控:开发人员选项管控");
setDeveloperoptions(extras);
break;
case GLOBAL_UPDATE:
ToastUtil.betaShow("收到管控:全局更新");
GlobalUpdate(extras);
break;
case EBAG_CODE:
ToastUtil.betaShow("收到管控:电子书包激活码");
setEbagCode(extras);
JGYUtils.getInstance().killBackgroundProcesses("com.jxw.launcher");
break;
case UPDATE_WHITELIST:
ToastUtil.betaShow("收到管控:更新白名单");
HTTPInterface.getAppLimit(mContext);
break;
case UPDATE_BATCH:
ToastUtil.betaShow("收到管控:更换批次不恢复出厂设置");
Aria.download(this).removeAllTask(true);
try {
new CacheUtils().cleanApplicationUserData(mContext, "com.android.browser");
} catch (Exception e) {
e.printStackTrace();
Log.e(TAG, "setHomepagtag: " + e.getMessage());
}
if (MainService.mPresenter != null) {
MainService.mPresenter.getLockedState();
Log.e("getLockedState", "mPresenter: " + "getLockedState");
} else {
Log.e("getLockedState", "mPresenter is NULL");
}
break;
case UPDATE_WIFI_PW:
HTTPInterface.getWiFiPasswd(mContext);
break;
case DEVICES_POWEROFF:
HTTPInterface.getPoweroffTime();
break;
case SN_RUN_LOG:
recordLog(extras);
break;
case CUSTOM_ORDER:
customOrder(extras);
break;
case CLEAN_MEMORY:
JGYUtils.getInstance().cleanBackgroundMemory();
break;
case SN_LOG_SETTING:
senSNLogFile(extras);
break;
}
}
private void setLock_screen(int state, String name) {
if (ServiceAliveUtils.isServiceAlive(mContext)) {
mContext.startService(new Intent(mContext, MainService.class));
}
Intent intent = new Intent();
intent.putExtra("name", name);
if (state == 1) {
intent.setAction(MainService.LockScreenReceiver.action_lock);
} else if (state == 0) {
intent.setAction(MainService.LockScreenReceiver.action_unlock);
}
mContext.sendBroadcast(intent);
}
private void doDownloadAndInstall(String jsonString) {
File file = new File(JGYUtils.getInstance().getDownLoadPath());
if (!file.exists()) {
file.mkdirs();
}
if (TextUtils.isEmpty(jsonString)) {
Log.e(TAG, "doDownloadAndInstall: extras is null");
return;
}
JSONObject jSONObject = JSON.parseObject(jsonString);
String app_name = jSONObject.getString("app_name");
String app_package = jSONObject.getString("bg");
String app_url = jSONObject.getString("app_url");
int app_version_code = jSONObject.getInteger("app_version_code");
String app_id = jSONObject.getString("app_id");
String MD5 = jSONObject.getString("app_md5");
JSONObject packageObj = new JSONObject();
packageObj.put("app_name", app_name);
packageObj.put("app_package", app_package);
packageObj.put("app_id", app_id);
packageObj.put("MD5", MD5);
Log.e(TAG, "doDownloadAndInstall: app_package:" + app_package);
Log.e(TAG, "doDownloadAndInstall: app_url:" + app_url);
SaveListUtils.addList(app_package);
SaveListUtils.sendForceAPP(mContext);
PackageInfo packageInfo = null;
try {
packageInfo = mPackageManager.getPackageInfo(app_package, 0);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
if (packageInfo == null) {
Log.e(TAG, "doDownloadAndInstall: " + app_package + "未安装");
if (!SaveListUtils.isDownLoading(app_url)) {
Log.e(TAG, "doDownloadAndInstall: " + app_package + "开始下载");
Utils.ariaDownload(mContext, app_url, packageObj);
}
} else {
long appVersionCode;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
appVersionCode = packageInfo.getLongVersionCode();
} else {
appVersionCode = packageInfo.versionCode;
}
if (app_version_code > appVersionCode) {
if (!SaveListUtils.isDownLoading(app_url)) {
Utils.ariaDownload(mContext, app_url, packageObj);
}
} else {
Log.e(TAG, "doDownloadAndInstall: " + app_package + "已安装最新版");
}
}
}
private int getBatteryLevel() {
if (Build.VERSION.SDK_INT >= 21) {
return ((BatteryManager) mContext.getSystemService(Context.BATTERY_SERVICE)).getIntProperty(4);
}
Intent intent = (new ContextWrapper(mContext)).registerReceiver(null, new IntentFilter("android.intent.action.BATTERY_CHANGED"));
return intent.getIntExtra("level", -1) * 100 / intent.getIntExtra("scale", -1);
}
private void getDeselectBrowerID() {
HTTPInterface.setBrowserBlackList(mContext);//浏览器网址管控
}
private void getDeselectID() {
NetInterfaceManager.getInstance().getDeselectIDApi()
.getDeselectIDApi(NetInterfaceManager.HTTP_KEY,
Utils.getSerial())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<ResponseBody>() {
@Override
public void onSubscribe(Disposable param1Disposable) {
Log.e("getDeselectID", "onSubscribe: ");
}
@Override
public void onNext(ResponseBody param1ResponseBody) {
String ids = "";
String packages = "";
try {
String responString = param1ResponseBody.string();
Log.e("getDeselectID", "onNext: " + responString);
JSONObject jSONObject = JSON.parseObject(responString);
int code = jSONObject.getInteger("code");
if (code == 200) {
ids = jSONObject.getJSONObject("data").getString("ids");
packages = jSONObject.getJSONObject("data").getString("package");
}
} catch (Exception e) {
Log.e("getDeselectID", "onNext: Exception: " + e.getMessage());
e.printStackTrace();
}
JGYUtils.getInstance().writeDeselectIDtoSystem(ids, packages);
}
@Override
public void onError(Throwable param1Throwable) {
Log.e("getDeselectID", "onError: " + param1Throwable.getMessage());
}
@Override
public void onComplete() {
Log.e("getDeselectID", "onComplete: ");
}
});
}
private void setDisableSlideList(String jsonString) {
JSONObject jSONObject = JSON.parseObject(jsonString);
Log.e("setDisableSlideList", "jSONObject::" + jSONObject.toString());
String strban = jSONObject.getString("ban");
String strnot = jSONObject.getString("not");
String qch_disable_slide = Settings.System.getString(mResolver, "qch_disable_slide");
Log.e("fht", "qch_disable_slide::" + qch_disable_slide);
if (!TextUtils.isEmpty(strban)) {
Settings.System.putString(mResolver, "qch_disable_slide", strban);
Log.e("fht", "sendban::" + strban);
} else {
Settings.System.putString(mResolver, "qch_disable_slide", "Invalid");
}
Log.e("fht", "qch_disable_slide::" + Settings.System.getString(mResolver, "qch_disable_slide"));
}
private void setDisableUpdateList(String jsonString) {
Log.e("setDisableUpdateList", jsonString);
JSONObject jsonObject = JSON.parseObject(jsonString);
String ban = jsonObject.getString("ban");
String not = jsonObject.getString("not");
String[] banList = ban.split(",");
String[] notList = not.split(",");
boolean b = Utils.writeDisableUpdateList(mContext, banList, notList);
HTTPInterface.getAppLimit(mContext);
}
private void settingCamera(String s) {
if (TextUtils.isEmpty(s)) {
Intent intent = new Intent("qch_camera_forbid").setPackage("com.android.settings");
intent.putExtra("camera_package_name", "close");
mContext.sendBroadcast(intent);
Log.e(TAG, "settingNetControl extras is null");
return;
}
JSONObject jSONObject = JSON.parseObject(s);
String s1 = jSONObject.getString("ban");
// String str = jSONObject.optString("not");
Log.e("settingCamera", "ban::" + s1);
// Log.e("settingCamera", "not::" + str);
if ("0".equals(s1)) {
Intent intent2 = new Intent("qch_camera_forbid").setPackage("com.android.settings");
// intent2.putExtra("camera_package_name", s1);
mContext.sendBroadcast(intent2);
} else {
Intent intent1 = new Intent("qch_camera_open").setPackage("com.android.settings");
// intent1.putExtra("camera_package_name", str);
mContext.sendBroadcast(intent1);
}
}
private void settingOneNet(String s) {
if (TextUtils.isEmpty(s)) {
Log.e(TAG, "settingNetControl extras is null");
// return;
}
JSONObject jSONObject = JSON.parseObject(s);
Log.e("settingOneNet", "jSONObject::" + jSONObject.toString());
String packages = jSONObject.getString("package");
String status = jSONObject.getString("status");
}
private void settingNetControl(String s) {
if (TextUtils.isEmpty(s)) {
Log.e(TAG, "settingNetControl extras is null");
}
JSONObject jSONObject = JSON.parseObject(s);
Log.e("settingNetControl", "jSONObject::" + jSONObject.toString());
String disallow = jSONObject.getString("ban");
String allow = jSONObject.getString("not");
HashSet<String> disallowApp = new HashSet<>(Arrays.asList(disallow.split(",")));
JGYUtils.setAppNetwork(mContext, disallowApp);
}
private void settingPowerOn(String s) {
if (TextUtils.isEmpty(s)) {
Log.e(TAG, "settingPowerOn extras is null");
return;
}
JSONObject jSONObject = JSON.parseObject(s);
String ban = jSONObject.getString("ban");
String not = jSONObject.getString("not");
Log.e(TAG, "settingPowerOn qch_app_power_on = " + not);
if (TextUtils.isEmpty(not)) {
//当 qch_app_power_on 的值为空时,会造成系统所有应用断网
Settings.System.putString(mResolver, "qch_app_power_on", "Invalid");
} else {
Settings.System.putString(mResolver, "qch_app_power_on", not);
}
}
private void writeDeselectBrowserIDtoSystem(String s) {
boolean bool = Settings.System.putString(mResolver, "DeselectBrowserArray", s);
Log.e("SystemSetting", "DeselectBrowserArray---------" + s);
Log.e("SystemSetting", "DeselectBrowserArray---------" + bool);
}
private void setHomepagtag() {
HTTPInterface.getHomePageBookmarks(mContext, null);
}
private void setAPPinsideWebsite(String s) {
//禁止app内部网页访问包名用,隔开
HTTPInterface.getAppinsideWeb(mContext, new HTTPInterface.GetAppinsideWebCallback() {
@Override
public void onComplete() {
Log.e(TAG, "ononComplete: setAPPinsideWebsite");
}
});
}
/**
* 锁定设备
*
* @param s
*/
public void settingLock(String s) {
if (TextUtils.isEmpty(s)) {
Log.e(TAG, "settingLock extras is null");
return;
}
JSONObject jSONObject = JSON.parseObject(s);
int i = changeNum(jSONObject.getIntValue("lock"));
Settings.System.putInt(mResolver, JGYActions.ACTION_QCH_UNLOCK_IPAD, i);
Log.e("SystemSetting", "qch_unlock_ipad---------" + i);
if (getBatteryLevel() >= CommonConfig.MIN_POWER) {
Utils.doMasterClear(mContext);
} else {
MySQLData.SetBooleanData(mContext, CommonConfig.IS_RESET, true);
}
}
public void screenshot(String s) {
JSONObject jSONObject = JSON.parseObject(s);
long createTime = jSONObject.getLong("createTime");
if (createTime != 0) {
Log.e("createTime", String.valueOf(createTime));
doscreenshot(createTime);
}
}
public void doscreenshot(final long time) {
Observable.create(new ObservableOnSubscribe<Integer>() {
@Override
public void subscribe(ObservableEmitter<Integer> e) throws Exception {
String filepath = mContext.getExternalFilesDir("db").getAbsolutePath();
int n = CmdUtil.execute("screencap -p " + filepath + File.separator + time + ".db").code;
e.onNext(n);
}
}).subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<Integer>() {
@Override
public void onSubscribe(Disposable d) {
}
@Override
public void onNext(Integer integer) {
if (integer == 0) {
uplaodImage(time);
} else {
Log.e("doss", "失败");
}
}
@Override
public void onError(Throwable e) {
Log.e("doss", "Throwable=" + e.getMessage());
}
@Override
public void onComplete() {
}
});
}
private void uplaodImage(long time) {
String filepath = mContext.getExternalFilesDir("db").getAbsolutePath();
// String filepath = mContext.getFileStreamPath("screenshot").getAbsolutePath();
//放在app内部data下面
File file = new File(filepath + File.separator + time + ".db");
//不要直接使用常用图片格式
if (!file.exists()) {
Log.e("uplaodImage", "File does not exists");
return;
}
//设置图片格式
// RequestBody requestFile = RequestBody.create(MediaType.parse("image/jpg"), file);
//File转RequestBody
MediaType mediaType = MediaType.Companion.parse("image/png");
RequestBody fileBody = RequestBody.Companion.create(file, mediaType);
//设置一个file文件
MultipartBody.Part body = MultipartBody.Part.createFormData("file", file.getName(), fileBody);
Map<String, String> params = new HashMap<>();
params.put("sn", Utils.getSerial());
params.put("createtime", String.valueOf(time));
NetInterfaceManager.getInstance().getScreenshotApi()
.sendScreenshot(params, body)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<BaseResponse>() {
@Override
public void onSubscribe(Disposable d) {
Log.e("uplaodImage", "onSubscribe: ");
}
@Override
public void onNext(BaseResponse baseResponse) {
Log.e("uplaodImage", "onNext: " + baseResponse.msg);
}
@Override
public void onError(Throwable e) {
Log.e("uplaodImage", "onError: " + e.getMessage());
}
@Override
public void onComplete() {
Log.e("uplaodImage", "onComplete: ");
}
});
}
private void getTimeControl(String extras) {
HTTPInterface.getSnTimeControl(mContext);
}
private void getTopApp(String extras) {
JSONObject jsonObject = JSON.parseObject(extras);
String packageName = jsonObject.getString("app_package");
if (TextUtils.isEmpty(packageName)) {
SPUtils.put(mContext, ForegroundAppUtil.TOPAPP_KEY, "");
ForegroundAppUtil.setTopAppClass(mContext, "");
} else {
SPUtils.put(mContext, ForegroundAppUtil.TOPAPP_KEY, packageName);
ForegroundAppUtil.setTopAppClass(mContext, packageName);
ForegroundAppUtil.openTopApp(mContext);
}
}
private void setBootanimation(String extras) {
JSONObject jsonObject = JSONObject.parseObject(extras);
int type = jsonObject.getInteger("type");
if (type == 1) {
String file_url = jsonObject.getString("file_url");
String file_md5 = jsonObject.getString("file_md5");
JGYUtils.getInstance().checkBootFile(file_url, file_md5);
} else {
JGYUtils.getInstance().removeBootanimation();
}
}
private void setDefalutApp(String extras) {
if (TextUtils.isEmpty(extras)) {
JGYUtils.getInstance().setDefaultDesktop("");
} else {
JSONObject jsonObject = JSON.parseObject(extras);
String default_launcher = jsonObject.getString("default_launcher");
if (TextUtils.isEmpty(default_launcher)) {
JGYUtils.getInstance().setDefaultDesktop("");
SPUtils.put(mContext, "default_launcher", "");
} else {
JGYUtils.getInstance().setDefaultDesktop(default_launcher);
SPUtils.put(mContext, "default_launcher", default_launcher);
}
}
}
private void playSound(String extras) {
JSONObject jsonObject = JSONObject.parseObject(extras);
defaultCallMediaPlayer(mContext);
}
/**
* 播放系统默认来电铃声
*
* @return MediaPlayer对象
* @throws Exception
*/
MediaPlayer mediaPlayer;
public void defaultCallMediaPlayer(Context mContext) {
if (mediaPlayer != null) {
mediaPlayer.stop();
mediaPlayer.release();
}
mediaPlayer = MediaPlayer.create(mContext, R.raw.test);
try {
// mediaPlayer.prepare();
mediaPlayer.setLooping(false);
int duration = mediaPlayer.getDuration() / 1000;
Log.e(TAG, "defaultCallMediaPlayer: " + "duration: " + duration);
int loop = 0;
if (duration <= 1) {
loop = 30;
} else {
loop = (30 / duration);
}
final int[] soundCount = {0};
int finalLoop = loop;
mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mediaPlayer) {
if (soundCount[0] <= finalLoop) {
setMaxVolume(mContext);
mediaPlayer.start();
soundCount[0] += 1;
Log.e(TAG, "onCompletion: " + "loop: " + finalLoop);
Log.e(TAG, "onCompletion: " + "soundCount: " + soundCount[0]);
} else {
mediaPlayer.stop();
mediaPlayer.release();
Log.e(TAG, "onCompletion: " + "loop: " + finalLoop);
Log.e(TAG, "onCompletion: " + "soundCount: " + soundCount[0]);
}
}
});
mediaPlayer.setLooping(false);
setMaxVolume(mContext);
mediaPlayer.start();
} catch (Exception e) {
e.printStackTrace();
Log.e(TAG, "defaultCallMediaPlayer: " + e.getMessage());
}
}
private void setMaxVolume(Context mContext) {
AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
int ringMax = audioManager.getStreamMaxVolume(AudioManager.STREAM_RING);
int musicMax = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
int voiceMax = audioManager.getStreamMaxVolume(AudioManager.STREAM_VOICE_CALL);
audioManager.setStreamVolume(AudioManager.STREAM_RING, ringMax, 0);
audioManager.setStreamVolume(AudioManager.STREAM_VOICE_CALL, voiceMax, 0);
audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, musicMax, 0); //音乐音量
audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
audioManager.setSpeakerphoneOn(true);
}
private void cleanCache(String extras) {
JSONObject jsonObject = JSONObject.parseObject(extras);
String packageName = jsonObject.getString("app_package");
if (TextUtils.isEmpty(packageName)) {
Log.e(TAG, "cleanCache: " + "package is empty");
} else {
try {
if (new CacheUtils().cleanApplicationUserData(mContext, packageName)) {
Log.e(TAG, "cleanCache: " + packageName + " success");
} else {
Log.e(TAG, "cleanCache: " + packageName + " failed");
}
} catch (Exception e) {
e.printStackTrace();
Log.e(TAG, "cleanCache: " + e.getMessage());
}
}
}
private void setDeveloperoptions(String extras) {
JSONObject jsonObject = JSONObject.parseObject(extras);
int is_developer = jsonObject.getInteger("is_developer");
Log.e(TAG + ":" + "getDeveloper", "onNext: " + is_developer);
Log.e(TAG, "setDeveloperoptions: " + is_developer);
JGYUtils.getInstance().setDeveloperOptions(is_developer == 0 ? 1 : 0);
}
private void GlobalUpdate(String jsonString) {
if (TextUtils.isEmpty(jsonString)) {
throw new RuntimeException();
}
JSONObject jsonObject = JSON.parseObject(jsonString);
String platform = jsonObject.getString("platform");
if (JGYUtils.getInstance().isSamePlatform(platform)) {
checkAPPInstall(jsonObject);
} else {
Log.e(TAG, "GlobalUpdate: " + "应用与app平台不符合");
}
}
@SuppressLint("NewApi")
private void checkAPPInstall(JSONObject jsonObject) {
long version_code = jsonObject.getLong("app_version_code");
PackageInfo packageInfo = null;
try {
packageInfo = mPackageManager.getPackageInfo(jsonObject.getString("app_package"), 0);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
if (packageInfo == null || packageInfo.getLongVersionCode() < version_code) {
Utils.ariaDownload(mContext, jsonObject.getString("app_url"), jsonObject);
} else {
Log.e(TAG, "checkAPPInstall: " + "已经是最新版");
}
}
private void setEbagCode(String jsonString) {
JSONObject jsonObject = JSON.parseObject(jsonString);
String ebagCode = jsonObject.getString("ebagCode");
if (TextUtils.isEmpty(ebagCode)) {
Log.e(TAG, "setEbagCode: " + "ebagCode is empty");
} else {
SPUtils.put(mContext, "ebagCode", ebagCode);
}
}
private void recordLog(String jsonString) {
HTTPInterface.getRunLog(mContext);
}
private static final int ACTION_PULL = 1;
private static final int ACTION_DELETE = 2;
private static final int ACTION_UPGRADE = 3;
private void customOrder(String jsonString) {
Gson gson = new Gson();
Type type = new TypeToken<RemoteDebug>() {
}.getType();
RemoteDebug remoteDebug = gson.fromJson(jsonString, type);
if (remoteDebug != null) {
String pkg = remoteDebug.getApp_package();
String content = remoteDebug.getContent();
switch (remoteDebug.getType()) {
case ACTION_PULL:
Log.e(TAG, "customOrder: 唤起");
ApkUtils.openPackage(mContext, pkg);
break;
case ACTION_DELETE:
Log.e(TAG, "customOrder: 删除");
ApkUtils.UninstallAPP(mContext, pkg);
break;
case ACTION_UPGRADE:
Log.e(TAG, "customOrder: 更新");
HTTPInterface.getForceDownload(mContext);
break;
default:
break;
}
}
}
/**
* @param jsonString
* "is_log": 1,//是否开启运行日志 0关闭 1开启
* "is_log_type": 1 //获取运行日志类型 0即时 1定时
*/
private void senSNLogFile(String jsonString) {
JSONObject jsonObject = JSON.parseObject(jsonString);
int is_log = jsonObject.getInteger("is_log");
int is_log_type = jsonObject.getInteger("is_log_type");
if (is_log == 0) {
return;
}
if (is_log_type == 0) {
NetInterfaceManager.getInstance().uploadLogFile();
} else {
SPUtils.put(mContext, CommonConfig.UPLOAD_LOG_TYPE, 1);
}
}
}