Support old configuration and system defaults
This commit is contained in:
parent
4e3a6dac96
commit
3d5fc38ac1
|
@ -19,8 +19,7 @@
|
||||||
<service
|
<service
|
||||||
android:name=".GeocodeService"
|
android:name=".GeocodeService"
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
android:permission="android.permission.INTERNET"
|
android:permission="android.permission.INTERNET">
|
||||||
android:process=":geocservice">
|
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="com.android.location.service.GeocodeProvider" />
|
<action android:name="com.android.location.service.GeocodeProvider" />
|
||||||
<action android:name="com.google.android.location.GeocodeProvider" />
|
<action android:name="com.google.android.location.GeocodeProvider" />
|
||||||
|
|
|
@ -22,7 +22,6 @@
|
||||||
<service
|
<service
|
||||||
android:name=".LocationService"
|
android:name=".LocationService"
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
android:process=":locservice"
|
|
||||||
android:permission="android.permission.ACCESS_COARSE_LOCATION">
|
android:permission="android.permission.ACCESS_COARSE_LOCATION">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="com.android.location.service.v2.NetworkLocationProvider" />
|
<action android:name="com.android.location.service.v2.NetworkLocationProvider" />
|
||||||
|
|
|
@ -21,7 +21,6 @@
|
||||||
<service
|
<service
|
||||||
android:name=".LocationService"
|
android:name=".LocationService"
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
android:process=":locservice"
|
|
||||||
android:permission="android.permission.ACCESS_COARSE_LOCATION">
|
android:permission="android.permission.ACCESS_COARSE_LOCATION">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="com.android.location.service.v3.NetworkLocationProvider" />
|
<action android:name="com.android.location.service.v3.NetworkLocationProvider" />
|
||||||
|
|
|
@ -19,7 +19,6 @@
|
||||||
<service
|
<service
|
||||||
android:name=".UnifiedLocationServiceEntryPoint"
|
android:name=".UnifiedLocationServiceEntryPoint"
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
android:process=":ulocservice"
|
|
||||||
tools:ignore="ExportedService">
|
tools:ignore="ExportedService">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="org.microg.nlp.service.UnifiedLocationService" />
|
<action android:name="org.microg.nlp.service.UnifiedLocationService" />
|
||||||
|
|
|
@ -8,13 +8,24 @@ package org.microg.nlp.service
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
|
||||||
class Preferences(private val context: Context) {
|
class Preferences(private val context: Context) {
|
||||||
|
|
||||||
private val sharedPreferences: SharedPreferences
|
private val preferences: SharedPreferences
|
||||||
get() = context.getSharedPreferences(PREFERENCES_NAME, Context.MODE_PRIVATE)
|
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<String>? = null): Set<String>? {
|
private fun SharedPreferences.getStringSetCompat(key: String, defValues: Set<String>? = null): Set<String>? {
|
||||||
if (Build.VERSION.SDK_INT >= 11) {
|
if (Build.VERSION.SDK_INT >= 11) {
|
||||||
try {
|
try {
|
||||||
|
@ -41,18 +52,24 @@ class Preferences(private val context: Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getStringSetFromAny(key: String): Set<String>? {
|
||||||
|
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<String>
|
var locationBackends: Set<String>
|
||||||
get() =
|
get() = getStringSetFromAny(PREF_LOCATION_BACKENDS) ?: emptySet()
|
||||||
sharedPreferences.getStringSetCompat(PREF_LOCATION_BACKENDS) ?: emptySet()
|
|
||||||
set(backends) {
|
set(backends) {
|
||||||
sharedPreferences.edit().putStringSetCompat(PREF_LOCATION_BACKENDS, backends).apply()
|
preferences.edit().putStringSetCompat(PREF_LOCATION_BACKENDS, backends).apply()
|
||||||
}
|
}
|
||||||
|
|
||||||
var geocoderBackends: Set<String>
|
var geocoderBackends: Set<String>
|
||||||
get() =
|
get() = getStringSetFromAny(PREF_GEOCODER_BACKENDS) ?: emptySet()
|
||||||
sharedPreferences.getStringSetCompat(PREF_GEOCODER_BACKENDS) ?: emptySet()
|
|
||||||
set(backends) {
|
set(backends) {
|
||||||
sharedPreferences.edit().putStringSetCompat(PREF_GEOCODER_BACKENDS, backends).apply()
|
preferences.edit().putStringSetCompat(PREF_GEOCODER_BACKENDS, backends).apply()
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
Loading…
Reference in a new issue