-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Base: Allow default settings to be provided in meta-data
This is useful for apps that include microG as a library, so they can easily modify the default configuration of their embedded microG.
- Loading branch information
Showing
2 changed files
with
54 additions
and
4 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
play-services-base/core/src/main/kotlin/org/microg/gms/settings/MetaDataPreferences.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2023 microG Project Team | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.microg.gms.settings | ||
|
||
import android.content.Context | ||
import android.content.SharedPreferences | ||
import android.content.pm.PackageManager.GET_META_DATA | ||
import android.os.Bundle | ||
|
||
class MetaDataPreferences(private val context: Context, private val prefix: String = "") : SharedPreferences { | ||
private val metaData by lazy { | ||
runCatching { context.packageManager.getApplicationInfo(context.packageName, GET_META_DATA) }.getOrNull()?.metaData ?: Bundle.EMPTY | ||
} | ||
|
||
override fun getAll(): Map<String, *> = metaData.keySet().filter { it.startsWith(prefix) }.associate { it.substring(prefix.length) to metaData.get(it) } | ||
|
||
override fun getString(key: String, defValue: String?): String? = metaData.getString(prefix + key, defValue) | ||
|
||
override fun getStringSet(key: String, defValues: Set<String>?): Set<String>? = metaData.getStringArray(prefix + key)?.toSet() ?: defValues | ||
|
||
override fun getInt(key: String?, defValue: Int): Int = metaData.getInt(prefix + key, defValue) | ||
|
||
override fun getLong(key: String?, defValue: Long): Long = metaData.getLong(prefix + key, defValue) | ||
|
||
override fun getFloat(key: String?, defValue: Float): Float = metaData.getFloat(prefix + key, defValue) | ||
|
||
override fun getBoolean(key: String?, defValue: Boolean): Boolean = metaData.getBoolean(prefix + key, defValue) | ||
|
||
override fun contains(key: String?): Boolean = metaData.containsKey(prefix + key) | ||
|
||
override fun edit(): SharedPreferences.Editor { | ||
throw UnsupportedOperationException() | ||
} | ||
|
||
override fun registerOnSharedPreferenceChangeListener(listener: SharedPreferences.OnSharedPreferenceChangeListener?) { | ||
throw UnsupportedOperationException() | ||
} | ||
|
||
override fun unregisterOnSharedPreferenceChangeListener(listener: SharedPreferences.OnSharedPreferenceChangeListener?) { | ||
throw UnsupportedOperationException() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters