1 /* 2 * Copyright (C) 2025 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.settings.sound 18 19 import android.app.settings.SettingsEnums.ACTION_SHOW_MEDIA_ON_LOCK_SCREEN 20 import android.content.Context 21 import android.provider.Settings.Secure.MEDIA_CONTROLS_LOCK_SCREEN 22 import com.android.settings.R 23 import com.android.settings.contract.KEY_SHOW_MEDIA_ON_LOCK_SCREEN 24 import com.android.settings.metrics.PreferenceActionMetricsProvider 25 import com.android.settingslib.datastore.KeyValueStore 26 import com.android.settingslib.datastore.KeyValueStoreDelegate 27 import com.android.settingslib.datastore.SettingsSecureStore 28 import com.android.settingslib.metadata.ReadWritePermit 29 import com.android.settingslib.metadata.SensitivityLevel 30 import com.android.settingslib.metadata.SwitchPreference 31 32 // LINT.IfChange 33 class MediaControlsLockscreenSwitchPreference : 34 SwitchPreference( 35 KEY, 36 R.string.media_controls_lockscreen_title, 37 R.string.media_controls_lockscreen_description, 38 ), 39 PreferenceActionMetricsProvider { 40 41 override val preferenceActionMetrics: Int 42 get() = ACTION_SHOW_MEDIA_ON_LOCK_SCREEN 43 tagsnull44 override fun tags(context: Context) = arrayOf(KEY_SHOW_MEDIA_ON_LOCK_SCREEN) 45 46 override val sensitivityLevel 47 get() = SensitivityLevel.NO_SENSITIVITY 48 49 override fun getReadPermissions(context: Context) = SettingsSecureStore.getReadPermissions() 50 51 override fun getWritePermissions(context: Context) = SettingsSecureStore.getWritePermissions() 52 53 override fun getReadPermit(context: Context, callingPid: Int, callingUid: Int) = 54 ReadWritePermit.ALLOW 55 56 override fun getWritePermit(context: Context, callingPid: Int, callingUid: Int) = 57 ReadWritePermit.ALLOW 58 59 override fun storage(context: Context): KeyValueStore = 60 MediaControlsLockscreenStore(SettingsSecureStore.get(context)) 61 62 @Suppress("UNCHECKED_CAST") 63 private class MediaControlsLockscreenStore(private val settingsStore: KeyValueStore) : 64 KeyValueStoreDelegate { 65 66 override val keyValueStoreDelegate 67 get() = settingsStore 68 69 override fun <T : Any> getDefaultValue(key: String, valueType: Class<T>) = true as T 70 } 71 72 companion object { 73 const val KEY = MEDIA_CONTROLS_LOCK_SCREEN 74 } 75 } 76 // LINT.ThenChange(MediaControlsLockScreenPreferenceController.java) 77