Browse Source

1.添加违规事件处理的socket消息接口。

2.修改推送事件处理的消息接口。
20241218TB223FC(测试jar包)
wangwanlei 10 months ago
parent
commit
55723605c4

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

@@ -171,11 +171,11 @@ class ManageApplication : MultiDexApplication() {
171 171
         }
172 172
 
173 173
         /**
174
-         * 打开关闭 wifi true:打开 wifi false:关闭 wifi
174
+         * 打开关闭 wifi true:打开 wifi false:关闭 wifi(禁用这个方法,防止用户误操作)
175 175
          */
176 176
         fun enableWifi(enableFlag: Boolean) {
177 177
             if (ModelNameUtils.IS_LianxX505f()) {
178
-                csdkManager?.enableWifi_v3(enableFlag)
178
+                //csdkManager?.enableWifi_v3(enableFlag)
179 179
             }
180 180
         }
181 181
 

+ 3
- 26
app/src/main/java/com/xhly/manageapp/bean/log/LogPushBean.kt View File

@@ -4,33 +4,10 @@ package com.xhly.manageapp.bean.log
4 4
  * 处理推送事件后的回调
5 5
  */
6 6
 class LogPushBean {
7
-    /** app只处理6,2,3,7
8
-     * 推送类型:1发送消息2解除限制3限制使用4更新策略5重启设备6恢复出厂7解除管控
7
+    /** app不处理1
8
+     * 1发送消息2解除锁定3锁定4更新策略5重启设备6恢复出厂7解除管控
9 9
      */
10 10
     var pushType = 0
11 11
 
12
-    /**
13
-     * 推送对象:1学生2班级
14
-     */
15
-    var pushObj = 1
16
-
17
-    /**
18
-     * 推送目标:班级ID(pushObj=2)
19
-     */
20
-    var pushObjid:Long? = null
21
-
22
-    /**
23
-     * :学生ids(pushObj=1)
24
-     */
25
-    var userids = longArrayOf()
26
-
27
-    /**
28
-     * 推送目标:学生名称/班级名称
29
-     */
30
-    var pushObjname = ""
31
-
32
-    /**
33
-     * 日志内容
34
-     */
35
-    var content = ""
12
+    var sn:String=""
36 13
 }

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

@@ -7,9 +7,10 @@ object UriAdress {
7 7
     const val LOGDOPERATEADD = "/logdoperate/add"
8 8
 
9 9
     /**
10
-     * 设备推送事件接口
10
+     * 设备推送事件接口(1不用处理)
11
+     * 推送类型:1发送消息2解除锁定3锁定4更新策略5重启设备6恢复出厂7解除管控
11 12
      */
12
-    const val LOGPUSH_ADD = "/logPush/add"
13
+    const val LOGPUSH_RECEIVED = "/logPush/received"
13 14
 
14 15
     /**
15 16
      *应用启动日志-添加,用来记录app的使用时长。
@@ -100,4 +101,18 @@ object UriAdress {
100 101
      * 退出管控
101 102
      */
102 103
     const val EXIT_CONTROL="/password/exit_control"
104
+
105
+    /**
106
+     * 违规事件发送socket消息后,请求接口然后处理锁定
107
+     * sn 设备号
108
+     *  pushType  3锁定
109
+     */
110
+    const val EDIT_LOCKED="/logdoperate/edit_locked"
111
+
112
+    /**
113
+     * 违规事件发送socket消息后,请求接口然后处理恢复出厂设置
114
+     * sn 设备号
115
+     * pushType  6恢复出厂设置
116
+     */
117
+    const val EDIT_RESETED="/logdoperate/edit_reseted"
103 118
 }

+ 1
- 1
app/src/main/java/com/xhly/manageapp/network/log/LogService.kt View File

@@ -40,6 +40,6 @@ interface LogService {
40 40
     /**
41 41
      * 设备--推送事件接口
42 42
      */
43
-    @POST(UriAdress.LOGPUSH_ADD)
43
+    @POST(UriAdress.LOGPUSH_RECEIVED)
44 44
     suspend fun postLogPushAdd(@Body logPushBean: LogPushBean)
45 45
 }

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

@@ -7,10 +7,16 @@ import android.content.Intent
7 7
 import android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DISABLED
