Browse Source

1.添加解除管控接口和处理

20241218TB223FC(测试jar包)
wangwanlei 10 months ago
parent
commit
2e99f096bd

+ 41
- 36
app/src/main/java/com/xhly/manageapp/ManageApplication.kt View File

15
 import com.xhly.corelib.utils.SharedPreferencesUtils
15
 import com.xhly.corelib.utils.SharedPreferencesUtils
16
 import com.xhly.manageapp.bean.user.UserBean
16
 import com.xhly.manageapp.bean.user.UserBean
17
 import com.xhly.manageapp.service.websocket.AppSocket
17
 import com.xhly.manageapp.service.websocket.AppSocket
18
+import com.xhly.manageapp.utils.CurrentAppSharedPreferencesUtils
18
 import com.xhly.manageapp.utils.ZJAPPUtils
19
 import com.xhly.manageapp.utils.ZJAPPUtils
19
 import java.io.File
20
 import java.io.File
20
 
21
 
558
         super.onCreate()
559
         super.onCreate()
559
         instance = this
560
         instance = this
560
         val spUtils=SharedPreferencesUtils.getInstance(this)
561
         val spUtils=SharedPreferencesUtils.getInstance(this)
562
+        //获取是否已经解除管控
563
+        val currentSpUtils by lazy { CurrentAppSharedPreferencesUtils.getInstance(this) }
564
+        val exitControlFlag = currentSpUtils.getParam(Const.EXIT_CONTROL, false) as Boolean
561
         try {
565
         try {
562
             val userBean = spUtils.getFromJson(
566
             val userBean = spUtils.getFromJson(
563
                 Const.USERINFO, UserBean().javaClass
567
                 Const.USERINFO, UserBean().javaClass
570
 
574
 
571
         }
575
         }
572
         Toaster.init(this)
576
         Toaster.init(this)
573
-        AppSocket.startSocket(this)
574
-        if (ModelNameUtils.IS_LianxX505f()) {
575
-            //是505f则执行
576
-            csdkManager = CSDKManager(this)
577
-            addInstallPackageWhiteList(
578
-                arrayListOf(
577
+        //如果解除管控为真,则不在执行以下代码
578
+        if (!exitControlFlag){
579
+            AppSocket.startSocket(this)
580
+            if (ModelNameUtils.IS_LianxX505f()) {
581
+                //是505f则执行
582
+                csdkManager = CSDKManager(this)
583
+                addInstallPackageWhiteList(
584
+                    arrayListOf(
585
+                        Const.CURRENTAPPPKG,
586
+                        Const.STOREAPPPKG
587
+                    )
588
+                )
589
+                //给自己加入网络白名单
590
+                addAppWhiteRule(arrayListOf(Const.CURRENTAPPPKG))
591
+                //允许运行时权限,禁止状态栏下拉,屏蔽底部虚拟键。
592
+                setRuntimePermissions(true)
593
+                disableStatusBarPanel(true)
594
+                hideHomeSoftKey(true)
595
+                hideMenuSoftKey(true)
596
+                enableAccessibility()
597
+                setCustomLauncher(
579
                     Const.CURRENTAPPPKG,
598
                     Const.CURRENTAPPPKG,
580
-                    Const.STOREAPPPKG
599
+                    Const.CURRENTAPPPKG+".ui.ManageActivity"
581
                 )
600
                 )
582
-            )
583
-            //给自己加入网络白名单
584
-            addAppWhiteRule(arrayListOf(Const.CURRENTAPPPKG))
585
-            //启动网络限制
586
-            setUrlWhiteListEnable(true)
587
-            //允许运行时权限,禁止状态栏下拉,屏蔽底部虚拟键。
588
-           // setRuntimePermissions(true)
589
-            disableStatusBarPanel(true)
590
-            hideHomeSoftKey(true)
591
-            hideMenuSoftKey(true)
592
-            enableAccessibility()
593
-            setCustomLauncher(
594
-                Const.CURRENTAPPPKG,
595
-                Const.CURRENTAPPPKG+".ui.ManageActivity"
596
-            )
597
-            if (Const.isDebug){
598
-                csdkManager?.setPackageEnabled("com.xhly.easystud", true)
599
-                setUrlWhiteListEnable(false)
600
-                disableStatusBarPanel(false)
601
-                hideHomeSoftKey(false)
602
-                hideMenuSoftKey(false)
603
-                csdkManager?.wifiWhiteList.let {
604
-                    csdkManager?.removeWifiWhiteList(it)
601
+                if (Const.isDebug){
602
+                    csdkManager?.setPackageEnabled("com.xhly.easystud", true)
603
+                    setUrlWhiteListEnable(false)
604
+                    disableStatusBarPanel(false)
605
+                    hideHomeSoftKey(false)
606
+                    hideMenuSoftKey(false)
607
+                    csdkManager?.wifiWhiteList.let {
608
+                        csdkManager?.removeWifiWhiteList(it)
609
+                    }
610
+                }
611
+                csdkManager?.urlWhiteListRead()?.forEach {
612
+                    LogShow("白名单有"+it.toString())
613
+                }
614
+                csdkManager?.wifiWhiteList?.forEach {
615
+                    LogShow("wifi白名单有"+it.toString())
605
                 }
616
                 }
606
-            }
607
-            csdkManager?.urlWhiteListRead()?.forEach {
608
-                LogShow("白名单有"+it.toString())
609
-            }
610
-            csdkManager?.wifiWhiteList?.forEach {
611
-                LogShow("wifi白名单有"+it.toString())
612
             }
617
             }
613
         }
618
         }
614
     }
619
     }

