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
         mBinding.rv.adapter = adapter
217
         mBinding.rv.adapter = adapter
218
         updateAppRv()
218
         updateAppRv()
219
         // checkAccessibility(this)
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
          val permissionIntent = Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS)
237
          val permissionIntent = Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS)
324
                     }
331
                     }
325
                     unInstallAppList.clear()
332
                     unInstallAppList.clear()
326
                     if (modelList.size>0){
333
                     if (modelList.size>0){
327
-                        //modelList为0表示未打开应用策略,不删除应用
334
+                        ManageApplication.disableInstallation(true)
335
+                        //modelList为0表示未打开应用策略,不删除应用,并且打开应用安装权限,其余情况关闭
328
                         appList.forEach { app ->
336
                         appList.forEach { app ->
329
                             val filter = modelList.filter { it.appPackage.equals(app.packageName) }
337
                             val filter = modelList.filter { it.appPackage.equals(app.packageName) }
330
                             val appInfos = firstAppList.filter { app.packageName.equals(it) }
338
                             val appInfos = firstAppList.filter { app.packageName.equals(it) }
332
                             LogShow("${app.name},被冻结" + (filter.isEmpty() && appInfos.isEmpty()))
340
                             LogShow("${app.name},被冻结" + (filter.isEmpty() && appInfos.isEmpty()))
333
                             if (filter.isEmpty() && appInfos.isEmpty()) {
341
                             if (filter.isEmpty() && appInfos.isEmpty()) {
334
                                 unInstallAppList.add(app)
342
                                 unInstallAppList.add(app)
335
-                                //ManageApplication.setPackageEnabled(app.packageName, (filter.isNotEmpty()))
336
                                 ManageApplication.uninstallPackage(app.packageName)
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
         mXhlyUpdeteStrategyReceiver?.let {
2088
         mXhlyUpdeteStrategyReceiver?.let {
2079
             unregisterReceiver(it)
2089
             unregisterReceiver(it)
2080
         }
2090
         }
2081
-        mLoginOutReceiver.let {
2091
+        mLoginOutReceiver?.let {
2082
             unregisterReceiver(it)
2092
             unregisterReceiver(it)
2083
         }
2093
         }
2084
         LogShow("MainActivity被销毁")
2094
         LogShow("MainActivity被销毁")

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

470
             ManageApplication.disableStatusBarPanel(true)
470
             ManageApplication.disableStatusBarPanel(true)
471
             ManageApplication.hideHomeSoftKey(true)
471
             ManageApplication.hideHomeSoftKey(true)
472
             ManageApplication.hideMenuSoftKey(true)
472
             ManageApplication.hideMenuSoftKey(true)
473
-            ManageApplication.enableAccessibility()
474
             ManageApplication.setLockScreenMode()
473
             ManageApplication.setLockScreenMode()
475
             //禁用蓝牙分享
474
             //禁用蓝牙分享
476
             ManageApplication.disableBluetoothShare()
475
             ManageApplication.disableBluetoothShare()
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