[Catalyst] Update permission check API signature

NO_IFTTT=Catalyst only

Bug: 374115149
Flag: com.android.settings.flags.catalyst
Test: manual
Change-Id: Ib13a5fddd517e3e260815b753b55c008e24d70d8
This commit is contained in:
Jacky Wang
2024-12-13 11:49:42 +08:00
parent da9f71257d
commit 821d320051
23 changed files with 152 additions and 74 deletions

View File

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

View File

@@ -65,11 +65,15 @@ class RemoveAnimationsPreference :
override fun storage(context: Context): KeyValueStore = RemoveAnimationsStorage(context) 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 ReadWritePermit.ALLOW
override fun getWritePermit(context: Context, value: Boolean?, myUid: Int, callingUid: Int) = override fun getWritePermit(
ReadWritePermit.ALLOW context: Context,
value: Boolean?,
callingPid: Int,
callingUid: Int,
) = ReadWritePermit.ALLOW
override val sensitivityLevel override val sensitivityLevel
get() = SensitivityLevel.NO_SENSITIVITY get() = SensitivityLevel.NO_SENSITIVITY

View File

@@ -30,16 +30,16 @@ import com.android.settingslib.metadata.MainSwitchPreference
import com.android.settingslib.metadata.PreferenceLifecycleContext import com.android.settingslib.metadata.PreferenceLifecycleContext
import com.android.settingslib.metadata.PreferenceLifecycleProvider import com.android.settingslib.metadata.PreferenceLifecycleProvider
import com.android.settingslib.metadata.ReadWritePermit import com.android.settingslib.metadata.ReadWritePermit
import com.android.settingslib.preference.MainSwitchPreferenceBinding
/** /** Accessibility settings for vibration. */
* Accessibility settings for vibration.
*/
// LINT.IfChange // LINT.IfChange
class VibrationMainSwitchPreference : MainSwitchPreference( class VibrationMainSwitchPreference :
key = Settings.System.VIBRATE_ON, MainSwitchPreference(
title = R.string.accessibility_vibration_primary_switch_title, key = Settings.System.VIBRATE_ON,
), PreferenceLifecycleProvider, OnCheckedChangeListener { title = R.string.accessibility_vibration_primary_switch_title,
),
PreferenceLifecycleProvider,
OnCheckedChangeListener {
override val keywords: Int override val keywords: Int
get() = R.string.keywords_accessibility_vibration_primary_switch get() = R.string.keywords_accessibility_vibration_primary_switch
@@ -48,20 +48,26 @@ class VibrationMainSwitchPreference : MainSwitchPreference(
override fun storage(context: Context): KeyValueStore = override fun storage(context: Context): KeyValueStore =
VibrationMainSwitchToggleStorage(SettingsSystemStore.get(context)) VibrationMainSwitchToggleStorage(SettingsSystemStore.get(context))
override fun getReadPermit(context: Context, myUid: Int, callingUid: Int) = override fun getReadPermit(context: Context, callingPid: Int, callingUid: Int) =
ReadWritePermit.ALLOW ReadWritePermit.ALLOW
override fun getWritePermit(context: Context, value: Boolean?, myUid: Int, callingUid: Int) = override fun getWritePermit(
ReadWritePermit.ALLOW context: Context,
value: Boolean?,
callingPid: Int,
callingUid: Int,
) = ReadWritePermit.ALLOW
override fun onResume(context: PreferenceLifecycleContext) { override fun onResume(context: PreferenceLifecycleContext) {
vibrator = context.getSystemService(Vibrator::class.java) vibrator = context.getSystemService(Vibrator::class.java)
context.findPreference<com.android.settingslib.widget.MainSwitchPreference>(key) context
.findPreference<com.android.settingslib.widget.MainSwitchPreference>(key)
?.addOnSwitchChangeListener(this) ?.addOnSwitchChangeListener(this)
} }
override fun onPause(context: PreferenceLifecycleContext) { override fun onPause(context: PreferenceLifecycleContext) {
context.findPreference<com.android.settingslib.widget.MainSwitchPreference>(key) context
.findPreference<com.android.settingslib.widget.MainSwitchPreference>(key)
?.removeOnSwitchChangeListener(this) ?.removeOnSwitchChangeListener(this)
} }
@@ -69,16 +75,16 @@ class VibrationMainSwitchPreference : MainSwitchPreference(
if (isChecked) { if (isChecked) {
// Play a haptic as preview for the main toggle only when touch feedback is enabled. // Play a haptic as preview for the main toggle only when touch feedback is enabled.
VibrationPreferenceConfig.playVibrationPreview( VibrationPreferenceConfig.playVibrationPreview(
vibrator, VibrationAttributes.USAGE_TOUCH vibrator,
VibrationAttributes.USAGE_TOUCH,
) )
} }
} }
/** Provides SettingsStore for vibration main switch with custom default value. */ /** Provides SettingsStore for vibration main switch with custom default value. */
@Suppress("UNCHECKED_CAST") @Suppress("UNCHECKED_CAST")
private class VibrationMainSwitchToggleStorage( private class VibrationMainSwitchToggleStorage(private val settingsStore: SettingsStore) :
private val settingsStore: SettingsStore, KeyedObservableDelegate<String>(settingsStore), KeyValueStore {
) : KeyedObservableDelegate<String>(settingsStore), KeyValueStore {
override fun contains(key: String) = settingsStore.contains(key) override fun contains(key: String) = settingsStore.contains(key)

View File

@@ -52,10 +52,15 @@ class BluetoothPreference(private val bluetoothDataStore: BluetoothDataStore) :
override val restrictionKeys: Array<String> override val restrictionKeys: Array<String>
get() = arrayOf(UserManager.DISALLOW_BLUETOOTH, UserManager.DISALLOW_CONFIG_BLUETOOTH) 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 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 { when {
isSatelliteOn(context, 3000) || isSatelliteOn(context, 3000) ||
(value == true && (value == true &&

View File

@@ -36,11 +36,15 @@ class DataSaverMainSwitchPreference : MainSwitchBarMetadata, PreferenceLifecycle
override fun storage(context: Context) = createDataStore(context) 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 ReadWritePermit.ALLOW
override fun getWritePermit(context: Context, value: Boolean?, myUid: Int, callingUid: Int) = override fun getWritePermit(
ReadWritePermit.ALLOW context: Context,
value: Boolean?,
callingPid: Int,
callingUid: Int,
) = ReadWritePermit.ALLOW
override val sensitivityLevel override val sensitivityLevel
get() = SensitivityLevel.NO_SENSITIVITY get() = SensitivityLevel.NO_SENSITIVITY

View File

@@ -77,11 +77,15 @@ class AdaptiveSleepPreference :
override fun storage(context: Context): KeyValueStore = Storage(context) override fun storage(context: Context): KeyValueStore = Storage(context)
override fun getReadPermit(context: Context, myUid: Int, callingUid: Int) = override fun getReadPermit(context: Context, callingPid: Int, callingUid: Int) =
ReadWritePermit.ALLOW ReadWritePermit.ALLOW
override fun getWritePermit(context: Context, value: Boolean?, myUid: Int, callingUid: Int) = override fun getWritePermit(
ReadWritePermit.ALLOW context: Context,
value: Boolean?,
callingPid: Int,
callingUid: Int,
) = ReadWritePermit.ALLOW
override val sensitivityLevel override val sensitivityLevel
get() = SensitivityLevel.NO_SENSITIVITY get() = SensitivityLevel.NO_SENSITIVITY

View File

@@ -71,11 +71,15 @@ class AmbientDisplayAlwaysOnPreference :
override fun storage(context: Context): KeyValueStore = Storage(context) override fun storage(context: Context): KeyValueStore = Storage(context)
override fun getReadPermit(context: Context, myUid: Int, callingUid: Int) = override fun getReadPermit(context: Context, callingPid: Int, callingUid: Int) =
ReadWritePermit.ALLOW ReadWritePermit.ALLOW
override fun getWritePermit(context: Context, value: Boolean?, myUid: Int, callingUid: Int) = override fun getWritePermit(
ReadWritePermit.ALLOW context: Context,
value: Boolean?,
callingPid: Int,
callingUid: Int,
) = ReadWritePermit.ALLOW
override val sensitivityLevel override val sensitivityLevel
get() = SensitivityLevel.NO_SENSITIVITY get() = SensitivityLevel.NO_SENSITIVITY

View File

@@ -65,11 +65,15 @@ class AutoBrightnessScreen :
override fun storage(context: Context): KeyValueStore = override fun storage(context: Context): KeyValueStore =
AutoBrightnessDataStore(SettingsSystemStore.get(context)) AutoBrightnessDataStore(SettingsSystemStore.get(context))
override fun getReadPermit(context: Context, myUid: Int, callingUid: Int) = override fun getReadPermit(context: Context, callingPid: Int, callingUid: Int) =
ReadWritePermit.ALLOW ReadWritePermit.ALLOW
override fun getWritePermit(context: Context, value: Boolean?, myUid: Int, callingUid: Int) = override fun getWritePermit(
ReadWritePermit.ALLOW context: Context,
value: Boolean?,
callingPid: Int,
callingUid: Int,
) = ReadWritePermit.ALLOW
override val sensitivityLevel override val sensitivityLevel
get() = SensitivityLevel.NO_SENSITIVITY get() = SensitivityLevel.NO_SENSITIVITY

View File

@@ -49,11 +49,15 @@ class BatteryPercentageSwitchPreference :
com.android.internal.R.bool.config_battery_percentage_setting_available com.android.internal.R.bool.config_battery_percentage_setting_available
) )
override fun getReadPermit(context: Context, myUid: Int, callingUid: Int) = override fun getReadPermit(context: Context, callingPid: Int, callingUid: Int) =
ReadWritePermit.ALLOW ReadWritePermit.ALLOW
override fun getWritePermit(context: Context, value: Boolean?, myUid: Int, callingUid: Int) = override fun getWritePermit(
ReadWritePermit.ALLOW context: Context,
value: Boolean?,
callingPid: Int,
callingUid: Int,
) = ReadWritePermit.ALLOW
override val sensitivityLevel override val sensitivityLevel
get() = SensitivityLevel.NO_SENSITIVITY get() = SensitivityLevel.NO_SENSITIVITY

View File

@@ -50,11 +50,15 @@ class PeakRefreshRateSwitchPreference :
override fun storage(context: Context): KeyValueStore = override fun storage(context: Context): KeyValueStore =
PeakRefreshRateStore(context, SettingsSystemStore.get(context)) PeakRefreshRateStore(context, SettingsSystemStore.get(context))
override fun getReadPermit(context: Context, myUid: Int, callingUid: Int) = override fun getReadPermit(context: Context, callingPid: Int, callingUid: Int) =
ReadWritePermit.ALLOW ReadWritePermit.ALLOW
override fun getWritePermit(context: Context, value: Boolean?, myUid: Int, callingUid: Int) = override fun getWritePermit(
ReadWritePermit.ALLOW context: Context,
value: Boolean?,
callingPid: Int,
callingUid: Int,
) = ReadWritePermit.ALLOW
override val sensitivityLevel override val sensitivityLevel
get() = SensitivityLevel.NO_SENSITIVITY get() = SensitivityLevel.NO_SENSITIVITY

View File

@@ -71,11 +71,15 @@ class DarkModeScreen :
override val keywords: Int override val keywords: Int
get() = R.string.keywords_dark_ui_mode get() = R.string.keywords_dark_ui_mode
override fun getReadPermit(context: Context, myUid: Int, callingUid: Int) = override fun getReadPermit(context: Context, callingPid: Int, callingUid: Int) =
ReadWritePermit.ALLOW ReadWritePermit.ALLOW
override fun getWritePermit(context: Context, value: Boolean?, myUid: Int, callingUid: Int) = override fun getWritePermit(
ReadWritePermit.ALLOW context: Context,
value: Boolean?,
callingPid: Int,
callingUid: Int,
) = ReadWritePermit.ALLOW
override val sensitivityLevel override val sensitivityLevel
get() = SensitivityLevel.NO_SENSITIVITY get() = SensitivityLevel.NO_SENSITIVITY

View File

@@ -102,10 +102,10 @@ class BatteryHeaderPreference :
override fun getMaxValue(context: Context): Int = 100 override fun getMaxValue(context: Context): Int = 100
override fun getReadPermit(context: Context, myUid: Int, callingUid: Int) = override fun getReadPermit(context: Context, callingPid: Int, callingUid: Int) =
ReadWritePermit.ALLOW ReadWritePermit.ALLOW
override fun getWritePermit(context: Context, value: Int?, myUid: Int, callingUid: Int) = override fun getWritePermit(context: Context, value: Int?, callingPid: Int, callingUid: Int) =
ReadWritePermit.DISALLOW ReadWritePermit.DISALLOW
companion object { companion object {

View File

@@ -43,11 +43,15 @@ class BatterySaverPreference :
override fun storage(context: Context) = BatterySaverStore(context) override fun storage(context: Context) = BatterySaverStore(context)
override fun getReadPermit(context: Context, myUid: Int, callingUid: Int) = override fun getReadPermit(context: Context, callingPid: Int, callingUid: Int) =
ReadWritePermit.ALLOW ReadWritePermit.ALLOW
override fun getWritePermit(context: Context, value: Boolean?, myUid: Int, callingUid: Int) = override fun getWritePermit(
ReadWritePermit.ALLOW context: Context,
value: Boolean?,
callingPid: Int,
callingUid: Int,
) = ReadWritePermit.ALLOW
override val sensitivityLevel override val sensitivityLevel
get() = SensitivityLevel.NO_SENSITIVITY get() = SensitivityLevel.NO_SENSITIVITY

View File

@@ -35,11 +35,15 @@ class AdaptiveConnectivityTogglePreference :
override fun storage(context: Context): KeyValueStore = override fun storage(context: Context): KeyValueStore =
AdaptiveConnectivityToggleStorage(context, SettingsSecureStore.get(context)) AdaptiveConnectivityToggleStorage(context, SettingsSecureStore.get(context))
override fun getReadPermit(context: Context, myUid: Int, callingUid: Int) = override fun getReadPermit(context: Context, callingPid: Int, callingUid: Int) =
ReadWritePermit.ALLOW ReadWritePermit.ALLOW
override fun getWritePermit(context: Context, value: Boolean?, myUid: Int, callingUid: Int) = override fun getWritePermit(
ReadWritePermit.ALLOW context: Context,
value: Boolean?,
callingPid: Int,
callingUid: Int,
) = ReadWritePermit.ALLOW
override val sensitivityLevel override val sensitivityLevel
get() = SensitivityLevel.NO_SENSITIVITY get() = SensitivityLevel.NO_SENSITIVITY

View File

@@ -65,10 +65,15 @@ class AirplaneModePreference :
override val restrictionKeys override val restrictionKeys
get() = arrayOf(UserManager.DISALLOW_AIRPLANE_MODE) get() = arrayOf(UserManager.DISALLOW_AIRPLANE_MODE)
override fun getReadPermit(context: Context, myUid: Int, callingUid: Int) = override fun getReadPermit(context: Context, callingPid: Int, callingUid: Int) =
ReadWritePermit.ALLOW 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 { when {
isSatelliteOn(context) || isInEcmMode(context) -> ReadWritePermit.DISALLOW isSatelliteOn(context) || isInEcmMode(context) -> ReadWritePermit.DISALLOW
else -> ReadWritePermit.ALLOW else -> ReadWritePermit.ALLOW

View File

@@ -45,11 +45,15 @@ class MobileDataPreference :
override fun storage(context: Context): KeyValueStore = MobileDataStorage(context) override fun storage(context: Context): KeyValueStore = MobileDataStorage(context)
override fun getReadPermit(context: Context, myUid: Int, callingUid: Int) = override fun getReadPermit(context: Context, callingPid: Int, callingUid: Int) =
ReadWritePermit.ALLOW ReadWritePermit.ALLOW
override fun getWritePermit(context: Context, value: Boolean?, myUid: Int, callingUid: Int) = override fun getWritePermit(
ReadWritePermit.ALLOW context: Context,
value: Boolean?,
callingPid: Int,
callingUid: Int,
) = ReadWritePermit.ALLOW
override val sensitivityLevel override val sensitivityLevel
get() = SensitivityLevel.LOW_SENSITIVITY get() = SensitivityLevel.LOW_SENSITIVITY

View File

@@ -77,11 +77,15 @@ class BluetoothTetherSwitchPreference :
return !dataSaverBackend.isDataSaverEnabled return !dataSaverBackend.isDataSaverEnabled
} }
override fun getReadPermit(context: Context, myUid: Int, callingUid: Int) = override fun getReadPermit(context: Context, callingPid: Int, callingUid: Int) =
ReadWritePermit.ALLOW ReadWritePermit.ALLOW
override fun getWritePermit(context: Context, value: Boolean?, myUid: Int, callingUid: Int) = override fun getWritePermit(
ReadWritePermit.ALLOW context: Context,
value: Boolean?,
callingPid: Int,
callingUid: Int,
) = ReadWritePermit.ALLOW
override val sensitivityLevel: Int override val sensitivityLevel: Int
get() = SensitivityLevel.LOW_SENSITIVITY get() = SensitivityLevel.LOW_SENSITIVITY

View File

@@ -76,10 +76,10 @@ open class CallVolumePreference :
} }
} }
override fun getReadPermit(context: Context, myUid: Int, callingUid: Int) = override fun getReadPermit(context: Context, callingPid: Int, callingUid: Int) =
ReadWritePermit.ALLOW ReadWritePermit.ALLOW
override fun getWritePermit(context: Context, value: Int?, myUid: Int, callingUid: Int) = override fun getWritePermit(context: Context, value: Int?, callingPid: Int, callingUid: Int) =
ReadWritePermit.ALLOW ReadWritePermit.ALLOW
override val sensitivityLevel override val sensitivityLevel

View File

@@ -77,10 +77,10 @@ open class MediaVolumePreference :
} }
} }
override fun getReadPermit(context: Context, myUid: Int, callingUid: Int) = override fun getReadPermit(context: Context, callingPid: Int, callingUid: Int) =
ReadWritePermit.ALLOW ReadWritePermit.ALLOW
override fun getWritePermit(context: Context, value: Int?, myUid: Int, callingUid: Int) = override fun getWritePermit(context: Context, value: Int?, callingPid: Int, callingUid: Int) =
ReadWritePermit.ALLOW ReadWritePermit.ALLOW
override val sensitivityLevel override val sensitivityLevel

