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

Commit 63a24ea5 authored by Jacky Wang's avatar Jacky Wang Committed by Android (Google) Code Review
Browse files

Merge changes from topic "catalyst" into main

* changes:
  [Catalyst] Clean up AmbientWallpaperPreference data store
  [Catalyst] Avoid PreferenceAvailabilityProvider for ambient wallpaper
parents b42336a4 2ffa7b74
Loading
Loading
Loading
Loading
+14 −6
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.hardware.display.AmbientDisplayConfiguration
import android.os.SystemProperties
import android.os.UserHandle
import android.os.UserManager
import com.android.internal.R.bool.config_dozeSupportsAodWallpaper
import com.android.settings.CatalystFragment
import com.android.settings.CatalystSettingsActivity
import com.android.settings.R
@@ -31,7 +32,6 @@ import com.android.settings.display.AmbientDisplayAlwaysOnPreferenceController.i
import com.android.settings.display.ambient.AmbientDisplayMainSwitchPreference
import com.android.settings.display.ambient.AmbientDisplayStorage
import com.android.settings.display.ambient.AmbientDisplayTopIntroPreference
import com.android.settings.display.ambient.AmbientWallpaperOptionsCategory
import com.android.settings.display.ambient.AmbientWallpaperPreference
import com.android.settings.metrics.PreferenceActionMetricsProvider
import com.android.settings.restriction.PreferenceRestrictionMixin
@@ -41,6 +41,7 @@ import com.android.settingslib.datastore.KeyValueStore
import com.android.settingslib.datastore.SettingsSecureStore
import com.android.settingslib.metadata.BooleanValuePreference
import com.android.settingslib.metadata.PreferenceAvailabilityProvider
import com.android.settingslib.metadata.PreferenceCategory as Category
import com.android.settingslib.metadata.PreferenceLifecycleContext
import com.android.settingslib.metadata.PreferenceLifecycleProvider
import com.android.settingslib.metadata.PreferenceMetadata
@@ -57,7 +58,7 @@ import com.android.systemui.shared.Flags.ambientAod
 * subpage for additional related settings.
 */
@ProvidePreferenceScreen(AmbientDisplayAlwaysOnPreferenceScreen.KEY)
open class AmbientDisplayAlwaysOnPreferenceScreen :
open class AmbientDisplayAlwaysOnPreferenceScreen(context: Context) :
    PreferenceScreenMixin,
    BooleanValuePreference,
    PrimarySwitchPreferenceBinding,
