|
@@ -27,9 +27,14 @@ import com.blankj.utilcode.util.LogUtils;
|
|
|
import com.blankj.utilcode.util.NetworkUtils;
|
|
|
import com.blankj.utilcode.util.SPUtils;
|
|
|
import com.blankj.utilcode.util.ThreadUtils;
|
|
|
+import com.hikvision.dmb.EthernetConfig;
|
|
|
+import com.hikvision.dmb.LauncherInfo;
|
|
|
+import com.hikvision.dmb.MemoryInfo;
|
|
|
+import com.hikvision.dmb.TimeSwitchConfig;
|
|
|
import com.hikvision.dmb.display.InfoDisplayApi;
|
|
|
import com.hikvision.dmb.network.InfoNetworkApi;
|
|
|
import com.hikvision.dmb.system.InfoSystemApi;
|
|
|
+import com.hikvision.dmb.time.InfoTimeApi;
|
|
|
import com.hikvision.dmb.util.InfoUtilApi;
|
|
|
import com.hjq.permissions.OnPermissionCallback;
|
|
|
import com.hjq.permissions.Permission;
|
|
@@ -41,8 +46,11 @@ import org.json.JSONObject;
|
|
|
|
|
|
import java.io.File;
|
|
|
import java.util.List;
|
|
|
+import java.util.concurrent.Executors;
|
|
|
+import java.util.concurrent.ScheduledExecutorService;
|
|
|
import java.util.concurrent.ThreadLocalRandom;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
+import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
|
|
|
import okhttp3.Response;
|
|
|
import xn.update.R;
|
|
@@ -56,7 +64,8 @@ import xn.update.works.TaskWork;
|
|
|
public class TaskService extends Service {
|
|
|
|
|
|
private TimeTickReceiver timeTickReceiver;
|
|
|
- private CountDownTimer permissionCdt;
|
|
|
+ private final AtomicBoolean isUploading = new AtomicBoolean(false);
|
|
|
+ private ScheduledExecutorService scheduler;
|
|
|
|
|
|
@Nullable
|
|
|
@Override
|
|
@@ -67,6 +76,28 @@ public class TaskService extends Service {
|
|
|
@Override
|
|
|
public void onCreate() {
|
|
|
super.onCreate();
|
|
|
+ scheduler = Executors.newSingleThreadScheduledExecutor();
|
|
|
+ scheduler.scheduleWithFixedDelay(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ if (!isUploading.compareAndSet(false, true)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ ThreadUtils.executeByCached(new ThreadUtils.SimpleTask<Object>() {
|
|
|
+ @Override
|
|
|
+ public Object doInBackground() throws Throwable {
|
|
|
+ Response response = HttpTool.INSTANCE.heartbeat();
|
|
|
+ LogUtils.d("发送心跳");
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onSuccess(Object result) {
|
|
|
+ isUploading.set(false);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }, 0, 2, TimeUnit.SECONDS);
|
|
|
// 卸载老旧app
|
|
|
Tool.INSTANCE.cmd("pm uninstall com.dlc.xn.eboard");
|
|
|
|
|
@@ -81,7 +112,6 @@ public class TaskService extends Service {
|
|
|
InfoSystemApi.openAdb();
|
|
|
InfoDisplayApi.setStatusBarEnable(false);
|
|
|
InfoDisplayApi.setNavigationBarEnable(false);
|
|
|
- InfoUtilApi.setUsbSwitch(false);
|
|
|
SPUtils.getInstance().put("isRoot", 0 == InfoUtilApi.getRoot());
|
|
|
SPUtils.getInstance().put("IP", InfoNetworkApi.getEthernetConfig().ipAddress);
|
|
|
InfoUtilApi.enableProtection(AppUtils.getAppPackageName(), false);
|
|
@@ -95,31 +125,33 @@ public class TaskService extends Service {
|
|
|
Tool.INSTANCE.cmd("pm grant " + AppUtils.getAppPackageName() + " android.permission.READ_EXTERNAL_STORAGE");
|
|
|
Tool.INSTANCE.cmd("pm grant " + AppUtils.getAppPackageName() + " android.permission.WRITE_EXTERNAL_STORAGE");
|
|
|
Tool.INSTANCE.cmd("pm grant " + AppUtils.getAppPackageName() + " android.permission.NOTIFICATION_SERVICE");
|
|
|
- permissionCdt = new CountDownTimer(1000, 1000) {
|
|
|
+ ThreadUtils.executeByCachedAtFixRate(new ThreadUtils.SimpleTask<Boolean>() {
|
|
|
@Override
|
|
|
- public void onTick(long millisUntilFinished) {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onFinish() {
|
|
|
- if (!XXPermissions.isGranted(ActivityUtils.getTopActivity(), Permission.READ_EXTERNAL_STORAGE)
|
|
|
- || !XXPermissions.isGranted(ActivityUtils.getTopActivity(), Permission.WRITE_EXTERNAL_STORAGE)
|
|
|
- || !XXPermissions.isGranted(ActivityUtils.getTopActivity(), Permission.NOTIFICATION_SERVICE)
|
|
|
- ) {
|
|
|
- Tool.INSTANCE.cmd("pm grant " + AppUtils.getAppPackageName() + " android.permission.READ_EXTERNAL_STORAGE");
|
|
|
- Tool.INSTANCE.cmd("pm grant " + AppUtils.getAppPackageName() + " android.permission.WRITE_EXTERNAL_STORAGE");
|
|
|
- Tool.INSTANCE.cmd("pm grant " + AppUtils.getAppPackageName() + " android.permission.NOTIFICATION_SERVICE");
|
|
|
- permissionCdt.start();
|
|
|
+ public Boolean doInBackground() throws Throwable {
|
|
|
+ if (null == ActivityUtils.getTopActivity()) {
|
|
|
+ Tool.INSTANCE.stopApp(AppUtils.getAppPackageName());
|
|
|
+ Tool.INSTANCE.openApp(AppUtils.getAppPackageName());
|
|
|
} else {
|
|
|
- requestPermission();
|
|
|
- permissionCdt.cancel();
|
|
|
- permissionCdt = null;
|
|
|
+ if (!XXPermissions.isGranted(ActivityUtils.getTopActivity(), Permission.READ_EXTERNAL_STORAGE)
|
|
|
+ || !XXPermissions.isGranted(ActivityUtils.getTopActivity(), Permission.WRITE_EXTERNAL_STORAGE)
|
|
|
+ || !XXPermissions.isGranted(ActivityUtils.getTopActivity(), Permission.NOTIFICATION_SERVICE)
|
|
|
+ ) {
|
|
|
+ Tool.INSTANCE.cmd("pm grant " + AppUtils.getAppPackageName() + " android.permission.READ_EXTERNAL_STORAGE");
|
|
|
+ Tool.INSTANCE.cmd("pm grant " + AppUtils.getAppPackageName() + " android.permission.WRITE_EXTERNAL_STORAGE");
|
|
|
+ Tool.INSTANCE.cmd("pm grant " + AppUtils.getAppPackageName() + " android.permission.NOTIFICATION_SERVICE");
|
|
|
+ } else {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
}
|
|
|
+ return false;
|
|
|
+ }
|
|
|
|
|
|
+ @Override
|
|
|
+ public void onSuccess(Boolean result) {
|
|
|
+ requestPermission();
|
|
|
+ cancel();
|
|
|
}
|
|
|
- };
|
|
|
- permissionCdt.start();
|
|
|
+ }, 1, 1, TimeUnit.SECONDS);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -140,6 +172,9 @@ public class TaskService extends Service {
|
|
|
@Override
|
|
|
public void onDestroy() {
|
|
|
super.onDestroy();
|
|
|
+ if (null != scheduler) {
|
|
|
+ scheduler.shutdown();
|
|
|
+ }
|
|
|
if (null != timeTickReceiver) {
|
|
|
unregisterReceiver(timeTickReceiver);
|
|
|
timeTickReceiver = null;
|
|
@@ -247,6 +282,75 @@ public class TaskService extends Service {
|
|
|
@Override
|
|
|
public void onSuccess(Pair<Boolean, String> result) {
|
|
|
if (result.first) {
|
|
|
+// // 状态栏是否开启
|
|
|
+// boolean isStatusBarEnable = InfoDisplayApi.getStatusBarEnable();
|
|
|
+// // 导航栏是否开启
|
|
|
+// boolean isNavBarEnable = InfoDisplayApi.getNavigationBarEnable();
|
|
|
+//
|
|
|
+// EthernetConfig ethernetConfig = InfoNetworkApi.getEthernetConfig();
|
|
|
+// // Ip
|
|
|
+// String ip = ethernetConfig.getIpAddress();
|
|
|
+// // dhcp
|
|
|
+// int dhcp = ethernetConfig.getDhcp();
|
|
|
+// // dns1
|
|
|
+// String dns1 = ethernetConfig.getDns1Address();
|
|
|
+// // dns2
|
|
|
+// String dns2 = ethernetConfig.getDns2Address();
|
|
|
+// // mac
|
|
|
+// String mac = ethernetConfig.getMacAddress();
|
|
|
+// // route
|
|
|
+// String route = ethernetConfig.getRouteAddress();
|
|
|
+// // subnetMask
|
|
|
+// String subnetMask = ethernetConfig.getSubnetMask();
|
|
|
+// // 最优Ip地址 以太网>无线网>3、4G
|
|
|
+// String optimalIp = InfoNetworkApi.getOptimalIp();
|
|
|
+// // 设备型号
|
|
|
+// String deviceType = InfoSystemApi.getDeviceType();
|
|
|
+// // 设备序列号
|
|
|
+// String sn = InfoSystemApi.getSerialNumber();
|
|
|
+// // adb状态
|
|
|
+// int adbStatus = InfoSystemApi.getAdbStatus();
|
|
|
+// // 设备箱体温度
|
|
|
+// String temperature = InfoSystemApi.getTemperature();
|
|
|
+// // 系统编译版本号 V2.0.0 build 171226
|
|
|
+// String buildDesc = InfoSystemApi.getBuildDesc();
|
|
|
+// // 系统MCU版本号 V1.0.0 build 171226
|
|
|
+// String mcuVersion = InfoSystemApi.getMcuVersion();
|
|
|
+// // CPU使用率 当前 Cpu 的使用率,百分比,获取失败时返回”-1.00”字符串
|
|
|
+// String cpuUsageRate = InfoSystemApi.getCpuUsageRate();
|
|
|
+// // GPU使用率 当前 Gpu 的使用率,百分比,获取失败时返回”-1.00”字符串
|
|
|
+// String gpuUsageRate = InfoSystemApi.getGpuUsageRate();
|
|
|
+// // 获取内存使用情况
|
|
|
+// MemoryInfo memoryInfo = InfoSystemApi.getMemoryUsage();
|
|
|
+// // MemoryInfo .used 已使用内存大小(单位 MB)
|
|
|
+// int used = memoryInfo.used;
|
|
|
+// // MemoryInfo.total 总内存大小(MB)
|
|
|
+// int total = memoryInfo.total;
|
|
|
+// // MemoryInfo.describe 583.00MB/1.96GB
|
|
|
+// String describe = memoryInfo.describe;
|
|
|
+// int describeContents = memoryInfo.describeContents();
|
|
|
+// // 获取SDK版本 返回 SDK 版本号,获取失败返回”none”字符串
|
|
|
+// String sdkVersion = InfoSystemApi.getSdkVersion();
|
|
|
+// // 如果系统不支持该接口,则 currentLauncherName 和 preferredLauncherName 的值均为空字符串(“”)。
|
|
|
+// // 关于“默认“一词,默认 Launcher 即多个 Launcher 应用中优先级最高的,默认启动的。
|
|
|
+// LauncherInfo launcherInfo = InfoSystemApi.getLauncherName();
|
|
|
+// // 为当前生效的默认 Launcher 应用包名,默认(始终)Launcher 应用修改后该值即时更新。如果当前系统未设置默认(始终)Launcher,则该值为空字符串(“”)。
|
|
|
+// String currentLauncherName = launcherInfo.getCurrentLauncherName();
|
|
|
+// // 为持久化文件中保存的默认 Launcher 应用包名,默认 Launcher 应用修改后约 10 秒后该值才会更新,该值仅当系统内存在 2 个及以上Launcher 应用时才会存在,否则为空字符串(“”)。
|
|
|
+// String preferredLauncherName = launcherInfo.getPreferredLauncherName();
|
|
|
+// // 获取定时开关机计划
|
|
|
+// TimeSwitchConfig timeSwitchConfig = InfoTimeApi.getTimeSwitch();
|
|
|
+// // 开机时间 默认-1
|
|
|
+// long onTime = timeSwitchConfig.setOnTime;
|
|
|
+// // 关机时间 默认-1
|
|
|
+// long offTime = timeSwitchConfig.setOffTime;
|
|
|
+// // 门禁点锁状态1 true-当前锁处于上电锁门状态
|
|
|
+// // false-当前锁处于断电开门状态或参数错误
|
|
|
+// boolean electricLock1 = InfoUtilApi.getElectricLock(1);
|
|
|
+// // 门禁点锁状态2
|
|
|
+// boolean electricLock2 = InfoUtilApi.getElectricLock(2);
|
|
|
+
|
|
|
+
|
|
|
EventBus.getDefault().post(new UpdateUiEvent(result.second));
|
|
|
ThreadUtils.cancel(simpleTask);
|
|
|
} else {
|