8 8
 import android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_ENABLED
9 9
 import android.content.pm.PackageManager.DONT_KILL_APP
10
+import android.graphics.Color
10 11
 import android.os.Environment
11 12
 import android.os.Environment.DIRECTORY_DOWNLOADS
12 13
 import android.os.storage.StorageManager
13 14
 import android.provider.Settings
15
+import android.view.View
16
+import android.widget.EditText
17
+import android.widget.TextView
18
+import com.kongzue.dialogx.dialogs.CustomDialog
19
+import com.kongzue.dialogx.interfaces.OnBindView
14 20
 import com.xhkjedu.manageapp.R
15 21
 import com.xhkjedu.manageapp.databinding.ActivityManageBinding
16 22
 import com.xhly.corelib.Const
@@ -18,6 +24,7 @@ import com.xhly.corelib.base.viewmodel.CommonBaseViewModel
18 24
 import com.xhly.corelib.eventbus.UIEvent
19 25
 import com.xhly.corelib.utils.LogShow
20 26
 import com.xhly.manageapp.ManageApplication
27
+import com.xhly.manageapp.bean.user.UserBean
21 28
 import com.xhly.manageapp.utils.CurrentAppSharedPreferencesUtils
22 29
 import com.xhly.manageapp.utils.StrategyUtils
23 30
 import com.xhly.manageapp.viewmodel.BaseViewModel
