|
@@ -20,6 +20,7 @@ import android.graphics.drawable.Drawable
|
20
|
20
|
import android.net.ConnectivityManager
|
21
|
21
|
import android.os.Build
|
22
|
22
|
import android.os.Bundle
|
|
23
|
+import android.os.Environment
|
23
|
24
|
import android.provider.Settings
|
24
|
25
|
import android.util.Log
|
25
|
26
|
import android.util.TypedValue
|
|
@@ -113,7 +114,6 @@ import java.util.Calendar
|
113
|
114
|
import java.util.Timer
|
114
|
115
|
import java.util.TimerTask
|
115
|
116
|
import java.util.concurrent.TimeUnit
|
116
|
|
-import kotlin.system.exitProcess
|
117
|
117
|
|
118
|
118
|
|
119
|
119
|
class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>(), DownloadCallback {
|
|
@@ -218,6 +218,42 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>(), Downloa
|
218
|
218
|
CrashReport.setUserId(it.userid.toString())
|
219
|
219
|
}
|
220
|
220
|
}
|
|
221
|
+ initWallpaper()
|
|
222
|
+ initAppRv()
|
|
223
|
+ DownLoadUtils.addCallback(this)
|
|
224
|
+ try {
|
|
225
|
+ StrategyUtils.initMainControlStrategy()
|
|
226
|
+ userBean?.let {
|
|
227
|
+ registerAppInstallReceiver()
|
|
228
|
+ registerNetConnectReceiver()
|
|
229
|
+ registerScreenReceiver()
|
|
230
|
+ registerBleStateReceiver()
|
|
231
|
+ registerUSBReceiver()
|
|
232
|
+ registerSDReceiver()
|
|
233
|
+ registerLoginOutReceiver()
|
|
234
|
+ registerLoginEditReceiver()
|
|
235
|
+ registerXhlyUpdeteStrategyReceiver()
|
|
236
|
+ adapter?.userBean = it
|
|
237
|
+ }
|
|
238
|
+ } catch (e: Exception) {
|
|
239
|
+ LogShow("错误是" + e.toString())
|
|
240
|
+ }
|
|
241
|
+ initViewModelCallBack()
|
|
242
|
+ isCreatFlag = true
|
|
243
|
+ lifecycleScope.launch {
|
|
244
|
+ isDestroyFlag = false
|
|
245
|
+ withContext(Dispatchers.IO) {
|
|
246
|
+ delay(2000)
|
|
247
|
+ }
|
|
248
|
+ //自动同时一次时间
|
|
249
|
+ viewModel.postSyncTime()
|
|
250
|
+ lastTimeLong = System.currentTimeMillis()
|
|
251
|
+ getLocation()
|
|
252
|
+ //startWorkManager()
|
|
253
|
+ //updateAllStrategy()
|
|
254
|
+ }
|
|
255
|
+ }
|
|
256
|
+ private fun initWallpaper() {
|
221
|
257
|
lifecycleScope.launch {
|
222
|
258
|
withContext(Dispatchers.IO) {
|
223
|
259
|
val file = File(filesDir, "wallpaper.png")
|
|
@@ -237,36 +273,17 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>(), Downloa
|
237
|
273
|
}
|
238
|
274
|
}
|
239
|
275
|
}
|
240
|
|
- DownLoadUtils.addCallback(this)
|
|
276
|
+ }
|
|
277
|
+
|
|
278
|
+ private fun initAppRv() {
|
241
|
279
|
adapter = AppAdapter(this, dataList)
|
242
|
280
|
mBinding.rv.layoutManager = GridLayoutManager(this, 6, GridLayoutManager.VERTICAL, false)
|
243
|
281
|
adapter?.changePwdListener = getChangeCodeListener()
|
244
|
282
|
mBinding.rv.adapter = adapter
|
245
|
283
|
updateAppRv()
|
246
|
|
- // checkAccessibility(this)
|
247
|
|
- try {
|
248
|
|
- StrategyUtils.initMainControlStrategy()
|
249
|
|
- userBean?.let {
|
250
|
|
- registerAppInstallReceiver()
|
251
|
|
- registerNetConnectReceiver()
|
252
|
|
- registerScreenReceiver()
|
253
|
|
- registerBleStateReceiver()
|
254
|
|
- registerUSBReceiver()
|
255
|
|
- registerSDReceiver()
|
256
|
|
- registerLoginOutReceiver()
|
257
|
|
- registerLoginEditReceiver()
|
258
|
|
- registerXhlyUpdeteStrategyReceiver()
|
259
|
|
- adapter?.userBean = it
|
260
|
|
- }
|
261
|
|
- } catch (e: Exception) {
|
262
|
|
- LogShow("错误是" + e.toString())
|
263
|
|
- }
|
264
|
|
- /*
|
265
|
|
- 使用情况权限
|
266
|
|
- val permissionIntent = Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS)
|
267
|
|
- startActivity(permissionIntent)*/
|
268
|
|
- // csdkManagerUtils.csdkManager.enableAccessibility("com.xhly.manageapp","com.xhly.manageapp.service.TestService",true)
|
|
284
|
+ }
|
269
|
285
|
|
|
286
|
+ private fun initViewModelCallBack() {
|
270
|
287
|
viewModel.pwdResultData.observe(this) {
|
271
|
288
|
if (it) {
|
272
|
289
|
unBindBlock()
|
|
@@ -407,22 +424,36 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>(), Downloa
|
407
|
424
|
if (granted || ModelNameUtils.IS_LianxX505f() || ModelNameUtils.IS_LianxX6e6f()|| ModelNameUtils.IS_LianxTB223FC()) {
|
408
|
425
|
// 权限已授予,执行安装操作
|
409
|
426
|
val appList = AppUtils.GetAppList(this@MainActivity)
|
410
|
|
- getExternalFilesDir(null)?.let {
|
|
427
|
+ //修改路径
|
|
428
|
+ /* getExternalFilesDir(null)?.let {
|
411
|
429
|
FileUtils.deleteCurrentFlie(it)
|
412
|
430
|
}
|
413
|
|
- val file = getExternalFilesDir(null)
|
|
431
|
+ val file = getExternalFilesDir(null)*/
|
|
432
|
+ var file:File?=null
|
|
433
|
+ if (ModelNameUtils.IS_LianxTB223FC()){
|
|
434
|
+ var directory =
|
|
435
|
+ Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)
|
|
436
|
+ file=File(directory, "appdownload")
|
|
437
|
+ if (!file.exists()){
|
|
438
|
+ file.mkdirs()
|
|
439
|
+ }else{
|
|
440
|
+ FileUtils.deleteCurrentFlie(file)
|
|
441
|
+ }
|
|
442
|
+ }else{
|
|
443
|
+ getExternalFilesDir(null)?.let {
|
|
444
|
+ FileUtils.deleteCurrentFlie(it)
|
|
445
|
+ }
|
|
446
|
+ file = getExternalFilesDir(null)
|
|
447
|
+ }
|
414
|
448
|
modelList.forEach { app ->
|
415
|
449
|
try {
|
416
|
450
|
//获得已安装的应用判断版本,未安装的则直接静默安装。
|
417
|
|
- val filter =
|
418
|
|
- appList.filter { it.packageName.equals(app.appPackage) }
|
|
451
|
+ val filter = appList.filter { it.packageName.equals(app.appPackage) }
|
419
|
452
|
//列表中不存在,或者版本较低则更新
|
420
|
453
|
val apkPath = app.apkPath
|
421
|
454
|
val appName = app.appName
|
422
|
|
- if (filter.isNotEmpty() || app.appPackage.equals(
|
423
|
|
- packageName
|
424
|
|
- )
|
425
|
|
- ) {
|
|
455
|
+ if (filter.isNotEmpty() || app.appPackage.equals(packageName)) {
|
|
456
|
+ //不为空filter.isNotEmpty()表示列表存在应用则判断版本号,app.appPackage.equals(packageName)表示需要判断是否更新桌面应用,都不满足表示应用不存在
|
426
|
457
|
val appversion =
|
427
|
458
|
if (app.appPackage.equals(packageName)) {
|
428
|
459
|
SystemUtil.getAppVersionCode(
|
|
@@ -703,18 +734,18 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>(), Downloa
|
703
|
734
|
}
|
704
|
735
|
}
|
705
|
736
|
}
|
706
|
|
- /* viewModel.timeResultData.observe(this) {
|
707
|
|
- if (SystemUtil.updateTimeFlag) {
|
708
|
|
- SystemUtil.updateTimeFlag = false
|
709
|
|
- ManageApplication.setSysTime(it)
|
710
|
|
- LogShow("当前设置的时间是" + it + "|||" + SystemClock.getDateString(it))
|
711
|
|
- try {
|
712
|
|
- tipsDialog?.dismiss()
|
713
|
|
- } catch (e: Exception) {
|
|
737
|
+ /* viewModel.timeResultData.observe(this) {
|
|
738
|
+ if (SystemUtil.updateTimeFlag) {
|
|
739
|
+ SystemUtil.updateTimeFlag = false
|
|
740
|
+ ManageApplication.setSysTime(it)
|
|
741
|
+ LogShow("当前设置的时间是" + it + "|||" + SystemClock.getDateString(it))
|
|
742
|
+ try {
|
|
743
|
+ tipsDialog?.dismiss()
|
|
744
|
+ } catch (e: Exception) {
|
714
|
745
|
|
715
|
|
- }
|
716
|
|
- }
|
717
|
|
- }*/
|
|
746
|
+ }
|
|
747
|
+ }
|
|
748
|
+ }*/
|
718
|
749
|
viewModel.viewModelScope.launch {
|
719
|
750
|
viewModel.timeResultDataFlow.collect{
|
720
|
751
|
if (SystemUtil.updateTimeFlag&&it!=null) {
|
|
@@ -764,23 +795,6 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>(), Downloa
|
764
|
795
|
}
|
765
|
796
|
}
|
766
|
797
|
}
|
767
|
|
-
|
768
|
|
- /*viewModel.mainLoginData.observe(this){userBean->
|
769
|
|
- }
|
770
|
|
-*/
|
771
|
|
- lifecycleScope.launch {
|
772
|
|
- isCreatFlag = true
|
773
|
|
- isDestroyFlag = false
|
774
|
|
- withContext(Dispatchers.IO) {
|
775
|
|
- delay(2000)
|
776
|
|
- }
|
777
|
|
- //自动同时一次时间
|
778
|
|
- viewModel.postSyncTime()
|
779
|
|
- lastTimeLong = System.currentTimeMillis()
|
780
|
|
- getLocation()
|
781
|
|
- startWorkManager()
|
782
|
|
- //updateAllStrategy()
|
783
|
|
- }
|
784
|
798
|
}
|
785
|
799
|
|
786
|
800
|
|
|
@@ -1122,7 +1136,7 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>(), Downloa
|
1122
|
1136
|
//亮屏,点击,和onresume都执行这个请求策略的方法,达到次数则请求策略。
|
1123
|
1137
|
private fun updateResumeStrategy() {
|
1124
|
1138
|
//在activity中判断,如果连续10分钟都没执行则重启任务。
|
1125
|
|
- if (!isCreatFlag&&System.currentTimeMillis() - TimingWorker.lastTime > 10 * 60 * 1000) {
|
|
1139
|
+ if (System.currentTimeMillis() - TimingWorker.lastTime > 10 * 60 * 1000) {
|
1126
|
1140
|
startWorkManager()
|
1127
|
1141
|
}
|
1128
|
1142
|
lifecycleScope.launch(Dispatchers.IO) {
|