Add preference for play licensing microg@4ef2248

This commit is contained in:
Cuynu 2024-10-02 16:18:37 +07:00
commit 9a12599b40
33 changed files with 257 additions and 6 deletions

View file

@ -104,6 +104,17 @@ 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 {

View file

@ -14,6 +14,7 @@ import android.content.SharedPreferences
import android.database.Cursor
import android.database.MatrixCursor
import android.net.Uri
import org.microg.gms.settings.SettingsContract.Play
import android.preference.PreferenceManager
import org.microg.gms.common.PackageUtils.warnIfNotMainProcess
import org.microg.gms.settings.SettingsContract.Auth
@ -68,6 +69,7 @@ class SettingsProvider : ContentProvider() {
Gcm.getContentUri(context!!) -> queryGcm(projection ?: Gcm.PROJECTION)
Auth.getContentUri(context!!) -> queryAuth(projection ?: Auth.PROJECTION)
Profile.getContentUri(context!!) -> queryProfile(projection ?: Profile.PROJECTION)
Play.getContentUri(context!!) -> queryPlay(projection ?: Play.PROJECTION)
else -> null
}
@ -84,11 +86,30 @@ class SettingsProvider : ContentProvider() {
Gcm.getContentUri(context!!) -> updateGcm(values)
Auth.getContentUri(context!!) -> updateAuth(values)
Profile.getContentUri(context!!) -> updateProfile(values)
Play.getContentUri(context!!) -> updatePlay(values)
else -> return 0
}
return 1
}
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 queryCheckIn(p: Array<out String>): Cursor = MatrixCursor(p).addRow(p) { key ->
when (key) {
CheckIn.ENABLED -> getSettingsBoolean(key, true)

View file

@ -0,0 +1,18 @@
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)
}
}
}

View file

@ -0,0 +1,42 @@
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.mgoogle.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"
}
}

View file