@@ -57,7 +64,7 @@ class ManageActivity : BaseActivity<BaseViewModel, ActivityManageBinding>() {
57 64
 
58 65
     override fun initView() {
59 66
         mBinding.closemanageBtn.setOnClickListener {
60
-            StrategyUtils.releaseControl()
67
+            showEditDialog()
61 68
         }
62 69
         mBinding.adbopenBtn.setOnClickListener {
63 70
             Toast("设置" + ManageApplication.enableUsbDebugging(true))
@@ -259,6 +266,36 @@ class ManageActivity : BaseActivity<BaseViewModel, ActivityManageBinding>() {
259 266
         }
260 267
     }
261 268
 
269
+    private fun showEditDialog() {
270
+        CustomDialog.build()
271
+            .setCustomView(object : OnBindView<CustomDialog>(R.layout.layout_edit_dialog) {
272
+                override fun onBind(dialog: CustomDialog, v: View) {
273
+                    val titleTv = v.findViewById<TextView>(R.id.dialog_title_tv)
274
+                    val enterTv = v.findViewById<TextView>(R.id.dialog_enter_tv)
275
+                    val cancelTv = v.findViewById<TextView>(R.id.dialog_cancel_tv)
276
+                    val editText = v.findViewById<EditText>(R.id.dialog_et)
277
+                    editText.hint = getString(R.string.inputcode)
278
+                    titleTv.text = getString(R.string.exitcontrol)
279
+                    enterTv.setOnClickListener {
280
+                        val code = editText.text
281
+                        if ((!code.isNullOrBlank()) && code.length >= 6) {
282
+                            dialog.dismiss()
283
+                            try {
284
+                                viewModel.postExitControl(code.toString())
285
+                            } catch (e: Exception) {
286
+
287
+                            }
288
+                        }
289
+                    }
290
+                    cancelTv.setOnClickListener {
291
+                        dialog.dismiss()
292
+                    }
293
+                }
294
+            }).setCancelable(false).setMaskColor(Color.parseColor("#66000000"))
295
+            .setAlign(CustomDialog.ALIGN.CENTER).show()
296
+    }
297
+
298
+
262 299
     override fun finish() {
263 300
         super.finish()
264 301
         UIEvent("update").post()

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

@@ -234,22 +234,20 @@ class LoginActivity : BaseActivity<LoginViewModel, ActivityLoginBinding>() {
234 234
             }
235 235
 
236 236
             Const.CODE2002.toString() -> {
237
+                postLogPush(3)
237 238
                 spUtils.setParam(Const.DISABLEPAD, true)
238 239
                 useTimeStrategy()
239
-                postLogPush(3)
240 240
             }
241 241
 
242 242
             Const.CODE2003.toString() -> {
243
+                postLogPush(2)
243 244
                 spUtils.setParam(Const.DISABLEPAD, false)
244 245
                 useTimeStrategy()
245
-                postLogPush(2)
246 246
             }
247 247
 
248
-            Const.CODE2004.toString() -> {
249
-
250
-            }
251 248
 
252 249
             Const.CODE2005.toString() -> {
250
+                postLogPush(5)
253 251
                 ManageApplication.rebootDevice()
254 252
             }
255 253
 
@@ -329,13 +327,7 @@ class LoginActivity : BaseActivity<LoginViewModel, ActivityLoginBinding>() {
329 327
     private fun postLogPush(pushType:Int){
330 328
         val pushBean=LogPushBean()
331 329
         pushBean.pushType=pushType
332
-        pushBean.pushObjid=Const.SCHOOLID
333
-        Const.USERID?.let {
334
-            pushBean.userids= longArrayOf(it)
335
-        }
336
-        Const.USERNAME?.let {
337
-            pushBean.pushObjname=it
338
-        }
330
+        pushBean.sn=ManageApplication.getDeviceInfo()?:""
339 331
         viewModel.postLogPushAdd(pushBean)
340 332
     }
341 333
 

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

@@ -53,4 +53,19 @@ interface LoginService {
53 53
     @POST(UriAdress.EXIT_CONTROL)
54 54
     suspend fun postExitControl(@Body map:HashMap<String,Any>):ResponseData<CodeDetailBean>
55 55
 
56
+    /**
57
+     * 违规事件发送socket消息后,请求接口然后处理锁定
58
+     * sn 设备号
59
+     *  pushType  3锁定
60
+     */
61
+    @POST(UriAdress.EDIT_LOCKED)
62
+    suspend fun postExitLocked(@Body map:HashMap<String,Any>):ResponseData<CodeDetailBean>
63
+
64
+    /**
65
+     * 违规事件发送socket消息后,请求接口然后处理恢复出厂设置
66
+     * sn 设备号
67
+     * pushType  6恢复出厂设置
68
+     */
69
+    @POST(UriAdress.EDIT_RESETED)
70
+    suspend fun postExitReseted(@Body map:HashMap<String,Any>):ResponseData<CodeDetailBean>
56 71
 }

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

@@ -12,7 +12,6 @@ import android.graphics.Color
12 12
 import android.graphics.drawable.Drawable
13 13
 import android.os.Build
14 14
 import android.provider.Settings
15
-import android.text.TextUtils
16 15
 import android.view.View
17 16
 import android.widget.Button
18 17
 import android.widget.EditText
@@ -106,11 +105,11 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
106 105
         viewModel.listAppData.observe(this) { modelList ->
107 106
             //存储商店应用包名到本地
108 107
             val appNameList = arrayListOf<String>()
109
-            val whiteList= arrayListOf<String>()
108
+            val whiteList = arrayListOf<String>()
110 109
             modelList.forEach {
111 110
                 appNameList.add(it.appPackage)
112
-                if (it.whited==1){
113
-                   whiteList.add(it.appPackage)
111
+                if (it.whited == 1) {
112
+                    whiteList.add(it.appPackage)
114 113
                 }
115 114
             }
116 115
             ManageApplication.addAppWhiteRule(whiteList)
@@ -136,7 +135,7 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
136 135
                 LogShow("${app.name},被冻结" + (filter.isEmpty() && appInfos.isEmpty()))
137 136
                 if (filter.isEmpty() && appInfos.isEmpty()) {
138 137
                     //ManageApplication.setPackageEnabled(app.packageName, (filter.isNotEmpty()))
139
-                     ManageApplication.uninstallPackage(app.packageName)
138
+                    ManageApplication.uninstallPackage(app.packageName)
140 139
                 }
141 140
             }
142 141
         }
@@ -238,6 +237,19 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
238 237
                 Toast(getString(R.string.codeerror))
239 238
             }
240 239
         }
240
+        viewModel.lockResultData.observe(this){
241
+            if (it){
242
+                spUtils.setParam(Const.DISABLEPAD, true)
243
+                startIntentActivity(MainActivity().javaClass)
244
+                val appList = AppUtils.GetAppList(this)
245
+                StrategyUtils.clearMemory(this, appList)
246
+            }
247
+        }
248
+        viewModel.resetlResultData.observe(this){
249
+            if (it){
250
+                ManageApplication.launchFactoryReset()
251
+            }
252
+        }
241 253
         startWorkManager()
242 254
     }
243 255
 
@@ -253,11 +265,19 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
253 265
         }
