Browse Source

1.修改策略bean类字段名称。

master
wangwanlei 11 months ago
parent
commit
d15fa8b07b

+ 2
- 2
app/src/main/java/com/xhly/manageapp/bean/strategy/StrategyBean.kt View File

@@ -10,7 +10,7 @@ class StrategyBean :Serializable{
10 10
     /**
11 11
      * wifi策略
12 12
      */
13
-    var wifis: Array<String?>? = arrayOf()
13
+    var padWifis: Array<String?>? = arrayOf()
14 14
 
15 15
     /**
16 16
      * 是否开启应用策略:0否 1是
@@ -59,5 +59,5 @@ class StrategyBean :Serializable{
59 59
     /**
60 60
      * 授权应用
61 61
      */
62
-    var apps: ArrayList<AppModel>? = arrayListOf()
62
+    var padApps: ArrayList<AppModel>? = arrayListOf()
63 63
 }

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

@@ -1,8 +1,12 @@
1 1
 package com.xhly.manageapp.utils
2 2
 
3
+import android.content.Context
3 4
 import com.xhly.corelib.Const
5
+import com.xhly.corelib.utils.LogShow
6
+import com.xhly.corelib.utils.SharedPreferencesUtils
4 7
 import com.xhly.corelib.utils.hourToCurrentDateLong
5 8
 import com.xhly.manageapp.ManageApplication
9
+import com.xhly.manageapp.bean.strategy.AppTimeManageBean
6 10
 import com.xhly.manageapp.bean.strategy.StrategyBean
7 11
 import java.util.Calendar
8 12
 
@@ -11,7 +15,7 @@ object StrategyUtils {
11 15
         //是否启用白名单
12 16
         if (strategyBean.haswifi == 1) {
13 17
             ManageApplication.enableWifiWhiteList(true)
14
-            strategyBean.wifis?.let {
18
+            strategyBean.padWifis?.let {
15 19
                 val list = arrayListOf<String>()
16 20
                 it.forEach { s ->
17 21
                     if (!s.isNullOrBlank()) {
@@ -26,7 +30,7 @@ object StrategyUtils {
26 30
         //是否开启应用策略
27 31
         if (strategyBean.hasapp == 1) {
28 32
             //开启
29
-            strategyBean.apps?.let { appArray ->
33
+            strategyBean.padApps?.let { appArray ->
30 34
                 val list = arrayListOf<String>()
31 35
                 appArray.forEach {
32 36
                     list.add(it.appPackage)
@@ -39,7 +43,7 @@ object StrategyUtils {
39 43
             ManageApplication.removeInstallPackageWhiteList(installPackageWhiteList)
40 44
         }
41 45
 
42
-        //是否开启时间策略,这个策略在生命周期中调用getAppTimeStrategy(strategyBean)
46
+        //是否开启时间策略,这个策略在生命周期中调用getPadTimeStrategy(strategyBean)
43 47
 
44 48
 
45 49
         //是否设备策略
@@ -107,7 +111,7 @@ object StrategyUtils {
107 111
     /**
108 112
      * 时间策略处理,返回为真则锁定
109 113
      */
110
-    public fun getAppTimeStrategy(strategyBean: StrategyBean): Boolean {
114
+    public fun getPadTimeStrategy(strategyBean: StrategyBean): Boolean {
111 115
         //是否开启时间策略,返回为真则锁定
112 116
         var lockFlag = false
113 117
         val dayList = arrayListOf(2, 3, 4, 5, 6, 7, 1)
@@ -121,11 +125,11 @@ object StrategyUtils {
121 125
                 //开启策略,但不返回时间则表示锁定
122 126
                 return true
123 127
             }
124
-            padTimes?.forEach { appTimeManageBean ->
125
-                val day = dayList[appTimeManageBean.week - 1]
128
+            padTimes?.forEach { padTimeManageBean ->
129
+                val day = dayList[padTimeManageBean.week - 1]
126 130
                 if (day == dayWeek) {
127
-                    val starttime = appTimeManageBean.starttime
128
-                    val stoptime = appTimeManageBean.stoptime
131
+                    val starttime = padTimeManageBean.starttime
132
+                    val stoptime = padTimeManageBean.stoptime
129 133
                     starttime?.let {
130 134
                         val start = starttime.hourToCurrentDateLong()
131 135
                         stoptime?.let {
@@ -139,7 +143,8 @@ object StrategyUtils {
139 143
                             }
140 144
                         }
141 145
                     }
142
-                }else{
146
+                } else {
147
+                    //不包含今天则锁定
143 148
                     lockFlag = true
144 149
                 }
145 150
             }
@@ -148,7 +153,61 @@ object StrategyUtils {
148 153
         return false
149 154
     }
150 155
 
151
-    public fun getAppTimeStrategy() {
152
-
156
+    //处理app打开策略
157
+    public fun getAppTimeStrategy(
158
+        context: Context,
159
+        pkgName: String
160
+    ): Boolean {
161
+        try {
162
+            val spUtils by lazy { SharedPreferencesUtils.getInstance(context) }
163
+            val appTimeManageBeanList = spUtils.getFromJson(
164
+                Const.APPSTRATEGYBEANKEY,
165
+                ArrayList<AppTimeManageBean>().javaClass
166
+            ) as ArrayList<AppTimeManageBean>
167
+            //为真则可以使用,为false不可以使用
168
+            var lockFlag = true
169
+            val dayList = arrayListOf(2, 3, 4, 5, 6, 7, 1)
170
+            val currentTimeMillis = System.currentTimeMillis()
171
+            val filter = appTimeManageBeanList.filter { it.appPackage.equals(pkgName) }
172
+            if (filter.isNotEmpty()) {
173
+                val calendar = Calendar.getInstance()
174
+                //返回值 1 周日 2周一 3周二 4周三 5周四 6周五 7周六
175
+                val dayWeek = calendar.get(Calendar.DAY_OF_WEEK)
176
+                val appTimeManageBean = filter[0]
177
+                val appTimes = appTimeManageBean.times
178
+                if (appTimes == null || appTimes.size == 0) {
179
+                    //开启策略,但不返回时间则表示锁定
180
+                    return false
181
+                }
182
+                appTimes?.forEach { appTimeManageBean ->
183
+                    val day = dayList[appTimeManageBean.week - 1]
184
+                    if (day == dayWeek) {
185
+                        val starttime = appTimeManageBean.starttime
186
+                        val stoptime = appTimeManageBean.stoptime
187
+                        starttime?.let {
188
+                            val start = starttime.hourToCurrentDateLong()
189
+                            stoptime?.let {
190
+                                val end = stoptime.hourToCurrentDateLong()
191
+                                //只有有一个时段符合即为可用
192
+                                if (currentTimeMillis > start && currentTimeMillis < end) {
193
+                                    //在使用范围则可用
194
+                                    return true
195
+                                } else {
196
+                                    lockFlag = false
197
+                                }
198
+                            }
199
+                        }
200
+                    } else {
201
+                        //不包含今天则不可用
202
+                        lockFlag = false
203
+                    }
204
+                }
205
+                return lockFlag
206
+            }
207
+            return true
208
+        } catch (e: Exception) {
209
+            LogShow("问题是"+e.toString())
210
+            return true
211
+        }
153 212
     }
154 213
 }

Loading…
Cancel
Save