From 04b4b48077571ee6395b4948a6ed38a53c0bcaf2 Mon Sep 17 00:00:00 2001 From: Ayaan Zaidi Date: Sun, 8 Mar 2026 16:20:52 +0530 Subject: [PATCH] fix(android): persist legacy location mode migration --- .../main/java/ai/openclaw/app/SecurePrefs.kt | 15 +++++++++--- .../java/ai/openclaw/app/SecurePrefsTest.kt | 23 +++++++++++++++++++ 2 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 apps/android/app/src/test/java/ai/openclaw/app/SecurePrefsTest.kt diff --git a/apps/android/app/src/main/java/ai/openclaw/app/SecurePrefs.kt b/apps/android/app/src/main/java/ai/openclaw/app/SecurePrefs.kt index cc996cf65d8..b7e72ee4126 100644 --- a/apps/android/app/src/main/java/ai/openclaw/app/SecurePrefs.kt +++ b/apps/android/app/src/main/java/ai/openclaw/app/SecurePrefs.kt @@ -19,6 +19,7 @@ class SecurePrefs(context: Context) { companion object { val defaultWakeWords: List = listOf("openclaw", "claude") private const val displayNameKey = "node.displayName" + private const val locationModeKey = "location.enabledMode" private const val voiceWakeModeKey = "voiceWake.mode" private const val plainPrefsName = "openclaw.node" private const val securePrefsName = "openclaw.node.secure" @@ -46,8 +47,7 @@ class SecurePrefs(context: Context) { private val _cameraEnabled = MutableStateFlow(plainPrefs.getBoolean("camera.enabled", true)) val cameraEnabled: StateFlow = _cameraEnabled - private val _locationMode = - MutableStateFlow(LocationMode.fromRawValue(plainPrefs.getString("location.enabledMode", "off"))) + private val _locationMode = MutableStateFlow(loadLocationMode()) val locationMode: StateFlow = _locationMode private val _locationPreciseEnabled = @@ -120,7 +120,7 @@ class SecurePrefs(context: Context) { } fun setLocationMode(mode: LocationMode) { - plainPrefs.edit { putString("location.enabledMode", mode.rawValue) } + plainPrefs.edit { putString(locationModeKey, mode.rawValue) } _locationMode.value = mode } @@ -290,6 +290,15 @@ class SecurePrefs(context: Context) { return resolved } + private fun loadLocationMode(): LocationMode { + val raw = plainPrefs.getString(locationModeKey, "off") + val resolved = LocationMode.fromRawValue(raw) + if (raw?.trim()?.lowercase() == "always") { + plainPrefs.edit { putString(locationModeKey, resolved.rawValue) } + } + return resolved + } + private fun loadWakeWords(): List { val raw = plainPrefs.getString("voiceWake.triggerWords", null)?.trim() if (raw.isNullOrEmpty()) return defaultWakeWords diff --git a/apps/android/app/src/test/java/ai/openclaw/app/SecurePrefsTest.kt b/apps/android/app/src/test/java/ai/openclaw/app/SecurePrefsTest.kt new file mode 100644 index 00000000000..cd72bf75dff --- /dev/null +++ b/apps/android/app/src/test/java/ai/openclaw/app/SecurePrefsTest.kt @@ -0,0 +1,23 @@ +package ai.openclaw.app + +import android.content.Context +import org.junit.Assert.assertEquals +import org.junit.Test +import org.junit.runner.RunWith +import org.robolectric.RobolectricTestRunner +import org.robolectric.RuntimeEnvironment + +@RunWith(RobolectricTestRunner::class) +class SecurePrefsTest { + @Test + fun loadLocationMode_migratesLegacyAlwaysValue() { + val context = RuntimeEnvironment.getApplication() + val plainPrefs = context.getSharedPreferences("openclaw.node", Context.MODE_PRIVATE) + plainPrefs.edit().clear().putString("location.enabledMode", "always").commit() + + val prefs = SecurePrefs(context) + + assertEquals(LocationMode.WhileUsing, prefs.locationMode.value) + assertEquals("whileUsing", plainPrefs.getString("location.enabledMode", null)) + } +}