Global.kt 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. package com.example.modifier
  2. import android.content.Context
  3. import android.os.Build
  4. import android.util.Log
  5. import androidx.core.content.ContextCompat
  6. import com.example.modifier.model.TelephonyConfig
  7. import com.google.gson.Gson
  8. import org.apache.commons.io.FileUtils
  9. import org.apache.commons.lang3.StringUtils
  10. import java.io.File
  11. import java.io.FileWriter
  12. object Global {
  13. @JvmField
  14. var serverUrl: String? = ""
  15. @JvmField
  16. var name: String? = ""
  17. @JvmField
  18. var telephonyConfig: TelephonyConfig = TelephonyConfig("", "", "", "", "", "", "")
  19. @JvmStatic
  20. fun load() {
  21. val context = Utils.getContext()
  22. val prefs = context.getSharedPreferences(BuildConfig.APPLICATION_ID, Context.MODE_PRIVATE)
  23. serverUrl = prefs.getString("server", "http://192.168.6.215:3000")
  24. name = prefs.getString("name", Build.DEVICE)
  25. try {
  26. val file = File(ContextCompat.getDataDir(context), "config.json")
  27. if (file.exists()) {
  28. val gson = Gson()
  29. val json = FileUtils.readFileToString(file, "UTF-8")
  30. telephonyConfig = gson.fromJson(json, TelephonyConfig::class.java)
  31. }
  32. } catch (e: Exception) {
  33. e.printStackTrace()
  34. }
  35. }
  36. @JvmStatic
  37. val servers: MutableSet<String>
  38. get() {
  39. val context = Utils.getContext()
  40. val defServers: MutableSet<String> = HashSet()
  41. defServers.add("http://192.168.6.215:3000")
  42. defServers.add("http://192.168.50.135:3000")
  43. defServers.add("https://rcs.izouma.com")
  44. val prefs =
  45. context.getSharedPreferences(BuildConfig.APPLICATION_ID, Context.MODE_PRIVATE)
  46. return HashSet(prefs.getStringSet("servers", defServers))
  47. }
  48. @JvmStatic
  49. fun saveServer(server: String, name: String?) {
  50. serverUrl = server
  51. Global.name = name
  52. val context = Utils.getContext()
  53. val prefs = context.getSharedPreferences(BuildConfig.APPLICATION_ID, Context.MODE_PRIVATE)
  54. val servers = servers
  55. servers.add(server)
  56. prefs.edit().putStringSet("servers", servers)
  57. .putString("server", server)
  58. .putString("name", name)
  59. .apply()
  60. }
  61. @JvmStatic
  62. fun save(telephonyConfig: TelephonyConfig) {
  63. val context = Utils.getContext()
  64. Global.telephonyConfig.mcc = telephonyConfig.mcc
  65. Global.telephonyConfig.mnc = telephonyConfig.mnc
  66. Global.telephonyConfig.number = telephonyConfig.number
  67. Global.telephonyConfig.country = telephonyConfig.country
  68. Global.telephonyConfig.iccid = telephonyConfig.iccid
  69. Global.telephonyConfig.imei = telephonyConfig.imei
  70. Global.telephonyConfig.imsi = telephonyConfig.imsi
  71. try {
  72. val file = File(ContextCompat.getDataDir(context), "config.json")
  73. val gson = Gson()
  74. val json = gson.toJson(telephonyConfig)
  75. try {
  76. val writer = FileWriter(file)
  77. writer.write(json)
  78. writer.close()
  79. } catch (e: Exception) {
  80. e.printStackTrace()
  81. }
  82. Utils.runAsRoot(
  83. "cp " + file.path + " /data/data/com.android.phone/rcsConfig.json",
  84. "echo 'copied to phone'",
  85. "chmod 777 /data/data/com.android.phone/rcsConfig.json"
  86. )
  87. } catch (e: Exception) {
  88. e.printStackTrace()
  89. }
  90. }
  91. @JvmStatic
  92. fun clear(gsf: Boolean, gms: Boolean, sms: Boolean) {
  93. try {
  94. val cmds: MutableList<String> = ArrayList()
  95. if (gsf) {
  96. cmds.add("pm clear com.google.android.gsf")
  97. cmds.add("echo 'cleared gsf'")
  98. }
  99. if (gms) {
  100. cmds.add("pm clear com.google.android.gms")
  101. cmds.add("echo 'cleared gms'")
  102. }
  103. if (sms) {
  104. cmds.add("pm clear com.google.android.apps.messaging")
  105. cmds.add("echo 'cleared sms'")
  106. }
  107. Utils.runAsRoot(*cmds.toTypedArray<String>())
  108. } catch (e: Exception) {
  109. e.printStackTrace()
  110. }
  111. }
  112. @JvmStatic
  113. fun stop(gsf: Boolean, gms: Boolean, sms: Boolean) {
  114. try {
  115. val cmds: MutableList<String> = ArrayList()
  116. if (gsf) {
  117. cmds.add("am force-stop com.google.android.gsf")
  118. cmds.add("echo 'stopped gsf'")
  119. }
  120. if (gms) {
  121. cmds.add("am force-stop com.google.android.gms")
  122. cmds.add("echo 'stopped gms'")
  123. }
  124. if (sms) {
  125. cmds.add("am force-stop com.google.android.apps.messaging")
  126. cmds.add("echo 'stopped sms'")
  127. }
  128. Utils.runAsRoot(*cmds.toTypedArray<String>())
  129. } catch (e: Exception) {
  130. e.printStackTrace()
  131. }
  132. }
  133. @JvmStatic
  134. fun clearConv() {
  135. val context = Utils.getContext()
  136. try {
  137. val dataDir = ContextCompat.getDataDir(context)
  138. Utils.copyAssetFolder(context.assets, "bin", File(dataDir, "bin").path)
  139. // Utils.runAsRoot("su -c \"\"");
  140. Log.i("Modifier", "arch: " + StringUtils.join(Build.SUPPORTED_ABIS, ", "))
  141. var arch: String? = null
  142. for (supportedAbi in Build.SUPPORTED_ABIS) {
  143. if ("x86" == supportedAbi) {
  144. arch = "x86"
  145. } else if ("x86_64" == supportedAbi) {
  146. arch = "x64"
  147. } else if ("arm64-v8a" == supportedAbi) {
  148. arch = "arm64"
  149. } else if ("armeabi-v7a" == supportedAbi) {
  150. arch = "arm"
  151. }
  152. if (StringUtils.isNoneBlank(arch)) {
  153. val binPath = File(dataDir, "bin/sqlite3.$arch").path
  154. Log.i("Modifier", "sqlite3 binPath: $binPath")
  155. Utils.runAsRoot(
  156. "chmod +x $binPath",
  157. "$binPath /data/data/com.google.android.apps.messaging/databases/bugle_db \"DELETE FROM conversations;\"",
  158. "$binPath /data/data/com.google.android.apps.messaging/databases/bugle_db \"DELETE FROM messages;\"",
  159. "echo ok"
  160. )
  161. stop(false, false, true)
  162. Utils.runAsRoot("am start com.google.android.apps.messaging")
  163. Utils.runAsRoot("input keyevent KEYCODE_BACK")
  164. break
  165. }
  166. }
  167. } catch (e: Exception) {
  168. e.printStackTrace()
  169. }
  170. }
  171. }