Files
CubeAoleyunSN/app/src/main/java/com/aoleyun/sn/jpush/MyJPushReceiver.java
Godfather 3c45ccc7b1 version:2.6
fix:更新retrofit,优化请求次数
update:
2022-02-24 18:44:56 +08:00

941 lines
41 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.jpush;
import android.annotation.SuppressLint;
import android.content.BroadcastReceiver;
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.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.aoleyun.sn.R;
import com.aoleyun.sn.bean.BaseResponse;
import com.aoleyun.sn.bean.RemoteDebug;
import com.aoleyun.sn.comm.CommonConfig;
import com.aoleyun.sn.comm.JGYActions;
import com.aoleyun.sn.network.HTTPInterface;
import com.aoleyun.sn.network.NetInterfaceManager;
import com.aoleyun.sn.service.main.MainService;
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.Utils;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import java.io.File;
import java.lang.reflect.Type;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.core.ObservableEmitter;
import io.reactivex.rxjava3.core.ObservableOnSubscribe;
import io.reactivex.rxjava3.core.Observer;
import io.reactivex.rxjava3.disposables.Disposable;
import io.reactivex.rxjava3.schedulers.Schedulers;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
public class MyJPushReceiver extends BroadcastReceiver {
private static final String TAG = MyJPushReceiver.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 Context mContext;
private int changeNum(int paramInt) {
return paramInt == 0 ? 1 : 0;
}
@Override
public void onReceive(Context context, Intent intent) {
mContext = context;
// Bundle bundle = intent.getExtras();
// if (JPushInterface.ACTION_REGISTRATION_ID.equals(intent.getAction())) {
// String regId = bundle.getString(JPushInterface.EXTRA_REGISTRATION_ID);
// Log.e(TAG, "[MyReceiver] 接收Registration Id : " + regId);
// //send the Registration Id to your server...
// } else if (JPushInterface.ACTION_MESSAGE_RECEIVED.equals(intent.getAction())) {
// // ToastTool.show("[MyReceiver] 接收到推送下来的自定义消息: " + bundle.getString(JPushInterface.EXTRA_MESSAGE)
// // + "---" + bundle.getString(JPushInterface.EXTRA_TITLE) + "---" + bundle.getString(JPushInterface.EXTRA_CONTENT_TYPE)
// // + "---" + bundle.getString(JPushInterface.EXTRA_EXTRA) + "----" + bundle.getString("package_name"));
// // Log.e(TAG, "[MyReceiver] 接收到推送下来的自定义消息: " + bundle.getString(JPushInterface.EXTRA_MESSAGE)
// // + "---" + bundle.getString(JPushInterface.EXTRA_TITLE) + "---" + bundle.getString(JPushInterface.EXTRA_CONTENT_TYPE)
// // + "---" + bundle.getString(JPushInterface.EXTRA_EXTRA) + "----" + bundle.getString("package_name"));
// processCustomMessage(context, bundle);//屏蔽推送
// } else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(intent.getAction())) {
// Log.e(TAG, "[MyReceiver] 接收到推送下来的通知" + bundle.getString(JPushInterface.EXTRA_EXTRA));
// // doDownloadAndInstall(bundle.getString(JPushInterface.EXTRA_EXTRA));
// // Log.e(getBatteryLevel()+"-0-iweroiwerewefeerer-----------");
// int notifactionId = bundle.getInt(JPushInterface.EXTRA_NOTIFICATION_ID);
// Log.e(TAG, "[MyReceiver] 接收到推送下来的通知的ID: " + notifactionId);
// } else if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals(intent.getAction())) {
// Log.e(TAG, "[MyReceiver] 用户点击打开了通知");
// } else if (JPushInterface.ACTION_RICHPUSH_CALLBACK.equals(intent.getAction())) {
// Log.e(TAG, "[MyReceiver] 用户收到到RICH PUSH CALLBACK: " + bundle.getString(JPushInterface.EXTRA_EXTRA));
// //在这里根据 JPushInterface.EXTRA_EXTRA 的内容处理代码比如打开新的Activity 打开一个网页等..
// } else if (JPushInterface.ACTION_CONNECTION_CHANGE.equals(intent.getAction())) {
// boolean connected = intent.getBooleanExtra(JPushInterface.EXTRA_CONNECTION_CHANGE, false);
// Log.i(TAG, "[MyReceiver]" + intent.getAction() + " connected state change to " + connected);
// } else {
// Log.e(TAG, "[MyReceiver] Unhandled intent - " + intent.getAction());
// }
}
// private void processCustomMessage(final Context context, Bundle bundle) {
//// String message = bundle.getString(JPushInterface.EXTRA_MESSAGE);
//// String title = bundle.getString(JPushInterface.EXTRA_TITLE);
//// String type = bundle.getString(JPushInterface.EXTRA_CONTENT_TYPE);
//// String extras = bundle.getString(JPushInterface.EXTRA_EXTRA);
//// String package_name = bundle.getString("package_name");
//
// Log.e(TAG, "message::" + message + "--type::" + type + "--title::" + title + "--extras::" + extras);
// switch (message) {
// 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(context);
// 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(context);
// 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 jsonObject = JSON.parseObject(extras);
// String random = jsonObject.getString("random");
// String sendType = jsonObject.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(extras);
// 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(context);
// }, 2000);
// break;
// case DISABLE_APP_SLIDE:
// ToastUtil.betaShow("收到管控:应用滑动设置");
// setDisableSlideList(extras);
// break;
// case UPDATE_INFO:
// ToastUtil.betaShow("收到管控:更新白名单");
// HTTPInterface.getAppLimit(context);
// 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());
// HTTPInterface.updateDeviceInfo(mContext);
// }
// });
// break;
// case LOCK_SCREEN:
// ToastUtil.betaShow("收到管控:屏幕锁定");
// JSONObject lockJSONObject = JSON.parseObject(extras);
// String name = lockJSONObject.getString("name");
// setLock_screen(1, context, name);
// break;
// case UNLOCK_SCREEN:
// ToastUtil.betaShow("收到管控:屏幕解锁");
// setLock_screen(0, context, "");
// break;
// case KILL_SERVER:
// ToastUtil.betaShow("收到管控:停止应用");
// JSONObject killJSONObject = JSON.parseObject(extras);
// String packages = killJSONObject.getString("package_name");
// JGYUtils.getInstance().killBackgroundProcesses(context, packages);
// break;
// case TIME_CONTROL:
// ToastUtil.betaShow("收到管控:使用时间管控");
// getTimeControl(context, extras);
// break;
// case TOP_APP:
// ToastUtil.betaShow("收到管控:应用霸屏");
// getTopApp(context, extras);
// break;
// case LOGO_IMG:
// ToastUtil.betaShow("收到管控:开机动画设置");
// setBootanimation(context, extras);
// Log.e(TAG, "processCustomMessage: " + extras);
// break;
// case DEFAULTP_APP:
// ToastUtil.betaShow("收到管控:");
// setDefalutApp(context, extras);
// break;
// case PLAY_SOUND:
// ToastUtil.betaShow("收到管控:查找设备");
// playSound(context, extras);
// break;
// case CLEAN_APP_CACHE:
// ToastUtil.betaShow("收到管控:应用缓存清除");
// cleanCache(context, 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(context, "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(context);
// break;
// case DEVICES_POWEROFF:
// HTTPInterface.getPoweroffTime();
// break;
// case SN_RUN_LOG:
// recordLog(context, extras);
// break;
// case CUSTOM_ORDER:
// customOrder(context, extras);
// break;
// }
//
// }
private void setLock_screen(int state, Context context, String name) {
if (ServiceAliveUtils.isServiceAlive(context)) {
context.startService(new Intent(context, 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);
}
context.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);
PackageManager pm = mContext.getPackageManager();
PackageInfo packageInfo = null;
try {
packageInfo = pm.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) this.mContext.getSystemService(Context.BATTERY_SERVICE)).getIntProperty(4);
}
Intent intent = (new ContextWrapper(this.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 s) {
JSONObject jSONObject = JSON.parseObject(s);
Log.e("setDisableSlideList", "jSONObject::" + jSONObject.toString());
String strban = jSONObject.getString("ban");
String strnot = jSONObject.getString("not");
String qch_disable_slide = Settings.System.getString(mContext.getApplicationContext().getContentResolver(), "qch_disable_slide");
Log.e("fht", "qch_disable_slide::" + qch_disable_slide);
if (!TextUtils.isEmpty(strban)) {
Settings.System.putString(mContext.getContentResolver(), "qch_disable_slide", strban);
Log.e("fht", "sendban::" + strban);
} else {
Settings.System.putString(mContext.getContentResolver(), "qch_disable_slide", "Invalid");
}
Log.e("fht", "qch_disable_slide::" + Settings.System.getString(mContext.getApplicationContext().getContentResolver(), "qch_disable_slide"));
}
private void setDisableUpdateList(String s) {
Log.e("setDisableUpdateList", s);
JSONObject jsonObject = JSON.parseObject(s);
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");
this.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);
this.mContext.sendBroadcast(intent2);
} else {
Intent intent1 = new Intent("qch_camera_open").setPackage("com.android.settings");
// intent1.putExtra("camera_package_name", str);
this.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(mContext.getContentResolver(), "qch_app_power_on", "Invalid");
} else {
Settings.System.putString(mContext.getContentResolver(), "qch_app_power_on", not);
}
}
private void writeDeselectBrowserIDtoSystem(String s) {
boolean bool = Settings.System.putString(this.mContext.getContentResolver(), "DeselectBrowserArray", s);
Log.e("SystemSetting", "DeselectBrowserArray---------" + s);
Log.e("SystemSetting", "DeselectBrowserArray---------" + bool);
}
private void setHomepagtag(String s) {
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(this.mContext.getContentResolver(), 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);
}
}
private void getTimeControl(Context context, String extras) {
HTTPInterface.getSnTimeControl(context);
}
private void getTopApp(Context context, String extras) {
JSONObject jsonObject = JSON.parseObject(extras);
String packageName = jsonObject.getString("app_package");
if (TextUtils.isEmpty(packageName)) {
SPUtils.put(context, ForegroundAppUtil.TOPAPP_KEY, "");
ForegroundAppUtil.setTopAppClass(context, "");
} else {
SPUtils.put(context, ForegroundAppUtil.TOPAPP_KEY, packageName);
ForegroundAppUtil.setTopAppClass(context, packageName);
ForegroundAppUtil.openTopApp(context);
}
}
private void setBootanimation(Context context, 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(Context context, 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(context, "default_launcher", "");
} else {
JGYUtils.getInstance().setDefaultDesktop(default_launcher);
SPUtils.put(context, "default_launcher", default_launcher);
}
}
}
private void playSound(Context context, String extras) {
JSONObject jsonObject = JSONObject.parseObject(extras);
defaultCallMediaPlayer(context);
}
/**
* 播放系统默认来电铃声
*
* @return MediaPlayer对象
* @throws Exception
*/
MediaPlayer mediaPlayer;
public void defaultCallMediaPlayer(Context context) {
if (mediaPlayer != null) {
mediaPlayer.stop();
mediaPlayer.release();
}
mediaPlayer = MediaPlayer.create(context, 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(context);
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(context);
mediaPlayer.start();
} catch (Exception e) {
e.printStackTrace();
Log.e(TAG, "defaultCallMediaPlayer: " + e.getMessage());
}
}
private void setMaxVolume(Context context) {
AudioManager audioManager = (AudioManager) context.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(Context context, 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(context, 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");
PackageManager pm = mContext.getPackageManager();
PackageInfo packageInfo = null;
try {
packageInfo = pm.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(Context context, String jsonString) {
HTTPInterface.getRunLog(context);
}
private static final int ACTION_PULL = 1;
private static final int ACTION_DELETE = 2;
private static final int ACTION_UPGRADE = 3;
private void customOrder(Context context, 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(context, pkg);
break;
case ACTION_DELETE:
Log.e(TAG, "customOrder: 删除");
ApkUtils.UninstallAPP(context, pkg);
break;
case ACTION_UPGRADE:
Log.e(TAG, "customOrder: 更新");
HTTPInterface.getForceDownload(context);
break;
default:
break;
}
}
}
}