@@ -10,22 +10,14 @@ import moe.lyniko.hiderecent.R
1010class PreferenceUtils ( // init context on constructor
1111 context : Context
1212) {
13- // ------ 1. get several SharedPreferences (funcPref is the only accessible during Xposed inject) ------
14- private var funcPref: SharedPreferences = try {
15- @Suppress(" DEPRECATION" )
16- context.getSharedPreferences(functionalConfigName, Context .MODE_WORLD_READABLE )
17- } catch (e: SecurityException ) {
18- throw e
19- // Log.w("PreferenceUtil", "Fallback to Private SharedPref for error!!!: ${e.message}")
20- // context.getSharedPreferences(functionalConfigName, Context.MODE_PRIVATE)
21- }
13+ // ------ 1. get several SharedPreferences ------
14+ // Vector/LSPosed hooks checkMode to allow MODE_WORLD_READABLE when the module
15+ // is in its own scope. Fall back to MODE_PRIVATE if the hook isn't active.
16+ private var funcPref: SharedPreferences = openWorldReadable(context, functionalConfigName)
2217
23- @Suppress(" DEPRECATION" )
24- var managerPref: SharedPreferences =
25- context.getSharedPreferences(managerConfigName, Context .MODE_WORLD_READABLE )
18+ var managerPref: SharedPreferences = openWorldReadable(context, managerConfigName)
2619
27- @Suppress(" DEPRECATION" )
28- private val legacyFuncPref = context.getSharedPreferences(legacyConfigName, Context .MODE_WORLD_READABLE )
20+ private val legacyFuncPref = openWorldReadable(context, legacyConfigName)
2921
3022 // ------ 2. init packages ------
3123 private fun initPackageFromLegacyAndNew (funcPref : SharedPreferences , legacyPref : SharedPreferences ) {
@@ -58,6 +50,15 @@ class PreferenceUtils( // init context on constructor
5850 instance ? : PreferenceUtils (context).also { instance = it }
5951 }
6052
53+ @Suppress(" DEPRECATION" )
54+ private fun openWorldReadable (context : Context , name : String ): SharedPreferences {
55+ return try {
56+ context.getSharedPreferences(name, Context .MODE_WORLD_READABLE )
57+ } catch (_: SecurityException ) {
58+ context.getSharedPreferences(name, Context .MODE_PRIVATE )
59+ }
60+ }
61+
6162 private const val packagesTag = " packages"
6263 const val functionalConfigName = " functional_config"
6364 const val managerConfigName = " manager_config"
0 commit comments