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

Commit fe2f8c35 authored by Fiona Campbell's avatar Fiona Campbell Committed by Android (Google) Code Review
Browse files

Merge "Make RBC tile single use in even dimmer" into main

parents a74007e9 e941e0cf
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
@@ -30,7 +30,6 @@ import com.android.systemui.qs.tiles.impl.reducebrightness.domain.model.ReduceBr
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.toCollection
import kotlinx.coroutines.test.runCurrent
import kotlinx.coroutines.test.runTest
import org.junit.Test
@@ -56,8 +55,7 @@ class ReduceBrightColorsTileDataInteractorTest : SysuiTestCase() {
    @Test
    fun alwaysAvailable() =
        testScope.runTest {
            val availability = underTest.availability(TEST_USER).toCollection(mutableListOf())

            val availability by collectValues(underTest.availability(TEST_USER))
            assertThat(availability).hasSize(1)
            assertThat(availability.last()).isEqualTo(isAvailable)
        }
+72 −0
Original line number Diff line number Diff line
@@ -17,9 +17,13 @@
package com.android.systemui.qs.tiles.impl.reducebrightness.domain.interactor

import android.platform.test.annotations.EnabledOnRavenwood
import android.platform.test.annotations.RequiresFlagsDisabled
import android.platform.test.annotations.RequiresFlagsEnabled
import android.provider.Settings
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.internal.R
import com.android.server.display.feature.flags.Flags
import com.android.systemui.SysuiTestCase
import com.android.systemui.accessibility.reduceBrightColorsController
import com.android.systemui.kosmos.Kosmos
@@ -43,11 +47,22 @@ class ReduceBrightColorsTileUserActionInteractorTest : SysuiTestCase() {

    private val underTest =
        ReduceBrightColorsTileUserActionInteractor(
            context.resources,
            inputHandler,
            controller,
        )

    private val underTestEvenDimmerEnabled =
        ReduceBrightColorsTileUserActionInteractor(
            context.orCreateTestableResources
                .apply { addOverride(R.bool.config_evenDimmerEnabled, true) }
                .resources,
            inputHandler,
            controller,
        )

    @Test
    @RequiresFlagsDisabled(Flags.FLAG_EVEN_DIMMER)
    fun handleClickWhenEnabled() = runTest {
        val wasEnabled = true
        controller.isReduceBrightColorsActivated = wasEnabled
@@ -58,6 +73,7 @@ class ReduceBrightColorsTileUserActionInteractorTest : SysuiTestCase() {
    }

    @Test
    @RequiresFlagsDisabled(Flags.FLAG_EVEN_DIMMER)
    fun handleClickWhenDisabled() = runTest {
        val wasEnabled = false
        controller.isReduceBrightColorsActivated = wasEnabled
@@ -68,6 +84,7 @@ class ReduceBrightColorsTileUserActionInteractorTest : SysuiTestCase() {
    }

    @Test
    @RequiresFlagsDisabled(Flags.FLAG_EVEN_DIMMER)
    fun handleLongClickWhenDisabled() = runTest {
        val enabled = false

@@ -79,6 +96,7 @@ class ReduceBrightColorsTileUserActionInteractorTest : SysuiTestCase() {
    }

    @Test
    @RequiresFlagsDisabled(Flags.FLAG_EVEN_DIMMER)
    fun handleLongClickWhenEnabled() = runTest {
        val enabled = true

@@ -88,4 +106,58 @@ class ReduceBrightColorsTileUserActionInteractorTest : SysuiTestCase() {
            assertThat(it.intent.action).isEqualTo(Settings.ACTION_REDUCE_BRIGHT_COLORS_SETTINGS)
        }
    }

    @Test
    @RequiresFlagsEnabled(Flags.FLAG_EVEN_DIMMER)
    fun handleClickWhenEnabledEvenDimmer() = runTest {
        val wasEnabled = true
        controller.isReduceBrightColorsActivated = wasEnabled

        underTestEvenDimmerEnabled.handleInput(
            QSTileInputTestKtx.click(ReduceBrightColorsTileModel(wasEnabled))
        )

        assertThat(controller.isReduceBrightColorsActivated).isEqualTo(wasEnabled)
    }

    @Test
    @RequiresFlagsEnabled(Flags.FLAG_EVEN_DIMMER)
    fun handleClickWhenDisabledEvenDimmer() = runTest {
        val wasEnabled = false
        controller.isReduceBrightColorsActivated = wasEnabled

        underTestEvenDimmerEnabled.handleInput(
            QSTileInputTestKtx.click(ReduceBrightColorsTileModel(wasEnabled))
        )

        assertThat(controller.isReduceBrightColorsActivated).isEqualTo(wasEnabled)
    }

    @Test
    @RequiresFlagsEnabled(Flags.FLAG_EVEN_DIMMER)
    fun handleLongClickWhenDisabledEvenDimmer() = runTest {
        val enabled = false

        underTestEvenDimmerEnabled.handleInput(
            QSTileInputTestKtx.longClick(ReduceBrightColorsTileModel(enabled))
        )

        QSTileIntentUserInputHandlerSubject.assertThat(inputHandler).handledOneIntentInput {
            assertThat(it.intent.action).isEqualTo(Settings.ACTION_DISPLAY_SETTINGS)
        }
    }

    @Test
    @RequiresFlagsEnabled(Flags.FLAG_EVEN_DIMMER)
    fun handleLongClickWhenEnabledEvenDimmer() = runTest {
        val enabled = true

        underTestEvenDimmerEnabled.handleInput(
            QSTileInputTestKtx.longClick(ReduceBrightColorsTileModel(enabled))
        )

        QSTileIntentUserInputHandlerSubject.assertThat(inputHandler).handledOneIntentInput {
            assertThat(it.intent.action).isEqualTo(Settings.ACTION_DISPLAY_SETTINGS)
        }
    }
}
+17 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.systemui.qs;

import android.content.res.Resources;

import com.android.systemui.statusbar.policy.CallbackController;

public interface ReduceBrightColorsController extends
@@ -27,6 +29,14 @@ public interface ReduceBrightColorsController extends
    /** Sets the activation state of Reduce Bright Colors */
    void setReduceBrightColorsActivated(boolean activated);

    /** Sets whether Reduce Bright Colors is enabled */
    void setReduceBrightColorsFeatureAvailable(boolean enabled);

    /** Gets whether Reduce Bright Colors is enabled */
    boolean isReduceBrightColorsFeatureAvailable();

    /** Gets whether Reduce Bright Colors is being transitioned to Even Dimmer */
    boolean isInUpgradeMode(Resources resources);
    /**
     * Listener invoked whenever the Reduce Bright Colors settings are changed.
     */
@@ -38,5 +48,12 @@ public interface ReduceBrightColorsController extends
         */
        default void onActivated(boolean activated) {
        }
        /**
         * Listener invoked when the feature enabled state changes.
         *
         * @param enabled {@code true} if Reduce Bright Colors feature is enabled.
         */
        default void onFeatureEnabledChanged(boolean enabled) {
        }
    }
}
 No newline at end of file
+29 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@
package com.android.systemui.qs;

import android.content.Context;
import android.content.res.Resources;
import android.database.ContentObserver;
import android.hardware.display.ColorDisplayManager;
import android.net.Uri;
@@ -28,6 +29,7 @@ import android.provider.Settings;

import androidx.annotation.NonNull;

import com.android.server.display.feature.flags.Flags;
import com.android.systemui.dagger.SysUISingleton;
import com.android.systemui.dagger.qualifiers.Background;
import com.android.systemui.settings.UserTracker;
@@ -47,6 +49,7 @@ public class ReduceBrightColorsControllerImpl implements
    private final ContentObserver mContentObserver;
    private final SecureSettings mSecureSettings;
    private final ArrayList<ReduceBrightColorsController.Listener> mListeners = new ArrayList<>();
    private boolean mAvailable = true;

    @Inject
    public ReduceBrightColorsControllerImpl(UserTracker userTracker,
@@ -75,6 +78,7 @@ public class ReduceBrightColorsControllerImpl implements
        mCurrentUserTrackerCallback = new UserTracker.Callback() {
            @Override
            public void onUserChanged(int newUser, Context userContext) {
                mAvailable = true;
                synchronized (mListeners) {
                    if (mListeners.size() > 0) {
                        mSecureSettings.unregisterContentObserverSync(mContentObserver);
@@ -121,10 +125,35 @@ public class ReduceBrightColorsControllerImpl implements
        mManager.setReduceBrightColorsActivated(activated);
    }

    @Override
    public void setReduceBrightColorsFeatureAvailable(boolean enabled) {
        mAvailable = enabled;
        dispatchOnEnabledChanged(enabled);
        mAvailable = true;
    }

    @Override
    public boolean isReduceBrightColorsFeatureAvailable() {
        return mAvailable;
    }

    @Override
    public boolean isInUpgradeMode(Resources resources) {
        return Flags.evenDimmer() && resources.getBoolean(
                com.android.internal.R.bool.config_evenDimmerEnabled);
    }

    private void dispatchOnActivated(boolean activated) {
        ArrayList<Listener> copy = new ArrayList<>(mListeners);
        for (Listener l : copy) {
            l.onActivated(activated);
        }
    }

    private void dispatchOnEnabledChanged(boolean enabled) {
        ArrayList<Listener> copy = new ArrayList<>(mListeners);
        for (Listener l : copy) {
            l.onFeatureEnabledChanged(enabled);
        }
    }
}
+5 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import android.widget.Button;

import androidx.annotation.Nullable;

import com.android.server.display.feature.flags.Flags;
import com.android.systemui.dagger.qualifiers.Background;
import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.plugins.qs.QSTile;
@@ -116,6 +117,10 @@ public class TileQueryHelper {
        final ArrayList<QSTile> tilesToAdd = new ArrayList<>();
        possibleTiles.remove("cell");
        possibleTiles.remove("wifi");
        if (Flags.evenDimmer() && mContext.getResources().getBoolean(
                com.android.internal.R.bool.config_evenDimmerEnabled)) {
            possibleTiles.remove("reduce_brightness");
        }

        for (String spec : possibleTiles) {
            // Only add current and stock tiles that can be created from QSFactoryImpl.
Loading