|
@@ -16,6 +16,7 @@ import android.widget.EditText
|
16
|
16
|
import android.widget.TextView
|
17
|
17
|
import android.widget.Toast
|
18
|
18
|
import androidx.activity.addCallback
|
|
19
|
+import androidx.lifecycle.viewModelScope
|
19
|
20
|
import androidx.recyclerview.widget.GridLayoutManager
|
20
|
21
|
import androidx.work.PeriodicWorkRequest
|
21
|
22
|
import androidx.work.WorkManager
|
|
@@ -27,6 +28,7 @@ import com.xhly.corelib.bean.AppInfo
|
27
|
28
|
import com.xhly.corelib.eventbus.UIEvent
|
28
|
29
|
import com.xhly.corelib.utils.AppUtils
|
29
|
30
|
import com.xhly.corelib.utils.CustomOSUtils
|
|
31
|
+import com.xhly.corelib.utils.GsonUtils
|
30
|
32
|
import com.xhly.corelib.utils.LogShow
|
31
|
33
|
import com.xhly.corelib.utils.SharedPreferencesUtils
|
32
|
34
|
import com.xhly.corelib.utils.SystemUtil
|
|
@@ -34,6 +36,7 @@ import com.xhly.manageapp.AppAdapter
|
34
|
36
|
import com.xhly.manageapp.ManageApplication
|
35
|
37
|
import com.xhly.manageapp.R
|
36
|
38
|
import com.xhly.manageapp.bean.EventLog
|
|
39
|
+import com.xhly.manageapp.bean.SocketMsgBean
|
37
|
40
|
import com.xhly.manageapp.bean.UpdateBean
|
38
|
41
|
import com.xhly.manageapp.bean.log.LogdOperateBean
|
39
|
42
|
import com.xhly.manageapp.bean.strategy.StrategyBean
|
|
@@ -45,15 +48,17 @@ import com.xhly.manageapp.service.websocket.AppSocket
|
45
|
48
|
import com.xhly.manageapp.ui.ManageActivity
|
46
|
49
|
import com.xhly.manageapp.ui.login.activity.LoginActivity
|
47
|
50
|
import com.xhly.manageapp.ui.main.viewmodel.MainViewModel
|
|
51
|
+import com.xhly.manageapp.utils.AppDownLoadUtils
|
48
|
52
|
import com.xhly.manageapp.utils.PadInfoUtils
|
49
|
53
|
import com.xhly.manageapp.utils.StrategyUtils
|
50
|
54
|
import com.xhly.manageapp.workmanager.TimingWorker
|
|
55
|
+import kotlinx.coroutines.launch
|
51
|
56
|
import java.util.Calendar
|
52
|
57
|
import java.util.concurrent.TimeUnit
|
53
|
58
|
|
54
|
59
|
|
55
|
60
|
class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
|
56
|
|
- lateinit var adapter: AppAdapter
|
|
61
|
+ var adapter: AppAdapter? = null
|
57
|
62
|
|
58
|
63
|
private var mMyInstallReceiver: AppInstallReceiver? = null
|
59
|
64
|
private var dataList: ArrayList<AppInfo> = arrayListOf()
|
|
@@ -84,11 +89,41 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
|
84
|
89
|
startActivity(permissionIntent)*/
|
85
|
90
|
// csdkManagerUtils.csdkManager.enableAccessibility("com.xhly.manageapp","com.xhly.manageapp.service.TestService",true)
|
86
|
91
|
viewModel.getAppList()
|
87
|
|
- viewModel.listAppData.observe(this) {
|
88
|
|
- //获得应用集合,必装应用和推荐应用,再加上预装应用,其余应用需要静默卸载,必装应用需要进行静默下载和安装。
|
89
|
|
- var appList = AppUtils.GetAppList(this)
|
90
|
|
-
|
|
92
|
+ viewModel.listAppData.observe(this) { modelList ->
|
|
93
|
+ //获得应用集合,必装应用和推荐应用,再加上预装应用,其余应用需要静默卸载,必装应用需要进行静默下载和安装。安装应用从forceapp接口获取
|
|
94
|
+ val appList = AppUtils.GetAppList(this)
|
|
95
|
+ appList.forEach { app ->
|
|
96
|
+ val filter = modelList.filter { it.appPackage.equals(app.packageName) }
|
|
97
|
+ //列表中不存在则将应用冻结或者卸载,目前是冻结
|
|
98
|
+ ManageApplication.setPackageEnabled(app.packageName, (filter.isNotEmpty()))
|
|
99
|
+ }
|
91
|
100
|
}
|
|
101
|
+ viewModel.forceListAppData.observe(this) { modelList ->
|
|
102
|
+ //获得必装应用,未安装或者版本较低则更新
|
|
103
|
+ val appList = AppUtils.GetAppList(this)
|
|
104
|
+ modelList.forEach { app ->
|
|
105
|
+ //获得已安装的应用判断版本,未安装的则直接静默安装。
|
|
106
|
+ val filter = appList.filter { it.packageName.equals(app.appPackage) }
|
|
107
|
+ //列表中不存在,或者版本较低则更新
|
|
108
|
+ val apkPath = app.apkPath
|
|
109
|
+ val appName = app.appName
|
|
110
|
+ if (filter.isNotEmpty()) {
|
|
111
|
+ val currentApp = filter[0]
|
|
112
|
+ if (app.versionNum > currentApp.versionNum) {
|
|
113
|
+ //版本低则更新安装。
|
|
114
|
+ viewModel.viewModelScope.launch {
|
|
115
|
+ AppDownLoadUtils.addToDownloadQueue(apkPath, appName)
|
|
116
|
+ }
|
|
117
|
+ }
|
|
118
|
+ } else {
|
|
119
|
+ //不存在,直接下载安装。
|
|
120
|
+ viewModel.viewModelScope.launch {
|
|
121
|
+ AppDownLoadUtils.addToDownloadQueue(apkPath, appName)
|
|
122
|
+ }
|
|
123
|
+ }
|
|
124
|
+ }
|
|
125
|
+ }
|
|
126
|
+
|
92
|
127
|
viewModel.strategyData.observe(this) {
|
93
|
128
|
spUtils.saveJson(Const.STRATEGYBEANKEY, it)
|
94
|
129
|
StrategyUtils.setStrategy(it)
|
|
@@ -137,7 +172,8 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
|
137
|
172
|
}
|
138
|
173
|
onBackPressedDispatcher.addCallback {
|
139
|
174
|
//屏蔽返回
|
140
|
|
- viewModel.getAppList()
|
|
175
|
+ /* viewModel.getAppList()
|
|
176
|
+ viewModel.getForceAppList()*/
|
141
|
177
|
}
|
142
|
178
|
}
|
143
|
179
|
|
|
@@ -151,6 +187,9 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
|
151
|
187
|
updatePadInfo()
|
152
|
188
|
updateMcApp()
|
153
|
189
|
getLocation()
|
|
190
|
+ ManageApplication.lockTaskPackages().forEach {
|
|
191
|
+ LogShow("获得的姓名是"+it)
|
|
192
|
+ }
|
154
|
193
|
try {
|
155
|
194
|
var s =
|
156
|
195
|
"厂商" + CustomOSUtils.getSystemBrand() + ",型号" + CustomOSUtils.getSystemDevice() + ",系统版本" + CustomOSUtils.getSystemDisplay()
|
|
@@ -298,13 +337,7 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
|
298
|
337
|
super.onUiEvent(uiEvent)
|
299
|
338
|
when (uiEvent.getEvent()) {
|
300
|
339
|
"update" -> {
|
301
|
|
- dataList.clear()
|
302
|
|
- val getAppList1 = AppUtils.GetAppList(this)
|
303
|
|
- dataList.addAll(getAppList1)
|
304
|
|
- adapter.notifyDataSetChanged()
|
305
|
|
- dataList.forEach {
|
306
|
|
- LogShow("app包名" + it.packageName)
|
307
|
|
- }
|
|
340
|
+ updateAppRv()
|
308
|
341
|
}
|
309
|
342
|
|
310
|
343
|
Const.CODE2001.toString() -> {
|
|
@@ -323,6 +356,7 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
|
323
|
356
|
}
|
324
|
357
|
|
325
|
358
|
Const.CODE2004.toString() -> {
|
|
359
|
+ //TODO 更新策略是否需要通过应用接口处理应用
|
326
|
360
|
//请求接口更新策略
|
327
|
361
|
viewModel.uploadAppStrategy()
|
328
|
362
|
viewModel.updateStrategy()
|
|
@@ -355,14 +389,11 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
|
355
|
389
|
}
|
356
|
390
|
|
357
|
391
|
Const.APPINSTALL -> {
|
358
|
|
- try {
|
359
|
|
- dataList.clear()
|
360
|
|
- val getAppList1 = AppUtils.GetAppList(this)
|
361
|
|
- dataList.addAll(getAppList1)
|
362
|
|
- adapter.notifyDataSetChanged()
|
363
|
|
- } catch (e: Exception) {
|
|
392
|
+ updateAppRv()
|
|
393
|
+ }
|
364
|
394
|
|
365
|
|
- }
|
|
395
|
+ Const.APPUNINSTALL -> {
|
|
396
|
+ updateAppRv()
|
366
|
397
|
}
|
367
|
398
|
|
368
|
399
|
Const.SDINSTALL -> {
|
|
@@ -431,6 +462,23 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
|
431
|
462
|
}
|
432
|
463
|
}
|
433
|
464
|
|
|
465
|
+ private fun updateAppRv() {
|
|
466
|
+ try {
|
|
467
|
+ dataList.clear()
|
|
468
|
+ val appList = AppUtils.GetAppList(this)
|
|
469
|
+ dataList.addAll(appList)
|
|
470
|
+ if (adapter == null) {
|
|
471
|
+ adapter = AppAdapter(this, dataList)
|
|
472
|
+ mBinding.rv.adapter = adapter
|
|
473
|
+ }
|
|
474
|
+ adapter?.let {
|
|
475
|
+ it.notifyDataSetChanged()
|
|
476
|
+ }
|
|
477
|
+ } catch (e: Exception) {
|
|
478
|
+
|
|
479
|
+ }
|
|
480
|
+ }
|
|
481
|
+
|
434
|
482
|
fun checkAccessibility(context: Context): Boolean {
|
435
|
483
|
// 判断辅助功能是否开启
|
436
|
484
|
if (!isServiceON(this, ManageAccessibilityService::class.java.name)) {
|
|
@@ -509,9 +557,21 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
|
509
|
557
|
.setCustomView(object : OnBindView<CustomDialog>(R.layout.layout_notice_dialog) {
|
510
|
558
|
override fun onBind(dialog: CustomDialog, v: View) {
|
511
|
559
|
val closeBtn = v.findViewById<Button>(R.id.dialog_close_btn)
|
|
560
|
+ val titleTv = v.findViewById<TextView>(R.id.dialog_title_tv)
|
|
561
|
+ val contentTv = v.findViewById<TextView>(R.id.dialog_content_tv)
|
|
562
|
+ try {
|
|
563
|
+ val msgBean =
|
|
564
|
+ GsonUtils.parseJsonWithGson(
|
|
565
|
+ msg,
|
|
566
|
+ SocketMsgBean().javaClass
|
|
567
|
+ ) as SocketMsgBean
|
|
568
|
+ titleTv.text = msgBean.title
|
|
569
|
+ contentTv.text = msgBean.content
|
|
570
|
+ } catch (e: Exception) {
|
|
571
|
+
|
|
572
|
+ }
|
512
|
573
|
closeBtn.setOnClickListener {
|
513
|
574
|
dialog.dismiss()
|
514
|
|
-
|
515
|
575
|
}
|
516
|
576
|
}
|
517
|
577
|
}).setCancelable(false).setMaskColor(Color.parseColor("#66000000"))
|