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
         }
171
         }
172
 
172
 
173
         /**
173
         /**
174
-         * 打开关闭 wifi true:打开 wifi false:关闭 wifi
174
+         * 打开关闭 wifi true:打开 wifi false:关闭 wifi(禁用这个方法,防止用户误操作)
175
          */
175
          */
176
         fun enableWifi(enableFlag: Boolean) {
176
         fun enableWifi(enableFlag: Boolean) {
177
             if (ModelNameUtils.IS_LianxX505f()) {
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
  * 处理推送事件后的回调
4
  * 处理推送事件后的回调
5
  */
5
  */
6
 class LogPushBean {
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
     var pushType = 0
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
     const val LOGDOPERATEADD = "/logdoperate/add"
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
      *应用启动日志-添加,用来记录app的使用时长。
16
      *应用启动日志-添加,用来记录app的使用时长。
100
      * 退出管控
101
      * 退出管控
101
      */
102
      */
102
     const val EXIT_CONTROL="/password/exit_control"
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
     /**
40
     /**
41
      * 设备--推送事件接口
41
      * 设备--推送事件接口
42
      */
42
      */
43
-    @POST(UriAdress.LOGPUSH_ADD)
43
+    @POST(UriAdress.LOGPUSH_RECEIVED)
44
     suspend fun postLogPushAdd(@Body logPushBean: LogPushBean)
44
     suspend fun postLogPushAdd(@Body logPushBean: LogPushBean)
45
 }
45
 }

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

7
 import android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DISABLED
7
 import android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_DISABLED
8
 import android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_ENABLED
8
 import android.content.pm.PackageManager.COMPONENT_ENABLED_STATE_ENABLED
9
 import android.content.pm.PackageManager.DONT_KILL_APP
9
 import android.content.pm.PackageManager.DONT_KILL_APP
10
+import android.graphics.Color
10
 import android.os.Environment
11
 import android.os.Environment
11
 import android.os.Environment.DIRECTORY_DOWNLOADS
12
 import android.os.Environment.DIRECTORY_DOWNLOADS
12
 import android.os.storage.StorageManager
13
 import android.os.storage.StorageManager
13
 import android.provider.Settings
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
 import com.xhkjedu.manageapp.R
20
 import com.xhkjedu.manageapp.R
15
 import com.xhkjedu.manageapp.databinding.ActivityManageBinding
21
 import com.xhkjedu.manageapp.databinding.ActivityManageBinding
16
 import com.xhly.corelib.Const
22
 import com.xhly.corelib.Const
18
 import com.xhly.corelib.eventbus.UIEvent
24
 import com.xhly.corelib.eventbus.UIEvent
19
 import com.xhly.corelib.utils.LogShow
25
 import com.xhly.corelib.utils.LogShow
20
 import com.xhly.manageapp.ManageApplication
26
 import com.xhly.manageapp.ManageApplication
27
+import com.xhly.manageapp.bean.user.UserBean
21
 import com.xhly.manageapp.utils.CurrentAppSharedPreferencesUtils
28
 import com.xhly.manageapp.utils.CurrentAppSharedPreferencesUtils
22
 import com.xhly.manageapp.utils.StrategyUtils
29
 import com.xhly.manageapp.utils.StrategyUtils
23
 import com.xhly.manageapp.viewmodel.BaseViewModel
30
 import com.xhly.manageapp.viewmodel.BaseViewModel
57
 
64
 
58
     override fun initView() {
65
     override fun initView() {
59
         mBinding.closemanageBtn.setOnClickListener {
66
         mBinding.closemanageBtn.setOnClickListener {
60
-            StrategyUtils.releaseControl()
67
+            showEditDialog()
61
         }
68
         }
62
         mBinding.adbopenBtn.setOnClickListener {
69
         mBinding.adbopenBtn.setOnClickListener {
63
             Toast("设置" + ManageApplication.enableUsbDebugging(true))
70
             Toast("设置" + ManageApplication.enableUsbDebugging(true))
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
     override fun finish() {
299
     override fun finish() {
263
         super.finish()
300
         super.finish()
264
         UIEvent("update").post()
301
         UIEvent("update").post()

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

234
             }
234
             }
235
 
235
 
236
             Const.CODE2002.toString() -> {
236
             Const.CODE2002.toString() -> {
237
+                postLogPush(3)
237
                 spUtils.setParam(Const.DISABLEPAD, true)
238
                 spUtils.setParam(Const.DISABLEPAD, true)
238
                 useTimeStrategy()
239
                 useTimeStrategy()
239
-                postLogPush(3)
240
             }
240
             }
241
 
241
 
242
             Const.CODE2003.toString() -> {
242
             Const.CODE2003.toString() -> {
243
+                postLogPush(2)
243
                 spUtils.setParam(Const.DISABLEPAD, false)
244
                 spUtils.setParam(Const.DISABLEPAD, false)
244
                 useTimeStrategy()
245
                 useTimeStrategy()
245
-                postLogPush(2)
246
             }
246
             }
247
 
247
 
248
-            Const.CODE2004.toString() -> {
249
-
250
-            }
251
 
248
 
252
             Const.CODE2005.toString() -> {
249
             Const.CODE2005.toString() -> {
250
+                postLogPush(5)
253
                 ManageApplication.rebootDevice()
251
                 ManageApplication.rebootDevice()
254
             }
252
             }
255
 
253
 
329
     private fun postLogPush(pushType:Int){
327
     private fun postLogPush(pushType:Int){
330
         val pushBean=LogPushBean()
328
         val pushBean=LogPushBean()
331
         pushBean.pushType=pushType
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
         viewModel.postLogPushAdd(pushBean)
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
     @POST(UriAdress.EXIT_CONTROL)
53
     @POST(UriAdress.EXIT_CONTROL)
54
     suspend fun postExitControl(@Body map:HashMap<String,Any>):ResponseData<CodeDetailBean>
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
 import android.graphics.drawable.Drawable
12
 import android.graphics.drawable.Drawable
13
 import android.os.Build
13
 import android.os.Build
14
 import android.provider.Settings
14
 import android.provider.Settings
15
-import android.text.TextUtils
16
 import android.view.View
15
 import android.view.View
17
 import android.widget.Button
16
 import android.widget.Button
18
 import android.widget.EditText
17
 import android.widget.EditText
106
         viewModel.listAppData.observe(this) { modelList ->
105
         viewModel.listAppData.observe(this) { modelList ->
107
             //存储商店应用包名到本地
106
             //存储商店应用包名到本地
108
             val appNameList = arrayListOf<String>()
107
             val appNameList = arrayListOf<String>()
109
-            val whiteList= arrayListOf<String>()
108
+            val whiteList = arrayListOf<String>()
110
             modelList.forEach {
109
             modelList.forEach {
111
                 appNameList.add(it.appPackage)
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
             ManageApplication.addAppWhiteRule(whiteList)
115
             ManageApplication.addAppWhiteRule(whiteList)
136
                 LogShow("${app.name},被冻结" + (filter.isEmpty() && appInfos.isEmpty()))
135
                 LogShow("${app.name},被冻结" + (filter.isEmpty() && appInfos.isEmpty()))
137
                 if (filter.isEmpty() && appInfos.isEmpty()) {
136
                 if (filter.isEmpty() && appInfos.isEmpty()) {
138
                     //ManageApplication.setPackageEnabled(app.packageName, (filter.isNotEmpty()))
137
                     //ManageApplication.setPackageEnabled(app.packageName, (filter.isNotEmpty()))
139
-                     ManageApplication.uninstallPackage(app.packageName)
138
+                    ManageApplication.uninstallPackage(app.packageName)
140
                 }
139
                 }
141
             }
140
             }
142
         }
141
         }
238
                 Toast(getString(R.string.codeerror))
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
         startWorkManager()
253
         startWorkManager()
242
     }
254
     }
243
 
255
 
253
         }
265
         }
254
         mBinding.loginoutIv.setOnClickListener {
266
         mBinding.loginoutIv.setOnClickListener {
255
             val schoolDeviceSetBean = StrategyUtils.getSchoolDeviceSetBean(this@MainActivity)
267
             val schoolDeviceSetBean = StrategyUtils.getSchoolDeviceSetBean(this@MainActivity)
268
+            //禁用注销则需要输入密码才能注销,不限制则直接注销登录
256
             if (schoolDeviceSetBean != null && schoolDeviceSetBean.logout == 1) {
269
             if (schoolDeviceSetBean != null && schoolDeviceSetBean.logout == 1) {
257
                 //禁用注销
270
                 //禁用注销
258
-                return@setOnClickListener
259
-            } else {
260
                 showEditDialog()
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
         mBinding.codeenterCv.setOnClickListener {
283
         mBinding.codeenterCv.setOnClickListener {
363
             Const.USERID = it.userid
383
             Const.USERID = it.userid
364
             Const.USERNAME = it.username.toString()
384
             Const.USERNAME = it.username.toString()
365
             viewModel.postDevicesetDetail(it.schoolid)
385
             viewModel.postDevicesetDetail(it.schoolid)
366
-            val name=StringBuffer()
367
-            if (!it.schoolName.isNullOrBlank()){
386
+            val name = StringBuffer()
387
+            if (!it.schoolName.isNullOrBlank()) {
368
                 name.append(it.schoolName)
388
                 name.append(it.schoolName)
369
             }
389
             }
370
-            if (!it.classname.isNullOrBlank()){
390
+            if (!it.classname.isNullOrBlank()) {
371
                 name.append(it.classname)
391
                 name.append(it.classname)
372
             }
392
             }
373
-            mBinding.userschoolTv.text =name.toString()
393
+            mBinding.userschoolTv.text = name.toString()
374
         }
394
         }
375
         viewModel.postWallpaperPad()
395
         viewModel.postWallpaperPad()
376
         viewModel.updateStrategy()
396
         viewModel.updateStrategy()
580
             }
600
             }
581
 
601
 
582
             Const.CODE2004.toString() -> {
602
             Const.CODE2004.toString() -> {
603
+                postLogPush(4)
583
                 //请求接口更新策略
604
                 //请求接口更新策略
584
                 viewModel.uploadAppStrategy()
605
                 viewModel.uploadAppStrategy()
585
                 viewModel.updateStrategy()
606
                 viewModel.updateStrategy()
586
             }
607
             }
587
 
608
 
588
             Const.CODE2005.toString() -> {
609
             Const.CODE2005.toString() -> {
610
+                postLogPush(5)
589
                 ManageApplication.rebootDevice()
611
                 ManageApplication.rebootDevice()
590
             }
612
             }
591
 
613
 
706
             Const.ACCOUNTLOGINOUT -> {
728
             Const.ACCOUNTLOGINOUT -> {
707
                 loginOut()
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
     private fun postLogPush(pushType: Int) {
746
     private fun postLogPush(pushType: Int) {
713
         val pushBean = LogPushBean()
747
         val pushBean = LogPushBean()
714
         pushBean.pushType = pushType
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
         viewModel.postLogPushAdd(pushBean)
750
         viewModel.postLogPushAdd(pushBean)
723
     }
751
     }
724
 
752
 
736
                         Const.FIRSTAPPLIST,
764
                         Const.FIRSTAPPLIST,
737
                         ArrayList<String>().javaClass
765
                         ArrayList<String>().javaClass
738
                     ) as ArrayList<String>
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
                 appList.removeAll(removeList)
777
                 appList.removeAll(removeList)
750
             } catch (e: Exception) {
778
             } catch (e: Exception) {

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

18
     val timeResultData: LiveData<Long> = timeResult
18
     val timeResultData: LiveData<Long> = timeResult
19
     private val controlResult = MutableLiveData<Boolean>()
19
     private val controlResult = MutableLiveData<Boolean>()
20
     val controlResultData: LiveData<Boolean> = controlResult
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
     fun postExitControl(password:String){
80
     fun postExitControl(password:String){
76
         launchUI {
81
         launchUI {
77
             val map=HashMap<String,Any>()
82
             val map=HashMap<String,Any>()
78
-            map[password]=password
83
+            map["password"]=password
79
             val result= loginService.postExitControl(map)
84
             val result= loginService.postExitControl(map)
80
             if (result.code==0){
85
             if (result.code==0){
81
                 val codeDetailBean = result.obj
86
                 val codeDetailBean = result.obj
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
     const val CODE2007 = 2007
93
     const val CODE2007 = 2007
94
 
94
 
95
 
95
 
96
-    //违规事件自动调用的限制使用
96
+    /**
97
+     * 违规事件自动调用的锁定
98
+     */
97
     const val CODE3002 = 3002
99
     const val CODE3002 = 3002
98
 
100
 
99
 
101
 
100
-    //违规事件自动调用的恢复出厂设置
102
+    /**
103
+     * 违规事件自动调用的恢复出厂设置
104
+     */
101
     const val CODE3006 = 3006
105
     const val CODE3006 = 3006
102
 
106
 
103
     //消息确认回发
107
     //消息确认回发

Loading…
Cancel
Save