| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- package com.example.modifier
- import android.content.Context
- import android.os.Build
- import android.util.Log
- import androidx.core.content.ContextCompat
- import com.example.modifier.model.TelephonyConfig
- import com.google.gson.Gson
- import org.apache.commons.io.FileUtils
- import org.apache.commons.lang3.StringUtils
- import java.io.File
- import java.io.FileWriter
- object Global {
- @JvmField
- var serverUrl: String? = ""
- @JvmField
- var name: String? = ""
- @JvmField
- var telephonyConfig: TelephonyConfig = TelephonyConfig("", "", "", "", "", "", "")
- @JvmStatic
- fun load() {
- val context = Utils.getContext()
- val prefs = context.getSharedPreferences(BuildConfig.APPLICATION_ID, Context.MODE_PRIVATE)
- serverUrl = prefs.getString("server", "http://192.168.6.215:3000")
- name = prefs.getString("name", Build.DEVICE)
- try {
- val file = File(ContextCompat.getDataDir(context), "config.json")
- if (file.exists()) {
- val gson = Gson()
- val json = FileUtils.readFileToString(file, "UTF-8")
- telephonyConfig = gson.fromJson(json, TelephonyConfig::class.java)
- }
- } catch (e: Exception) {
- e.printStackTrace()
- }
- }
- @JvmStatic
- val servers: MutableSet<String>
- get() {
- val context = Utils.getContext()
- val defServers: MutableSet<String> = HashSet()
- defServers.add("http://192.168.6.215:3000")
- defServers.add("http://192.168.50.135:3000")
- defServers.add("https://rcs.izouma.com")
- val prefs =
- context.getSharedPreferences(BuildConfig.APPLICATION_ID, Context.MODE_PRIVATE)
- return HashSet(prefs.getStringSet("servers", defServers))
- }
- @JvmStatic
- fun saveServer(server: String, name: String?) {
- serverUrl = server
- Global.name = name
- val context = Utils.getContext()
- val prefs = context.getSharedPreferences(BuildConfig.APPLICATION_ID, Context.MODE_PRIVATE)
- val servers = servers
- servers.add(server)
- prefs.edit().putStringSet("servers", servers)
- .putString("server", server)
- .putString("name", name)
- .apply()
- }
- @JvmStatic
- fun save(telephonyConfig: TelephonyConfig) {
- val context = Utils.getContext()
- Global.telephonyConfig.mcc = telephonyConfig.mcc
- Global.telephonyConfig.mnc = telephonyConfig.mnc
- Global.telephonyConfig.number = telephonyConfig.number
- Global.telephonyConfig.country = telephonyConfig.country
- Global.telephonyConfig.iccid = telephonyConfig.iccid
- Global.telephonyConfig.imei = telephonyConfig.imei
- Global.telephonyConfig.imsi = telephonyConfig.imsi
- try {
- val file = File(ContextCompat.getDataDir(context), "config.json")
- val gson = Gson()
- val json = gson.toJson(telephonyConfig)
- try {
- val writer = FileWriter(file)
- writer.write(json)
- writer.close()
- } catch (e: Exception) {
- e.printStackTrace()
- }
- Utils.runAsRoot(
- "cp " + file.path + " /data/data/com.android.phone/rcsConfig.json",
- "echo 'copied to phone'",
- "chmod 777 /data/data/com.android.phone/rcsConfig.json"
- )
- } catch (e: Exception) {
- e.printStackTrace()
- }
- }
- @JvmStatic
- fun clear(gsf: Boolean, gms: Boolean, sms: Boolean) {
- try {
- val cmds: MutableList<String> = ArrayList()
- if (gsf) {
- cmds.add("pm clear com.google.android.gsf")
- cmds.add("echo 'cleared gsf'")
- }
- if (gms) {
- cmds.add("pm clear com.google.android.gms")
- cmds.add("echo 'cleared gms'")
- }
- if (sms) {
- cmds.add("pm clear com.google.android.apps.messaging")
- cmds.add("echo 'cleared sms'")
- }
- Utils.runAsRoot(*cmds.toTypedArray<String>())
- } catch (e: Exception) {
- e.printStackTrace()
- }
- }
- @JvmStatic
- fun stop(gsf: Boolean, gms: Boolean, sms: Boolean) {
- try {
- val cmds: MutableList<String> = ArrayList()
- if (gsf) {
- cmds.add("am force-stop com.google.android.gsf")
- cmds.add("echo 'stopped gsf'")
- }
- if (gms) {
- cmds.add("am force-stop com.google.android.gms")
- cmds.add("echo 'stopped gms'")
- }
- if (sms) {
- 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
- fun clearConv() {
- val context = Utils.getContext()
- try {
- val dataDir = ContextCompat.getDataDir(context)
- Utils.copyAssetFolder(context.assets, "bin", File(dataDir, "bin").path)
- // Utils.runAsRoot("su -c \"\"");
- Log.i("Modifier", "arch: " + StringUtils.join(Build.SUPPORTED_ABIS, ", "))
- var arch: String? = null
- for (supportedAbi in Build.SUPPORTED_ABIS) {
- if ("x86" == supportedAbi) {
- arch = "x86"
- } else if ("x86_64" == supportedAbi) {
- arch = "x64"
- } else if ("arm64-v8a" == supportedAbi) {
- arch = "arm64"
- } else if ("armeabi-v7a" == supportedAbi) {
- arch = "arm"
- }
- if (StringUtils.isNoneBlank(arch)) {
- val binPath = File(dataDir, "bin/sqlite3.$arch").path
- Log.i("Modifier", "sqlite3 binPath: $binPath")
- Utils.runAsRoot(
- "chmod +x $binPath",
- "$binPath /data/data/com.google.android.apps.messaging/databases/bugle_db \"DELETE FROM conversations;\"",
- "$binPath /data/data/com.google.android.apps.messaging/databases/bugle_db \"DELETE FROM messages;\"",
- "echo ok"
- )
- stop(false, false, true)
- Utils.runAsRoot("am start com.google.android.apps.messaging")
- Utils.runAsRoot("input keyevent KEYCODE_BACK")
- break
- }
- }
- } catch (e: Exception) {
- e.printStackTrace()
- }
- }
- }
|