Skip to content

Commit e13738e

Browse files
fix(settings): prevent new-app default mode from resetting to Normal after restart
When native getNewAppProfileMode() returns 0 (which happens both when the mode is actually Normal and when the kernel storage read fails), loadNewAppProfileMode() was unconditionally treating native as authoritative and overwriting SharedPreferences with 0. This caused the Exclude/Root setting to be lost on app restart for many users. Now the function only trusts native for non-zero values. If native returns 0 but SharedPreferences has a saved preference, it restores the native state from SharedPreferences instead.
1 parent c83e9f3 commit e13738e

1 file changed

Lines changed: 17 additions & 5 deletions

File tree

app/src/main/java/me/bmax/apatch/ui/screen/settings/GeneralSettings.kt

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -805,16 +805,28 @@ fun NewAppProfileModeDialog(
805805
}
806806

807807
private suspend fun loadNewAppProfileMode(prefs: SharedPreferences): Int = withContext(Dispatchers.IO) {
808-
val fallback = runCatching {
808+
val prefsValue = runCatching {
809809
prefs.getInt(APApplication.PREF_AUTO_EXCLUDE_NEW_APPS, 0)
810810
}.getOrDefault(0)
811811
val nativeMode = runCatching {
812812
Natives.getNewAppProfileMode()
813-
}.getOrDefault(fallback)
814-
if (nativeMode != fallback) {
815-
prefs.edit { putInt(APApplication.PREF_AUTO_EXCLUDE_NEW_APPS, nativeMode) }
813+
}.getOrDefault(prefsValue)
814+
when {
815+
// Native has an explicit non-zero value — trust it as authoritative
816+
nativeMode != 0 -> {
817+
if (nativeMode != prefsValue) {
818+
prefs.edit { putInt(APApplication.PREF_AUTO_EXCLUDE_NEW_APPS, nativeMode) }
819+
}
820+
nativeMode
821+
}
822+
// Native returned 0 (default or read failure), but prefs has a saved preference — restore native
823+
prefsValue != 0 -> {
824+
runCatching { Natives.setNewAppProfileMode(prefsValue) }
825+
prefsValue
826+
}
827+
// Both are 0 — true default
828+
else -> 0
816829
}
817-
nativeMode
818830
}
819831

820832
@OptIn(ExperimentalMaterial3Api::class)

0 commit comments

Comments
 (0)