xiongzhu 10 months ago
parent
commit
705c80fd06

+ 1 - 0
app/build.gradle

@@ -157,4 +157,5 @@ dependencies {
     implementation("io.coil-kt.coil3:coil-compose:3.0.2")
     implementation("io.coil-kt.coil3:coil-compose:3.0.2")
     implementation("io.coil-kt.coil3:coil-network-ktor2:3.0.2")
     implementation("io.coil-kt.coil3:coil-network-ktor2:3.0.2")
 
 
+
 }
 }

+ 14 - 0
app/src/main/java/com/example/modifier/http/api/DeviceApi.kt

@@ -4,7 +4,11 @@ import com.example.modifier.http.ktorClient
 import com.example.modifier.http.response.DeviceResponse
 import com.example.modifier.http.response.DeviceResponse
 import io.ktor.client.call.body
 import io.ktor.client.call.body
 import io.ktor.client.plugins.resources.get
 import io.ktor.client.plugins.resources.get
+import io.ktor.client.plugins.resources.post
 import io.ktor.resources.Resource
 import io.ktor.resources.Resource
+import kotlinx.coroutines.CoroutineScope
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.launch
 
 
 @Resource("api/device")
 @Resource("api/device")
 class DeviceApi() {
 class DeviceApi() {
@@ -12,6 +16,8 @@ class DeviceApi() {
     @Resource("{id}")
     @Resource("{id}")
     class Id(val parent: DeviceApi = DeviceApi(), val id: String) {
     class Id(val parent: DeviceApi = DeviceApi(), val id: String) {
 
 
+        @Resource("removePinTask")
+        class RemovePinTask(val parent: Id) {}
     }
     }
 
 
     companion object {
     companion object {
@@ -27,5 +33,13 @@ class DeviceApi() {
                 clashProfile = null
                 clashProfile = null
             )
             )
         }
         }
+
+        fun removePinTask(deviceId: String) {
+            CoroutineScope(Dispatchers.IO).launch {
+                runCatching {
+                    ktorClient.post(Id.RemovePinTask(Id(id = deviceId))).body<String>()
+                }
+            }
+        }
     }
     }
 }
 }

+ 15 - 14
app/src/main/java/com/example/modifier/http/api/RcsNumberApi.kt

@@ -17,6 +17,7 @@ import io.ktor.http.ContentType
 import io.ktor.http.contentType
 import io.ktor.http.contentType
 import io.ktor.resources.Resource
 import io.ktor.resources.Resource
 import kotlinx.coroutines.CoroutineScope
 import kotlinx.coroutines.CoroutineScope
+import kotlinx.coroutines.Dispatchers
 import kotlinx.coroutines.coroutineScope
 import kotlinx.coroutines.coroutineScope
 import kotlinx.coroutines.delay
 import kotlinx.coroutines.delay
 import kotlinx.coroutines.launch
 import kotlinx.coroutines.launch
@@ -89,21 +90,21 @@ class RcsNumberApi() {
             return response.body<RcsNumberResponse>()
             return response.body<RcsNumberResponse>()
         }
         }
 
 
-        suspend fun notifyOtpState(id: Int) {
-            CoroutineScope(coroutineContext).launch {
-                try {
+        fun notifyOtpState(id: Int) {
+            CoroutineScope(Dispatchers.IO).launch {
+                runCatching {
                     ktorClient.post(Id.OtpState(Id(RcsNumberApi(), id)))
                     ktorClient.post(Id.OtpState(Id(RcsNumberApi(), id)))
-                } catch (e: Exception) {
+                }.onFailure { e ->
                     Log.e(TAG, "Send OtpState Error: ${e.message}", e)
                     Log.e(TAG, "Send OtpState Error: ${e.message}", e)
                 }
                 }
             }
             }
         }
         }
 
 
