|
|
@@ -306,7 +306,7 @@ class ModifierService : AccessibilityService(), Emitter.Listener {
|
|
|
if (Global.hasRoot()) {
|
|
|
Global.setupSystem()
|
|
|
if (Build.MODEL.startsWith("SM-F707") || Build.MODEL.startsWith("SM-F711")) {
|
|
|
- Global.killPhoneProcess(force = true)
|
|
|
+ Global.killPhoneProcess(force = false)
|
|
|
}
|
|
|
}
|
|
|
preparing.postValue(false)
|
|
|
@@ -776,7 +776,7 @@ class ModifierService : AccessibilityService(), Emitter.Listener {
|
|
|
binding.btnClean.setOnClickListener {
|
|
|
binding.btnClean.isEnabled = false
|
|
|
CoroutineScope(Dispatchers.IO).launch {
|
|
|
- Global.clearConv1()
|
|
|
+ Global.clearConv()
|
|
|
withContext(Dispatchers.Main) {
|
|
|
binding.btnClean.isEnabled = true
|
|
|
}
|
|
|
@@ -1031,7 +1031,11 @@ class ModifierService : AccessibilityService(), Emitter.Listener {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private suspend fun requestNumber(reset: Boolean = false, noBackup: Boolean = false) {
|
|
|
+ private suspend fun requestNumber(
|
|
|
+ reset: Boolean = false,
|
|
|
+ noBackup: Boolean = false,
|
|
|
+ fresh: Boolean = false
|
|
|
+ ) {
|
|
|
val color = ContextCompat.getColorStateList(binding.root.context, R.color.btn_color)
|
|
|
binding.btnReq.backgroundTintList = color
|
|
|
if (getSharedPreferences("settings", Context.MODE_PRIVATE)
|
|
|
@@ -1046,182 +1050,192 @@ class ModifierService : AccessibilityService(), Emitter.Listener {
|
|
|
requesting.postValue(true)
|
|
|
|
|
|
if (Global.telephonyConfig.mock == false) {
|
|
|
- backup(backupItemDao, "auto", sendCount)
|
|
|
+ backup(
|
|
|
+ backupItemDao = backupItemDao,
|
|
|
+ type = "auto",
|
|
|
+ sendCount = sendCount,
|
|
|
+ fresh = fresh
|
|
|
+ )
|
|
|
}
|
|
|
|
|
|
var requestSuccess = false
|
|
|
- if (requestMode == 2 && !noBackup) {
|
|
|
- val backup = backupItemDao.findBackupForRestore(
|
|
|
- Global.telephonyConfig.number,
|
|
|
- System.currentTimeMillis() - 2 * 24 * 60 * 60 * 1000
|
|
|
- )
|
|
|
- if (backup != null) {
|
|
|
- Global.restore(backup)
|
|
|
- requestSuccess = true
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
- if (!requestSuccess) {
|
|
|
- withTimeoutOrNull(1.hours) {
|
|
|
- var needRest = reset
|
|
|
- while (true) {
|
|
|
- delay(200)
|
|
|
- try {
|
|
|
- if (needRest &&
|
|
|
- !getSharedPreferences("settings", Context.MODE_PRIVATE)
|
|
|
- .getBoolean("do_not_reset", false)
|
|
|
- ) {
|
|
|
- reset()
|
|
|
- needRest = false
|
|
|
+ withTimeoutOrNull(1.hours) {
|
|
|
+ var needRest = reset
|
|
|
+ while (true) {
|
|
|
+ delay(200)
|
|
|
+ try {
|
|
|
+ if (requestMode == 2 && !noBackup) {
|
|
|
+ val backup = backupItemDao.findBackupForRestore(
|
|
|
+ Global.telephonyConfig.number,
|
|
|
+ System.currentTimeMillis() - 2 * 24 * 60 * 60 * 1000
|
|
|
+ )
|
|
|
+ if (backup != null) {
|
|
|
+ if (Global.restore(backup)) {
|
|
|
+ requestSuccess = true
|
|
|
+ break
|
|
|
+ } else {
|
|
|
+ backup(backupItemDao, "auto", 0)
|
|
|
+ continue
|
|
|
+ }
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- rcsConfigureState.postValue(RcsConfigureState.NOT_CONFIGURED)
|
|
|
- withContext(Dispatchers.Main) {
|
|
|
- binding.tvLog.text = "Requesting number..."
|
|
|
- }
|
|
|
+ if (needRest &&
|
|
|
+ !getSharedPreferences("settings", Context.MODE_PRIVATE)
|
|
|
+ .getBoolean("do_not_reset", false)
|
|
|
+ ) {
|
|
|
+ reset()
|
|
|
+ needRest = false
|
|
|
+ }
|
|
|
|
|
|
- val response = KtorClient.put(
|
|
|
- RcsNumberApi()
|
|
|
- ) {
|
|
|
- contentType(ContentType.Application.Json)
|
|
|
- setBody(
|
|
|
- RcsNumberRequest(
|
|
|
- deviceId = Utils.getUniqueID(),
|
|
|
- taskId = currentTaskId
|
|
|
- )
|
|
|
+ rcsConfigureState.postValue(RcsConfigureState.NOT_CONFIGURED)
|
|
|
+ withContext(Dispatchers.Main) {
|
|
|
+ binding.tvLog.text = "Requesting number..."
|
|
|
+ }
|
|
|
+
|
|
|
+ val response = KtorClient.put(
|
|
|
+ RcsNumberApi()
|
|
|
+ ) {
|
|
|
+ contentType(ContentType.Application.Json)
|
|
|
+ setBody(
|
|
|
+ RcsNumberRequest(
|
|
|
+ deviceId = Utils.getUniqueID(),
|
|
|
+ taskId = currentTaskId
|
|
|
)
|
|
|
- }
|
|
|
- var rcsNumber = response.body<RcsNumberResponse>()
|
|
|
- Log.i(TAG, "requestNumber response: $rcsNumber")
|
|
|
+ )
|
|
|
+ }
|
|
|
+ var rcsNumber = response.body<RcsNumberResponse>()
|
|
|
+ Log.i(TAG, "requestNumber response: $rcsNumber")
|
|
|
|
|
|
- withContext(Dispatchers.Main) {
|
|
|
- binding.tvLog.text = "Requesting success, waiting for logs..."
|
|
|
- }
|
|
|
+ withContext(Dispatchers.Main) {
|
|
|
+ binding.tvLog.text = "Requesting success, waiting for logs..."
|
|
|
+ }
|
|
|
|
|
|
- Global.save(
|
|
|
- TelephonyConfig(
|
|
|
- rcsNumber.number,
|
|
|
- rcsNumber.mcc,
|
|
|
- rcsNumber.mnc,
|
|
|
- Global.genICCID(rcsNumber.mnc, rcsNumber.areaCode),
|
|
|
- rcsNumber.mcc + rcsNumber.mnc + RandomStringUtils.randomNumeric(
|
|
|
- 15 - rcsNumber.mcc.length - rcsNumber.mnc.length
|
|
|
- ),
|
|
|
- Utils.generateIMEI(),
|
|
|
- rcsNumber.country,
|
|
|
- rcsNumber.areaCode
|
|
|
- )
|
|
|
+ Global.save(
|
|
|
+ TelephonyConfig(
|
|
|
+ rcsNumber.number,
|
|
|
+ rcsNumber.mcc,
|
|
|
+ rcsNumber.mnc,
|
|
|
+ Global.genICCID(rcsNumber.mnc, rcsNumber.areaCode),
|
|
|
+ rcsNumber.mcc + rcsNumber.mnc + RandomStringUtils.randomNumeric(
|
|
|
+ 15 - rcsNumber.mcc.length - rcsNumber.mnc.length
|
|
|
+ ),
|
|
|
+ Utils.generateIMEI(),
|
|
|
+ rcsNumber.country,
|
|
|
+ rcsNumber.areaCode
|
|
|
)
|
|
|
+ )
|
|
|
|
|
|
- shellRun(CMD_MESSAGING_APP)
|
|
|
- withContext(Dispatchers.Main) {
|
|
|
- binding.tvLog.text = "Waiting for logs..."
|
|
|
- }
|
|
|
+ shellRun(CMD_MESSAGING_APP)
|
|
|
+ withContext(Dispatchers.Main) {
|
|
|
+ binding.tvLog.text = "Waiting for logs..."
|
|
|
+ }
|
|
|
|
|
|
- if (rcsNumber.expiryTime.isBefore(LocalDateTime.now())) {
|
|
|
- Log.e(TAG, "RCS number expired, retrying...")
|
|
|
- continue
|
|
|
- }
|
|
|
- var sendOtpTimeout = ChronoUnit.SECONDS.between(
|
|
|
- LocalDateTime.now(),
|
|
|
- rcsNumber.expiryTime
|
|
|
- ).seconds
|
|
|
- if (sendOtpTimeout < 60.seconds) {
|
|
|
- Log.e(TAG, "OTP timeout too short, retrying...")
|
|
|
- continue
|
|
|
- }
|
|
|
- if (sendOtpTimeout > 2.minutes) {
|
|
|
- sendOtpTimeout = 2.minutes
|
|
|
- }
|
|
|
- if (waitForRcsState(
|
|
|
- arrayOf(RcsConfigureState.WAITING_FOR_OTP),
|
|
|
- sendOtpTimeout
|
|
|
- ) != RcsConfigureState.WAITING_FOR_OTP
|
|
|
- ) {
|
|
|
- if (!toggleRcsSwitch(true)) {
|
|
|
- needRest = true
|
|
|
- }
|
|
|
- Log.e(TAG, "RCS not entered waiting for OTP state, retrying...")
|
|
|
- continue
|
|
|
- }
|
|
|
- if (rcsNumber.expiryTime.isBefore(LocalDateTime.now())) {
|
|
|
- Log.e(TAG, "RCS number expired, retrying...")
|
|
|
- continue
|
|
|
+ if (rcsNumber.expiryTime.isBefore(LocalDateTime.now())) {
|
|
|
+ Log.e(TAG, "RCS number expired, retrying...")
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ var sendOtpTimeout = ChronoUnit.SECONDS.between(
|
|
|
+ LocalDateTime.now(),
|
|
|
+ rcsNumber.expiryTime
|
|
|
+ ).seconds
|
|
|
+ if (sendOtpTimeout < 60.seconds) {
|
|
|
+ Log.e(TAG, "OTP timeout too short, retrying...")
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ if (sendOtpTimeout > 2.minutes) {
|
|
|
+ sendOtpTimeout = 2.minutes
|
|
|
+ }
|
|
|
+ if (waitForRcsState(
|
|
|
+ arrayOf(RcsConfigureState.WAITING_FOR_OTP),
|
|
|
+ sendOtpTimeout
|
|
|
+ ) != RcsConfigureState.WAITING_FOR_OTP
|
|
|
+ ) {
|
|
|
+ if (!toggleRcsSwitch(true)) {
|
|
|
+ needRest = true
|
|
|
}
|
|
|
+ Log.e(TAG, "RCS not entered waiting for OTP state, retrying...")
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ if (rcsNumber.expiryTime.isBefore(LocalDateTime.now())) {
|
|
|
+ Log.e(TAG, "RCS number expired, retrying...")
|
|
|
+ continue
|
|
|
+ }
|
|
|
|
|
|
- withTimeoutOrNull(60.seconds) {
|
|
|
- while (true) {
|
|
|
- try {
|
|
|
- rcsNumber = 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) {
|
|
|
- break
|
|
|
- }
|
|
|
- } catch (exception: Exception) {
|
|
|
- Log.e(TAG, "wait for otp Error: ${exception.stackTrace}")
|
|
|
+ withTimeoutOrNull(60.seconds) {
|
|
|
+ while (true) {
|
|
|
+ try {
|
|
|
+ rcsNumber = 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) {
|
|
|
+ break
|
|
|
}
|
|
|
- delay(2.seconds)
|
|
|
+ } catch (exception: Exception) {
|
|
|
+ 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...")
|
|
|
- continue
|
|
|
- }
|
|
|
+ if (rcsNumber.status != RcsNumberResponse.STATUS_SUCCESS) {
|
|
|
+ Log.e(TAG, "OTP not received, retrying...")
|
|
|
+ continue
|
|
|
+ }
|
|
|
+
|
|
|
+ val match =
|
|
|
+ Regex("Your Messenger verification code is G-(\\d{6})")
|
|
|
+ .matchEntire(rcsNumber.message!!)
|
|
|
+ if (match != null) {
|
|
|
+ val otp = match.groupValues[1]
|
|
|
+ Log.i(TAG, "OTP: $otp")
|
|
|
+ val sender = "3538"
|
|
|
+ val msg = "Your Messenger verification code is G-$otp"
|
|
|
+
|
|
|
+ val configured = run configuring@{
|
|
|
+ repeat(2) {
|
|
|
+ Global.sendSmsIntent(sender, msg)
|
|
|
+ val state =
|
|
|
+ waitForRcsState(
|
|
|
+ arrayOf(
|
|
|
+ RcsConfigureState.CONFIGURED,
|
|
|
+ RcsConfigureState.RETRY
|
|
|
+ ), 60.seconds
|
|
|
+ )
|
|
|
+ when (state) {
|
|
|
+ RcsConfigureState.CONFIGURED -> {
|
|
|
+ return@configuring true
|
|
|
+ }
|
|
|
|
|
|
- val match =
|
|
|
- Regex("Your Messenger verification code is G-(\\d{6})")
|
|
|
- .matchEntire(rcsNumber.message!!)
|
|
|
- if (match != null) {
|
|
|
- val otp = match.groupValues[1]
|
|
|
- Log.i(TAG, "OTP: $otp")
|
|
|
- val sender = "3538"
|
|
|
- val msg = "Your Messenger verification code is G-$otp"
|
|
|
-
|
|
|
- val configured = run configuring@{
|
|
|
- repeat(2) {
|
|
|
- Global.sendSmsIntent(sender, msg)
|
|
|
- val state =
|
|
|
+ RcsConfigureState.RETRY -> {
|
|
|
waitForRcsState(
|
|
|
- arrayOf(
|
|
|
- RcsConfigureState.CONFIGURED,
|
|
|
- RcsConfigureState.RETRY
|
|
|
- ), 60.seconds
|
|
|
+ arrayOf(RcsConfigureState.WAITING_FOR_OTP),
|
|
|
+ 60.seconds
|
|
|
)
|
|
|
- when (state) {
|
|
|
- RcsConfigureState.CONFIGURED -> {
|
|
|
- return@configuring true
|
|
|
- }
|
|
|
-
|
|
|
- RcsConfigureState.RETRY -> {
|
|
|
- waitForRcsState(
|
|
|
- arrayOf(RcsConfigureState.WAITING_FOR_OTP),
|
|
|
- 60.seconds
|
|
|
- )
|
|
|
- }
|
|
|
-
|
|
|
- else -> {
|
|
|
- Log.e(TAG, "verifyOtp fail, retrying...")
|
|
|
- }
|
|
|
+ }
|
|
|
+
|
|
|
+ else -> {
|
|
|
+ Log.e(TAG, "verifyOtp fail, retrying...")
|
|
|
}
|
|
|
}
|
|
|
- false
|
|
|
- }
|
|
|
- if (!configured) {
|
|
|
- Log.e(TAG, "RCS not configured, retrying...")
|
|
|
- continue
|
|
|
- } else {
|
|
|
- requestSuccess = true
|
|
|
- break
|
|
|
}
|
|
|
+ false
|
|
|
+ }
|
|
|
+ if (!configured) {
|
|
|
+ Log.e(TAG, "RCS not configured, retrying...")
|
|
|
+ continue
|
|
|
+ } else {
|
|
|
+ requestSuccess = true
|
|
|
+ break
|
|
|
}
|
|
|
- } catch (e: Exception) {
|
|
|
- Log.e(TAG, "requestNumberError: ${e.message}", e)
|
|
|
}
|
|
|
+ } catch (e: Exception) {
|
|
|
+ Log.e(TAG, "requestNumberError: ${e.message}", e)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
requesting.postValue(false)
|
|
|
|
|
|
if (requestSuccess) {
|
|
|
@@ -1299,7 +1313,7 @@ class ModifierService : AccessibilityService(), Emitter.Listener {
|
|
|
|
|
|
checkRcsAvailabilityNumbers.forEach {
|
|
|
startActivity(smsIntent(it, ""))
|
|
|
- val s = withTimeoutOrNull(3.seconds) {
|
|
|
+ val s = withTimeoutOrNull(5.seconds) {
|
|
|
while (true) {
|
|
|
val root = rootInActiveWindow
|
|
|
val traverseResult = TraverseResult()
|
|
|
@@ -1329,7 +1343,7 @@ class ModifierService : AccessibilityService(), Emitter.Listener {
|
|
|
binding.btnStoreNumbers.isEnabled = false
|
|
|
}
|
|
|
repeat(100) {
|
|
|
- requestNumber()
|
|
|
+ requestNumber(fresh = it > 0)
|
|
|
delay(5000)
|
|
|
}
|
|
|
withContext(Dispatchers.Main) {
|