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

Commit b06d0a7e authored by Rupesh Bansal's avatar Rupesh Bansal
Browse files

Added Boost brightness strategy

Bug: 260573618
Test: atest BoostBrightnessStrategyTest
Change-Id: Iea5f64355833d11c2d00c7453056a67c6279ac4d
parent 01f07725
Loading
Loading
Loading
Loading
+0 −14
Original line number Diff line number Diff line
@@ -300,7 +300,6 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
    private boolean mAppliedDimming;
    private boolean mAppliedLowPower;
    private boolean mAppliedTemporaryAutoBrightnessAdjustment;
    private boolean mAppliedBrightnessBoost;
    private boolean mAppliedThrottling;

    // Reason for which the brightness was last changed. See {@link BrightnessReason} for more
@@ -1224,18 +1223,6 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
            brightnessAdjustmentFlags = BrightnessReason.ADJUSTMENT_AUTO;
            mAppliedTemporaryAutoBrightnessAdjustment = false;
        }
        // Apply brightness boost.
        // We do this here after deciding whether auto-brightness is enabled so that we don't
        // disable the light sensor during this temporary state.  That way when boost ends we will
        // be able to resume normal auto-brightness behavior without any delay.
        if (mPowerRequest.boostScreenBrightness
                && brightnessState != PowerManager.BRIGHTNESS_OFF_FLOAT) {
            brightnessState = PowerManager.BRIGHTNESS_MAX;
            mBrightnessReasonTemp.setReason(BrightnessReason.REASON_BOOST);
            mAppliedBrightnessBoost = true;
        } else {
            mAppliedBrightnessBoost = false;
        }

        // If the brightness is already set then it's been overridden by something other than the
        // user, or is a temporary adjustment.
@@ -2288,7 +2275,6 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
        pw.println("  mAppliedThrottling=" + mAppliedThrottling);
        pw.println("  mAppliedTemporaryAutoBrightnessAdjustment="
                + mAppliedTemporaryAutoBrightnessAdjustment);
        pw.println("  mAppliedBrightnessBoost=" + mAppliedBrightnessBoost);
        pw.println("  mDozing=" + mDozing);
        pw.println("  mSkipRampState=" + skipRampStateToString(mSkipRampState));
        pw.println("  mScreenOnBlockStartRealTime=" + mScreenOnBlockStartRealTime);
+10 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.view.Display;

