|
|
@@ -13,7 +13,6 @@ import com.example.modifier.constants.CMD_MESSAGING_APP
|
|
|
import com.example.modifier.constants.CMD_RCS_SETTINGS_ACTIVITY
|
|
|
import com.example.modifier.constants.PACKAGE_GMS
|
|
|
import com.example.modifier.constants.PACKAGE_MESSAGING
|
|
|
-import com.example.modifier.data.AppPreferences
|
|
|
import com.example.modifier.data.AppState
|
|
|
import com.example.modifier.enums.RcsConfigureState
|
|
|
import com.example.modifier.enums.RcsConnectionStatus
|
|
|
@@ -34,11 +33,11 @@ import com.example.modifier.model.TaskAction
|
|
|
import com.example.modifier.model.TaskConfig
|
|
|
import com.example.modifier.model.TaskExecutionResult
|
|
|
import com.example.modifier.model.UpdateDeviceAction
|
|
|
-import com.example.modifier.repo.AppPreferencesRepository
|
|
|
-import com.example.modifier.repo.AppStateRepository
|
|
|
+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.SpoofedSimInfoRepository
|
|
|
+import com.example.modifier.repo.SpoofedSimInfoRepo
|
|
|
import com.example.modifier.utils.changeClashProfile
|
|
|
import com.example.modifier.utils.clearConv
|
|
|
import com.example.modifier.utils.genICCID
|
|
|
@@ -86,9 +85,9 @@ class TaskRunner(
|
|
|
private val context: Context,
|
|
|
private val screenInspector: ScreenInspector,
|
|
|
private val screenController: ScreenController,
|
|
|
- private val appStateRepository: AppStateRepository,
|
|
|
- private val appPreferencesRepository: AppPreferencesRepository,
|
|
|
- private val spoofedSimInfoRepository: SpoofedSimInfoRepository,
|
|
|
+ private val appStateRepo: AppStateRepo,
|
|
|
+ private val appPrefsRepo: AppPrefsRepo,
|
|
|
+ private val spoofedSimInfoRepo: SpoofedSimInfoRepo,
|
|
|
private val googleMessageStateRepository: GoogleMessageStateRepository,
|
|
|
private val backupRepository: BackupRepository
|
|
|
) {
|
|
|
@@ -96,17 +95,6 @@ class TaskRunner(
|
|
|
private var lastSend = 0L
|
|
|
private var currentTaskId = 0
|
|
|
private var requestMode = 1
|
|
|
- private lateinit var appState: StateFlow<AppState>
|
|
|
- private lateinit var appPreferences: StateFlow<AppPreferences>
|
|
|
- private lateinit var spoofedSimInfo: StateFlow<SpoofedSimInfo>
|
|
|
-
|
|
|
- init {
|
|
|
- CoroutineScope(Dispatchers.IO).launch {
|
|
|
- appState = appStateRepository.stateFlow()
|
|
|
- appPreferences = appPreferencesRepository.stateFlow()
|
|
|
- spoofedSimInfo = spoofedSimInfoRepository.stateFlow()
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
suspend fun send(
|
|
|
to: String,
|
|
|
@@ -162,10 +150,10 @@ class TaskRunner(
|
|
|
} else {
|
|
|
Log.i(tag, "RCS not detected")
|
|
|
}
|
|
|
- appStateRepository.incrementExecutedNum(success)
|
|
|
+ appStateRepo.incrementExecutedNum(success)
|
|
|
Log.i(
|
|
|
tag,
|
|
|
- "executedNum: ${appState.value.executedNum}, successNum: ${appState.value.successNum}"
|
|
|
+ "executedNum: ${appStateRepo.appState.value.executedNum}, successNum: ${appStateRepo.appState.value.successNum}"
|
|
|
)
|
|
|
delay(1000)
|
|
|
return success
|
|
|
@@ -180,7 +168,7 @@ class TaskRunner(
|
|
|
onSuccess: (TaskExecutionResult) -> Unit,
|
|
|
onError: (Exception) -> Unit
|
|
|
) {
|
|
|
- if (appState.value.busy) {
|
|
|
+ if (appStateRepo.appState.value.busy) {
|
|
|
onError(Exception("device busy"))
|
|
|
return
|
|
|
}
|
|
|
@@ -190,18 +178,18 @@ class TaskRunner(
|
|
|
currentTaskId = taskAction.data.taskId
|
|
|
requestMode = if (taskAction.data.config.useBackup) 2 else 1
|
|
|
|
|
|
- if (taskAction.data.config.checkConnection && appState.value.executedNum == 0) {
|
|
|
- appStateRepository.updateRuntimeFlags(checkingConnection = true)
|
|
|
+ if (taskAction.data.config.checkConnection && appStateRepo.appState.value.executedNum == 0) {
|
|
|
+ appStateRepo.updateRuntimeFlags(checkingConnection = true)
|
|
|
if (!checkRcsA10y()) {
|
|
|
onError(Exception("RCS not available"))
|
|
|
requestNumber()
|
|
|
- appStateRepository.updateRuntimeFlags(checkingConnection = false)
|
|
|
+ appStateRepo.updateRuntimeFlags(checkingConnection = false)
|
|
|
return
|
|
|
}
|
|
|
- appStateRepository.updateRuntimeFlags(checkingConnection = false)
|
|
|
+ appStateRepo.updateRuntimeFlags(checkingConnection = false)
|
|
|
}
|
|
|
|
|
|
- appStateRepository.updateRuntimeFlags(running = true, checkingConnection = false)
|
|
|
+ appStateRepo.updateRuntimeFlags(running = true, checkingConnection = false)
|
|
|
val success = ArrayList<Int>()
|
|
|
val fail = ArrayList<Int>()
|
|
|
for (i in 0 until taskAction.data.tasks.size) {
|
|
|
@@ -224,31 +212,31 @@ class TaskRunner(
|
|
|
}
|
|
|
shellRun(CMD_BACK)
|
|
|
onSuccess(TaskExecutionResult(success, fail))
|
|
|
- if (taskConfig.requestNumberInterval in 1..appState.value.successNum) {
|
|
|
+ if (taskConfig.requestNumberInterval in 1..appStateRepo.appState.value.successNum) {
|
|
|
delay(3000)
|
|
|
requestNumber()
|
|
|
- } else if (taskConfig.cleanCount in 1..appState.value.executedNum && !appPreferences.value.preventClean) {
|
|
|
+ } else if (taskConfig.cleanCount in 1..appStateRepo.appState.value.executedNum && !appPrefsRepo.appPrefs.value.preventClean) {
|
|
|
delay(3000)
|
|
|
clearConv();
|
|
|
shellRun(CMD_MESSAGING_APP)
|
|
|
delay(3000)
|
|
|
- appStateRepository.resetExecutedNum()
|
|
|
+ appStateRepo.resetExecutedNum()
|
|
|
} else {
|
|
|
delay(2000)
|
|
|
}
|
|
|
- appStateRepository.updateRuntimeFlags(running = false)
|
|
|
+ appStateRepo.updateRuntimeFlags(running = false)
|
|
|
if (taskAction.data.config.checkConnection && success.isEmpty()) {
|
|
|
- appStateRepository.updateRuntimeFlags(checkingConnection = true)
|
|
|
+ appStateRepo.updateRuntimeFlags(checkingConnection = true)
|
|
|
if (!checkRcsA10y()) {
|
|
|
onError(Exception("RCS not available"))
|
|
|
requestNumber()
|
|
|
}
|
|
|
- appStateRepository.updateRuntimeFlags(checkingConnection = false)
|
|
|
+ appStateRepo.updateRuntimeFlags(checkingConnection = false)
|
|
|
}
|
|
|
} catch (e: Exception) {
|
|
|
Log.e(tag, "runTaskError: ${e.message}", e)
|
|
|
onError(e)
|
|
|
- appStateRepository.updateRuntimeFlags(running = false)
|
|
|
+ appStateRepo.updateRuntimeFlags(running = false)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -257,9 +245,9 @@ class TaskRunner(
|
|
|
withTimeout(1.hours) {
|
|
|
while (true) {
|
|
|
delay(100)
|
|
|
- appStateRepository.updateRuntimeFlags(requestNumberState = RequestNumberState.RESET)
|
|
|
+ appStateRepo.updateRuntimeFlags(requestNumberState = RequestNumberState.RESET)
|
|
|
googleMessageStateRepository.updateRcsState(RcsConfigureState.NOT_CONFIGURED)
|
|
|
- spoofedSimInfoRepository.mock()
|
|
|
+ spoofedSimInfoRepo.mock()
|
|
|
resetAll()
|
|
|
var switchAppear = googleMessageStateRepository.waitForRcsState(
|
|
|
arrayOf(RcsConfigureState.WAITING_FOR_TOS),
|
|
|
@@ -307,7 +295,7 @@ class TaskRunner(
|
|
|
).let { it == RcsConfigureState.READY }
|
|
|
}
|
|
|
Log.i(tag, "waitForRcsState: $resetSuccess")
|
|
|
- appStateRepository.resetRequestedNum()
|
|
|
+ appStateRepo.resetRequestedNum()
|
|
|
if (resetSuccess) {
|
|
|
delay(3000)
|
|
|
break
|
|
|
@@ -318,9 +306,9 @@ class TaskRunner(
|
|
|
withTimeout(1.hours) {
|
|
|
while (true) {
|
|
|
delay(100)
|
|
|
- appStateRepository.updateRuntimeFlags(requestNumberState = RequestNumberState.RESET)
|
|
|
+ appStateRepo.updateRuntimeFlags(requestNumberState = RequestNumberState.RESET)
|
|
|
googleMessageStateRepository.updateRcsState(RcsConfigureState.NOT_CONFIGURED)
|
|
|
- spoofedSimInfoRepository.mock()
|
|
|
+ spoofedSimInfoRepo.mock()
|
|
|
resetAll()
|
|
|
var switchAppear = googleMessageStateRepository.waitForRcsState(
|
|
|
arrayOf(RcsConfigureState.WAITING_FOR_DEFAULT_ON),
|
|
|
@@ -365,7 +353,7 @@ class TaskRunner(
|
|
|
).let { it == RcsConfigureState.READY }
|
|
|
}
|
|
|
Log.i(tag, "waitForRcsState: $resetSuccess")
|
|
|
- appStateRepository.resetRequestedNum()
|
|
|
+ appStateRepo.resetRequestedNum()
|
|
|
if (resetSuccess) {
|
|
|
delay(3000)
|
|
|
break
|
|
|
@@ -380,37 +368,37 @@ class TaskRunner(
|
|
|
noBackup: Boolean = false,
|
|
|
fresh: Boolean = false
|
|
|
) {
|
|
|
- appStateRepository.updateRuntimeFlags(suspended = false)
|
|
|
- if (appPreferences.value.preventRequest) {
|
|
|
+ appStateRepo.updateRuntimeFlags(suspended = false)
|
|
|
+ if (appPrefsRepo.appPrefs.value.preventRequest) {
|
|
|
return
|
|
|
}
|
|
|
- if (appState.value.requesting) {
|
|
|
+ if (appStateRepo.appState.value.requesting) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- appStateRepository.updateRuntimeFlags(requesting = true)
|
|
|
+ appStateRepo.updateRuntimeFlags(requesting = true)
|
|
|
clearConv()
|
|
|
- if (spoofedSimInfo.value.available) {
|
|
|
- appStateRepository.updateRuntimeFlags(requestNumberState = RequestNumberState.BACKUP)
|
|
|
+ if (spoofedSimInfoRepo.spoofedSimInfo.value.available) {
|
|
|
+ appStateRepo.updateRuntimeFlags(requestNumberState = RequestNumberState.BACKUP)
|
|
|
backupRepository.backup(
|
|
|
- spoofedSimInfo = spoofedSimInfo.value,
|
|
|
+ spoofedSimInfo = spoofedSimInfoRepo.spoofedSimInfo.value,
|
|
|
type = "auto",
|
|
|
- sendCount = appState.value.executedNum,
|
|
|
- fresh = fresh
|
|
|
+ sendCount = appStateRepo.appState.value.successNum,
|
|
|
+ stock = fresh
|
|
|
)
|
|
|
}
|
|
|
|
|
|
- appStateRepository.incrementRequestedNum()
|
|
|
+ appStateRepo.incrementRequestedNum()
|
|
|
var requestSuccess = false
|
|
|
var retry = 0
|
|
|
var needRest = reset
|
|
|
withTimeoutOrNull(2.hours) {
|
|
|
while (true) {
|
|
|
delay(200)
|
|
|
- needRest = needRest || retry > 2 || appState.value.requestedNum > 5
|
|
|
+ needRest = needRest || retry > 2 || appStateRepo.appState.value.requestedNum > 5
|
|
|
try {
|
|
|
val device =
|
|
|
- ktorClient(appPreferences.value.server).get(DeviceApi.Id(id = appPreferences.value.id))
|
|
|
+ ktorClient.get(DeviceApi.Id(id = appPrefsRepo.appPrefs.value.id))
|
|
|
.body<DeviceResponse>()
|
|
|
if (isClashInstalled(context)) {
|
|
|
|
|
|
@@ -439,7 +427,7 @@ class TaskRunner(
|
|
|
|
|
|
if (requestMode == 2 && !noBackup) {
|
|
|
val backup = backupRepository.findBackupForRestore(
|
|
|
- spoofedSimInfo.value.number,
|
|
|
+ spoofedSimInfoRepo.spoofedSimInfo.value.number,
|
|
|
System.currentTimeMillis() - 2.days.inWholeMilliseconds
|
|
|
)
|
|
|
if (backup != null) {
|
|
|
@@ -447,9 +435,9 @@ class TaskRunner(
|
|
|
requestSuccess = true
|
|
|
break
|
|
|
} else {
|
|
|
- appStateRepository.updateRuntimeFlags(requestNumberState = RequestNumberState.BACKUP)
|
|
|
+ appStateRepo.updateRuntimeFlags(requestNumberState = RequestNumberState.BACKUP)
|
|
|
backupRepository.backup(
|
|
|
- spoofedSimInfo = spoofedSimInfo.value,
|
|
|
+ spoofedSimInfo = spoofedSimInfoRepo.spoofedSimInfo.value,
|
|
|
type = "auto",
|
|
|
sendCount = 0
|
|
|
)
|
|
|
@@ -458,23 +446,23 @@ class TaskRunner(
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if (needRest && !appPreferences.value.preventReset) {
|
|
|
+ if (needRest && !appPrefsRepo.appPrefs.value.preventReset) {
|
|
|
reset()
|
|
|
retry = 0
|
|
|
needRest = false
|
|
|
}
|
|
|
|
|
|
googleMessageStateRepository.updateRcsState(RcsConfigureState.NOT_CONFIGURED)
|
|
|
- appStateRepository.updateRuntimeFlags(requestNumberState = RequestNumberState.REQUEST)
|
|
|
+ appStateRepo.updateRuntimeFlags(requestNumberState = RequestNumberState.REQUEST)
|
|
|
|
|
|
val req = RcsNumberRequest(
|
|
|
- deviceId = appPreferences.value.id,
|
|
|
+ deviceId = appPrefsRepo.appPrefs.value.id,
|
|
|
taskId = currentTaskId
|
|
|
)
|
|
|
if (!TextUtils.isEmpty(device.pinCountry)) {
|
|
|
req.country = device.pinCountry
|
|
|
}
|
|
|
- val response = ktorClient(appPreferences.value.server).put(
|
|
|
+ val response = ktorClient.put(
|
|
|
RcsNumberApi()
|
|
|
) {
|
|
|
contentType(ContentType.Application.Json)
|
|
|
@@ -487,10 +475,11 @@ class TaskRunner(
|
|
|
var rcsNumber = response.body<RcsNumberResponse>()
|
|
|
Log.i(tag, "requestNumber response: $rcsNumber")
|
|
|
|
|
|
- appStateRepository.updateRuntimeFlags(requestNumberState = RequestNumberState.OTP_1)
|
|
|
+ appStateRepo.updateRuntimeFlags(requestNumberState = RequestNumberState.OTP_1)
|
|
|
|
|
|
- spoofedSimInfoRepository.updateSpoofedSimInfo(
|
|
|
+ spoofedSimInfoRepo.updateSpoofedSimInfo(
|
|
|
SpoofedSimInfo(
|
|
|
+ numberId = rcsNumber.id,
|
|
|
number = rcsNumber.number,
|
|
|
mcc = rcsNumber.mcc,
|
|
|
mnc = rcsNumber.mnc,
|
|
|
@@ -540,7 +529,7 @@ class TaskRunner(
|
|
|
|
|
|
launch {
|
|
|
try {
|
|
|
- ktorClient(appPreferences.value.server).post(
|
|
|
+ ktorClient.post(
|
|
|
RcsNumberApi.Id.OtpState(
|
|
|
RcsNumberApi.Id(
|
|
|
RcsNumberApi(),
|
|
|
@@ -558,12 +547,12 @@ class TaskRunner(
|
|
|
continue
|
|
|
}
|
|
|
|
|
|
- appStateRepository.updateRuntimeFlags(requestNumberState = RequestNumberState.OTP_2)
|
|
|
+ appStateRepo.updateRuntimeFlags(requestNumberState = RequestNumberState.OTP_2)
|
|
|
withTimeoutOrNull(60.seconds) {
|
|
|
while (true) {
|
|
|
try {
|
|
|
rcsNumber =
|
|
|
- ktorClient(appPreferences.value.server).get(RcsNumberApi.Id(id = rcsNumber.id))
|
|
|
+ ktorClient.get(RcsNumberApi.Id(id = rcsNumber.id))
|
|
|
.body<RcsNumberResponse>()
|
|
|
Log.i(tag, "wait for otp response: $rcsNumber")
|
|
|
if (rcsNumber.status == RcsNumberResponse.STATUS_SUCCESS || rcsNumber.status == RcsNumberResponse.STATUS_EXPIRED) {
|
|
|
@@ -585,7 +574,7 @@ class TaskRunner(
|
|
|
Regex("Your Messenger verification code is G-(\\d{6})")
|
|
|
.find(rcsNumber.message!!)
|
|
|
if (match != null) {
|
|
|
- appStateRepository.updateRuntimeFlags(requestNumberState = RequestNumberState.CONFIG)
|
|
|
+ appStateRepo.updateRuntimeFlags(requestNumberState = RequestNumberState.CONFIG)
|
|
|
|
|
|
val otp = match.groupValues[1]
|
|
|
Log.i(tag, "OTP: $otp")
|
|
|
@@ -627,7 +616,7 @@ class TaskRunner(
|
|
|
} else {
|
|
|
launch {
|
|
|
try {
|
|
|
- ktorClient(appPreferences.value.server).post(
|
|
|
+ ktorClient.post(
|
|
|
RcsNumberApi.Id.Configured(
|
|
|
RcsNumberApi.Id(
|
|
|
RcsNumberApi(),
|
|
|
@@ -653,23 +642,23 @@ class TaskRunner(
|
|
|
}
|
|
|
}
|
|
|
if (requestSuccess) {
|
|
|
- spoofedSimInfoRepository.updateSpoofedSimInfo(
|
|
|
- spoofedSimInfo = spoofedSimInfo.value.copy(
|
|
|
+ spoofedSimInfoRepo.updateSpoofedSimInfo(
|
|
|
+ spoofedSimInfo = spoofedSimInfoRepo.spoofedSimInfo.value.copy(
|
|
|
available = true
|
|
|
),
|
|
|
suspend = false
|
|
|
)
|
|
|
- appStateRepository.resetSuccessNum()
|
|
|
- appStateRepository.resetExecutedNum()
|
|
|
+ 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")
|
|
|
- appStateRepository.updateSend(false)
|
|
|
+ appStateRepo.updateSend(false)
|
|
|
}
|
|
|
- appStateRepository.updateRuntimeFlags(
|
|
|
+ appStateRepo.updateRuntimeFlags(
|
|
|
requesting = false,
|
|
|
requestNumberState = RequestNumberState.IDLE,
|
|
|
suspended = !requestSuccess
|
|
|
@@ -705,7 +694,7 @@ class TaskRunner(
|
|
|
if (rcsConnected) {
|
|
|
val checkRcsA10yNumbers = mutableListOf<String>()
|
|
|
try {
|
|
|
- val config = ktorClient(appPreferences.value.server)
|
|
|
+ val config = ktorClient
|
|
|
.get(SysConfigApi.Id(SysConfigApi(), "check_availability_numbers"))
|
|
|
.body<SysConfigResponse>()
|
|
|
Log.i(tag, "sysConfig response: $config")
|
|
|
@@ -803,10 +792,10 @@ class TaskRunner(
|
|
|
) {
|
|
|
try {
|
|
|
if (updateDeviceAction.data.id != null) {
|
|
|
- appPreferencesRepository.updateId(updateDeviceAction.data.id)
|
|
|
+ appPrefsRepo.updateId(updateDeviceAction.data.id)
|
|
|
}
|
|
|
if (updateDeviceAction.data.name != null) {
|
|
|
- appPreferencesRepository.updateName(updateDeviceAction.data.name)
|
|
|
+ appPrefsRepo.updateName(updateDeviceAction.data.name)
|
|
|
}
|
|
|
onSuccess()
|
|
|
} catch (e: Exception) {
|