Browse Source

1.登录后才注册广播。

2.在未设置应用白名单是,允许安装应用。
3.在MainActivity中调用初始化策略方法,防止状态栏下拉和底部按钮显示。
0423x6e6f
wangwanlei 4 days ago
parent
commit
eb258dbc6f

+ 21
- 11
app/src/main/java/com/xhly/manageapp/ui/main/activity/MainActivity.kt View File

@@ -217,14 +217,21 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>(), Downloa
217 217
         mBinding.rv.adapter = adapter
218 218
         updateAppRv()
219 219
         // checkAccessibility(this)
220
-        registerAppInstallReceiver()
221
-        registerNetConnectReceiver()
222
-        registerScreenReceiver()
223
-        registerBleStateReceiver()
224
-        registerUSBReceiver()
225
-        registerSDReceiver()
226
-        registerLoginOutReceiver()
227
-        registerXhlyUpdeteStrategyReceiver()
220
+        try {
221
+            StrategyUtils.initMainControlStrategy()
222
+            userBean?.let {
223
+                registerAppInstallReceiver()
224
+                registerNetConnectReceiver()
225
+                registerScreenReceiver()
226
+                registerBleStateReceiver()
227
+                registerUSBReceiver()
228
+                registerSDReceiver()
229
+                registerLoginOutReceiver()
230
+                registerXhlyUpdeteStrategyReceiver()
231
+            }
232
+        }catch (e:Exception){
233
+            LogShow("错误是"+e.toString())
234
+        }
228 235
         /*
229 236
          使用情况权限
230 237
          val permissionIntent = Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS)
@@ -324,7 +331,8 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>(), Downloa
324 331
                     }
325 332
                     unInstallAppList.clear()
326 333
                     if (modelList.size>0){
327
-                        //modelList为0表示未打开应用策略,不删除应用
334
+                        ManageApplication.disableInstallation(true)
335
+                        //modelList为0表示未打开应用策略,不删除应用,并且打开应用安装权限,其余情况关闭
328 336
                         appList.forEach { app ->
329 337
                             val filter = modelList.filter { it.appPackage.equals(app.packageName) }
330 338
                             val appInfos = firstAppList.filter { app.packageName.equals(it) }
@@ -332,10 +340,12 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>(), Downloa
332 340
                             LogShow("${app.name},被冻结" + (filter.isEmpty() && appInfos.isEmpty()))
333 341
                             if (filter.isEmpty() && appInfos.isEmpty()) {
334 342
                                 unInstallAppList.add(app)
335
-                                //ManageApplication.setPackageEnabled(app.packageName, (filter.isNotEmpty()))
336 343
                                 ManageApplication.uninstallPackage(app.packageName)
337 344
                             }
338 345
                         }
346
+                    }else{
347
+                        //modelList为0表示未打开应用策略,所以打开打开应用安装权限
348
+                        ManageApplication.disableInstallation(false)
339 349
                     }
340 350
                 }
341 351
             }
@@ -2078,7 +2088,7 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>(), Downloa
2078 2088
         mXhlyUpdeteStrategyReceiver?.let {
2079 2089
             unregisterReceiver(it)
2080 2090
         }
2081
-        mLoginOutReceiver.let {
2091
+        mLoginOutReceiver?.let {
2082 2092
             unregisterReceiver(it)
2083 2093
         }
2084 2094
         LogShow("MainActivity被销毁")

+ 14
- 1
app/src/main/java/com/xhly/manageapp/utils/StrategyUtils.kt View File

@@ -470,7 +470,6 @@ object StrategyUtils {
470 470
             ManageApplication.disableStatusBarPanel(true)
471 471
             ManageApplication.hideHomeSoftKey(true)
472 472
             ManageApplication.hideMenuSoftKey(true)
473
-            ManageApplication.enableAccessibility()
474 473
             ManageApplication.setLockScreenMode()
475 474
             //禁用蓝牙分享
476 475
             ManageApplication.disableBluetoothShare()
@@ -497,4 +496,18 @@ object StrategyUtils {
497 496
             }
498 497
         }
499 498
     }
499
+
500
+    /**
501
+     * 这些在mainActivity中调用,防止jar未起作用
502
+     */
503
+   fun initMainControlStrategy(){
504
+        //禁止安装app
505
+        ManageApplication.disableInstallation(true)
506
+        //禁止截屏
507
+        ManageApplication.enableCaptureScreen(false)
508
+        //禁止状态栏下拉,屏蔽底部虚拟键。
509
+        ManageApplication.disableStatusBarPanel(true)
510
+        ManageApplication.hideHomeSoftKey(true)
511
+        ManageApplication.hideMenuSoftKey(true)
512
+    }
500 513
 }

Loading…
Cancel
Save