254 266
         mBinding.loginoutIv.setOnClickListener {
255 267
             val schoolDeviceSetBean = StrategyUtils.getSchoolDeviceSetBean(this@MainActivity)
268
+            //禁用注销则需要输入密码才能注销,不限制则直接注销登录
256 269
             if (schoolDeviceSetBean != null && schoolDeviceSetBean.logout == 1) {
257 270
                 //禁用注销
258
-                return@setOnClickListener
259
-            } else {
260 271
                 showEditDialog()
272
+            } else {
273
+                try {
274
+                    val userBean = spUtils.getFromJson(
275
+                        Const.USERINFO, UserBean().javaClass
276
+                    ) as UserBean
277
+                    viewModel.loginOut(userBean.userid.toString(), "")
278
+                } catch (e: Exception) {
279
+
280
+                }
261 281
             }
262 282
         }
263 283
         mBinding.codeenterCv.setOnClickListener {
@@ -363,14 +383,14 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
363 383
             Const.USERID = it.userid
364 384
             Const.USERNAME = it.username.toString()
365 385
             viewModel.postDevicesetDetail(it.schoolid)
366
-            val name=StringBuffer()
367
-            if (!it.schoolName.isNullOrBlank()){
386
+            val name = StringBuffer()
387
+            if (!it.schoolName.isNullOrBlank()) {
368 388
                 name.append(it.schoolName)
369 389
             }
370
-            if (!it.classname.isNullOrBlank()){
390
+            if (!it.classname.isNullOrBlank()) {
371 391
                 name.append(it.classname)
372 392
             }
373
-            mBinding.userschoolTv.text =name.toString()
393
+            mBinding.userschoolTv.text = name.toString()
374 394
         }
375 395
         viewModel.postWallpaperPad()
376 396
         viewModel.updateStrategy()
@@ -580,12 +600,14 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
580 600
             }
581 601
 
582 602
             Const.CODE2004.toString() -> {
603
+                postLogPush(4)
583 604
                 //请求接口更新策略
584 605
                 viewModel.uploadAppStrategy()
585 606
                 viewModel.updateStrategy()
586 607
             }
587 608
 
588 609
             Const.CODE2005.toString() -> {
610
+                postLogPush(5)
589 611
                 ManageApplication.rebootDevice()
590 612
             }
591 613
 
@@ -706,19 +728,25 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
706 728
             Const.ACCOUNTLOGINOUT -> {
707 729
                 loginOut()
708 730
             }
731
+
732
+            Const.CODE3002.toString() -> {
733
+                val deviceInfo = ManageApplication.getDeviceInfo()
734
+                val sn= deviceInfo ?: ""
735
+                viewModel.postExitLocked(sn)
736
+            }
737
+
738
+            Const.CODE3006.toString() -> {
739
+                val deviceInfo = ManageApplication.getDeviceInfo()
740
+                val sn= deviceInfo ?: ""
741
+                viewModel.postExitReseted(sn)
742
+            }
709 743
         }
710 744
     }
711 745
 
712 746
     private fun postLogPush(pushType: Int) {
713 747
         val pushBean = LogPushBean()
714 748
         pushBean.pushType = pushType
715
-        pushBean.pushObjid = Const.SCHOOLID
716
-        Const.USERID?.let {
717
-            pushBean.userids = longArrayOf(it)
718
-        }
719
-        Const.USERNAME?.let {
720
-            pushBean.pushObjname = it
721
-        }
749
+        pushBean.sn=ManageApplication.getDeviceInfo()?:""
722 750
         viewModel.postLogPushAdd(pushBean)
723 751
     }
724 752
 
@@ -736,15 +764,15 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
736 764
                         Const.FIRSTAPPLIST,
737 765
                         ArrayList<String>().javaClass
738 766
                     ) as ArrayList<String>
