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

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

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.aidl.IAFWService
12
 import cn.com.microtrust.firewall.aidl.IAFWService
13
+import com.xhly.corelib.utils.AppUtils
13
 
14
 
14
 
15
 
15
 object AfwUtils {
16
 object AfwUtils {
98
         }
99
         }
99
         return sb.toString()
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
         try {
104
         try {
105
+            var getAllAppList = AppUtils.GetAllAppList(context)
105
             if (iafwService != null) {
106
             if (iafwService != null) {
106
                 val afwRes = iafwService!!.whiteRules
107
                 val afwRes = iafwService!!.whiteRules
107
                 val data = afwRes.data
108
                 val data = afwRes.data
108
                 for (i in data.indices) {
109
                 for (i in data.indices) {
109
                     Log.i(TAG, "whiteRules=" + data[i])
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
             } else {
123
             } else {
113
                 Log.i(TAG, "iafwService=null")
124
                 Log.i(TAG, "iafwService=null")
114
-                sb.append("iafwService=null")
115
             }
125
             }
116
         } catch (e: java.lang.Exception) {
126
         } catch (e: java.lang.Exception) {
117
             e.printStackTrace()
127
             e.printStackTrace()
118
             Log.e(TAG, e.toString())
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