Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 821d3200 authored by Jacky Wang's avatar Jacky Wang
Browse files

[Catalyst] Update permission check API signature

NO_IFTTT=Catalyst only

Bug: 374115149
Flag: com.android.settings.flags.catalyst
Test: manual
Change-Id: Ib13a5fddd517e3e260815b753b55c008e24d70d8
parent da9f7125
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -41,7 +41,7 @@ private class SetterPermissionChecker : ApiPermissionChecker<PreferenceSetterReq

    override fun hasPermission(
        application: Application,
        myUid: Int,
        callingPid: Int,
        callingUid: Int,
        request: PreferenceSetterRequest,
    ) = true
@@ -52,7 +52,7 @@ private class GetterPermissionChecker : ApiPermissionChecker<PreferenceGetterReq

    override fun hasPermission(
        application: Application,
        myUid: Int,
        callingPid: Int,
        callingUid: Int,
        request: PreferenceGetterRequest,
    ) = true
+7 −3
Original line number Diff line number Diff line
@@ -65,11 +65,15 @@ class RemoveAnimationsPreference :

    override fun storage(context: Context): KeyValueStore = RemoveAnimationsStorage(context)

    override fun getReadPermit(context: Context, myUid: Int, callingUid: Int) =
    override fun getReadPermit(context: Context, callingPid: Int, callingUid: Int) =
        ReadWritePermit.ALLOW

    override fun getWritePermit(context: Context, value: Boolean?, myUid: Int, callingUid: Int) =
        ReadWritePermit.ALLOW
    override fun getWritePermit(
        context: Context,
        value: Boolean?,
        callingPid: Int,
        callingUid: Int,
    ) = ReadWritePermit.ALLOW

    override val sensitivityLevel
        get() = SensitivityLevel.NO_SENSITIVITY
+23 −17
Original line number Diff line number Diff line
@@ -30,16 +30,16 @@ import com.android.settingslib.metadata.MainSwitchPreference
import com.android.settingslib.metadata.PreferenceLifecycleContext
import com.android.settingslib.metadata.PreferenceLifecycleProvider
import com.android.settingslib.metadata.ReadWritePermit
import com.android.settingslib.preference.MainSwitchPreferenceBinding

/**
 * Accessibility settings for vibration.
 */
/** Accessibility settings for vibration. */
// LINT.IfChange
class VibrationMainSwitchPreference : MainSwitchPreference(
class VibrationMainSwitchPreference :
    MainSwitchPreference(
        key = Settings.System.VIBRATE_ON,
        title = R.string.accessibility_vibration_primary_switch_title,
), PreferenceLifecycleProvider, OnCheckedChangeListener {
    ),
    PreferenceLifecycleProvider,
    OnCheckedChangeListener {
    override val keywords: Int
        get() = R.string.keywords_accessibility_vibration_primary_switch

@@ -48,20 +48,26 @@ class VibrationMainSwitchPreference : MainSwitchPreference(
    override fun storage(context: Context): KeyValueStore =
        VibrationMainSwitchToggleStorage(SettingsSystemStore.get(context))

    override fun getReadPermit(context: Context, myUid: Int, callingUid: Int) =
    override fun getReadPermit(context: Context, callingPid: Int, callingUid: Int) =
        ReadWritePermit.ALLOW

    override fun getWritePermit(context: Context, value: Boolean?, myUid: Int, callingUid: Int) =
        ReadWritePermit.ALLOW
    override fun getWritePermit(
        context: Context,
        value: Boolean?,
        callingPid: Int,
        callingUid: Int,
    ) = ReadWritePermit.ALLOW

    override fun onResume(context: PreferenceLifecycleContext) {
        vibrator = context.getSystemService(Vibrator::class.java)
        context.findPreference<com.android.settingslib.widget.MainSwitchPreference>(key)
        context
            .findPreference<com.android.settingslib.widget.MainSwitchPreference>(key)
            ?.addOnSwitchChangeListener(this)
    }

    override fun onPause(context: PreferenceLifecycleContext) {
        context.findPreference<com.android.settingslib.widget.MainSwitchPreference>(key)
        context
            .findPreference<com.android.settingslib.widget.MainSwitchPreference>(key)
            ?.removeOnSwitchChangeListener(this)
    }

@@ -69,16 +75,16 @@ class VibrationMainSwitchPreference : MainSwitchPreference(
        if (isChecked) {
            // Play a haptic as preview for the main toggle only when touch feedback is enabled.
            VibrationPreferenceConfig.playVibrationPreview(
                vibrator, VibrationAttributes.USAGE_TOUCH
                vibrator,
                VibrationAttributes.USAGE_TOUCH,
            )
        }
    }

    /** Provides SettingsStore for vibration main switch with custom default value. */
    @Suppress("UNCHECKED_CAST")
    private class VibrationMainSwitchToggleStorage(
        private val settingsStore: SettingsStore,
    ) : KeyedObservableDelegate<String>(settingsStore), KeyValueStore {
    private class VibrationMainSwitchToggleStorage(private val settingsStore: SettingsStore) :
        KeyedObservableDelegate<String>(settingsStore), KeyValueStore {

        override fun contains(key: String) = settingsStore.contains(key)

+7 −2
Original line number Diff line number Diff line
@@ -52,10 +52,15 @@ class BluetoothPreference(private val bluetoothDataStore: BluetoothDataStore) :
    override val restrictionKeys: Array<String>
        get() = arrayOf(UserManager.DISALLOW_BLUETOOTH, UserManager.DISALLOW_CONFIG_BLUETOOTH)

    override fun getReadPermit(context: Context, myUid: Int, callingUid: Int) =
    override fun getReadPermit(context: Context, callingPid: Int, callingUid: Int) =
        ReadWritePermit.ALLOW

    override fun getWritePermit(context: Context, value: Boolean?, myUid: Int, callingUid: Int) =
    override fun getWritePermit(
        context: Context,
        value: Boolean?,
        callingPid: Int,
        callingUid: Int,
    ) =
        when {
            isSatelliteOn(context, 3000) ||
                (value == true &&
+7 −3
Original line number Diff line number Diff line
@@ -36,11 +36,15 @@ class DataSaverMainSwitchPreference : MainSwitchBarMetadata, PreferenceLifecycle

    override fun storage(context: Context) = createDataStore(context)

    override fun getReadPermit(context: Context, myUid: Int, callingUid: Int) =
    override fun getReadPermit(context: Context, callingPid: Int, callingUid: Int) =
        ReadWritePermit.ALLOW

    override fun getWritePermit(context: Context, value: Boolean?, myUid: Int, callingUid: Int) =
        ReadWritePermit.ALLOW
    override fun getWritePermit(
        context: Context,
        value: Boolean?,
        callingPid: Int,
        callingUid: Int,
    ) = ReadWritePermit.ALLOW

    override val sensitivityLevel
        get() = SensitivityLevel.NO_SENSITIVITY
Loading