Просмотр исходного кода

1.添加广播监听熄屏和亮屏处理设备提醒。

2.添加SN校验接口。
20241218TB223FC(测试jar包)
wangwanlei 11 месяцев назад
Родитель
Сommit
98616e2c3a

+ 19
- 0
app/src/main/java/com/xhly/manageapp/broadcastreceiver/ScreenReceiver.kt Просмотреть файл

1
+package com.xhly.manageapp.broadcastreceiver
2
+
3
+import android.content.BroadcastReceiver
4
+import android.content.Context
5
+import android.content.Intent
6
+import com.xhly.corelib.Const
7
+import com.xhly.corelib.eventbus.UIEvent
8
+import com.xhly.corelib.utils.LogShow
9
+
10
+class ScreenReceiver: BroadcastReceiver() {
11
+    override fun onReceive(context: Context, intent: Intent) {
12
+        val action = intent.action
13
+        if (Intent.ACTION_SCREEN_ON==action){
14
+            UIEvent(Const.ACTION_SCREEN_ON).post()
15
+        }else if (Intent.ACTION_SCREEN_OFF==action){
16
+            UIEvent(Const.ACTION_SCREEN_OFF).post()
17
+        }
18
+    }
19
+}

+ 4
- 1
app/src/main/java/com/xhly/manageapp/network/UriAdress.kt Просмотреть файл

139
      */
139
      */
140
     const val AUTOAPP_DETAIL="/autoapp/detail_pad"
140
     const val AUTOAPP_DETAIL="/autoapp/detail_pad"
141
 
141
 
142
-
142
+    /**
143
+     * 校验sn,为true则退出
144
+     */
145
+    const val CHECK_SN="/ulogin/check_sn"
143
 }
146
 }

+ 6
- 0
app/src/main/java/com/xhly/manageapp/ui/login/netservice/LoginService.kt Просмотреть файл

86
      */
86
      */
87
     @POST(UriAdress.AUTOAPP_DETAIL)
87
     @POST(UriAdress.AUTOAPP_DETAIL)
88
     suspend fun postAutoAppDetail(@Body map: HashMap<String, Any>):ResponseData<AutoAppBean>
88
     suspend fun postAutoAppDetail(@Body map: HashMap<String, Any>):ResponseData<AutoAppBean>
89
+
90
+    /**
91
+     * 校验sn,true需要退出 false不需要退出
92
+     */
93
+    @POST(UriAdress.CHECK_SN)
94
+    suspend fun postCheckSn(@Body map: HashMap<String, Any>):ResponseData<Boolean>
89
 }
95
 }

+ 41
- 3
app/src/main/java/com/xhly/manageapp/ui/main/activity/MainActivity.kt Просмотреть файл

72
 import com.xhly.manageapp.bean.user.UserBean
72
 import com.xhly.manageapp.bean.user.UserBean
73
 import com.xhly.manageapp.broadcastreceiver.AppInstallReceiver
73
 import com.xhly.manageapp.broadcastreceiver.AppInstallReceiver
74
 import com.xhly.manageapp.broadcastreceiver.NetConnectReceiver
74
 import com.xhly.manageapp.broadcastreceiver.NetConnectReceiver
75
+import com.xhly.manageapp.broadcastreceiver.ScreenReceiver
75
 import com.xhly.manageapp.service.ManageAccessibilityService
76
 import com.xhly.manageapp.service.ManageAccessibilityService
76
 import com.xhly.manageapp.service.websocket.AppSocket
77
 import com.xhly.manageapp.service.websocket.AppSocket
77
 import com.xhly.manageapp.ui.ManageActivity
78
 import com.xhly.manageapp.ui.ManageActivity
98
 
99
 
99
     private var mMyInstallReceiver: AppInstallReceiver? = null
100
     private var mMyInstallReceiver: AppInstallReceiver? = null
100
     private var netConnectReceiver:NetConnectReceiver?=null
101
     private var netConnectReceiver:NetConnectReceiver?=null
