diff --git a/geocode-v1/src/main/AndroidManifest.xml b/geocode-v1/src/main/AndroidManifest.xml index 04b94e2..828ac60 100644 --- a/geocode-v1/src/main/AndroidManifest.xml +++ b/geocode-v1/src/main/AndroidManifest.xml @@ -19,8 +19,7 @@ + android:permission="android.permission.INTERNET"> diff --git a/location-v2/src/main/AndroidManifest.xml b/location-v2/src/main/AndroidManifest.xml index 1ba4554..05cafe3 100644 --- a/location-v2/src/main/AndroidManifest.xml +++ b/location-v2/src/main/AndroidManifest.xml @@ -22,7 +22,6 @@ diff --git a/location-v3/src/main/AndroidManifest.xml b/location-v3/src/main/AndroidManifest.xml index 9a1a197..c4cc9d1 100644 --- a/location-v3/src/main/AndroidManifest.xml +++ b/location-v3/src/main/AndroidManifest.xml @@ -21,7 +21,6 @@ diff --git a/service/src/main/AndroidManifest.xml b/service/src/main/AndroidManifest.xml index be6ed2a..8ebf360 100644 --- a/service/src/main/AndroidManifest.xml +++ b/service/src/main/AndroidManifest.xml @@ -19,7 +19,6 @@ diff --git a/service/src/main/kotlin/org/microg/nlp/service/Preferences.kt b/service/src/main/kotlin/org/microg/nlp/service/Preferences.kt index 777f1b5..9217220 100644 --- a/service/src/main/kotlin/org/microg/nlp/service/Preferences.kt +++ b/service/src/main/kotlin/org/microg/nlp/service/Preferences.kt @@ -8,13 +8,24 @@ package org.microg.nlp.service import android.content.Context import android.content.SharedPreferences import android.os.Build +import java.io.File class Preferences(private val context: Context) { - private val sharedPreferences: SharedPreferences + private val preferences: SharedPreferences get() = context.getSharedPreferences(PREFERENCES_NAME, Context.MODE_PRIVATE) + private val oldPreferences: SharedPreferences + get() = context.getSharedPreferences(context.packageName + "_preferences", Context.MODE_PRIVATE) + + private val systemDefaultPreferences: SharedPreferences? + get() = try { + Context::class.java.getDeclaredMethod("getSharedPreferences", File::class.java, Int::class.javaPrimitiveType).invoke(context, File("/system/etc/microg.xml"), Context.MODE_PRIVATE) as SharedPreferences + } catch (e: java.lang.Exception) { + null + } + private fun SharedPreferences.getStringSetCompat(key: String, defValues: Set? = null): Set? { if (Build.VERSION.SDK_INT >= 11) { try { @@ -41,18 +52,24 @@ class Preferences(private val context: Context) { } } + private fun getStringSetFromAny(key: String): Set? { + val fromNewSettings = preferences.getStringSetCompat(key) + if (fromNewSettings != null) return fromNewSettings + val fromOldSettings = oldPreferences.getStringSetCompat(key) + if (fromOldSettings != null) return fromOldSettings + return systemDefaultPreferences?.getStringSetCompat(key) + } + var locationBackends: Set - get() = - sharedPreferences.getStringSetCompat(PREF_LOCATION_BACKENDS) ?: emptySet() + get() = getStringSetFromAny(PREF_LOCATION_BACKENDS) ?: emptySet() set(backends) { - sharedPreferences.edit().putStringSetCompat(PREF_LOCATION_BACKENDS, backends).apply() + preferences.edit().putStringSetCompat(PREF_LOCATION_BACKENDS, backends).apply() } var geocoderBackends: Set - get() = - sharedPreferences.getStringSetCompat(PREF_GEOCODER_BACKENDS) ?: emptySet() + get() = getStringSetFromAny(PREF_GEOCODER_BACKENDS) ?: emptySet() set(backends) { - sharedPreferences.edit().putStringSetCompat(PREF_GEOCODER_BACKENDS, backends).apply() + preferences.edit().putStringSetCompat(PREF_GEOCODER_BACKENDS, backends).apply() } companion object {