Browse Source

1.添加应用策略接口数据请求以及逻辑处理。

master
wangwanlei 11 months ago
parent
commit
b04aff62c4

+ 3
- 0
app/src/main/java/com/xhly/manageapp/AppAdapter.kt View File

@@ -12,6 +12,7 @@ import com.hjq.toast.Toaster
12 12
 import com.xhly.corelib.bean.AppInfo
13 13
 import com.xhly.corelib.utils.LogShow
14 14
 import com.xhly.manageapp.databinding.ItemAppBinding
15
+import com.xhly.manageapp.utils.StrategyUtils
15 16
 import java.util.Calendar
16 17
 
17 18
 class AppAdapter(var context: Context, var data: ArrayList<AppInfo>) :
@@ -66,6 +67,8 @@ class AppAdapter(var context: Context, var data: ArrayList<AppInfo>) :
66 67
                 instance.set(Calendar.MINUTE, 0)
67 68
                 var timeInMillis = instance.timeInMillis
68 69
                 context.startActivity(appInfo.intent)
70
+                var appTimeStrategy = StrategyUtils.getAppTimeStrategy(context, appInfo.packageName)
71
+                LogShow("可以打开吗"+appTimeStrategy)
69 72
                 /* if (currentTimeMillis>=timeInMillis){
70 73
                     context.startActivity(appInfo.intent)
71 74
                 }else{

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

@@ -121,7 +121,7 @@ class ManageApplication : MultiDexApplication() {
121 121
         }
122 122
 
123 123
         /**
124
-         * 打开关闭usb调试
124
+         * 打开关闭usb调试,true:打开
125 125
          */
126 126
         fun disallowUsbDebugging(enableFlag: Boolean) {
127 127
             if (ModelNameUtils.IS_LianxX505f()) {
@@ -253,7 +253,7 @@ class ManageApplication : MultiDexApplication() {
253 253
          */
254 254
         fun addWifiWhiteList(list: List<String>) {
255 255
             if (ModelNameUtils.IS_LianxX505f()) {
256
-                csdkManager?.addWifiWhiteList(list)
256
+                //csdkManager?.addWifiWhiteList(list)
257 257
             }
258 258
         }
259 259
 
@@ -262,10 +262,18 @@ class ManageApplication : MultiDexApplication() {
262 262
          */
263 263
         fun enableWifiWhiteList(enable: Boolean) {
264 264
             if (ModelNameUtils.IS_LianxX505f()) {
265
-                csdkManager?.enableWifiWhiteList(enable)
265
+                //csdkManager?.enableWifiWhiteList(enable)
266 266
             }
267 267
         }
268 268
 
269
+        /**
270
+         * 启用无障碍服务
271
+         */
272
+         fun enableAccessibility(){
273
+            if (ModelNameUtils.IS_LianxX505f()) {
274
+               //csdkManager?.enableAccessibility("com.xhly.manageapp","com.xhly.manageapp.service.TestService",true)
275
+            }
276
+         }
269 277
     }
270 278
 
271 279
     override fun onCreate() {
@@ -276,9 +284,10 @@ class ManageApplication : MultiDexApplication() {
276 284
         if (ModelNameUtils.IS_LianxX505f()) {
277 285
             //是505f则执行
278 286
             csdkManager = CSDKManager(this)
279
-            addInstallPackageWhiteList(arrayListOf("com.xhly.manageapp"))
287
+            addInstallPackageWhiteList(arrayListOf("com.xhly.manageapp","com.xhkjedu.xh_control_appstore"))
280 288
             // disableInstallation(false)
281 289
             setRuntimePermissions(true)
290
+            enableAccessibility()
282 291
         }
283 292
     }
284 293
 

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

@@ -11,5 +11,5 @@ interface StrategyService {
11 11
     suspend fun postDetailPad(): ResponseData<StrategyBean>
12 12
 
13 13
     @POST(UriAdress.APP_LISTPAD)
14
-    suspend fun postAppListPad():ResponseData<List<AppTimeManageBean>>
14
+    suspend fun postAppListPad():ResponseData<ArrayList<AppTimeManageBean>>
15 15
 }

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

@@ -91,6 +91,10 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
91 91
             spUtils.saveJson(Const.STRATEGYBEANKEY, it)
92 92
             StrategyUtils.setStrategy(it)
93 93
         }
94
+        viewModel.appStrategyData.observe(this) {
95
+            //存储app时间策略
96
+            spUtils.saveJson(Const.APPSTRATEGYBEANKEY, it)
97
+        }
94 98
         startWorkManager()
95 99
     }
96 100
 
@@ -112,7 +116,6 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
112 116
         }
113 117
         onBackPressedDispatcher.addCallback {
114 118
             //屏蔽返回
115
-
116 119
         }
117 120
     }
