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

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

9
 import android.os.Bundle
9
 import android.os.Bundle
10
 import android.os.IBinder
10
 import android.os.IBinder
11
 import android.util.Log
11
 import android.util.Log
12
+import cn.com.microtrust.firewall.afw.AFWUtils
12
 import cn.com.microtrust.firewall.aidl.IAFWService
13
 import cn.com.microtrust.firewall.aidl.IAFWService
13
 import com.xhly.corelib.utils.AppUtils
14
 import com.xhly.corelib.utils.AppUtils
14
 
15
 
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
         try {
84
         try {
84
             if (iafwService != null) {
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
             } else {
89
             } else {
92
                 Log.i(TAG, "iafwService=null")
90
                 Log.i(TAG, "iafwService=null")
93
-                sb.append("iafwService=null")
94
             }
91
             }
95
         } catch (e: java.lang.Exception) {
92
         } catch (e: java.lang.Exception) {
96
             e.printStackTrace()
93
             e.printStackTrace()
97
             Log.e(TAG, e.toString())
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
     fun getNetAppWhiteList(context: Context):ArrayList<String>{
100
     fun getNetAppWhiteList(context: Context):ArrayList<String>{
103
         val appList= arrayListOf<String>()
101
         val appList= arrayListOf<String>()
104
         try {
102
         try {
105
-            var getAllAppList = AppUtils.GetAllAppList(context)
106
             if (iafwService != null) {
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
             } else {
106
             } else {
124
                 Log.i(TAG, "iafwService=null")
107
                 Log.i(TAG, "iafwService=null")
125
             }
108
             }
130
         return appList
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
         try {
119
         try {
139
             if (iafwService != null) {
120
             if (iafwService != null) {
140
-                val afwRes = iafwService!!.whiteRules
121
+                val afwRes = iafwService!!.blackRules
141
                 val data = afwRes.data
122
                 val data = afwRes.data
142
                 for (i in data.indices) {
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
             } else {
127
             } else {
152
                 Log.i(TAG, "iafwService=null")
128
                 Log.i(TAG, "iafwService=null")
129
+                sb.append("iafwService=null")
153
             }
130
             }
154
         } catch (e: java.lang.Exception) {
131
         } catch (e: java.lang.Exception) {
155
             e.printStackTrace()
132
             e.printStackTrace()
156
             Log.e(TAG, e.toString())
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
         }
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