Files
CubeAoleyunSN/app/src/main/java/com/aoleyun/sn/push/PushManager.java

1668 lines
72 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.push;
import android.annotation.SuppressLint;
import android.content.ComponentName;
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.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.os.BatteryManager;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.os.PowerManager;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.WindowManager;
import com.aoleyun.sn.R;
import com.aoleyun.sn.activity.AudioActivity;
import com.aoleyun.sn.activity.main.MainActivity;
import com.aoleyun.sn.bean.ApkInfoPush;
import com.aoleyun.sn.bean.BaseResponse;
import com.aoleyun.sn.bean.BatteryInfo;
import com.aoleyun.sn.bean.DownloadInfo;
import com.aoleyun.sn.bean.RemoteDebug;
import com.aoleyun.sn.bean.ScreenLockState;
import com.aoleyun.sn.comm.CommonConfig;
import com.aoleyun.sn.comm.JGYActions;
import com.aoleyun.sn.dialog.CustomDialog;
import com.aoleyun.sn.gson.GsonUtils;
import com.aoleyun.sn.gson.NullStringToEmptyAdapterFactory;
import com.aoleyun.sn.manager.MapManager;
import com.aoleyun.sn.network.NetInterfaceManager;
import com.aoleyun.sn.network.RetryCallback;
import com.aoleyun.sn.network.UrlAddress;
import com.aoleyun.sn.service.main.MainService;
import com.aoleyun.sn.utils.ApkUtils;
import com.aoleyun.sn.utils.BatteryUtils;
import com.aoleyun.sn.utils.CacheUtils;
import com.aoleyun.sn.utils.Camera2BackgroundUtil;
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.ReceiverCompat;
import com.aoleyun.sn.utils.ServiceAliveUtils;
import com.aoleyun.sn.utils.SysSettingUtils;
import com.aoleyun.sn.utils.TimeUtils;
import com.aoleyun.sn.utils.Utils;
import com.arialyy.aria.core.Aria;
import com.baidu.location.BDAbstractLocationListener;
import com.baidu.location.BDLocation;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
import com.hjq.toast.Toaster;
import com.tencent.mmkv.MMKV;
import java.io.File;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
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.Observer;
import io.reactivex.rxjava3.disposables.Disposable;
import io.reactivex.rxjava3.functions.Consumer;
import io.reactivex.rxjava3.schedulers.Schedulers;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;
import retrofit2.Call;
import retrofit2.Response;
public class PushManager {
private static final String TAG = "PushManager";
private static final String ACTION_REFRESH_BINDING_STATUS = "RefreshBindingStatus";
private static final String AOLEYUN_REFRESH_DESKTOP = "aoleyun_refresh_desktop_action";
@SuppressLint("StaticFieldLeak")
private static PushManager sInstance;
private Context mContext;
private PackageManager mPackageManager;
private ContentResolver mResolver;
private MMKV mMMKV = MMKV.mmkvWithID(CommonConfig.MMKV_ID, MMKV.MULTI_PROCESS_MODE);
private PushManager(Context context) {
if (context == null) {
throw new RuntimeException("Context is NULL");
}
this.mContext = context;
this.mResolver = context.getContentResolver();
this.mPackageManager = mContext.getPackageManager();
}
public static void init(Context context) {
if (sInstance == null) {
sInstance = new PushManager(context);
}
}
public static PushManager getInstance() {
if (sInstance == null) {
throw new IllegalStateException("You must be init PushManager first");
}
return sInstance;
}
/*删除应用*/
private static final String MSG_DELETE = "1";
/*系统设置管控*/
private static final String MSG_SETTING = "2";
/*浏览器网址管控*/
private static final String MSG_BROWSER = "4";
/*app id管控*/
private static final String MSG_APPID = "5";
/*应用联网管控*/
private static final String MSG_NET_CONTROL = "6";
/*APP自启联网滑动管控*/
private static final String MSG_POWER_ON = "7";
/*重置*/
private static final String MSG_RESET = "8";
/*强制安装*/
private static final String MSG_INSTALL = "9";
/*解锁*/
private static final String MSG_LOCK = "10";
/*旧版相机管控*/
private static final String MSG_CAMERA = "11";
private static final String MSG_ONEPACKAGES = "12";
/*app使用时间*/
private static final String GET_APP_USEDTIME = "13";
/*强制下载*/
private static final String GET_FORCEDOWNLOADURL = "14";
/*主页和书签管控*/
private static final String SET_HOMEPAG_TAG = "15";
/*app内网页管控*/
private static final String APP_WEBSITE = "16";
/*禁止app升级*/
private static final String DISABLE_APPUPDATE = "17";
/*隐藏桌面图标*/
private static final String HIDE_DESKTOP_ICON = "18";
/*禁止滑动*/
private static final String DISABLE_APP_SLIDE = "19";
/*更新应用白名单*/
private static final String UPDATE_INFO = "20";
/*截图*/
private static final String SN_SCREENSHOT = "21";
/*重启*/
private static final String DEVICES_REBOOT = "22";
/*获取设备详细信息*/
private static final String GET_DEVICES_INFO = "23";
/*霸屏*/
private static final String LOCK_SCREEN = "24";
/*取消霸屏*/
private static final String UNLOCK_SCREEN = "25";
/*结束进程*/
private static final String KILL_SERVER = "26";
/*时间管控*/
private static final String TIME_CONTROL = "27";
/*app霸屏*/
private static final String TOP_APP = "28";
/*开机动画*/
private static final String LOGO_IMG = "29";
/*默认应用*/
private static final String DEFAULTP_APP = "30";
/*发出声音*/
private static final String PLAY_SOUND = "31";
/*清除app数据*/
private static final String CLEAN_APP_CACHE = "32";
/*开发人员选项*/
private static final String DEVELOPER_OPTIONS = "33";
/*全局更新*/
private static final String GLOBAL_UPDATE = "34";
/*电子书包激活码*/
private static final String EBAG_CODE = "35";
/*更新白名单*/
private static final String UPDATE_WHITELIST = "36";
/*更换批次不恢复出厂*/
private static final String UPDATE_BATCH = "37";
/*添加wifi*/
private static final String UPDATE_WIFI_PW = "38";
/*应用密码锁*/
private static final String APP_LOCK_PASSWD = "39";
/*远程关机*/
private static final String DEVICES_SHUTDOWN_NOW = "40";
/*远程定时关机*/
private static final String DEVICES_POWEROFF = "41";
/*远程log*/
private static final String SN_RUN_LOG = "43";
/*自定义指令*/
private static final String CUSTOM_ORDER = "44";
/*优化内存*/
private static final String CLEAN_MEMORY = "47";
/*运行日志设置*/
private static final String SN_LOG_SETTING = "48";
/*禁止应用打开*/
private static final String DISABLE_APP_USAGE = "51";
/*上传电池信息*/
private static final String INFO_BATTERY_INFO = "53";
/*判断是否更新桌面*/
private static final String UPDATE_DESKTOP = "56";
/*前置拍照*/
private static final String TAKE_FRONT_PICTURE = "58";
/*时间管控*/
private static final String TIME_CONTROL2 = "59";
/*应用安装总开关*/
private static final String INSTALL_CONTROL = "60";
/*usb传输*/
private static final String USB_CONTROL = "61";
/*专注模式*/
private static final String FOCUS_MODE = "62";
/*修改锁屏密码*/
private static final String CHANGE_LOCKED_PASSWD = "63";
/*蓝牙传输管控*/
private static final String BLUETOOTH_CONTROL = "64";
/*开发者选项*/
private static final String DEVELOPER_CONTROL = "65";
/*恢复出厂模式*/
private static final String FACTORY_CONTROL = "66";
/*通知栏开关*/
private static final String SETTING_STATUSBAR = "67";
/*导航栏管控*/
private static final String SETTING_NAVIGATION = "68";
/*存储卡管控*/
private static final String SETTING_TF_CARD = "69";
/*绑定设备*/
private static final String BIND_DEVICE = "71";
/*文件分享*/
private static final String FILE_DISTRIBUTE = "72";
/*打开应用*/
private static final String OPEN_APK = "73";
/*全局黑名单*/
private static final String GLOBAL_BALCK_LIST = "74";
/*全局白名单*/
private static final String GLOBAL_WHITE_LIST = "75";
/*应用市场应用安装*/
private static final String APPSTORE_INSTALL = "76";
/*设置壁纸*/
private static final String SET_WALLPAPER = "78";
/*更换小组标签*/
private static final String UPDATE_CHILD_BATCH = "79";
/*分组应用分发*/
private static final String GROUP_APP_INSTALL = "80";
/*分组应用卸载*/
private static final String GROUP_APP_UNINSTALL = "81";
/*电子围栏*/
private static final String ELECTRONIC_FENCE = "82";
/*发出声音*/
private static final String PLAY_SOUND2 = "89";
/*更新公共应用设置,不安装*/
private static final String PUBLIC_APP_SETTING = "91";
/*公共应用卸载*/
private static final String PUBLIC_APP_UNINSTALL = "92";
public void setPushContent(String title, String extras) {
switch (title) {
case MSG_DELETE:
Toaster.debugShow("收到管控:应用删除");
if (!TextUtils.isEmpty(extras)) {
JsonObject jsonObject = GsonUtils.getJsonObject(extras);
String pkg = jsonObject.get("package_name").getAsString();
deleteApp(pkg);
}
break;
case MSG_SETTING:
Toaster.debugShow("收到管控:系统设置");
if (!TextUtils.isEmpty(extras)) {
JgyUtils.getInstance().SettingSysData(extras);
// JgyUtils.getInstance().removeAllTask();
}
break;
case MSG_BROWSER:
Toaster.debugShow("收到管控:浏览器网址管控");
getDeselectBrowerID();
break;
case MSG_APPID:
Toaster.debugShow("收到管控:APP ID管控");
getDeselectID();
break;
case MSG_NET_CONTROL:
Toaster.debugShow("收到管控:应用联网管控");
settingNetControl(extras);
break;
case MSG_POWER_ON:
Toaster.debugShow("收到管控:应用自启管控");
settingPowerOn(extras);
break;
case MSG_RESET:
Toaster.debugShow("收到管控:设备重置");
JgyUtils.getInstance().cleanAoleLauncher3Cache();
Utils.doMasterClear(mContext);
Aria.download(this).removeAllTask(true);
mMMKV.clearAll();
JgyUtils.getInstance().deleteOtherApp();
JgyUtils.getInstance().cleanAoleAppCache();
JgyUtils.getInstance().wakeUpAoleyunAPP();
NetInterfaceManager.getInstance().getPushAndPubAppTag();
NetInterfaceManager.clearAllCache();
Settings.System.putString(mContext.getContentResolver(), CommonConfig.AOLE_ACTION_FORCE_APP, "");
Settings.System.putString(mContext.getContentResolver(), CommonConfig.AOLE_ACTION_APP_FORBID, "");
sendRefreshBroadcast(mContext);
SysSettingUtils.setDisableSetting(mContext);
break;
case MSG_INSTALL:
Toaster.debugShow("收到管控:应用安装");
NetInterfaceManager.removeCache(UrlAddress.GET_FORCE_INSTALL_LIST);
NetInterfaceManager.removeCache(UrlAddress.GROUP_APP_INSTALL_LIST);
new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
@Override
public void run() {
NetInterfaceManager.getInstance().getAppLimit();
NetInterfaceManager.getInstance().getIconControl();
NetInterfaceManager.getInstance().getDefaultDesktop();
NetInterfaceManager.getInstance().getAppAutoStartUpdateAndNet();
}
}, 2345);
new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
@Override
public void run() {
doDownloadAndInstall(extras);
}
}, 4321);
mContext.sendBroadcast(new Intent(AOLEYUN_REFRESH_DESKTOP));
break;
case MSG_LOCK:
Toaster.debugShow("收到管控:设备锁定");
settingLock(extras);
break;
case MSG_CAMERA:
Toaster.debugShow("收到管控:相机管控");
settingCamera(extras);
break;
case MSG_ONEPACKAGES:
Toaster.debugShow("收到管控:");
settingOneNet(extras);
break;
case GET_APP_USEDTIME:
Toaster.debugShow("收到管控:获取应用使用时间");
JsonObject usedTimeJson = GsonUtils.getJsonObject(extras);
String random = usedTimeJson.get("random").getAsString();
String sendType = usedTimeJson.get("type").getAsString();
NetInterfaceManager.getInstance().sendAppUsedTime(random, sendType);
break;
case GET_FORCEDOWNLOADURL:
case GROUP_APP_INSTALL:
Toaster.debugShow("收到管控:应用强制安装");
NetInterfaceManager.removeCache(UrlAddress.GET_FORCE_INSTALL_LIST);
NetInterfaceManager.removeCache(UrlAddress.GROUP_APP_INSTALL_LIST);
new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
@Override
public void run() {
NetInterfaceManager.getInstance().getAppLimit();
NetInterfaceManager.getInstance().getIconControl();
NetInterfaceManager.getInstance().getDefaultDesktop();
NetInterfaceManager.getInstance().getAppAutoStartUpdateAndNet();
}
}, 2345);
new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
@Override
public void run() {
downloadForceInstallApk(extras);
}
}, 4321);
mContext.sendBroadcast(new Intent(AOLEYUN_REFRESH_DESKTOP));
break;
case SET_HOMEPAG_TAG:
new Handler(Looper.getMainLooper()).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();
Toaster.debugShow("收到管控:浏览器主页书签设置");
}
}, 2000);
break;
case APP_WEBSITE:
Toaster.debugShow("收到管控:APP内部网页管控");
setAPPinsideWebsite(extras);
break;
case DISABLE_APPUPDATE:
Toaster.debugShow("收到管控:应用禁止更新设置");
setDisableUpdateList(extras);
break;
case HIDE_DESKTOP_ICON:
Toaster.debugShow("收到管控:隐藏应用设置");
new Handler(Looper.getMainLooper()).postDelayed(() -> {
//后台发送时数据库未改变,有时候可能获取到的数据时上一次的
Log.e(TAG, "run: HIDE_DESKTOP_ICON ");
NetInterfaceManager.getInstance().getIconControl();
}, 2000);
break;
case DISABLE_APP_SLIDE:
Toaster.debugShow("收到管控:应用滑动设置");
setDisableSlideList(extras);
break;
case UPDATE_INFO:
Toaster.debugShow("收到管控:更新白名单");
NetInterfaceManager.getInstance().getAppLimit();
break;
case SN_SCREENSHOT:
Toaster.debugShow("收到管控:设备截图");
screenshot(extras);
break;
case DEVICES_REBOOT:
Toaster.debugShow("收到管控:设备重启");
Utils.rebootDevices(mContext);
break;
case GET_DEVICES_INFO:
Toaster.debugShow("收到管控:获取设备信息");
getBatteryInfo(mContext);
sendRefreshBroadcast(mContext);
//定位前记录并临时开启系统定位设置,定位结束自动还原
MapManager.getInstance().startLocation(new BDAbstractLocationListener() {
@Override
public void onReceiveLocation(BDLocation location) {
if (null != location) {
switch (location.getLocType()) {
case BDLocation.TypeGpsLocation:// GPS定位结果
case BDLocation.TypeNetWorkLocation:// 网络定位结果
case BDLocation.TypeOffLineLocation:// 离线定位结果
Log.e(TAG, "onLocationChanged: " + "定位成功");
Log.e(TAG, "onLocationChanged: " + location.getAddrStr() + location.getLocationDescribe());
mMMKV.encode("MapAddress", location.getAddrStr() + location.getLocationDescribe());
mMMKV.encode("longitude", String.valueOf(location.getLongitude()));
mMMKV.encode("latitude", String.valueOf(location.getLatitude()));
mMMKV.encode("MapError", "-");
break;
case BDLocation.TypeServerError:
Log.e(TAG, "onReceiveLocation: " + "服务端网络定位失败");
mMMKV.encode("MapError", "服务端网络定位失败,可以反馈IMEI号和大体定位时间到loc-bugs@baidu.com,会有人追查原因");
break;
case BDLocation.TypeNetWorkException:
Log.e(TAG, "onReceiveLocation: " + "网络不同导致定位失败,请检查网络是否通畅");
mMMKV.encode("MapError", "网络不同导致定位失败,请检查网络是否通畅");
break;
case BDLocation.TypeCriteriaException:
Log.e(TAG, "onReceiveLocation: " + "无法获取有效定位依据导致定位失败");
mMMKV.encode("MapError", "无法获取有效定位依据导致定位失败,一般是由于手机的原因,处于飞行模式下一般会造成这种结果,可以试着重启手机");
break;
default:
}
}
Log.e(TAG, "MapAddress: " + mMMKV.decodeString("MapAddress", "-"));
Log.e(TAG, "MapError: " + mMMKV.decodeString("MapError", "-"));
//定位结束(成功或失败),停止定位并还原定位前的系统设置
MapManager.getInstance().stopLocation();
}
@Override
public void onLocDiagnosticMessage(int locType, int diagnosticType, String diagnosticMessage) {
super.onLocDiagnosticMessage(locType, diagnosticType, diagnosticMessage);
StringBuffer sb = new StringBuffer(256);
sb.append("诊断结果: ");
if (locType == BDLocation.TypeNetWorkLocation) {
if (diagnosticType == 1) {
sb.append("网络定位成功,没有开启GPS,建议打开GPS会更好");
sb.append("\n" + diagnosticMessage);
} else if (diagnosticType == 2) {
sb.append("网络定位成功,没有开启Wi-Fi,建议打开Wi-Fi会更好");
sb.append("\n" + diagnosticMessage);
}
} else if (locType == BDLocation.TypeOffLineLocationFail) {
if (diagnosticType == 3) {
sb.append("定位失败,请您检查您的网络状态");
sb.append("\n" + diagnosticMessage);
}
} else if (locType == BDLocation.TypeCriteriaException) {
if (diagnosticType == 4) {
sb.append("定位失败,无法获取任何有效定位依据");
sb.append("\n" + diagnosticMessage);
} else if (diagnosticType == 5) {
sb.append("定位失败,无法获取有效定位依据,请检查运营商网络或者Wi-Fi网络是否正常开启,尝试重新请求定位");
sb.append(diagnosticMessage);
} else if (diagnosticType == 6) {
sb.append("定位失败,无法获取有效定位依据,请尝试插入一张sim卡或打开Wi-Fi重试");
sb.append("\n" + diagnosticMessage);
} else if (diagnosticType == 7) {
sb.append("定位失败,飞行模式下无法获取有效定位依据,请关闭飞行模式重试");
sb.append("\n" + diagnosticMessage);
} else if (diagnosticType == 9) {
sb.append("定位失败,无法获取任何有效定位依据");
sb.append("\n" + diagnosticMessage);
}
} else if (locType == BDLocation.TypeServerError) {
if (diagnosticType == 8) {
sb.append("定位失败,请确认您定位的开关打开状态,是否赋予APP定位权限");
sb.append("\n" + diagnosticMessage);
}
}
Log.e(TAG, "onLocationChanged: " + "定位失败");
mMMKV.encode("MapError", sb.toString());
Log.e(TAG, "onLocDiagnosticMessage: " + sb);
}
});
break;
case LOCK_SCREEN:
Toaster.debugShow("收到管控:屏幕锁定");
// JsonObject lockJSONObject = GsonUtils.getJsonObject(extras);
// String name = lockJSONObject.get("name").getAsString();
setLock_screen(1, "锁屏管控中");
break;
case UNLOCK_SCREEN:
Toaster.debugShow("收到管控:屏幕解锁");
setLock_screen(0, "");
break;
case KILL_SERVER:
Toaster.debugShow("收到管控:停止应用");
JsonObject killJSONObject = GsonUtils.getJsonObject(extras);
String packages = killJSONObject.get("package_name").getAsString();
JgyUtils.getInstance().killBackgroundProcesses(packages);
break;
case TIME_CONTROL:
Toaster.debugShow("收到管控:使用时间管控");
getTimeControl(extras);
break;
case TOP_APP:
Toaster.debugShow("收到管控:应用霸屏");
getTopApp(extras);
break;
case LOGO_IMG:
Toaster.debugShow("收到管控:开机动画设置");
setBootanimation(extras);
Log.e(TAG, "processCustomMessage: " + extras);
break;
case DEFAULTP_APP:
Toaster.debugShow("收到管控:设置默认APP");
setDefalutApp(extras);
break;
case PLAY_SOUND:
case PLAY_SOUND2:
Toaster.debugShow("收到管控:查找设备");
playSound(extras);
break;
case CLEAN_APP_CACHE:
Toaster.debugShow("收到管控:应用缓存清除");
cleanCache(extras);
break;
case DEVELOPER_OPTIONS:
Toaster.debugShow("收到管控:开发人员选项管控");
setDeveloperoptions(extras);
break;
case GLOBAL_UPDATE:
Toaster.debugShow("收到管控:全局更新");
GlobalUpdate(extras);
break;
case EBAG_CODE:
Toaster.debugShow("收到管控:电子书包激活码");
setEbagCode(extras);
JgyUtils.getInstance().killBackgroundProcesses("com.jxw.launcher");
break;
case UPDATE_WHITELIST:
Toaster.debugShow("收到管控:更新白名单");
NetInterfaceManager.getInstance().getAppLimit();
break;
case UPDATE_BATCH:
Utils.doMasterClear(mContext);
break;
case UPDATE_CHILD_BATCH:
Toaster.debugShow("收到管控:更换批次不恢复出厂设置");
NetInterfaceManager.getInstance().getPushAndPubAppTag();
Aria.download(this).removeAllTask(true);
JgyUtils.getInstance().cleanAoleAppCache();
try {
new CacheUtils().cleanApplicationUserData(mContext, "com.android.browser");
} catch (Exception e) {
e.printStackTrace();
Log.e(TAG, "setHomepagtag: " + e.getMessage());
}
sendRefreshBroadcast(mContext);
break;
case UPDATE_WIFI_PW:
NetInterfaceManager.getInstance().getWiFiPasswd();
break;
case APP_LOCK_PASSWD:
mContext.sendBroadcast(new Intent(AOLEYUN_REFRESH_DESKTOP));
break;
case DEVICES_SHUTDOWN_NOW:
JgyUtils.getInstance().shutdown();
break;
case DEVICES_POWEROFF:
NetInterfaceManager.getInstance().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;
case DISABLE_APP_USAGE:
disableApp(extras);
break;
case INFO_BATTERY_INFO:
getBatteryInfo(mContext);
break;
case UPDATE_DESKTOP:
NetInterfaceManager.getInstance().getDefaultDesktop();
break;
case TAKE_FRONT_PICTURE:
Toaster.debugShow("收到推送消息: 截图");
long createTime = System.currentTimeMillis() / 1000;
Camera2BackgroundUtil camera2BackgroundUtil = new Camera2BackgroundUtil(mContext, new Camera2BackgroundUtil.CameraCallBack() {
@Override
public void onErr(String msg) {
Log.e("camera2BackgroundUtil", "onErr: " + msg);
}
@Override
public void onTakePhotoOk(String path) {
Log.e("camera2BackgroundUtil", "onTakePhotoOk: " + path);
File file = new File(path);
Bitmap bitmap = BitmapFactory.decodeFile(path);
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(mContext));
params.put("createtime", String.valueOf(createTime));
Call<BaseResponse> call = NetInterfaceManager.getInstance().getUploadInfoApi().sendScreenshot(params, body);
call.enqueue(new RetryCallback<BaseResponse>(call, 10, 30 * 1000) {
@Override
public void onRequestResponse(Call call, Response response) {
Log.e(TAG, "onRequestResponse: " + response.body().toString());
}
@Override
public void onRequestFail(Call call, Throwable t) {
Log.e(TAG, "onRequestFail: ");
}
@Override
public void onStartRetry() {
Log.e(TAG, "onStartRetry: ");
}
});
}
});
camera2BackgroundUtil.startTakePicture(mContext.getExternalCacheDir().getAbsolutePath() + File.separator + TimeUtils.getPhotoDate() + ".jpg");
break;
case FOCUS_MODE:
refreshFocusMode();
break;
case TIME_CONTROL2:
case USB_CONTROL:
NetInterfaceManager.getInstance().getSnSetting();
break;
case INSTALL_CONTROL:
case BLUETOOTH_CONTROL:
case DEVELOPER_CONTROL:
case FACTORY_CONTROL:
case SETTING_STATUSBAR:
case SETTING_NAVIGATION:
case SETTING_TF_CARD:
// NetInterfaceManager.getInstance().setSystemSetting();
NetInterfaceManager.getInstance().getSnSetting();
break;
case BIND_DEVICE:
bindService(extras);
break;
case FILE_DISTRIBUTE:
ApkUtils.openPackage(mContext, "com.uiui.filecloud");
break;
case OPEN_APK:
openApk(extras);
break;
case GLOBAL_BALCK_LIST:
NetInterfaceManager.getInstance().getBlackList();
break;
case GLOBAL_WHITE_LIST:
NetInterfaceManager.getInstance().getWhiteList();
break;
case APPSTORE_INSTALL:
break;
case SET_WALLPAPER:
setWallpaper(extras);
break;
case GROUP_APP_UNINSTALL:
Toaster.debugShow("收到管控:应用删除");
if (!TextUtils.isEmpty(extras)) {
JsonObject jsonObject = GsonUtils.getJsonObject(extras);
String pkg = jsonObject.get("app_package").getAsString();
deleteApp(pkg);
}
case ELECTRONIC_FENCE:
break;
case PUBLIC_APP_SETTING:
updatePublicAppSettings(extras);
break;
case PUBLIC_APP_UNINSTALL:
uninstallPublicApp(extras);
break;
default:
}
}
private void downloadForceInstallApk(String extras) {
File file = new File(JgyUtils.getInstance().getDownLoadPath());
if (!file.exists()) {
file.mkdirs();
}
if (TextUtils.isEmpty(extras)) {
Log.e(TAG, "settingNetControl extras is null");
return;
}
ApkInfoPush apkInfoPush = GsonUtils.toJavaObject(extras, ApkInfoPush.class);
JsonObject packageObj = GsonUtils.getJsonObject(GsonUtils.toJSONString(apkInfoPush));
Utils.ariaDownload(mContext, apkInfoPush.getApp_url(), packageObj);
}
private void setWallpaper(String extras) {
NetInterfaceManager.getInstance().getWallpaper();
}
private void refreshFocusMode() {
// Intent intent = new Intent();
// ComponentName componentName = new ComponentName("com.aoleyunos.dop6", "com.aoleyunos.dop6.service.main.MainService");
// intent.setComponent(componentName);
// intent.setAction(CommonConfig.FOCUS_MODE_REFRESH_KEY);
// mContext.sendBroadcast(intent);
JgyUtils.getInstance().gotoLauncher();
NetInterfaceManager.getInstance().getCloudLessonSettings();
}
private void deleteApp(String pkg) {
Log.e(TAG, "deleteApp: " + pkg);
if (TextUtils.isEmpty(pkg)) return;
String forceApp = Settings.System.getString(mContext.getContentResolver(), CommonConfig.AOLE_ACTION_FORCE_APP);
if (!TextUtils.isEmpty(forceApp)) {
List<String> forceAppList = new ArrayList<>(Arrays.asList(forceApp.split(",")));
forceAppList.remove(pkg);
if (forceAppList.size() != 0) {
Settings.System.putString(mContext.getContentResolver(), CommonConfig.AOLE_ACTION_FORCE_APP, String.join(",", forceAppList));
} else {
Settings.System.putString(mContext.getContentResolver(), CommonConfig.AOLE_ACTION_FORCE_APP, "");
}
}
ApkUtils.UninstallAPP(mContext, pkg);
new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
@Override
public void run() {
NetInterfaceManager.getInstance().getIconControl();
NetInterfaceManager.getInstance().getDefaultDesktop();
NetInterfaceManager.getInstance().getAppAutoStartUpdateAndNet();
}
}, 1234);
}
private int changeNum(int paramInt) {
return paramInt == 0 ? 1 : 0;
}
private void disableApp(String extras) {
JsonObject jsonObject = GsonUtils.getJsonObject(extras);
try {
String packages = jsonObject.get("package").getAsString();
int is_open = jsonObject.get("is_open").getAsInt();
if (is_open == 0) {
JgyUtils.getInstance().killBackgroundProcesses(packages);
}
} catch (Exception e) {
Log.e(TAG, "disableApp: " + e.getMessage());
}
new Handler(Looper.getMainLooper()).postDelayed(() -> NetInterfaceManager.getInstance().getSnAppAttr(), 1234);
}
private void setLock_screen(int state, String name) {
if (ServiceAliveUtils.isServiceAlive(mContext)) {
mContext.startService(new Intent(mContext, MainService.class));
}
ScreenLockState screenLockState = new ScreenLockState();
screenLockState.setIs_screen_lock(state);
screenLockState.setName(name);
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;
}
Gson gson = new GsonBuilder().registerTypeAdapterFactory(new NullStringToEmptyAdapterFactory()).create();
Type type = new TypeToken<DownloadInfo>() {
}.getType();
DownloadInfo downloadInfo = gson.fromJson(jsonString, type);
Log.e("doDownloadAndInstall", "downloadInfo: " + downloadInfo);
String app_name = downloadInfo.getApp_name();
String app_package = downloadInfo.getApp_package();
String app_url = downloadInfo.getApp_url();
long app_version_code = downloadInfo.getApp_version_code();
String app_id = downloadInfo.getApp_id();
String MD5 = downloadInfo.getMD5();
if ("com.aoleyunos.dop1".equals(app_package) || "com.aoleyunos.dop2".equals(app_package)) {
Intent intent = new Intent("com.aoleyunos.dop.activity.refresh");
intent.setPackage(app_package);
// intent.setComponent(new ComponentName(app_package, app_package + ".MainActivity"));
mContext.sendBroadcast(intent);
}
JsonObject packageObj = new JsonObject();
packageObj.addProperty("app_name", app_name);
packageObj.addProperty("app_package", app_package);
packageObj.addProperty("app_id", app_id);
packageObj.addProperty("MD5", MD5);
Log.e(TAG, "doDownloadAndInstall: app_package:" + app_package);
Log.e(TAG, "doDownloadAndInstall: app_url:" + app_url);
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 + " 未安装");
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) {
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 = ReceiverCompat.registerReceiver(new ContextWrapper(mContext), null,
new IntentFilter("android.intent.action.BATTERY_CHANGED"), ReceiverCompat.RECEIVER_NOT_EXPORTED);
return intent.getIntExtra("level", -1) * 100 / intent.getIntExtra("scale", -1);
}
private void getDeselectBrowerID() {
NetInterfaceManager.getInstance().setBrowserBlackList();//浏览器网址管控
}
private void getDeselectID() {
NetInterfaceManager.getInstance()
.getAppIDControl();
}
private void setDisableSlideList(String jsonString) {
JsonObject jSONObject = GsonUtils.getJsonObject(jsonString);
Log.e("setDisableSlideList", "jSONObject::" + jSONObject.toString());
String strban = jSONObject.get("ban").getAsString();
String strnot = jSONObject.get("not").getAsString();
String aole_disable_slide = Settings.System.getString(mResolver, CommonConfig.AOLE_ACTION_DISABLE_SLIDE);
Log.e("fht", "aole_disable_slide: " + aole_disable_slide);
if (!TextUtils.isEmpty(strban)) {
Settings.System.putString(mResolver, CommonConfig.AOLE_ACTION_DISABLE_SLIDE, strban);
Log.e("fht", "sendban::" + strban);
} else {
Settings.System.putString(mResolver, CommonConfig.AOLE_ACTION_DISABLE_SLIDE, "Invalid");
}
Log.e("fht", "aole_disable_slide::" + Settings.System.getString(mResolver, CommonConfig.AOLE_ACTION_DISABLE_SLIDE));
}
private void setDisableUpdateList(String jsonString) {
Log.e("setDisableUpdateList", jsonString);
JsonObject jsonObject = GsonUtils.getJsonObject(jsonString);
String ban = jsonObject.get("ban").getAsString();
String not = jsonObject.get("not").getAsString();
String[] banList = ban.split(",");
String[] notList = not.split(",");
boolean b = Utils.writeDisableUpdateList(mContext, banList, notList);
}
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 = GsonUtils.getJsonObject(s);
String s1 = jSONObject.get("ban").getAsString();
// 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 = GsonUtils.getJsonObject(s);
Log.e("settingOneNet", "jSONObject::" + jSONObject.toString());
String packages = jSONObject.get("package").getAsString();
String status = jSONObject.get("status").getAsString();
}
private void settingNetControl(String s) {
if (TextUtils.isEmpty(s)) {
Log.e(TAG, "settingNetControl extras is null");
}
JsonObject jSONObject = GsonUtils.getJsonObject(s);
Log.e("settingNetControl", "jSONObject::" + jSONObject.toString());
String disallow = jSONObject.get("ban").getAsString();
String allow = jSONObject.get("not").getAsString();
HashSet<String> disallowApp = new HashSet<>(Arrays.asList(disallow.split(",")));
HashSet<String> allowApp = new HashSet<>(Arrays.asList(allow.split(",")));
JgyUtils.getInstance().setAppNetwork(disallowApp, allowApp);
}
private void settingPowerOn(String s) {
if (TextUtils.isEmpty(s)) {
Log.e(TAG, "settingPowerOn extras is null");
return;
}
JsonObject jSONObject = GsonUtils.getJsonObject(s);
String ban = jSONObject.get("ban").getAsString();
String not = jSONObject.get("not").getAsString();
Log.e(TAG, "settingPowerOn: aole_app_power_on = " + not);
if (TextUtils.isEmpty(not)) {
//当 qch_app_power_on 的值为空时,会造成系统所有应用断网
Settings.System.putString(mResolver, CommonConfig.AOLE_ACTION_APP_POWER_ON, "Invalid");
} else {
Settings.System.putString(mResolver, CommonConfig.AOLE_ACTION_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() {
NetInterfaceManager.getInstance().getBookMarkBlackWhiteList();
}
private void setAPPinsideWebsite(String s) {
//禁止app内部网页访问,包名用,隔开
NetInterfaceManager.getInstance().getAppinsideWeb(new NetInterfaceManager.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 = GsonUtils.getJsonObject(s);
int i = changeNum(jSONObject.get("lock").getAsInt());
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 = GsonUtils.getJsonObject(s);
// long createTime = jSONObject.getLong("createTime");
long createTime = System.currentTimeMillis() / 1000;
PowerManager.WakeLock mWakeLock = JgyUtils.acquireWakeLock(mContext, 60 * 1000);
JgyUtils.release(mWakeLock);
if (createTime != 0) {
Log.e("createTime", String.valueOf(createTime));
new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
@Override
public void run() {
doscreenshot(createTime);
}
}, 1234);
}
}
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(mContext));
params.put("createtime", String.valueOf(time));
Call<BaseResponse> call = NetInterfaceManager.getInstance().getUploadInfoApi().sendScreenshot(params, body);
call.enqueue(new RetryCallback<BaseResponse>(call, 10, 30 * 1000) {
@Override
public void onRequestResponse(Call call, Response response) {
Log.e(TAG, "onRequestResponse: " + response.body().toString());
}
@Override
public void onRequestFail(Call call, Throwable t) {
Log.e(TAG, "onRequestFail: ");
}
@Override
public void onStartRetry() {
Log.e(TAG, "onStartRetry: ");
}
});
// 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) {
// NetInterfaceManager.getInstance().getSnTimeControl();
NetInterfaceManager.getInstance().getTimeControl();
}
private void getTopApp(String extras) {
JsonObject jsonObject = GsonUtils.getJsonObject(extras);
String packageName = jsonObject.get("app_package").getAsString();
if (TextUtils.isEmpty(packageName)) {
Settings.Global.putString(mResolver, ForegroundAppUtil.TOPAPP_KEY, "");
ForegroundAppUtil.setTopAppClass(mContext, "");
} else {
Settings.Global.putString(mResolver, ForegroundAppUtil.TOPAPP_KEY, packageName);
ForegroundAppUtil.setTopAppClass(mContext, packageName);
ForegroundAppUtil.openTopApp(mContext);
}
Log.e(TAG, "getTopApp: " + Settings.Global.getString(mResolver, ForegroundAppUtil.TOPAPP_KEY));
}
private void setBootanimation(String extras) {
JsonObject jsonObject = GsonUtils.getJsonObject(extras);
int type = jsonObject.get("type").getAsInt();
if (type == 1) {
String file_url = jsonObject.get("file_url").getAsString();
String file_md5 = jsonObject.get("file_md5").getAsString();
JgyUtils.getInstance().checkBootFile(file_url, file_md5);
} else {
JgyUtils.getInstance().removeBootanimation();
}
}
private void setDefalutApp(String extras) {
if (TextUtils.isEmpty(extras)) {
JgyUtils.getInstance().setDefaultDesktop("");
JgyUtils.getInstance().openLauncher3();
} else {
JsonObject jsonObject = GsonUtils.getJsonObject(extras);
JsonElement launcherElement = jsonObject.get("default_launcher");
if (launcherElement.isJsonNull() || TextUtils.isEmpty(launcherElement.getAsString())) {
JgyUtils.getInstance().setDefaultDesktop("");
mMMKV.encode(CommonConfig.DEFAULT_LAUNCHER_PACKAGE_NAME, "");
JgyUtils.getInstance().openLauncher3();
} else {
String default_launcher = launcherElement.getAsString();
mMMKV.encode(CommonConfig.DEFAULT_LAUNCHER_PACKAGE_NAME, default_launcher);
JgyUtils.getInstance().setDefaultDesktop(default_launcher);
ComponentName cn = new ComponentName(default_launcher, JgyUtils.getInstance().getStartClassName(default_launcher));
Intent intent = new Intent();
intent.setComponent(cn);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.startActivity(intent);
}
JsonElement keyboardElement = jsonObject.get("default_IME");
if (keyboardElement.isJsonNull() || TextUtils.isEmpty(keyboardElement.getAsString())) {
Intent intent = new Intent("setDefaultInputMethod");
if (JgyUtils.getInstance().checkAppPlatform() == JgyUtils.QualcommPlatform) {
intent.putExtra("package", "com.onyx.kime");
intent.setPackage("com.onyx.neoservice");
} else {
intent.putExtra("package", "com.android.inputmethod.latin");
intent.setPackage("com.android.settings");
}
mContext.sendBroadcast(intent);
} else {
String default_IME = jsonObject.get("default_IME").getAsString();
Intent intent = new Intent("setDefaultInputMethod");
intent.putExtra("package", default_IME);
if (JgyUtils.getInstance().checkAppPlatform() == JgyUtils.QualcommPlatform) {
intent.setPackage("com.onyx.neoservice");
} else {
intent.setPackage("com.android.settings");
}
mContext.sendBroadcast(intent);
}
String default_browser = jsonObject.get("default_browser").getAsString();
Log.e(TAG, "setDefalutApp: default_browser = " + default_browser);
Intent intent = new Intent("setDefaultBrowser");
intent.putExtra("package", default_browser);
if (JgyUtils.getInstance().checkAppPlatform() == JgyUtils.QualcommPlatform) {
intent.setPackage("com.onyx.neoservice");
// } else if (JgyUtils.getInstance().checkAppPlatform() == JgyUtils.G122JPlatform) {
} else {
intent.setPackage("com.android.settings");
}
mContext.sendBroadcast(intent);
}
}
private void playSound(String extras) {
// defaultCallMediaPlayer(mContext);
Intent intent = new Intent(mContext, AudioActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.startActivity(intent);
}
/**
* 播放系统默认来电铃声
*
* @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 = GsonUtils.getJsonObject(extras);
String packageName = jsonObject.get("app_package").getAsString();
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 = GsonUtils.getJsonObject(extras);
int is_developer = jsonObject.get("is_developer").getAsInt();
Log.e(TAG + ":" + "getDeveloper", "onNext: " + is_developer);
Log.e(TAG, "setDeveloperoptions: " + is_developer);
JgyUtils.getInstance().setDeveloperOptions(is_developer);
}
private void GlobalUpdate(String jsonString) {
if (TextUtils.isEmpty(jsonString)) {
throw new RuntimeException();
}
JsonObject jsonObject = GsonUtils.getJsonObject(jsonString);
String platform = jsonObject.get("platform").getAsString();
if (JgyUtils.getInstance().isSamePlatform(platform)) {
checkAPPInstall(jsonObject);
} else {
Log.e(TAG, "GlobalUpdate: " + "应用与app平台不符合");
}
}
@SuppressLint("NewApi")
private void checkAPPInstall(JsonObject jsonObject) {
long version_code = jsonObject.get("app_version_code").getAsLong();
PackageInfo packageInfo = null;
try {
packageInfo = mPackageManager.getPackageInfo(jsonObject.get("app_package").getAsString(), 0);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
long appVersionCode;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
appVersionCode = packageInfo.getLongVersionCode();
} else {
appVersionCode = packageInfo.versionCode;
}
if (packageInfo == null || appVersionCode < version_code) {
Utils.ariaDownload(mContext, jsonObject.get("app_url").getAsString(), jsonObject);
} else {
Log.e(TAG, "checkAPPInstall: " + "已经是最新版");
}
}
private void setEbagCode(String jsonString) {
JsonObject jsonObject = GsonUtils.getJsonObject(jsonString);
String ebagCode = jsonObject.get("ebagCode").getAsString();
if (TextUtils.isEmpty(ebagCode)) {
Log.e(TAG, "setEbagCode: " + "ebagCode is empty");
mMMKV.encode("ebagCode", "");
if (JgyUtils.getInstance().checkAppPlatform() != JgyUtils.YXPD1Platform) {
Settings.System.putString(mContext.getContentResolver(), CommonConfig.ACTIVATIONBEAN_CODE_KEY, "");
Settings.Global.putInt(mContext.getContentResolver(), CommonConfig.UIUI_ACTIVATION_KEY, 0);
}
} else {
mMMKV.encode("ebagCode", ebagCode);
if (JgyUtils.getInstance().checkAppPlatform() != JgyUtils.YXPD1Platform) {
Settings.System.putString(mContext.getContentResolver(), CommonConfig.ACTIVATIONBEAN_CODE_KEY, ebagCode);
Settings.Global.putInt(mContext.getContentResolver(), CommonConfig.UIUI_ACTIVATION_KEY, 1);
}
}
}
private void recordLog(String jsonString) {
NetInterfaceManager.getInstance().getRunLog();
}
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: 唤起");
openApp(pkg);
break;
case ACTION_DELETE:
Log.e(TAG, "customOrder: 删除");
orderDeleteApp(pkg);
break;
case ACTION_UPGRADE:
Log.e(TAG, "customOrder: 更新");
NetInterfaceManager.getInstance().getForceDownload();
break;
default:
break;
}
}
}
public static final String DEBUG_APP_LIST = "debug_app_pkg_list";
private void openApp(String pkg) {
Set<String> pkgs = mMMKV.decodeStringSet(DEBUG_APP_LIST, new HashSet<>());
pkgs.add(pkg);
Log.e(TAG, "openApp: pkg = " + pkgs);
mMMKV.encode(DEBUG_APP_LIST, pkgs);
PackageManager pm = mContext.getPackageManager();
if (pm.getApplicationEnabledSetting(pkg) == PackageManager.COMPONENT_ENABLED_STATE_DISABLED) {
try {
pm.setApplicationEnabledSetting(pkg, PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, 0);
} catch (Exception e) {
Log.e(TAG, "openApp: " + e.getMessage());
}
}
ApkUtils.openPackage(mContext, pkg);
}
private void orderDeleteApp(String pkg) {
Set<String> pkgs = mMMKV.decodeStringSet(DEBUG_APP_LIST, new HashSet<>());
pkgs.remove(pkg);
Log.e(TAG, "orderDeleteApp: pkgs = " + pkgs);
mMMKV.encode(DEBUG_APP_LIST, pkgs);
if (ApkUtils.isSystemApp(mContext, pkg)) {
JgyUtils.getInstance().hideApp(pkg);
} else {
ApkUtils.UninstallAPP(mContext, pkg);
}
}
/**
* @param jsonString "is_log": 1,//是否开启运行日志 0关闭 1开启
* "is_log_type": 1 //获取运行日志类型 0即时 1定时
*/
private void senSNLogFile(String jsonString) {
JsonObject jsonObject = GsonUtils.getJsonObject(jsonString);
int is_log = jsonObject.get("is_log").getAsInt();
int is_log_type = jsonObject.get("is_log_type").getAsInt();
if (is_log == 0) {
return;
}
if (is_log_type == 0) {
NetInterfaceManager.getInstance().uploadLogFile();
} else {
mMMKV.encode(CommonConfig.UPLOAD_LOG_TYPE, 1);
}
}
private void getBatteryInfo(Context context) {
IntentFilter filter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
Intent receiver = ReceiverCompat.registerReceiver(context, null, filter, ReceiverCompat.RECEIVER_NOT_EXPORTED);
String jsonString = BatteryUtils.getBatteryJson(context, receiver).toString();
Gson gson = new Gson();
Type type = new TypeToken<BatteryInfo>() {
}.getType();
BatteryInfo batteryInfo = gson.fromJson(jsonString, type);
NetInterfaceManager.getInstance().sendBatteryInfo(batteryInfo);
}
private void sendRefreshBroadcast(Context context) {
Intent intent = new Intent(MainService.RefreshReceiver.REFRESH_RECEIVER_ACTION);
context.sendBroadcast(intent);
}
private Disposable subscribe;
private long cutdownTime = 30;
private CustomDialog dialog;
void bindService(final String jsonString) {
Toaster.debugShow("收到绑定设备请求");
JsonObject object = GsonUtils.getJsonObject(jsonString);
// String userName = object.get("member_name").getAsString();
final String id = object.get("userId").getAsString();
String phoneNum = object.get("mobile").getAsString();
if (dialog == null) {
dialog = new CustomDialog(mContext);
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(id, 0);
dialog.dismiss();
dialog = null;
subscribe.dispose();
subscribe = null;
}
}
});
dialog.setMessage(phoneNum + "请求绑定你的设备")
.setTitle("设备绑定请求")
.setPositive("允许")
.setNegtive("拒绝")
// .setSingle(true)
.setOnClickBottomListener(new CustomDialog.OnClickBottomListener() {
@Override
public void onPositiveClick() {
bind(id, 1);
dialog.dismiss();
dialog = null;
subscribe.dispose();
subscribe = null;
}
@Override
public void onNegtiveClick() {
bind(id, 2);
Toaster.show("设备取消绑定");
dialog.dismiss();
dialog = null;
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_info.setNegtiveText("拒绝" + "(" + value + ")");
// }
//
// @Override
// public void onFinish() {
// bind(context, id, 0);
// dialog_info.dismiss();
// }
// }.start();
}
private void bind(final String id, int type) {
NetInterfaceManager.getInstance()
.getDevicesStatusApi()
.snConfirmBind(Utils.getSerial(mContext), 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) {
Toaster.show("绑定成功");
sendRefreshIntent();
} else if (code == 301) {
Toaster.show(msg);
}
}
@Override
public void onError(@NonNull Throwable e) {
Log.e("bind", "onError: " + e.getMessage());
onComplete();
}
@Override
public void onComplete() {
Log.e("bind", "onComplete: ");
// NetInterfaceManager.getInstance().getSnInfo();
Intent serviceIntent = new Intent(MainService.RefreshReceiver.REFRESH_RECEIVER_ACTION);
mContext.sendBroadcast(serviceIntent);
Intent activityIntent = new Intent(MainActivity.REFRESHACTION);
mContext.sendBroadcast(activityIntent);
}
});
}
private void sendRefreshIntent() {
Intent intent = new Intent(ACTION_REFRESH_BINDING_STATUS);
intent.setPackage("com.teclast.zyos");
mContext.sendBroadcast(intent);
}
private void openApk(String extras) {
JsonObject jsonObject = GsonUtils.getJsonObject(extras);
String app_package = jsonObject.get("app_package").getAsString();
ApkUtils.openPackage(mContext, app_package);
}
public void updatePublicAppSettings(String extras) {
Toaster.debugShow("收到管控:应用公共设置");
if (TextUtils.isEmpty(extras)) {
Log.e(TAG, "updatePublicAppSettings: extras is null");
return;
}
new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
@Override
public void run() {
NetInterfaceManager.getInstance().getAppLimit();
NetInterfaceManager.getInstance().getAppAutoStartUpdateAndNet();
}
}, 2345);
ApkInfoPush apkInfoPush = GsonUtils.toJavaObject(extras, ApkInfoPush.class);
}
public void uninstallPublicApp(String extras) {
Toaster.debugShow("收到管控:应用公共删除");
if (!TextUtils.isEmpty(extras)) {
JsonObject jsonObject = GsonUtils.getJsonObject(extras);
String pkg = jsonObject.get("package_name").getAsString();
deleteApp(pkg);
}
}
}