118 121
 
@@ -121,6 +124,7 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
121 124
         super.onResume()
122 125
         AppSocketService.lastPkgName = ""/*getAppInfo()*/
123 126
         viewModel.updateStrategy()
127
+        viewModel.uploadAppStrategy()
124 128
         useStrategy()
125 129
         try {
126 130
             var s =
@@ -140,7 +144,7 @@ class MainActivity : BaseActivity<MainViewModel, ActivityMainBinding>() {
140 144
                 spUtils.getFromJson(Const.STRATEGYBEANKEY, StrategyBean::class.java) as StrategyBean
141 145
             strategyBean?.let { bean ->
142 146
                 //获得是否在使用时间范围
143
-                block = StrategyUtils.getAppTimeStrategy(bean)
147
+                block = StrategyUtils.getPadTimeStrategy(bean)
144 148
             }
145 149
             if (Const.isDebug) {
146 150
                 //测试状态不锁定

+ 39
- 19
app/src/main/java/com/xhly/manageapp/ui/main/viewmodel/MainViewModel.kt View File

@@ -7,11 +7,11 @@ import com.xhly.corelib.network.RetrofitService
7 7
 import com.xhly.manageapp.bean.AppModel
8 8
 import com.xhly.manageapp.bean.ListAppBean
9 9
 import com.xhly.manageapp.bean.log.LogdOperateBean
10
+import com.xhly.manageapp.bean.strategy.AppTimeManageBean
10 11
 import com.xhly.manageapp.bean.strategy.StrategyBean
11 12
 import com.xhly.manageapp.network.app.AppService
12 13
 import com.xhly.manageapp.network.log.LogService
13 14
 import com.xhly.manageapp.network.strategy.StrategyService
14
-import kotlinx.coroutines.launch
15 15
 
16 16
 class MainViewModel : CommonBaseViewModel() {
17 17
     private val appService by lazy { RetrofitService.create<AppService>() }
@@ -19,8 +19,10 @@ class MainViewModel : CommonBaseViewModel() {
19 19
     private var logService = RetrofitService.create<LogService>()
20 20
     private val listData = MutableLiveData<ArrayList<AppModel>>()
21 21
     val listAppData: LiveData<ArrayList<AppModel>> = listData
22
-    private val strategy=MutableLiveData<StrategyBean>()
23
-    val strategyData=strategy
22
+    private val strategy = MutableLiveData<StrategyBean>()
23
+    val strategyData: LiveData<StrategyBean> = strategy
24
+    private val appStrategy = MutableLiveData<ArrayList<AppTimeManageBean>>()
25
+    val appStrategyData: LiveData<ArrayList<AppTimeManageBean>> = appStrategy
24 26
     fun getAppList() {
25 27
         launchUI {
26 28
             val postListApp = appService.postListApp(ListAppBean())
@@ -39,23 +41,41 @@ class MainViewModel : CommonBaseViewModel() {
39 41
     }
40 42
 
41 43
     fun updateStrategy() {
42
-          launchUI {
43
-              val postDetailPad = strategyService.postDetailPad()
44
-              if (postDetailPad.code == 0) {
45
-                  if (postDetailPad.obj != null) {
46
-                     strategy.value=postDetailPad.obj
47
-                  }
48
-              } else {
49
-                  if (!postDetailPad.msg.isNullOrEmpty()) {
50
-                      netMessage.value = postDetailPad.msg
51
-                  }
52
-              }
53
-          }
44
+        launchUI {
45
+            val postDetailPad = strategyService.postDetailPad()
46
+            if (postDetailPad.code == 0) {
47
+                if (postDetailPad.obj != null) {
48
+                    strategy.value = postDetailPad.obj
49
+                }
50
+            } else {
51
+                if (!postDetailPad.msg.isNullOrEmpty()) {
52
+                    netMessage.value = postDetailPad.msg
53
+                }
54
+            }
55
+        }
56
+    }
57
+
58
+    fun eventLog(operateBean: LogdOperateBean) {
59
+        launchUI {
60
+            logService.postLogdoperateAdd(operateBean)
61
+        }
54 62
     }
55 63
 
56
-     fun eventLog(operateBean: LogdOperateBean) {
57
-         launchUI {
58
-             logService.postLogdoperateAdd(operateBean)
59
-         }
64
+    fun uploadAppStrategy() {
65
+
66
+        launchUI {
67
+            val postAppListPad = strategyService.postAppListPad()
68
+            if (postAppListPad.code == 0) {
69
+                if (postAppListPad.obj != null && postAppListPad.obj.size > 0) {
70
+                    appStrategy.value = postAppListPad.obj
71
+                } else {
72
+                    appStrategy.value = arrayListOf()
73
+                }
74
+            } else {
75
+                if (!postAppListPad.msg.isNullOrEmpty()) {
76
+                    netMessage.value = postAppListPad.msg
77
+                }
78
+            }
79
+        }
60 80
     }
61 81
 }

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

@@ -1,6 +1,7 @@
1 1
 package com.xhly.manageapp.utils
2 2
 
3 3
 import android.content.Context
4
+import com.google.gson.reflect.TypeToken
4 5
 import com.xhly.corelib.Const
5 6
 import com.xhly.corelib.utils.LogShow
6 7
 import com.xhly.corelib.utils.SharedPreferencesUtils
@@ -56,9 +57,9 @@ object StrategyUtils {
56 57
         }
57 58
 
58 59
         //违规处理,直接在事件触发时判断,不再这里处理
59
-        if (strategyBean.hasviolate == 1) {
60
+        /*if (strategyBean.hasviolate == 1) {
60 61
 
61
-        }
62
+        }*/
62 63
     }
63 64
 
64 65
     private fun deviceStrategy(strategyBean: StrategyBean) {
@@ -160,12 +161,14 @@ object StrategyUtils {
160 161
     ): Boolean {
161 162
         try {
162 163
             val spUtils by lazy { SharedPreferencesUtils.getInstance(context) }
163
-            val appTimeManageBeanList = spUtils.getFromJson(
164
+            val type = object : TypeToken<List<AppTimeManageBean>>() {}.type
165
+            val appTimeManageBeanList = spUtils.getFromJsonType(
164 166
                 Const.APPSTRATEGYBEANKEY,
165
-                ArrayList<AppTimeManageBean>().javaClass
167
+                ArrayList<AppTimeManageBean>().javaClass,
168
+                type
166 169
             ) as ArrayList<AppTimeManageBean>
167
-            //为真则可以使用,为false不可以使用
168
-            var lockFlag = true
170
+            //为真则可以使用,为false不可以使用,为黑名单机制,只有范围内的限制,不在范围内的不限制返回true
171
+            var useFlag = true
169 172
             val dayList = arrayListOf(2, 3, 4, 5, 6, 7, 1)
170 173
             val currentTimeMillis = System.currentTimeMillis()
171 174
             val filter = appTimeManageBeanList.filter { it.appPackage.equals(pkgName) }
@@ -193,16 +196,16 @@ object StrategyUtils {
193 196
                                     //在使用范围则可用
194 197
                                     return true
195 198
                                 } else {
196
-                                    lockFlag = false
199
+                                    useFlag = false
197 200
                                 }
198 201
                             }
199 202
                         }
200 203
                     } else {
201 204
                         //不包含今天则不可用
202
-                        lockFlag = false
205
+                        useFlag = false
203 206
                     }
204 207
                 }
205
-                return lockFlag
208
+                return useFlag
206 209
             }
207 210
             return true
208 211
         } catch (e: Exception) {

+ 3
- 1
corelib/src/main/java/com/xhly/corelib/Const.kt View File

@@ -85,8 +85,10 @@ object Const {
85 85
     //标记更新策略
86 86
     const val UPDATESTRATEGY = "UPDATESTRATEGY"
87 87
 
88
-    //存储策略
88
+    //存储平板策略
89 89
     const val STRATEGYBEANKEY = "STRATEGYBEAN"
90
+    //存储app时间策略
91
+    const val APPSTRATEGYBEANKEY = "APPSTRATEGYBEAN"
90 92
 
91 93
     //记录设备策略名称
92 94
     const val DEVICETYPE1 = "摄像头"

+ 16
- 0
corelib/src/main/java/com/xhly/corelib/utils/SharedPreferencesUtils.java View File

@@ -7,6 +7,8 @@ import android.util.Log;
7 7
 
8 8
 import com.google.gson.Gson;
9 9
 
10
+import java.lang.reflect.Type;
11
+
10 12
 public class SharedPreferencesUtils {
11 13
     /**
12 14
      * 保存在手机里面的文件名
@@ -133,6 +135,20 @@ public class SharedPreferencesUtils {
133 135
         }
134 136
     }
135 137
 
138
+    public <T> Object getFromJsonType(String key, Class<T> cls, Type type) {
139
+        try {
140
+            String json = preferences.getString(key, "");
141
+            if (TextUtils.isEmpty(json)) {
142
+                Log.d("转换失败", "数据为空");
143
+                return null;
144
+            }
145
+            Gson gson = new Gson();
146
+            return gson.fromJson(json, type);
147
+        } catch (Exception e) {
148
+            Log.d("转换失败", e.toString());
149
+            return null;
150
+        }
151
+    }
136 152
 
137 153
     public String get(String key) {
138 154
         return preferences.getString(key, "");

Loading…
Cancel
Save