fix: try-catch Context.MODE_WORLD_READABLE if failure of non-hook environment in ModulePreferenceFragment

This commit is contained in:
2024-11-10 21:55:41 +08:00
parent 8b607b2243
commit 7aecf84829

View File

@@ -66,8 +66,10 @@ abstract class ModulePreferenceFragment : PreferenceFragmentCompat(), SharedPref
* 获取应用默认的 [SharedPreferences] * 获取应用默认的 [SharedPreferences]
* @return [SharedPreferences] * @return [SharedPreferences]
*/ */
@Suppress("DEPRECATION", "WorldReadableFiles") private val currentSharedPrefs get() = runCatching {
private val currentSharedPrefs get() = currentActivity.getSharedPreferences(prefsName, Context.MODE_WORLD_READABLE) @Suppress("DEPRECATION", "WorldReadableFiles")
currentActivity.getSharedPreferences(prefsName, Context.MODE_WORLD_READABLE)
}.getOrNull() ?: PreferenceManager.getDefaultSharedPreferences(currentActivity)
@CallSuper @CallSuper
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {