|
|
@@ -24,10 +24,17 @@ import com.example.modifier.service.ModifierService
|
|
|
import com.example.modifier.utils.clearConv
|
|
|
import com.example.modifier.utils.getContext
|
|
|
import com.example.modifier.utils.shellRun
|
|
|
+import kotlinx.coroutines.CoroutineScope
|
|
|
+import kotlinx.coroutines.Dispatchers
|
|
|
+import kotlinx.coroutines.coroutineScope
|
|
|
import kotlinx.coroutines.delay
|
|
|
+import kotlinx.coroutines.launch
|
|
|
+import kotlinx.coroutines.withContext
|
|
|
import java.io.File
|
|
|
import java.util.Date
|
|
|
import java.util.Optional
|
|
|
+import kotlin.coroutines.coroutineContext
|
|
|
+import kotlin.time.Duration.Companion.minutes
|
|
|
import kotlin.time.Duration.Companion.seconds
|
|
|
|
|
|
class BackupRepository(
|
|
|
@@ -100,7 +107,8 @@ class BackupRepository(
|
|
|
type = type,
|
|
|
stock = stock,
|
|
|
carrierId = Optional.ofNullable(spoofedSimInfo.carrierId).orElse("1"),
|
|
|
- carrierName = Optional.ofNullable(spoofedSimInfo.carrierName).orElse("T-Mobile")
|
|
|
+ carrierName = Optional.ofNullable(spoofedSimInfo.carrierName).orElse("T-Mobile"),
|
|
|
+ retry = 0
|
|
|
)
|
|
|
|
|
|
dao.findBackupForNumber(spoofedSimInfo.country, spoofedSimInfo.number)?.let {
|
|
|
@@ -116,7 +124,6 @@ class BackupRepository(
|
|
|
|
|
|
@SuppressLint("SdCardPath")
|
|
|
suspend fun restore(backup: BackupItem): Boolean {
|
|
|
- AppStateRepo.instance.updateRuntimeFlags(reqState = ReqState.RESTORE)
|
|
|
val spoofedSimInfoRepo = SpoofedSimInfoRepo.instance
|
|
|
val simInfo = SpoofedSimInfo(
|
|
|
numberId = backup.numberId,
|
|
|
@@ -209,6 +216,7 @@ class BackupRepository(
|
|
|
if (backup.stock != 1) {
|
|
|
return@isSuccess true
|
|
|
}
|
|
|
+
|
|
|
if (taskRunner == null) return@isSuccess false
|
|
|
if (!taskRunner.screenController.toggleRcsSwitch(true)) {
|
|
|
shellRun(
|
|
|
@@ -222,11 +230,26 @@ class BackupRepository(
|
|
|
return@isSuccess false
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ val job = CoroutineScope(coroutineContext).launch {
|
|
|
+ taskRunner.gmsgStateRepository.rcsConfigureState.collect {
|
|
|
+ if (it == RcsConfigureState.RETRY) {
|
|
|
+ shellRun(
|
|
|
+ PACKAGE_GMS.kill(),
|
|
|
+ "sleep 5",
|
|
|
+ PACKAGE_MESSAGING.kill(),
|
|
|
+ CMD_MESSAGING_APP
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
val state = taskRunner.gmsgStateRepository.waitForRcsState(
|
|
|
- arrayOf(RcsConfigureState.CONFIGURED), 120.seconds
|
|
|
+ arrayOf(RcsConfigureState.CONFIGURED), 5.minutes
|
|
|
)
|
|
|
- if (state != RcsConfigureState.CONFIGURED) return@isSuccess false
|
|
|
- true
|
|
|
+ job.cancel()
|
|
|
+ if (state == RcsConfigureState.CONFIGURED) return@isSuccess true
|
|
|
+ false
|
|
|
}
|
|
|
|
|
|
if (success) {
|
|
|
@@ -236,17 +259,22 @@ class BackupRepository(
|
|
|
suspend = false
|
|
|
)
|
|
|
if (backup.stock == 1) {
|
|
|
-// backup.stock = 2
|
|
|
-// dao.update(backup)
|
|
|
+ backup.stock = 2
|
|
|
+ dao.update(backup)
|
|
|
RcsNumberApi.updateStockFlag(backup.numberId, 2)
|
|
|
}
|
|
|
return true
|
|
|
} else {
|
|
|
Log.i(TAG, "restore: failed")
|
|
|
if (backup.stock == 1) {
|
|
|
-// backup.stock = 3
|
|
|
-// dao.update(backup)
|
|
|
- RcsNumberApi.updateStockFlag(backup.numberId, 3)
|
|
|
+ backup.retry++
|
|
|
+ if (backup.retry >= 3) {
|
|
|
+ backup.stock = 3
|
|
|
+ dao.update(backup)
|
|
|
+ RcsNumberApi.updateStockFlag(backup.numberId, 3)
|
|
|
+ } else {
|
|
|
+ dao.update(backup)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
return false
|
|
|
@@ -260,7 +288,12 @@ class BackupRepository(
|
|
|
return dao.findBackupForRestore(number)
|
|
|
}
|
|
|
|
|
|
- suspend fun update(backupItem: BackupItem) {
|
|
|
- dao.update(backupItem)
|
|
|
+ suspend fun cleanBackup(start: Long, end: Long) {
|
|
|
+ dao.findBackupsBetween(start, end).forEach {
|
|
|
+ runCatching {
|
|
|
+ File(it.path).deleteRecursively()
|
|
|
+ }
|
|
|
+ dao.delete(it)
|
|
|
+ }
|
|
|
}
|
|
|
}
|