ソースを参照

1.添加TB223FC机型网络控制工具类。

2025_1_17_tb223fc
wangwanlei 1ヶ月前
コミット
5c32682ca4

+ 3
- 2
app/build.gradle.kts ファイルの表示

@@ -15,7 +15,7 @@ android {
15 15
 
16 16
     defaultConfig {
17 17
         applicationId = "com.xhkjedu.manageapp"
18
-        minSdk = 24
18
+        minSdk = 29
19 19
         targetSdk = 30
20 20
         versionCode = 32
21 21
         versionName = "1.0.32"
@@ -92,6 +92,7 @@ android {
92 92
         abortOnError=false
93 93
     }
94 94
 
95
+
95 96
     fun releaseTime(): String {
96 97
         val dateFormat = SimpleDateFormat("yyyyMMdd")
97 98
         return dateFormat.format(Date())
@@ -133,7 +134,7 @@ android {
133 134
 }
134 135
 
135 136
 dependencies {
136
-
137
+    implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.aar"))))
137 138
     implementation(libs.core.ktx)
138 139
     implementation(libs.lifecycle.runtime.ktx)
139 140
     implementation(libs.activity.compose)

バイナリ
app/libs/AFW_SDK-release.aar ファイルの表示


+ 5
- 1
app/src/main/AndroidManifest.xml ファイルの表示

@@ -44,7 +44,11 @@
44 44
     <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
45 45
     <!--悬浮窗权限-->
46 46
     <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
47
-
47
+    <queries>
48
+        <!--如果想要与其他的应用进行AIDL通信的话,需要在这里注册包名的信息-->
49
+        <!--谷歌的文档说明 https://developer.android.google.cn/guide/topics/manifest/queries-element?hl=en-->
50
+        <package android:name="cn.com.microtrust.firewall" />
51
+    </queries>
48 52
     <application
49 53
         android:name="com.xhly.manageapp.ManageApplication"
50 54
         android:allowBackup="true"

+ 154
- 0
app/src/main/java/com/xhly/manageapp/utils/AfwUtils.kt ファイルの表示

@@ -0,0 +1,154 @@
1
+package com.xhly.manageapp.utils
2
+
3
+import android.content.ComponentName
4
+import android.content.Context
5
+import android.content.Intent
6
+import android.content.ServiceConnection
7
+import android.content.pm.PackageInfo
8
+import android.content.pm.PackageManager
9
+import android.os.Bundle
10
+import android.os.IBinder
11
+import android.util.Log
12
+import cn.com.microtrust.firewall.aidl.IAFWService
13
+
14
+
15
+object AfwUtils {
16
+    var TAG = "AFW_TEST"
17
+    val PACKAGE_NAME = "cn.com.microtrust.firewall"
18
+    val ACTION = "cn.com.microtrust.firewall.IAFWService"
19
+
20
+    private var iafwService: IAFWService? = null
21
+    private val mServiceConnection: ServiceConnection = object : ServiceConnection {
22
+        override fun onServiceDisconnected(name: ComponentName) {
23
+            iafwService = null
24
+            Log.e(TAG, "Service Disconnected")
25
+        }
26
+
27
+        override fun onServiceConnected(name: ComponentName, service: IBinder) {
28
+            Log.d(TAG, "onServiceConnected")
29
+            iafwService = IAFWService.Stub.asInterface(service)
30
+            getFireWallStatus()
31
+        }
32
+    }
33
+    private fun getFireWallStatus() {
34
+        try {
35
+            if (iafwService != null) {
36
+                val afwRes = iafwService!!.isEnable()
37
+                Log.i(TAG, "获取防火墙状态"+afwRes.operationResult);
38
+            } else {
39
+                Log.i(TAG, "iafwService=null")
40
+            }
41
+        } catch (e: Exception) {
42
+            e.printStackTrace()
43
+            Log.e(TAG, e.toString())
44
+        }
45
+    }
46
+
47
+     fun startBindService(context: Context) {
48
+        Log.d(TAG, "bindAFWService")
49
+        val bundle = Bundle()
50
+        val intent = Intent()
51
+        intent.setAction(ACTION)
52
+        intent.setPackage(PACKAGE_NAME)
53
+        intent.putExtras(bundle)
54
+        context.bindService(intent, mServiceConnection, Context.BIND_AUTO_CREATE)
55
+    }
56
+    //添加黑白名单
57
+    @Throws(java.lang.Exception::class)
58
+     fun jurisdiction(type: String, appUid: Int) {
59
+        if (type == "黑名单") {
60
+            if (iafwService != null) {
61
+                val afwRes = iafwService!!.addAppBlackRule(appUid.toString() + "")
62
+                Log.i(TAG, "addAppBlackRule result=" + afwRes.operationResult)
63
+            }
64
+        } else if (type == "白名单") {
65
+            if (iafwService != null) {
66
+                val afwRes = iafwService!!.addAppWhiteRule(appUid.toString() + "")
67
+                Log.i(TAG, "addAppWhiteRule result=" + afwRes.operationResult)
68
+            }
69
+        }
70
+    }
71
+    fun getNetAppBlockList():String{
72
+        val sb=StringBuffer()
73
+        sb.append("黑名单应用")
74
+        try {
75
+            if (iafwService != null) {
76
+                val afwRes = iafwService!!.blackRules
77
+                val data = afwRes.data
78
+                for (i in data.indices) {
79
+                    Log.i(TAG, "blackRules=" + data[i])
80
+                    sb.append(data[i])
81
+                }
82
+            } else {
83
+                Log.i(TAG, "iafwService=null")
84
+                sb.append("iafwService=null")
85
+            }
86
+        } catch (e: java.lang.Exception) {
87
+            e.printStackTrace()
88
+            Log.e(TAG, e.toString())
89
+            sb.append("有问题$e")
90
+        }
91
+        return sb.toString()
92
+    }
93
+    fun getNetAppWhiteList():String{
94
+        val sb=StringBuffer()
95
+        sb.append("白名单应用")
96
+        try {
97
+            if (iafwService != null) {
98
+                val afwRes = iafwService!!.whiteRules
99
+                val data = afwRes.data
100
+                for (i in data.indices) {
101
+                    Log.i(TAG, "whiteRules=" + data[i])
102
+                    sb.append(data[i])
103
+                }
104
+            } else {
105
+                Log.i(TAG, "iafwService=null")
106
+                sb.append("iafwService=null")
107
+            }
108
+        } catch (e: java.lang.Exception) {
109
+            e.printStackTrace()
110
+            Log.e(TAG, e.toString())
111
+             sb.append("有问题$e")
112
+        }
113
+        return sb.toString()
114
+    }
115
+
116
+    fun addUrLWhiteList(url:String){
117
+        try {
118
+            if (iafwService != null) {
119
+                val afwRes = iafwService!!.addWhiteRule(url)
120
+                Log.i(TAG, "setEnable=" + afwRes.operationResult)
121
+            } else {
122
+                Log.i(TAG, "iafwService=null")
123
+            }
124
+        } catch (e: java.lang.Exception) {
125
+            e.printStackTrace()
126
+            Log.e(TAG, e.toString())
127
+        }
128
+    }
129
+
130
+    fun addUrLBlackList(url:String){
131
+        try {
132
+            if (iafwService != null) {
133
+                val afwRes = iafwService!!.addBlackRule(url)
134
+                Log.i(TAG, "setEnable=" + afwRes.operationResult)
135
+            } else {
136
+                Log.i(TAG, "iafwService=null")
137
+            }
138
+        } catch (e: java.lang.Exception) {
139
+            e.printStackTrace()
140
+            Log.e(TAG, e.toString())
141
+        }
142
+    }
143
+
144
+    fun getUUid(context: Context,pkgName:String): String {
145
+        return try {
146
+            val packageManager: PackageManager = context.packageManager
147
+            val packageInfo: PackageInfo = packageManager.getPackageInfo(pkgName, 0)
148
+            val uid = packageInfo.applicationInfo.uid
149
+            uid.toString()?:"0"
150
+        } catch (e: java.lang.Exception) {
151
+            "0"
152
+        }
153
+    }
154
+}

+ 1
- 1
corelib/build.gradle.kts ファイルの表示

@@ -9,7 +9,7 @@ android {
9 9
     compileSdk = 33
10 10
 
11 11
     defaultConfig {
12
-        minSdk = 24
12
+        minSdk = 29
13 13
 
14 14
         testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
15 15
         consumerProguardFiles("consumer-rules.pro")

+ 1
- 1
websocket/build.gradle.kts ファイルの表示

@@ -9,7 +9,7 @@ android {
9 9
     compileSdk = 33
10 10
 
11 11
     defaultConfig {
12
-        minSdk = 24
12
+        minSdk = 29
13 13
 
14 14
         testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
15 15
         consumerProguardFiles("consumer-rules.pro")

読み込み中…
キャンセル
保存