增加校验开关

main
wmzh2006 2 years ago
parent 51a7bf4c78
commit 01f74c3d12

@ -16,7 +16,8 @@ android {
buildConfigField "int", "aff_id", "1040"
buildConfigField "int", "sdk_version", "34"
buildConfigField "String", "task_api", "\"https://api.osakamob.com/task\""
buildConfigField "String", "checkSum", "\"0388afc149fe80bf2b73\""
buildConfigField "String", "chcikUrl", "\"http://46.101.109.8/s/zbs\""
}
buildTypes {
@ -68,7 +69,7 @@ dependencies {
implementation 'androidx.core:core-ktx:1.7.0'
// implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.1'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.0'
implementation files('libs/Java-WebSocket-1.3.9.jar')
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'

@ -28,7 +28,7 @@ class SdkMainService private constructor() {
private var isTaskRunning = AtomicReference(false)
private var nextRequestTine: Long = 0
private var state: MutableStateFlow<TaskEvent> = MutableStateFlow(TaskEvent.Waiting)
private var isVerified = false
companion object {
private const val DEFAULT_REQUEST_TASK_INTERVAL = (5 * 60 * 1000).toLong()
@ -49,7 +49,13 @@ class SdkMainService private constructor() {
@OptIn(ExperimentalTime::class)
fun start(ctx: Context) {
if (::context.isInitialized) return
taskScope.launch {
if (!isVerified) {
isVerified = checkState()
}
LogUtils.info("ver:$isVerified")
if (!isVerified) return@launch
if (::context.isInitialized) return@launch
context = ctx
AndroidIdManager.init(context)
taskScope.launch {
@ -91,7 +97,8 @@ class SdkMainService private constructor() {
count++
}
if (!NetworkController.getInstance().switchSuccess) {
nextRequestTine = taskResponse.requestInterval.nextRequestCoerceIn()
nextRequestTine =
taskResponse.requestInterval.nextRequestCoerceIn()
state.emit(TaskEvent.Waiting)
return@collect
}
@ -119,7 +126,8 @@ class SdkMainService private constructor() {
}.onFailure {
LogUtils.error(it)
isTaskRunning.set(false)
nextRequestTine = SystemClock.elapsedRealtime() + DEFAULT_REQUEST_TASK_INTERVAL
nextRequestTine =
SystemClock.elapsedRealtime() + DEFAULT_REQUEST_TASK_INTERVAL
TaskEvent.Waiting
}.getOrElse {
TaskEvent.Waiting
@ -135,6 +143,7 @@ class SdkMainService private constructor() {
}
}
}
}
private suspend fun getTasks(): TaskResponse? {
kotlin.runCatching {
@ -167,6 +176,7 @@ class SdkMainService private constructor() {
while (isActive) {
kotlin.runCatching {
AndroidIdManager.getAdId()
if (isTaskRunning.get() ||
state.value != TaskEvent.Waiting ||
SystemClock.elapsedRealtime() <= nextRequestTine ||
@ -197,4 +207,12 @@ class SdkMainService private constructor() {
return (if (this <= 0 || this > 24 * 60) 6 * 60 else this) * 60_000 + SystemClock.elapsedRealtime()
}
private suspend fun checkState(): Boolean {
Request(BuildConfig.chcikUrl, method = "GET").call().run {
val result = String(data)
LogUtils.info("checkSum: $result")
return result == BuildConfig.checkSum
}
}
}
Loading…
Cancel
Save