|
|
@@ -5,7 +5,7 @@ import android.text.TextUtils
|
|
|
import android.util.Base64
|
|
|
import android.util.Log
|
|
|
import android.view.accessibility.AccessibilityNodeInfo
|
|
|
-import com.example.modifier.TAG
|
|
|
+import com.example.modifier.baseTag
|
|
|
import com.example.modifier.TraverseResult
|
|
|
import com.example.modifier.constants.CMD_BACK
|
|
|
import com.example.modifier.constants.CMD_CONVERSATION_LIST_ACTIVITY
|
|
|
@@ -29,7 +29,6 @@ import com.example.modifier.http.response.RcsNumberResponse
|
|
|
import com.example.modifier.http.response.SysConfigResponse
|
|
|
import com.example.modifier.model.InstallApkAction
|
|
|
import com.example.modifier.model.RunScriptAction
|
|
|
-import com.example.modifier.model.SocketCallback
|
|
|
import com.example.modifier.model.SpoofedSimInfo
|
|
|
import com.example.modifier.model.TaskAction
|
|
|
import com.example.modifier.model.TaskConfig
|
|
|
@@ -39,7 +38,6 @@ import com.example.modifier.repo.AppStateRepository
|
|
|
import com.example.modifier.repo.BackupRepository
|
|
|
import com.example.modifier.repo.GoogleMessageStateRepository
|
|
|
import com.example.modifier.repo.SpoofedSimInfoRepository
|
|
|
-import com.example.modifier.serializer.Json
|
|
|
import com.example.modifier.utils.changeClashProfile
|
|
|
import com.example.modifier.utils.clearConv
|
|
|
import com.example.modifier.utils.genICCID
|
|
|
@@ -77,8 +75,6 @@ import kotlinx.coroutines.launch
|
|
|
import kotlinx.coroutines.withContext
|
|
|
import kotlinx.coroutines.withTimeout
|
|
|
import kotlinx.coroutines.withTimeoutOrNull
|
|
|
-import kotlinx.serialization.encodeToString
|
|
|
-import org.json.JSONObject
|
|
|
import java.io.File
|
|
|
import java.time.LocalDateTime
|
|
|
import java.time.temporal.ChronoUnit
|
|
|
@@ -97,6 +93,7 @@ class TaskRunner(
|
|
|
private val googleMessageStateRepository: GoogleMessageStateRepository,
|
|
|
private val backupRepository: BackupRepository
|
|
|
) {
|
|
|
+ private val tag = "$baseTag/TaskRunner"
|
|
|
private var lastSend = 0L
|
|
|
private var currentTaskId = 0
|
|
|
private var requestMode = 1
|
|
|
@@ -117,37 +114,49 @@ 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,
|
|
|
+ tag,
|
|
|
"Command executed successfully, waiting for app to open..."
|
|
|
)
|
|
|
delay(1000)
|
|
|
var success = false
|
|
|
var traverseResult = TraverseResult()
|
|
|
withTimeoutOrNull(taskConfig.rcsWait) {
|
|
|
- while (true) {
|
|
|
+ repeat(999) {
|
|
|
traverseResult = TraverseResult()
|
|
|
screenInspector.traverseNode(traverseResult)
|
|
|
if (traverseResult.isRcsCapable && traverseResult.sendBtn != null) {
|
|
|
- if (!taskConfig.endToEndEncryption || traverseResult.encrypted) {
|
|
|
- break
|
|
|
- }
|
|
|
+ return@withTimeoutOrNull
|
|
|
}
|
|
|
delay(200)
|
|
|
}
|
|
|
}
|
|
|
+ if (traverseResult.isRcsCapable && traverseResult.sendBtn != null && taskConfig.e2ee > 0) {
|
|
|
+ withTimeoutOrNull(taskConfig.e2eeTimeout) {
|
|
|
+ repeat(999) {
|
|
|
+ traverseResult = TraverseResult()
|
|
|
+ screenInspector.traverseNode(traverseResult)
|
|
|
+ if (traverseResult.encrypted) {
|
|
|
+ return@withTimeoutOrNull
|
|
|
+ }
|
|
|
+ delay(200)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
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")
|
|
|
} 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)
|
|
|
@@ -155,11 +164,11 @@ class TaskRunner(
|
|
|
success = true
|
|
|
}
|
|
|
} else {
|
|
|
- Log.i(TAG, "RCS not detected")
|
|
|
+ Log.i(tag, "RCS not detected")
|
|
|
}
|
|
|
appStateRepository.incrementExecutedNum(success)
|
|
|
Log.i(
|
|
|
- TAG,
|
|
|
+ tag,
|
|
|
"executedNum: ${appState.value.executedNum}, successNum: ${appState.value.successNum}"
|
|
|
)
|
|
|
delay(1000)
|
|
|
@@ -213,7 +222,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)
|
|
|
}
|
|
|
}
|
|
|
@@ -233,7 +242,7 @@ class TaskRunner(
|
|
|
}
|
|
|
appStateRepository.updateRuntimeFlags(running = false)
|
|
|
} catch (e: Exception) {
|
|
|
- Log.e(TAG, "runTaskError: ${e.message}", e)
|
|
|
+ Log.e(tag, "runTaskError: ${e.message}", e)
|
|
|
onError(e)
|
|
|
appStateRepository.updateRuntimeFlags(running = false)
|
|
|
}
|
|
|
@@ -267,18 +276,18 @@ class TaskRunner(
|
|
|
}
|
|
|
if (switchAppear != true) {
|
|
|
Log.e(
|
|
|
- TAG,
|
|
|
+ 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(
|
|
|
@@ -296,7 +305,7 @@ class TaskRunner(
|
|
|
), 1.minutes
|
|
|
).let { it == RcsConfigureState.READY }
|
|
|
}
|
|
|
- Log.i(TAG, "waitForRcsState: $resetSuccess")
|
|
|
+ Log.i(tag, "waitForRcsState: $resetSuccess")
|
|
|
appStateRepository.resetRequestedNum()
|
|
|
if (resetSuccess) {
|
|
|
delay(3000)
|
|
|
@@ -331,7 +340,7 @@ class TaskRunner(
|
|
|
}
|
|
|
if (switchAppear != true) {
|
|
|
Log.e(
|
|
|
- TAG,
|
|
|
+ tag,
|
|
|
"RCS not entered default on state, retrying..."
|
|
|
)
|
|
|
continue
|
|
|
@@ -339,7 +348,7 @@ class TaskRunner(
|
|
|
}
|
|
|
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(
|
|
|
@@ -357,7 +366,7 @@ class TaskRunner(
|
|
|
), 1.minutes
|
|
|
).let { it == RcsConfigureState.READY }
|
|
|
}
|
|
|
- Log.i(TAG, "waitForRcsState: $resetSuccess")
|
|
|
+ Log.i(tag, "waitForRcsState: $resetSuccess")
|
|
|
appStateRepository.resetRequestedNum()
|
|
|
if (resetSuccess) {
|
|
|
delay(3000)
|
|
|
@@ -441,6 +450,7 @@ class TaskRunner(
|
|
|
requestSuccess = true
|
|
|
break
|
|
|
} else {
|
|
|
+ appStateRepository.updateRuntimeFlags(requestNumberState = RequestNumberState.BACKUP)
|
|
|
backupRepository.backup(
|
|
|
spoofedSimInfo = spoofedSimInfo.value,
|
|
|
type = "auto",
|
|
|
@@ -478,7 +488,7 @@ class TaskRunner(
|
|
|
}
|
|
|
}
|
|
|
var rcsNumber = response.body<RcsNumberResponse>()
|
|
|
- Log.i(TAG, "requestNumber response: $rcsNumber")
|
|
|
+ Log.i(tag, "requestNumber response: $rcsNumber")
|
|
|
|
|
|
appStateRepository.updateRuntimeFlags(requestNumberState = RequestNumberState.OTP_1)
|
|
|
|
|
|
@@ -501,7 +511,7 @@ class TaskRunner(
|
|
|
shellRun(CMD_MESSAGING_APP)
|
|
|
|
|
|
if (rcsNumber.expiryTime.isBefore(LocalDateTime.now())) {
|
|
|
- Log.e(TAG, "RCS number expired, retrying...")
|
|
|
+ Log.e(tag, "RCS number expired, retrying...")
|
|
|
continue
|
|
|
}
|
|
|
var sendOtpTimeout = ChronoUnit.SECONDS.between(
|
|
|
@@ -509,7 +519,7 @@ class TaskRunner(
|
|
|
rcsNumber.expiryTime
|
|
|
).seconds
|
|
|
if (sendOtpTimeout < 60.seconds) {
|
|
|
- Log.e(TAG, "OTP timeout too short, retrying...")
|
|
|
+ Log.e(tag, "OTP timeout too short, retrying...")
|
|
|
continue
|
|
|
}
|
|
|
if (sendOtpTimeout > 2.minutes) {
|
|
|
@@ -524,10 +534,10 @@ class TaskRunner(
|
|
|
needRest = true
|
|
|
}
|
|
|
if (RcsConfigureState.REPLAY_REQUEST == googleMessageStateRepository.rcsConfigureState.value) {
|
|
|
- Log.e(TAG, "REPLAY_REQUEST detected, may reset after 3 retry ($retry)")
|
|
|
+ Log.e(tag, "REPLAY_REQUEST detected, may reset after 3 retry ($retry)")
|
|
|
retry++
|
|
|
}
|
|
|
- Log.e(TAG, "RCS not entered waiting for OTP state, retrying...")
|
|
|
+ Log.e(tag, "RCS not entered waiting for OTP state, retrying...")
|
|
|
continue
|
|
|
}
|
|
|
|
|
|
@@ -542,12 +552,12 @@ class TaskRunner(
|
|
|
)
|
|
|
)
|
|
|
} catch (e: Exception) {
|
|
|
- Log.e(TAG, "Send OtpState Error: ${e.message}", e)
|
|
|
+ Log.e(tag, "Send OtpState Error: ${e.message}", e)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (rcsNumber.expiryTime.isBefore(LocalDateTime.now())) {
|
|
|
- Log.e(TAG, "RCS number expired, retrying...")
|
|
|
+ Log.e(tag, "RCS number expired, retrying...")
|
|
|
continue
|
|
|
}
|
|
|
|
|
|
@@ -558,19 +568,19 @@ class TaskRunner(
|
|
|
rcsNumber =
|
|
|
ktorClient(appPreferences.value.server).get(RcsNumberApi.Id(id = rcsNumber.id))
|
|
|
.body<RcsNumberResponse>()
|
|
|
- Log.i(TAG, "wait for otp response: $rcsNumber")
|
|
|
+ Log.i(tag, "wait for otp response: $rcsNumber")
|
|
|
if (rcsNumber.status == RcsNumberResponse.STATUS_SUCCESS || rcsNumber.status == RcsNumberResponse.STATUS_EXPIRED) {
|
|
|
break
|
|
|
}
|
|
|
} catch (exception: Exception) {
|
|
|
- Log.e(TAG, "wait for otp Error: ${exception.stackTrace}")
|
|
|
+ Log.e(tag, "wait for otp Error: ${exception.stackTrace}")
|
|
|
}
|
|
|
delay(2.seconds)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (rcsNumber.status != RcsNumberResponse.STATUS_SUCCESS) {
|
|
|
- Log.e(TAG, "OTP not received, retrying...")
|
|
|
+ Log.e(tag, "OTP not received, retrying...")
|
|
|
continue
|
|
|
}
|
|
|
|
|
|
@@ -581,7 +591,7 @@ class TaskRunner(
|
|
|
appStateRepository.updateRuntimeFlags(requestNumberState = RequestNumberState.CONFIG)
|
|
|
|
|
|
val otp = match.groupValues[1]
|
|
|
- Log.i(TAG, "OTP: $otp")
|
|
|
+ Log.i(tag, "OTP: $otp")
|
|
|
val sender = "3538"
|
|
|
val msg = "Your Messenger verification code is G-$otp"
|
|
|
|
|
|
@@ -608,14 +618,14 @@ class TaskRunner(
|
|
|
}
|
|
|
|
|
|
else -> {
|
|
|
- Log.e(TAG, "verifyOtp fail, retrying...")
|
|
|
+ Log.e(tag, "verifyOtp fail, retrying...")
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
false
|
|
|
}
|
|
|
if (!configured) {
|
|
|
- Log.e(TAG, "RCS not configured, retrying...")
|
|
|
+ Log.e(tag, "RCS not configured, retrying...")
|
|
|
continue
|
|
|
} else {
|
|
|
launch {
|
|
|
@@ -630,7 +640,7 @@ class TaskRunner(
|
|
|
)
|
|
|
} catch (e: Exception) {
|
|
|
Log.e(
|
|
|
- TAG,
|
|
|
+ tag,
|
|
|
"Send ConfiguredState Error: ${e.message}",
|
|
|
e
|
|
|
)
|
|
|
@@ -641,7 +651,7 @@ class TaskRunner(
|
|
|
}
|
|
|
}
|
|
|
} catch (e: Exception) {
|
|
|
- Log.e(TAG, "requestNumberError: ${e.message}", e)
|
|
|
+ Log.e(tag, "requestNumberError: ${e.message}", e)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -653,12 +663,12 @@ class TaskRunner(
|
|
|
)
|
|
|
appStateRepository.resetSuccessNum()
|
|
|
appStateRepository.resetExecutedNum()
|
|
|
- Log.i(TAG, "requestNumber success")
|
|
|
+ Log.i(tag, "requestNumber success")
|
|
|
delay(5000)
|
|
|
shellRun(PACKAGE_MESSAGING.kill(), "sleep 1", CMD_MESSAGING_APP)
|
|
|
delay(2000)
|
|
|
} else {
|
|
|
- Log.e(TAG, "requestNumber failed")
|
|
|
+ Log.e(tag, "requestNumber failed")
|
|
|
appStateRepository.updateSend(false)
|
|
|
}
|
|
|
appStateRepository.updateRuntimeFlags(
|
|
|
@@ -670,7 +680,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,
|
|
|
@@ -679,11 +689,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}")
|
|
|
}
|
|
|
@@ -706,19 +716,19 @@ class TaskRunner(
|
|
|
)
|
|
|
)
|
|
|
.body<SysConfigResponse>()
|
|
|
- Log.i(TAG, "sysConfig response: $config")
|
|
|
+ Log.i(tag, "sysConfig response: $config")
|
|
|
checkRcsAvailabilityNumbers.addAll(
|
|
|
config.value.split(",").map { it.trim() })
|
|
|
} catch (exception: Exception) {
|
|
|
Log.e(
|
|
|
- TAG,
|
|
|
+ tag,
|
|
|
"sysConfig Error: ${exception.message}",
|
|
|
exception
|
|
|
)
|
|
|
}
|
|
|
|
|
|
if (checkRcsAvailabilityNumbers.isEmpty()) {
|
|
|
- Log.e(TAG, "checkRcsAvailabilityNumbers is empty")
|
|
|
+ Log.e(tag, "checkRcsAvailabilityNumbers is empty")
|
|
|
return@checkAvailability true
|
|
|
}
|
|
|
|
|
|
@@ -732,7 +742,7 @@ class TaskRunner(
|
|
|
return@withTimeoutOrNull true
|
|
|
} else {
|
|
|
Log.i(
|
|
|
- TAG,
|
|
|
+ tag,
|
|
|
"checkRcsAvailability: RCS not detected"
|
|
|
)
|
|
|
}
|
|
|
@@ -740,7 +750,7 @@ class TaskRunner(
|
|
|
}
|
|
|
}
|
|
|
if (s == true) {
|
|
|
- Log.i(TAG, "checkRcsAvailability: $it success")
|
|
|
+ Log.i(tag, "checkRcsAvailability: $it success")
|
|
|
delay(1000)
|
|
|
return@checkAvailability true
|
|
|
}
|
|
|
@@ -782,7 +792,7 @@ 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()
|
|
|
@@ -801,7 +811,7 @@ class TaskRunner(
|
|
|
val (out, err) = shellRun(*installApkAction.data.script.split("\n").toTypedArray())
|
|
|
onSuccess(out, err)
|
|
|
} catch (e: Exception) {
|
|
|
- Log.e("Modifier", "Failed to install apk", e)
|
|
|
+ Log.e("Modifier", "Failed to run script", e)
|
|
|
onError(e)
|
|
|
}
|
|
|
}
|