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

Commit 9c59b7f8 authored by Piotr Wilczyński's avatar Piotr Wilczyński
Browse files

Only use DozeBrightnessStrategy if dozeBrightness valid

Bug: 326917509
Test: adb logcat | grep -i "brightnessEvent"
Test: atest DisplayBrightnessStrategySelectorTest
Change-Id: Ib937e7e92ef460893638211f9dd9d9daaa33de66
parent f320e4b5
Loading
Loading
Loading
Loading
+3 −6
Original line number Diff line number Diff line
@@ -200,12 +200,9 @@ public class DisplayBrightnessStrategySelector {
        // We are not checking the targetDisplayState, but rather relying on the policy because
        // a user can define a different display state(displayPowerRequest.dozeScreenState) too
        // in the request with the Doze policy
        if (displayPowerRequest.policy == DisplayManagerInternal.DisplayPowerRequest.POLICY_DOZE) {
            if (!mAllowAutoBrightnessWhileDozingConfig) {
                return true;
            }
        }
        return false;
        return displayPowerRequest.policy == DisplayManagerInternal.DisplayPowerRequest.POLICY_DOZE
                && !mAllowAutoBrightnessWhileDozingConfig
                && BrightnessUtils.isValidBrightnessValue(displayPowerRequest.dozeScreenBrightness);
    }

    @VisibleForTesting
+14 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.content.Context;
import android.content.ContextWrapper;
import android.content.res.Resources;
import android.hardware.display.DisplayManagerInternal;
import android.os.PowerManager;
import android.view.Display;

import androidx.test.core.app.ApplicationProvider;
@@ -155,12 +156,25 @@ public final class DisplayBrightnessStrategySelectorTest {
        DisplayManagerInternal.DisplayPowerRequest displayPowerRequest = mock(
                DisplayManagerInternal.DisplayPowerRequest.class);
        displayPowerRequest.policy = DisplayManagerInternal.DisplayPowerRequest.POLICY_DOZE;
        displayPowerRequest.dozeScreenBrightness = 0.2f;
        when(mResources.getBoolean(R.bool.config_allowAutoBrightnessWhileDozing)).thenReturn(
                DISALLOW_AUTO_BRIGHTNESS_WHILE_DOZING);
        assertEquals(mDisplayBrightnessStrategySelector.selectStrategy(displayPowerRequest,
                Display.STATE_DOZE), mDozeBrightnessModeStrategy);
    }

    @Test
    public void selectStrategyDoesNotSelectDozeStrategyWhenInvalidBrightness() {
        DisplayManagerInternal.DisplayPowerRequest displayPowerRequest = mock(
                DisplayManagerInternal.DisplayPowerRequest.class);
        displayPowerRequest.policy = DisplayManagerInternal.DisplayPowerRequest.POLICY_DOZE;
        displayPowerRequest.dozeScreenBrightness = PowerManager.BRIGHTNESS_INVALID_FLOAT;
        when(mResources.getBoolean(R.bool.config_allowAutoBrightnessWhileDozing)).thenReturn(
                DISALLOW_AUTO_BRIGHTNESS_WHILE_DOZING);
        assertNotEquals(mDisplayBrightnessStrategySelector.selectStrategy(displayPowerRequest,
                Display.STATE_DOZE), mDozeBrightnessModeStrategy);
    }

    @Test
    public void selectStrategySelectsScreenOffStrategyWhenValid() {
        DisplayManagerInternal.DisplayPowerRequest displayPowerRequest = mock(