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

+ 101 - 8
app/src/main/java/com/example/modifier/Global.kt

@@ -67,7 +67,7 @@ object Global {
     }
     }
 
 
     @JvmStatic
     @JvmStatic
-    fun save(telephonyConfig: TelephonyConfig) {
+    fun save(telephonyConfig: TelephonyConfig, suspend: Boolean? = true) {
         val context = Utils.getContext()
         val context = Utils.getContext()
         Global.telephonyConfig.mcc = telephonyConfig.mcc
         Global.telephonyConfig.mcc = telephonyConfig.mcc
         Global.telephonyConfig.mnc = telephonyConfig.mnc
         Global.telephonyConfig.mnc = telephonyConfig.mnc
@@ -78,6 +78,9 @@ object Global {
         Global.telephonyConfig.imsi = telephonyConfig.imsi
         Global.telephonyConfig.imsi = telephonyConfig.imsi
 
 
         try {
         try {
+            if (suspend == true) {
+                suspend(gms = true, sms = true)
+            }
             val file = File(ContextCompat.getDataDir(context), "config.json")
             val file = File(ContextCompat.getDataDir(context), "config.json")
             val gson = Gson()
             val gson = Gson()
             val json = gson.toJson(telephonyConfig)
             val json = gson.toJson(telephonyConfig)
@@ -93,8 +96,12 @@ object Global {
             Utils.runAsRoot(
             Utils.runAsRoot(
                 "cp " + file.path + " /data/data/com.android.phone/rcsConfig.json",
                 "cp " + file.path + " /data/data/com.android.phone/rcsConfig.json",
                 "echo 'copied to phone'",
                 "echo 'copied to phone'",
-                "chmod 777 /data/data/com.android.phone/rcsConfig.json"
+                "chmod 777 /data/data/com.android.phone/rcsConfig.json",
+                "sleep 1"
             )
             )
+            if (suspend == true) {
+                unsuspend(gms = true, sms = true)
+            }
         } catch (e: Exception) {
         } catch (e: Exception) {
             e.printStackTrace()
             e.printStackTrace()
         }
         }
@@ -103,7 +110,26 @@ object Global {
     @JvmStatic
     @JvmStatic
     fun clear(gsf: Boolean, gms: Boolean, sms: Boolean) {
     fun clear(gsf: Boolean, gms: Boolean, sms: Boolean) {
         try {
         try {
+            suspend(gsf, gms, sms)
             val cmds: MutableList<String> = ArrayList()
             val cmds: MutableList<String> = ArrayList()
+            // suspend
+            if (gsf) {
+                cmds.add("pm suspend com.google.android.gsf")
+                cmds.add("am force-stop com.google.android.gsf")
+                cmds.add("echo 'gsf suspended'")
+            }
+            if (gms) {
+                cmds.add("pm suspend com.google.android.gms")
+                cmds.add("am force-stop com.google.android.gms")
+                cmds.add("echo 'gms suspended'")
+            }
+            if (sms) {
+                cmds.add("pm suspend com.google.android.apps.messaging")
+                cmds.add("am force-stop com.google.android.apps.messaging")
+                cmds.add("echo 'sms suspended'")
+            }
+            cmds.add("sleep 1")
+            // clear
             if (gsf) {
             if (gsf) {
                 cmds.add("pm clear com.google.android.gsf")
                 cmds.add("pm clear com.google.android.gsf")
                 cmds.add("echo 'cleared gsf'")
                 cmds.add("echo 'cleared gsf'")
@@ -116,29 +142,93 @@ object Global {
                 cmds.add("pm clear com.google.android.apps.messaging")
                 cmds.add("pm clear com.google.android.apps.messaging")
                 cmds.add("echo 'cleared sms'")
                 cmds.add("echo 'cleared sms'")
             }
             }
+            cmds.add("sleep 1")
+            // unsuspend
+            if (gsf) {
+                cmds.add("pm unsuspend com.google.android.gsf")
+                cmds.add("echo 'gsf unsuspend'")
+            }
+            if (gms) {
+                cmds.add("pm unsuspend com.google.android.gms")
+                cmds.add("echo 'gms unsuspend'")
+            }
+            if (sms) {
+                cmds.add("pm unsuspend com.google.android.apps.messaging")
+                cmds.add("echo 'sms unsuspend'")
+            }
+            cmds.add("sleep 1")
             Utils.runAsRoot(*cmds.toTypedArray<String>())
             Utils.runAsRoot(*cmds.toTypedArray<String>())
         } catch (e: Exception) {
         } catch (e: Exception) {
             e.printStackTrace()
             e.printStackTrace()
         }
         }
     }
     }
 
 
+//    @JvmStatic
+//    fun stop(gsf: Boolean? = false, gms: Boolean? = false, sms: Boolean? = false) {
+//        try {
+//            val cmds: MutableList<String> = ArrayList()
+//            if (gsf == true) {
+//                cmds.add("am force-stop com.google.android.gsf")
+//                cmds.add("echo 'stopped gsf'")
+//            }
+//            if (gms == true) {
+//                cmds.add("am force-stop com.google.android.gms")
+//                cmds.add("echo 'stopped gms'")
+//                Thread.sleep(1000)
+//            }
+//            if (sms == true) {
+//                cmds.add("am force-stop com.google.android.apps.messaging")
+//                cmds.add("echo 'stopped sms'")
+//            }
+//            Utils.runAsRoot(*cmds.toTypedArray<String>())
+//        } catch (e: Exception) {
+//            e.printStackTrace()
+//        }
+//    }
+
     @JvmStatic
     @JvmStatic
-    fun stop(gsf: Boolean? = false, gms: Boolean? = false, sms: Boolean? = false) {
+    fun suspend(gsf: Boolean? = false, gms: Boolean? = false, sms: Boolean? = false) {
         try {
         try {
             val cmds: MutableList<String> = ArrayList()
             val cmds: MutableList<String> = ArrayList()
             if (gsf == true) {
             if (gsf == true) {
+                cmds.add("pm suspend com.google.android.gsf")
                 cmds.add("am force-stop com.google.android.gsf")
                 cmds.add("am force-stop com.google.android.gsf")
-                cmds.add("echo 'stopped gsf'")
+                cmds.add("echo 'gsf suspended'")
             }
             }
             if (gms == true) {
             if (gms == true) {
+                cmds.add("pm suspend com.google.android.gms")
                 cmds.add("am force-stop com.google.android.gms")
                 cmds.add("am force-stop com.google.android.gms")
-                cmds.add("echo 'stopped gms'")
-                Thread.sleep(1000)
+                cmds.add("echo 'gms suspended'")
             }
             }
             if (sms == true) {
             if (sms == true) {
+                cmds.add("pm suspend com.google.android.apps.messaging")
                 cmds.add("am force-stop com.google.android.apps.messaging")
                 cmds.add("am force-stop com.google.android.apps.messaging")
-                cmds.add("echo 'stopped sms'")
+                cmds.add("echo 'sms suspended'")
             }
             }
+            cmds.add("sleep 1")
+            Utils.runAsRoot(*cmds.toTypedArray<String>())
+        } catch (e: Exception) {
+            e.printStackTrace()
+        }
+    }
+
+    @JvmStatic
+    fun unsuspend(gsf: Boolean? = false, gms: Boolean? = false, sms: Boolean? = false) {
+        try {
+            val cmds: MutableList<String> = ArrayList()
+            if (gsf == true) {
+                cmds.add("pm unsuspend com.google.android.gsf")
+                cmds.add("echo 'gsf unsuspend'")
+            }
+            if (gms == true) {
+                cmds.add("pm unsuspend com.google.android.gms")
+                cmds.add("echo 'gms unsuspend'")
+            }
+            if (sms == true) {
+                cmds.add("pm unsuspend com.google.android.apps.messaging")
+                cmds.add("echo 'sms unsuspend'")
+            }
+            cmds.add("sleep 1")
             Utils.runAsRoot(*cmds.toTypedArray<String>())
             Utils.runAsRoot(*cmds.toTypedArray<String>())
         } catch (e: Exception) {
         } catch (e: Exception) {
             e.printStackTrace()
             e.printStackTrace()
@@ -166,6 +256,8 @@ object Global {
                     arch = "arm"
                     arch = "arm"
                 }
                 }
                 if (StringUtils.isNoneBlank(arch)) {
                 if (StringUtils.isNoneBlank(arch)) {
+                    suspend(sms = true)
+
                     val binPath = File(dataDir, "bin/sqlite3.$arch").path
                     val binPath = File(dataDir, "bin/sqlite3.$arch").path
                     Log.i("Modifier", "sqlite3 binPath: $binPath")
                     Log.i("Modifier", "sqlite3 binPath: $binPath")
                     Utils.runAsRoot(
                     Utils.runAsRoot(
@@ -174,12 +266,13 @@ object Global {
                         "$binPath /data/data/com.google.android.apps.messaging/databases/bugle_db \"DELETE FROM messages;\"",
                         "$binPath /data/data/com.google.android.apps.messaging/databases/bugle_db \"DELETE FROM messages;\"",
                         "echo ok"
                         "echo ok"
                     )
                     )
-                    stop(false, false, true)
+                    unsuspend(sms = true)
                     Utils.runAsRoot("am start com.google.android.apps.messaging")
                     Utils.runAsRoot("am start com.google.android.apps.messaging")
                     Utils.runAsRoot("input keyevent KEYCODE_BACK")
                     Utils.runAsRoot("input keyevent KEYCODE_BACK")
                     break
                     break
                 }
                 }
             }
             }
+
         } catch (e: Exception) {
         } catch (e: Exception) {
             e.printStackTrace()
             e.printStackTrace()
         }
         }

+ 3 - 2
app/src/main/java/com/example/modifier/adapter/BackupAdapter.java

@@ -58,13 +58,14 @@ public class BackupAdapter extends RecyclerView.Adapter<BackupAdapter.BackupView
                                 int uid = packageManager.getApplicationInfo("com.google.android.apps.messaging", 0).uid;
                                 int uid = packageManager.getApplicationInfo("com.google.android.apps.messaging", 0).uid;
                                 int gmsUid = packageManager.getApplicationInfo("com.google.android.gms", 0).uid;
                                 int gmsUid = packageManager.getApplicationInfo("com.google.android.gms", 0).uid;
 
 
-                                Global.save(backup.getConfig());
+                                Global.suspend(false, true, true);
+                                Global.save(backup.getConfig(), false);
                                 Utils.runAsRoot("pm clear com.google.android.apps.messaging",
                                 Utils.runAsRoot("pm clear com.google.android.apps.messaging",
                                         "cp -rf " + backup.getPath() + "/data/* /data/data/com.google.android.apps.messaging/",
                                         "cp -rf " + backup.getPath() + "/data/* /data/data/com.google.android.apps.messaging/",
                                         "chown -R " + uid + ":" + uid + " /data/data/com.google.android.apps.messaging/*",
                                         "chown -R " + uid + ":" + uid + " /data/data/com.google.android.apps.messaging/*",
                                         "cp -rf " + backup.getPath() + "/gmsData/* /data/data/com.google.android.gms/",
                                         "cp -rf " + backup.getPath() + "/gmsData/* /data/data/com.google.android.gms/",
                                         "chown -R " + gmsUid + ":" + gmsUid + " /data/data/com.google.android.gms/*");
                                         "chown -R " + gmsUid + ":" + gmsUid + " /data/data/com.google.android.gms/*");
-                                Global.stop(false, false, true);
+                                Global.unsuspend(false, true, true);
                             } catch (Exception e) {
                             } catch (Exception e) {
                                 e.printStackTrace();
                                 e.printStackTrace();
                             }
                             }

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

@@ -547,7 +547,6 @@ class ModifierService : AccessibilityService(), Emitter.Listener {
                     rcsRes.country
                     rcsRes.country
                 )
                 )
             )
             )
-            Global.stop(gms = true, sms = true)
             delay(1000)
             delay(1000)
             Utils.runAsRoot("am start -a android.intent.action.MAIN -c android.intent.category.LAUNCHER com.google.android.apps.messaging")
             Utils.runAsRoot("am start -a android.intent.action.MAIN -c android.intent.category.LAUNCHER com.google.android.apps.messaging")
             delay(1000)
             delay(1000)

+ 3 - 1
app/src/main/java/com/example/modifier/ui/backup/BackupFragment.java

@@ -13,6 +13,7 @@ import androidx.core.content.ContextCompat;
 import androidx.fragment.app.Fragment;
 import androidx.fragment.app.Fragment;
 import androidx.recyclerview.widget.LinearLayoutManager;
 import androidx.recyclerview.widget.LinearLayoutManager;
 
 
+import com.example.modifier.Global;
 import com.example.modifier.model.Backup;
 import com.example.modifier.model.Backup;
 import com.example.modifier.adapter.BackupAdapter;
 import com.example.modifier.adapter.BackupAdapter;
 import com.example.modifier.model.TelephonyConfig;
 import com.example.modifier.model.TelephonyConfig;
@@ -91,6 +92,7 @@ public class BackupFragment extends Fragment {
 
 
     private void createBackup() {
     private void createBackup() {
         try {
         try {
+            Global.suspend(false, true, true);
             File backupDir = new File(ContextCompat.getExternalFilesDirs(getContext(), "backup")[0], System.currentTimeMillis() + "");
             File backupDir = new File(ContextCompat.getExternalFilesDirs(getContext(), "backup")[0], System.currentTimeMillis() + "");
             backupDir.mkdirs();
             backupDir.mkdirs();
             File file = new File(ContextCompat.getDataDir(getContext()), "config.json");
             File file = new File(ContextCompat.getDataDir(getContext()), "config.json");
@@ -110,7 +112,7 @@ public class BackupFragment extends Fragment {
             Utils.runAsRoot("cp -r /data/data/com.google.android.gms/* " + gmsDataDir.getPath());
             Utils.runAsRoot("cp -r /data/data/com.google.android.gms/* " + gmsDataDir.getPath());
 
 
             Log.d("BackupFragment", "Backup created at " + backupDir.getPath());
             Log.d("BackupFragment", "Backup created at " + backupDir.getPath());
-
+            Global.unsuspend(false, true, true);
             handler.post(() -> {
             handler.post(() -> {
                 loadBackups();
                 loadBackups();
             });
             });

+ 0 - 3
app/src/main/java/com/example/modifier/ui/settings/SettingsFragment.kt

@@ -23,7 +23,6 @@ import com.example.modifier.Global.load
 import com.example.modifier.Global.save
 import com.example.modifier.Global.save
 import com.example.modifier.Global.saveServer
 import com.example.modifier.Global.saveServer
 import com.example.modifier.Global.servers
 import com.example.modifier.Global.servers
-import com.example.modifier.Global.stop
 import com.example.modifier.MainActivity
 import com.example.modifier.MainActivity
 import com.example.modifier.service.ModifierService.Companion.instance
 import com.example.modifier.service.ModifierService.Companion.instance
 import com.example.modifier.R
 import com.example.modifier.R
@@ -146,8 +145,6 @@ class SettingsFragment : Fragment() {
                     val imei = Utils.generateIMEI()
                     val imei = Utils.generateIMEI()
                     save(TelephonyConfig(number, mcc, mnc, iccid, imsi, imei, country))
                     save(TelephonyConfig(number, mcc, mnc, iccid, imsi, imei, country))
 
 
-                    stop(false, true, true)
-
                     handler.post {
                     handler.post {
                         val telephonyConfig = Global.telephonyConfig
                         val telephonyConfig = Global.telephonyConfig
                         binding.etNumber.setText(telephonyConfig.number)
                         binding.etNumber.setText(telephonyConfig.number)

+ 0 - 1
app/src/main/java/com/example/modifier/ui/settings/SettingsViewModel.kt

@@ -40,7 +40,6 @@ class SettingsViewModel : ViewModel() {
                 rcsRes.country
                 rcsRes.country
             )
             )
         )
         )
-        Global.stop(gms = true, sms = true)
 
 
         liveData(Dispatchers.IO) {
         liveData(Dispatchers.IO) {
             viewModelScope.launch {
             viewModelScope.launch {

+ 42 - 3
app/src/main/java/com/example/modifier/ui/utils/UtilsFragment.kt

@@ -10,7 +10,8 @@ import android.view.ViewGroup
 import androidx.fragment.app.Fragment
 import androidx.fragment.app.Fragment
 import com.example.modifier.Global.clear
 import com.example.modifier.Global.clear
 import com.example.modifier.Global.clearConv
 import com.example.modifier.Global.clearConv
-import com.example.modifier.Global.stop
+import com.example.modifier.Global.suspend
+import com.example.modifier.Global.unsuspend
 import com.example.modifier.R
 import com.example.modifier.R
 import com.example.modifier.Utils
 import com.example.modifier.Utils
 import com.example.modifier.databinding.FragmentUtilsBinding
 import com.example.modifier.databinding.FragmentUtilsBinding
@@ -85,6 +86,44 @@ class UtilsFragment : Fragment() {
                 }
                 }
             }
             }
         }
         }
+        binding.btnSuspend.setOnClickListener {
+            binding.btnSuspend.isEnabled = false
+            Utils.makeLoadingButton(context, binding.btnSuspend)
+            executor.execute {
+                val gsf = binding.cbGsf.isChecked
+                val gms = binding.cbGms.isChecked
+                val sms = binding.cbSms.isChecked
+                suspend(gsf, gms, sms)
+                handler.post {
+                    binding.btnSuspend.setIconResource(R.drawable.ic_done)
+                    binding.btnSuspend.text = "OK"
+                    handler.postDelayed({
+                        binding.btnSuspend.isEnabled = true
+                        binding.btnSuspend.icon = null
+                        binding.btnSuspend.text = "Suspend"
+                    }, 1500)
+                }
+            }
+        }
+        binding.btnUnsuspend.setOnClickListener {
+            binding.btnUnsuspend.isEnabled = false
+            Utils.makeLoadingButton(context, binding.btnUnsuspend)
+            executor.execute {
+                val gsf = binding.cbGsf.isChecked
+                val gms = binding.cbGms.isChecked
+                val sms = binding.cbSms.isChecked
+                unsuspend(gsf, gms, sms)
+                handler.post {
+                    binding.btnUnsuspend.setIconResource(R.drawable.ic_done)
+                    binding.btnUnsuspend.text = "OK"
+                    handler.postDelayed({
+                        binding.btnUnsuspend.isEnabled = true
+                        binding.btnUnsuspend.icon = null
+                        binding.btnUnsuspend.text = "Unsuspend"
+                    }, 1500)
+                }
+            }
+        }
         return binding.root
         return binding.root
     }
     }
 
 
@@ -96,7 +135,6 @@ class UtilsFragment : Fragment() {
             val gms = binding.cbGms.isChecked
             val gms = binding.cbGms.isChecked
             val sms = binding.cbSms.isChecked
             val sms = binding.cbSms.isChecked
             clear(gsf, gms, sms)
             clear(gsf, gms, sms)
-            stop(gsf, gms, sms)
             handler.post {
             handler.post {
                 binding.btnClear.setIconResource(R.drawable.ic_done)
                 binding.btnClear.setIconResource(R.drawable.ic_done)
                 binding.btnClear.text = "OK"
                 binding.btnClear.text = "OK"
@@ -117,7 +155,8 @@ class UtilsFragment : Fragment() {
             val gsf = binding.cbGsf.isChecked
             val gsf = binding.cbGsf.isChecked
             val gms = binding.cbGms.isChecked
             val gms = binding.cbGms.isChecked
             val sms = binding.cbSms.isChecked
             val sms = binding.cbSms.isChecked
-            stop(gsf, gms, sms)
+            suspend(gsf, gms, sms)
+            unsuspend(gsf, gms, sms)
             handler.post {
             handler.post {
                 binding.btnStop.setIconResource(R.drawable.ic_done)
                 binding.btnStop.setIconResource(R.drawable.ic_done)
                 binding.btnStop.text = "OK"
                 binding.btnStop.text = "OK"

+ 22 - 0
app/src/main/res/layout/fragment_utils.xml

@@ -86,6 +86,28 @@
                                 android:layout_weight="1"
                                 android:layout_weight="1"
                                 android:text="Stop" />
                                 android:text="Stop" />
                         </LinearLayout>
                         </LinearLayout>
+
+                        <LinearLayout
+                            android:layout_width="match_parent"
+                            android:layout_height="wrap_content"
+                            android:layout_marginTop="8dp"
+                            android:orientation="horizontal">
+
+                            <com.google.android.material.button.MaterialButton
+                                android:id="@+id/btn_suspend"
+                                android:layout_width="0dp"
+                                android:layout_height="wrap_content"
+                                android:layout_weight="1"
+                                android:text="Suspend" />
+
+                            <com.google.android.material.button.MaterialButton
+                                android:id="@+id/btn_unsuspend"
+                                android:layout_width="0dp"
+                                android:layout_height="wrap_content"
+                                android:layout_marginLeft="16dp"
+                                android:layout_weight="1"
+                                android:text="Unsuspend" />
+                        </LinearLayout>
                     </LinearLayout>
                     </LinearLayout>
                 </com.google.android.material.card.MaterialCardView>
                 </com.google.android.material.card.MaterialCardView>