Loading play-services-base/core/src/main/AndroidManifest.xml +8 −1 Original line number Diff line number Diff line Loading @@ -5,10 +5,17 @@ --> <manifest xmlns:android="http://schemas.android.com/apk/res/android"> <permission android:name="org.microg.gms.permission.READ_SETTINGS" android:protectionLevel="signature" /> <permission android:name="org.microg.gms.permission.WRITE_SETTINGS" android:protectionLevel="signature" /> <application> <provider android:name="org.microg.gms.settings.SettingsProvider" android:authorities="${applicationId}.microg.settings" android:exported="false" /> android:exported="true" android:readPermission="org.microg.gms.permission.READ_SETTINGS" android:writePermission="org.microg.gms.permission.WRITE_SETTINGS" /> </application> </manifest> play-services-base/core/src/main/kotlin/org/microg/gms/settings/SettingsContract.kt +12 −0 Original line number Diff line number Diff line Loading @@ -171,6 +171,18 @@ object SettingsContract { ) } object Play { private const val id = "play" fun getContentUri(context: Context) = Uri.withAppendedPath(getAuthorityUri(context), id) fun getContentType(context: Context) = "vnd.android.cursor.item/vnd.${getAuthority(context)}.$id" const val LICENSING = "play_licensing" val PROJECTION = arrayOf( LICENSING ) } private fun <T> withoutCallingIdentity(f: () -> T): T { val identity = Binder.clearCallingIdentity() try { Loading play-services-base/core/src/main/kotlin/org/microg/gms/settings/SettingsProvider.kt +22 −0 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ import org.microg.gms.settings.SettingsContract.DroidGuard import org.microg.gms.settings.SettingsContract.Exposure import org.microg.gms.settings.SettingsContract.Gcm import org.microg.gms.settings.SettingsContract.Location import org.microg.gms.settings.SettingsContract.Play import org.microg.gms.settings.SettingsContract.Profile import org.microg.gms.settings.SettingsContract.SafetyNet import org.microg.gms.settings.SettingsContract.getAuthority Loading Loading @@ -78,6 +79,7 @@ class SettingsProvider : ContentProvider() { DroidGuard.getContentUri(context!!) -> queryDroidGuard(projection ?: DroidGuard.PROJECTION) Profile.getContentUri(context!!) -> queryProfile(projection ?: Profile.PROJECTION) Location.getContentUri(context!!) -> queryLocation(projection ?: Location.PROJECTION) Play.getContentUri(context!!) -> queryPlay(projection ?: Play.PROJECTION) else -> null } Loading @@ -98,6 +100,7 @@ class SettingsProvider : ContentProvider() { DroidGuard.getContentUri(context!!) -> updateDroidGuard(values) Profile.getContentUri(context!!) -> updateProfile(values) Location.getContentUri(context!!) -> updateLocation(values) Play.getContentUri(context!!) -> updatePlay(values) else -> return 0 } return 1 Loading Loading @@ -335,6 +338,25 @@ class SettingsProvider : ContentProvider() { editor.apply() } private fun queryPlay(p: Array<out String>): Cursor = MatrixCursor(p).addRow(p) { key -> when (key) { Play.LICENSING -> getSettingsBoolean(key, false) else -> throw IllegalArgumentException("Unknown key: $key") } } private fun updatePlay(values: ContentValues) { if (values.size() == 0) return val editor = preferences.edit() values.valueSet().forEach { (key, value) -> when (key) { Play.LICENSING -> editor.putBoolean(key, value as Boolean) else -> throw IllegalArgumentException("Unknown key: $key") } } editor.apply() } private fun MatrixCursor.addRow( p: Array<out String>, valueGetter: (String) -> Any? Loading play-services-core/src/main/kotlin/org/microg/gms/play/PlayPreferences.kt 0 → 100644 +21 −0 Original line number Diff line number Diff line package org.microg.gms.play import android.content.Context import org.microg.gms.settings.SettingsContract object PlayPreferences { @JvmStatic fun isLicensingEnabled(context: Context): Boolean { val projection = arrayOf(SettingsContract.Play.LICENSING) return SettingsContract.getSettings(context, SettingsContract.Play.getContentUri(context), projection) { c -> c.getInt(0) != 0 } } @JvmStatic fun setLicensingEnabled(context: Context, enabled: Boolean) { SettingsContract.setSettings(context, SettingsContract.Play.getContentUri(context)) { put(SettingsContract.Play.LICENSING, enabled) } } } No newline at end of file play-services-core/src/main/kotlin/org/microg/gms/ui/PlayFragment.kt 0 → 100644 +49 −0 Original line number Diff line number Diff line package org.microg.gms.ui import android.annotation.SuppressLint import android.os.Bundle import androidx.lifecycle.lifecycleScope import androidx.preference.Preference import androidx.preference.PreferenceFragmentCompat import androidx.preference.TwoStatePreference import com.google.android.gms.R import org.microg.gms.play.PlayPreferences class PlayFragment : PreferenceFragmentCompat() { private lateinit var licensingEnabled: TwoStatePreference override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { addPreferencesFromResource(R.xml.preferences_play) } @SuppressLint("RestrictedApi") override fun onBindPreferences() { licensingEnabled = preferenceScreen.findPreference(PREF_LICENSING_ENABLED) ?: licensingEnabled licensingEnabled.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, newValue -> val appContext = requireContext().applicationContext lifecycleScope.launchWhenResumed { if (newValue is Boolean) { PlayPreferences.setLicensingEnabled(appContext, newValue) } updateContent() } true } } override fun onResume() { super.onResume() updateContent() } private fun updateContent() { val appContext = requireContext().applicationContext lifecycleScope.launchWhenResumed { licensingEnabled.isChecked = PlayPreferences.isLicensingEnabled(appContext) } } companion object { const val PREF_LICENSING_ENABLED = "play_licensing" } } No newline at end of file Loading
play-services-base/core/src/main/AndroidManifest.xml +8 −1 Original line number Diff line number Diff line Loading @@ -5,10 +5,17 @@ --> <manifest xmlns:android="http://schemas.android.com/apk/res/android"> <permission android:name="org.microg.gms.permission.READ_SETTINGS" android:protectionLevel="signature" /> <permission android:name="org.microg.gms.permission.WRITE_SETTINGS" android:protectionLevel="signature" /> <application> <provider android:name="org.microg.gms.settings.SettingsProvider" android:authorities="${applicationId}.microg.settings" android:exported="false" /> android:exported="true" android:readPermission="org.microg.gms.permission.READ_SETTINGS" android:writePermission="org.microg.gms.permission.WRITE_SETTINGS" /> </application> </manifest>
play-services-base/core/src/main/kotlin/org/microg/gms/settings/SettingsContract.kt +12 −0 Original line number Diff line number Diff line Loading @@ -171,6 +171,18 @@ object SettingsContract { ) } object Play { private const val id = "play" fun getContentUri(context: Context) = Uri.withAppendedPath(getAuthorityUri(context), id) fun getContentType(context: Context) = "vnd.android.cursor.item/vnd.${getAuthority(context)}.$id" const val LICENSING = "play_licensing" val PROJECTION = arrayOf( LICENSING ) } private fun <T> withoutCallingIdentity(f: () -> T): T { val identity = Binder.clearCallingIdentity() try { Loading
play-services-base/core/src/main/kotlin/org/microg/gms/settings/SettingsProvider.kt +22 −0 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ import org.microg.gms.settings.SettingsContract.DroidGuard import org.microg.gms.settings.SettingsContract.Exposure import org.microg.gms.settings.SettingsContract.Gcm import org.microg.gms.settings.SettingsContract.Location import org.microg.gms.settings.SettingsContract.Play import org.microg.gms.settings.SettingsContract.Profile import org.microg.gms.settings.SettingsContract.SafetyNet import org.microg.gms.settings.SettingsContract.getAuthority Loading Loading @@ -78,6 +79,7 @@ class SettingsProvider : ContentProvider() { DroidGuard.getContentUri(context!!) -> queryDroidGuard(projection ?: DroidGuard.PROJECTION) Profile.getContentUri(context!!) -> queryProfile(projection ?: Profile.PROJECTION) Location.getContentUri(context!!) -> queryLocation(projection ?: Location.PROJECTION) Play.getContentUri(context!!) -> queryPlay(projection ?: Play.PROJECTION) else -> null } Loading @@ -98,6 +100,7 @@ class SettingsProvider : ContentProvider() { DroidGuard.getContentUri(context!!) -> updateDroidGuard(values) Profile.getContentUri(context!!) -> updateProfile(values) Location.getContentUri(context!!) -> updateLocation(values) Play.getContentUri(context!!) -> updatePlay(values) else -> return 0 } return 1 Loading Loading @@ -335,6 +338,25 @@ class SettingsProvider : ContentProvider() { editor.apply() } private fun queryPlay(p: Array<out String>): Cursor = MatrixCursor(p).addRow(p) { key -> when (key) { Play.LICENSING -> getSettingsBoolean(key, false) else -> throw IllegalArgumentException("Unknown key: $key") } } private fun updatePlay(values: ContentValues) { if (values.size() == 0) return val editor = preferences.edit() values.valueSet().forEach { (key, value) -> when (key) { Play.LICENSING -> editor.putBoolean(key, value as Boolean) else -> throw IllegalArgumentException("Unknown key: $key") } } editor.apply() } private fun MatrixCursor.addRow( p: Array<out String>, valueGetter: (String) -> Any? Loading
play-services-core/src/main/kotlin/org/microg/gms/play/PlayPreferences.kt 0 → 100644 +21 −0 Original line number Diff line number Diff line package org.microg.gms.play import android.content.Context import org.microg.gms.settings.SettingsContract object PlayPreferences { @JvmStatic fun isLicensingEnabled(context: Context): Boolean { val projection = arrayOf(SettingsContract.Play.LICENSING) return SettingsContract.getSettings(context, SettingsContract.Play.getContentUri(context), projection) { c -> c.getInt(0) != 0 } } @JvmStatic fun setLicensingEnabled(context: Context, enabled: Boolean) { SettingsContract.setSettings(context, SettingsContract.Play.getContentUri(context)) { put(SettingsContract.Play.LICENSING, enabled) } } } No newline at end of file
play-services-core/src/main/kotlin/org/microg/gms/ui/PlayFragment.kt 0 → 100644 +49 −0 Original line number Diff line number Diff line package org.microg.gms.ui import android.annotation.SuppressLint import android.os.Bundle import androidx.lifecycle.lifecycleScope import androidx.preference.Preference import androidx.preference.PreferenceFragmentCompat import androidx.preference.TwoStatePreference import com.google.android.gms.R import org.microg.gms.play.PlayPreferences class PlayFragment : PreferenceFragmentCompat() { private lateinit var licensingEnabled: TwoStatePreference override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { addPreferencesFromResource(R.xml.preferences_play) } @SuppressLint("RestrictedApi") override fun onBindPreferences() { licensingEnabled = preferenceScreen.findPreference(PREF_LICENSING_ENABLED) ?: licensingEnabled licensingEnabled.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, newValue -> val appContext = requireContext().applicationContext lifecycleScope.launchWhenResumed { if (newValue is Boolean) { PlayPreferences.setLicensingEnabled(appContext, newValue) } updateContent() } true } } override fun onResume() { super.onResume() updateContent() } private fun updateContent() { val appContext = requireContext().applicationContext lifecycleScope.launchWhenResumed { licensingEnabled.isChecked = PlayPreferences.isLicensingEnabled(appContext) } } companion object { const val PREF_LICENSING_ENABLED = "play_licensing" } } No newline at end of file