Skip to content

Commit ae7c807

Browse files
proguard bs
Signed-off-by: androidacy-user <opensource@androidacy.com>
1 parent 60d284d commit ae7c807

16 files changed

Lines changed: 104 additions & 81 deletions

app/src/main/kotlin/com/fox2code/mmm/MainActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,7 @@ class MainActivity : AppCompatActivity(), OnRefreshListener, OverScrollHelper {
821821
}
822822
})
823823
// update last feedback time
824-
MainApplication.getSharedPreferences("mmm")?.edit()
824+
MainApplication.getPreferences("mmm")?.edit()
825825
?.putLong("last_feedback", System.currentTimeMillis())?.apply()
826826
}
827827
} else {

app/src/main/kotlin/com/fox2code/mmm/MainApplication.kt

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ class MainApplication : Application(), Configuration.Provider, ActivityLifecycle
143143
@StyleRes val themeResId: Int
144144
var theme: String?
145145
val monet = isMonetEnabled
146-
when (getSharedPreferences("mmm")!!.getString("pref_theme", "system").also { theme = it }) {
146+
when (getPreferences("mmm")!!.getString("pref_theme", "system").also { theme = it }) {
147147
"system" -> themeResId =
148148
if (monet) R.style.Theme_MagiskModuleManager_Monet else R.style.Theme_MagiskModuleManager
149149

@@ -327,9 +327,9 @@ class MainApplication : Application(), Configuration.Provider, ActivityLifecycle
327327
o = listOf(*osh).contains(oosh)
328328
} catch (ignored: PackageManager.NameNotFoundException) {
329329
}
330-
val sharedPreferences = getSharedPreferences("mmm")
330+
val sharedPreferences = getPreferences("mmm")
331331
// We are only one process so it's ok to do this
332-
val bootPrefs = getSharedPreferences("mmm_boot")
332+
val bootPrefs = getPreferences("mmm_boot")
333333
val lastBoot = System.currentTimeMillis() - SystemClock.elapsedRealtime()
334334
val lastBootPrefs = bootPrefs!!.getLong("last_boot", 0)
335335
isFirstBoot = if (lastBootPrefs == 0L || abs(lastBoot - lastBootPrefs) > 100) {
@@ -499,7 +499,7 @@ class MainApplication : Application(), Configuration.Provider, ActivityLifecycle
499499
companion object {
500500

501501
var forceDebugLogging: Boolean =
502-
BuildConfig.DEBUG || getSharedPreferences("mmm")?.getBoolean(
502+
BuildConfig.DEBUG || getPreferences("mmm")?.getBoolean(
503503
"pref_force_debug_logging",
504504
false
505505
) ?: false
@@ -577,18 +577,18 @@ class MainApplication : Application(), Configuration.Provider, ActivityLifecycle
577577
}
578578

579579
@Suppress("NAME_SHADOWING")
580-
fun getSharedPreferences(name: String): SharedPreferences? {
580+
fun getPreferences(name: String): SharedPreferences? {
581581
// encryptedSharedPreferences is used
582+
return try {
582583
var name = name
583-
val mContext: Context? = INSTANCE
584+
val mContext: Context? = INSTANCE!!.applicationContext
584585
name += "x"
585586
if (mSharedPrefs == null) {
586587
mSharedPrefs = HashMap()
587588
}
588589
if (mSharedPrefs!!.containsKey(name)) {
589590
return mSharedPrefs!![name] as SharedPreferences?
590591
}
591-
return try {
592592
val masterKey =
593593
MasterKey.Builder(mContext!!).setKeyScheme(MasterKey.KeyScheme.AES256_GCM)
594594
.build()
@@ -604,31 +604,33 @@ class MainApplication : Application(), Configuration.Provider, ActivityLifecycle
604604
} catch (e: Exception) {
605605
// try again five times, with a 250ms delay between each try. if we still can't get the shared preferences, throw an exception
606606
var i = 0
607+
var s = false
607608
while (i < 5) {
608609
try {
609610
Thread.sleep(250)
610611
} catch (ignored: InterruptedException) {
611612
}
612613
try {
613614
val masterKey =
614-
MasterKey.Builder(mContext!!)
615+
MasterKey.Builder(INSTANCE!!.applicationContext)
615616
.setKeyScheme(MasterKey.KeyScheme.AES256_GCM)
616617
.build()
617618
val sharedPreferences = EncryptedSharedPreferences.create(
618-
mContext,
619+
INSTANCE!!.applicationContext,
619620
name,
620621
masterKey,
621622
EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
622623
EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM
623624
)
624625
mSharedPrefs!![name] = sharedPreferences
626+
s = true
625627
return sharedPreferences
626628
} catch (e: Exception) {
627629
Timber.e(e, "Failed to get shared preferences")
628630
}
629631
i++
630632
}
631-
throw IllegalStateException("Failed to get shared preferences")
633+
return null
632634
}
633635
}
634636

@@ -648,42 +650,42 @@ class MainApplication : Application(), Configuration.Provider, ActivityLifecycle
648650
return java.lang.Boolean.parseBoolean(SHOWCASE_MODE_TRUE)
649651
}
650652
val showcaseMode =
651-
getSharedPreferences("mmm")!!.getBoolean("pref_showcase_mode", false)
653+
getPreferences("mmm")!!.getBoolean("pref_showcase_mode", false)
652654
SHOWCASE_MODE_TRUE = showcaseMode.toString()
653655
return showcaseMode
654656
}
655657

656658
fun shouldPreventReboot(): Boolean {
657-
return getSharedPreferences("mmm")!!.getBoolean("pref_prevent_reboot", true)
659+
return getPreferences("mmm")!!.getBoolean("pref_prevent_reboot", true)
658660
}
659661

660662
val isShowIncompatibleModules: Boolean
661-
get() = getSharedPreferences("mmm")!!.getBoolean("pref_show_incompatible", false)
663+
get() = getPreferences("mmm")!!.getBoolean("pref_show_incompatible", false)
662664
val isForceDarkTerminal: Boolean
663-
get() = getSharedPreferences("mmm")!!.getBoolean("pref_force_dark_terminal", false)
665+
get() = getPreferences("mmm")!!.getBoolean("pref_force_dark_terminal", false)
664666
val isTextWrapEnabled: Boolean
665-
get() = getSharedPreferences("mmm")!!.getBoolean("pref_wrap_text", false)
667+
get() = getPreferences("mmm")!!.getBoolean("pref_wrap_text", false)
666668
val isDohEnabled: Boolean
667-
get() = getSharedPreferences("mmm")!!.getBoolean("pref_dns_over_https", true)
669+
get() = getPreferences("mmm")!!.getBoolean("pref_dns_over_https", true)
668670
val isMonetEnabled: Boolean
669-
get() = Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && getSharedPreferences("mmm")!!.getBoolean(
671+
get() = Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && getPreferences("mmm")!!.getBoolean(
670672
"pref_enable_monet", true
671673
)
672674
val isBlurEnabled: Boolean
673-
get() = getSharedPreferences("mmm")!!.getBoolean("pref_enable_blur", false)
675+
get() = getPreferences("mmm")!!.getBoolean("pref_enable_blur", false)
674676

675677
val isDeveloper: Boolean
676678
get() {
677-
return if (BuildConfig.DEBUG) true else getSharedPreferences("mmm")!!.getBoolean(
679+
return if (BuildConfig.DEBUG) true else getPreferences("mmm")!!.getBoolean(
678680
"developer", false
679681
)
680682
}
681683
val isDisableLowQualityModuleFilter: Boolean
682-
get() = getSharedPreferences("mmm")!!.getBoolean(
684+
get() = getPreferences("mmm")!!.getBoolean(
683685
"pref_disable_low_quality_module_filter", false
684686
) && isDeveloper
685687
val isUsingMagiskCommand: Boolean
686-
get() = (peekMagiskVersion() >= Constants.MAGISK_VER_CODE_INSTALL_COMMAND) && getSharedPreferences(
688+
get() = (peekMagiskVersion() >= Constants.MAGISK_VER_CODE_INSTALL_COMMAND) && getPreferences(
687689
"mmm"
688690
)!!.getBoolean(
689691
"pref_use_magisk_install_command",
@@ -696,27 +698,27 @@ class MainApplication : Application(), Configuration.Provider, ActivityLifecycle
696698
return java.lang.Boolean.parseBoolean(updateCheckBg)
697699
}
698700
val wrapped = isWrapped
699-
val updateCheckBgTemp = !wrapped && getSharedPreferences("mmm")!!.getBoolean(
701+
val updateCheckBgTemp = !wrapped && getPreferences("mmm")!!.getBoolean(
700702
"pref_background_update_check", true
701703
)
702704
updateCheckBg = updateCheckBgTemp.toString()
703705
return java.lang.Boolean.parseBoolean(updateCheckBg)
704706
}
705707
val isAndroidacyTestMode: Boolean
706-
get() = isDeveloper && getSharedPreferences("mmm")!!.getBoolean(
708+
get() = isDeveloper && getPreferences("mmm")!!.getBoolean(
707709
"pref_androidacy_test_mode", false
708710
)
709711

710712
fun setHasGottenRootAccess(bool: Boolean) {
711-
getSharedPreferences("mmm")!!.edit().putBoolean("has_root_access", bool).apply()
713+
getPreferences("mmm")!!.edit().putBoolean("has_root_access", bool).apply()
712714
}
713715

714716
val isCrashReportingEnabled: Boolean
715-
get() = getSharedPreferences("mmm")!!.getBoolean(
717+
get() = getPreferences("mmm")!!.getBoolean(
716718
"pref_crash_reporting", BuildConfig.DEFAULT_ENABLE_CRASH_REPORTING
717719
)
718720
val bootSharedPreferences: SharedPreferences?
719-
get() = getSharedPreferences("mmm_boot")
721+
get() = getPreferences("mmm_boot")
720722

721723
fun formatTime(timeStamp: Long): String {
722724
// new Date(x) also get the local timestamp for format
@@ -727,15 +729,15 @@ class MainApplication : Application(), Configuration.Provider, ActivityLifecycle
727729
get() = NotificationManagerCompat.from((INSTANCE)!!).areNotificationsEnabled()
728730

729731
fun analyticsAllowed(): Boolean {
730-
return getSharedPreferences("mmm")!!.getBoolean(
732+
return getPreferences("mmm")!!.getBoolean(
731733
"pref_analytics_enabled", BuildConfig.DEFAULT_ENABLE_ANALYTICS
732734
)
733735
}
734736

735737
fun shouldShowFeedback(): Boolean {
736738
// should not have been shown in 14 days and only 1 in 5 chance
737739
val randChance = Random().nextInt(5)
738-
val lastShown = getSharedPreferences("mmm")!!.getLong("last_feedback", 0)
740+
val lastShown = getPreferences("mmm")!!.getLong("last_feedback", 0)
739741
if (forceDebugLogging) Timber.d(
740742
"Last feedback shown: %d, randChance: %d",
741743
lastShown,

app/src/main/kotlin/com/fox2code/mmm/NotificationType.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ enum class NotificationType(
192192
androidx.appcompat.R.attr.colorBackgroundFloating,
193193
com.google.android.material.R.attr.colorOnBackground,
194194
View.OnClickListener { v: View? ->
195-
if (MainApplication.getSharedPreferences("mmm")
195+
if (MainApplication.getPreferences("mmm")
196196
?.getBoolean("pref_require_security", false) == true
197197
) {
198198
// block local install for safety

app/src/main/kotlin/com/fox2code/mmm/SetupActivity.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class SetupActivity : AppCompatActivity(), LanguageActivity {
5555
createFiles()
5656
disableUpdateActivityForFdroidFlavor()
5757
// Set theme
58-
val prefs = MainApplication.getSharedPreferences("mmm")!!
58+
val prefs = MainApplication.getPreferences("mmm")!!
5959
when (prefs.getString("theme", "system")) {
6060
"light" -> setTheme(R.style.Theme_MagiskModuleManager_Monet_Light)
6161
"dark" -> setTheme(R.style.Theme_MagiskModuleManager_Monet_Dark)
@@ -405,7 +405,7 @@ class SetupActivity : AppCompatActivity(), LanguageActivity {
405405
return theme
406406
}
407407
// Set the theme
408-
val prefs = MainApplication.getSharedPreferences("mmm")!!
408+
val prefs = MainApplication.getPreferences("mmm")!!
409409
when (prefs.getString("pref_theme", "system")) {
410410
"light" -> {
411411
theme.applyStyle(R.style.Theme_MagiskModuleManager_Monet_Light, true)

app/src/main/kotlin/com/fox2code/mmm/androidacy/AndroidacyRepoData.kt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import com.fingerprintjs.android.fingerprint.FingerprinterFactory.create
1515
import com.fox2code.mmm.BuildConfig
1616
import com.fox2code.mmm.MainApplication
1717
import com.fox2code.mmm.MainApplication.Companion.INSTANCE
18-
import com.fox2code.mmm.MainApplication.Companion.getSharedPreferences
18+
import com.fox2code.mmm.MainApplication.Companion.getPreferences
1919
import com.fox2code.mmm.R
2020
import com.fox2code.mmm.androidacy.AndroidacyUtil.Companion.hideToken
2121
import com.fox2code.mmm.androidacy.AndroidacyUtil.Companion.isAndroidacyLink
@@ -97,7 +97,7 @@ class AndroidacyRepoData(cacheRoot: File?, testMode: Boolean) : RepoData(
9797
if (e.errorCode == 401) {
9898
Timber.w("Invalid token, resetting...")
9999
// Remove saved preference
100-
val editor = getSharedPreferences("androidacy")!!.edit()
100+
val editor = getPreferences("androidacy")!!.edit()
101101
editor.remove("pref_androidacy_api_token")
102102
editor.apply()
103103
return false
@@ -118,12 +118,12 @@ class AndroidacyRepoData(cacheRoot: File?, testMode: Boolean) : RepoData(
118118
Timber.w("Invalid token, resetting...")
119119
Timber.w(e)
120120
// Remove saved preference
121-
val editor = getSharedPreferences("androidacy")!!.edit()
121+
val editor = getPreferences("androidacy")!!.edit()
122122
editor.remove("pref_androidacy_api_token")
123123
editor.apply()
124124
requestNewToken()
125125
isValidToken(
126-
getSharedPreferences("androidacy")!!.getString(
126+
getPreferences("androidacy")!!.getString(
127127
"pref_androidacy_api_token",
128128
null
129129
))
@@ -152,7 +152,7 @@ class AndroidacyRepoData(cacheRoot: File?, testMode: Boolean) : RepoData(
152152
}
153153
}
154154
// Save the token to the shared preferences
155-
val editor = getSharedPreferences("androidacy")!!.edit()
155+
val editor = getPreferences("androidacy")!!.edit()
156156
editor.putString("pref_androidacy_api_token", token)
157157
editor.apply()
158158
return token
@@ -163,7 +163,7 @@ class AndroidacyRepoData(cacheRoot: File?, testMode: Boolean) : RepoData(
163163
// If ANDROIDACY_CLIENT_ID is not set or is empty, disable this repo and return
164164
@Suppress("KotlinConstantConditions")
165165
if (BuildConfig.ANDROIDACY_CLIENT_ID == "") {
166-
val editor = getSharedPreferences("mmm")!!.edit()
166+
val editor = getPreferences("mmm")!!.edit()
167167
editor.putBoolean("pref_androidacy_repo_enabled", false)
168168
editor.apply()
169169
Timber.w("ANDROIDACY_CLIENT_ID is empty, disabling AndroidacyRepoData 2")
@@ -208,7 +208,7 @@ class AndroidacyRepoData(cacheRoot: File?, testMode: Boolean) : RepoData(
208208
try {
209209
if (token == null) {
210210
token =
211-
getSharedPreferences("androidacy")?.getString("pref_androidacy_api_token", null)
211+
getPreferences("androidacy")?.getString("pref_androidacy_api_token", null)
212212
if (token != null && !isValidToken(token)) {
213213
if (MainApplication.forceDebugLogging) Timber.i("Token expired or invalid, requesting new one...")
214214
token = null
@@ -250,7 +250,7 @@ class AndroidacyRepoData(cacheRoot: File?, testMode: Boolean) : RepoData(
250250
return false
251251
} else {
252252
// Save token to shared preference
253-
val editor = getSharedPreferences("androidacy")!!.edit()
253+
val editor = getPreferences("androidacy")!!.edit()
254254
editor.putString("pref_androidacy_api_token", token)
255255
editor.apply()
256256
if (MainApplication.forceDebugLogging) Timber.i("Token saved to shared preference")
@@ -468,7 +468,7 @@ class AndroidacyRepoData(cacheRoot: File?, testMode: Boolean) : RepoData(
468468
companion object {
469469
private var ANDROIDACY_DEVICE_ID: String? = null
470470
var token =
471-
getSharedPreferences("androidacy")!!.getString("pref_androidacy_api_token", null)
471+
getPreferences("androidacy")!!.getString("pref_androidacy_api_token", null)
472472

473473
init {
474474
@Suppress("LocalVariableName") val OK_HTTP_URL_BUILDER: Builder =
@@ -495,7 +495,7 @@ class AndroidacyRepoData(cacheRoot: File?, testMode: Boolean) : RepoData(
495495
return ANDROIDACY_DEVICE_ID
496496
}
497497
// Try to get the device ID from the shared preferences
498-
val sharedPreferences = getSharedPreferences("androidacy")
498+
val sharedPreferences = getPreferences("androidacy")
499499
val deviceIdPref =
500500
sharedPreferences!!.getString("device_id_v2", null)
501501
return if (deviceIdPref != null) {

0 commit comments

Comments
 (0)