xiongzhu пре 10 месеци
родитељ
комит
f8945430b2

+ 1 - 0
app/src/main/java/com/example/modifier/data/AppState.kt

@@ -13,6 +13,7 @@ data class AppState(
     val suspended: Boolean,
     val reqState: ReqState,
     val storing: Boolean = false,
+    val failure:Int = 0
 ) {
 
     val busy: Boolean

+ 12 - 0
app/src/main/java/com/example/modifier/repo/AppStateRepo.kt

@@ -132,4 +132,16 @@ class AppStateRepo private constructor(private val context: Context) {
             )
         }
     }
+
+    fun incrementFailure() {
+        appState.update {
+            it.copy(failure = it.failure + 1)
+        }
+    }
+
+    fun resetFailure() {
+        appState.update {
+            it.copy(failure = 0)
+        }
+    }
 }

+ 9 - 2
app/src/main/java/com/example/modifier/service/TaskRunner.kt

@@ -204,8 +204,12 @@ class TaskRunner(
                 appStateRepo.updateRuntimeFlags(checkingConnection = true)
                 if (!spoofedInfoRepo.spoofedInfo.value.available || !checkRcsA10y()) {
                     onError(Exception("RCS not available"))
-                    requestNumberOnTask()
-                    appStateRepo.updateRuntimeFlags(checkingConnection = false)
+                    if (appStateRepo.appState.value.failure >= 3) {
+                        appStateRepo.updateRuntimeFlags(reqState = ReqState.NONE, suspended = true)
+                    } else {
+                        requestNumberOnTask()
+                        appStateRepo.updateRuntimeFlags(checkingConnection = false)
+                    }
                     return
                 }
                 appStateRepo.updateRuntimeFlags(checkingConnection = false)
@@ -673,6 +677,9 @@ class TaskRunner(
         }
         if (!availability) {
             RcsNumberApi.notifyWasted(spoofedInfoRepo.spoofedInfo.value.numberId)
+            appStateRepo.incrementFailure()
+        } else {
+            appStateRepo.resetFailure()
         }
         return availability
     }