|
|
@@ -12,6 +12,8 @@ import android.net.Uri
|
|
|
import android.os.Build
|
|
|
import android.os.Handler
|
|
|
import android.os.Looper
|
|
|
+import android.text.TextUtils
|
|
|
+import android.util.Base64
|
|
|
import android.util.DisplayMetrics
|
|
|
import android.util.Log
|
|
|
import android.view.Gravity
|
|
|
@@ -52,9 +54,11 @@ import com.example.modifier.databinding.FloatingWindowBinding
|
|
|
import com.example.modifier.enums.RcsConfigureState
|
|
|
import com.example.modifier.enums.RcsConnectionStatus
|
|
|
import com.example.modifier.http.KtorClient
|
|
|
+import com.example.modifier.http.api.DeviceApi
|
|
|
import com.example.modifier.http.api.RcsNumberApi
|
|
|
import com.example.modifier.http.api.SysConfigApi
|
|
|
import com.example.modifier.http.request.RcsNumberRequest
|
|
|
+import com.example.modifier.http.response.DeviceResponse
|
|
|
import com.example.modifier.http.response.RcsNumberResponse
|
|
|
import com.example.modifier.http.response.SysConfigResponse
|
|
|
import com.example.modifier.model.SocketCallback
|
|
|
@@ -304,6 +308,8 @@ class ModifierService : AccessibilityService(), Emitter.Listener {
|
|
|
preparing.postValue(true)
|
|
|
if (Global.rebooted()) {
|
|
|
delay(2.minutes)
|
|
|
+ } else {
|
|
|
+ delay(5000)
|
|
|
}
|
|
|
if (Global.hasRoot()) {
|
|
|
Global.setupSystem()
|
|
|
@@ -1081,6 +1087,40 @@ class ModifierService : AccessibilityService(), Emitter.Listener {
|
|
|
delay(200)
|
|
|
needRest = needRest || retry > 2 || requestNumberCount > 5
|
|
|
try {
|
|
|
+ val device = KtorClient.get(DeviceApi.Id(id = Utils.getUniqueID()))
|
|
|
+ .body<DeviceResponse>()
|
|
|
+
|
|
|
+ val prefs = getSharedPreferences("settings", Context.MODE_PRIVATE)
|
|
|
+ if (TextUtils.isEmpty(device.clashProfile)) {
|
|
|
+ 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)
|
|
|
+ } 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(
|
|
|
+ device.clashProfile!!.toByteArray(),
|
|
|
+ Base64.DEFAULT
|
|
|
+ )
|
|
|
+ )
|
|
|
+ intent.putExtra("name", device.pinCountry)
|
|
|
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
|
|
+ startActivity(intent)
|
|
|
+ delay(5000)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
if (requestMode == 2 && !noBackup) {
|
|
|
val backup = backupItemDao.findBackupForRestore(
|
|
|
Global.telephonyConfig.number,
|
|
|
@@ -1111,16 +1151,18 @@ class ModifierService : AccessibilityService(), Emitter.Listener {
|
|
|
binding.tvLog.text = "Requesting number..."
|
|
|
}
|
|
|
|
|
|
+ val req = RcsNumberRequest(
|
|
|
+ deviceId = Utils.getUniqueID(),
|
|
|
+ taskId = currentTaskId
|
|
|
+ )
|
|
|
+ if (!TextUtils.isEmpty(device.pinCountry)) {
|
|
|
+ req.country = device.pinCountry
|
|
|
+ }
|
|
|
val response = KtorClient.put(
|
|
|
RcsNumberApi()
|
|
|
) {
|
|
|
contentType(ContentType.Application.Json)
|
|
|
- setBody(
|
|
|
- RcsNumberRequest(
|
|
|
- deviceId = Utils.getUniqueID(),
|
|
|
- taskId = currentTaskId
|
|
|
- )
|
|
|
- )
|
|
|
+ setBody(req)
|
|
|
}
|
|
|
var rcsNumber = response.body<RcsNumberResponse>()
|
|
|
Log.i(TAG, "requestNumber response: $rcsNumber")
|