|
|
@@ -18,6 +18,7 @@ import android.util.DisplayMetrics
|
|
|
import android.util.Log
|
|
|
import android.view.Gravity
|
|
|
import android.view.LayoutInflater
|
|
|
+import android.view.MenuItem
|
|
|
import android.view.MotionEvent
|
|
|
import android.view.View
|
|
|
import android.view.View.OnTouchListener
|
|
|
@@ -26,6 +27,8 @@ import android.view.accessibility.AccessibilityEvent
|
|
|
import android.view.accessibility.AccessibilityNodeInfo
|
|
|
import android.widget.CompoundButton
|
|
|
import android.widget.FrameLayout
|
|
|
+import androidx.annotation.MenuRes
|
|
|
+import androidx.appcompat.widget.PopupMenu
|
|
|
import androidx.core.content.ContextCompat
|
|
|
import androidx.datastore.core.DataStore
|
|
|
import androidx.datastore.preferences.core.Preferences
|
|
|
@@ -43,8 +46,11 @@ import com.example.modifier.CMD_MESSAGING_APP
|
|
|
import com.example.modifier.CMD_RCS_SETTINGS_ACTIVITY
|
|
|
import com.example.modifier.Global
|
|
|
import com.example.modifier.Global.backup
|
|
|
+import com.example.modifier.Global.changeClashProfile
|
|
|
import com.example.modifier.Global.load
|
|
|
import com.example.modifier.Global.resetAll
|
|
|
+import com.example.modifier.Global.restartModifier
|
|
|
+import com.example.modifier.Global.stopClash
|
|
|
import com.example.modifier.R
|
|
|
import com.example.modifier.TraverseResult
|
|
|
import com.example.modifier.Utils
|
|
|
@@ -173,10 +179,8 @@ class ModifierService : AccessibilityService(), Emitter.Listener {
|
|
|
|
|
|
private var sendCount: Int
|
|
|
get() {
|
|
|
- return getSharedPreferences(
|
|
|
- BuildConfig.APPLICATION_ID,
|
|
|
- MODE_PRIVATE
|
|
|
- ).getInt("sendCount", 0)
|
|
|
+ return getSharedPreferences(BuildConfig.APPLICATION_ID, MODE_PRIVATE)
|
|
|
+ .getInt("sendCount", 0)
|
|
|
}
|
|
|
set(value) {
|
|
|
getSharedPreferences(BuildConfig.APPLICATION_ID, MODE_PRIVATE).edit()
|
|
|
@@ -185,10 +189,8 @@ class ModifierService : AccessibilityService(), Emitter.Listener {
|
|
|
|
|
|
private var requestNumberCount: Int
|
|
|
get() {
|
|
|
- return getSharedPreferences(
|
|
|
- BuildConfig.APPLICATION_ID,
|
|
|
- MODE_PRIVATE
|
|
|
- ).getInt("requestNumberCount", 0)
|
|
|
+ return getSharedPreferences(BuildConfig.APPLICATION_ID, MODE_PRIVATE)
|
|
|
+ .getInt("requestNumberCount", 0)
|
|
|
}
|
|
|
set(value) {
|
|
|
getSharedPreferences(BuildConfig.APPLICATION_ID, MODE_PRIVATE).edit()
|
|
|
@@ -230,24 +232,24 @@ class ModifierService : AccessibilityService(), Emitter.Listener {
|
|
|
} else if (line.contains("destState=ReplayRequestState")) {
|
|
|
rcsConfigureState.postValue(RcsConfigureState.REPLAY_REQUEST)
|
|
|
}
|
|
|
- Regex("(?<time>\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}.\\d{3}) I/BugleRcsEngine\\(\\W*\\d+\\): (?<log>.*)").matchEntire(
|
|
|
- line
|
|
|
- )?.apply {
|
|
|
- val time = groups["time"]?.value?.dropLast(4)
|
|
|
- val log = groups["log"]?.value
|
|
|
- ?.replace(Regex("\\[\\w+-\\w+-\\w+-\\w+-\\w+]"), "")
|
|
|
- ?.replace(Regex("\\[CONTEXT.*]"), "")
|
|
|
- ?.trim()
|
|
|
-
|
|
|
- if (time != null && log != null) {
|
|
|
- if (log.contains("destState=")) {
|
|
|
- logs.add("$time: $log")
|
|
|
- emit(logs.joinToString("\n"))
|
|
|
- delay(100)
|
|
|
- emit(logs.joinToString("\n"))
|
|
|
+ Regex("(?<time>\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}.\\d{3}) I/BugleRcsEngine\\(\\W*\\d+\\): (?<log>.*)")
|
|
|
+ .matchEntire(line)
|
|
|
+ ?.apply {
|
|
|
+ val time = groups["time"]?.value?.dropLast(4)
|
|
|
+ val log = groups["log"]?.value
|
|
|
+ ?.replace(Regex("\\[\\w+-\\w+-\\w+-\\w+-\\w+]"), "")
|
|
|
+ ?.replace(Regex("\\[CONTEXT.*]"), "")
|
|
|
+ ?.trim()
|
|
|
+
|
|
|
+ if (time != null && log != null) {
|
|
|
+ if (log.contains("destState=")) {
|
|
|
+ logs.add("$time: $log")
|
|
|
+ emit(logs.joinToString("\n"))
|
|
|
+ delay(100)
|
|
|
+ emit(logs.joinToString("\n"))
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
}
|
|
|
}
|
|
|
} catch (e: Exception) {
|
|
|
@@ -437,6 +439,7 @@ class ModifierService : AccessibilityService(), Emitter.Listener {
|
|
|
Log.e(TAG, "runTaskError: ${e.message}", e)
|
|
|
fail.add(taskItem.id)
|
|
|
}
|
|
|
+ updateCountUI()
|
|
|
}
|
|
|
Utils.runAsRoot(CMD_BACK)
|
|
|
mSocket.emit(
|
|
|
@@ -754,57 +757,66 @@ class ModifierService : AccessibilityService(), Emitter.Listener {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- binding.btnCheck.setOnClickListener {
|
|
|
- CoroutineScope(Dispatchers.IO).launch {
|
|
|
- checkRcsAvailability()
|
|
|
- }
|
|
|
- }
|
|
|
- binding.btnStoreNumbers.setOnClickListener {
|
|
|
- CoroutineScope(Dispatchers.IO).launch {
|
|
|
- storeNumbers()
|
|
|
- }
|
|
|
+ binding.btnMore.setOnClickListener {
|
|
|
+ showMenu(newContext, binding.btnMore, R.menu.more)
|
|
|
}
|
|
|
- binding.btnToggleOn.setOnClickListener {
|
|
|
- binding.btnToggleOn.isEnabled = false
|
|
|
- CoroutineScope(Dispatchers.IO).launch {
|
|
|
- toggleRcsSwitch(true)
|
|
|
- withContext(Dispatchers.Main) {
|
|
|
- binding.btnToggleOn.isEnabled = true
|
|
|
- }
|
|
|
- }
|
|
|
+ busy.observeForever {
|
|
|
+ reportDeviceStatues()
|
|
|
}
|
|
|
- binding.btnToggleOff.setOnClickListener {
|
|
|
- binding.btnToggleOff.isEnabled = false
|
|
|
+ updateCountUI()
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun showMenu(context: Context, v: View, @MenuRes menuRes: Int) {
|
|
|
+ val popup = PopupMenu(context, v)
|
|
|
+ popup.menuInflater.inflate(menuRes, popup.menu)
|
|
|
+ popup.setOnMenuItemClickListener { item ->
|
|
|
+ binding.btnMore.isEnabled = false
|
|
|
CoroutineScope(Dispatchers.IO).launch {
|
|
|
- toggleRcsSwitch(false)
|
|
|
- withContext(Dispatchers.Main) {
|
|
|
- binding.btnToggleOff.isEnabled = true
|
|
|
+ when (item.itemId) {
|
|
|
+ R.id.check_availability -> {
|
|
|
+ checkRcsAvailability()
|
|
|
+ }
|
|
|
+
|
|
|
+ R.id.toggle_on -> {
|
|
|
+ toggleRcsSwitch(true)
|
|
|
+ }
|
|
|
+
|
|
|
+ R.id.toggle_off -> {
|
|
|
+ toggleRcsSwitch(false)
|
|
|
+ }
|
|
|
+
|
|
|
+ R.id.clear_conv -> {
|
|
|
+ Global.clearConv()
|
|
|
+ }
|
|
|
+
|
|
|
+ R.id.store_numbers -> {
|
|
|
+ storeNumbers()
|
|
|
+ }
|
|
|
+
|
|
|
+ R.id.change_profile -> {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ R.id.restart_modifier -> {
|
|
|
+ restartModifier()
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- }
|
|
|
- binding.btnClean.setOnClickListener {
|
|
|
- binding.btnClean.isEnabled = false
|
|
|
- CoroutineScope(Dispatchers.IO).launch {
|
|
|
- Global.clearConv()
|
|
|
+
|
|
|
withContext(Dispatchers.Main) {
|
|
|
- binding.btnClean.isEnabled = true
|
|
|
+ binding.btnMore.isEnabled = true
|
|
|
}
|
|
|
}
|
|
|
+ true
|
|
|
}
|
|
|
- binding.btnChangeProfile.setOnClickListener {
|
|
|
- val intent = Intent()
|
|
|
- intent.action = "com.github.metacubex.clash.meta.action.USE_PROFILE"
|
|
|
- intent.putExtra(
|
|
|
- "base64",
|
|
|
- "bW9kZTogcnVsZQ0KdW5pZmllZC1kZ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DQogIC0gR0VPSVAsQ04sRElSRUNUDQogIC0gTUFUQ0gs6IqC54K56YCJ5oup"
|
|
|
- )
|
|
|
- intent.putExtra("name", "ve")
|
|
|
- intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
|
|
- startActivity(intent)
|
|
|
- }
|
|
|
- busy.observeForever {
|
|
|
- reportDeviceStatues()
|
|
|
+ popup.setOnDismissListener {
|
|
|
+ // Respond to popup being dismissed.
|
|
|
}
|
|
|
+ // Show the popup menu.
|
|
|
+ popup.show()
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun updateCountUI() {
|
|
|
+ binding.tvCount.text = "${sendCount} / ${counter}"
|
|
|
}
|
|
|
|
|
|
private fun reportDeviceStatues() {
|
|
|
@@ -815,6 +827,7 @@ class ModifierService : AccessibilityService(), Emitter.Listener {
|
|
|
val dataObj = JSONObject()
|
|
|
dataObj.put("canSend", canSend)
|
|
|
dataObj.put("busy", busy.value)
|
|
|
+ dataObj.put("currentCountry", Global.telephonyConfig.country)
|
|
|
data.put("data", dataObj)
|
|
|
mSocket.emit("message", data)
|
|
|
} catch (e: JSONException) {
|
|
|
@@ -1076,6 +1089,8 @@ class ModifierService : AccessibilityService(), Emitter.Listener {
|
|
|
sendCount = sendCount,
|
|
|
fresh = fresh
|
|
|
)
|
|
|
+ } else {
|
|
|
+ Global.clearConv();
|
|
|
}
|
|
|
|
|
|
requestNumberCount++
|
|
|
@@ -1096,28 +1111,19 @@ class ModifierService : AccessibilityService(), Emitter.Listener {
|
|
|
prefs.edit()
|
|
|
.remove("clash_profile")
|
|
|
.apply()
|
|
|
- val intent = Intent()
|
|
|
- intent.action = "com.github.metacubex.clash.meta.action.STOP_CLASH"
|
|
|
- intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
|
|
- startActivity(intent)
|
|
|
+ stopClash()
|
|
|
} else {
|
|
|
val oldProfile = prefs.getString("clash_profile", "")
|
|
|
if (oldProfile != device.clashProfile) {
|
|
|
prefs.edit()
|
|
|
.putString("clash_profile", device.clashProfile)
|
|
|
.apply()
|
|
|
- val intent = Intent()
|
|
|
- intent.action = "com.github.metacubex.clash.meta.action.USE_PROFILE"
|
|
|
- intent.putExtra(
|
|
|
- "base64",
|
|
|
- Base64.encodeToString(
|
|
|
+ changeClashProfile(
|
|
|
+ device.pinCountry!!, Base64.encodeToString(
|
|
|
device.clashProfile!!.toByteArray(),
|
|
|
Base64.DEFAULT
|
|
|
)
|
|
|
)
|
|
|
- intent.putExtra("name", device.pinCountry)
|
|
|
- intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
|
|
- startActivity(intent)
|
|
|
delay(5000)
|
|
|
}
|
|
|
}
|
|
|
@@ -1404,16 +1410,10 @@ class ModifierService : AccessibilityService(), Emitter.Listener {
|
|
|
}
|
|
|
|
|
|
private suspend fun storeNumbers() {
|
|
|
- withContext(Dispatchers.Main) {
|
|
|
- binding.btnStoreNumbers.isEnabled = false
|
|
|
- }
|
|
|
repeat(100) {
|
|
|
requestNumber(reset = true, fresh = it > 0)
|
|
|
delay(5000)
|
|
|
}
|
|
|
- withContext(Dispatchers.Main) {
|
|
|
- binding.btnStoreNumbers.isEnabled = true
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
}
|