xiongzhu hace 1 año
padre
commit
767d6bff40

+ 12 - 0
app/src/main/java/com/example/modifier/exception/RequestNumberException.kt

@@ -33,6 +33,18 @@ class RequestNumberException(code: Int) : Exception() {
                 message = "REPLAY_REQUEST or RETRY detected, may reset after 3 retry"
             }
 
+            ErrorCode.CODE_OTP_NOT_SENT -> {
+                message = "OTP not sent"
+            }
+
+            ErrorCode.CODE_OTP_NOT_RECEIVED -> {
+                message = "OTP not received"
+            }
+
+            ErrorCode.CODE_OTP_VERIFY_FAILED -> {
+                message = "OTP verify failed"
+            }
+
             else -> {
                 message = "Unknown error"
             }

+ 3 - 3
app/src/main/java/com/example/modifier/http/KtorClient.kt

@@ -24,7 +24,7 @@ import kotlinx.coroutines.CancellationException
 import kotlinx.serialization.ExperimentalSerializationApi
 import kotlinx.serialization.json.Json
 
-private fun Throwable.isTimeoutException(): Boolean {
+fun Throwable.isTimeoutException(): Boolean {
     val exception = unwrapCancellationException()
     return exception is HttpRequestTimeoutException ||
             exception is ConnectTimeoutException ||
@@ -40,10 +40,10 @@ var ktorClient = HttpClient(OkHttp) {
         })
     }
     install(HttpSend) {
-        maxSendCount = 200
+        maxSendCount = 3600
     }
     install(Logging) {
-        level = LogLevel.INFO
+        level = LogLevel.NONE
     }
     install(HttpRequestRetry) {
         maxRetries = 3

+ 23 - 3
app/src/main/java/com/example/modifier/http/api/RcsNumberApi.kt

@@ -2,6 +2,7 @@ package com.example.modifier.http.api
 
 import android.util.Log
 import com.example.modifier.baseTag
+import com.example.modifier.http.isTimeoutException
 import com.example.modifier.http.ktorClient
 import com.example.modifier.http.request.RcsNumberRequest
 import com.example.modifier.http.response.RcsNumberResponse
@@ -9,6 +10,7 @@ import io.ktor.client.call.body
 import io.ktor.client.plugins.resources.get
 import io.ktor.client.plugins.resources.post
 import io.ktor.client.plugins.resources.put
+import io.ktor.client.plugins.retry
 import io.ktor.client.plugins.timeout
 import io.ktor.client.request.setBody
 import io.ktor.http.ContentType
@@ -19,6 +21,7 @@ import kotlinx.coroutines.coroutineScope
 import kotlinx.coroutines.delay
 import kotlinx.coroutines.launch
 import kotlinx.coroutines.withTimeoutOrNull
+import kotlin.coroutines.cancellation.CancellationException
 import kotlin.coroutines.coroutineContext
 import kotlin.time.Duration.Companion.seconds
 
@@ -48,15 +51,32 @@ class RcsNumberApi() {
                 taskId = taskId,
                 country = pinCountry
             )
-            val response = ktorClient.put(
-                RcsNumberApi()
-            ) {
+            val response = ktorClient.put(RcsNumberApi()) {
                 contentType(ContentType.Application.Json)
                 setBody(req)
                 timeout {
                     requestTimeoutMillis = 60 * 1000
                     socketTimeoutMillis = 60 * 1000
                 }
+                retry {
+                    maxRetries = 3600
+                    retryOnExceptionIf { _, cause ->
+                        when {
+                            cause.isTimeoutException() -> true
+                            cause is CancellationException -> false
+                            else -> true
+                        }
+                    }
+                    retryIf { _, response ->
+                        response.status.value.let {
+                            when (it) {
+                                425, 429, 502, 503, 504 -> true
+                                else -> false
+                            }
+                        }
+                    }
+                    delayMillis { 1000 }
+                }
             }
             return response.body<RcsNumberResponse>()
         }

+ 2 - 8
app/src/main/java/com/example/modifier/repo/AppStateRepo.kt

@@ -8,6 +8,7 @@ import androidx.datastore.preferences.core.intPreferencesKey
 import androidx.datastore.preferences.preferencesDataStore
 import com.example.modifier.BuildConfig
 import com.example.modifier.Utils
+import com.example.modifier.baseTag
 import com.example.modifier.data.AppRuntimeFlags
 import com.example.modifier.data.AppState
 import com.example.modifier.enums.RequestNumberState
@@ -23,6 +24,7 @@ val Context.appStateDataStore by preferencesDataStore(name = "${BuildConfig.APPL
 class AppStateRepo private constructor(private val context: Context) {
 
     companion object {
+        private const val TAG = "${baseTag}/AppStateRepo"
         val instance by lazy { AppStateRepo(Utils.getContext()) }
     }
 
@@ -57,10 +59,6 @@ class AppStateRepo private constructor(private val context: Context) {
                 context.getSharedPreferences(BuildConfig.APPLICATION_ID, Context.MODE_PRIVATE)
             val busy =
                 runtimeFlags.running || runtimeFlags.requesting || runtimeFlags.preparing || runtimeFlags.checkingConnection
-            Log.i(
-                "AppStateRepository.appStateFlow",
-                "running: ${runtimeFlags.running}, \nrequesting: ${runtimeFlags.requesting}, \npreparing: ${runtimeFlags.preparing}, \ncheckingConnection: ${runtimeFlags.checkingConnection}, \nbusy: $busy"
-            )
             AppState(
                 send = preferences[PreferencesKeys.SEND] ?: false,
                 executedNum = preferences[PreferencesKeys.EXECUTED_NUM] ?: 0,
@@ -136,10 +134,6 @@ class AppStateRepo private constructor(private val context: Context) {
         suspended: Boolean? = null,
         requestNumberState: RequestNumberState? = null
     ) {
-        Log.i(
-            "AppStateRepository.updateRuntimeFlags",
-            "running: $running, \nrequesting: $requesting, \npreparing: $preparing, \ncheckingConnection: $checkingConnection, \nsuspended: $suspended, \nrequestNumberState: $requestNumberState"
-        )
         val value = appRuntimeFlags.value
         appRuntimeFlags.update {
             it.copy(

+ 2 - 12
app/src/main/java/com/example/modifier/repo/SpoofedSimInfoRepo.kt

@@ -139,18 +139,8 @@ class SpoofedSimInfoRepo private constructor(private val context: Context) {
                 "setprop persist.spoof.imsi ${spoofedSimInfo.imsi}",
                 "setprop persist.spoof.imei ${spoofedSimInfo.imei}",
                 "setprop persist.spoof.country ${spoofedSimInfo.country}",
-                "setprop persist.spoof.carrier.id ${
-                    spoofedSimInfo.carrierId.replace(
-                        "^\\W*\$".toRegex(),
-                        "''"
-                    )
-                }",
-                "setprop persist.spoof.carrier.name ${
-                    spoofedSimInfo.carrierName.replace(
-                        "^\\W*\$".toRegex(),
-                        "''"
-                    )
-                }",
+                "setprop persist.spoof.carrier.id ${spoofedSimInfo.carrierId}",
+                "setprop persist.spoof.carrier.name '${spoofedSimInfo.carrierName}'",
             )
 
             val context = Utils.getContext()

+ 4 - 5
app/src/main/java/com/example/modifier/service/ModifierService.kt

@@ -60,9 +60,8 @@ import kotlin.time.Duration.Companion.seconds
 
 @SuppressLint("SetTextI18n")
 class ModifierService : AccessibilityService() {
-    private val tag = "$baseTag/AccessibilityService"
-
     companion object {
+        private const val TAG = "$baseTag/Service"
         const val NAME: String = BuildConfig.APPLICATION_ID + ".service.ModifierService"
 
         @JvmStatic
@@ -92,13 +91,13 @@ class ModifierService : AccessibilityService() {
     override fun onAccessibilityEvent(event: AccessibilityEvent) {}
 
     override fun onInterrupt() {
-        Log.e(tag, "onInterrupt")
+        Log.e(TAG, "onInterrupt")
     }
 
     @SuppressLint("ClickableViewAccessibility")
     override fun onServiceConnected() {
         super.onServiceConnected()
-        Log.i(tag, "onServiceConnected")
+        Log.i(TAG, "onServiceConnected")
         instance = this
 
         val displayMetrics = DisplayMetrics()
@@ -132,7 +131,7 @@ class ModifierService : AccessibilityService() {
         binding.root.post {
             maxX = width - binding.root.measuredWidth
             maxY = height - binding.root.measuredHeight
-            Log.i(tag, "measured: $maxX, $maxY")
+            Log.i(TAG, "measured: $maxX, $maxY")
             layoutParams.x = maxX
             windowManager.updateViewLayout(mLayout, layoutParams)
         }

+ 4 - 3
app/src/main/java/com/example/modifier/service/TaskRunner.kt

@@ -488,7 +488,6 @@ class TaskRunner(
         var requestSuccess = withTimeoutOrNull(2.hours) {
             while (true) {
                 delay(200)
-                needRest = needRest || appStateRepo.appState.value.requestedNum > 5
                 try {
                     if (requestMode == 2 && !noBackup) {
                         val backup = backupRepository.findBackupForRestore(
@@ -510,6 +509,7 @@ class TaskRunner(
                         }
                     }
 
+                    needRest = needRest || appStateRepo.appState.value.requestedNum > 5
                     if (needRest && !appPrefsRepo.appPrefs.value.preventReset) {
                         reset()
                         needRest = false
@@ -525,8 +525,9 @@ class TaskRunner(
                     }
                 }
             }
+            false
         }
-        if (requestSuccess) {
+        if (requestSuccess == true) {
             spoofedSimInfoRepo.updateSpoofedSimInfo(
                 spoofedSimInfo = spoofedSimInfoRepo.spoofedSimInfo.value.copy(
                     available = true
@@ -546,7 +547,7 @@ class TaskRunner(
         appStateRepo.updateRuntimeFlags(
             requesting = false,
             requestNumberState = RequestNumberState.IDLE,
-            suspended = !requestSuccess
+            suspended = requestSuccess != true
         )
     }
 

+ 0 - 1
app/src/main/java/com/example/modifier/ui/settings/SettingsFragment.kt

@@ -317,7 +317,6 @@ class SettingsFragment : Fragment() {
             }
             launch {
                 spoofedSimInfoRepo.spoofedSimInfo.collect {
-                    Log.i(tag, "spoofedSimInfo.collect")
                     binding.etNumber.setText(it.number)
                     binding.etMcc.setText(it.mcc)
                     binding.etMnc.setText(it.mnc)

+ 5 - 5
app/src/main/java/com/example/modifier/ui/utils/UtilsFragment.kt

@@ -66,20 +66,20 @@ class UtilsFragment : Fragment() {
             return binding.root
         }
         binding = FragmentUtilsBinding.inflate(inflater, container, false)
-        binding.btnClear.setOnClickListener { v: View? ->
+        binding.btnClear.setOnClickListener {
             onClear()
         }
-        binding.btnStop.setOnClickListener { v: View? ->
+        binding.btnStop.setOnClickListener {
             onStopClick()
         }
-        binding.btnSend.setOnClickListener { v: View? ->
+        binding.btnSend.setOnClickListener {
             Utils.makeLoadingButton(context, binding.btnSend)
             lifecycleScope.launch {
                 delay(1000L)
 
                 val otp = binding.etOtp.text.toString()
                 withContext(Dispatchers.IO) {
-                    injectOTP("3538", "Your Messenger verification code is G-$otp")
+                    injectOTP(otp)
                 }
 
                 binding.btnSend.setIconResource(R.drawable.ic_done)
@@ -92,7 +92,7 @@ class UtilsFragment : Fragment() {
                 binding.btnSend.text = "Send"
             }
         }
-        binding.btnClearConv.setOnClickListener { v: View? ->
+        binding.btnClearConv.setOnClickListener {
             binding.btnClearConv.isEnabled = false
             Utils.makeLoadingButton(context, binding.btnClearConv)
             lifecycleScope.launch {