Loading services/core/java/com/android/server/display/DisplayBrightnessState.java +33 −3 Original line number Diff line number Diff line Loading @@ -33,12 +33,15 @@ public final class DisplayBrightnessState { private final String mDisplayBrightnessStrategyName; private final boolean mShouldUseAutoBrightness; private final boolean mIsSlowChange; private DisplayBrightnessState(Builder builder) { mBrightness = builder.getBrightness(); mSdrBrightness = builder.getSdrBrightness(); mBrightnessReason = builder.getBrightnessReason(); mDisplayBrightnessStrategyName = builder.getDisplayBrightnessStrategyName(); mShouldUseAutoBrightness = builder.getShouldUseAutoBrightness(); mIsSlowChange = builder.isSlowChange(); } /** Loading Loading @@ -77,6 +80,13 @@ public final class DisplayBrightnessState { return mShouldUseAutoBrightness; } /** * @return {@code true} if the should transit to new state slowly */ public boolean isSlowChange() { return mIsSlowChange; } @Override public String toString() { StringBuilder stringBuilder = new StringBuilder("DisplayBrightnessState:"); Loading @@ -88,6 +98,8 @@ public final class DisplayBrightnessState { stringBuilder.append(getBrightnessReason()); stringBuilder.append("\n shouldUseAutoBrightness:"); stringBuilder.append(getShouldUseAutoBrightness()); stringBuilder.append("\n isSlowChange:"); stringBuilder.append(mIsSlowChange); return stringBuilder.toString(); } Loading @@ -111,13 +123,14 @@ public final class DisplayBrightnessState { && mBrightnessReason.equals(otherState.getBrightnessReason()) && TextUtils.equals(mDisplayBrightnessStrategyName, otherState.getDisplayBrightnessStrategyName()) && mShouldUseAutoBrightness == otherState.getShouldUseAutoBrightness(); && mShouldUseAutoBrightness == otherState.getShouldUseAutoBrightness() && mIsSlowChange == otherState.isSlowChange(); } @Override public int hashCode() { return Objects.hash( mBrightness, mSdrBrightness, mBrightnessReason, mShouldUseAutoBrightness); return Objects.hash(mBrightness, mSdrBrightness, mBrightnessReason, mShouldUseAutoBrightness, mIsSlowChange); } /** Loading @@ -129,6 +142,7 @@ public final class DisplayBrightnessState { private BrightnessReason mBrightnessReason = new BrightnessReason(); private String mDisplayBrightnessStrategyName; private boolean mShouldUseAutoBrightness; private boolean mIsSlowChange; /** * Create a builder starting with the values from the specified {@link Loading @@ -143,6 +157,7 @@ public final class DisplayBrightnessState { builder.setBrightnessReason(state.getBrightnessReason()); builder.setDisplayBrightnessStrategyName(state.getDisplayBrightnessStrategyName()); builder.setShouldUseAutoBrightness(state.getShouldUseAutoBrightness()); builder.setIsSlowChange(state.isSlowChange()); return builder; } Loading Loading @@ -236,6 +251,21 @@ public final class DisplayBrightnessState { return mShouldUseAutoBrightness; } /** * See {@link DisplayBrightnessState#isSlowChange()}. */ public Builder setIsSlowChange(boolean shouldUseAutoBrightness) { this.mIsSlowChange = shouldUseAutoBrightness; return this; } /** * See {@link DisplayBrightnessState#isSlowChange()}. */ public boolean isSlowChange() { return mIsSlowChange; } /** * This is used to construct an immutable DisplayBrightnessState object from its builder */ Loading services/core/java/com/android/server/display/DisplayPowerController2.java +7 −14 Original line number Diff line number Diff line Loading @@ -442,9 +442,6 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal @Nullable private BrightnessMappingStrategy mIdleModeBrightnessMapper; // Indicates whether we should ramp slowly to the brightness value to follow. private boolean mBrightnessToFollowSlowChange; private boolean mIsRbcActive; // Animators. Loading Loading @@ -1289,7 +1286,7 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal // actual state instead of the desired one. animateScreenStateChange(state, mDisplayStateController.shouldPerformScreenOffTransition()); state = mPowerState.getScreenState(); boolean slowChange = false; final boolean userSetBrightnessChanged = mDisplayBrightnessController .updateUserSetScreenBrightness(); Loading @@ -1298,11 +1295,7 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal float brightnessState = displayBrightnessState.getBrightness(); float rawBrightnessState = displayBrightnessState.getBrightness(); mBrightnessReasonTemp.set(displayBrightnessState.getBrightnessReason()); if (displayBrightnessState.getBrightnessReason().getReason() == BrightnessReason.REASON_FOLLOWER) { slowChange = mBrightnessToFollowSlowChange; } boolean slowChange = displayBrightnessState.isSlowChange(); // Set up the ScreenOff controller used when coming out of SCREEN_OFF and the ALS sensor // doesn't yet have a valid lux value to use with auto-brightness. Loading Loading @@ -1352,6 +1345,7 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal .getRawAutomaticScreenBrightness(); brightnessState = clampScreenBrightness(brightnessState); // slowly adapt to auto-brightness // TODO(b/253226419): slowChange should be decided by strategy.updateBrightness slowChange = mAutomaticBrightnessStrategy.hasAppliedAutoBrightness() && !mAutomaticBrightnessStrategy.getAutoBrightnessAdjustmentChanged(); brightnessAdjustmentFlags = Loading Loading @@ -2256,17 +2250,17 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal boolean slowChange) { mBrightnessRangeController.onAmbientLuxChange(ambientLux); if (nits < 0) { mDisplayBrightnessController.setBrightnessToFollow(leadDisplayBrightness); mDisplayBrightnessController.setBrightnessToFollow(leadDisplayBrightness, slowChange); } else { float brightness = mDisplayBrightnessController.convertToFloatScale(nits); if (BrightnessUtils.isValidBrightnessValue(brightness)) { mDisplayBrightnessController.setBrightnessToFollow(brightness); mDisplayBrightnessController.setBrightnessToFollow(brightness, slowChange); } else { // The device does not support nits mDisplayBrightnessController.setBrightnessToFollow(leadDisplayBrightness); mDisplayBrightnessController.setBrightnessToFollow(leadDisplayBrightness, slowChange); } } mBrightnessToFollowSlowChange = slowChange; sendUpdatePowerState(); } Loading Loading @@ -2406,7 +2400,6 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal pw.println(" mReportedToPolicy=" + reportedToPolicyToString(mReportedScreenStateToPolicy)); pw.println(" mIsRbcActive=" + mIsRbcActive); pw.println(" mBrightnessToFollowSlowChange=" + mBrightnessToFollowSlowChange); IndentingPrintWriter ipw = new IndentingPrintWriter(pw, " "); mAutomaticBrightnessStrategy.dump(ipw); Loading services/core/java/com/android/server/display/brightness/BrightnessUtils.java +11 −0 Original line number Diff line number Diff line Loading @@ -54,6 +54,16 @@ public final class BrightnessUtils { public static DisplayBrightnessState constructDisplayBrightnessState( int brightnessChangeReason, float brightness, float sdrBrightness, String displayBrightnessStrategyName) { return constructDisplayBrightnessState(brightnessChangeReason, brightness, sdrBrightness, displayBrightnessStrategyName, /* slowChange= */ false); } /** * A utility to construct the DisplayBrightnessState */ public static DisplayBrightnessState constructDisplayBrightnessState( int brightnessChangeReason, float brightness, float sdrBrightness, String displayBrightnessStrategyName, boolean slowChange) { BrightnessReason brightnessReason = new BrightnessReason(); brightnessReason.setReason(brightnessChangeReason); return new DisplayBrightnessState.Builder() Loading @@ -61,6 +71,7 @@ public final class BrightnessUtils { .setSdrBrightness(sdrBrightness) .setBrightnessReason(brightnessReason) .setDisplayBrightnessStrategyName(displayBrightnessStrategyName) .setIsSlowChange(slowChange) .build(); } } services/core/java/com/android/server/display/brightness/DisplayBrightnessController.java +2 −2 Original line number Diff line number Diff line Loading @@ -164,10 +164,10 @@ public final class DisplayBrightnessController { /** * Sets the brightness to follow */ public void setBrightnessToFollow(Float brightnessToFollow) { public void setBrightnessToFollow(float brightnessToFollow, boolean slowChange) { synchronized (mLock) { mDisplayBrightnessStrategySelector.getFollowerDisplayBrightnessStrategy() .setBrightnessToFollow(brightnessToFollow); .setBrightnessToFollow(brightnessToFollow, slowChange); } } Loading services/core/java/com/android/server/display/brightness/strategy/FollowerBrightnessStrategy.java +11 −2 Original line number Diff line number Diff line Loading @@ -37,9 +37,13 @@ public class FollowerBrightnessStrategy implements DisplayBrightnessStrategy { // Set to PowerManager.BRIGHTNESS_INVALID_FLOAT when there's no brightness to follow set. private float mBrightnessToFollow; // Indicates whether we should ramp slowly to the brightness value to follow. private boolean mBrightnessToFollowSlowChange; public FollowerBrightnessStrategy(int displayId) { mDisplayId = displayId; mBrightnessToFollow = PowerManager.BRIGHTNESS_INVALID_FLOAT; mBrightnessToFollowSlowChange = false; } @Override Loading @@ -48,7 +52,7 @@ public class FollowerBrightnessStrategy implements DisplayBrightnessStrategy { // Todo(b/241308599): Introduce a validator class and add validations before setting // the brightness return BrightnessUtils.constructDisplayBrightnessState(BrightnessReason.REASON_FOLLOWER, mBrightnessToFollow, mBrightnessToFollow, getName()); mBrightnessToFollow, mBrightnessToFollow, getName(), mBrightnessToFollowSlowChange); } @Override Loading @@ -60,8 +64,12 @@ public class FollowerBrightnessStrategy implements DisplayBrightnessStrategy { return mBrightnessToFollow; } public void setBrightnessToFollow(float brightnessToFollow) { /** * Updates brightness value and brightness slowChange flag **/ public void setBrightnessToFollow(float brightnessToFollow, boolean slowChange) { mBrightnessToFollow = brightnessToFollow; mBrightnessToFollowSlowChange = slowChange; } /** Loading @@ -71,5 +79,6 @@ public class FollowerBrightnessStrategy implements DisplayBrightnessStrategy { writer.println("FollowerBrightnessStrategy:"); writer.println(" mDisplayId=" + mDisplayId); writer.println(" mBrightnessToFollow:" + mBrightnessToFollow); writer.println(" mBrightnessToFollowSlowChange:" + mBrightnessToFollowSlowChange); } } Loading
services/core/java/com/android/server/display/DisplayBrightnessState.java +33 −3 Original line number Diff line number Diff line Loading @@ -33,12 +33,15 @@ public final class DisplayBrightnessState { private final String mDisplayBrightnessStrategyName; private final boolean mShouldUseAutoBrightness; private final boolean mIsSlowChange; private DisplayBrightnessState(Builder builder) { mBrightness = builder.getBrightness(); mSdrBrightness = builder.getSdrBrightness(); mBrightnessReason = builder.getBrightnessReason(); mDisplayBrightnessStrategyName = builder.getDisplayBrightnessStrategyName(); mShouldUseAutoBrightness = builder.getShouldUseAutoBrightness(); mIsSlowChange = builder.isSlowChange(); } /** Loading Loading @@ -77,6 +80,13 @@ public final class DisplayBrightnessState { return mShouldUseAutoBrightness; } /** * @return {@code true} if the should transit to new state slowly */ public boolean isSlowChange() { return mIsSlowChange; } @Override public String toString() { StringBuilder stringBuilder = new StringBuilder("DisplayBrightnessState:"); Loading @@ -88,6 +98,8 @@ public final class DisplayBrightnessState { stringBuilder.append(getBrightnessReason()); stringBuilder.append("\n shouldUseAutoBrightness:"); stringBuilder.append(getShouldUseAutoBrightness()); stringBuilder.append("\n isSlowChange:"); stringBuilder.append(mIsSlowChange); return stringBuilder.toString(); } Loading @@ -111,13 +123,14 @@ public final class DisplayBrightnessState { && mBrightnessReason.equals(otherState.getBrightnessReason()) && TextUtils.equals(mDisplayBrightnessStrategyName, otherState.getDisplayBrightnessStrategyName()) && mShouldUseAutoBrightness == otherState.getShouldUseAutoBrightness(); && mShouldUseAutoBrightness == otherState.getShouldUseAutoBrightness() && mIsSlowChange == otherState.isSlowChange(); } @Override public int hashCode() { return Objects.hash( mBrightness, mSdrBrightness, mBrightnessReason, mShouldUseAutoBrightness); return Objects.hash(mBrightness, mSdrBrightness, mBrightnessReason, mShouldUseAutoBrightness, mIsSlowChange); } /** Loading @@ -129,6 +142,7 @@ public final class DisplayBrightnessState { private BrightnessReason mBrightnessReason = new BrightnessReason(); private String mDisplayBrightnessStrategyName; private boolean mShouldUseAutoBrightness; private boolean mIsSlowChange; /** * Create a builder starting with the values from the specified {@link Loading @@ -143,6 +157,7 @@ public final class DisplayBrightnessState { builder.setBrightnessReason(state.getBrightnessReason()); builder.setDisplayBrightnessStrategyName(state.getDisplayBrightnessStrategyName()); builder.setShouldUseAutoBrightness(state.getShouldUseAutoBrightness()); builder.setIsSlowChange(state.isSlowChange()); return builder; } Loading Loading @@ -236,6 +251,21 @@ public final class DisplayBrightnessState { return mShouldUseAutoBrightness; } /** * See {@link DisplayBrightnessState#isSlowChange()}. */ public Builder setIsSlowChange(boolean shouldUseAutoBrightness) { this.mIsSlowChange = shouldUseAutoBrightness; return this; } /** * See {@link DisplayBrightnessState#isSlowChange()}. */ public boolean isSlowChange() { return mIsSlowChange; } /** * This is used to construct an immutable DisplayBrightnessState object from its builder */ Loading
services/core/java/com/android/server/display/DisplayPowerController2.java +7 −14 Original line number Diff line number Diff line Loading @@ -442,9 +442,6 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal @Nullable private BrightnessMappingStrategy mIdleModeBrightnessMapper; // Indicates whether we should ramp slowly to the brightness value to follow. private boolean mBrightnessToFollowSlowChange; private boolean mIsRbcActive; // Animators. Loading Loading @@ -1289,7 +1286,7 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal // actual state instead of the desired one. animateScreenStateChange(state, mDisplayStateController.shouldPerformScreenOffTransition()); state = mPowerState.getScreenState(); boolean slowChange = false; final boolean userSetBrightnessChanged = mDisplayBrightnessController .updateUserSetScreenBrightness(); Loading @@ -1298,11 +1295,7 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal float brightnessState = displayBrightnessState.getBrightness(); float rawBrightnessState = displayBrightnessState.getBrightness(); mBrightnessReasonTemp.set(displayBrightnessState.getBrightnessReason()); if (displayBrightnessState.getBrightnessReason().getReason() == BrightnessReason.REASON_FOLLOWER) { slowChange = mBrightnessToFollowSlowChange; } boolean slowChange = displayBrightnessState.isSlowChange(); // Set up the ScreenOff controller used when coming out of SCREEN_OFF and the ALS sensor // doesn't yet have a valid lux value to use with auto-brightness. Loading Loading @@ -1352,6 +1345,7 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal .getRawAutomaticScreenBrightness(); brightnessState = clampScreenBrightness(brightnessState); // slowly adapt to auto-brightness // TODO(b/253226419): slowChange should be decided by strategy.updateBrightness slowChange = mAutomaticBrightnessStrategy.hasAppliedAutoBrightness() && !mAutomaticBrightnessStrategy.getAutoBrightnessAdjustmentChanged(); brightnessAdjustmentFlags = Loading Loading @@ -2256,17 +2250,17 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal boolean slowChange) { mBrightnessRangeController.onAmbientLuxChange(ambientLux); if (nits < 0) { mDisplayBrightnessController.setBrightnessToFollow(leadDisplayBrightness); mDisplayBrightnessController.setBrightnessToFollow(leadDisplayBrightness, slowChange); } else { float brightness = mDisplayBrightnessController.convertToFloatScale(nits); if (BrightnessUtils.isValidBrightnessValue(brightness)) { mDisplayBrightnessController.setBrightnessToFollow(brightness); mDisplayBrightnessController.setBrightnessToFollow(brightness, slowChange); } else { // The device does not support nits mDisplayBrightnessController.setBrightnessToFollow(leadDisplayBrightness); mDisplayBrightnessController.setBrightnessToFollow(leadDisplayBrightness, slowChange); } } mBrightnessToFollowSlowChange = slowChange; sendUpdatePowerState(); } Loading Loading @@ -2406,7 +2400,6 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal pw.println(" mReportedToPolicy=" + reportedToPolicyToString(mReportedScreenStateToPolicy)); pw.println(" mIsRbcActive=" + mIsRbcActive); pw.println(" mBrightnessToFollowSlowChange=" + mBrightnessToFollowSlowChange); IndentingPrintWriter ipw = new IndentingPrintWriter(pw, " "); mAutomaticBrightnessStrategy.dump(ipw); Loading
services/core/java/com/android/server/display/brightness/BrightnessUtils.java +11 −0 Original line number Diff line number Diff line Loading @@ -54,6 +54,16 @@ public final class BrightnessUtils { public static DisplayBrightnessState constructDisplayBrightnessState( int brightnessChangeReason, float brightness, float sdrBrightness, String displayBrightnessStrategyName) { return constructDisplayBrightnessState(brightnessChangeReason, brightness, sdrBrightness, displayBrightnessStrategyName, /* slowChange= */ false); } /** * A utility to construct the DisplayBrightnessState */ public static DisplayBrightnessState constructDisplayBrightnessState( int brightnessChangeReason, float brightness, float sdrBrightness, String displayBrightnessStrategyName, boolean slowChange) { BrightnessReason brightnessReason = new BrightnessReason(); brightnessReason.setReason(brightnessChangeReason); return new DisplayBrightnessState.Builder() Loading @@ -61,6 +71,7 @@ public final class BrightnessUtils { .setSdrBrightness(sdrBrightness) .setBrightnessReason(brightnessReason) .setDisplayBrightnessStrategyName(displayBrightnessStrategyName) .setIsSlowChange(slowChange) .build(); } }
services/core/java/com/android/server/display/brightness/DisplayBrightnessController.java +2 −2 Original line number Diff line number Diff line Loading @@ -164,10 +164,10 @@ public final class DisplayBrightnessController { /** * Sets the brightness to follow */ public void setBrightnessToFollow(Float brightnessToFollow) { public void setBrightnessToFollow(float brightnessToFollow, boolean slowChange) { synchronized (mLock) { mDisplayBrightnessStrategySelector.getFollowerDisplayBrightnessStrategy() .setBrightnessToFollow(brightnessToFollow); .setBrightnessToFollow(brightnessToFollow, slowChange); } } Loading
services/core/java/com/android/server/display/brightness/strategy/FollowerBrightnessStrategy.java +11 −2 Original line number Diff line number Diff line Loading @@ -37,9 +37,13 @@ public class FollowerBrightnessStrategy implements DisplayBrightnessStrategy { // Set to PowerManager.BRIGHTNESS_INVALID_FLOAT when there's no brightness to follow set. private float mBrightnessToFollow; // Indicates whether we should ramp slowly to the brightness value to follow. private boolean mBrightnessToFollowSlowChange; public FollowerBrightnessStrategy(int displayId) { mDisplayId = displayId; mBrightnessToFollow = PowerManager.BRIGHTNESS_INVALID_FLOAT; mBrightnessToFollowSlowChange = false; } @Override Loading @@ -48,7 +52,7 @@ public class FollowerBrightnessStrategy implements DisplayBrightnessStrategy { // Todo(b/241308599): Introduce a validator class and add validations before setting // the brightness return BrightnessUtils.constructDisplayBrightnessState(BrightnessReason.REASON_FOLLOWER, mBrightnessToFollow, mBrightnessToFollow, getName()); mBrightnessToFollow, mBrightnessToFollow, getName(), mBrightnessToFollowSlowChange); } @Override Loading @@ -60,8 +64,12 @@ public class FollowerBrightnessStrategy implements DisplayBrightnessStrategy { return mBrightnessToFollow; } public void setBrightnessToFollow(float brightnessToFollow) { /** * Updates brightness value and brightness slowChange flag **/ public void setBrightnessToFollow(float brightnessToFollow, boolean slowChange) { mBrightnessToFollow = brightnessToFollow; mBrightnessToFollowSlowChange = slowChange; } /** Loading @@ -71,5 +79,6 @@ public class FollowerBrightnessStrategy implements DisplayBrightnessStrategy { writer.println("FollowerBrightnessStrategy:"); writer.println(" mDisplayId=" + mDisplayId); writer.println(" mBrightnessToFollow:" + mBrightnessToFollow); writer.println(" mBrightnessToFollowSlowChange:" + mBrightnessToFollowSlowChange); } }