|
|
@@ -32,7 +32,7 @@ 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.GoogleMessageStateRepository
|
|
|
+import com.example.modifier.repo.GmsgStateRepository
|
|
|
import com.example.modifier.repo.SpoofedSimInfoRepo
|
|
|
import com.example.modifier.utils.clearConv
|
|
|
import com.example.modifier.utils.genICCID
|
|
|
@@ -75,10 +75,13 @@ class TaskRunner(
|
|
|
private val appStateRepo: AppStateRepo,
|
|
|
private val appPrefsRepo: AppPrefsRepo,
|
|
|
private val spoofedSimInfoRepo: SpoofedSimInfoRepo,
|
|
|
- private val googleMessageStateRepository: GoogleMessageStateRepository,
|
|
|
+ val gmsgStateRepository: GmsgStateRepository,
|
|
|
private val backupRepository: BackupRepository
|
|
|
) {
|
|
|
- private val tag = "$baseTag/TaskRunner"
|
|
|
+ companion object {
|
|
|
+ private const val TAG = "$baseTag/TaskRunner"
|
|
|
+ }
|
|
|
+
|
|
|
private var lastSend = 0L
|
|
|
private var currentTaskId = 0
|
|
|
private var requestMode = 1
|
|
|
@@ -88,10 +91,10 @@ class TaskRunner(
|
|
|
body: String,
|
|
|
taskConfig: TaskConfig
|
|
|
): Boolean {
|
|
|
- Log.i(tag, "Sending SMS to $to: $body")
|
|
|
+ Log.i(TAG, "Sending SMS to $to: $body")
|
|
|
context.startActivity(smsIntent(to, body))
|
|
|
try {
|
|
|
- Log.i(tag, "Command executed successfully, waiting for app to open...")
|
|
|
+ Log.i(TAG, "Command executed successfully, waiting for app to open...")
|
|
|
delay(1000)
|
|
|
var success = false
|
|
|
var traverseResult = TraverseResult()
|
|
|
@@ -119,15 +122,15 @@ class TaskRunner(
|
|
|
}
|
|
|
if (traverseResult.isRcsCapable) {
|
|
|
if (traverseResult.sendBtn == null) {
|
|
|
- Log.i(tag, "Send button not found")
|
|
|
+ Log.i(TAG, "Send button not found")
|
|
|
} else if (taskConfig.e2ee == 2 && !traverseResult.encrypted) {
|
|
|
- Log.i(tag, "E2EE not detected")
|
|
|
+ Log.i(TAG, "E2EE not detected")
|
|
|
} else {
|
|
|
- Log.i(tag, "Clicking send button")
|
|
|
+ Log.i(TAG, "Clicking send button")
|
|
|
|
|
|
val dt = System.currentTimeMillis() - lastSend
|
|
|
if (taskConfig.rcsInterval > 0 && dt < taskConfig.rcsInterval) {
|
|
|
- Log.i(tag, "Waiting for RCS interval")
|
|
|
+ Log.i(TAG, "Waiting for RCS interval")
|
|
|
delay(taskConfig.rcsInterval - dt)
|
|
|
}
|
|
|
traverseResult.sendBtn!!.performAction(AccessibilityNodeInfo.ACTION_CLICK)
|
|
|
@@ -135,11 +138,11 @@ class TaskRunner(
|
|
|
success = true
|
|
|
}
|
|
|
} else {
|
|
|
- Log.i(tag, "RCS not detected")
|
|
|
+ Log.i(TAG, "RCS not detected")
|
|
|
}
|
|
|
appStateRepo.incrementExecutedNum(success)
|
|
|
Log.i(
|
|
|
- tag,
|
|
|
+ TAG,
|
|
|
"executedNum: ${appStateRepo.appState.value.executedNum}, successNum: ${appStateRepo.appState.value.successNum}"
|
|
|
)
|
|
|
delay(1000)
|
|
|
@@ -188,7 +191,7 @@ class TaskRunner(
|
|
|
fail.add(taskItem.id)
|
|
|
}
|
|
|
} catch (e: Exception) {
|
|
|
- Log.e(tag, "runTaskError: ${e.message}", e)
|
|
|
+ Log.e(TAG, "runTaskError: ${e.message}", e)
|
|
|
fail.add(taskItem.id)
|
|
|
}
|
|
|
}
|
|
|
@@ -216,7 +219,7 @@ class TaskRunner(
|
|
|
appStateRepo.updateRuntimeFlags(checkingConnection = false)
|
|
|
}
|
|
|
} catch (e: Exception) {
|
|
|
- Log.e(tag, "runTaskError: ${e.message}", e)
|
|
|
+ Log.e(TAG, "runTaskError: ${e.message}", e)
|
|
|
onError(e)
|
|
|
appStateRepo.updateRuntimeFlags(running = false)
|
|
|
}
|
|
|
@@ -228,10 +231,10 @@ class TaskRunner(
|
|
|
while (true) {
|
|
|
delay(100)
|
|
|
appStateRepo.updateRuntimeFlags(requestNumberState = RequestNumberState.RESET)
|
|
|
- googleMessageStateRepository.updateRcsState(RcsConfigureState.NOT_CONFIGURED)
|
|
|
+ gmsgStateRepository.updateRcsState(RcsConfigureState.NOT_CONFIGURED)
|
|
|
spoofedSimInfoRepo.mock()
|
|
|
resetAll()
|
|
|
- var switchAppear = googleMessageStateRepository.waitForRcsState(
|
|
|
+ var switchAppear = gmsgStateRepository.waitForRcsState(
|
|
|
arrayOf(RcsConfigureState.WAITING_FOR_TOS),
|
|
|
2.minutes
|
|
|
)?.let {
|
|
|
@@ -242,26 +245,26 @@ class TaskRunner(
|
|
|
PACKAGE_GMS.kill(), PACKAGE_MESSAGING.kill(), "sleep 1",
|
|
|
CMD_MESSAGING_APP
|
|
|
)
|
|
|
- switchAppear = googleMessageStateRepository.waitForRcsState(
|
|
|
+ switchAppear = gmsgStateRepository.waitForRcsState(
|
|
|
arrayOf(RcsConfigureState.WAITING_FOR_TOS),
|
|
|
5.minutes
|
|
|
)?.let {
|
|
|
it == RcsConfigureState.WAITING_FOR_TOS
|
|
|
}
|
|
|
if (switchAppear != true) {
|
|
|
- Log.e(tag, "RCS not entered default on state, retrying...")
|
|
|
+ Log.e(TAG, "RCS not entered default on state, retrying...")
|
|
|
continue
|
|
|
}
|
|
|
}
|
|
|
if (!screenController.toggleRcsSwitch(false)) {
|
|
|
- Log.e(tag, "RCS switch not turned off, retrying...")
|
|
|
+ Log.e(TAG, "RCS switch not turned off, retrying...")
|
|
|
continue
|
|
|
}
|
|
|
if (!screenController.toggleRcsSwitch(true)) {
|
|
|
- Log.e(tag, "RCS switch not turned on, retrying...")
|
|
|
+ Log.e(TAG, "RCS switch not turned on, retrying...")
|
|
|
continue
|
|
|
}
|
|
|
- var resetSuccess = googleMessageStateRepository.waitForRcsState(
|
|
|
+ var resetSuccess = gmsgStateRepository.waitForRcsState(
|
|
|
arrayOf(
|
|
|
RcsConfigureState.READY
|
|
|
), 30.seconds
|
|
|
@@ -270,13 +273,13 @@ class TaskRunner(
|
|
|
screenController.toggleRcsSwitch(false)
|
|
|
delay(1000)
|
|
|
screenController.toggleRcsSwitch(true)
|
|
|
- resetSuccess = googleMessageStateRepository.waitForRcsState(
|
|
|
+ resetSuccess = gmsgStateRepository.waitForRcsState(
|
|
|
arrayOf(
|
|
|
RcsConfigureState.READY
|
|
|
), 1.minutes
|
|
|
).let { it == RcsConfigureState.READY }
|
|
|
}
|
|
|
- Log.i(tag, "waitForRcsState: $resetSuccess")
|
|
|
+ Log.i(TAG, "waitForRcsState: $resetSuccess")
|
|
|
appStateRepo.resetRequestedNum()
|
|
|
if (resetSuccess) {
|
|
|
delay(3000)
|
|
|
@@ -289,10 +292,10 @@ class TaskRunner(
|
|
|
while (true) {
|
|
|
delay(100)
|
|
|
appStateRepo.updateRuntimeFlags(requestNumberState = RequestNumberState.RESET)
|
|
|
- googleMessageStateRepository.updateRcsState(RcsConfigureState.NOT_CONFIGURED)
|
|
|
+ gmsgStateRepository.updateRcsState(RcsConfigureState.NOT_CONFIGURED)
|
|
|
spoofedSimInfoRepo.mock()
|
|
|
resetAll()
|
|
|
- var switchAppear = googleMessageStateRepository.waitForRcsState(
|
|
|
+ var switchAppear = gmsgStateRepository.waitForRcsState(
|
|
|
arrayOf(RcsConfigureState.WAITING_FOR_DEFAULT_ON),
|
|
|
1.minutes
|
|
|
)?.let {
|
|
|
@@ -303,23 +306,23 @@ class TaskRunner(
|
|
|
PACKAGE_GMS.kill(), PACKAGE_MESSAGING.kill(), "sleep 1",
|
|
|
CMD_MESSAGING_APP
|
|
|
)
|
|
|
- switchAppear = googleMessageStateRepository.waitForRcsState(
|
|
|
+ switchAppear = gmsgStateRepository.waitForRcsState(
|
|
|
arrayOf(RcsConfigureState.WAITING_FOR_DEFAULT_ON),
|
|
|
2.minutes
|
|
|
)?.let {
|
|
|
it == RcsConfigureState.WAITING_FOR_DEFAULT_ON
|
|
|
}
|
|
|
if (switchAppear != true) {
|
|
|
- Log.e(tag, "RCS not entered default on state, retrying...")
|
|
|
+ Log.e(TAG, "RCS not entered default on state, retrying...")
|
|
|
continue
|
|
|
}
|
|
|
}
|
|
|
val switchOn = screenController.toggleRcsSwitch(true)
|
|
|
if (!switchOn) {
|
|
|
- Log.e(tag, "RCS switch not turned on, retrying...")
|
|
|
+ Log.e(TAG, "RCS switch not turned on, retrying...")
|
|
|
continue
|
|
|
}
|
|
|
- var resetSuccess = googleMessageStateRepository.waitForRcsState(
|
|
|
+ var resetSuccess = gmsgStateRepository.waitForRcsState(
|
|
|
arrayOf(
|
|
|
RcsConfigureState.READY
|
|
|
), 30.seconds
|
|
|
@@ -328,13 +331,13 @@ class TaskRunner(
|
|
|
screenController.toggleRcsSwitch(false)
|
|
|
delay(1000)
|
|
|
screenController.toggleRcsSwitch(true)
|
|
|
- resetSuccess = googleMessageStateRepository.waitForRcsState(
|
|
|
+ resetSuccess = gmsgStateRepository.waitForRcsState(
|
|
|
arrayOf(
|
|
|
RcsConfigureState.READY
|
|
|
), 1.minutes
|
|
|
).let { it == RcsConfigureState.READY }
|
|
|
}
|
|
|
- Log.i(tag, "waitForRcsState: $resetSuccess")
|
|
|
+ Log.i(TAG, "waitForRcsState: $resetSuccess")
|
|
|
appStateRepo.resetRequestedNum()
|
|
|
if (resetSuccess) {
|
|
|
delay(1000)
|
|
|
@@ -347,14 +350,14 @@ class TaskRunner(
|
|
|
|
|
|
suspend fun requestNumberAtomic() {
|
|
|
appStateRepo.updateRuntimeFlags(requestNumberState = RequestNumberState.REQUEST)
|
|
|
- googleMessageStateRepository.updateRcsState(RcsConfigureState.NOT_CONFIGURED)
|
|
|
+ gmsgStateRepository.updateRcsState(RcsConfigureState.NOT_CONFIGURED)
|
|
|
val device = DeviceApi.getDevice(appPrefsRepo.appPrefs.value.id)
|
|
|
val rcsNumber = RcsNumberApi.getRcsNumber(
|
|
|
appPrefsRepo.appPrefs.value.id,
|
|
|
currentTaskId,
|
|
|
device.pinCountry
|
|
|
)
|
|
|
- Log.i(tag, "requestNumber response: $rcsNumber")
|
|
|
+ Log.i(TAG, "requestNumber response: $rcsNumber")
|
|
|
|
|
|
appStateRepo.updateRuntimeFlags(requestNumberState = RequestNumberState.OTP_1)
|
|
|
|
|
|
@@ -401,7 +404,7 @@ class TaskRunner(
|
|
|
if (sendOtpTimeout > 2.minutes) {
|
|
|
sendOtpTimeout = 2.minutes
|
|
|
}
|
|
|
- if (googleMessageStateRepository.waitForRcsState(
|
|
|
+ if (gmsgStateRepository.waitForRcsState(
|
|
|
arrayOf(RcsConfigureState.WAITING_FOR_OTP),
|
|
|
sendOtpTimeout
|
|
|
) != RcsConfigureState.WAITING_FOR_OTP
|
|
|
@@ -410,7 +413,7 @@ class TaskRunner(
|
|
|
if (!screenController.toggleRcsSwitch(true)) {
|
|
|
throw RequestNumberException(ErrorCode.CODE_RCS_TOGGLED_OFF)
|
|
|
}
|
|
|
- if (RcsConfigureState.REPLAY_REQUEST == googleMessageStateRepository.rcsConfigureState.value) {
|
|
|
+ if (RcsConfigureState.REPLAY_REQUEST == gmsgStateRepository.rcsConfigureState.value) {
|
|
|
throw RequestNumberException(ErrorCode.CODE_REPLAY_RETRY)
|
|
|
}
|
|
|
throw RequestNumberException(ErrorCode.CODE_OTP_NOT_SENT)
|
|
|
@@ -432,7 +435,7 @@ class TaskRunner(
|
|
|
repeat(2) {
|
|
|
injectOTP(otp)
|
|
|
val state =
|
|
|
- googleMessageStateRepository.waitForRcsState(
|
|
|
+ gmsgStateRepository.waitForRcsState(
|
|
|
arrayOf(
|
|
|
RcsConfigureState.CONFIGURED,
|
|
|
RcsConfigureState.RETRY
|
|
|
@@ -444,7 +447,7 @@ class TaskRunner(
|
|
|
}
|
|
|
|
|
|
RcsConfigureState.RETRY -> {
|
|
|
- googleMessageStateRepository.waitForRcsState(
|
|
|
+ gmsgStateRepository.waitForRcsState(
|
|
|
arrayOf(RcsConfigureState.WAITING_FOR_OTP),
|
|
|
60.seconds
|
|
|
)
|
|
|
@@ -520,9 +523,9 @@ class TaskRunner(
|
|
|
return@withTimeoutOrNull true
|
|
|
} catch (e: Exception) {
|
|
|
if (e is RequestNumberException) {
|
|
|
- Log.e(tag, "requestNumberError: ${e.message}")
|
|
|
+ Log.e(TAG, "requestNumberError: ${e.message}")
|
|
|
} else {
|
|
|
- Log.e(tag, "requestNumberError: ${e.message}", e)
|
|
|
+ Log.e(TAG, "requestNumberError: ${e.message}", e)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -535,9 +538,9 @@ class TaskRunner(
|
|
|
)
|
|
|
appStateRepo.resetSuccessNum()
|
|
|
appStateRepo.resetExecutedNum()
|
|
|
- Log.i(tag, "requestNumber success")
|
|
|
+ Log.i(TAG, "requestNumber success")
|
|
|
} else {
|
|
|
- Log.e(tag, "requestNumber failed")
|
|
|
+ Log.e(TAG, "requestNumber failed")
|
|
|
appStateRepo.updateSend(false)
|
|
|
}
|
|
|
appStateRepo.updateRuntimeFlags(
|
|
|
@@ -549,7 +552,7 @@ class TaskRunner(
|
|
|
|
|
|
private suspend fun checkRcsConnectivity(): Boolean = run checkRcsConnection@{
|
|
|
repeat(3) {
|
|
|
- Log.i(tag, "Checking RCS status...")
|
|
|
+ Log.i(TAG, "Checking RCS status...")
|
|
|
shellRun(
|
|
|
CMD_CONVERSATION_LIST_ACTIVITY,
|
|
|
CMD_RCS_SETTINGS_ACTIVITY,
|
|
|
@@ -558,11 +561,11 @@ class TaskRunner(
|
|
|
val res = TraverseResult()
|
|
|
screenInspector.traverseNode(res)
|
|
|
if (res.rcsConnectionStatus == RcsConnectionStatus.CONNECTED) {
|
|
|
- Log.i(tag, "RCS is connected")
|
|
|
+ Log.i(TAG, "RCS is connected")
|
|
|
shellRun(CMD_BACK)
|
|
|
return@checkRcsConnection true
|
|
|
} else {
|
|
|
- Log.i(tag, "RCS not connected, retrying...")
|
|
|
+ Log.i(TAG, "RCS not connected, retrying...")
|
|
|
}
|
|
|
shellRun(CMD_BACK, "sleep ${it * 2}")
|
|
|
}
|
|
|
@@ -579,14 +582,14 @@ class TaskRunner(
|
|
|
val config = ktorClient
|
|
|
.get(SysConfigApi.Id(SysConfigApi(), "check_availability_numbers"))
|
|
|
.body<SysConfigResponse>()
|
|
|
- Log.i(tag, "sysConfig response: $config")
|
|
|
+ Log.i(TAG, "sysConfig response: $config")
|
|
|
checkRcsA10yNumbers.addAll(config.value.split(",").map { it.trim() })
|
|
|
} catch (exception: Exception) {
|
|
|
- Log.e(tag, "sysConfig Error: ${exception.message}", exception)
|
|
|
+ Log.e(TAG, "sysConfig Error: ${exception.message}", exception)
|
|
|
}
|
|
|
|
|
|
if (checkRcsA10yNumbers.isEmpty()) {
|
|
|
- Log.e(tag, "checkRcsA10yNumbers is empty")
|
|
|
+ Log.e(TAG, "checkRcsA10yNumbers is empty")
|
|
|
return@checkA10y true
|
|
|
}
|
|
|
|
|
|
@@ -599,7 +602,7 @@ class TaskRunner(
|
|
|
if (traverseResult.isRcsCapable) {
|
|
|
return@checkA10y true
|
|
|
} else {
|
|
|
- Log.i(tag, "checkRcsA10y: RCS not detected")
|
|
|
+ Log.i(TAG, "checkRcsA10y: RCS not detected")
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -643,12 +646,12 @@ class TaskRunner(
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- Log.i(tag, "Apk file saved to ${file.path}")
|
|
|
+ Log.i(TAG, "Apk file saved to ${file.path}")
|
|
|
shellRun("pm install -d -r ${file.path}")
|
|
|
onSuccess()
|
|
|
file.delete()
|
|
|
} catch (e: Exception) {
|
|
|
- Log.e(tag, "Failed to install apk", e)
|
|
|
+ Log.e(TAG, "Failed to install apk", e)
|
|
|
onError(e)
|
|
|
}
|
|
|
}
|
|
|
@@ -662,7 +665,7 @@ class TaskRunner(
|
|
|
val (out, err) = shellRun(*installApkAction.data.script.split("\n").toTypedArray())
|
|
|
onSuccess(out, err)
|
|
|
} catch (e: Exception) {
|
|
|
- Log.e(tag, "Failed to run script", e)
|
|
|
+ Log.e(TAG, "Failed to run script", e)
|
|
|
onError(e)
|
|
|
}
|
|
|
}
|
|
|
@@ -681,7 +684,7 @@ class TaskRunner(
|
|
|
}
|
|
|
onSuccess()
|
|
|
} catch (e: Exception) {
|
|
|
- Log.e(tag, "Failed to update device", e)
|
|
|
+ Log.e(TAG, "Failed to update device", e)
|
|
|
onError(e)
|
|
|
}
|
|
|
}
|