102
+    private var mScreenReceiver:ScreenReceiver?=null
101
     private var dataList: ArrayList<AppInfo> = arrayListOf()
103
     private var dataList: ArrayList<AppInfo> = arrayListOf()
102
     private var userBean: UserBean? = null
104
     private var userBean: UserBean? = null
103
     private var timer: Timer? = null
105
     private var timer: Timer? = null
120
     private var canClickFlag=false
122
     private var canClickFlag=false
121
     //百度定位
123
     //百度定位
122
     private var locationClient:LocationClient?=null
124
     private var locationClient:LocationClient?=null
125
+
126
+    //上次提醒时长,用来设置是否重新设置提醒任务
127
+    private var lastTipsTimeLong=0
123
     override fun getBinding() = ActivityMainBinding.inflate(layoutInflater)
128
     override fun getBinding() = ActivityMainBinding.inflate(layoutInflater)
124
 
129
 
125
     @SuppressLint("CheckResult")
130
     @SuppressLint("CheckResult")
159
         // checkAccessibility(this)
164
         // checkAccessibility(this)
160
         registerAppInstallReceiver()
165
         registerAppInstallReceiver()
161
         registerNetConnectReceiver()
166
         registerNetConnectReceiver()
167
+        registerScreenReceiver()
162
         /*
168
         /*
163
          使用情况权限
169
          使用情况权限
164
          val permissionIntent = Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS)
170
          val permissionIntent = Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS)
914
         }
920
         }
915
     }
921
     }
916
 
922
 
917
-    private fun startTimeTask(bean: SchoolDeviceSetBean) {
918
-        if (bean.remindDuration == 1 && bean.duration > 0) {
923
+    private fun startTimeTask(bean: SchoolDeviceSetBean,fromBroadcast:Boolean=false) {
924
+        //和上次时长不一致才使用,但是从广播调用时不用和上次时长对比
925
+        if (bean.remindDuration == 1 && bean.duration > 0&&(lastTipsTimeLong!=bean.duration||fromBroadcast)) {
919
             //如果设置的有时间则执行任务
926
             //如果设置的有时间则执行任务
920
             try {
927
             try {
921
                 timer?.cancel()
928
                 timer?.cancel()
923
             } catch (e: Exception) {
930
             } catch (e: Exception) {
924
 
931
 
925
             }
932
             }
933
+            lastTipsTimeLong=bean.duration
926
             timer?.let {
934
             timer?.let {
927
                 timer?.schedule(object : TimerTask() {
935
                 timer?.schedule(object : TimerTask() {
928
                     override fun run() {
936
                     override fun run() {
929
                         Toast(getString(R.string.durationtips))
937
                         Toast(getString(R.string.durationtips))
930
                     }
938
                     }
931
-                }, bean.duration * 60 * 1000L, bean.duration * 60 * 1000L)
939
+                }, bean.duration * 60 * 1000L, bean.duration* 60 * 1000L)
932
             }
940
             }
933
         }
941
         }
934
         //如果设置的有时间则取消所有任务
942
         //如果设置的有时间则取消所有任务
1133
             Const.STARTSOCKET -> {
1141
             Const.STARTSOCKET -> {
1134
                 AppSocket.startSocket(this)
1142
                 AppSocket.startSocket(this)
1135
             }
1143
             }
1144
+
1145
+            Const.ACTION_SCREEN_ON->{
1146
+                StrategyUtils.getSchoolDeviceSetBean(this)?.let {
1147
+                    startTimeTask(it,true)
1148
+                }
1149
+            }
1150
+            Const.ACTION_SCREEN_OFF->{
1151
+                //取消定时任务
1152
+                if (timer != null) {
1153
+                    timer?.cancel()
1154
+                    timer = null
1155
+                }
1156
+                LogShow("关闭任务")
1157
+            }
1158
+            Const.ACCOUNTLOGINOUTSUCESS->{
1159
+                loginOutSucess()
1160
+            }
1136
         }
1161
         }
1137
     }
1162
     }
1138
 
1163
 
1268
         registerReceiver(netConnectReceiver, IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION))
1293
         registerReceiver(netConnectReceiver, IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION))
1269
     }
1294
     }
1270
 
1295
 
1296
+    /**
1297
+     * 熄屏注册监听
1298
+     */
1299
+    private fun registerScreenReceiver() {
1300
+        val filter = IntentFilter()
1301
+        filter.addAction(Intent.ACTION_SCREEN_ON)
1302
+        filter.addAction(Intent.ACTION_SCREEN_OFF)
1303
+        mScreenReceiver = ScreenReceiver()
1304
+        registerReceiver(mScreenReceiver, filter)
1305
+    }
1271
 