739
-                val removeList= arrayListOf<AppInfo>()
740
-               currentList.forEach {pkg->
741
-                   //学校控制之外的预装应用加入移除集合
742
-                   if (!Const.schoolSetAppList.contains(pkg)){
743
-                       appList.filter { it.packageName==pkg }.forEach {
744
-                           removeList.add(it)
745
-                       }
746
-                   }
747
-               }
767
+                val removeList = arrayListOf<AppInfo>()
768
+                currentList.forEach { pkg ->
769
+                    //学校控制之外的预装应用加入移除集合
770
+                    if (!Const.schoolSetAppList.contains(pkg)) {
771
+                        appList.filter { it.packageName == pkg }.forEach {
772
+                            removeList.add(it)
773
+                        }
774
+                    }
775
+                }
748 776
                 //移除学校控制之外预装应用
749 777
                 appList.removeAll(removeList)
750 778
             } catch (e: Exception) {

+ 48
- 1
app/src/main/java/com/xhly/manageapp/viewmodel/BaseViewModel.kt View File

@@ -18,6 +18,11 @@ open class BaseViewModel : CommonBaseViewModel() {
18 18
     val timeResultData: LiveData<Long> = timeResult
19 19
     private val controlResult = MutableLiveData<Boolean>()
20 20
     val controlResultData: LiveData<Boolean> = controlResult
21
+    private val lockResult = MutableLiveData<Boolean>()
22
+    val lockResultData: LiveData<Boolean> = lockResult
23
+    private val resetResult = MutableLiveData<Boolean>()
24
+    val resetlResultData: LiveData<Boolean> = resetResult
25
+
21 26
     /**
22 27
      * 解除当前锁屏
23 28
      */
@@ -75,7 +80,7 @@ open class BaseViewModel : CommonBaseViewModel() {
75 80
     fun postExitControl(password:String){
76 81
         launchUI {
77 82
             val map=HashMap<String,Any>()
78
-            map[password]=password
83
+            map["password"]=password
79 84
             val result= loginService.postExitControl(map)
80 85
             if (result.code==0){
81 86
                 val codeDetailBean = result.obj
@@ -87,4 +92,46 @@ open class BaseViewModel : CommonBaseViewModel() {
87 92
             }
88 93
         }
89 94
     }
95
+
96
+    /**
97
+     * 违规事件发送socket消息后,请求接口然后处理锁定
98
+     * sn 设备号
99
+     *  pushType  3锁定
100
+     */
101
+    fun postExitLocked(sn:String,pushType:Int=3){
102
+        launchUI {
103
+            val map=HashMap<String,Any>()
104
+            map["sn"]=sn
105
+            map["pushType"]=pushType
106
+            val result = loginService.postExitLocked(map)
107
+            if (result.code==0){
108
+                lockResult.value=true
109
+            }else{
110
+                if (!result.msg.isNullOrEmpty()){
111
+                    netMessage.value=result.msg
112
+                }
113
+            }
114
+        }
115
+    }
116
+
117
+    /**
118
+     * 违规事件发送socket消息后,请求接口然后处理恢复出厂设置
119
+     * sn 设备号
120
+     * pushType  6恢复出厂设置
121
+     */
122
+    fun postExitReseted(sn:String,pushType:Int=6){
123
+        launchUI {
124
+            val map=HashMap<String,Any>()
125
+            map["sn"]=sn
126
+            map["pushType"]=pushType
127
+            val result = loginService.postExitReseted(map)
128
+            if (result.code==0){
129
+                resetResult.value=true
130
+            }else{
131
+                if (!result.msg.isNullOrEmpty()){
132
+                    netMessage.value=result.msg
133
+                }
134
+            }
135
+        }
136
+    }
90 137
 }

+ 6
- 2
corelib/src/main/java/com/xhly/corelib/Const.kt View File

@@ -93,11 +93,15 @@ object Const {
93 93
     const val CODE2007 = 2007
94 94
 
95 95
 
96
-    //违规事件自动调用的限制使用
96
+    /**
97
+     * 违规事件自动调用的锁定
98
+     */
97 99
     const val CODE3002 = 3002
98 100
 
99 101
 
100
-    //违规事件自动调用的恢复出厂设置
102
+    /**
103
+     * 违规事件自动调用的恢复出厂设置
104
+     */
101 105
     const val CODE3006 = 3006
102 106
 
103 107
     //消息确认回发

Loading…
Cancel
Save