|
|
@@ -57,14 +57,19 @@ import io.ktor.client.request.prepareGet
|
|
|
import io.ktor.utils.io.ByteReadChannel
|
|
|
import io.ktor.utils.io.core.isEmpty
|
|
|
import io.ktor.utils.io.core.readBytes
|
|
|
+import kotlinx.coroutines.CoroutineScope
|
|
|
import kotlinx.coroutines.Dispatchers
|
|
|
+import kotlinx.coroutines.Job
|
|
|
+import kotlinx.coroutines.coroutineScope
|
|
|
import kotlinx.coroutines.delay
|
|
|
+import kotlinx.coroutines.launch
|
|
|
import kotlinx.coroutines.withContext
|
|
|
import kotlinx.coroutines.withTimeout
|
|
|
import kotlinx.coroutines.withTimeoutOrNull
|
|
|
import java.io.File
|
|
|
import java.time.LocalDateTime
|
|
|
import java.time.temporal.ChronoUnit
|
|
|
+import kotlin.coroutines.coroutineContext
|
|
|
import kotlin.time.Duration.Companion.days
|
|
|
import kotlin.time.Duration.Companion.hours
|
|
|
import kotlin.time.Duration.Companion.minutes
|
|
|
@@ -184,12 +189,7 @@ class TaskRunner(
|
|
|
for (i in 0 until taskAction.data.tasks.size) {
|
|
|
val taskItem = taskAction.data.tasks[i]
|
|
|
try {
|
|
|
- if (send(
|
|
|
- taskItem.number,
|
|
|
- taskItem.message,
|
|
|
- taskConfig
|
|
|
- )
|
|
|
- ) {
|
|
|
+ if (send(taskItem.number, taskItem.message, taskConfig)) {
|
|
|
success.add(taskItem.id)
|
|
|
} else {
|
|
|
fail.add(taskItem.id)
|
|
|
@@ -387,10 +387,24 @@ class TaskRunner(
|
|
|
if (rcsNumber.expiryTime.isBefore(LocalDateTime.now())) {
|
|
|
throw RequestNumberException(ErrorCode.CODE_NUMBER_EXPIRED)
|
|
|
}
|
|
|
- var sendOtpTimeout = ChronoUnit.SECONDS.between(
|
|
|
- LocalDateTime.now(),
|
|
|
- rcsNumber.expiryTime
|
|
|
- ).seconds
|
|
|
+ var tosAgreeJob: Job? = null
|
|
|
+ if (rcsNumber.country.lowercase() == "af") {
|
|
|
+ tosAgreeJob = CoroutineScope(coroutineContext).launch {
|
|
|
+ run tos@{
|
|
|
+ repeat(60 * 1000 / 200) {
|
|
|
+ delay(200)
|
|
|
+ val traverseResult = TraverseResult()
|
|
|
+ screenInspector.traverseNode(traverseResult)
|
|
|
+ if (traverseResult.tosAgreeBtn != null) {
|
|
|
+ traverseResult.tosAgreeBtn!!.performAction(AccessibilityNodeInfo.ACTION_CLICK)
|
|
|
+ return@tos
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ var sendOtpTimeout =
|
|
|
+ ChronoUnit.SECONDS.between(LocalDateTime.now(), rcsNumber.expiryTime).seconds
|
|
|
if (sendOtpTimeout < 5.seconds) {
|
|
|
throw RequestNumberException(ErrorCode.CODE_TIMEOUT_TOO_SHORT)
|
|
|
}
|
|
|
@@ -402,6 +416,7 @@ class TaskRunner(
|
|
|
sendOtpTimeout
|
|
|
) != RcsConfigureState.WAITING_FOR_OTP
|
|
|
) {
|
|
|
+ tosAgreeJob?.cancel()
|
|
|
if (!screenController.toggleRcsSwitch(true)) {
|
|
|
throw RequestNumberException(ErrorCode.CODE_RCS_TOGGLED_OFF)
|
|
|
}
|
|
|
@@ -410,7 +425,7 @@ class TaskRunner(
|
|
|
}
|
|
|
throw RequestNumberException(ErrorCode.CODE_OTP_NOT_SENT)
|
|
|
}
|
|
|
-
|
|
|
+ tosAgreeJob?.cancel()
|
|
|
RcsNumberApi.notifyOtpState(rcsNumber.id)
|
|
|
|
|
|
if (rcsNumber.expiryTime.isBefore(LocalDateTime.now())) {
|
|
|
@@ -455,6 +470,9 @@ class TaskRunner(
|
|
|
throw RequestNumberException(ErrorCode.CODE_OTP_VERIFY_FAILED)
|
|
|
} else {
|
|
|
RcsNumberApi.notifyConfigured(rcsNumber.id)
|
|
|
+ delay(5000)
|
|
|
+ shellRun(PACKAGE_MESSAGING.kill(), "sleep 1", CMD_MESSAGING_APP)
|
|
|
+ delay(2000)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -537,9 +555,6 @@ class TaskRunner(
|
|
|
appStateRepo.resetSuccessNum()
|
|
|
appStateRepo.resetExecutedNum()
|
|
|
Log.i(tag, "requestNumber success")
|
|
|
- delay(5000)
|
|
|
- shellRun(PACKAGE_MESSAGING.kill(), "sleep 1", CMD_MESSAGING_APP)
|
|
|
- delay(2000)
|
|
|
} else {
|
|
|
Log.e(tag, "requestNumber failed")
|
|
|
appStateRepo.updateSend(false)
|