1306
 
1272
     private fun showEditDialog() {
1307
     private fun showEditDialog() {
1273
         if (accountDialog==null){
1308
         if (accountDialog==null){
1372
         netConnectReceiver?.let {
1407
         netConnectReceiver?.let {
1373
             unregisterReceiver(it)
1408
             unregisterReceiver(it)
1374
         }
1409
         }
1410
+        mScreenReceiver?.let {
1411
+            unregisterReceiver(it)
1412
+        }
1375
         LogShow("MainActivity被销毁")
1413
         LogShow("MainActivity被销毁")
1376
     }
1414
     }
1377
 
1415
 

+ 8
- 0
app/src/main/java/com/xhly/manageapp/workmanager/TimingWorker.kt Просмотреть файл

82
                 LogShow("没有位置问题"+e.toString())
82
                 LogShow("没有位置问题"+e.toString())
83
             }
83
             }
84
 */
84
 */
85
+            userBean?.let {
86
+                val map=HashMap<String,Any>()
87
+                map["sn"]=ManageApplication.getDeviceInfo()?:""
88
+                val postCheckSn = loginService.postCheckSn(map)
89
+                if (postCheckSn.code==0&&postCheckSn.obj){
90
+                    UIEvent(Const.ACCOUNTLOGINOUTSUCESS).post()
91
+                }
92
+            }
85
             //创建socket
93
             //创建socket
86
             userBean?.let {
94
             userBean?.let {
87
                 ManageApplication.instance?.let {
95
                 ManageApplication.instance?.let {

+ 20
- 1
corelib/src/main/java/com/xhly/corelib/Const.kt Просмотреть файл

1
 package com.xhly.corelib
1
 package com.xhly.corelib
2
 
2
 
3
+import android.content.Intent
4
+
3
 
5
 
4
 object Const {
6
 object Const {
5
     const val isDebug = false
7
     const val isDebug = false
9
 
11
 
10
     //记录点击返回的次数,超过10次请求策略
12
     //记录点击返回的次数,超过10次请求策略
11
     const val UPDATESTRATEGYNUM = 20
13
     const val UPDATESTRATEGYNUM = 20
14
+
15
+    /**
16
+     * 标记熄屏
17
+     */
18
+    const val ACTION_SCREEN_OFF="ACTION_SCREEN_OFF"
19
+
20
+    /**
21
+     * 标记亮屏
22
+     */
23
+    const val ACTION_SCREEN_ON="ACTION_SCREEN_ON"
24
+
12
     /**
25
     /**
13
      * 当前应用包名
26
      * 当前应用包名
14
      */
27
      */
79
      */
92
      */
80
      const val STARTSOCKET="STARTSOCKET"
93
      const val STARTSOCKET="STARTSOCKET"
81
     /**
94
     /**
82
-     * 标记推出1登录
95
+     * 标记推出登录
83
      */
96
      */
84
     const val ACCOUNTLOGINOUT = "ACCOUNTLOGINOUT"
97
     const val ACCOUNTLOGINOUT = "ACCOUNTLOGINOUT"
85
 
98
 
99
+    /**
100
+     * 标记直接退出,不调用接口
101
+     */
102
+    const val ACCOUNTLOGINOUTSUCESS = "ACCOUNTLOGINOUTSUCESS"
103
+
104
+
86
     /**
105
     /**
87
      * 调用安装app方法
106
      * 调用安装app方法
88
      */
107
      */

Загрузка…
Отмена
Сохранить