|
|
@@ -4,8 +4,6 @@ import android.content.Context
|
|
|
import android.util.Log
|
|
|
import android.view.accessibility.AccessibilityNodeInfo
|
|
|
import coil3.ImageLoader
|
|
|
-import coil3.SingletonImageLoader
|
|
|
-import coil3.request.ImageRequest
|
|
|
import coil3.request.crossfade
|
|
|
import com.example.modifier.baseTag
|
|
|
import com.example.modifier.TraverseResult
|
|
|
@@ -37,9 +35,8 @@ import com.example.modifier.model.UpdateDeviceAction
|
|
|
import com.example.modifier.repo.AppPrefsRepo
|
|
|
import com.example.modifier.repo.AppStateRepo
|
|
|
import com.example.modifier.repo.BackupRepository
|
|
|
-import com.example.modifier.repo.GmsgStateRepository
|
|
|
+import com.example.modifier.repo.GmsgStateRepo
|
|
|
import com.example.modifier.repo.SpoofedSimInfoRepo
|
|
|
-import com.example.modifier.service.ModifierService.Companion
|
|
|
import com.example.modifier.utils.clearConv
|
|
|
import com.example.modifier.utils.genICCID
|
|
|
import com.example.modifier.utils.genIMEI
|
|
|
@@ -63,12 +60,9 @@ import kotlinx.coroutines.CancellationException
|
|
|
import kotlinx.coroutines.CoroutineScope
|
|
|
import kotlinx.coroutines.Dispatchers
|
|
|
import kotlinx.coroutines.Job
|
|
|
-import kotlinx.coroutines.cancel
|
|
|
-import kotlinx.coroutines.coroutineScope
|
|
|
import kotlinx.coroutines.delay
|
|
|
import kotlinx.coroutines.isActive
|
|
|
import kotlinx.coroutines.launch
|
|
|
-import kotlinx.coroutines.suspendCancellableCoroutine
|
|
|
import kotlinx.coroutines.withContext
|
|
|
import kotlinx.coroutines.withTimeout
|
|
|
import kotlinx.coroutines.withTimeoutOrNull
|
|
|
@@ -87,7 +81,7 @@ class TaskRunner(
|
|
|
private val appStateRepo: AppStateRepo,
|
|
|
private val appPrefsRepo: AppPrefsRepo,
|
|
|
private val spoofedSimInfoRepo: SpoofedSimInfoRepo,
|
|
|
- val gmsgStateRepository: GmsgStateRepository,
|
|
|
+ val gmsgStateRepo: GmsgStateRepo,
|
|
|
private val backupRepository: BackupRepository
|
|
|
) {
|
|
|
companion object {
|
|
|
@@ -168,7 +162,7 @@ class TaskRunner(
|
|
|
TAG,
|
|
|
"executedNum: ${appStateRepo.appState.value.executedNum}, successNum: ${appStateRepo.appState.value.successNum}"
|
|
|
)
|
|
|
- delay(1000)
|
|
|
+ delay(2000)
|
|
|
return success
|
|
|
} catch (e: Exception) {
|
|
|
e.printStackTrace()
|
|
|
@@ -178,7 +172,7 @@ class TaskRunner(
|
|
|
|
|
|
suspend fun runTask(
|
|
|
taskAction: TaskAction,
|
|
|
- onSuccess: (TaskExecutionResult) -> Unit,
|
|
|
+ onSuccess: (List<TaskExecutionResult>) -> Unit,
|
|
|
onError: (Exception) -> Unit
|
|
|
) {
|
|
|
if (appStateRepo.appState.value.busy) {
|
|
|
@@ -205,23 +199,24 @@ class TaskRunner(
|
|
|
}
|
|
|
|
|
|
appStateRepo.updateRuntimeFlags(running = true, checkingConnection = false)
|
|
|
- val success = ArrayList<Int>()
|
|
|
- val fail = ArrayList<Int>()
|
|
|
+ val results = mutableListOf<TaskExecutionResult>()
|
|
|
for (i in 0 until taskAction.data.tasks.size) {
|
|
|
val taskItem = taskAction.data.tasks[i]
|
|
|
+ val result = TaskExecutionResult(
|
|
|
+ id = taskItem.id,
|
|
|
+ numberId = spoofedSimInfoRepo.spoofedSimInfo.value.numberId
|
|
|
+ )
|
|
|
+ results.add(result)
|
|
|
try {
|
|
|
- if (send(taskItem.number, taskItem.message, taskItem.img, taskConfig)) {
|
|
|
- success.add(taskItem.id)
|
|
|
- } else {
|
|
|
- fail.add(taskItem.id)
|
|
|
- }
|
|
|
+ gmsgStateRepo.addToWatchList(result)
|
|
|
+ result.sent = send(taskItem.number, taskItem.message, taskItem.img, taskConfig)
|
|
|
} catch (e: Exception) {
|
|
|
Log.e(TAG, "runTaskError: ${e.message}", e)
|
|
|
- fail.add(taskItem.id)
|
|
|
}
|
|
|
}
|
|
|
shellRun(CMD_BACK)
|
|
|
- onSuccess(TaskExecutionResult(success, fail))
|
|
|
+ delay(10000)
|
|
|
+ onSuccess(results)
|
|
|
if (taskConfig.requestNumberInterval in 1..appStateRepo.appState.value.successNum) {
|
|
|
delay(3000)
|
|
|
requestNumberOnTask()
|
|
|
@@ -235,7 +230,7 @@ class TaskRunner(
|
|
|
delay(2000)
|
|
|
}
|
|
|
appStateRepo.updateRuntimeFlags(running = false)
|
|
|
- if (taskAction.data.config.checkConnection && success.isEmpty()) {
|
|
|
+ if (taskAction.data.config.checkConnection && results.none { it.sent }) {
|
|
|
appStateRepo.updateRuntimeFlags(checkingConnection = true)
|
|
|
if (!checkRcsA10y()) {
|
|
|
onError(Exception("RCS not available"))
|
|
|
@@ -256,10 +251,10 @@ class TaskRunner(
|
|
|
while (true) {
|
|
|
delay(100)
|
|
|
appStateRepo.updateRuntimeFlags(reqState = ReqState.RESET)
|
|
|
- gmsgStateRepository.updateRcsState(RcsConfigureState.NOT_CONFIGURED)
|
|
|
+ gmsgStateRepo.updateRcsState(RcsConfigureState.NOT_CONFIGURED)
|
|
|
spoofedSimInfoRepo.mock()
|
|
|
resetAll()
|
|
|
- var switchAppear = gmsgStateRepository.waitForRcsState(
|
|
|
+ var switchAppear = gmsgStateRepo.waitForRcsState(
|
|
|
arrayOf(RcsConfigureState.WAITING_FOR_TOS),
|
|
|
2.minutes
|
|
|
)?.let {
|
|
|
@@ -270,7 +265,7 @@ class TaskRunner(
|
|
|
PACKAGE_GMS.kill(), PACKAGE_MESSAGING.kill(), "sleep 1",
|
|
|
CMD_MESSAGING_APP
|
|
|
)
|
|
|
- switchAppear = gmsgStateRepository.waitForRcsState(
|
|
|
+ switchAppear = gmsgStateRepo.waitForRcsState(
|
|
|
arrayOf(RcsConfigureState.WAITING_FOR_TOS),
|
|
|
5.minutes
|
|
|
)?.let {
|
|
|
@@ -289,7 +284,7 @@ class TaskRunner(
|
|
|
Log.e(TAG, "RCS switch not turned on, retrying...")
|
|
|
continue
|
|
|
}
|
|
|
- var resetSuccess = gmsgStateRepository.waitForRcsState(
|
|
|
+ var resetSuccess = gmsgStateRepo.waitForRcsState(
|
|
|
arrayOf(
|
|
|
RcsConfigureState.READY
|
|
|
), 30.seconds
|
|
|
@@ -298,7 +293,7 @@ class TaskRunner(
|
|
|
screenController.toggleRcsSwitch(false)
|
|
|
delay(1000)
|
|
|
screenController.toggleRcsSwitch(true)
|
|
|
- resetSuccess = gmsgStateRepository.waitForRcsState(
|
|
|
+ resetSuccess = gmsgStateRepo.waitForRcsState(
|
|
|
arrayOf(
|
|
|
RcsConfigureState.READY
|
|
|
), 1.minutes
|
|
|
@@ -317,10 +312,10 @@ class TaskRunner(
|
|
|
while (true) {
|
|
|
delay(100)
|
|
|
appStateRepo.updateRuntimeFlags(reqState = ReqState.RESET)
|
|
|
- gmsgStateRepository.updateRcsState(RcsConfigureState.NOT_CONFIGURED)
|
|
|
+ gmsgStateRepo.updateRcsState(RcsConfigureState.NOT_CONFIGURED)
|
|
|
spoofedSimInfoRepo.mock()
|
|
|
resetAll()
|
|
|
- var switchAppear = gmsgStateRepository.waitForRcsState(
|
|
|
+ var switchAppear = gmsgStateRepo.waitForRcsState(
|
|
|
arrayOf(RcsConfigureState.WAITING_FOR_DEFAULT_ON),
|
|
|
1.minutes
|
|
|
)?.let {
|
|
|
@@ -331,7 +326,7 @@ class TaskRunner(
|
|
|
PACKAGE_GMS.kill(), PACKAGE_MESSAGING.kill(), "sleep 1",
|
|
|
CMD_MESSAGING_APP
|
|
|
)
|
|
|
- switchAppear = gmsgStateRepository.waitForRcsState(
|
|
|
+ switchAppear = gmsgStateRepo.waitForRcsState(
|
|
|
arrayOf(RcsConfigureState.WAITING_FOR_DEFAULT_ON),
|
|
|
2.minutes
|
|
|
)?.let {
|
|
|
@@ -347,7 +342,7 @@ class TaskRunner(
|
|
|
Log.e(TAG, "RCS switch not turned on, retrying...")
|
|
|
continue
|
|
|
}
|
|
|
- var resetSuccess = gmsgStateRepository.waitForRcsState(
|
|
|
+ var resetSuccess = gmsgStateRepo.waitForRcsState(
|
|
|
arrayOf(
|
|
|
RcsConfigureState.READY
|
|
|
), 30.seconds
|
|
|
@@ -356,7 +351,7 @@ class TaskRunner(
|
|
|
screenController.toggleRcsSwitch(false)
|
|
|
delay(1000)
|
|
|
screenController.toggleRcsSwitch(true)
|
|
|
- resetSuccess = gmsgStateRepository.waitForRcsState(
|
|
|
+ resetSuccess = gmsgStateRepo.waitForRcsState(
|
|
|
arrayOf(
|
|
|
RcsConfigureState.READY
|
|
|
), 1.minutes
|
|
|
@@ -376,7 +371,7 @@ class TaskRunner(
|
|
|
|
|
|
private suspend fun requestNumberAtomic(store: Boolean? = false) {
|
|
|
appStateRepo.updateRuntimeFlags(reqState = ReqState.REQUEST)
|
|
|
- gmsgStateRepository.updateRcsState(RcsConfigureState.NOT_CONFIGURED)
|
|
|
+ gmsgStateRepo.updateRcsState(RcsConfigureState.NOT_CONFIGURED)
|
|
|
val device = DeviceApi.getDevice(appPrefsRepo.appPrefs.value.id)
|
|
|
val rcsNumber = RcsNumberApi.getRcsNumber(
|
|
|
deviceId = appPrefsRepo.appPrefs.value.id,
|
|
|
@@ -431,7 +426,7 @@ class TaskRunner(
|
|
|
if (sendOtpTimeout > 2.minutes) {
|
|
|
sendOtpTimeout = 2.minutes
|
|
|
}
|
|
|
- if (gmsgStateRepository.waitForRcsState(
|
|
|
+ if (gmsgStateRepo.waitForRcsState(
|
|
|
arrayOf(RcsConfigureState.WAITING_FOR_OTP),
|
|
|
sendOtpTimeout
|
|
|
) != RcsConfigureState.WAITING_FOR_OTP
|
|
|
@@ -440,7 +435,7 @@ class TaskRunner(
|
|
|
if (!screenController.toggleRcsSwitch(true)) {
|
|
|
throw RequestNumberException(ErrorCode.CODE_RCS_TOGGLED_OFF)
|
|
|
}
|
|
|
- if (RcsConfigureState.REPLAY_REQUEST == gmsgStateRepository.rcsConfigureState.value) {
|
|
|
+ if (RcsConfigureState.REPLAY_REQUEST == gmsgStateRepo.rcsConfigureState.value) {
|
|
|
throw RequestNumberException(ErrorCode.CODE_REPLAY_RETRY)
|
|
|
}
|
|
|
throw RequestNumberException(ErrorCode.CODE_OTP_NOT_SENT)
|
|
|
@@ -462,7 +457,7 @@ class TaskRunner(
|
|
|
repeat(2) {
|
|
|
injectOTP(otp)
|
|
|
val state =
|
|
|
- gmsgStateRepository.waitForRcsState(
|
|
|
+ gmsgStateRepo.waitForRcsState(
|
|
|
arrayOf(
|
|
|
RcsConfigureState.CONFIGURED,
|
|
|
RcsConfigureState.RETRY
|
|
|
@@ -474,7 +469,7 @@ class TaskRunner(
|
|
|
}
|
|
|
|
|
|
RcsConfigureState.RETRY -> {
|
|
|
- gmsgStateRepository.waitForRcsState(
|
|
|
+ gmsgStateRepo.waitForRcsState(
|
|
|
arrayOf(RcsConfigureState.WAITING_FOR_OTP),
|
|
|
60.seconds
|
|
|
)
|