Added temporary screen brightness strategy
Bug: 260061783 Test: atest com.android.server.display Change-Id: I9386ffce6cbecf13abaf14b25810f6f415c963cc
This commit is contained in:
@@ -299,7 +299,6 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
|
||||
private boolean mAppliedAutoBrightness;
|
||||
private boolean mAppliedDimming;
|
||||
private boolean mAppliedLowPower;
|
||||
private boolean mAppliedTemporaryBrightness;
|
||||
private boolean mAppliedTemporaryAutoBrightnessAdjustment;
|
||||
private boolean mAppliedBrightnessBoost;
|
||||
private boolean mAppliedThrottling;
|
||||
@@ -395,11 +394,6 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
|
||||
// behalf of the user.
|
||||
private float mCurrentScreenBrightnessSetting;
|
||||
|
||||
// The temporary screen brightness. Typically set when a user is interacting with the
|
||||
// brightness slider but hasn't settled on a choice yet. Set to
|
||||
// PowerManager.BRIGHTNESS_INVALID_FLOAT when there's no temporary brightness set.
|
||||
private float mTemporaryScreenBrightness;
|
||||
|
||||
// The current screen brightness while in VR mode.
|
||||
private float mScreenBrightnessForVr;
|
||||
|
||||
@@ -566,7 +560,6 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
|
||||
mCurrentScreenBrightnessSetting = getScreenBrightnessSetting();
|
||||
mScreenBrightnessForVr = getScreenBrightnessForVrSetting();
|
||||
mAutoBrightnessAdjustment = getAutoBrightnessAdjustmentSetting();
|
||||
mTemporaryScreenBrightness = PowerManager.BRIGHTNESS_INVALID_FLOAT;
|
||||
mPendingScreenBrightnessSetting = PowerManager.BRIGHTNESS_INVALID_FLOAT;
|
||||
mTemporaryAutoBrightnessAdjustment = PowerManager.BRIGHTNESS_INVALID_FLOAT;
|
||||
mPendingAutoBrightnessAdjustment = PowerManager.BRIGHTNESS_INVALID_FLOAT;
|
||||
@@ -1218,16 +1211,6 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
|
||||
|
||||
final boolean userSetBrightnessChanged = updateUserSetScreenBrightness();
|
||||
|
||||
// Use the temporary screen brightness if there isn't an override, either from
|
||||
// WindowManager or based on the display state.
|
||||
if (isValidBrightnessValue(mTemporaryScreenBrightness)) {
|
||||
brightnessState = mTemporaryScreenBrightness;
|
||||
mAppliedTemporaryBrightness = true;
|
||||
mBrightnessReasonTemp.setReason(BrightnessReason.REASON_TEMPORARY);
|
||||
} else {
|
||||
mAppliedTemporaryBrightness = false;
|
||||
}
|
||||
|
||||
final boolean autoBrightnessAdjustmentChanged = updateAutoBrightnessAdjustment();
|
||||
|
||||
// Use the autobrightness adjustment override if set.
|
||||
@@ -1414,7 +1397,8 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
|
||||
// Skip the animation when the screen is off or suspended or transition to/from VR.
|
||||
boolean brightnessAdjusted = false;
|
||||
final boolean brightnessIsTemporary =
|
||||
mAppliedTemporaryBrightness || mAppliedTemporaryAutoBrightnessAdjustment;
|
||||
(mBrightnessReason.getReason() == BrightnessReason.REASON_TEMPORARY)
|
||||
|| mAppliedTemporaryAutoBrightnessAdjustment;
|
||||
if (!mPendingScreenOff) {
|
||||
if (mSkipScreenOnBrightnessRamp) {
|
||||
if (state == Display.STATE_ON) {
|
||||
@@ -2202,13 +2186,15 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
|
||||
}
|
||||
if (mCurrentScreenBrightnessSetting == mPendingScreenBrightnessSetting) {
|
||||
mPendingScreenBrightnessSetting = PowerManager.BRIGHTNESS_INVALID_FLOAT;
|
||||
mTemporaryScreenBrightness = PowerManager.BRIGHTNESS_INVALID_FLOAT;
|
||||
mDisplayBrightnessController
|
||||
.setTemporaryBrightness(PowerManager.BRIGHTNESS_INVALID_FLOAT);
|
||||
return false;
|
||||
}
|
||||
setCurrentScreenBrightness(mPendingScreenBrightnessSetting);
|
||||
mLastUserSetScreenBrightness = mPendingScreenBrightnessSetting;
|
||||
mPendingScreenBrightnessSetting = PowerManager.BRIGHTNESS_INVALID_FLOAT;
|
||||
mTemporaryScreenBrightness = PowerManager.BRIGHTNESS_INVALID_FLOAT;
|
||||
mDisplayBrightnessController
|
||||
.setTemporaryBrightness(PowerManager.BRIGHTNESS_INVALID_FLOAT);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -2291,7 +2277,6 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
|
||||
pw.println(" mLastUserSetScreenBrightness=" + mLastUserSetScreenBrightness);
|
||||
pw.println(" mPendingScreenBrightnessSetting="
|
||||
+ mPendingScreenBrightnessSetting);
|
||||
pw.println(" mTemporaryScreenBrightness=" + mTemporaryScreenBrightness);
|
||||
pw.println(" mAutoBrightnessAdjustment=" + mAutoBrightnessAdjustment);
|
||||
pw.println(" mBrightnessReason=" + mBrightnessReason);
|
||||
pw.println(" mTemporaryAutoBrightnessAdjustment=" + mTemporaryAutoBrightnessAdjustment);
|
||||
@@ -2301,7 +2286,6 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
|
||||
pw.println(" mAppliedDimming=" + mAppliedDimming);
|
||||
pw.println(" mAppliedLowPower=" + mAppliedLowPower);
|
||||
pw.println(" mAppliedThrottling=" + mAppliedThrottling);
|
||||
pw.println(" mAppliedTemporaryBrightness=" + mAppliedTemporaryBrightness);
|
||||
pw.println(" mAppliedTemporaryAutoBrightnessAdjustment="
|
||||
+ mAppliedTemporaryAutoBrightnessAdjustment);
|
||||
pw.println(" mAppliedBrightnessBoost=" + mAppliedBrightnessBoost);
|
||||
@@ -2541,7 +2525,8 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
|
||||
|
||||
case MSG_SET_TEMPORARY_BRIGHTNESS:
|
||||
// TODO: Should we have a a timeout for the temporary brightness?
|
||||
mTemporaryScreenBrightness = Float.intBitsToFloat(msg.arg1);
|
||||
mDisplayBrightnessController
|
||||
.setTemporaryBrightness(Float.intBitsToFloat(msg.arg1));
|
||||
updatePowerState();
|
||||
break;
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ public final class BrightnessUtils {
|
||||
* Checks whether the brightness is within the valid brightness range, not including off.
|
||||
*/
|
||||
public static boolean isValidBrightnessValue(float brightness) {
|
||||
return brightness >= PowerManager.BRIGHTNESS_MIN
|
||||
return !Float.isNaN(brightness) && brightness >= PowerManager.BRIGHTNESS_MIN
|
||||
&& brightness <= PowerManager.BRIGHTNESS_MAX;
|
||||
}
|
||||
|
||||
|
||||
@@ -67,6 +67,21 @@ public final class DisplayBrightnessController {
|
||||
return mDisplayBrightnessStrategy.updateBrightness(displayPowerRequest);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the temporary brightness
|
||||
*/
|
||||
public void setTemporaryBrightness(Float temporaryBrightness) {
|
||||
mDisplayBrightnessStrategySelector.getTemporaryDisplayBrightnessStrategy()
|
||||
.setTemporaryScreenBrightness(temporaryBrightness);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current selected DisplayBrightnessStrategy
|
||||
*/
|
||||
public DisplayBrightnessStrategy getCurrentDisplayBrightnessStrategy() {
|
||||
return mDisplayBrightnessStrategy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a boolean flag indicating if the light sensor is to be used to decide the screen
|
||||
* brightness when dozing
|
||||
|
||||
@@ -19,6 +19,7 @@ package com.android.server.display.brightness;
|
||||
import android.annotation.NonNull;
|
||||
import android.content.Context;
|
||||
import android.hardware.display.DisplayManagerInternal;
|
||||
import android.util.IndentingPrintWriter;
|
||||
import android.util.Slog;
|
||||
import android.view.Display;
|
||||
|
||||
@@ -29,6 +30,7 @@ import com.android.server.display.brightness.strategy.DozeBrightnessStrategy;
|
||||
import com.android.server.display.brightness.strategy.InvalidBrightnessStrategy;
|
||||
import com.android.server.display.brightness.strategy.OverrideBrightnessStrategy;
|
||||
import com.android.server.display.brightness.strategy.ScreenOffBrightnessStrategy;
|
||||
import com.android.server.display.brightness.strategy.TemporaryBrightnessStrategy;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
|
||||
@@ -48,7 +50,9 @@ public class DisplayBrightnessStrategySelector {
|
||||
// The brightness strategy used to manage the brightness state when the request state is
|
||||
// invalid.
|
||||
private final OverrideBrightnessStrategy mOverrideBrightnessStrategy;
|
||||
// The brightness strategy used to manage the brightness state request is invalid.
|
||||
// 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 the request is invalid.
|
||||
private final InvalidBrightnessStrategy mInvalidBrightnessStrategy;
|
||||
|
||||
// We take note of the old brightness strategy so that we can know when the strategy changes.
|
||||
@@ -67,6 +71,7 @@ public class DisplayBrightnessStrategySelector {
|
||||
mDozeBrightnessStrategy = injector.getDozeBrightnessStrategy();
|
||||
mScreenOffBrightnessStrategy = injector.getScreenOffBrightnessStrategy();
|
||||
mOverrideBrightnessStrategy = injector.getOverrideBrightnessStrategy();
|
||||
mTemporaryBrightnessStrategy = injector.getTemporaryBrightnessStrategy();
|
||||
mInvalidBrightnessStrategy = injector.getInvalidBrightnessStrategy();
|
||||
mAllowAutoBrightnessWhileDozingConfig = context.getResources().getBoolean(
|
||||
R.bool.config_allowAutoBrightnessWhileDozing);
|
||||
@@ -89,6 +94,9 @@ public class DisplayBrightnessStrategySelector {
|
||||
} else if (BrightnessUtils
|
||||
.isValidBrightnessValue(displayPowerRequest.screenBrightnessOverride)) {
|
||||
displayBrightnessStrategy = mOverrideBrightnessStrategy;
|
||||
} else if (BrightnessUtils.isValidBrightnessValue(
|
||||
mTemporaryBrightnessStrategy.getTemporaryScreenBrightness())) {
|
||||
displayBrightnessStrategy = mTemporaryBrightnessStrategy;
|
||||
}
|
||||
|
||||
if (!mOldBrightnessStrategyName.equals(displayBrightnessStrategy.getName())) {
|
||||
@@ -101,6 +109,10 @@ public class DisplayBrightnessStrategySelector {
|
||||
return displayBrightnessStrategy;
|
||||
}
|
||||
|
||||
public TemporaryBrightnessStrategy getTemporaryDisplayBrightnessStrategy() {
|
||||
return mTemporaryBrightnessStrategy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a boolean flag indicating if the light sensor is to be used to decide the screen
|
||||
* brightness when dozing
|
||||
@@ -120,6 +132,8 @@ public class DisplayBrightnessStrategySelector {
|
||||
writer.println(
|
||||
" mAllowAutoBrightnessWhileDozingConfig= "
|
||||
+ mAllowAutoBrightnessWhileDozingConfig);
|
||||
IndentingPrintWriter ipw = new IndentingPrintWriter(writer, " ");
|
||||
mTemporaryBrightnessStrategy.dump(ipw);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -152,6 +166,10 @@ public class DisplayBrightnessStrategySelector {
|
||||
return new OverrideBrightnessStrategy();
|
||||
}
|
||||
|
||||
TemporaryBrightnessStrategy getTemporaryBrightnessStrategy() {
|
||||
return new TemporaryBrightnessStrategy();
|
||||
}
|
||||
|
||||
InvalidBrightnessStrategy getInvalidBrightnessStrategy() {
|
||||
return new InvalidBrightnessStrategy();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
|
||||
/**
|
||||
* Manages the brightness of the display when the system brightness is temporary
|
||||
*/
|
||||
public class TemporaryBrightnessStrategy implements DisplayBrightnessStrategy {
|
||||
// The temporary screen brightness. Typically set when a user is interacting with the
|
||||
// brightness slider but hasn't settled on a choice yet. Set to
|
||||
// PowerManager.BRIGHTNESS_INVALID_FLOAT when there's no temporary brightness set.
|
||||
private float mTemporaryScreenBrightness;
|
||||
|
||||
public TemporaryBrightnessStrategy() {
|
||||
mTemporaryScreenBrightness = PowerManager.BRIGHTNESS_INVALID_FLOAT;
|
||||
}
|
||||
|
||||
// Use the temporary screen brightness if there isn't an override, either from
|
||||
// WindowManager or based on the display state.
|
||||
@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_TEMPORARY,
|
||||
mTemporaryScreenBrightness,
|
||||
mTemporaryScreenBrightness);
|
||||
mTemporaryScreenBrightness = Float.NaN;
|
||||
return displayBrightnessState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "TemporaryBrightnessStrategy";
|
||||
}
|
||||
|
||||
public float getTemporaryScreenBrightness() {
|
||||
return mTemporaryScreenBrightness;
|
||||
}
|
||||
|
||||
public void setTemporaryScreenBrightness(float temporaryScreenBrightness) {
|
||||
mTemporaryScreenBrightness = temporaryScreenBrightness;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dumps the state of this class.
|
||||
*/
|
||||
public void dump(PrintWriter writer) {
|
||||
writer.println("TemporaryBrightnessStrategy:");
|
||||
writer.println(" mTemporaryScreenBrightness:" + mTemporaryScreenBrightness);
|
||||
}
|
||||
}
|
||||
@@ -33,6 +33,7 @@ import com.android.server.display.brightness.strategy.DozeBrightnessStrategy;
|
||||
import com.android.server.display.brightness.strategy.InvalidBrightnessStrategy;
|
||||
import com.android.server.display.brightness.strategy.OverrideBrightnessStrategy;
|
||||
import com.android.server.display.brightness.strategy.ScreenOffBrightnessStrategy;
|
||||
import com.android.server.display.brightness.strategy.TemporaryBrightnessStrategy;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -53,6 +54,8 @@ public final class DisplayBrightnessStrategySelectorTest {
|
||||
@Mock
|
||||
private OverrideBrightnessStrategy mOverrideBrightnessStrategy;
|
||||
@Mock
|
||||
private TemporaryBrightnessStrategy mTemporaryBrightnessStrategy;
|
||||
@Mock
|
||||
private InvalidBrightnessStrategy mInvalidBrightnessStrategy;
|
||||
@Mock
|
||||
private Context mContext;
|
||||
@@ -65,6 +68,7 @@ public final class DisplayBrightnessStrategySelectorTest {
|
||||
public void before() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
when(mContext.getResources()).thenReturn(mResources);
|
||||
when(mInvalidBrightnessStrategy.getName()).thenReturn("InvalidBrightnessStrategy");
|
||||
DisplayBrightnessStrategySelector.Injector injector =
|
||||
new DisplayBrightnessStrategySelector.Injector() {
|
||||
@Override
|
||||
@@ -82,6 +86,11 @@ public final class DisplayBrightnessStrategySelectorTest {
|
||||
return mOverrideBrightnessStrategy;
|
||||
}
|
||||
|
||||
@Override
|
||||
TemporaryBrightnessStrategy getTemporaryBrightnessStrategy() {
|
||||
return mTemporaryBrightnessStrategy;
|
||||
}
|
||||
|
||||
@Override
|
||||
InvalidBrightnessStrategy getInvalidBrightnessStrategy() {
|
||||
return mInvalidBrightnessStrategy;
|
||||
@@ -120,6 +129,16 @@ public final class DisplayBrightnessStrategySelectorTest {
|
||||
Display.STATE_ON), mOverrideBrightnessStrategy);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void selectStrategySelectsTemporaryStrategyWhenValid() {
|
||||
DisplayManagerInternal.DisplayPowerRequest displayPowerRequest = mock(
|
||||
DisplayManagerInternal.DisplayPowerRequest.class);
|
||||
displayPowerRequest.screenBrightnessOverride = Float.NaN;
|
||||
when(mTemporaryBrightnessStrategy.getTemporaryScreenBrightness()).thenReturn(0.3f);
|
||||
assertEquals(mDisplayBrightnessStrategySelector.selectStrategy(displayPowerRequest,
|
||||
Display.STATE_ON), mTemporaryBrightnessStrategy);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void selectStrategySelectsInvalidStrategyWhenNoStrategyIsValid() {
|
||||
DisplayManagerInternal.DisplayPowerRequest displayPowerRequest = mock(
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* 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 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 TemporaryBrightnessStrategyTest {
|
||||
private TemporaryBrightnessStrategy mTemporaryBrightnessStrategy;
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
mTemporaryBrightnessStrategy = new TemporaryBrightnessStrategy();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateBrightnessWorksAsExpectedWhenTemporaryBrightnessIsSet() {
|
||||
DisplayManagerInternal.DisplayPowerRequest
|
||||
displayPowerRequest = new DisplayManagerInternal.DisplayPowerRequest();
|
||||
float temporaryBrightness = 0.2f;
|
||||
mTemporaryBrightnessStrategy.setTemporaryScreenBrightness(temporaryBrightness);
|
||||
BrightnessReason brightnessReason = new BrightnessReason();
|
||||
brightnessReason.setReason(BrightnessReason.REASON_TEMPORARY);
|
||||
DisplayBrightnessState expectedDisplayBrightnessState =
|
||||
new DisplayBrightnessState.Builder()
|
||||
.setBrightness(temporaryBrightness)
|
||||
.setBrightnessReason(brightnessReason)
|
||||
.setSdrBrightness(temporaryBrightness)
|
||||
.build();
|
||||
DisplayBrightnessState updatedDisplayBrightnessState =
|
||||
mTemporaryBrightnessStrategy.updateBrightness(displayPowerRequest);
|
||||
assertEquals(updatedDisplayBrightnessState, expectedDisplayBrightnessState);
|
||||
assertEquals(mTemporaryBrightnessStrategy.getTemporaryScreenBrightness(),
|
||||
Float.NaN, 0.0f);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user