x1ongzhu 1 год назад
Родитель
Сommit
2f45268f7a

+ 1 - 0
app/src/main/java/com/example/modifier/repo/GoogleMessageStateRepository.kt

@@ -64,6 +64,7 @@ class GoogleMessageStateRepository(context: Context) {
                                 val log = groups["log"]?.value
                                     ?.replace(Regex("\\[\\w+-\\w+-\\w+-\\w+-\\w+]"), "")
                                     ?.replace(Regex("\\[CONTEXT.*]"), "")
+                                    ?.replace("transitionTo: destState=", "")
                                     ?.trim()
 
                                 if (time != null && log != null) {

+ 19 - 13
app/src/main/java/com/example/modifier/service/SocketClient.kt

@@ -8,6 +8,7 @@ import com.example.modifier.model.InstallApkAction
 import com.example.modifier.model.SocketCallback
 import com.example.modifier.model.TaskAction
 import com.example.modifier.model.TaskConfig
+import com.example.modifier.model.TaskExecutionResult
 import com.example.modifier.serializer.Json
 import com.example.modifier.utils.uniqueId
 import io.socket.client.IO
@@ -38,9 +39,13 @@ class SocketClient(
         mSocket = IO.socket(server, mSocketOpts)
 
         mSocket.on("message", this)
-        mSocket.on(Socket.EVENT_CONNECT) { this.onConnected() }
-        mSocket.on(Socket.EVENT_DISCONNECT) { this.onDisconnected() }
-        mSocket.on(Socket.EVENT_CONNECT_ERROR) { this.onConnectError() }
+        mSocket.on(Socket.EVENT_CONNECT) { this.onConnected(it) }
+        mSocket.on(Socket.EVENT_DISCONNECT) { this.onDisconnected(it) }
+        mSocket.on(Socket.EVENT_CONNECT_ERROR) {
+            it.forEach {
+                Log.e(TAG, "Connection error", it as Throwable)
+            }
+        }
         try {
             mSocket.connect()
         } catch (e: Exception) {
@@ -119,22 +124,15 @@ class SocketClient(
         }
     }
 
-    fun onConnected() {
+    fun onConnected(vararg args: Any) {
         Log.i(tag, "Connected to server")
         CoroutineScope(Dispatchers.IO).launch {
             delay(500)
         }
     }
 
-    fun onDisconnected() {}
+    fun onDisconnected(vararg args: Any) {}
 
-    fun onConnectError(vararg args: Any) {
-        Log.i(TAG, "Connection error: " + args[0])
-        if (args[0] is Exception) {
-            val e = args[0] as Exception
-            e.printStackTrace()
-        }
-    }
 
     fun reportDeviceStatues(canSend: Boolean, busy: Boolean, currentCountry: String) {
         val data = JSONObject()
@@ -151,7 +149,15 @@ class SocketClient(
         }
     }
 
-    fun emitEvent(event: String, data: Any) {
+    fun emitEvent(event: String, data: TaskExecutionResult) {
+        try {
+            mSocket.emit(event, JSONObject(Json.encodeToString(data)))
+        } catch (e: Exception) {
+            Log.e(tag, "emitEvent error", e)
+        }
+    }
+
+    fun <T> emitEvent(event: String, data: SocketCallback<T>) {
         try {
             mSocket.emit(event, JSONObject(Json.encodeToString(data)))
         } catch (e: Exception) {

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

@@ -734,7 +734,7 @@ class TaskRunner(
 
             if (checkRcsAvailabilityNumbers.isEmpty()) {
                 Log.e(TAG, "checkRcsAvailabilityNumbers is empty")
-                return true
+                return@checkAvailability true
             }
 
             checkRcsAvailabilityNumbers.forEach {