@ -22,6 +22,7 @@ import org.microg.gms.settings.SettingsContract
import org.microg.gms.ui.settings.SettingsProvider
import org.microg.gms.ui.settings.getAllSettingsProviders
import org.microg.tools.ui.ResourceSettingsFragment
import org.microg.gms.play.PlayPreferences
import androidx.lifecycle.lifecycleScope
import androidx.navigation.fragment.findNavController
@ -39,11 +40,17 @@ class SettingsFragment : ResourceSettingsFragment() {
findNavController().navigate(requireContext(), R.id.openGcmSettings)
true
}
findPreference<Preference>(PREF_ABOUT)?.setOnPreferenceClickListener {
findNavController().navigate(requireContext(), R.id.openAbout)
findPreference<Preference>(PREF_PLAY)!!.onPreferenceClickListener = Preference.OnPreferenceClickListener {
findNavController().navigate(requireContext(), R.id.openPlaySettings)
true
}
findPreference<Preference>(PREF_ABOUT)?.summary = getString(R.string.about_version_str, AboutFragment.getSelfVersion(context))
findPreference<Preference>(PREF_ABOUT)!!.apply {
onPreferenceClickListener = Preference.OnPreferenceClickListener {
findNavController().navigate(requireContext(), R.id.openAbout)
true
}
summary = getString(org.microg.tools.ui.R.string.about_version_str, AboutFragment.getSelfVersion(context))
}
findPreference<SwitchPreferenceCompat>(SettingsContract.CheckIn.HIDE_LAUNCHER_ICON)?.apply {
setOnPreferenceChangeListener { _, newValue ->
@ -106,6 +113,7 @@ class SettingsFragment : ResourceSettingsFragment() {
}
findPreference<Preference>(PREF_CHECKIN)?.setSummary(if (CheckinPrefs.isEnabled(context)) R.string.service_status_enabled_short else R.string.service_status_disabled_short)
findPreference<Preference>(PREF_PLAY)!!.setSummary(if (PlayPreferences.isLicensingEnabled(requireContext())) R.string.pref_play_summary_licensing_on else R.string.pref_play_summary_licensing_off)
lifecycleScope.launchWhenResumed {
val entries = getAllSettingsProviders(requireContext()).flatMap { it.getEntriesDynamic(requireContext()) }
@ -124,6 +132,7 @@ class SettingsFragment : ResourceSettingsFragment() {
const val PREF_ABOUT = "pref_about"
const val PREF_GCM = "pref_gcm"
const val PREF_CHECKIN = "pref_checkin"
const val PREF_PLAY = "pref_play"
}
init {

View file

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorAccent">
<path
android:fillColor="@android:color/white"
android:pathData="M16,6L16,4c0,-1.11 -0.89,-2 -2,-2h-4c-1.11,0 -2,0.89 -2,2v2L2,6v13c0,1.11 0.89,2 2,2h16c1.11,0 2,-0.89 2,-2L22,6h-6zM10,4h4v2h-4L10,4zM9,18L9,9l7.5,4L9,18z"/>
</vector>

View file

@ -11,6 +11,9 @@
<action android:id="@+id/openCheckinSettings" app:destination="@id/checkinFragment" />
<action android:id="@+id/openGcmSettings" app:destination="@id/gcmFragment" />
<action android:id="@+id/openAbout" app:destination="@id/aboutFragment" />
<action
android:id="@+id/openPlaySettings"
app:destination="@id/playFragment" />
</fragment>
<fragment
@ -32,6 +35,9 @@
<action
android:id="@+id/openGcmAdvancedSettings"
app:destination="@id/gcmAdvancedFragment" />
<action
android:id="@+id/openPlaySettings"
app:destination="@id/playFragment" />
</fragment>
<fragment
android:id="@+id/gcmAllAppsFragment"
@ -59,4 +65,8 @@
android:id="@+id/aboutFragment"
android:name="org.microg.gms.ui.AboutFragment"
android:label="@string/prefcat_about" />
<fragment
android:id="@+id/playFragment"
android:name="org.microg.gms.ui.PlayFragment"
android:label="@string/service_name_play" />
</navigation>

View file

@ -138,4 +138,9 @@
<string name="manage_googleaccount_title">Manage signed in Google accounts</string>
<string name="manage_googleaccount_summary">This will open your device settings !</string>
<string name="miscellaneous_settings">Miscellaneous settings</string>
<string name="pref_play_summary_licensing_off">Licensing off</string>
<string name="pref_play_summary_licensing_on">Licensing on</string>
<string name="pref_play_licensing_enable_switch">Answer license verification requests</string>
<string name="pref_play_license_enable_summary">Some apps require verification that you have purchased them on Google Play. When requested by an app, Vanced+ microG can download a proof of purchase from Google. If disabled, or if no Google account is added, requests for license verification are ignored.</string>
<string name="service_name_play">Play Store services</string>
</resources>

View file

@ -138,4 +138,9 @@ Bu bir neçə dəqiqə çəkə bilər."</string>
<string name="manage_googleaccount_title">Manage signed in Google accounts</string>
<string name="manage_googleaccount_summary">This will open your device settings !</string>
<string name="miscellaneous_settings">Miscellaneous settings</string>
<string name="pref_play_summary_licensing_off">Licensing off</string>
<string name="pref_play_summary_licensing_on">Licensing on</string>
<string name="pref_play_licensing_enable_switch">Answer license verification requests</string>
<string name="pref_play_license_enable_summary">Some apps require verification that you have purchased them on Google Play. When requested by an app, Vanced+ microG can download a proof of purchase from Google. If disabled, or if no Google account is added, requests for license verification are ignored.</string>
<string name="service_name_play">Play Store services</string>
</resources>

View file

@ -138,4 +138,9 @@
<string name="manage_googleaccount_title">Manage signed in Google accounts</string>
<string name="manage_googleaccount_summary">This will open your device settings !</string>
<string name="miscellaneous_settings">Miscellaneous settings</string>
<string name="pref_play_summary_licensing_off">Licensing off</string>
<string name="pref_play_summary_licensing_on">Licensing on</string>
<string name="pref_play_licensing_enable_switch">Answer license verification requests</string>
<string name="pref_play_license_enable_summary">Some apps require verification that you have purchased them on Google Play. When requested by an app, Vanced+ microG can download a proof of purchase from Google. If disabled, or if no Google account is added, requests for license verification are ignored.</string>
<string name="service_name_play">Play Store services</string>
</resources>

View file

@ -139,4 +139,9 @@
<string name="manage_googleaccount_title">Manage signed in Google accounts</string>
<string name="manage_googleaccount_summary">This will open your device settings !</string>
<string name="miscellaneous_settings">Miscellaneous settings</string>
<string name="pref_play_summary_licensing_off">Licensing off</string>
<string name="pref_play_summary_licensing_on">Licensing on</string>
<string name="pref_play_licensing_enable_switch">Answer license verification requests</string>
<string name="pref_play_license_enable_summary">Some apps require verification that you have purchased them on Google Play. When requested by an app, Vanced+ microG can download a proof of purchase from Google. If disabled, or if no Google account is added, requests for license verification are ignored.</string>
<string name="service_name_play">Play Store services</string>
</resources>

View file

@ -135,4 +135,9 @@ Tato akce může trvat několik minut."</string>
<string name="manage_googleaccount_title">Manage signed in Google accounts</string>
<string name="manage_googleaccount_summary">This will open your device settings !</string>
<string name="miscellaneous_settings">Miscellaneous settings</string>
<string name="pref_play_summary_licensing_off">Licensing off</string>
<string name="pref_play_summary_licensing_on">Licensing on</string>
<string name="pref_play_licensing_enable_switch">Answer license verification requests</string>
<string name="pref_play_license_enable_summary">Some apps require verification that you have purchased them on Google Play. When requested by an app, Vanced+ microG can download a proof of purchase from Google. If disabled, or if no Google account is added, requests for license verification are ignored.</string>
<string name="service_name_play">Play Store services</string>
</resources>

View file

@ -138,4 +138,9 @@ Esto puede tardar unos minutos."</string>
<string name="manage_googleaccount_title">Manage signed in Google accounts</string>
<string name="manage_googleaccount_summary">This will open your device settings !</string>
<string name="miscellaneous_settings">Miscellaneous settings</string>
<string name="pref_play_summary_licensing_off">Licensing off</string>
<string name="pref_play_summary_licensing_on">Licensing on</string>
<string name="pref_play_licensing_enable_switch">Answer license verification requests</string>
<string name="pref_play_license_enable_summary">Some apps require verification that you have purchased them on Google Play. When requested by an app, Vanced+ microG can download a proof of purchase from Google. If disabled, or if no Google account is added, requests for license verification are ignored.</string>
<string name="service_name_play">Play Store services</string>
</resources>

View file

@ -138,4 +138,9 @@ Cela peut prendre quelques minutes."</string>
<string name="manage_googleaccount_title">Manage signed in Google accounts</string>
<string name="manage_googleaccount_summary">This will open your device settings !</string>
<string name="miscellaneous_settings">Miscellaneous settings</string>
<string name="pref_play_summary_licensing_off">Licensing off</string>
<string name="pref_play_summary_licensing_on">Licensing on</string>
<string name="pref_play_licensing_enable_switch">Answer license verification requests</string>
<string name="pref_play_license_enable_summary">Some apps require verification that you have purchased them on Google Play. When requested by an app, Vanced+ microG can download a proof of purchase from Google. If disabled, or if no Google account is added, requests for license verification are ignored.</string>
<string name="service_name_play">Play Store services</string>
</resources>

View file

@ -85,4 +85,9 @@
<string name="manage_googleaccount_title">Manage signed in Google accounts</string>
<string name="manage_googleaccount_summary">This will open your device settings !</string>
<string name="miscellaneous_settings">Miscellaneous settings</string>
<string name="pref_play_summary_licensing_off">Licensing off</string>
<string name="pref_play_summary_licensing_on">Licensing on</string>
<string name="pref_play_licensing_enable_switch">Answer license verification requests</string>
<string name="pref_play_license_enable_summary">Some apps require verification that you have purchased them on Google Play. When requested by an app, Vanced+ microG can download a proof of purchase from Google. If disabled, or if no Google account is added, requests for license verification are ignored.</string>
<string name="service_name_play">Play Store services</string>
</resources>

View file

@ -137,4 +137,9 @@
<string name="manage_googleaccount_title">Manage signed in Google accounts</string>
<string name="manage_googleaccount_summary">This will open your device settings !</string>
<string name="miscellaneous_settings">Miscellaneous settings</string>
<string name="pref_play_summary_licensing_off">Licensing off</string>
<string name="pref_play_summary_licensing_on">Licensing on</string>
<string name="pref_play_licensing_enable_switch">Answer license verification requests</string>
<string name="pref_play_license_enable_summary">Some apps require verification that you have purchased them on Google Play. When requested by an app, Vanced+ microG can download a proof of purchase from Google. If disabled, or if no Google account is added, requests for license verification are ignored.</string>
<string name="service_name_play">Play Store services</string>
</resources>

View file

@ -136,4 +136,9 @@ Ini bisa berlangsung beberapa menit."</string>
<string name="manage_googleaccount_title">Manage signed in Google accounts</string>
<string name="manage_googleaccount_summary">This will open your device settings !</string>
<string name="miscellaneous_settings">Miscellaneous settings</string>
<string name="pref_play_summary_licensing_off">Licensing off</string>
<string name="pref_play_summary_licensing_on">Licensing on</string>
<string name="pref_play_licensing_enable_switch">Answer license verification requests</string>
<string name="pref_play_license_enable_summary">Some apps require verification that you have purchased them on Google Play. When requested by an app, Vanced+ microG can download a proof of purchase from Google. If disabled, or if no Google account is added, requests for license verification are ignored.</string>
<string name="service_name_play">Play Store services</string>
</resources>

View file

@ -135,4 +135,9 @@ Questo potrà richiedere un paio di minuti"</string>
<string name="manage_googleaccount_title">Manage signed in Google accounts</string>
<string name="manage_googleaccount_summary">This will open your device settings !</string>
<string name="miscellaneous_settings">Miscellaneous settings</string>
<string name="pref_play_summary_licensing_off">Licensing off</string>
<string name="pref_play_summary_licensing_on">Licensing on</string>
<string name="pref_play_licensing_enable_switch">Answer license verification requests</string>
<string name="pref_play_license_enable_summary">Some apps require verification that you have purchased them on Google Play. When requested by an app, Vanced+ microG can download a proof of purchase from Google. If disabled, or if no Google account is added, requests for license verification are ignored.</string>
<string name="service_name_play">Play Store services</string>
</resources>

View file

@ -138,4 +138,9 @@
<string name="manage_googleaccount_title">Manage signed in Google accounts</string>
<string name="manage_googleaccount_summary">This will open your device settings !</string>
<string name="miscellaneous_settings">Miscellaneous settings</string>
<string name="pref_play_summary_licensing_off">Licensing off</string>
<string name="pref_play_summary_licensing_on">Licensing on</string>
<string name="pref_play_licensing_enable_switch">Answer license verification requests</string>
<string name="pref_play_license_enable_summary">Some apps require verification that you have purchased them on Google Play. When requested by an app, Vanced+ microG can download a proof of purchase from Google. If disabled, or if no Google account is added, requests for license verification are ignored.</string>
<string name="service_name_play">Play Store services</string>
</resources>

View file

@ -138,4 +138,9 @@
<string name="manage_googleaccount_title">Manage signed in Google accounts</string>
<string name="manage_googleaccount_summary">This will open your device settings !</string>
<string name="miscellaneous_settings">Miscellaneous settings</string>
<string name="pref_play_summary_licensing_off">Licensing off</string>
<string name="pref_play_summary_licensing_on">Licensing on</string>
<string name="pref_play_licensing_enable_switch">Answer license verification requests</string>
<string name="pref_play_license_enable_summary">Some apps require verification that you have purchased them on Google Play. When requested by an app, Vanced+ microG can download a proof of purchase from Google. If disabled, or if no Google account is added, requests for license verification are ignored.</string>
<string name="service_name_play">Play Store services</string>
</resources>

Some files were not shown because too many files have changed in this diff Show more