version:1.4

update:2021-10-21 10:14:40
fix:
add:增加浏览器桌面检测升级,修复重复请求
This commit is contained in:
2021-12-03 14:33:03 +08:00
parent 768519e14e
commit 34fa9fcdb7
70 changed files with 3189 additions and 1503 deletions

View File

@@ -35,7 +35,6 @@ import com.aoleyun.sn.network.api.newapi.GetLockStateApi;
import com.aoleyun.sn.receiver.BootReceiver;
import com.aoleyun.sn.receiver.NewAppReceiver;
import com.aoleyun.sn.utils.JGYUtils;
import com.aoleyun.sn.utils.Logutils;
import com.aoleyun.sn.utils.SPUtils;
import com.aoleyun.sn.utils.XAPKUtils;
import com.aoleyun.sn.KeepAliveConnection;
@@ -75,7 +74,7 @@ public class GuardService extends Service {
private ServiceConnection mServiceConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
Logutils.w(TAG, "GuardService:建立链接");
Log.w(TAG, "GuardService:建立链接");
boolean isServiceRunning = ServiceAliveUtils.isServiceAlive(GuardService.this, StepService.class.getName());
if (!isServiceRunning) {
startService(new Intent(GuardService.this, StepService.class));
@@ -119,7 +118,7 @@ public class GuardService extends Service {
@Override
public void onNext(Long aLong) {
Logutils.e(TAG, "timeObserver: onNext: " + aLong);
Log.e(TAG, "timeObserver: onNext: " + aLong);
startService(new Intent(GuardService.this, MainService.class));
}
@@ -151,7 +150,7 @@ public class GuardService extends Service {
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Logutils.e(TAG, "onStartCommand: ");
Log.e(TAG, "onStartCommand: ");
Aria.init(this);
Aria.download(this).register();
// 绑定建立链接
@@ -197,8 +196,12 @@ public class GuardService extends Service {
filter.addAction(Intent.ACTION_SCREEN_ON);
filter.addAction(Intent.ACTION_SCREEN_OFF);
filter.addAction(Intent.ACTION_USER_UNLOCKED);
filter.addAction("android.intent.action.FACTORY_RESET");
filter.addAction("android.intent.action.MASTER_CLEAR");
filter.addAction(Intent.ACTION_FACTORY_RESET);
filter.addAction(Intent.ACTION_MASTER_CLEAR);
filter.addAction(Intent.ACTION_MASTER_CLEAR_NOTIFICATION);
filter.addAction("android.intent.action.FORCE_FACTORY_RESET");
filter.addAction(Intent.ACTION_SHUTDOWN);
filter.addAction(Intent.ACTION_REBOOT);
registerReceiver(presentReceiver, filter);
}
@@ -206,7 +209,7 @@ public class GuardService extends Service {
@Override
public void onReceive(final Context context, Intent intent) {
String action = intent.getAction();
Logutils.e(TAG, "action:" + action);
Log.e(TAG, "action:" + action);
switch (action) {
default:
break;
@@ -267,18 +270,50 @@ public class GuardService extends Service {
sendScreenStatus(2);
}
break;
case "android.intent.action.FACTORY_RESET":
case "android.intent.action.MASTER_CLEAR":
case "android.intent.action.MASTER_CLEAR_NOTIFICATION":
case Intent.ACTION_SHUTDOWN:
case Intent.ACTION_REBOOT:
int restart_count = (int) SPUtils.get(context, "restart_count", 0);
SPUtils.put(context, "restart_count", restart_count + 1);
// android.os.Process.killProcess(android.os.Process.myPid());
break;
case Intent.ACTION_FACTORY_RESET:
case Intent.ACTION_MASTER_CLEAR:
case Intent.ACTION_MASTER_CLEAR_NOTIFICATION:
case "android.intent.action.FORCE_FACTORY_RESET":
Logutils.e("PresentReceiver", "MASTER_CLEAR");
android.os.Process.killProcess(android.os.Process.myPid());
System.exit(0);
sendRestoreTimes();
Log.e("PresentReceiver", "MASTER_CLEAR");
// android.os.Process.killProcess(android.os.Process.myPid());
// System.exit(0);
break;
}
}
}
private void sendRestoreTimes() {
NetInterfaceManager.getInstance().getRestoreTimesApi()
.subscribe(new Observer<BaseResponse>() {
@Override
public void onSubscribe(Disposable d) {
Log.e("sendRestoreTimes", "onSubscribe: ");
}
@Override
public void onNext(BaseResponse baseResponse) {
Log.e("sendRestoreTimes", "onNext: ");
}
@Override
public void onError(Throwable e) {
Log.e("sendRestoreTimes", "onError: " + e.getMessage());
}
@Override
public void onComplete() {
Log.e("sendRestoreTimes", "onComplete: ");
}
});
}
private void sendScreenStatus(int status) {
Retrofit retrofit = new Retrofit.Builder()
.client(NetInterfaceManager.getInstance().getOkHttpClient())
@@ -378,7 +413,7 @@ public class GuardService extends Service {
// 最大电量
int scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, 0);
int elec = (level * 100) / scale;
// Logutils.e(TAG, "electricity:=" + elec + "%");
// Log.e(TAG, "electricity:=" + elec + "%");
if (elec == 50) {
start.onstar(SystemClock.elapsedRealtime());
}
@@ -388,7 +423,7 @@ public class GuardService extends Service {
|| Intent.ACTION_BATTERY_OKAY.equals(action)
) {
setDefaultUSBStatus();
Logutils.e(TAG, action);
Log.e(TAG, action);
start.onstar(SystemClock.elapsedRealtime());
}
}
@@ -396,7 +431,7 @@ public class GuardService extends Service {
private void setDefaultUSBStatus() {
String setting_usb = Settings.System.getString(getContentResolver(), "qch_usb_choose");
Logutils.e("setDefaultUSBStatus", "setting_usb---------" + setting_usb);
Log.e("setDefaultUSBStatus", "setting_usb---------" + setting_usb);
String usbStatus = "";
if (TextUtils.isEmpty(setting_usb)) {
usbStatus = "qch_action_usb_usb_charge";
@@ -425,7 +460,7 @@ public class GuardService extends Service {
JSONObject jsonObject = JSON.parseObject(task.getExtendField());
String app_name = jsonObject.getString("app_name");
String app_package = jsonObject.getString("app_package");
Logutils.e("aria", "正在下载:" + task.getPercent() + ":" + task.getExtendField());
Log.e("aria", "正在下载:" + task.getPercent() + ":" + task.getExtendField());
ToastUtil.show("正在下载:" + app_name + "-" + task.getPercent() + "%" + "\t" + Formatter.formatFileSize(GuardService.this, task.getSpeed()) + "/s");
}
@@ -434,8 +469,8 @@ public class GuardService extends Service {
//在这里处理任务完成的状态
String filepath = task.getFilePath();
String extendField = task.getExtendField();
Logutils.e("taskComplete", "downloadPath::" + filepath);
Logutils.e("taskComplete", "extendField::" + extendField);
Log.e("taskComplete", "downloadPath::" + filepath);
Log.e("taskComplete", "extendField::" + extendField);
if (filepath.endsWith("apk")) {
JSONObject jsonObject = JSON.parseObject(extendField);
@@ -445,13 +480,13 @@ public class GuardService extends Service {
ToastUtil.show(app_name + "\t:下载完成");
if (filepath.endsWith(".xapk")) {
XAPKUtils.getInstance().installXAPK(filepath);
Logutils.e(TAG, "taskComplete: " + filepath);
Log.e(TAG, "taskComplete: " + filepath);
} else if (filepath.endsWith(".apk")) {
new Thread(() -> ApkUtils.installApp(GuardService.this, filepath)).start();
List<DownloadEntity> list = Aria.download(this).getDRunningTask();
if (list == null || list.size() == 0) {
BaseApplication.getInstance().setDownloadState(false);
Logutils.e("taskComplete", "isDownloading=" + BaseApplication.getInstance().isDownloading());
Log.e("taskComplete", "isDownloading=" + BaseApplication.getInstance().isDownloading());
}
}
NetInterfaceManager.getInstance()
@@ -495,12 +530,12 @@ public class GuardService extends Service {
@Override
public void onNext(BaseResponse baseResponse) {
Log.e("SEND_DOWNLOAD_FILE_INFO", "onNext: "+baseResponse.msg);
Log.e("SEND_DOWNLOAD_FILE_INFO", "onNext: " + baseResponse.msg);
}
@Override
public void onError(Throwable e) {
Log.e("SEND_DOWNLOAD_FILE_INFO", "onError: "+e.getMessage());
Log.e("SEND_DOWNLOAD_FILE_INFO", "onError: " + e.getMessage());
}
@Override
@@ -509,7 +544,7 @@ public class GuardService extends Service {
}
});
} else if (filepath.endsWith(".zip")) {
Logutils.e("taskComplete", "下载完成:" + task.getPercent() + ":" + task.getExtendField());
Log.e("taskComplete", "下载完成:" + task.getPercent() + ":" + task.getExtendField());
JGYUtils.getInstance().setBootanimation(task.getFilePath());
}
}
@@ -522,10 +557,10 @@ public class GuardService extends Service {
JSONObject jsonObject = JSON.parseObject(task.getExtendField());
String app_name = jsonObject.getString("app_name");
String app_package = jsonObject.getString("app_package");
Logutils.e("aria", "下载失败: " + packageName + "filepath " + filepath + "Exception: " + e.getMessage());
Log.e("aria", "taskFail: " + packageName + "filepath " + filepath + "Exception: " + e.getMessage());
// ToastUtil.show(app_name + "\t:下载失败");
} catch (Exception e1) {
Logutils.e("aria", "taskFail: " + e1.getMessage());
Log.e("aria", "taskFail: " + e1.getMessage());
}
}
}