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

Commit 03de6af4 authored by Sunny Shao's avatar Sunny Shao
Browse files

[Catalyst] Rollback the Adaptive brightness key

Let the redirect highlight function work from Turbo app.

NO_IFTTT=Catalyst migration

Test: devtool, atest AutoBrightnessScreenTest
Bug: 390525596
Flag: com.android.settings.flags.catalyst_display_settings_screen
Change-Id: Id7261d8a51368c45b7e23fee911565a226b30779
parent 1ac39a15
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -34,7 +34,7 @@
            settings:userRestriction="no_config_brightness"/>

        <com.android.settingslib.PrimarySwitchPreference
            android:key="screen_brightness_mode"
            android:key="@string/preference_key_auto_brightness"
            android:title="@string/auto_brightness_title"
            android:fragment="com.android.settings.display.AutoBrightnessSettings"
            settings:useAdminDisabledSummary="true"
+23 −7
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@ package com.android.settings.display

import android.content.Context
import android.os.UserManager
import android.provider.Settings
import android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE
import android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC
import android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL
import androidx.preference.Preference
@@ -26,8 +26,10 @@ import com.android.settings.PreferenceRestrictionMixin
import com.android.settings.R
import com.android.settings.flags.Flags
import com.android.settingslib.PrimarySwitchPreferenceBinding
import com.android.settingslib.datastore.AbstractKeyedDataObservable
import com.android.settingslib.datastore.HandlerExecutor
import com.android.settingslib.datastore.KeyValueStore
import com.android.settingslib.datastore.KeyedObservableDelegate
import com.android.settingslib.datastore.KeyedObserver
import com.android.settingslib.datastore.SettingsStore
import com.android.settingslib.datastore.SettingsSystemStore
import com.android.settingslib.metadata.BooleanValuePreference
@@ -106,18 +108,32 @@ class AutoBrightnessScreen :
     */
    @Suppress("UNCHECKED_CAST")
    private class AutoBrightnessDataStore(private val settingsStore: SettingsStore) :
        KeyedObservableDelegate<String>(settingsStore), KeyValueStore {
        AbstractKeyedDataObservable<String>(), KeyedObserver<String>, KeyValueStore {

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

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

        override fun <T : Any> getValue(key: String, valueType: Class<T>) =
            (settingsStore.getInt(key) ?: DEFAULT_VALUE).toBoolean() as T
            (settingsStore.getInt(SCREEN_BRIGHTNESS_MODE) ?: DEFAULT_VALUE).toBoolean() as T

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

        override fun onFirstObserverAdded() {
            // observe the underlying storage key
            settingsStore.addObserver(SCREEN_BRIGHTNESS_MODE, this, HandlerExecutor.main)
        }

        override fun onKeyChanged(key: String, reason: Int) {
            // forward data change to preference hierarchy key
            notifyChange(KEY, reason)
        }

        override fun onLastObserverRemoved() {
            settingsStore.removeObserver(SCREEN_BRIGHTNESS_MODE, this)
        }

        /** Converts brightness mode integer to boolean. */
        private fun Int.toBoolean() = this == SCREEN_BRIGHTNESS_MODE_AUTOMATIC
@@ -128,7 +144,7 @@ class AutoBrightnessScreen :
    }

    companion object {
        const val KEY = Settings.System.SCREEN_BRIGHTNESS_MODE
        const val KEY = "auto_brightness_entry"
        private const val DEFAULT_VALUE = SCREEN_BRIGHTNESS_MODE_MANUAL
    }
}
+5 −1
Original line number Diff line number Diff line
@@ -128,7 +128,11 @@ class AutoBrightnessScreenTest {
        }

    private fun setScreenBrightnessMode(value: Int) =
        Settings.System.putInt(context.contentResolver, AutoBrightnessScreen.KEY, value)
        Settings.System.putInt(
            context.contentResolver,
            Settings.System.SCREEN_BRIGHTNESS_MODE,
            value,
        )

    private fun getResId() =
        when {