-        suspend fun notifyConfigured(id: Int) {
-            CoroutineScope(coroutineContext).launch {
-                try {
+        fun notifyConfigured(id: Int) {
+            CoroutineScope(Dispatchers.IO).launch {
+                runCatching {
                     ktorClient.post(Id.Configured(Id(RcsNumberApi(), id)))
                     ktorClient.post(Id.Configured(Id(RcsNumberApi(), id)))
-                } catch (e: Exception) {
+                }.onFailure { e ->
                     Log.e(TAG, "Send Configured Error: ${e.message}", e)
                     Log.e(TAG, "Send Configured Error: ${e.message}", e)
                 }
                 }
             }
             }
@@ -111,9 +112,9 @@ class RcsNumberApi() {
 
 
         suspend fun notifyWasted(id: Int) {
         suspend fun notifyWasted(id: Int) {
             CoroutineScope(coroutineContext).launch {
             CoroutineScope(coroutineContext).launch {
-                try {
+                runCatching {
                     ktorClient.post(Id.Wasted(Id(RcsNumberApi(), id)))
                     ktorClient.post(Id.Wasted(Id(RcsNumberApi(), id)))
-                } catch (e: Exception) {
+                }.onFailure { e ->
                     Log.e(TAG, "Send Wasted Error: ${e.message}", e)
                     Log.e(TAG, "Send Wasted Error: ${e.message}", e)
                 }
                 }
             }
             }
@@ -122,7 +123,7 @@ class RcsNumberApi() {
         suspend fun waitForOtp(id: Int): String? {
         suspend fun waitForOtp(id: Int): String? {
             return withTimeoutOrNull(60.seconds) {
             return withTimeoutOrNull(60.seconds) {
                 while (true) {
                 while (true) {
-                    try {
+                    runCatching {
                         val rcsNumber =
                         val rcsNumber =
                             ktorClient.get(Id(id = id))
                             ktorClient.get(Id(id = id))
                                 .body<RcsNumberResponse>()
                                 .body<RcsNumberResponse>()
@@ -136,10 +137,10 @@ class RcsNumberApi() {
                                 return@withTimeoutOrNull otp
                                 return@withTimeoutOrNull otp
                             }
                             }
                         } else if (rcsNumber.status == RcsNumberResponse.STATUS_EXPIRED) {
                         } else if (rcsNumber.status == RcsNumberResponse.STATUS_EXPIRED) {
-                            break
+                            return@withTimeoutOrNull null
                         }
                         }
-                    } catch (exception: Exception) {
-                        Log.e(TAG, "wait for otp Error: ${exception.stackTrace}")
+                    }.onFailure { e ->
+                        Log.e(TAG, "wait for otp Error: ${e.stackTrace}")
                     }
                     }
                     delay(2.seconds)
                     delay(2.seconds)
                 }
                 }

+ 1 - 1
app/src/main/java/com/example/modifier/model/TaskExecutionResult.kt

@@ -6,7 +6,7 @@ import kotlinx.serialization.Serializable
 data class TaskExecutionResult(
 data class TaskExecutionResult(
     val id: Int,
     val id: Int,
     var messageId: String? = null,
     var messageId: String? = null,
-    var sent: Boolean = false,
+    var sent: Int = 0,
     var delivery: Int = 0,
     var delivery: Int = 0,
     var numberId: Int? = null,
     var numberId: Int? = null,
 )
 )

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

@@ -53,6 +53,7 @@ import kotlinx.coroutines.delay
 import kotlinx.coroutines.flow.debounce
 import kotlinx.coroutines.flow.debounce
 import kotlinx.coroutines.launch
 import kotlinx.coroutines.launch
 import kotlinx.coroutines.withContext
 import kotlinx.coroutines.withContext
+import java.net.URL
 import java.util.Timer
 import java.util.Timer
 import java.util.TimerTask
 import java.util.TimerTask
 import java.util.concurrent.atomic.AtomicReference
 import java.util.concurrent.atomic.AtomicReference
@@ -198,6 +199,7 @@ class ModifierService : AccessibilityService() {
                         socketClient.disconnect()
                         socketClient.disconnect()
                     }
                     }
                     socketClient = SocketClient(taskRunner)
                     socketClient = SocketClient(taskRunner)
+
                 }
                 }
             }
             }
             launch {
             launch {
@@ -431,6 +433,9 @@ class ModifierService : AccessibilityService() {
                             appStateRepo.resetExecutedNum()
                             appStateRepo.resetExecutedNum()
                             appStateRepo.resetSuccessNum()
                             appStateRepo.resetSuccessNum()
                             appStateRepo.resetRequestedNum()
                             appStateRepo.resetRequestedNum()
+
+                            appStateRepo.resetGroupExecutedNum()
+                            appStateRepo.resetGroupSuccessNum()
                         }
                         }
                     }
                     }
 
 

+ 29 - 8
app/src/main/java/com/example/modifier/service/TaskRunner.kt

@@ -213,7 +213,7 @@ class TaskRunner(
             return@run true
             return@run true
         }
         }
         appStateRepo.incrementGroupExecutedNum(1, success)
         appStateRepo.incrementGroupExecutedNum(1, success)
