Explorar el Código

1.添加策略处理逻辑

master
wangwanlei hace 11 meses
padre
commit
dc1f21ee14

+ 0
- 13
app/src/main/java/com/xhly/manageapp/service/websocket/AppSocket.kt Ver fichero

@@ -123,20 +123,7 @@ class AppSocket : SocketClient() {
123 123
                 }
124 124
                 val filter = appList.filter { it.packageName == message }
125 125
                 if (filter.isNotEmpty()) {
126
-                    val appInfo = filter[0]
127 126
                     lastPkgName = message
128
-                    serviceScope.launch {
129
-                        val logStartBean = LogAppStartBean()
130
-                        ManageApplication.getDeviceInfo()?.let {
131
-                            logStartBean.sn = it
132
-                        }
133
-                        logStartBean.appName = appInfo.name
134
-                        logStartBean.appPackage = appInfo.packageName
135
-                        logStartBean.versionName = appInfo.versionName
136
-                        logStartBean.versionNum = appInfo.versionNum
137
-                        LogShow("当前应用" + logStartBean.appName + "|||" + logStartBean.versionName + "|||" + logStartBean.versionNum)
138
-                        logService.postLogAppStartAdd(logStartBean)
139
-                    }
140 127
                     val data = LogdOperateBean()
141 128
                     ManageApplication.getDeviceInfo()?.let {
142 129
                         data.sn = it

+ 114
- 0
app/src/main/java/com/xhly/manageapp/utils/StrategyUtils.kt Ver fichero

@@ -0,0 +1,114 @@
1
+package com.xhly.manageapp.utils
2
+
3
+import com.xhly.corelib.Const
4
+import com.xhly.manageapp.ManageApplication
5
+import com.xhly.manageapp.bean.strategy.StrategyBean
6
+
7
+object StrategyUtils {
8
+    public fun setStrategy(strategyBean: StrategyBean) {
9
+        //是否启用白名单
10
+        if (strategyBean.haswifi == 1) {
11
+            ManageApplication.enableWifiWhiteList(true)
12
+            strategyBean.wifis?.let {
13
+                val list = arrayListOf<String>()
14
+                it.forEach { s ->
15
+                    if (!s.isNullOrBlank()) {
16
+                        list.add(s)
17
+                    }
18
+                }
19
+                ManageApplication.addWifiWhiteList(list)
20
+            }
21
+        } else {
22
+            ManageApplication.enableWifiWhiteList(false)
23
+        }
24
+        //是否开启应用策略
25
+        if (strategyBean.hasapp == 1) {
26
+            //开启
27
+            strategyBean.apps?.let { appArray ->
28
+                val list = arrayListOf<String>()
29
+                appArray.forEach {
30
+                    list.add(it.appPackage)
31
+                }
32
+                ManageApplication.addInstallPackageWhiteList(list)
33
+            }
34
+        } else {
35
+            //不开启应用策略
36
+            val installPackageWhiteList = ManageApplication.getInstallPackageWhiteList()
37
+            ManageApplication.removeInstallPackageWhiteList(installPackageWhiteList)
38
+        }
39
+        //是否开启时间策略
40
+        if (strategyBean.hastime == 1) {
41
+            var currentTimeMillis = System.currentTimeMillis()
42
+
43
+        } else {
44
+
45
+        }
46
+
47
+        //是否设备策略
48
+        if (strategyBean.hasdevice == 1) {
49
+            //开启
50
+            deviceStrategy(strategyBean)
51
+        } else {
52
+            //不设置则默认全部打开
53
+            deviceStrategy(strategyBean)
54
+        }
55
+
56
+        //违规处理,直接在事件触发时判断,不再这里处理
57
+        if (strategyBean.hasviolate==1){
58
+
59
+        }
60
+
61
+
62
+    }
63
+
64
+    private fun deviceStrategy(strategyBean: StrategyBean) {
65
+        val padDevices = strategyBean.padDevices
66
+        padDevices?.forEach {
67
+            when (it.pdtype) {
68
+                Const.DEVICETYPE1 -> {
69
+                    ManageApplication.disableCamera(it.enabled == 1)
70
+                }
71
+
72
+                Const.DEVICETYPE2 -> {
73
+                    ManageApplication.enableBluetooth(it.enabled == 1)
74
+                }
75
+
76
+                Const.DEVICETYPE3 -> {
77
+                    ManageApplication.disallowUsbDebugging(it.enabled == 1)
78
+                }
79
+
80
+                Const.DEVICETYPE4 -> {
81
+                    ManageApplication.enableWifi(it.enabled == 1)
82
+                }
83
+
84
+                Const.DEVICETYPE5 -> {
85
+
86
+                }
87
+
88
+                Const.DEVICETYPE6 -> {
89
+                    ManageApplication.enableData(it.enabled == 1)
90
+                }
91
+
92
+                Const.DEVICETYPE7 -> {
93
+                    ManageApplication.enableLocation(it.enabled == 1)
94
+                }
95
+
96
+                Const.DEVICETYPE8 -> {
97
+                    ManageApplication.disallowWifiAdvanceSettings(it.enabled != 1)
98
+                }
99
+
100
+                Const.DEVICETYPE9 -> {
101
+                    ManageApplication.enableMassStorage(it.enabled == 1)
102
+                }
103
+
104
+                Const.DEVICETYPE10 -> {
105
+                    ManageApplication.setCustomOTG(it.enabled == 1)
106
+                }
107
+            }
108
+        }
109
+    }
110
+
111
+    public fun getAppTimeStrategy() {
112
+
113
+    }
114
+}

+ 260
- 0
app/src/main/java/com/xhly/manageapp/utils/ToolUtils.java Ver fichero

@@ -0,0 +1,260 @@
1
+package com.xhly.manageapp.utils;
2
+
3
+
4
+import java.util.*;
5
+import java.util.regex.Matcher;
6
+import java.util.regex.Pattern;
7
+import java.util.stream.Collectors;
8
+
9
+/**
10
+ * @Description 公用工具类
11
+ * @Author WN
12
+ * @Date 2023/7/24 11:27:10
13
+ **/
14
+
15
+public class ToolUtils {
16
+
17
+    /**
18
+     * @Description 字符串是否不为空
19
+     * @Param [obj]
20
+     * @Author WN
21
+     * @Return boolean
22
+     */
23
+    public static boolean isNotEmpty(Object obj) {
24
+        return null != obj && !"".equals(obj.toString().trim());
25
+    }
26
+
27
+    /**
28
+     * @Description 字符串是否为空
29
+     * @Param [obj]
30
+     * @Author WN
31
+     * @Return boolean
32
+     */
33
+    public static boolean isEmpty(Object obj) {
34
+        return null == obj || "".equals(obj.toString().trim()) || "null".equals(obj.toString().trim());
35
+    }
36
+
37
+    /**
38
+     * json字符串是否不为空
39
+     * @Return boolean
40
+     * @Param [jsonStr]
41
+     * @Author ywx
42
+     * @Date 2020/5/13 16:06
43
+     **/
44
+    public static boolean isJsonStrNotEmpty(String jsonStr) {
45
+        return isNotEmpty(jsonStr) && !jsonStr.equals("[]");
46
+    }
47
+
48
+
49
+    /**
50
+     * 功能描述  integer 是否是有效的类型
51
+     * @Param obj
52
+     * @Return boolean
53
+     * @Author WN
54
+     * @Date 2019/7/15
55
+     */
56
+    public static boolean isTrueInteger(Integer obj) {
57
+        return null != obj && obj > 0;
58
+    }
59
+
60
+    /**
61
+     * 去除字符串中前后的全、半角空格
62
+     * @Return java.lang.String
63
+     * @Param [str]
64
+     * @Author ywx
65
+     * @Date 2020/4/1 9:57
66
+     **/
67
+    public static String strTrim(String str) {
68
+        str = str.trim();// 去除字符串前后的半角空格
69
+        while (str.startsWith(" ")) {// 去除字符串前的全角空格
70
+            str = str.substring(1).trim();
71
+        }
72
+        while (str.endsWith(" ")) {// 去除字符串后的全角空格
73
+            str = str.substring(0, str.length() - 1).trim();
74
+        }
75
+        return str;
76
+    }
77
+
78
+
79
+    /**
80
+
81
+    /**
82
+     * @Return boolean
83
+     * @Description list不为空
84
+     * @Author ywx
85
+     * @Date 2023/8/10 15:01
86
+     **/
87
+    public static boolean isListNotEmpty(List list) {
88
+        return null != list && list.size() > 0;
89
+    }
90
+
91
+    /**
92
+     * @Return boolean
93
+     * @Description list为空
94
+     * @Author ywx
95
+     * @Date 2023/8/10 15:01
96
+     **/
97
+    public static boolean isListEmpty(List list) {
98
+        return null == list || list.size() <= 0;
99
+    }
100
+
101
+    /**
102
+     * @Description UUID的版本4是通过生成一个包含128位随机数的UUID来实现的。
103
+     * 这些随机数是通过操作系统提供的随机数生成器生成的,保证了UUID的唯一性和随机性。
104
+     * 因此,每次调用UUID.randomUUID()方法都会生成一个不同的UUID值。
105
+     * @Date 2023/8/11 16:39
106
+     * @Author YWX
107
+     * @Param []
108
+     * @Return java.lang.String
109
+     **/
110
+    public static String generateUUIDv4() {
111
+        try {
112
+            String uuid = UUID.randomUUID().toString();
113
+            return uuid.replaceAll("-", "");
114
+        } catch (Exception e) {
115
+            e.printStackTrace();
116
+        }
117
+        return null;
118
+    }
119
+
120
+    // 构建树
121
+    public static List<Map<String, Object>> buildTree(List<Map<String, Object>> trees
122
+            , String id, String pid, String cname) {
123
+        // 获取grouppid为空的根节点
124
+        List<Map<String, Object>> list = trees.stream().filter(
125
+                item -> ToolUtils.isEmpty(item.get(pid))).collect(Collectors.toList());
126
+        // 根据grouppid进行分组
127
+        Map<String, List<Map<String, Object>>> map = trees.stream().filter(
128
+                m -> ToolUtils.isNotEmpty(m.get(pid))).collect(
129
+                Collectors.groupingBy(m -> m.get(pid).toString(), LinkedHashMap::new, Collectors.toList()));
130
+        recursionTree(list, map, id, cname);
131
+        return list;
132
+    }
133
+
134
+    // 递归遍历节点
135
+    public static void recursionTree(List<Map<String, Object>> list, Map<String, List<Map<String, Object>>> map
136
+            , String id, String cname) {
137
+        for (Map<String, Object> treeSelect : list) {
138
+            List<Map<String, Object>> childList = map.get(treeSelect.get(id).toString());
139
+            treeSelect.put(cname, childList);
140
+            if (null != childList && 0 < childList.size()) {
141
+                recursionTree(childList, map, id, cname);
142
+            }
143
+        }
144
+    }
145
+
146
+    /**
147
+     * @Description 递归搜索父节点并将其添加到指定列表中
148
+     * @Date 2024/1/3 9:26
149
+     * @Author YWX
150
+     * @Param [list1(到目前为止找到的节点列表), list2(需要查找父节点的子节点列表), list(完整节点列表), id, pid]
151
+     * @Return void
152
+     **/
153
+    public static void searchParents(List<Map<String, Object>> list1, List<Map<String, Object>> list2
154
+            , List<Map<String, Object>> list, String id, String pid) {
155
+        List<Map<String, Object>> parents = new ArrayList<>();
156
+        for (Map<String, Object> t : list2) {
157
+            Object treepid = t.get(pid);
158
+            if (ToolUtils.isEmpty(treepid)) continue;
159
+            Map<String, Object> parent = list.stream().filter(p -> treepid.equals(p.get(id))).findFirst().orElse(null);
160
+            // 如果找到父节点且父节点不在parents列表中,则将其添加到parents列表中
161
+            if (parent != null && !parents.contains(parent)) parents.add(parent);
162
+        }
163
+
164
+        // 如果`parents`列表不为空,将其中的父节点添加到`list1`列表中,
165
+        // 并递归调用`searchParents`方法,将`parents`列表作为新的子节点列表传入,继续搜索更高层级的父节点。
166
+        if (ToolUtils.isListNotEmpty(parents)) {
167
+            for (Map<String, Object> parent : parents) {
168
+                // 如果找到的父节点尚未存在于list1中,则将其添加到list1中
169
+                if (!list1.contains(parent)) list1.add(parent);
170
+            }
171
+            // 递归地遍历子节点,并从提供的列表中获取它们的父节点
172
+            searchParents(list1, parents, list, id, pid);
173
+        }
174
+    }
175
+
176
+    /**
177
+     * @Description 数字是否包含在集合中的数字集合
178
+     * @Date 2023/11/10 11:43
179
+     * @Author YWX
180
+     * @Param [num, nums]
181
+     * @Return boolean
182
+     **/
183
+    public static boolean numInList(Integer num, List<Integer> nums) {
184
+        return isListNotEmpty(nums) && nums.contains(new Integer(num));
185
+    }
186
+
187
+    /**
188
+     * 随机生成4位随机码
189
+     * @Return java.lang.Integer
190
+     * @Param []
191
+     * @Author ywx
192
+     * @Date 2020/5/8 9:29
193
+     **/
194
+    public static Integer messageCode() {
195
+        return (int) ((Math.random() * 9 + 1) * 1000);
196
+    }
197
+
198
+    /*
199
+     * @Description 验证手机号
200
+     * @Date 2024/3/12 16:12:34
201
+     * @Author WN
202
+     * @Param [phone]
203
+     * @Return boolean
204
+     **/
205
+    public static boolean checkPhone(String phone){
206
+        String regex="^1[3456789]\\d{9}$";
207
+        Pattern pattern = Pattern.compile(regex);
208
+        Matcher matcher = pattern.matcher(phone);
209
+
210
+        return matcher.matches();
211
+    }
212
+
213
+
214
+
215
+    /**
216
+     * @Description 性别名称转数字
217
+     * @Date 2024/3/25 14:30
218
+     * @Author YWX
219
+     * @Param [userSex]
220
+     * @Return java.lang.Integer
221
+     **/
222
+    public static Integer getUserSex(String userSex) {
223
+        if (ToolUtils.isEmpty(userSex)) return 0;
224
+        int usersex;
225
+        switch (userSex) {
226
+            case "男":
227
+                usersex = 1;
228
+                break;
229
+            case "女":
230
+                usersex = 2;
231
+                break;
232
+            default:
233
+                usersex = 0;
234
+                break;
235
+        }
236
+        return usersex;
237
+    }
238
+
239
+    /**
240
+     * @Description 去除字符串末尾的0,如果最后一个字符是小数点,也一并移除
241
+     * @Date 2024/3/28 14:43
242
+     * @Author YWX
243
+     * @Param [numStr]
244
+     * @Return java.lang.String
245
+     **/
246
+    public static String removeTrailingZeros(String numStr) {
247
+        StringBuilder sb = new StringBuilder(numStr);
248
+        int i = sb.length() - 1;
249
+        while (i >= 0 && sb.charAt(i) == '0') {
250
+            sb.deleteCharAt(i);
251
+            i--;
252
+        }
253
+        if (sb.length() > 0 && sb.charAt(sb.length() - 1) == '.') {
254
+            sb.deleteCharAt(sb.length() - 1); // 如果最后一个字符是小数点,也一并移除
255
+        }
256
+        return sb.toString();
257
+    }
258
+
259
+
260
+}

+ 15
- 0
corelib/src/main/java/com/xhly/corelib/Const.kt Ver fichero

@@ -58,4 +58,19 @@ object Const {
58 58
 
59 59
     //标记更新策略
60 60
     const val UPDATESTRATEGY = "UPDATESTRATEGY"
61
+
62
+    //存储策略
63
+    const val STRATEGYBEANKEY = "STRATEGYBEAN"
64
+
65
+    //记录设备策略名称
66
+    const val DEVICETYPE1 = "摄像头"
67
+    const val DEVICETYPE2 = "蓝牙"
68
+    const val DEVICETYPE3 = "USB连接"
69
+    const val DEVICETYPE4 = "WiFi开关"
70
+    const val DEVICETYPE5 = "电话短信"
71
+    const val DEVICETYPE6 = "数据流量"
72
+    const val DEVICETYPE7 = "GPS"
73
+    const val DEVICETYPE8 = "WiFi高级选项"
74
+    const val DEVICETYPE9 = "SD卡"
75
+    const val DEVICETYPE10 = "OTG"
61 76
 }

Loading…
Cancelar
Guardar