import com.android.internal.R;
import com.android.internal.annotations.VisibleForTesting;
import com.android.server.display.brightness.strategy.BoostBrightnessStrategy;
import com.android.server.display.brightness.strategy.DisplayBrightnessStrategy;
import com.android.server.display.brightness.strategy.DozeBrightnessStrategy;
import com.android.server.display.brightness.strategy.InvalidBrightnessStrategy;
@@ -52,6 +53,8 @@ public class DisplayBrightnessStrategySelector {
    private final OverrideBrightnessStrategy mOverrideBrightnessStrategy;
    // The brightness strategy used to manage the brightness state in temporary state
    private final TemporaryBrightnessStrategy mTemporaryBrightnessStrategy;
    // The brightness strategy used to manage the brightness state when boost is requested
    private final BoostBrightnessStrategy mBoostBrightnessStrategy;
    // The brightness strategy used to manage the brightness state when the request is invalid.
    private final InvalidBrightnessStrategy mInvalidBrightnessStrategy;

@@ -72,6 +75,7 @@ public class DisplayBrightnessStrategySelector {
        mScreenOffBrightnessStrategy = injector.getScreenOffBrightnessStrategy();
        mOverrideBrightnessStrategy = injector.getOverrideBrightnessStrategy();
        mTemporaryBrightnessStrategy = injector.getTemporaryBrightnessStrategy();
        mBoostBrightnessStrategy = injector.getBoostBrightnessStrategy();
        mInvalidBrightnessStrategy = injector.getInvalidBrightnessStrategy();
        mAllowAutoBrightnessWhileDozingConfig = context.getResources().getBoolean(
                R.bool.config_allowAutoBrightnessWhileDozing);
@@ -89,6 +93,8 @@ public class DisplayBrightnessStrategySelector {
        DisplayBrightnessStrategy displayBrightnessStrategy = mInvalidBrightnessStrategy;
        if (targetDisplayState == Display.STATE_OFF) {
            displayBrightnessStrategy = mScreenOffBrightnessStrategy;
        } else if (displayPowerRequest.boostScreenBrightness) {
            displayBrightnessStrategy = mBoostBrightnessStrategy;
        } else if (shouldUseDozeBrightnessStrategy(displayPowerRequest)) {
            displayBrightnessStrategy = mDozeBrightnessStrategy;
        } else if (BrightnessUtils
@@ -170,6 +176,10 @@ public class DisplayBrightnessStrategySelector {
            return new TemporaryBrightnessStrategy();
        }

        BoostBrightnessStrategy getBoostBrightnessStrategy() {
            return new BoostBrightnessStrategy();
        }

        InvalidBrightnessStrategy getInvalidBrightnessStrategy() {
            return new InvalidBrightnessStrategy();
        }
+50 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 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.server.display.brightness.strategy;

import android.hardware.display.DisplayManagerInternal;
import android.os.PowerManager;

import com.android.server.display.DisplayBrightnessState;
import com.android.server.display.brightness.BrightnessReason;
import com.android.server.display.brightness.BrightnessUtils;

/**
 * Manages the brightness of the display when the system brightness boost is requested.
 */
public class BoostBrightnessStrategy implements DisplayBrightnessStrategy {

    public BoostBrightnessStrategy() {
    }

    // Set the brightness to the maximum value when display brightness boost is requested
    @Override
    public DisplayBrightnessState updateBrightness(
            DisplayManagerInternal.DisplayPowerRequest displayPowerRequest) {
        // Todo(brup): Introduce a validator class and add validations before setting the brightness
        DisplayBrightnessState displayBrightnessState =
                BrightnessUtils.constructDisplayBrightnessState(BrightnessReason.REASON_BOOST,
                        PowerManager.BRIGHTNESS_MAX,
                        PowerManager.BRIGHTNESS_MAX);
        return displayBrightnessState;
    }

    @Override
    public String getName() {
        return "BoostBrightnessStrategy";
    }
}
+20 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;

import com.android.internal.R;
import com.android.server.display.brightness.strategy.BoostBrightnessStrategy;
import com.android.server.display.brightness.strategy.DozeBrightnessStrategy;
import com.android.server.display.brightness.strategy.InvalidBrightnessStrategy;
import com.android.server.display.brightness.strategy.OverrideBrightnessStrategy;
@@ -56,6 +57,8 @@ public final class DisplayBrightnessStrategySelectorTest {
    @Mock
    private TemporaryBrightnessStrategy mTemporaryBrightnessStrategy;
    @Mock
    private BoostBrightnessStrategy mBoostBrightnessStrategy;
    @Mock
    private InvalidBrightnessStrategy mInvalidBrightnessStrategy;
    @Mock
    private Context mContext;
@@ -91,6 +94,11 @@ public final class DisplayBrightnessStrategySelectorTest {
                        return mTemporaryBrightnessStrategy;
                    }

                    @Override
                    BoostBrightnessStrategy getBoostBrightnessStrategy() {
                        return mBoostBrightnessStrategy;
                    }

                    @Override
                    InvalidBrightnessStrategy getInvalidBrightnessStrategy() {
                        return mInvalidBrightnessStrategy;
@@ -139,11 +147,23 @@ public final class DisplayBrightnessStrategySelectorTest {
                Display.STATE_ON), mTemporaryBrightnessStrategy);
    }

    @Test
    public void selectStrategySelectsBoostStrategyWhenValid() {
        DisplayManagerInternal.DisplayPowerRequest displayPowerRequest = mock(
                DisplayManagerInternal.DisplayPowerRequest.class);
        displayPowerRequest.boostScreenBrightness = true;
        displayPowerRequest.screenBrightnessOverride = Float.NaN;
        when(mTemporaryBrightnessStrategy.getTemporaryScreenBrightness()).thenReturn(Float.NaN);
        assertEquals(mDisplayBrightnessStrategySelector.selectStrategy(displayPowerRequest,
                Display.STATE_ON), mBoostBrightnessStrategy);
    }

    @Test
    public void selectStrategySelectsInvalidStrategyWhenNoStrategyIsValid() {
        DisplayManagerInternal.DisplayPowerRequest displayPowerRequest = mock(
                DisplayManagerInternal.DisplayPowerRequest.class);
        displayPowerRequest.screenBrightnessOverride = Float.NaN;
        when(mTemporaryBrightnessStrategy.getTemporaryScreenBrightness()).thenReturn(Float.NaN);
        assertEquals(mDisplayBrightnessStrategySelector.selectStrategy(displayPowerRequest,
                Display.STATE_ON), mInvalidBrightnessStrategy);
    }
+64 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 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.server.display.brightness.strategy;


import static org.junit.Assert.assertEquals;

import android.hardware.display.DisplayManagerInternal;
import android.os.PowerManager;

import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;

import com.android.server.display.DisplayBrightnessState;
import com.android.server.display.brightness.BrightnessReason;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

@SmallTest
@RunWith(AndroidJUnit4.class)

public class BoostBrightnessStrategyTest {
    private BoostBrightnessStrategy mBoostBrightnessStrategy;

    @Before
    public void before() {
        mBoostBrightnessStrategy = new BoostBrightnessStrategy();
    }

    @Test
    public void updateBrightnessWorksAsExpectedWhenBoostBrightnessIsRequested() {
        DisplayManagerInternal.DisplayPowerRequest
                displayPowerRequest = new DisplayManagerInternal.DisplayPowerRequest();
        displayPowerRequest.boostScreenBrightness = true;
        BrightnessReason brightnessReason = new BrightnessReason();
        brightnessReason.setReason(BrightnessReason.REASON_BOOST);
        DisplayBrightnessState expectedDisplayBrightnessState =
                new DisplayBrightnessState.Builder()
                        .setBrightness(PowerManager.BRIGHTNESS_MAX)
                        .setBrightnessReason(brightnessReason)
                        .setSdrBrightness(PowerManager.BRIGHTNESS_MAX)
                        .build();
        DisplayBrightnessState updatedDisplayBrightnessState =
                mBoostBrightnessStrategy.updateBrightness(displayPowerRequest);
        assertEquals(updatedDisplayBrightnessState, expectedDisplayBrightnessState);
    }

}