+ 5
- 0
app/src/main/java/com/xhly/manageapp/network/UriAdress.kt View File

95
      * 同步时间
95
      * 同步时间
96
      */
96
      */
97
     const val SYNCTIME="/tool/milli"
97
     const val SYNCTIME="/tool/milli"
98
+
99
+    /**
100
+     * 退出管控
101
+     */
102
+    const val EXIT_CONTROL="/password/exit_control"
98
 }
103
 }

+ 21
- 1
app/src/main/java/com/xhly/manageapp/ui/ManageActivity.kt View File

9
 import android.content.pm.PackageManager.DONT_KILL_APP
9
 import android.content.pm.PackageManager.DONT_KILL_APP
10
 import android.os.Environment
10
 import android.os.Environment
11
 import android.os.Environment.DIRECTORY_DOWNLOADS
11
 import android.os.Environment.DIRECTORY_DOWNLOADS
12
+import android.os.storage.StorageManager
12
 import android.provider.Settings
13
 import android.provider.Settings
14
+import com.xhkjedu.manageapp.R
13
 import com.xhkjedu.manageapp.databinding.ActivityManageBinding
15
 import com.xhkjedu.manageapp.databinding.ActivityManageBinding
16
+import com.xhly.corelib.Const
14
 import com.xhly.corelib.base.viewmodel.CommonBaseViewModel
17
 import com.xhly.corelib.base.viewmodel.CommonBaseViewModel
15
 import com.xhly.corelib.eventbus.UIEvent
18
 import com.xhly.corelib.eventbus.UIEvent
16
 import com.xhly.corelib.utils.LogShow
19
 import com.xhly.corelib.utils.LogShow
17
 import com.xhly.manageapp.ManageApplication
20
 import com.xhly.manageapp.ManageApplication
21
+import com.xhly.manageapp.utils.CurrentAppSharedPreferencesUtils
22
+import com.xhly.manageapp.utils.StrategyUtils
23
+import com.xhly.manageapp.viewmodel.BaseViewModel
24
+import java.io.Console
18
 import java.io.File
25
 import java.io.File
19
 
26
 
20
 
27
 
21
 //安装白名单为添加机制,不在白名单时需要去移除
28
 //安装白名单为添加机制,不在白名单时需要去移除
22
-class ManageActivity : BaseActivity<CommonBaseViewModel, ActivityManageBinding>() {
29
+class ManageActivity : BaseActivity<BaseViewModel, ActivityManageBinding>() {
30
+    //存储退出管控
31
+    private val currentSpUtils by lazy { CurrentAppSharedPreferencesUtils.getInstance(this) }
23
     private var type = 1
32
     private var type = 1
24
     private var type1 = 0
33
     private var type1 = 0
25
     private var type2 = 0
34
     private var type2 = 0
35
     override fun initData() {
44
     override fun initData() {
36
         //同意运行时权限
45
         //同意运行时权限
37
         ManageApplication.setRuntimePermissions(true)
46
         ManageApplication.setRuntimePermissions(true)
47
+        viewModel.controlResultData.observe(this){
48
+            if(it){
49
+                currentSpUtils.saveJson(Const.EXIT_CONTROL,type)
50
+                StrategyUtils.releaseControl()
51
+            }else{
52
+                Toast(getString(R.string.codeerror))
53
+            }
54
+        }
38
     }
55
     }
39
 
56
 
40
 
57
 
41
     override fun initView() {
58
     override fun initView() {
59
+        mBinding.closemanageBtn.setOnClickListener {
60
+            StrategyUtils.releaseControl()
61
+        }
42
         mBinding.adbopenBtn.setOnClickListener {
62
         mBinding.adbopenBtn.setOnClickListener {
43
             Toast("设置" + ManageApplication.enableUsbDebugging(true))
63
             Toast("设置" + ManageApplication.enableUsbDebugging(true))
44
         }
64
         }

+ 5
- 1
app/src/main/java/com/xhly/manageapp/ui/login/activity/LoginActivity.kt View File

68
             ManageApplication.setSysTime(it)
68
             ManageApplication.setSysTime(it)
69
             Toast(getString(R.string.syncsucess))
69
             Toast(getString(R.string.syncsucess))
70
         }
70
         }
71
-        startWorkManager()
71
+        val exitControlFlag = currentSpUtils.getParam(Const.EXIT_CONTROL, false) as Boolean
72
+        //如果解除管控为真,则不在执行以下代码
73
+        if (!exitControlFlag){
74
+            startWorkManager()
75
+        }
72
     }
76
     }