@@ -67,7 +68,7 @@ open class AmbientDisplayAlwaysOnPreferenceScreen :
    PreferenceLifecycleProvider,
    PreferenceSummaryProvider {

    private val ambientWallpaperPreference = AmbientWallpaperPreference()
    private val ambientWallpaperPreference = AmbientWallpaperPreference(context)

    override val title: Int
        get() = if (ambientAod()) R.string.doze_always_on_title2 else R.string.doze_always_on_title
@@ -105,8 +106,8 @@ open class AmbientDisplayAlwaysOnPreferenceScreen :
        context.getText(
            if (isAodSuppressedByBedtime(context)) {
                R.string.aware_summary_when_bedtime_on
            } else if (ambientWallpaperPreference.isAvailable(context)) {
                if (ambientWallpaperPreference.isChecked(context)) {
            } else if (context.isAmbientWallpaperOptionsAvailable) {
                if (ambientWallpaperPreference.isChecked()) {
                    R.string.doze_always_on_summary_with_wallpaper
                } else {
                    R.string.doze_always_on_summary_without_wallpaper
@@ -133,7 +134,11 @@ open class AmbientDisplayAlwaysOnPreferenceScreen :
        preferenceHierarchy(context, this) {
            +AmbientDisplayTopIntroPreference()
            +AmbientDisplayMainSwitchPreference()
            +AmbientWallpaperOptionsCategory() += { +ambientWallpaperPreference }
            if (context.isAmbientWallpaperOptionsAvailable) {
                +Category("ambient_wallpaperGroup", R.string.doze_always_on_wallpaper_options) += {
                    +ambientWallpaperPreference
                }
            }
        }

    override fun storage(context: Context): KeyValueStore = AmbientDisplayStorage(context)
@@ -154,6 +159,9 @@ open class AmbientDisplayAlwaysOnPreferenceScreen :
    companion object {
        const val KEY = "ambient_display_always_on_screen"
        const val PROP_AWARE_AVAILABLE = "ro.vendor.aware_available"

        private val Context.isAmbientWallpaperOptionsAvailable: Boolean
            get() = ambientAod() && resources.getBoolean(config_dozeSupportsAodWallpaper)
    }
}

+0 −31
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.settings.display.ambient

import android.content.Context
import com.android.internal.R as InternalR
import com.android.settings.R
import com.android.settingslib.metadata.PreferenceAvailabilityProvider
import com.android.settingslib.metadata.PreferenceCategory
import com.android.systemui.shared.Flags.ambientAod

class AmbientWallpaperOptionsCategory :
    PreferenceCategory("ambient_wallpaperGroup", R.string.doze_always_on_wallpaper_options),
    PreferenceAvailabilityProvider {

    override fun isAvailable(context: Context): Boolean =
        ambientAod() && context.resources.getBoolean(InternalR.bool.config_dozeSupportsAodWallpaper)
}
+9 −38
Original line number Diff line number Diff line
@@ -17,57 +17,28 @@ package com.android.settings.display.ambient

import android.content.Context
import android.provider.Settings.Secure.DOZE_ALWAYS_ON_WALLPAPER_ENABLED
import com.android.internal.R as InternalR
import com.android.settings.R
import com.android.settings.display.AmbientDisplayAlwaysOnPreference
import com.android.settingslib.datastore.KeyValueStore
import com.android.settingslib.datastore.KeyValueStoreDelegate
import com.android.settingslib.datastore.KeyedObserver
import com.android.settingslib.datastore.SettingsSecureStore
import com.android.settingslib.metadata.PreferenceAvailabilityProvider
import com.android.settingslib.metadata.SwitchPreference
import com.android.systemui.shared.Flags.ambientAod

class AmbientWallpaperPreference :
class AmbientWallpaperPreference(context: Context) :
    SwitchPreference(
        KEY,
        R.string.doze_always_on_wallpaper_title,
        R.string.doze_always_on_wallpaper_description,
    ),
    PreferenceAvailabilityProvider {
    ) {

    override fun isAvailable(context: Context): Boolean =
        ambientAod() && context.resources.getBoolean(InternalR.bool.config_dozeSupportsAodWallpaper)
    private val dataStore = context.dataStore

    override fun storage(context: Context): KeyValueStore =
        Storage(SettingsSecureStore.get(context))
    override fun storage(context: Context) = dataStore

    fun isChecked(context: Context) = isAvailable(context) && storage(context).getBoolean(KEY)!!

    @Suppress("UNCHECKED_CAST")
    private class Storage(private val settingsStore: KeyValueStore) :
        KeyValueStoreDelegate, KeyedObserver<String> {

        override val keyValueStoreDelegate
            get() = settingsStore

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

        override fun <T : Any> getDefaultValue(key: String, valueType: Class<T>) = true as T

        override fun <T : Any> getValue(key: String, valueType: Class<T>) =
            settingsStore.getValue(key, valueType) ?: getDefaultValue(key, valueType)

        override fun <T : Any> setValue(key: String, valueType: Class<T>, value: T?) =
            settingsStore.setValue(key, valueType, value)

        override fun onKeyChanged(key: String, reason: Int) {
            notifyChange(AmbientDisplayAlwaysOnPreference.KEY, reason)
            notifyChange(AmbientDisplayMainSwitchPreference.KEY, reason)
        }
    }
    fun isChecked() = dataStore.getBoolean(KEY)!!

    companion object {
        val KEY = DOZE_ALWAYS_ON_WALLPAPER_ENABLED
        const val KEY = DOZE_ALWAYS_ON_WALLPAPER_ENABLED

        private val Context.dataStore: KeyValueStore
            get() = SettingsSecureStore.get(this).apply { setDefaultValue(KEY, true) }
    }
}