Browse Source

1.修改添加和获取APP网络白名单列表的方法。

2.修改获得网址白名单列表的方法。
2025_1_17_tb223fc
wangwanlei 2 weeks ago
parent
commit
b2c55c4368

+ 1
- 3
app/src/main/java/com/xhly/manageapp/ManageApplication.kt View File

@@ -735,9 +735,7 @@ class ManageApplication : MultiDexApplication() {
735 735
             if (ModelNameUtils.IS_LianxX505f() || ModelNameUtils.IS_LianxX6e6f()|| ModelNameUtils.IS_LianxTB223FC()) {
736 736
                 if (ModelNameUtils.IS_LianxTB223FC()){
737 737
                   try {
738
-                      pkgList.forEach {
739
-                          TB23FCAfwUtils.jurisdiction(1,TB23FCAfwUtils.getUUid(instance!!,it).toInt())
740
-                      }
738
+                      TB23FCAfwUtils.addAppWhiteList(pkgList, instance!!)
741 739
                   }catch (e:Exception){
742 740
 
743 741
                   }

+ 42
- 42
app/src/main/java/com/xhly/manageapp/utils/TB23FCAfwUtils.kt View File

@@ -9,6 +9,7 @@ import android.content.pm.PackageManager
9 9
 import android.os.Bundle
10 10
 import android.os.IBinder
11 11
 import android.util.Log
12
+import cn.com.microtrust.firewall.afw.AFWUtils
12 13
 import cn.com.microtrust.firewall.aidl.IAFWService
13 14
 import com.xhly.corelib.utils.AppUtils
14 15
 
@@ -77,49 +78,31 @@ object TB23FCAfwUtils {
77 78
 
78 79
        }
79 80
     }
80
-    fun getNetAppBlockList():String{
81
-        val sb=StringBuffer()
82
-        sb.append("黑名单应用")
81
+
82
+    //添加app白名单 2025.3.18
83
+    fun addAppWhiteList(appList:List<String>,context: Context){
83 84
         try {
84 85
             if (iafwService != null) {
85
-                val afwRes = iafwService!!.blackRules
86
-                val data = afwRes.data
87
-                for (i in data.indices) {
88
-                    Log.i(TAG, "blackRules=" + data[i])
89
-                    sb.append(data[i])
86
+                appList.forEach {app->
87
+                    AFWUtils.addAppWhiteRule(context, iafwService,app)
90 88
                 }
91 89
             } else {
92 90
                 Log.i(TAG, "iafwService=null")
93
-                sb.append("iafwService=null")
94 91
             }
95 92
         } catch (e: java.lang.Exception) {
96 93
             e.printStackTrace()
97 94
             Log.e(TAG, e.toString())
98
-            sb.append("有问题$e")
99 95
         }
100
-        return sb.toString()
101 96
     }
97
+    /**
98
+     * 使用新方法获得app白名单 2025.3.18
99
+     */
102 100
     fun getNetAppWhiteList(context: Context):ArrayList<String>{
103 101
         val appList= arrayListOf<String>()
104 102
         try {
105
-            var getAllAppList = AppUtils.GetAllAppList(context)
106 103
             if (iafwService != null) {
107
-                val afwRes = iafwService!!.whiteRules
108
-                val data = afwRes.data
109
-                for (i in data.indices) {
110
-                    Log.i(TAG, "whiteRules=" + data[i])
111
-                    try {
112
-                        //转换成功则认为是APP否则是网址
113
-                        val toInt = data[i].toInt()
114
-                        getAllAppList.forEach { appInfo ->
115
-                            if (getUUid(context,appInfo.packageName).toInt() == toInt) {
116
-                                appList.add(appInfo.packageName)
117
-                            }
118
-                        }
119
-                    }catch (e:Exception){
120
-
121
-                    }
122
-                }
104
+                val appWhiteRules = AFWUtils.getAppWhiteRules(context, iafwService)
105
+                appList.addAll(appWhiteRules)
123 106
             } else {
124 107
                 Log.i(TAG, "iafwService=null")
125 108
             }
@@ -130,34 +113,30 @@ object TB23FCAfwUtils {
130 113
         return appList
131 114
     }
132 115
 
133
-    /**
134
-     * 获得网址白名单
135
-     */
136
-    fun getUrlWhiteList():ArrayList<String>{
137
-        val urlList= arrayListOf<String>()
116
+    fun getNetAppBlockList():String{
117
+        val sb=StringBuffer()
118
+        sb.append("黑名单应用")
138 119
         try {
139 120
             if (iafwService != null) {
140
-                val afwRes = iafwService!!.whiteRules
121
+                val afwRes = iafwService!!.blackRules
141 122
                 val data = afwRes.data
142 123
                 for (i in data.indices) {
143
-                    Log.i(TAG, "whiteRules=" + data[i])
144
-                    try {
145
-                        //转换成功则认为是APP否则是网址
146
-                        data[i].toInt()
147
-                    }catch (e:Exception){
148
-                        urlList.add(data[i])
149
-                    }
124
+                    Log.i(TAG, "blackRules=" + data[i])
125
+                    sb.append(data[i])
150 126
                 }
151 127
             } else {
152 128
                 Log.i(TAG, "iafwService=null")
129
+                sb.append("iafwService=null")
153 130
             }
154 131
         } catch (e: java.lang.Exception) {
155 132
             e.printStackTrace()
156 133
             Log.e(TAG, e.toString())
134
+            sb.append("有问题$e")
157 135
         }
158
-        return urlList
136
+        return sb.toString()
159 137
     }
160 138
 
139
+
161 140
     /**
162 141
      * 添加网址白名单
163 142
      */
@@ -177,6 +156,27 @@ object TB23FCAfwUtils {
177 156
         }
178 157
     }
179 158
 
159
+    /**
160
+     * 获得网址白名单
161
+     */
162
+    fun getUrlWhiteList():ArrayList<String>{
163
+        val urlList= arrayListOf<String>()
164
+        try {
165
+            if (iafwService != null) {
166
+                val whiteRules = AFWUtils.getWhiteRules(iafwService)
167
+                urlList.addAll(whiteRules)
168
+            } else {
169
+                Log.i(TAG, "iafwService=null")
170
+            }
171
+        } catch (e: java.lang.Exception) {
172
+            e.printStackTrace()
173
+            Log.e(TAG, e.toString())
174
+        }
175
+        return urlList
176
+    }
177
+
178
+
179
+
180 180
     /**
181 181
      * 添加网址黑名单
182 182
      */

Loading…
Cancel
Save