|
|
@@ -34,8 +34,14 @@ import androidx.lifecycle.liveData
|
|
|
import com.example.modifier.BuildConfig
|
|
|
import com.example.modifier.CMD_BACK
|
|
|
import com.example.modifier.CMD_CONVERSATION_LIST_ACTIVITY
|
|
|
+import com.example.modifier.CMD_KILL_GMS
|
|
|
+import com.example.modifier.CMD_KILL_MESSAGING_APP
|
|
|
import com.example.modifier.CMD_MESSAGING_APP
|
|
|
import com.example.modifier.CMD_RCS_SETTINGS_ACTIVITY
|
|
|
+import com.example.modifier.CMD_RESUME_GMS
|
|
|
+import com.example.modifier.CMD_RESUME_MESSAGING_APP
|
|
|
+import com.example.modifier.CMD_SUSPEND_GMS
|
|
|
+import com.example.modifier.CMD_SUSPEND_MESSAGING_APP
|
|
|
import com.example.modifier.Global
|
|
|
import com.example.modifier.Global.load
|
|
|
import com.example.modifier.Global.resetAll
|
|
|
@@ -75,6 +81,7 @@ import kotlinx.coroutines.isActive
|
|
|
import kotlinx.coroutines.launch
|
|
|
import kotlinx.coroutines.suspendCancellableCoroutine
|
|
|
import kotlinx.coroutines.withContext
|
|
|
+import kotlinx.coroutines.withTimeout
|
|
|
import kotlinx.coroutines.withTimeoutOrNull
|
|
|
import kotlinx.serialization.encodeToString
|
|
|
import kotlinx.serialization.json.Json
|
|
|
@@ -693,8 +700,15 @@ class ModifierService : AccessibilityService(), Emitter.Listener {
|
|
|
}
|
|
|
}
|
|
|
binding.btnInspect.setOnClickListener {
|
|
|
- CoroutineScope(Dispatchers.IO).launch {
|
|
|
- toggleRcsSwitch(false)
|
|
|
+ traverseNode(rootInActiveWindow, TraverseResult())
|
|
|
+ }
|
|
|
+ binding.btnReset.setOnClickListener {
|
|
|
+ binding.btnReset.isEnabled = false
|
|
|
+ CoroutineScope(Dispatchers.IO).launch {
|
|
|
+ reset()
|
|
|
+ withContext(Dispatchers.Main) {
|
|
|
+ binding.btnReset.isEnabled = true
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
binding.btnCheck.setOnClickListener {
|
|
|
@@ -707,6 +721,24 @@ class ModifierService : AccessibilityService(), Emitter.Listener {
|
|
|
storeNumbers()
|
|
|
}
|
|
|
}
|
|
|
+ binding.btnToggleOn.setOnClickListener {
|
|
|
+ binding.btnToggleOn.isEnabled = false
|
|
|
+ CoroutineScope(Dispatchers.IO).launch {
|
|
|
+ toggleRcsSwitch(true)
|
|
|
+ withContext(Dispatchers.Main) {
|
|
|
+ binding.btnToggleOn.isEnabled = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ binding.btnToggleOff.setOnClickListener {
|
|
|
+ binding.btnToggleOff.isEnabled = false
|
|
|
+ CoroutineScope(Dispatchers.IO).launch {
|
|
|
+ toggleRcsSwitch(false)
|
|
|
+ withContext(Dispatchers.Main) {
|
|
|
+ binding.btnToggleOff.isEnabled = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
busy.observeForever {
|
|
|
reportDeviceStatues()
|
|
|
}
|
|
|
@@ -762,23 +794,24 @@ class ModifierService : AccessibilityService(), Emitter.Listener {
|
|
|
private suspend fun toggleRcsSwitch(on: Boolean, retry: Int = 3): Boolean {
|
|
|
val res = TraverseResult()
|
|
|
|
|
|
- val success = run {
|
|
|
- shellRun(CMD_RCS_SETTINGS_ACTIVITY, "sleep 1")
|
|
|
+ shellRun(CMD_RCS_SETTINGS_ACTIVITY, "sleep 0.5")
|
|
|
+ val success = run repeatBlock@{
|
|
|
+
|
|
|
repeat(retry) {
|
|
|
res.rcsSwitch = null
|
|
|
traverseNode(rootInActiveWindow, res)
|
|
|
if (res.rcsSwitch == null) {
|
|
|
- shellRun(CMD_BACK, "sleep 2", CMD_RCS_SETTINGS_ACTIVITY, "sleep 1")
|
|
|
+ shellRun(CMD_BACK, "sleep 0.5", CMD_RCS_SETTINGS_ACTIVITY, "sleep 0.5")
|
|
|
} else {
|
|
|
if (res.rcsSwitch!!.isChecked == on) {
|
|
|
- return true
|
|
|
+ return@repeatBlock true
|
|
|
}
|
|
|
val rect = Rect()
|
|
|
res.rcsSwitch!!.getBoundsInScreen(rect)
|
|
|
if (on) {
|
|
|
shellRun(
|
|
|
- "input tap ${rect.centerX()} ${rect.centerY()}",
|
|
|
- "sleep 1", CMD_BACK, "sleep 1",
|
|
|
+ "input tap ${rect.centerX()} ${rect.centerY()}", "sleep 1",
|
|
|
+ CMD_BACK, "sleep 0.5",
|
|
|
CMD_RCS_SETTINGS_ACTIVITY, "sleep 1",
|
|
|
)
|
|
|
} else {
|
|
|
@@ -788,22 +821,72 @@ class ModifierService : AccessibilityService(), Emitter.Listener {
|
|
|
rootInActiveWindow.findAccessibilityNodeInfosByViewId("android:id/button1")
|
|
|
.firstOrNull()?.performAction(AccessibilityNodeInfo.ACTION_CLICK)
|
|
|
shellRun(
|
|
|
- "sleep 1", CMD_BACK, "sleep 1",
|
|
|
- CMD_RCS_SETTINGS_ACTIVITY, "sleep 1",
|
|
|
+ "sleep 0.5", CMD_BACK, "sleep 0.5",
|
|
|
+ CMD_RCS_SETTINGS_ACTIVITY, "sleep 0.5",
|
|
|
)
|
|
|
}
|
|
|
+ res.rcsSwitch = null
|
|
|
traverseNode(rootInActiveWindow, res)
|
|
|
- if (res.rcsSwitch!!.isChecked == on) {
|
|
|
- return true
|
|
|
+ if (res.rcsSwitch?.isChecked == on) {
|
|
|
+ return@repeatBlock true
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
false
|
|
|
}
|
|
|
- shellRun(CMD_BACK, "sleep 1")
|
|
|
+ shellRun(CMD_BACK, "sleep 0.5")
|
|
|
return success
|
|
|
}
|
|
|
|
|
|
+ private suspend fun reset() {
|
|
|
+ withTimeout(1.hours) {
|
|
|
+ while (true) {
|
|
|
+ delay(100)
|
|
|
+ withContext(Dispatchers.Main) {
|
|
|
+ binding.tvLog.text = "Waiting for RCS switch on..."
|
|
|
+ }
|
|
|
+ rcsConfigureState.postValue(RcsConfigureState.NOT_CONFIGURED)
|
|
|
+ Global.saveMock()
|
|
|
+ resetAll()
|
|
|
+ var switchAppear = waitForRcsState(
|
|
|
+ arrayOf(RcsConfigureState.WAITING_FOR_DEFAULT_ON),
|
|
|
+ 1.minutes
|
|
|
+ )?.let {
|
|
|
+ it == RcsConfigureState.WAITING_FOR_DEFAULT_ON
|
|
|
+ }
|
|
|
+ if (switchAppear != true) {
|
|
|
+ shellRun(
|
|
|
+ CMD_KILL_GMS, CMD_KILL_MESSAGING_APP, "sleep 1",
|
|
|
+ CMD_MESSAGING_APP
|
|
|
+ )
|
|
|
+ switchAppear = waitForRcsState(
|
|
|
+ arrayOf(RcsConfigureState.WAITING_FOR_DEFAULT_ON),
|
|
|
+ 2.minutes
|
|
|
+ )?.let {
|
|
|
+ it == RcsConfigureState.WAITING_FOR_DEFAULT_ON
|
|
|
+ }
|
|
|
+ if (switchAppear != true) {
|
|
|
+ Log.e(TAG, "RCS not entered default on state, retrying...")
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ }
|
|
|
+ val switchOn = toggleRcsSwitch(true)
|
|
|
+ if (!switchOn) {
|
|
|
+ Log.e(TAG, "RCS switch not turned on, retrying...")
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ val resetSuccess = waitForRcsState(
|
|
|
+ arrayOf(
|
|
|
+ RcsConfigureState.READY
|
|
|
+ ), 3.minutes
|
|
|
+ )
|
|
|
+ Log.i(TAG, "waitForRcsState: $resetSuccess")
|
|
|
+ requestNumberCount = 0
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private suspend fun requestNumber() {
|
|
|
val color = ContextCompat.getColorStateList(binding.root.context, R.color.btn_color)
|
|
|
binding.btnReq.backgroundTintList = color
|
|
|
@@ -863,7 +946,7 @@ class ModifierService : AccessibilityService(), Emitter.Listener {
|
|
|
)
|
|
|
)
|
|
|
|
|
|
- if (needRest &&
|
|
|
+ if (requestNumberCount > 5 &&
|
|
|
!getSharedPreferences("settings", Context.MODE_PRIVATE)
|
|
|
.getBoolean("do_not_reset", false)
|
|
|
) {
|
|
|
@@ -896,8 +979,9 @@ class ModifierService : AccessibilityService(), Emitter.Listener {
|
|
|
), 3.minutes
|
|
|
)
|
|
|
Log.i(TAG, "waitForRcsState: $resetSuccess")
|
|
|
- Global.suspend(gms = true, sms = true)
|
|
|
- Global.unsuspend(gms = true, sms = true)
|
|
|
+ toggleRcsSwitch(false)
|
|
|
+ delay(500)
|
|
|
+ toggleRcsSwitch(true)
|
|
|
requestNumberCount = 0
|
|
|
break
|
|
|
}
|