|
|
@@ -82,6 +82,7 @@ import org.json.JSONException
|
|
|
import org.json.JSONObject
|
|
|
import java.util.Optional
|
|
|
import java.util.concurrent.atomic.AtomicReference
|
|
|
+import java.util.concurrent.locks.ReentrantLock
|
|
|
import kotlin.coroutines.resume
|
|
|
import kotlin.math.max
|
|
|
import kotlin.math.min
|
|
|
@@ -110,6 +111,7 @@ class ModifierService : AccessibilityService(), Emitter.Listener {
|
|
|
private lateinit var mSocket: Socket
|
|
|
private lateinit var binding: FloatingWindowBinding
|
|
|
|
|
|
+ val lock = ReentrantLock()
|
|
|
|
|
|
private var canSend: Boolean
|
|
|
get() {
|
|
|
@@ -319,13 +321,7 @@ class ModifierService : AccessibilityService(), Emitter.Listener {
|
|
|
}
|
|
|
|
|
|
private suspend fun runTask(taskAction: TaskAction) {
|
|
|
- val rcsWait = taskAction.data.config.rcsWait
|
|
|
- cleanCount = taskAction.data.config.cleanCount
|
|
|
- rcsInterval = taskAction.data.config.rcsInterval
|
|
|
- requestNumberInterval = taskAction.data.config.requestNumberInterval
|
|
|
- currentTaskId = taskAction.data.taskId
|
|
|
-
|
|
|
- if (taskAction.data.config.checkConnection && !checkRcsAvailability()) {
|
|
|
+ if (checkingConnection.value!! || running.value!!) {
|
|
|
mSocket.emit(
|
|
|
"callback",
|
|
|
JSONObject(
|
|
|
@@ -333,50 +329,94 @@ class ModifierService : AccessibilityService(), Emitter.Listener {
|
|
|
SocketCallback<String>(
|
|
|
id = taskAction.id,
|
|
|
status = -1,
|
|
|
- error = "RCS not available"
|
|
|
+ error = "another task is running"
|
|
|
)
|
|
|
)
|
|
|
)
|
|
|
)
|
|
|
- requestNumber()
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- running.postValue(true)
|
|
|
- val success = ArrayList<Int>()
|
|
|
- val fail = ArrayList<Int>()
|
|
|
- for (i in 0 until taskAction.data.tasks.size) {
|
|
|
- val taskItem = taskAction.data.tasks[i]
|
|
|
- try {
|
|
|
- if (send(taskItem.number, taskItem.message, rcsWait)) {
|
|
|
- success.add(taskItem.id)
|
|
|
- } else {
|
|
|
+ try {
|
|
|
+ val rcsWait = taskAction.data.config.rcsWait
|
|
|
+ cleanCount = taskAction.data.config.cleanCount
|
|
|
+ rcsInterval = taskAction.data.config.rcsInterval
|
|
|
+ requestNumberInterval = taskAction.data.config.requestNumberInterval
|
|
|
+ currentTaskId = taskAction.data.taskId
|
|
|
+
|
|
|
+ if (taskAction.data.config.checkConnection) {
|
|
|
+ checkingConnection.postValue(true)
|
|
|
+ if (!checkRcsAvailability()) {
|
|
|
+ mSocket.emit(
|
|
|
+ "callback",
|
|
|
+ JSONObject(
|
|
|
+ Json.encodeToString(
|
|
|
+ SocketCallback<String>(
|
|
|
+ id = taskAction.id,
|
|
|
+ status = -1,
|
|
|
+ error = "RCS not available"
|
|
|
+ )
|
|
|
+ )
|
|
|
+ )
|
|
|
+ )
|
|
|
+ requestNumber()
|
|
|
+ checkingConnection.postValue(false)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ checkingConnection.postValue(false)
|
|
|
+ }
|
|
|
+
|
|
|
+ running.postValue(true)
|
|
|
+ val success = ArrayList<Int>()
|
|
|
+ val fail = ArrayList<Int>()
|
|
|
+ for (i in 0 until taskAction.data.tasks.size) {
|
|
|
+ val taskItem = taskAction.data.tasks[i]
|
|
|
+ try {
|
|
|
+ if (send(taskItem.number, taskItem.message, rcsWait)) {
|
|
|
+ success.add(taskItem.id)
|
|
|
+ } else {
|
|
|
+ fail.add(taskItem.id)
|
|
|
+ }
|
|
|
+ } catch (e: Exception) {
|
|
|
+ Log.e(TAG, "runTaskError: ${e.message}", e)
|
|
|
fail.add(taskItem.id)
|
|
|
}
|
|
|
- } catch (e: Exception) {
|
|
|
- Log.e(TAG, "runTaskError: ${e.message}", e)
|
|
|
- fail.add(taskItem.id)
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- mSocket.emit(
|
|
|
- "callback",
|
|
|
- JSONObject(
|
|
|
- Json.encodeToString(
|
|
|
- SocketCallback(
|
|
|
- id = taskAction.id,
|
|
|
- status = 0,
|
|
|
- data = TaskExecutionResult(success, fail)
|
|
|
+ mSocket.emit(
|
|
|
+ "callback",
|
|
|
+ JSONObject(
|
|
|
+ Json.encodeToString(
|
|
|
+ SocketCallback(
|
|
|
+ id = taskAction.id,
|
|
|
+ status = 0,
|
|
|
+ data = TaskExecutionResult(success, fail)
|
|
|
+ )
|
|
|
)
|
|
|
)
|
|
|
)
|
|
|
- )
|
|
|
- if (requestNumberInterval in 1..sendCount) {
|
|
|
- runBlocking {
|
|
|
- requestNumber()
|
|
|
+ if (requestNumberInterval in 1..sendCount) {
|
|
|
+ runBlocking {
|
|
|
+ requestNumber()
|
|
|
+ }
|
|
|
}
|
|
|
+ running.postValue(false)
|
|
|
+ } catch (e: Exception) {
|
|
|
+ Log.e(TAG, "runTaskError: ${e.message}", e)
|
|
|
+ mSocket.emit(
|
|
|
+ "callback",
|
|
|
+ JSONObject(
|
|
|
+ Json.encodeToString(
|
|
|
+ SocketCallback<String>(
|
|
|
+ id = taskAction.id,
|
|
|
+ status = -1,
|
|
|
+ error = e.message
|
|
|
+ )
|
|
|
+ )
|
|
|
+ )
|
|
|
+ )
|
|
|
+ running.postValue(false)
|
|
|
}
|
|
|
- running.postValue(false)
|
|
|
}
|
|
|
|
|
|
private fun smsIntent(to: String, body: String): Intent {
|
|
|
@@ -749,7 +789,7 @@ class ModifierService : AccessibilityService(), Emitter.Listener {
|
|
|
continue
|
|
|
}
|
|
|
Utils.runAsRoot(
|
|
|
- "am start com.google.android.apps.messaging/com.google.android.apps.messaging.ui.appsettings.RcsSettingsActivity",
|
|
|
+ CMD_RCS_SETTINGS_ACTIVITY,
|
|
|
"sleep 1"
|
|
|
)
|
|
|
val res = TraverseResult()
|
|
|
@@ -763,8 +803,8 @@ class ModifierService : AccessibilityService(), Emitter.Listener {
|
|
|
Utils.runAsRoot(
|
|
|
"input tap ${rect.centerX()} ${rect.centerY()}",
|
|
|
"sleep 1",
|
|
|
- "input keyevent KEYCODE_BACK",
|
|
|
- "am start com.google.android.apps.messaging/com.google.android.apps.messaging.ui.appsettings.RcsSettingsActivity",
|
|
|
+ CMD_BACK,
|
|
|
+ CMD_RCS_SETTINGS_ACTIVITY,
|
|
|
)
|
|
|
Log.i(TAG, "RCS switch turned on, waiting for state change...")
|
|
|
|
|
|
@@ -869,6 +909,7 @@ class ModifierService : AccessibilityService(), Emitter.Listener {
|
|
|
} else {
|
|
|
Log.e(TAG, "requestNumber failed")
|
|
|
}
|
|
|
+ Utils.runAsRoot(CMD_BACK)
|
|
|
}
|
|
|
|
|
|
suspend fun checkRcsAvailability(): Boolean {
|
|
|
@@ -933,7 +974,7 @@ class ModifierService : AccessibilityService(), Emitter.Listener {
|
|
|
if (traverseResult.isRcsCapable) {
|
|
|
return@withTimeoutOrNull true
|
|
|
} else {
|
|
|
- Log.i(TAG, "RCS not detected")
|
|
|
+ Log.i(TAG, "checkRcsAvailability: RCS not detected")
|
|
|
}
|
|
|
try {
|
|
|
delay(200)
|