View File

@@ -94,10 +94,10 @@ open class SeparateRingVolumePreference :
} }
} }
override fun getReadPermit(context: Context, myUid: Int, callingUid: Int) = override fun getReadPermit(context: Context, callingPid: Int, callingUid: Int) =
ReadWritePermit.ALLOW ReadWritePermit.ALLOW
override fun getWritePermit(context: Context, value: Int?, myUid: Int, callingUid: Int) = override fun getWritePermit(context: Context, value: Int?, callingPid: Int, callingUid: Int) =
ReadWritePermit.ALLOW ReadWritePermit.ALLOW
override val sensitivityLevel override val sensitivityLevel

View File

@@ -92,10 +92,15 @@ class WifiSwitchPreference :
return true return true
} }
override fun getReadPermit(context: Context, myUid: Int, callingUid: Int) = override fun getReadPermit(context: Context, callingPid: Int, callingUid: Int) =
ReadWritePermit.ALLOW 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 { when {
(value == true && !context.isRadioAllowed()) || isSatelliteOn(context) -> (value == true && !context.isRadioAllowed()) || isSatelliteOn(context) ->
ReadWritePermit.DISALLOW ReadWritePermit.DISALLOW

View File

@@ -60,10 +60,15 @@ class WifiCallingMainSwitchPreference(private val subId: Int) :
override fun createWidget(context: Context) = SettingsMainSwitchPreference(context) override fun createWidget(context: Context) = SettingsMainSwitchPreference(context)
override fun getReadPermit(context: Context, myUid: Int, callingUid: Int) = override fun getReadPermit(context: Context, callingPid: Int, callingUid: Int) =
ReadWritePermit.ALLOW 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 { when {
value == true && value == true &&
(DisclaimerItemFactory.create(context, subId).isNotEmpty() || (DisclaimerItemFactory.create(context, subId).isNotEmpty() ||

View File

@@ -106,11 +106,15 @@ class WifiHotspotSwitchPreference(context: Context, dataSaverStore: KeyValueStor
override val restrictionKeys override val restrictionKeys
get() = arrayOf(UserManager.DISALLOW_WIFI_TETHERING) get() = arrayOf(UserManager.DISALLOW_WIFI_TETHERING)
override fun getReadPermit(context: Context, myUid: Int, callingUid: Int) = override fun getReadPermit(context: Context, callingPid: Int, callingUid: Int) =
ReadWritePermit.ALLOW ReadWritePermit.ALLOW
override fun getWritePermit(context: Context, value: Boolean?, myUid: Int, callingUid: Int) = override fun getWritePermit(
ReadWritePermit.ALLOW context: Context,
value: Boolean?,
callingPid: Int,
callingUid: Int,
) = ReadWritePermit.ALLOW
override val sensitivityLevel override val sensitivityLevel
get() = SensitivityLevel.HIGH_SENSITIVITY get() = SensitivityLevel.HIGH_SENSITIVITY