Loading services/core/java/com/android/server/display/DisplayBrightnessState.java +33 −3 Original line number Diff line number Diff line Loading @@ -27,6 +27,8 @@ import java.util.Objects; * the DisplayBrightnessModeStrategies when updating the brightness. */ public final class DisplayBrightnessState { public static final float CUSTOM_ANIMATION_RATE_NOT_SET = -1f; private final float mBrightness; private final float mSdrBrightness; Loading @@ -37,6 +39,8 @@ public final class DisplayBrightnessState { private final boolean mIsSlowChange; private final float mCustomAnimationRate; private DisplayBrightnessState(Builder builder) { mBrightness = builder.getBrightness(); mSdrBrightness = builder.getSdrBrightness(); Loading @@ -45,6 +49,7 @@ public final class DisplayBrightnessState { mShouldUseAutoBrightness = builder.getShouldUseAutoBrightness(); mIsSlowChange = builder.isSlowChange(); mMaxBrightness = builder.getMaxBrightness(); mCustomAnimationRate = builder.getCustomAnimationRate(); } /** Loading Loading @@ -97,7 +102,12 @@ public final class DisplayBrightnessState { return mMaxBrightness; } /** * @return custom animation rate */ public float getCustomAnimationRate() { return mCustomAnimationRate; } @Override public String toString() { Loading @@ -112,6 +122,7 @@ public final class DisplayBrightnessState { stringBuilder.append(getShouldUseAutoBrightness()); stringBuilder.append("\n isSlowChange:").append(mIsSlowChange); stringBuilder.append("\n maxBrightness:").append(mMaxBrightness); stringBuilder.append("\n customAnimationRate:").append(mCustomAnimationRate); return stringBuilder.toString(); } Loading @@ -137,13 +148,14 @@ public final class DisplayBrightnessState { otherState.getDisplayBrightnessStrategyName()) && mShouldUseAutoBrightness == otherState.getShouldUseAutoBrightness() && mIsSlowChange == otherState.isSlowChange() && mMaxBrightness == otherState.getMaxBrightness(); && mMaxBrightness == otherState.getMaxBrightness() && mCustomAnimationRate == otherState.getCustomAnimationRate(); } @Override public int hashCode() { return Objects.hash(mBrightness, mSdrBrightness, mBrightnessReason, mShouldUseAutoBrightness, mIsSlowChange, mMaxBrightness); mShouldUseAutoBrightness, mIsSlowChange, mMaxBrightness, mCustomAnimationRate); } /** Loading @@ -164,6 +176,7 @@ public final class DisplayBrightnessState { private boolean mShouldUseAutoBrightness; private boolean mIsSlowChange; private float mMaxBrightness; private float mCustomAnimationRate = CUSTOM_ANIMATION_RATE_NOT_SET; /** * Create a builder starting with the values from the specified {@link Loading @@ -180,6 +193,7 @@ public final class DisplayBrightnessState { builder.setShouldUseAutoBrightness(state.getShouldUseAutoBrightness()); builder.setIsSlowChange(state.isSlowChange()); builder.setMaxBrightness(state.getMaxBrightness()); builder.setCustomAnimationRate(state.getCustomAnimationRate()); return builder; } Loading Loading @@ -303,6 +317,22 @@ public final class DisplayBrightnessState { return mMaxBrightness; } /** * See {@link DisplayBrightnessState#getCustomAnimationRate()}. */ public Builder setCustomAnimationRate(float animationRate) { this.mCustomAnimationRate = animationRate; return this; } /** * See {@link DisplayBrightnessState#getCustomAnimationRate()}. */ public float getCustomAnimationRate() { return mCustomAnimationRate; } /** * This is used to construct an immutable DisplayBrightnessState object from its builder */ Loading services/core/java/com/android/server/display/DisplayPowerController2.java +31 −8 Original line number Diff line number Diff line Loading @@ -561,8 +561,9 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal brightnessSetting, () -> postBrightnessChangeRunnable(), new HandlerExecutor(mHandler)); mBrightnessClamperController = new BrightnessClamperController(mHandler, modeChangeCallback::run, new BrightnessClamperController.DisplayDeviceData( mBrightnessClamperController = mInjector.getBrightnessClamperController( mHandler, modeChangeCallback::run, new BrightnessClamperController.DisplayDeviceData( mUniqueDisplayId, mThermalBrightnessThrottlingDataId, logicalDisplay.getPowerThrottlingDataIdLocked(), Loading Loading @@ -1353,6 +1354,8 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal float rawBrightnessState = displayBrightnessState.getBrightness(); mBrightnessReasonTemp.set(displayBrightnessState.getBrightnessReason()); boolean slowChange = displayBrightnessState.isSlowChange(); // custom transition duration float customAnimationRate = displayBrightnessState.getCustomAnimationRate(); // 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 @@ -1485,6 +1488,9 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal brightnessState = clampedState.getBrightness(); slowChange = clampedState.isSlowChange(); // faster rate wins, at this point customAnimationRate == -1, strategy does not control // customAnimationRate. Should be revisited if strategy start setting this value customAnimationRate = Math.max(customAnimationRate, clampedState.getCustomAnimationRate()); mBrightnessReasonTemp.addModifier(clampedState.getBrightnessReason().getModifier()); if (updateScreenBrightnessSetting) { Loading Loading @@ -1553,9 +1559,6 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal // allowed range. float animateValue = clampScreenBrightness(brightnessState); // custom transition duration float customTransitionRate = -1f; // If there are any HDR layers on the screen, we have a special brightness value that we // use instead. We still preserve the calculated brightness for Standard Dynamic Range // (SDR) layers, but the main brightness value will be the one for HDR. Loading @@ -1570,10 +1573,21 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal // We want to scale HDR brightness level with the SDR level, we also need to restore // SDR brightness immediately when entering dim or low power mode. animateValue = mBrightnessRangeController.getHdrBrightnessValue(); customTransitionRate = mBrightnessRangeController.getHdrTransitionRate(); customAnimationRate = Math.max(customAnimationRate, mBrightnessRangeController.getHdrTransitionRate()); mBrightnessReasonTemp.addModifier(BrightnessReason.MODIFIER_HDR); } // if doze or suspend state is requested, we want to finish brightnes animation fast // to allow state animation to start if (mPowerRequest.policy == DisplayManagerInternal.DisplayPowerRequest.POLICY_DOZE && (mPowerRequest.dozeScreenState == Display.STATE_UNKNOWN // dozing || mPowerRequest.dozeScreenState == Display.STATE_DOZE_SUSPEND || mPowerRequest.dozeScreenState == Display.STATE_ON_SUSPEND)) { customAnimationRate = DisplayBrightnessState.CUSTOM_ANIMATION_RATE_NOT_SET; slowChange = false; } final float currentBrightness = mPowerState.getScreenBrightness(); final float currentSdrBrightness = mPowerState.getSdrScreenBrightness(); Loading Loading @@ -1601,9 +1615,9 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal if (skipAnimation) { animateScreenBrightness(animateValue, sdrAnimateValue, SCREEN_ANIMATION_RATE_MINIMUM); } else if (customTransitionRate > 0) { } else if (customAnimationRate > 0) { animateScreenBrightness(animateValue, sdrAnimateValue, customTransitionRate, /* ignoreAnimationLimits = */true); customAnimationRate, /* ignoreAnimationLimits = */true); } else { boolean isIncreasing = animateValue > currentBrightness; final float rampSpeed; Loading Loading @@ -3059,6 +3073,15 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal modeChangeCallback, displayDeviceConfig, handler, flags, displayToken, info); } BrightnessClamperController getBrightnessClamperController(Handler handler, BrightnessClamperController.ClamperChangeListener clamperChangeListener, BrightnessClamperController.DisplayDeviceData data, Context context, DisplayManagerFlags flags) { return new BrightnessClamperController(handler, clamperChangeListener, data, context, flags); } DisplayWhiteBalanceController getDisplayWhiteBalanceController(Handler handler, SensorManager sensorManager, Resources resources) { return DisplayWhiteBalanceFactory.create(handler, Loading services/core/java/com/android/server/display/brightness/clamper/BrightnessClamper.java +6 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,8 @@ package com.android.server.display.brightness.clamper; import android.annotation.NonNull; import android.os.PowerManager; import com.android.server.display.DisplayBrightnessState; import java.io.PrintWriter; /** Loading @@ -33,6 +35,10 @@ abstract class BrightnessClamper<T> { return mBrightnessCap; } float getCustomAnimationRate() { return DisplayBrightnessState.CUSTOM_ANIMATION_RATE_NOT_SET; } boolean isActive() { return mIsActive; } Loading services/core/java/com/android/server/display/brightness/clamper/BrightnessClamperController.java +9 −1 Original line number Diff line number Diff line Loading @@ -51,6 +51,7 @@ import java.util.concurrent.Executor; */ public class BrightnessClamperController { private static final String TAG = "BrightnessClamperController"; private final DeviceConfigParameterProvider mDeviceConfigParameterProvider; private final Handler mHandler; private final ClamperChangeListener mClamperChangeListenerExternal; Loading @@ -60,6 +61,8 @@ public class BrightnessClamperController { private final List<BrightnessModifier> mModifiers; private final DeviceConfig.OnPropertiesChangedListener mOnPropertiesChangedListener; private float mBrightnessCap = PowerManager.BRIGHTNESS_MAX; private float mCustomAnimationRate = DisplayBrightnessState.CUSTOM_ANIMATION_RATE_NOT_SET; @Nullable private Type mClamperType = null; private boolean mClamperApplied = false; Loading Loading @@ -113,6 +116,7 @@ public class BrightnessClamperController { builder.setIsSlowChange(slowChange); builder.setBrightness(cappedBrightness); builder.setMaxBrightness(mBrightnessCap); builder.setCustomAnimationRate(mCustomAnimationRate); if (mClamperType != null) { builder.getBrightnessReason().addModifier(BrightnessReason.MODIFIER_THROTTLED); Loading Loading @@ -182,6 +186,7 @@ public class BrightnessClamperController { private void recalculateBrightnessCap() { float brightnessCap = PowerManager.BRIGHTNESS_MAX; Type clamperType = null; float customAnimationRate = DisplayBrightnessState.CUSTOM_ANIMATION_RATE_NOT_SET; BrightnessClamper<?> minClamper = mClampers.stream() .filter(BrightnessClamper::isActive) Loading @@ -191,11 +196,14 @@ public class BrightnessClamperController { if (minClamper != null) { brightnessCap = minClamper.getBrightnessCap(); clamperType = minClamper.getType(); customAnimationRate = minClamper.getCustomAnimationRate(); } if (mBrightnessCap != brightnessCap || mClamperType != clamperType) { if (mBrightnessCap != brightnessCap || mClamperType != clamperType || mCustomAnimationRate != customAnimationRate) { mBrightnessCap = brightnessCap; mClamperType = clamperType; mCustomAnimationRate = customAnimationRate; mClamperChangeListenerExternal.onChanged(); } Loading services/tests/displayservicetests/src/com/android/server/display/DisplayBrightnessStateTest.java +3 −1 Original line number Diff line number Diff line Loading @@ -90,7 +90,9 @@ public class DisplayBrightnessStateTest { .append("\n isSlowChange:") .append(displayBrightnessState.isSlowChange()) .append("\n maxBrightness:") .append(displayBrightnessState.getMaxBrightness()); .append(displayBrightnessState.getMaxBrightness()) .append("\n customAnimationRate:") .append(displayBrightnessState.getCustomAnimationRate()); return sb.toString(); } } Loading
services/core/java/com/android/server/display/DisplayBrightnessState.java +33 −3 Original line number Diff line number Diff line Loading @@ -27,6 +27,8 @@ import java.util.Objects; * the DisplayBrightnessModeStrategies when updating the brightness. */ public final class DisplayBrightnessState { public static final float CUSTOM_ANIMATION_RATE_NOT_SET = -1f; private final float mBrightness; private final float mSdrBrightness; Loading @@ -37,6 +39,8 @@ public final class DisplayBrightnessState { private final boolean mIsSlowChange; private final float mCustomAnimationRate; private DisplayBrightnessState(Builder builder) { mBrightness = builder.getBrightness(); mSdrBrightness = builder.getSdrBrightness(); Loading @@ -45,6 +49,7 @@ public final class DisplayBrightnessState { mShouldUseAutoBrightness = builder.getShouldUseAutoBrightness(); mIsSlowChange = builder.isSlowChange(); mMaxBrightness = builder.getMaxBrightness(); mCustomAnimationRate = builder.getCustomAnimationRate(); } /** Loading Loading @@ -97,7 +102,12 @@ public final class DisplayBrightnessState { return mMaxBrightness; } /** * @return custom animation rate */ public float getCustomAnimationRate() { return mCustomAnimationRate; } @Override public String toString() { Loading @@ -112,6 +122,7 @@ public final class DisplayBrightnessState { stringBuilder.append(getShouldUseAutoBrightness()); stringBuilder.append("\n isSlowChange:").append(mIsSlowChange); stringBuilder.append("\n maxBrightness:").append(mMaxBrightness); stringBuilder.append("\n customAnimationRate:").append(mCustomAnimationRate); return stringBuilder.toString(); } Loading @@ -137,13 +148,14 @@ public final class DisplayBrightnessState { otherState.getDisplayBrightnessStrategyName()) && mShouldUseAutoBrightness == otherState.getShouldUseAutoBrightness() && mIsSlowChange == otherState.isSlowChange() && mMaxBrightness == otherState.getMaxBrightness(); && mMaxBrightness == otherState.getMaxBrightness() && mCustomAnimationRate == otherState.getCustomAnimationRate(); } @Override public int hashCode() { return Objects.hash(mBrightness, mSdrBrightness, mBrightnessReason, mShouldUseAutoBrightness, mIsSlowChange, mMaxBrightness); mShouldUseAutoBrightness, mIsSlowChange, mMaxBrightness, mCustomAnimationRate); } /** Loading @@ -164,6 +176,7 @@ public final class DisplayBrightnessState { private boolean mShouldUseAutoBrightness; private boolean mIsSlowChange; private float mMaxBrightness; private float mCustomAnimationRate = CUSTOM_ANIMATION_RATE_NOT_SET; /** * Create a builder starting with the values from the specified {@link Loading @@ -180,6 +193,7 @@ public final class DisplayBrightnessState { builder.setShouldUseAutoBrightness(state.getShouldUseAutoBrightness()); builder.setIsSlowChange(state.isSlowChange()); builder.setMaxBrightness(state.getMaxBrightness()); builder.setCustomAnimationRate(state.getCustomAnimationRate()); return builder; } Loading Loading @@ -303,6 +317,22 @@ public final class DisplayBrightnessState { return mMaxBrightness; } /** * See {@link DisplayBrightnessState#getCustomAnimationRate()}. */ public Builder setCustomAnimationRate(float animationRate) { this.mCustomAnimationRate = animationRate; return this; } /** * See {@link DisplayBrightnessState#getCustomAnimationRate()}. */ public float getCustomAnimationRate() { return mCustomAnimationRate; } /** * This is used to construct an immutable DisplayBrightnessState object from its builder */ Loading
services/core/java/com/android/server/display/DisplayPowerController2.java +31 −8 Original line number Diff line number Diff line Loading @@ -561,8 +561,9 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal brightnessSetting, () -> postBrightnessChangeRunnable(), new HandlerExecutor(mHandler)); mBrightnessClamperController = new BrightnessClamperController(mHandler, modeChangeCallback::run, new BrightnessClamperController.DisplayDeviceData( mBrightnessClamperController = mInjector.getBrightnessClamperController( mHandler, modeChangeCallback::run, new BrightnessClamperController.DisplayDeviceData( mUniqueDisplayId, mThermalBrightnessThrottlingDataId, logicalDisplay.getPowerThrottlingDataIdLocked(), Loading Loading @@ -1353,6 +1354,8 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal float rawBrightnessState = displayBrightnessState.getBrightness(); mBrightnessReasonTemp.set(displayBrightnessState.getBrightnessReason()); boolean slowChange = displayBrightnessState.isSlowChange(); // custom transition duration float customAnimationRate = displayBrightnessState.getCustomAnimationRate(); // 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 @@ -1485,6 +1488,9 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal brightnessState = clampedState.getBrightness(); slowChange = clampedState.isSlowChange(); // faster rate wins, at this point customAnimationRate == -1, strategy does not control // customAnimationRate. Should be revisited if strategy start setting this value customAnimationRate = Math.max(customAnimationRate, clampedState.getCustomAnimationRate()); mBrightnessReasonTemp.addModifier(clampedState.getBrightnessReason().getModifier()); if (updateScreenBrightnessSetting) { Loading Loading @@ -1553,9 +1559,6 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal // allowed range. float animateValue = clampScreenBrightness(brightnessState); // custom transition duration float customTransitionRate = -1f; // If there are any HDR layers on the screen, we have a special brightness value that we // use instead. We still preserve the calculated brightness for Standard Dynamic Range // (SDR) layers, but the main brightness value will be the one for HDR. Loading @@ -1570,10 +1573,21 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal // We want to scale HDR brightness level with the SDR level, we also need to restore // SDR brightness immediately when entering dim or low power mode. animateValue = mBrightnessRangeController.getHdrBrightnessValue(); customTransitionRate = mBrightnessRangeController.getHdrTransitionRate(); customAnimationRate = Math.max(customAnimationRate, mBrightnessRangeController.getHdrTransitionRate()); mBrightnessReasonTemp.addModifier(BrightnessReason.MODIFIER_HDR); } // if doze or suspend state is requested, we want to finish brightnes animation fast // to allow state animation to start if (mPowerRequest.policy == DisplayManagerInternal.DisplayPowerRequest.POLICY_DOZE && (mPowerRequest.dozeScreenState == Display.STATE_UNKNOWN // dozing || mPowerRequest.dozeScreenState == Display.STATE_DOZE_SUSPEND || mPowerRequest.dozeScreenState == Display.STATE_ON_SUSPEND)) { customAnimationRate = DisplayBrightnessState.CUSTOM_ANIMATION_RATE_NOT_SET; slowChange = false; } final float currentBrightness = mPowerState.getScreenBrightness(); final float currentSdrBrightness = mPowerState.getSdrScreenBrightness(); Loading Loading @@ -1601,9 +1615,9 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal if (skipAnimation) { animateScreenBrightness(animateValue, sdrAnimateValue, SCREEN_ANIMATION_RATE_MINIMUM); } else if (customTransitionRate > 0) { } else if (customAnimationRate > 0) { animateScreenBrightness(animateValue, sdrAnimateValue, customTransitionRate, /* ignoreAnimationLimits = */true); customAnimationRate, /* ignoreAnimationLimits = */true); } else { boolean isIncreasing = animateValue > currentBrightness; final float rampSpeed; Loading Loading @@ -3059,6 +3073,15 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal modeChangeCallback, displayDeviceConfig, handler, flags, displayToken, info); } BrightnessClamperController getBrightnessClamperController(Handler handler, BrightnessClamperController.ClamperChangeListener clamperChangeListener, BrightnessClamperController.DisplayDeviceData data, Context context, DisplayManagerFlags flags) { return new BrightnessClamperController(handler, clamperChangeListener, data, context, flags); } DisplayWhiteBalanceController getDisplayWhiteBalanceController(Handler handler, SensorManager sensorManager, Resources resources) { return DisplayWhiteBalanceFactory.create(handler, Loading
services/core/java/com/android/server/display/brightness/clamper/BrightnessClamper.java +6 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,8 @@ package com.android.server.display.brightness.clamper; import android.annotation.NonNull; import android.os.PowerManager; import com.android.server.display.DisplayBrightnessState; import java.io.PrintWriter; /** Loading @@ -33,6 +35,10 @@ abstract class BrightnessClamper<T> { return mBrightnessCap; } float getCustomAnimationRate() { return DisplayBrightnessState.CUSTOM_ANIMATION_RATE_NOT_SET; } boolean isActive() { return mIsActive; } Loading
services/core/java/com/android/server/display/brightness/clamper/BrightnessClamperController.java +9 −1 Original line number Diff line number Diff line Loading @@ -51,6 +51,7 @@ import java.util.concurrent.Executor; */ public class BrightnessClamperController { private static final String TAG = "BrightnessClamperController"; private final DeviceConfigParameterProvider mDeviceConfigParameterProvider; private final Handler mHandler; private final ClamperChangeListener mClamperChangeListenerExternal; Loading @@ -60,6 +61,8 @@ public class BrightnessClamperController { private final List<BrightnessModifier> mModifiers; private final DeviceConfig.OnPropertiesChangedListener mOnPropertiesChangedListener; private float mBrightnessCap = PowerManager.BRIGHTNESS_MAX; private float mCustomAnimationRate = DisplayBrightnessState.CUSTOM_ANIMATION_RATE_NOT_SET; @Nullable private Type mClamperType = null; private boolean mClamperApplied = false; Loading Loading @@ -113,6 +116,7 @@ public class BrightnessClamperController { builder.setIsSlowChange(slowChange); builder.setBrightness(cappedBrightness); builder.setMaxBrightness(mBrightnessCap); builder.setCustomAnimationRate(mCustomAnimationRate); if (mClamperType != null) { builder.getBrightnessReason().addModifier(BrightnessReason.MODIFIER_THROTTLED); Loading Loading @@ -182,6 +186,7 @@ public class BrightnessClamperController { private void recalculateBrightnessCap() { float brightnessCap = PowerManager.BRIGHTNESS_MAX; Type clamperType = null; float customAnimationRate = DisplayBrightnessState.CUSTOM_ANIMATION_RATE_NOT_SET; BrightnessClamper<?> minClamper = mClampers.stream() .filter(BrightnessClamper::isActive) Loading @@ -191,11 +196,14 @@ public class BrightnessClamperController { if (minClamper != null) { brightnessCap = minClamper.getBrightnessCap(); clamperType = minClamper.getType(); customAnimationRate = minClamper.getCustomAnimationRate(); } if (mBrightnessCap != brightnessCap || mClamperType != clamperType) { if (mBrightnessCap != brightnessCap || mClamperType != clamperType || mCustomAnimationRate != customAnimationRate) { mBrightnessCap = brightnessCap; mClamperType = clamperType; mCustomAnimationRate = customAnimationRate; mClamperChangeListenerExternal.onChanged(); } Loading
services/tests/displayservicetests/src/com/android/server/display/DisplayBrightnessStateTest.java +3 −1 Original line number Diff line number Diff line Loading @@ -90,7 +90,9 @@ public class DisplayBrightnessStateTest { .append("\n isSlowChange:") .append(displayBrightnessState.isSlowChange()) .append("\n maxBrightness:") .append(displayBrightnessState.getMaxBrightness()); .append(displayBrightnessState.getMaxBrightness()) .append("\n customAnimationRate:") .append(displayBrightnessState.getCustomAnimationRate()); return sb.toString(); } }