Browse Source

1.对获取APP白名单和网址白名单的方法进行区分。

2025_1_17_tb223fc
wangwanlei 1 week ago
parent
commit
2c8330269e

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

@@ -762,7 +762,9 @@ class ManageApplication : MultiDexApplication() {
762 762
             val appList = arrayListOf<String>()
763 763
             if (ModelNameUtils.IS_LianxX505f() || ModelNameUtils.IS_LianxX6e6f()|| ModelNameUtils.IS_LianxTB223FC()) {
764 764
                 if (ModelNameUtils.IS_LianxTB223FC()){
765
-                    AfwUtils.getNetAppWhiteList()
765
+                    instance?.let {
766
+                        appList.addAll(AfwUtils.getNetAppWhiteList(it))
767
+                    }
766 768
                 }else{
767 769
                     val appWhiteRules = csdkManager?.appWhiteRules
768 770
                     appWhiteRules?.let {
@@ -791,7 +793,7 @@ class ManageApplication : MultiDexApplication() {
791 793
         fun urlWhiteListRead(): List<String> {
792 794
             if (ModelNameUtils.IS_LianxX505f() || ModelNameUtils.IS_LianxX6e6f()|| ModelNameUtils.IS_LianxTB223FC()) {
793 795
                 if (ModelNameUtils.IS_LianxTB223FC()){
794
-                    AfwUtils.getNetAppWhiteList()
796
+                    return AfwUtils.getUrlWhiteList()
795 797
                 }else{
796 798
                     csdkManager?.urlWhiteListRead()?.let {
797 799
                         return it

+ 44
- 7
app/src/main/java/com/xhly/manageapp/utils/AfwUtils.kt View File

@@ -10,6 +10,7 @@ import android.os.Bundle
10 10
 import android.os.IBinder
11 11
 import android.util.Log
12 12
 import cn.com.microtrust.firewall.aidl.IAFWService
13
+import com.xhly.corelib.utils.AppUtils
13 14
 
14 15
 
15 16
 object AfwUtils {
@@ -98,27 +99,63 @@ object AfwUtils {
98 99
         }
99 100
         return sb.toString()
100 101
     }
101
-    fun getNetAppWhiteList():String{
102
-        val sb=StringBuffer()
103
-        sb.append("白名单应用")
102
+    fun getNetAppWhiteList(context: Context):ArrayList<String>{
103
+        val appList= arrayListOf<String>()
104 104
         try {
105
+            var getAllAppList = AppUtils.GetAllAppList(context)
105 106
             if (iafwService != null) {
106 107
                 val afwRes = iafwService!!.whiteRules
107 108
                 val data = afwRes.data
108 109
                 for (i in data.indices) {
109 110
                     Log.i(TAG, "whiteRules=" + data[i])
110
-                    sb.append(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
+                    }
111 122
                 }
112 123
             } else {
113 124
                 Log.i(TAG, "iafwService=null")
114
-                sb.append("iafwService=null")
115 125
             }
116 126
         } catch (e: java.lang.Exception) {
117 127
             e.printStackTrace()
118 128
             Log.e(TAG, e.toString())
119
-             sb.append("有问题$e")
120 129
         }
121
-        return sb.toString()
130
+        return appList
131
+    }
132
+
133
+    /**
134
+     * 获得网址白名单
135
+     */
136
+    fun getUrlWhiteList():ArrayList<String>{
137
+        val urlList= arrayListOf<String>()
138
+        try {
139
+            if (iafwService != null) {
140
+                val afwRes = iafwService!!.whiteRules
141
+                val data = afwRes.data
142
+                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
+                    }
150
+                }
151
+            } else {
152
+                Log.i(TAG, "iafwService=null")
153
+            }
154
+        } catch (e: java.lang.Exception) {
155
+            e.printStackTrace()
156
+            Log.e(TAG, e.toString())
157
+        }
158
+        return urlList
122 159
     }
123 160
 
124 161
     /**

Loading…
Cancel
Save