version:
fix:优化请求次数 add:
This commit is contained in:
@@ -21,7 +21,9 @@ import com.arialyy.aria.core.task.DownloadTask;
|
||||
import com.blankj.utilcode.util.ToastUtils;
|
||||
import com.uiui.sn.KeepAliveConnection;
|
||||
import com.uiui.sn.R;
|
||||
import com.uiui.sn.service.main.MainService;
|
||||
import com.uiui.sn.utils.ApkUtils;
|
||||
import com.uiui.sn.utils.JGYUtils;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@@ -142,4 +144,19 @@ public class DownloadService extends Service {
|
||||
Log.e("taskComplete", task.getExtendField());
|
||||
Aria.download(this).load(task.getDownloadEntity().getId()).cancel();
|
||||
}
|
||||
|
||||
@Download.onTaskFail
|
||||
void taskFail(DownloadTask task, Exception e) {
|
||||
Aria.download(this).resumeAllTask();
|
||||
final String filepath = task.getFilePath();
|
||||
final String packageName = task.getExtendField();
|
||||
Log.e("aria", "taskFail: " + packageName + "filepath: " + filepath + "Exception: " + e.getMessage());
|
||||
|
||||
// Aria.download(this)
|
||||
// .load(task.getDownloadEntity().getRealUrl()) //读取下载地址
|
||||
// .setFilePath(task.getFilePath())
|
||||
// .ignoreFilePathOccupy()
|
||||
// .setExtendField(task.getExtendField())
|
||||
// .create(); //启动下载}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,413 +0,0 @@
|
||||
package com.uiui.sn.service;
|
||||
|
||||
import android.app.Service;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.IBinder;
|
||||
import android.os.SystemClock;
|
||||
import android.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.blankj.utilcode.util.NetworkUtils;
|
||||
import com.uiui.sn.activity.main.MainActivity;
|
||||
import com.uiui.sn.activity.main.MainContact;
|
||||
import com.uiui.sn.activity.main.MainPresenter;
|
||||
import com.uiui.sn.bean.zuoye.BaseResponse;
|
||||
import com.uiui.sn.bean.zuoye.UserInfo;
|
||||
import com.uiui.sn.bean.gankao.AvailableProduct;
|
||||
import com.uiui.sn.config.Configs;
|
||||
import com.uiui.sn.jpush.TagAliasOperatorHelper;
|
||||
import com.uiui.sn.manager.ControlManager;
|
||||
import com.uiui.sn.network.HTTPInterface;
|
||||
import com.uiui.sn.utils.SPUtils;
|
||||
import com.uiui.sn.utils.ToastUtil;
|
||||
import com.uiui.sn.utils.Utils;
|
||||
import com.trello.rxlifecycle2.LifecycleProvider;
|
||||
import com.trello.rxlifecycle2.LifecycleTransformer;
|
||||
import com.trello.rxlifecycle2.RxLifecycle;
|
||||
import com.trello.rxlifecycle2.android.ActivityEvent;
|
||||
import com.trello.rxlifecycle2.android.RxLifecycleAndroid;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import cn.jpush.android.api.JPushInterface;
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.ObservableEmitter;
|
||||
import io.reactivex.ObservableOnSubscribe;
|
||||
import io.reactivex.Observer;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
import io.reactivex.subjects.BehaviorSubject;
|
||||
|
||||
import static com.uiui.sn.jpush.TagAliasOperatorHelper.ACTION_SET;
|
||||
|
||||
/**
|
||||
* @author jgy02
|
||||
*/
|
||||
public class MainService extends Service implements MainContact.MainView, NetworkUtils.OnNetworkStatusChangedListener, LifecycleProvider<ActivityEvent> {
|
||||
private String TAG = MainService.class.getSimpleName();
|
||||
public static MainPresenter mPresenter;
|
||||
|
||||
//执行所有请求的时间
|
||||
long runningTime = 0;
|
||||
|
||||
//MainService上次执行时间
|
||||
long startCommandTime = 0;
|
||||
|
||||
private final BehaviorSubject<ActivityEvent> lifecycleSubject = BehaviorSubject.create();
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Observable<ActivityEvent> lifecycle() {
|
||||
return lifecycleSubject.hide();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public <T> LifecycleTransformer<T> bindUntilEvent(@NotNull ActivityEvent event) {
|
||||
return RxLifecycle.bindUntilEvent(lifecycleSubject, event);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public <T> LifecycleTransformer<T> bindToLifecycle() {
|
||||
return RxLifecycleAndroid.bindActivity(lifecycleSubject);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisconnected() {
|
||||
Log.e(TAG, "网络未连接");
|
||||
ToastUtil.show("网络未连接");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnected(NetworkUtils.NetworkType networkType) {
|
||||
mPresenter.getUserInfo();
|
||||
HTTPInterface.checkUpdate(this);
|
||||
Log.e(TAG, "网络已连接");
|
||||
ToastUtil.show("网络已连接");
|
||||
Log.e(TAG, "onConnected: wifi ssid = " + Utils.getWifiSSID(this));
|
||||
SPUtils.put(this, "wifi_last_connect_time", System.currentTimeMillis());
|
||||
mPresenter.checkUpdate();
|
||||
}
|
||||
|
||||
private interface Start {
|
||||
void onstar(long time);
|
||||
}
|
||||
|
||||
private Start start;
|
||||
|
||||
private final ObservableOnSubscribe<Long> subscribe = new ObservableOnSubscribe<Long>() {
|
||||
@Override
|
||||
public void subscribe(ObservableEmitter emitter) throws Exception {
|
||||
start = new Start() {
|
||||
@Override
|
||||
public void onstar(long time) {
|
||||
emitter.onNext(time);
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
private Observer<Long> timeObserver = new Observer<Long>() {
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(Long aLong) {
|
||||
Log.e("TimeObserver", "onNext: $aLong");
|
||||
startCommandTime = runningTime = SystemClock.elapsedRealtime();
|
||||
mPresenter.checkUpdate();
|
||||
mPresenter.initAmap();
|
||||
mPresenter.getUserInfo();
|
||||
HTTPInterface.sendAppUsed(MainService.this);
|
||||
HTTPInterface.sendRunningApp(MainService.this);
|
||||
HTTPInterface.getAPPinfo(MainService.this);
|
||||
startService();
|
||||
mPresenter.setAlias();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public IBinder onBind(Intent intent) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
lifecycleSubject.onNext(ActivityEvent.CREATE);
|
||||
JPushInterface.init(this);
|
||||
mPresenter = new MainPresenter(this);
|
||||
mPresenter.setProvider(this);
|
||||
mPresenter.attachView(this);
|
||||
NetworkUtils.registerNetworkStatusChangedListener(this);
|
||||
Observable.create(subscribe)
|
||||
.throttleFirst(60, TimeUnit.SECONDS)
|
||||
.subscribe(timeObserver);
|
||||
PackageManager packageManager = getPackageManager();
|
||||
try {
|
||||
// packageManager.setApplicationEnabledSetting("com.jiaoguanyi.appstore", PackageManager.COMPONENT_ENABLED_STATE_DISABLED, 0)
|
||||
// packageManager.setApplicationEnabledSetting("com.jiaoguanyi.store", PackageManager.COMPONENT_ENABLED_STATE_DISABLED, 0)
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "onCreate: " + e.getMessage());
|
||||
}
|
||||
ControlManager.getInstance().setDefaultUSBstate();
|
||||
mPresenter.setAlias();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
JPushInterface.init(this);
|
||||
if (MainActivity.isForeground) {
|
||||
Log.e(TAG, "onStartCommand: MainActivity: isForeground: " + MainActivity.isForeground);
|
||||
} else {
|
||||
JPushInterface.init(this);
|
||||
start.onstar(startCommandTime);
|
||||
Log.e(TAG, "onStartCommand: " + (SystemClock.elapsedRealtime() - startCommandTime) + "ms");
|
||||
}
|
||||
return START_STICKY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
lifecycleSubject.onNext(ActivityEvent.DESTROY);
|
||||
NetworkUtils.unregisterNetworkStatusChangedListener(this);
|
||||
mPresenter.detachView();
|
||||
}
|
||||
|
||||
private void startService() {
|
||||
startService(new Intent(this, GuardService.class));
|
||||
startService(new Intent(this, StepService.class));
|
||||
startService(new Intent(this, DownloadService.class));
|
||||
}
|
||||
|
||||
public static MainPresenter getPresenter() {
|
||||
return mPresenter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPowerUserList(String date) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkSNFinish(int code) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGankaoUID(String gankaoUID) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAvailableProduct(List<AvailableProduct> availableProductList, String gankaoUID) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void activeUserFinish(int code) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAlias() {
|
||||
setJpushAlias();
|
||||
Log.e(TAG, "setAlias: " + "finish");
|
||||
mPresenter.getBatch();
|
||||
}
|
||||
|
||||
private void setJpushAlias() {
|
||||
String alias = Utils.getSerial();
|
||||
TagAliasOperatorHelper.TagAliasBean tagAliasBean = new TagAliasOperatorHelper.TagAliasBean();
|
||||
tagAliasBean.action = ACTION_SET;
|
||||
TagAliasOperatorHelper.sequence++;
|
||||
tagAliasBean.alias = alias;
|
||||
tagAliasBean.isAliasAction = true;
|
||||
TagAliasOperatorHelper.getInstance().handleAction(this, TagAliasOperatorHelper.sequence, tagAliasBean);
|
||||
}
|
||||
|
||||
private void setTag(Set set) {
|
||||
TagAliasOperatorHelper.TagAliasBean tagAliasBean = new TagAliasOperatorHelper.TagAliasBean();
|
||||
tagAliasBean.action = ACTION_SET;
|
||||
TagAliasOperatorHelper.sequence++;
|
||||
tagAliasBean.tags = set;
|
||||
tagAliasBean.isAliasAction = false;
|
||||
TagAliasOperatorHelper.getInstance().handleAction(this, TagAliasOperatorHelper.sequence, tagAliasBean);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBatch(String batch) {
|
||||
HashSet hashSet = new HashSet();
|
||||
hashSet.add(batch);
|
||||
hashSet.removeIf(o -> TextUtils.isEmpty(o.toString()));
|
||||
if (hashSet.size() != 0) {
|
||||
setTag(hashSet);
|
||||
} else {
|
||||
Log.e(TAG, "setBatch: " + "hashSet size is 0");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setQRCode(Bitmap bitmap) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSnInfo(BaseResponse<UserInfo> response) {
|
||||
if (response != null) {
|
||||
int code = response.code;
|
||||
//设备已经绑定
|
||||
if (code == 200) {
|
||||
UserInfo userInfo = response.data;
|
||||
boolean username = Settings.System.putString(getContentResolver(), "UserInfo_username", userInfo.getSn_name());
|
||||
boolean gread = Settings.System.putString(getContentResolver(), "UserInfo_grade", userInfo.getGrade());
|
||||
SPUtils.put(this, "member_id", userInfo.getMember_id());
|
||||
SPUtils.put(this, "sn_id", userInfo.getId());
|
||||
if (!TextUtils.isEmpty(userInfo.getSn_name())) {
|
||||
SPUtils.put(this, "USERINFO_NAME", userInfo.getSn_name());
|
||||
}
|
||||
if (!TextUtils.isEmpty(userInfo.getSchool())) {
|
||||
SPUtils.put(this, "USERINFO_SCHOOL", userInfo.getSchool());
|
||||
}
|
||||
if (!TextUtils.isEmpty(userInfo.getGrade())) {
|
||||
SPUtils.put(this, "USERINFO_GRADE", userInfo.getGrade());
|
||||
}
|
||||
|
||||
mPresenter.getLocked();
|
||||
}
|
||||
//设备没有绑定
|
||||
else if (code == 300) {
|
||||
ControlManager.getInstance().setDisableSetting();
|
||||
}
|
||||
//没有授权的设备
|
||||
else if (code == 400) {
|
||||
ControlManager.getInstance().setDisableSetting();
|
||||
}
|
||||
}
|
||||
mPresenter.getSnUid();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSnUid(JSONObject jsonObject) {
|
||||
if (jsonObject != null) {
|
||||
String uid = jsonObject.getString("uid");
|
||||
if (!TextUtils.isEmpty(uid)) {
|
||||
Settings.System.putString(getContentResolver(), "gankaoUID", uid);
|
||||
}
|
||||
// String uid = jsonObject.getString("uid");
|
||||
// long activate_time = jsonObject.getLong("activate_time");
|
||||
// String card_info = jsonObject.getString("card_info");
|
||||
// SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
// Date d1 = new Date(activate_time * 1000);
|
||||
// int grade = jsonObject.getIntValue("grade");
|
||||
// SPUtils.put(MainService.this, "int_grade", grade);
|
||||
// String t1 = format.format(d1);
|
||||
} else {
|
||||
mPresenter.registerGankao();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGankao(String gankaoUID) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUserInfo() {
|
||||
mPresenter.getSnInfo();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLocked(int lockedStatus) {
|
||||
switch (lockedStatus) {
|
||||
case 0:
|
||||
ControlManager.getInstance().setDisableSetting();
|
||||
break;
|
||||
case 1:
|
||||
break;
|
||||
case 2:
|
||||
ControlManager.getInstance().setDisableSetting();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
mPresenter.checkUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLocationChanged() {
|
||||
HTTPInterface.updateAdminInfo(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkUpdateFinish() {
|
||||
mPresenter.getAllApp();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getAllAppFinish() {
|
||||
mPresenter.getAppInside();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAppInside() {
|
||||
mPresenter.getForceInstall();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setForceInstall() {
|
||||
mPresenter.getSystemSettings();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSystemSettings() {
|
||||
mPresenter.getBrowserLabel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBrowserLabel() {
|
||||
mPresenter.getBrowserWhiteList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBrowserWhiteList() {
|
||||
mPresenter.getAppStart();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAppStart() {
|
||||
mPresenter.getTimeControl();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTimeControl() {
|
||||
mPresenter.getScreenLock();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setScreenLock() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,6 @@ import android.content.IntentFilter;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.PixelFormat;
|
||||
import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
import android.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
@@ -24,27 +23,25 @@ import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.blankj.utilcode.util.NetworkUtils;
|
||||
import com.uiui.sn.R;
|
||||
import com.uiui.sn.bean.zuoye.BaseResponse;
|
||||
import com.uiui.sn.config.Configs;
|
||||
import com.uiui.sn.bean.BaseResponse;
|
||||
import com.uiui.sn.config.CommonConfig;
|
||||
import com.uiui.sn.manager.ControlManager;
|
||||
import com.uiui.sn.manager.NetInterfaceManager;
|
||||
import com.uiui.sn.network.HTTPInterface;
|
||||
import com.uiui.sn.network.NetInterfaceManager;
|
||||
import com.uiui.sn.receiver.APKinstallReceiver;
|
||||
import com.uiui.sn.receiver.BootReceiver;
|
||||
import com.uiui.sn.utils.JGYUtils;
|
||||
import com.uiui.sn.utils.SPUtils;
|
||||
import com.uiui.sn.utils.TimeUtils;
|
||||
import com.uiui.sn.utils.Utils;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
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 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;
|
||||
|
||||
|
||||
/**
|
||||
@@ -99,14 +96,10 @@ public class ManagerService extends Service implements NetworkUtils.OnNetworkSta
|
||||
@Override
|
||||
public void onNext(Long aLong) {
|
||||
Log.e("TimeObserver", "onNext: " + aLong);
|
||||
int isLogined = (int) SPUtils.get(ManagerService.this, Configs.isLogined, 2);
|
||||
if (isLogined == 2) return;
|
||||
Handler.getMain().postDelayed(() -> HTTPInterface.checkUpdate(ManagerService.this), 1234);
|
||||
Handler.getMain().postDelayed(() -> HTTPInterface.checkUpdate(ManagerService.this, JGYUtils.PACKAGE_APPSTORE), 2345);
|
||||
Handler.getMain().postDelayed(() -> HTTPInterface.checkUpdate(ManagerService.this, JGYUtils.PACKAGE_BROWSER), 3456);
|
||||
Handler.getMain().postDelayed(() -> HTTPInterface.checkUpdate(ManagerService.this, JGYUtils.PACKAGE_OS), 5678);
|
||||
Handler.getMain().postDelayed(() -> HTTPInterface.checkUpdate(ManagerService.this, JGYUtils.PACKAGE_VIDEOPLAYER), 6789);
|
||||
int isLogined = (int) SPUtils.get(ManagerService.this, CommonConfig.isLogined, 2);
|
||||
if (isLogined == 2) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -9,6 +9,7 @@ import android.util.Log;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.uiui.sn.IGetInfoInterface;
|
||||
import com.uiui.sn.service.main.MainService;
|
||||
import com.uiui.sn.utils.JGYUtils;
|
||||
import com.uiui.sn.utils.SPUtils;
|
||||
import com.uiui.sn.utils.Utils;
|
||||
@@ -47,12 +48,11 @@ public class RemoteService extends Service {
|
||||
|
||||
@Override
|
||||
public String getUserInfo() throws RemoteException {
|
||||
if (MainService.mPresenter != null) {
|
||||
MainService.mPresenter.getUserInfo();
|
||||
if (MainService.getPresenter() != null) {
|
||||
// MainService.getPresenter().getUserInfo();
|
||||
}
|
||||
String username = Settings.System.getString(getContentResolver(), "UserInfo_username");
|
||||
String avatar = Settings.System.getString(getContentResolver(), "UserInfo_avatar");
|
||||
// String gread = Settings.System.getString(getContentResolver(), "UserInfo_grade");
|
||||
int gread = (int) SPUtils.get(RemoteService.this, "int_grade", 0);
|
||||
String gankaoUID = Settings.System.getString(getContentResolver(), "gankaoUID");
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
|
||||
52
app/src/main/java/com/uiui/sn/service/main/MainSContact.java
Normal file
52
app/src/main/java/com/uiui/sn/service/main/MainSContact.java
Normal file
@@ -0,0 +1,52 @@
|
||||
package com.uiui.sn.service.main;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.uiui.sn.base.BasePresenter;
|
||||
import com.uiui.sn.base.BaseView;
|
||||
import com.uiui.sn.bean.BaseResponse;
|
||||
import com.uiui.sn.bean.SnInfo;
|
||||
|
||||
public class MainSContact {
|
||||
public interface MainView extends BaseView {
|
||||
void setSnInfo(BaseResponse<SnInfo> response);
|
||||
void setLocked(int lockedStatus);
|
||||
void checkUpdateFinish();
|
||||
void getAllAppFinish();
|
||||
void setAppInside();
|
||||
void setForceInstall();
|
||||
void setSystemSettings();
|
||||
void setBrowserLabel();
|
||||
void setBrowserWhiteList();
|
||||
void setAppStart();
|
||||
void setTimeControl();
|
||||
void setScreenLock();
|
||||
}
|
||||
|
||||
interface Presenter extends BasePresenter<MainView> {
|
||||
//获取设备信息
|
||||
void getSnInfo();
|
||||
//获取锁定状态
|
||||
void getLocked();
|
||||
//检查更新
|
||||
void checkUpdate();
|
||||
//获取所有app包名
|
||||
void getAllApp();
|
||||
//获取id管控
|
||||
void getAppInside();
|
||||
//获取强制下载
|
||||
void getForceInstall();
|
||||
//获取系统设置
|
||||
void getSystemSettings();
|
||||
//获取浏览器书签
|
||||
void getBrowserLabel();
|
||||
//获取浏览器黑白名单
|
||||
void getBrowserWhiteList();
|
||||
//应用自启
|
||||
void getAppStart();
|
||||
//获取时间管控
|
||||
void getTimeControl();
|
||||
//获取锁屏管控
|
||||
void getScreenLock();
|
||||
|
||||
}
|
||||
}
|
||||
571
app/src/main/java/com/uiui/sn/service/main/MainSPresenter.java
Normal file
571
app/src/main/java/com/uiui/sn/service/main/MainSPresenter.java
Normal file
@@ -0,0 +1,571 @@
|
||||
package com.uiui.sn.service.main;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.amap.api.location.AMapLocation;
|
||||
import com.amap.api.location.AMapLocationClient;
|
||||
import com.amap.api.location.AMapLocationListener;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.trello.rxlifecycle4.RxLifecycle;
|
||||
import com.trello.rxlifecycle4.android.ActivityEvent;
|
||||
import com.uiui.sn.bean.AppInfo;
|
||||
import com.uiui.sn.bean.AppStart;
|
||||
import com.uiui.sn.bean.BaseResponse;
|
||||
import com.uiui.sn.bean.Label;
|
||||
import com.uiui.sn.bean.UserAvatarInfo;
|
||||
import com.uiui.sn.bean.SnInfo;
|
||||
import com.uiui.sn.bean.browser.BrowserApiData;
|
||||
import com.uiui.sn.bean.browser.BrowserBean;
|
||||
import com.uiui.sn.config.CommonConfig;
|
||||
import com.uiui.sn.manager.AmapManager;
|
||||
import com.uiui.sn.manager.ControlManager;
|
||||
import com.uiui.sn.network.HTTPInterface;
|
||||
import com.uiui.sn.network.NetInterfaceManager;
|
||||
import com.uiui.sn.service.ManagerService;
|
||||
import com.uiui.sn.utils.ApkUtils;
|
||||
import com.uiui.sn.utils.JGYUtils;
|
||||
import com.uiui.sn.utils.SPUtils;
|
||||
import com.uiui.sn.utils.ServiceAliveUtils;
|
||||
import com.uiui.sn.utils.TimeUtils;
|
||||
import com.uiui.sn.utils.URLUtils;
|
||||
import com.uiui.sn.utils.Utils;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.rxjava3.core.Observer;
|
||||
import io.reactivex.rxjava3.disposables.Disposable;
|
||||
import io.reactivex.rxjava3.schedulers.Schedulers;
|
||||
import io.reactivex.rxjava3.subjects.BehaviorSubject;
|
||||
|
||||
import static com.uiui.sn.service.ManagerService.LOCK_STATE;
|
||||
|
||||
/**
|
||||
* @author jgy02
|
||||
*/
|
||||
public class MainSPresenter implements MainSContact.Presenter {
|
||||
private String TAG = MainSPresenter.class.getSimpleName();
|
||||
|
||||
private MainSContact.MainView mView;
|
||||
private Context mContext;
|
||||
|
||||
public MainSPresenter(Context context) {
|
||||
this.mContext = context;
|
||||
}
|
||||
|
||||
private BehaviorSubject<ActivityEvent> lifecycle;
|
||||
|
||||
public void setLifecycle(BehaviorSubject<ActivityEvent> lifecycle) {
|
||||
this.lifecycle = lifecycle;
|
||||
}
|
||||
|
||||
public BehaviorSubject<ActivityEvent> getLifecycle() {
|
||||
return lifecycle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void attachView(MainSContact.MainView view) {
|
||||
this.mView = view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detachView() {
|
||||
this.mView = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getSnInfo() {
|
||||
NetInterfaceManager.getInstance()
|
||||
.getSnInfo(lifecycle, new NetInterfaceManager.ObserverCallback() {
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(BaseResponse response) {
|
||||
mView.setSnInfo(response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getLocked() {
|
||||
int statu = (int) SPUtils.get(mContext, CommonConfig.isLogined, 0);
|
||||
mView.setLocked(statu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkUpdate() {
|
||||
mView.checkUpdateFinish();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressLint("NewApi")
|
||||
public void getAllApp() {
|
||||
NetInterfaceManager.getInstance()
|
||||
.getQueryAllAppControl()
|
||||
.compose(RxLifecycle.bindUntilEvent(lifecycle, ActivityEvent.DESTROY))
|
||||
.subscribe(new Observer<BaseResponse<List<AppInfo>>>() {
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
Log.e("getAllApp", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(BaseResponse<List<AppInfo>> listBaseResponse) {
|
||||
Log.e("getAllApp", "onNext: " + listBaseResponse);
|
||||
int code = listBaseResponse.code;
|
||||
if (code == 200) {
|
||||
List<AppInfo> appInfoList = listBaseResponse.data;
|
||||
if (appInfoList == null || appInfoList.size() == 0) {
|
||||
ApkUtils.writeAppPackageList(mContext, "Invalid");
|
||||
} else {
|
||||
HashSet allPkgSet = new HashSet<String>();
|
||||
for (AppInfo pkg : appInfoList) {
|
||||
allPkgSet.add(pkg.getApp_package());
|
||||
}
|
||||
String allPkgString = String.join(",", allPkgSet);
|
||||
Settings.System.putString(mContext.getContentResolver(), CommonConfig.ONLY_SHORTCUT_LIST, allPkgString);
|
||||
Log.e("getAllApp", "onNext: " + allPkgString);
|
||||
ApkUtils.writeAppPackageList(mContext, allPkgString);
|
||||
HTTPInterface.getAppStart(mContext, appInfoList);
|
||||
}
|
||||
JGYUtils.getInstance().deleteOtherApp();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
Log.e("getAllApp", "onError: " + e.getMessage());
|
||||
onComplete();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("getAllApp", "onComplete: ");
|
||||
mView.getAllAppFinish();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getAppInside() {
|
||||
NetInterfaceManager.getInstance()
|
||||
.getAppInsideControl()
|
||||
.compose(RxLifecycle.bindUntilEvent(lifecycle, ActivityEvent.DESTROY))
|
||||
.subscribe(new Observer<BaseResponse>() {
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
Log.e("getAppInside", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(BaseResponse baseResponse) {
|
||||
String jsonString = JSON.toJSONString(baseResponse.data);
|
||||
Log.e("getAppInside", "onNext: " + jsonString);
|
||||
if (baseResponse.code == 200) {
|
||||
JSONObject jsonObject = JSON.parseObject(jsonString);
|
||||
String ids = jsonObject.getString("ids");
|
||||
String packages = jsonObject.getString("package");
|
||||
JGYUtils.getInstance().writeDeselectIDtoSystem(ids, packages);
|
||||
} else {
|
||||
Log.e("getAppInside", "onNext: " + baseResponse.msg);
|
||||
JGYUtils.putString(mContext.getContentResolver(), "qch_app_forbid_id", " ");
|
||||
JGYUtils.putString(mContext.getContentResolver(), "DeselectViewArray", " ");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
Log.e("getAppInside", "onError: " + e.getMessage());
|
||||
onComplete();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("getAppInside", "onComplete: ");
|
||||
mView.setAppInside();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getForceInstall() {
|
||||
NetInterfaceManager.getInstance()
|
||||
.getForceInstallControl()
|
||||
.compose(RxLifecycle.bindUntilEvent(lifecycle, ActivityEvent.DESTROY))
|
||||
.subscribe(new Observer<BaseResponse<List<AppInfo>>>() {
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
Log.e("getForceInstall", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(BaseResponse<List<AppInfo>> listBaseResponse) {
|
||||
Log.e("getForceInstall", "onNext: " + listBaseResponse);
|
||||
int code = listBaseResponse.code;
|
||||
if (code == 200) {
|
||||
List<AppInfo> appInfos = listBaseResponse.data;
|
||||
if (null != appInfos && appInfos.size() != 0) {
|
||||
HTTPInterface.getForceInstallState(mContext, appInfos);
|
||||
}
|
||||
} else {
|
||||
boolean qch_force_app = JGYUtils.putString(mContext.getContentResolver(), "qch_force_app", "invalid");
|
||||
Log.e("getForceInstall", "qch_force_app: invalid: " + qch_force_app);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
Log.e("getForceInstall", "onError: ");
|
||||
onComplete();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("getForceInstall", "onComplete: ");
|
||||
mView.setForceInstall();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getSystemSettings() {
|
||||
NetInterfaceManager.getInstance()
|
||||
.getsettingControl()
|
||||
.compose(RxLifecycle.bindUntilEvent(lifecycle, ActivityEvent.DESTROY))
|
||||
.subscribe(new Observer<BaseResponse>() {
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
Log.e("getSystemSettings", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(BaseResponse systemSettingsBaseResponse) {
|
||||
Log.e("getSystemSettings", "onNext: ");
|
||||
SPUtils.put(mContext, "is_first_connection", 0);
|
||||
int code = systemSettingsBaseResponse.code;
|
||||
if (code == 200) {
|
||||
String data = new Gson().toJson(systemSettingsBaseResponse.data);
|
||||
Log.e("getSystemSettings", "onNext: " + data);
|
||||
ControlManager.getInstance().setSystemSetting(data);
|
||||
} else {
|
||||
ControlManager.getInstance().setDisableSetting();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
if ((int) SPUtils.get(mContext, "is_first_connection", 1) == 1) {
|
||||
ControlManager.getInstance().setDisableSetting();
|
||||
}
|
||||
Log.e("getSystemSettings", "onError: " + e.getMessage());
|
||||
onComplete();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("getSystemSettings", "onComplete: ");
|
||||
mView.setSystemSettings();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getBrowserLabel() {
|
||||
NetInterfaceManager.getInstance().getLabelControl()
|
||||
.compose(RxLifecycle.bindUntilEvent(lifecycle, ActivityEvent.DESTROY))
|
||||
.subscribe(new Observer<BaseResponse<Label>>() {
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
Log.e("getBrowserLabel", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(BaseResponse<Label> labelBaseResponse) {
|
||||
Log.e("getBrowserLabel", "onNext: " + labelBaseResponse);
|
||||
if (labelBaseResponse.code == 200) {
|
||||
String home_page = labelBaseResponse.data.getHome_page();
|
||||
JGYUtils.putString(mContext.getContentResolver(), "homepagURL", home_page);
|
||||
//主页
|
||||
Intent homepag = new Intent("qch_app_brower_homepage");
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
homepag.setPackage("com.android.settings")
|
||||
.setPackage("com.android.browser");
|
||||
}
|
||||
if (!TextUtils.isEmpty(home_page)) {
|
||||
homepag.putExtra("homepage", home_page);
|
||||
} else {
|
||||
homepag.putExtra("homepage", "Invalid");
|
||||
}
|
||||
mContext.sendBroadcast(homepag);
|
||||
|
||||
//书签
|
||||
String label_page = labelBaseResponse.data.getLabel_page();
|
||||
Intent websiteBookMark = new Intent("qch_app_brower_website");
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
websiteBookMark.setPackage("com.android.settings")
|
||||
.setPackage("com.android.browser");
|
||||
}
|
||||
if (!TextUtils.isEmpty(label_page)) {
|
||||
websiteBookMark.putExtra("websiteBookMark", label_page);
|
||||
} else {
|
||||
websiteBookMark.putExtra("websiteBookMark", "Invalid");
|
||||
}
|
||||
mContext.sendBroadcast(websiteBookMark);
|
||||
} else {
|
||||
Intent intent1 = new Intent("qch_app_brower_homepage");
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
intent1.setPackage("com.android.settings")
|
||||
.setPackage("com.android.browser");
|
||||
}
|
||||
intent1.putExtra("homepage", "Invalid");
|
||||
mContext.sendBroadcast(intent1);
|
||||
Intent intent2 = new Intent("qch_app_brower_website");
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
intent2.setPackage("com.android.settings")
|
||||
.setPackage("com.android.browser");
|
||||
}
|
||||
intent2.putExtra("websiteBookMark", "Invalid");
|
||||
mContext.sendBroadcast(intent2);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
Log.e("getBrowserLabel", "onError: " + e.getMessage());
|
||||
onComplete();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("getBrowserLabel", "onComplete: ");
|
||||
mView.setBrowserLabel();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 浏览器黑白名单
|
||||
*/
|
||||
@Override
|
||||
public void getBrowserWhiteList() {
|
||||
NetInterfaceManager.getInstance().getBrowserControl()
|
||||
.compose(RxLifecycle.bindUntilEvent(lifecycle, ActivityEvent.DESTROY))
|
||||
.subscribe(new Observer<BaseResponse<BrowserApiData>>() {
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
Log.e("getBrowserWhiteList", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(BaseResponse<BrowserApiData> response) {
|
||||
Log.e("getBrowserWhiteList", "onNext: " + response);
|
||||
if (response.code == 200) {
|
||||
//白名单
|
||||
List<BrowserBean> white = response.data.getWhiteList();
|
||||
if (null != white && white.size() != 0) {
|
||||
boolean whiteList = JGYUtils.putString(mContext.getContentResolver(), "DeselectBrowserArray",
|
||||
white.stream().map(BrowserBean::getAddress).collect(Collectors.joining(",")));
|
||||
Log.e("getBrowserWhiteList", "setBrowserList_white:" + white + ":" + whiteList);
|
||||
} else {
|
||||
JGYUtils.putString(mContext.getContentResolver(), "DeselectBrowserArray", " ");
|
||||
}
|
||||
//黑名单
|
||||
List<BrowserBean> black = response.data.getBlackList();
|
||||
if (null != black && black.size() != 0) {
|
||||
boolean blackList = JGYUtils.putString(mContext.getContentResolver(), "qch_webblack_url",
|
||||
black.stream().map(BrowserBean::getAddress).collect(Collectors.joining(",")));
|
||||
Log.e("getBrowserWhiteList", "setBrowserList_black:" + black + ":" + blackList);
|
||||
} else {
|
||||
JGYUtils.putString(mContext.getContentResolver(), "qch_webblack_url", " ");
|
||||
}
|
||||
} else {
|
||||
JGYUtils.putString(mContext.getContentResolver(), "DeselectBrowserArray", " ");
|
||||
JGYUtils.putString(mContext.getContentResolver(), "qch_webblack_url", " ");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
Log.e("getBrowserWhiteList", "onError: " + e.getMessage());
|
||||
onComplete();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
new URLUtils(mContext).setBrowserList();
|
||||
mView.setBrowserWhiteList();
|
||||
Log.e("getBrowserWhiteList", "onComplete: ");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getAppStart() {
|
||||
NetInterfaceManager.getInstance()
|
||||
.getAppStartControl()
|
||||
.compose(RxLifecycle.bindUntilEvent(lifecycle, ActivityEvent.DESTROY))
|
||||
.subscribe(new Observer<BaseResponse<List<AppStart>>>() {
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
Log.e("getAppStart", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(BaseResponse<List<AppStart>> listBaseResponse) {
|
||||
Log.e("getAppStart", "onNext: ");
|
||||
int code = listBaseResponse.code;
|
||||
if (code == 200) {
|
||||
List<AppStart> list = listBaseResponse.data;
|
||||
HTTPInterface.setAppState(mContext, list);
|
||||
} else {
|
||||
HTTPInterface.setInvalid(mContext);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
Log.e("getAppStart", "onError: " + e.getMessage());
|
||||
onComplete();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("getAppStart", "onComplete: ");
|
||||
mView.setAppStart();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getTimeControl() {
|
||||
NetInterfaceManager.getInstance()
|
||||
.getTimeControl()
|
||||
.compose(RxLifecycle.bindUntilEvent(lifecycle, ActivityEvent.DESTROY))
|
||||
.subscribe(new Observer<BaseResponse>() {
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
Log.e("getTimeControl", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(BaseResponse baseResponse) {
|
||||
Log.e("getTimeControl", "onNext: ");
|
||||
int code = baseResponse.code;
|
||||
if (code == 200) {
|
||||
JSONObject jsonObject = (JSONObject) JSON.toJSON(baseResponse.data);
|
||||
JSONObject work = jsonObject.getJSONObject("work");
|
||||
String work_start_time = work.getString("start_time");
|
||||
String work_end_time = work.getString("end_time");
|
||||
JSONObject rest = jsonObject.getJSONObject("rest");
|
||||
String rest_start_time = rest.getString("start_time");
|
||||
String rest_end_time = rest.getString("end_time");
|
||||
TimeUtils.ContralTime workingTime = TimeUtils.String2WorkingTime(mContext, work_start_time + "-" + work_end_time);
|
||||
TimeUtils.ContralTime weekTime = TimeUtils.String2WeekTime(mContext, rest_start_time + "-" + rest_end_time);
|
||||
if (null != workingTime) {
|
||||
Log.e("getTimeControl", "200:" + workingTime.toString());
|
||||
}
|
||||
if (null != weekTime) {
|
||||
Log.e("getTimeControl", "200:" + weekTime.toString());
|
||||
}
|
||||
} else {
|
||||
TimeUtils.setEmpty(mContext);
|
||||
TimeUtils.ContralTime workingTime = TimeUtils.getWorkingDayContralTime(mContext);
|
||||
if (null != workingTime) {
|
||||
Log.e("getTimeControl", workingTime.toString());
|
||||
}
|
||||
TimeUtils.ContralTime weekTime = TimeUtils.getWeekDayContralTime(mContext);
|
||||
if (null != weekTime) {
|
||||
Log.e("getTimeControl", weekTime.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
Log.e("getTimeControl", "onError: " + e.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("getTimeControl", "onComplete: ");
|
||||
Intent intent = new Intent();
|
||||
intent.setAction(ManagerService.ACTION_UPDATE);
|
||||
mContext.sendBroadcast(intent);
|
||||
mView.setTimeControl();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getScreenLock() {
|
||||
NetInterfaceManager.getInstance()
|
||||
.getScreenLockControl()
|
||||
.getScreenshot(Utils.getSerial())
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.compose(RxLifecycle.bindUntilEvent(lifecycle, ActivityEvent.DESTROY))
|
||||
.subscribe(new Observer<BaseResponse>() {
|
||||
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
Log.e("getScreenLock", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(BaseResponse baseResponse) {
|
||||
Log.e("getScreenLock", "onNext: " + baseResponse);
|
||||
int code = baseResponse.code;
|
||||
if (code == 200) {
|
||||
JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(baseResponse.data));
|
||||
int is_screen_lock = jsonObject.getIntValue("is_screen_lock");
|
||||
if (!ServiceAliveUtils.isServiceAlice(mContext, ManagerService.class.getName())) {
|
||||
mContext.startService(new Intent(mContext, ManagerService.class));
|
||||
}
|
||||
SPUtils.put(mContext, LOCK_STATE, is_screen_lock);
|
||||
Intent intent = new Intent();
|
||||
// intent.putExtra("name", name);
|
||||
if (1 == is_screen_lock) {
|
||||
intent.setAction(ManagerService.ACTION_LOCK);
|
||||
} else if (0 == is_screen_lock) {
|
||||
intent.setAction(ManagerService.ACTION_UNLOCK);
|
||||
}
|
||||
mContext.sendBroadcast(intent);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
Log.e("getScreenLock", "onError: " + e.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("getScreenLock", "onComplete: ");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
451
app/src/main/java/com/uiui/sn/service/main/MainService.java
Normal file
451
app/src/main/java/com/uiui/sn/service/main/MainService.java
Normal file
@@ -0,0 +1,451 @@
|
||||
package com.uiui.sn.service.main;
|
||||
|
||||
import android.app.AlarmManager;
|
||||
import android.app.Service;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.IBinder;
|
||||
import android.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.blankj.utilcode.util.NetworkUtils;
|
||||
import com.tencent.android.tpush.XGIOperateCallback;
|
||||
import com.tencent.android.tpush.XGPushConfig;
|
||||
import com.tencent.android.tpush.XGPushManager;
|
||||
import com.tencent.mmkv.MMKV;
|
||||
import com.trello.rxlifecycle4.LifecycleProvider;
|
||||
import com.trello.rxlifecycle4.LifecycleTransformer;
|
||||
import com.trello.rxlifecycle4.RxLifecycle;
|
||||
import com.trello.rxlifecycle4.android.ActivityEvent;
|
||||
import com.trello.rxlifecycle4.android.RxLifecycleAndroid;
|
||||
import com.uiui.sn.BuildConfig;
|
||||
import com.uiui.sn.bean.BaseResponse;
|
||||
import com.uiui.sn.bean.SnInfo;
|
||||
import com.uiui.sn.config.CommonConfig;
|
||||
import com.uiui.sn.manager.ConnectManager;
|
||||
import com.uiui.sn.manager.ControlManager;
|
||||
import com.uiui.sn.network.NetInterfaceManager;
|
||||
import com.uiui.sn.rlog.LogDBManager;
|
||||
import com.uiui.sn.service.DownloadService;
|
||||
import com.uiui.sn.service.GuardService;
|
||||
import com.uiui.sn.service.StepService;
|
||||
import com.uiui.sn.utils.CacheUtils;
|
||||
import com.uiui.sn.utils.SPUtils;
|
||||
import com.uiui.sn.utils.TimeUtils;
|
||||
import com.uiui.sn.utils.ToastUtil;
|
||||
import com.uiui.sn.utils.Utils;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import cn.jpush.android.api.JPushInterface;
|
||||
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.subjects.BehaviorSubject;
|
||||
|
||||
/**
|
||||
* @author jgy02
|
||||
*/
|
||||
public class MainService extends Service implements MainSContact.MainView, NetworkUtils.OnNetworkStatusChangedListener, LifecycleProvider<ActivityEvent> {
|
||||
private String TAG = MainService.class.getSimpleName();
|
||||
public static MainSPresenter mPresenter;
|
||||
private MMKV mMMKV = MMKV.defaultMMKV();
|
||||
|
||||
private final BehaviorSubject<ActivityEvent> lifecycleSubject = BehaviorSubject.create();
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Observable<ActivityEvent> lifecycle() {
|
||||
return lifecycleSubject.hide();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public <T> LifecycleTransformer<T> bindUntilEvent(@NotNull ActivityEvent event) {
|
||||
return RxLifecycle.bindUntilEvent(lifecycleSubject, event);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public <T> LifecycleTransformer<T> bindToLifecycle() {
|
||||
return RxLifecycleAndroid.bindActivity(lifecycleSubject);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisconnected() {
|
||||
Log.e(TAG, "网络未连接");
|
||||
ToastUtil.show("网络未连接");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnected(NetworkUtils.NetworkType networkType) {
|
||||
ToastUtil.show("网络已连接");
|
||||
String WiFiAlias = Utils.getWifiAlias(this);
|
||||
Log.e("OnNetworkStatusChanged", "onConnected: " + WiFiAlias);
|
||||
Utils.getPublicIP(this);
|
||||
if (ConnectManager.getInstance().isWiFiFistConnect()) {
|
||||
start.onstar(ConnectManager.WIFI_LAST_CONNECT_TIME);
|
||||
} else {
|
||||
if (ConnectManager.getInstance().isWiFiCutoverFistConnect(WiFiAlias)) {
|
||||
start.onstar(WiFiAlias);
|
||||
}
|
||||
}
|
||||
|
||||
TimeTask task = new TimeTask();
|
||||
task.execute("ntp.aliyun.com");
|
||||
}
|
||||
|
||||
private class TimeTask extends AsyncTask<String, Long, Long> {
|
||||
@Override
|
||||
protected Long doInBackground(String... strings) {
|
||||
return TimeUtils.getTimeFromNtpServer(strings[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Long aLong) {
|
||||
super.onPostExecute(aLong);
|
||||
AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
|
||||
am.setTime(aLong);
|
||||
tPushInit();
|
||||
NetInterfaceManager.getInstance().setPushTags(lifecycleSubject, new NetInterfaceManager.ObserverCallback() {
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
Log.e("TimeTask", "onSubscribe: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(BaseResponse response) {
|
||||
Log.e("TimeTask", "onNext: ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
Log.e("TimeTask", "onError: " + e.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
Log.e("TimeTask", "onComplete: ");
|
||||
}
|
||||
});
|
||||
Log.e(TAG, "getTimeFromNtpServer: " + aLong);
|
||||
}
|
||||
}
|
||||
|
||||
private void tPushInit() {
|
||||
XGPushConfig.enableDebug(this, true);
|
||||
XGPushManager.registerPush(this, new XGIOperateCallback() {
|
||||
@Override
|
||||
public void onSuccess(Object data, int flag) {
|
||||
//token在设备卸载重装的时候有可能会变
|
||||
Log.e("TPush", "注册成功,设备token为:" + data);
|
||||
List<XGPushManager.AccountInfo> accountInfoList = new ArrayList<>();
|
||||
accountInfoList.add(new XGPushManager.AccountInfo(XGPushManager.AccountType.CUSTOM.getValue(), Utils.getSerial()));
|
||||
XGPushManager.upsertAccounts(MainService.this, accountInfoList, new XGIOperateCallback() {
|
||||
@Override
|
||||
public void onSuccess(Object data, int flag) {
|
||||
Log.e("TPush", "onSuccess, data:" + data + ", flag:" + flag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFail(Object data, int errCode, String msg) {
|
||||
Log.e("TPush", "onFail, data:" + data + ", code:" + errCode + ", msg:" + msg);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFail(Object data, int errCode, String msg) {
|
||||
Log.e("TPush", "注册失败,错误码:" + errCode + ",错误信息:" + msg);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private WifiReceiver mWifiReceiver;
|
||||
|
||||
private void registerWiFiReceiver() {
|
||||
if (mWifiReceiver == null) {
|
||||
mWifiReceiver = new WifiReceiver();
|
||||
}
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
|
||||
filter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
|
||||
filter.addAction(WifiManager.RSSI_CHANGED_ACTION);
|
||||
filter.addAction(WifiManager.NETWORK_IDS_CHANGED_ACTION);
|
||||
filter.addAction(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION);
|
||||
filter.addAction(WifiManager.CONFIGURED_NETWORKS_CHANGED_ACTION);
|
||||
filter.addAction(WifiManager.LINK_CONFIGURATION_CHANGED_ACTION);
|
||||
filter.addAction(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION);
|
||||
filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
|
||||
registerReceiver(mWifiReceiver, filter);
|
||||
}
|
||||
|
||||
public class WifiReceiver extends BroadcastReceiver {
|
||||
private static final String TAG = "wifiReceiver";
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
switch (intent.getAction()) {
|
||||
case WifiManager.RSSI_CHANGED_ACTION:
|
||||
Log.e(TAG, "wifi信号强度变化");
|
||||
break;
|
||||
//wifi连接上与否
|
||||
case WifiManager.NETWORK_STATE_CHANGED_ACTION:
|
||||
NetworkInfo info = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
|
||||
if (info.getState().equals(NetworkInfo.State.DISCONNECTED)) {
|
||||
Log.e(TAG, "wifi断开");
|
||||
LogDBManager.getInstance().creatNetChangeLog("wifi断开", TimeUtils.transferLongToDate(System.currentTimeMillis()));
|
||||
} else if (info.getState().equals(NetworkInfo.State.CONNECTED)) {
|
||||
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
|
||||
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
|
||||
//获取当前wifi名称
|
||||
String oldSSID = mMMKV.decodeString("WiFiSSID", "");
|
||||
Log.e(TAG, "oldSSID " + oldSSID);
|
||||
String newSSID = wifiInfo.getSSID();
|
||||
Log.e(TAG, "连接到网络 " + newSSID);
|
||||
if (!oldSSID.equals(newSSID)) {
|
||||
LogDBManager.getInstance().creatNetChangeLog("", oldSSID + " change to: " + newSSID);
|
||||
//直接获取数据
|
||||
if (ConnectManager.getInstance().isWiFiCutoverFistConnect(newSSID)) {
|
||||
start.onstar(newSSID);
|
||||
}
|
||||
} else {
|
||||
LogDBManager.getInstance().creatNetChangeLog("接入WiFi",
|
||||
"connect to: " + newSSID + " time: "
|
||||
+ TimeUtils.transferLongToDate(System.currentTimeMillis()));
|
||||
}
|
||||
mMMKV.encode("WiFiSSID", Utils.getWifiAlias(context));
|
||||
}
|
||||
break;
|
||||
//wifi打开与否
|
||||
case WifiManager.WIFI_STATE_CHANGED_ACTION:
|
||||
int wifistate = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, WifiManager.WIFI_STATE_DISABLED);
|
||||
if (wifistate == WifiManager.WIFI_STATE_DISABLED) {
|
||||
Log.e(TAG, "系统关闭wifi");
|
||||
} else if (wifistate == WifiManager.WIFI_STATE_ENABLED) {
|
||||
Log.e(TAG, "系统开启wifi");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private interface Start {
|
||||
void onstar(String key);
|
||||
}
|
||||
|
||||
private Start start;
|
||||
|
||||
private ObservableOnSubscribe<String> subscribe = new ObservableOnSubscribe<String>() {
|
||||
@Override
|
||||
public void subscribe(ObservableEmitter<String> emitter) throws Exception {
|
||||
start = emitter::onNext;
|
||||
}
|
||||
};
|
||||
|
||||
private Observer<String> timeObserver = new Observer<String>() {
|
||||
@Override
|
||||
public void onSubscribe(Disposable d) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNext(String string) {
|
||||
Log.e("TimeObserver", "onNext: " + string);
|
||||
mPresenter.getSnInfo();
|
||||
startService();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete() {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
public static MainSPresenter getPresenter() {
|
||||
return mPresenter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBinder onBind(Intent intent) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
lifecycleSubject.onNext(ActivityEvent.CREATE);
|
||||
mPresenter = new MainSPresenter(this);
|
||||
mPresenter.setLifecycle(lifecycleSubject);
|
||||
mPresenter.attachView(this);
|
||||
|
||||
TimeTask task = new TimeTask();
|
||||
task.execute("ntp.aliyun.com");
|
||||
|
||||
try {
|
||||
getPackageManager().setApplicationEnabledSetting("com.android.email", PackageManager.COMPONENT_ENABLED_STATE_DISABLED, 0);
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "onCreate: " + e.getMessage());
|
||||
}
|
||||
|
||||
Observable.create(subscribe)
|
||||
.throttleFirst(1, TimeUnit.MINUTES)
|
||||
.subscribe(timeObserver);
|
||||
|
||||
if ((int) SPUtils.get(this, CommonConfig.JGY_FIRST_CONNECT, 0) == 0) {
|
||||
// TODO: 2021/5/26 待底层修改,临时解决办法
|
||||
Log.e(TAG, "onCreate: " + "Disable All Settings");
|
||||
start.onstar(ConnectManager.REBOOT_LAST_ONNECT_TIME);
|
||||
}
|
||||
int oldVersionCode = (int) SPUtils.get(this, CommonConfig.SN_VERSIONCODE, 0);
|
||||
if (oldVersionCode < BuildConfig.VERSION_CODE) {
|
||||
Log.e(TAG, "onCreate: " + "upgrade successful");
|
||||
try {
|
||||
new CacheUtils().cleanApplicationUserData(this, "com.aoleyun.os");
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "onReceive: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
// if (ConnectManager.getInstance().isRebootFistConnect()) {
|
||||
start.onstar(ConnectManager.REBOOT_LAST_ONNECT_TIME);
|
||||
// }
|
||||
}
|
||||
SPUtils.put(this, CommonConfig.SN_VERSIONCODE, BuildConfig.VERSION_CODE);
|
||||
registerReceivers();
|
||||
NetworkUtils.registerNetworkStatusChangedListener(this);
|
||||
ControlManager.getInstance().setDefaultUSBstate();
|
||||
JPushInterface.init(this);
|
||||
}
|
||||
|
||||
private void registerReceivers() {
|
||||
registerWiFiReceiver();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
Log.e(TAG, "onStartCommand: " + System.currentTimeMillis());
|
||||
return START_STICKY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
lifecycleSubject.onNext(ActivityEvent.DESTROY);
|
||||
NetworkUtils.unregisterNetworkStatusChangedListener(this);
|
||||
mPresenter.detachView();
|
||||
}
|
||||
|
||||
private void startService() {
|
||||
startService(new Intent(this, GuardService.class));
|
||||
startService(new Intent(this, StepService.class));
|
||||
startService(new Intent(this, DownloadService.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSnInfo(BaseResponse<SnInfo> response) {
|
||||
if (response != null) {
|
||||
int code = response.code;
|
||||
//设备已经绑定
|
||||
if (code == 200) {
|
||||
mPresenter.getLocked();
|
||||
}
|
||||
//设备没有绑定
|
||||
else if (code == 300) {
|
||||
ControlManager.getInstance().setDisableSetting();
|
||||
}
|
||||
//没有授权的设备
|
||||
else if (code == 400) {
|
||||
ControlManager.getInstance().setDisableSetting();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLocked(int lockedStatus) {
|
||||
switch (lockedStatus) {
|
||||
case 0:
|
||||
ControlManager.getInstance().setDisableSetting();
|
||||
break;
|
||||
case 1:
|
||||
break;
|
||||
case 2:
|
||||
ControlManager.getInstance().setDisableSetting();
|
||||
break;
|
||||
default:
|
||||
}
|
||||
mPresenter.checkUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkUpdateFinish() {
|
||||
mPresenter.getAllApp();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getAllAppFinish() {
|
||||
mPresenter.getAppInside();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAppInside() {
|
||||
mPresenter.getForceInstall();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setForceInstall() {
|
||||
mPresenter.getSystemSettings();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSystemSettings() {
|
||||
mPresenter.getBrowserLabel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBrowserLabel() {
|
||||
mPresenter.getBrowserWhiteList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBrowserWhiteList() {
|
||||
mPresenter.getAppStart();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAppStart() {
|
||||
mPresenter.getTimeControl();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTimeControl() {
|
||||
mPresenter.getScreenLock();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setScreenLock() {
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user