73
 
77
 
74
     @SuppressLint("CheckResult")
78
     @SuppressLint("CheckResult")

+ 7
- 0
app/src/main/java/com/xhly/manageapp/ui/login/netservice/LoginService.kt View File

46
      */
46
      */
47
     @POST(UriAdress.SYNCTIME)
47
     @POST(UriAdress.SYNCTIME)
48
     suspend fun postSyncTime():ResponseData<Long>
48
     suspend fun postSyncTime():ResponseData<Long>
49
+
50
+    /**
51
+     * 退出管控调用这个接口,参数password
52
+     */
53
+    @POST(UriAdress.EXIT_CONTROL)
54
+    suspend fun postExitControl(@Body map:HashMap<String,Any>):ResponseData<CodeDetailBean>
55
+
49
 }
56
 }

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

1
 package com.xhly.manageapp.utils
1
 package com.xhly.manageapp.utils
2
 
2
 
3
 import android.app.ActivityManager
3
 import android.app.ActivityManager
4
+import android.content.ComponentName
4
 import android.content.Context
5
 import android.content.Context
6
+import android.content.Intent
5
 import com.google.gson.reflect.TypeToken
7
 import com.google.gson.reflect.TypeToken
8
+import com.hjq.toast.Toaster
6
 import com.xhly.corelib.Const
9
 import com.xhly.corelib.Const
7
 import com.xhly.corelib.bean.AppInfo
10
 import com.xhly.corelib.bean.AppInfo
8
 import com.xhly.corelib.utils.LogShow
11
 import com.xhly.corelib.utils.LogShow
14
 import com.xhly.manageapp.bean.strategy.AppTimeManageBean
17
 import com.xhly.manageapp.bean.strategy.AppTimeManageBean
15
 import com.xhly.manageapp.bean.strategy.StrategyBean
18
 import com.xhly.manageapp.bean.strategy.StrategyBean
16
 import java.util.Calendar
19
 import java.util.Calendar
20
+import kotlin.system.exitProcess
17
 
21
 
18
 object StrategyUtils {
22
 object StrategyUtils {
19
     public fun setStrategy(strategyBean: StrategyBean) {
23
     public fun setStrategy(strategyBean: StrategyBean) {
360
               ManageApplication.setUrlWhiteListEnable(false)
364
               ManageApplication.setUrlWhiteListEnable(false)
361
               //设置默认启动器
365
               //设置默认启动器
362
               ManageApplication.setCustomLauncher("com.tblenovo.launcher","com.android.iotlauncher.IotLauncher")
366
               ManageApplication.setCustomLauncher("com.tblenovo.launcher","com.android.iotlauncher.IotLauncher")
367
+              try {
368
+                  val launchIntent = Intent()
369
+                  launchIntent.setComponent(
370
+                      ComponentName(
371
+                          "com.tblenovo.launcher",
372
+                          "com.android.iotlauncher.IotLauncher"
373
+                      )
374
+                  )
375
+                  launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
376
+                  ManageApplication.instance?.startActivity(launchIntent)
377
+                  exitProcess(0)
378
+              }catch (e:Exception){
379
+                  Toaster.showLong("失败原因"+e.toString())
380
+              }
363
           }catch (e:Exception){
381
           }catch (e:Exception){
364
 
382
 
365
           }
383
           }

+ 4
- 0
corelib/src/main/java/com/xhly/corelib/Const.kt View File

14
      */
14
      */
15
     const val STOREAPPPKG="com.xhkjedu.xh_control_appstore"
15
     const val STOREAPPPKG="com.xhkjedu.xh_control_appstore"
16
 
16
 
17
+    /**
18
+     * 存储管控是否已解除的key
19
+     */
20
+    const val EXIT_CONTROL="EXIT_CONTROL"
17
     //用户id
21
     //用户id
18
     var USERID :Long?= 1L
22
     var USERID :Long?= 1L
19
 
23
 

Loading…
Cancel
Save