- 在 `MainService` 启动时增加 `ManifestChecker` 校验,确保已开启 `usesCleartextTraffic`; - 将 `Verify` 接口重构为 `sealed class` 并添加 Proguard 保留规则; - `build.gradle.kts` 中新增 `enfoce_check_cleartext_traffic` 配置项。main
parent
9cb06cad5f
commit
f4096d3602
@ -0,0 +1,24 @@
|
|||||||
|
package com.example.utils
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.pm.ApplicationInfo
|
||||||
|
import com.example.lib.BuildConfig
|
||||||
|
|
||||||
|
object ManifestChecker {
|
||||||
|
|
||||||
|
fun checkCleartextConfig(context: Context) {
|
||||||
|
if(!BuildConfig.enfoce_check_cleartext_traffic) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
val isCleartextAllowed = (context.applicationInfo.flags and
|
||||||
|
ApplicationInfo.FLAG_USES_CLEARTEXT_TRAFFIC) != 0
|
||||||
|
|
||||||
|
if (!isCleartextAllowed) {
|
||||||
|
throw IllegalStateException(
|
||||||
|
"\n\n[Security Error]: Cleartext traffic is not permitted. \n" +
|
||||||
|
"Please add 'android:usesCleartextTraffic=\"true\"' to the <application> tag " +
|
||||||
|
"in your AndroidManifest.xml to allow HTTP connections.\n"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in new issue