-        return true
+        return success
     }
     }
 
 
     suspend fun runTask(
     suspend fun runTask(
@@ -232,7 +232,7 @@ class TaskRunner(
             requestMode = if (taskAction.data.config.useBackup) 2 else 1
             requestMode = if (taskAction.data.config.useBackup) 2 else 1
 
 
             if (!spoofedInfoRepo.spoofedInfo.value.available ||
             if (!spoofedInfoRepo.spoofedInfo.value.available ||
-                (taskAction.data.config.checkConnection && appStateRepo.appState.value.singleExecuted == 0)
+                (taskAction.data.config.checkConnection && appStateRepo.appState.value.singleExecuted == 0 && appStateRepo.appState.value.groupExecuted == 0)
             ) {
             ) {
                 appStateRepo.updateRuntimeFlags(checkingConnection = true)
                 appStateRepo.updateRuntimeFlags(checkingConnection = true)
                 if (!spoofedInfoRepo.spoofedInfo.value.available || !checkRcsA10y()) {
                 if (!spoofedInfoRepo.spoofedInfo.value.available || !checkRcsA10y()) {
@@ -254,7 +254,7 @@ class TaskRunner(
             val results = mutableListOf<TaskExecutionResult>()
             val results = mutableListOf<TaskExecutionResult>()
 
 
             while (tasks.isNotEmpty() && taskConfig.groupMode && tasks.size > 2 && appStateRepo.appState.value.groupExecuted < taskConfig.groupQty) {
             while (tasks.isNotEmpty() && taskConfig.groupMode && tasks.size > 2 && appStateRepo.appState.value.groupExecuted < taskConfig.groupQty) {
-                val items = tasks.take(taskConfig.groupQty)
+                val items = tasks.take(taskConfig.groupSize)
                 tasks.removeAll(items)
                 tasks.removeAll(items)
                 val groupSent = groupSend(
                 val groupSent = groupSend(
                     to = items.map { it.number }.toTypedArray(),
                     to = items.map { it.number }.toTypedArray(),
@@ -266,13 +266,13 @@ class TaskRunner(
                     TaskExecutionResult(
                     TaskExecutionResult(
                         id = it.id,
                         id = it.id,
                         numberId = spoofedInfoRepo.spoofedInfo.value.numberId,
                         numberId = spoofedInfoRepo.spoofedInfo.value.numberId,
-                        sent = true,
+                        sent = 1,
                         delivery = if (groupSent) 1 else 0
                         delivery = if (groupSent) 1 else 0
                     )
                     )
                 })
                 })
             }
             }
 
 
-            while (tasks.isNotEmpty()) {
+            while (tasks.isNotEmpty() && appStateRepo.appState.value.singleExecuted < taskConfig.singleQty) {
                 val taskItem = tasks[0]
                 val taskItem = tasks[0]
                 tasks.removeAt(0)
                 tasks.removeAt(0)
                 val result = TaskExecutionResult(
                 val result = TaskExecutionResult(
@@ -282,11 +282,29 @@ class TaskRunner(
                 results.add(result)
                 results.add(result)
                 try {
                 try {
                     gmsgStateRepo.addToWatchList(result)
                     gmsgStateRepo.addToWatchList(result)
-                    result.sent = send(taskItem.number, taskItem.message, taskItem.img, taskConfig)
+                    result.sent = if (send(
+                            taskItem.number,
+                            taskItem.message,
+                            taskItem.img,
+                            taskConfig
+                        )
+                    ) 1 else 0
                 } catch (e: Exception) {
                 } catch (e: Exception) {
                     Log.e(TAG, "runTaskError: ${e.message}", e)
                     Log.e(TAG, "runTaskError: ${e.message}", e)
                 }
                 }
             }
             }
+
+            while (tasks.isNotEmpty()) {
+                val taskItem = tasks[0]
+                tasks.removeAt(0)
+                results.add(
+                    TaskExecutionResult(
+                        id = taskItem.id,
+                        sent = 2
+                    )
+                )
+            }
+
             shellRun(CMD_BACK)
             shellRun(CMD_BACK)
             delay(5000)
             delay(5000)
             onSuccess(results)
             onSuccess(results)
@@ -303,7 +321,7 @@ class TaskRunner(
                 delay(2000)
                 delay(2000)
             }
             }
             appStateRepo.updateRuntimeFlags(running = false)
             appStateRepo.updateRuntimeFlags(running = false)
-            if (taskAction.data.config.checkConnection && results.none { it.sent }) {
+            if (taskAction.data.config.checkConnection && results.none { it.sent == 1 }) {
                 appStateRepo.updateRuntimeFlags(checkingConnection = true)
                 appStateRepo.updateRuntimeFlags(checkingConnection = true)
                 if (!checkRcsA10y()) {
                 if (!checkRcsA10y()) {
                     onError(Exception("RCS not available"))
                     onError(Exception("RCS not available"))
@@ -607,6 +625,7 @@ class TaskRunner(
             return
             return
         }
         }
         appStateRepo.updateRuntimeFlags(reqState = ReqState.CLEAN)
         appStateRepo.updateRuntimeFlags(reqState = ReqState.CLEAN)
+        DeviceApi.removePinTask(appPrefsRepo.appPrefs.value.id)
         clearConv(restoreRole = false)
         clearConv(restoreRole = false)
         if (spoofedInfoRepo.spoofedInfo.value.available) {
         if (spoofedInfoRepo.spoofedInfo.value.available) {
             backupRepository.backup(
             backupRepository.backup(
@@ -658,6 +677,8 @@ class TaskRunner(
             spoofedInfoRepo.updateAvailable(available = true)
             spoofedInfoRepo.updateAvailable(available = true)
             appStateRepo.resetSuccessNum()
             appStateRepo.resetSuccessNum()
             appStateRepo.resetExecutedNum()
             appStateRepo.resetExecutedNum()
+            appStateRepo.resetGroupExecutedNum()
+            appStateRepo.resetGroupSuccessNum()
             Log.i(TAG, "requestNumber success")
             Log.i(TAG, "requestNumber success")
         } else {
         } else {
             Log.e(TAG, "requestNumber failed")
             Log.e(TAG, "requestNumber failed")
@@ -891,7 +912,7 @@ class TaskRunner(
         }
         }
     }
     }
 
 
-    suspend fun cancelStoreNumber() {
+    fun cancelStoreNumber() {
         if (storeNumberJob != null) {
         if (storeNumberJob != null) {
             if (storeNumberJob!!.isActive) {
             if (storeNumberJob!!.isActive) {
                 storeNumberJob!!.cancel()
                 storeNumberJob!!.cancel()