Loading core/java/android/hardware/display/DisplayManagerInternal.java +10 −0 Original line number Diff line number Diff line Loading @@ -778,6 +778,16 @@ public abstract class DisplayManagerInternal { */ float[] getAutoBrightnessLuxLevels(int mode); /** * @return The current brightness setting */ float getBrightness(); /** * @return The brightness value that is used when the device is in doze */ float getDozeBrightness(); /** Returns whether displayoffload supports the given display state. */ static boolean isSupportedOffloadState(int displayState) { return Display.isSuspendedState(displayState); Loading core/res/res/values/config.xml +4 −1 Original line number Diff line number Diff line Loading @@ -1608,7 +1608,10 @@ <fraction name="config_autoBrightnessAdjustmentMaxGamma">300%</fraction> <!-- If we allow automatic adjustment of screen brightness while dozing, how many times we want to reduce it to preserve the battery. Value of 100% means no scaling. --> to reduce it to preserve the battery. Value of 100% means no scaling. Not used if there is a designated auto-brightness doze mapping defined in Display Device Config. Also used to scale the brightness for the doze mode when auto-brightness is disabled if there is an offload session present. --> <fraction name="config_screenAutoBrightnessDozeScaleFactor">100%</fraction> <!-- When the screen is turned on, the previous estimate of the ambient light level at the time Loading services/core/java/com/android/server/display/AutomaticBrightnessController.java +10 −6 Original line number Diff line number Diff line Loading @@ -403,15 +403,14 @@ public class AutomaticBrightnessController { brightnessEvent.setRecommendedBrightness(mScreenAutoBrightness); brightnessEvent.setFlags(brightnessEvent.getFlags() | (!mAmbientLuxValid ? BrightnessEvent.FLAG_INVALID_LUX : 0) | (mDisplayPolicy == DisplayPowerRequest.POLICY_DOZE ? BrightnessEvent.FLAG_DOZE_SCALE : 0)); | (shouldApplyDozeScaleFactor() ? BrightnessEvent.FLAG_DOZE_SCALE : 0)); brightnessEvent.setAutoBrightnessMode(getMode()); } if (!mAmbientLuxValid) { return PowerManager.BRIGHTNESS_INVALID_FLOAT; } if (mDisplayPolicy == DisplayPowerRequest.POLICY_DOZE) { if (shouldApplyDozeScaleFactor()) { return mScreenAutoBrightness * mDozeScaleFactor; } return mScreenAutoBrightness; Loading @@ -434,7 +433,7 @@ public class AutomaticBrightnessController { float brightness = mCurrentBrightnessMapper.getBrightness(mLastObservedLux, mForegroundAppPackageName, mForegroundAppCategory); if (mDisplayPolicy == DisplayPowerRequest.POLICY_DOZE) { if (shouldApplyDozeScaleFactor()) { brightness *= mDozeScaleFactor; } Loading @@ -443,8 +442,7 @@ public class AutomaticBrightnessController { brightnessEvent.setRecommendedBrightness(brightness); brightnessEvent.setFlags(brightnessEvent.getFlags() | (mLastObservedLux == INVALID_LUX ? BrightnessEvent.FLAG_INVALID_LUX : 0) | (mDisplayPolicy == DisplayPowerRequest.POLICY_DOZE ? BrightnessEvent.FLAG_DOZE_SCALE : 0)); | (shouldApplyDozeScaleFactor() ? BrightnessEvent.FLAG_DOZE_SCALE : 0)); brightnessEvent.setAutoBrightnessMode(getMode()); } return brightness; Loading Loading @@ -1263,6 +1261,12 @@ public class AutomaticBrightnessController { } } private boolean shouldApplyDozeScaleFactor() { // Don't apply the doze scale factor if we have a designated brightness curve for doze return mDisplayPolicy == DisplayPowerRequest.POLICY_DOZE && getMode() != AUTO_BRIGHTNESS_MODE_DOZE; } private class ShortTermModel { // When the short term model is invalidated, we don't necessarily reset it (i.e. clear the // user's adjustment) immediately, but wait for a drastic enough change in the ambient Loading services/core/java/com/android/server/display/DisplayOffloadSessionImpl.java +10 −0 Original line number Diff line number Diff line Loading @@ -113,4 +113,14 @@ public class DisplayOffloadSessionImpl implements DisplayManagerInternal.Display Trace.traceEnd(Trace.TRACE_TAG_POWER); } } @Override public float getBrightness() { return mDisplayPowerController.getScreenBrightnessSetting(); } @Override public float getDozeBrightness() { return mDisplayPowerController.getDozeBrightnessForOffload(); } } services/core/java/com/android/server/display/DisplayPowerController.java +29 −16 Original line number Diff line number Diff line Loading @@ -487,6 +487,9 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call private DisplayOffloadSession mDisplayOffloadSession; // Used to scale the brightness in doze mode private float mDozeScaleFactor; /** * Creates the display power controller. */ Loading Loading @@ -547,6 +550,9 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call loadBrightnessRampRates(); mSkipScreenOnBrightnessRamp = resources.getBoolean( R.bool.config_skipScreenOnBrightnessRamp); mDozeScaleFactor = context.getResources().getFraction( R.fraction.config_screenAutoBrightnessDozeScaleFactor, 1, 1); Runnable modeChangeCallback = () -> { sendUpdatePowerState(); Loading Loading @@ -1042,10 +1048,6 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call } if (defaultModeBrightnessMapper != null) { final float dozeScaleFactor = context.getResources().getFraction( R.fraction.config_screenAutoBrightnessDozeScaleFactor, 1, 1); // Ambient Lux - Active Mode Brightness Thresholds float[] ambientBrighteningThresholds = mDisplayDeviceConfig.getAmbientBrighteningPercentages(); Loading Loading @@ -1156,7 +1158,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call mAutomaticBrightnessController = mInjector.getAutomaticBrightnessController( this, handler.getLooper(), mSensorManager, mLightSensor, brightnessMappers, lightSensorWarmUpTimeConfig, PowerManager.BRIGHTNESS_MIN, PowerManager.BRIGHTNESS_MAX, dozeScaleFactor, lightSensorRate, PowerManager.BRIGHTNESS_MAX, mDozeScaleFactor, lightSensorRate, initialLightSensorRate, brighteningLightDebounce, darkeningLightDebounce, brighteningLightDebounceIdle, darkeningLightDebounceIdle, autoBrightnessResetAmbientLuxAfterWarmUp, ambientBrightnessThresholds, Loading Loading @@ -1473,17 +1475,22 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call mAutomaticBrightnessStrategy.setAutoBrightnessApplied(false); } // If there's an offload session and auto-brightness is on, we need to set the initial doze // brightness using the doze auto-brightness curve before the offload session starts // controlling the brightness. if (Float.isNaN(brightnessState) && mFlags.areAutoBrightnessModesEnabled() && mFlags.isDisplayOffloadEnabled() && mPowerRequest.policy == POLICY_DOZE && mDisplayOffloadSession != null && mAutomaticBrightnessController != null // If there's an offload session, we need to set the initial doze brightness before // the offload session starts controlling the brightness. if (Float.isNaN(brightnessState) && mFlags.isDisplayOffloadEnabled() && mPowerRequest.policy == POLICY_DOZE && mDisplayOffloadSession != null) { if (mAutomaticBrightnessController != null && mAutomaticBrightnessStrategy.shouldUseAutoBrightness()) { // Use the auto-brightness curve and the last observed lux rawBrightnessState = mAutomaticBrightnessController .getAutomaticScreenBrightnessBasedOnLastObservedLux(mTempBrightnessEvent); .getAutomaticScreenBrightnessBasedOnLastObservedLux( mTempBrightnessEvent); } else { rawBrightnessState = getDozeBrightnessForOffload(); mTempBrightnessEvent.setFlags(mTempBrightnessEvent.getFlags() | BrightnessEvent.FLAG_DOZE_SCALE); } if (BrightnessUtils.isValidBrightnessValue(rawBrightnessState)) { brightnessState = clampScreenBrightness(rawBrightnessState); mBrightnessReasonTemp.setReason(BrightnessReason.REASON_DOZE_INITIAL); Loading Loading @@ -2443,6 +2450,11 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call return mDisplayBrightnessController.getScreenBrightnessSetting(); } @Override public float getDozeBrightnessForOffload() { return mDisplayBrightnessController.getCurrentBrightness() * mDozeScaleFactor; } @Override public void setBrightness(float brightness) { mDisplayBrightnessController.setBrightness(clampScreenBrightness(brightness)); Loading Loading @@ -2596,6 +2608,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call } pw.println(" mDisplayBlanksAfterDozeConfig=" + mDisplayBlanksAfterDozeConfig); pw.println(" mBrightnessBucketsInDozeConfig=" + mBrightnessBucketsInDozeConfig); pw.println(" mDozeScaleFactor=" + mDozeScaleFactor); mHandler.runWithScissors(() -> dumpLocal(pw), 1000); } Loading Loading
core/java/android/hardware/display/DisplayManagerInternal.java +10 −0 Original line number Diff line number Diff line Loading @@ -778,6 +778,16 @@ public abstract class DisplayManagerInternal { */ float[] getAutoBrightnessLuxLevels(int mode); /** * @return The current brightness setting */ float getBrightness(); /** * @return The brightness value that is used when the device is in doze */ float getDozeBrightness(); /** Returns whether displayoffload supports the given display state. */ static boolean isSupportedOffloadState(int displayState) { return Display.isSuspendedState(displayState); Loading
core/res/res/values/config.xml +4 −1 Original line number Diff line number Diff line Loading @@ -1608,7 +1608,10 @@ <fraction name="config_autoBrightnessAdjustmentMaxGamma">300%</fraction> <!-- If we allow automatic adjustment of screen brightness while dozing, how many times we want to reduce it to preserve the battery. Value of 100% means no scaling. --> to reduce it to preserve the battery. Value of 100% means no scaling. Not used if there is a designated auto-brightness doze mapping defined in Display Device Config. Also used to scale the brightness for the doze mode when auto-brightness is disabled if there is an offload session present. --> <fraction name="config_screenAutoBrightnessDozeScaleFactor">100%</fraction> <!-- When the screen is turned on, the previous estimate of the ambient light level at the time Loading
services/core/java/com/android/server/display/AutomaticBrightnessController.java +10 −6 Original line number Diff line number Diff line Loading @@ -403,15 +403,14 @@ public class AutomaticBrightnessController { brightnessEvent.setRecommendedBrightness(mScreenAutoBrightness); brightnessEvent.setFlags(brightnessEvent.getFlags() | (!mAmbientLuxValid ? BrightnessEvent.FLAG_INVALID_LUX : 0) | (mDisplayPolicy == DisplayPowerRequest.POLICY_DOZE ? BrightnessEvent.FLAG_DOZE_SCALE : 0)); | (shouldApplyDozeScaleFactor() ? BrightnessEvent.FLAG_DOZE_SCALE : 0)); brightnessEvent.setAutoBrightnessMode(getMode()); } if (!mAmbientLuxValid) { return PowerManager.BRIGHTNESS_INVALID_FLOAT; } if (mDisplayPolicy == DisplayPowerRequest.POLICY_DOZE) { if (shouldApplyDozeScaleFactor()) { return mScreenAutoBrightness * mDozeScaleFactor; } return mScreenAutoBrightness; Loading @@ -434,7 +433,7 @@ public class AutomaticBrightnessController { float brightness = mCurrentBrightnessMapper.getBrightness(mLastObservedLux, mForegroundAppPackageName, mForegroundAppCategory); if (mDisplayPolicy == DisplayPowerRequest.POLICY_DOZE) { if (shouldApplyDozeScaleFactor()) { brightness *= mDozeScaleFactor; } Loading @@ -443,8 +442,7 @@ public class AutomaticBrightnessController { brightnessEvent.setRecommendedBrightness(brightness); brightnessEvent.setFlags(brightnessEvent.getFlags() | (mLastObservedLux == INVALID_LUX ? BrightnessEvent.FLAG_INVALID_LUX : 0) | (mDisplayPolicy == DisplayPowerRequest.POLICY_DOZE ? BrightnessEvent.FLAG_DOZE_SCALE : 0)); | (shouldApplyDozeScaleFactor() ? BrightnessEvent.FLAG_DOZE_SCALE : 0)); brightnessEvent.setAutoBrightnessMode(getMode()); } return brightness; Loading Loading @@ -1263,6 +1261,12 @@ public class AutomaticBrightnessController { } } private boolean shouldApplyDozeScaleFactor() { // Don't apply the doze scale factor if we have a designated brightness curve for doze return mDisplayPolicy == DisplayPowerRequest.POLICY_DOZE && getMode() != AUTO_BRIGHTNESS_MODE_DOZE; } private class ShortTermModel { // When the short term model is invalidated, we don't necessarily reset it (i.e. clear the // user's adjustment) immediately, but wait for a drastic enough change in the ambient Loading
services/core/java/com/android/server/display/DisplayOffloadSessionImpl.java +10 −0 Original line number Diff line number Diff line Loading @@ -113,4 +113,14 @@ public class DisplayOffloadSessionImpl implements DisplayManagerInternal.Display Trace.traceEnd(Trace.TRACE_TAG_POWER); } } @Override public float getBrightness() { return mDisplayPowerController.getScreenBrightnessSetting(); } @Override public float getDozeBrightness() { return mDisplayPowerController.getDozeBrightnessForOffload(); } }
services/core/java/com/android/server/display/DisplayPowerController.java +29 −16 Original line number Diff line number Diff line Loading @@ -487,6 +487,9 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call private DisplayOffloadSession mDisplayOffloadSession; // Used to scale the brightness in doze mode private float mDozeScaleFactor; /** * Creates the display power controller. */ Loading Loading @@ -547,6 +550,9 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call loadBrightnessRampRates(); mSkipScreenOnBrightnessRamp = resources.getBoolean( R.bool.config_skipScreenOnBrightnessRamp); mDozeScaleFactor = context.getResources().getFraction( R.fraction.config_screenAutoBrightnessDozeScaleFactor, 1, 1); Runnable modeChangeCallback = () -> { sendUpdatePowerState(); Loading Loading @@ -1042,10 +1048,6 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call } if (defaultModeBrightnessMapper != null) { final float dozeScaleFactor = context.getResources().getFraction( R.fraction.config_screenAutoBrightnessDozeScaleFactor, 1, 1); // Ambient Lux - Active Mode Brightness Thresholds float[] ambientBrighteningThresholds = mDisplayDeviceConfig.getAmbientBrighteningPercentages(); Loading Loading @@ -1156,7 +1158,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call mAutomaticBrightnessController = mInjector.getAutomaticBrightnessController( this, handler.getLooper(), mSensorManager, mLightSensor, brightnessMappers, lightSensorWarmUpTimeConfig, PowerManager.BRIGHTNESS_MIN, PowerManager.BRIGHTNESS_MAX, dozeScaleFactor, lightSensorRate, PowerManager.BRIGHTNESS_MAX, mDozeScaleFactor, lightSensorRate, initialLightSensorRate, brighteningLightDebounce, darkeningLightDebounce, brighteningLightDebounceIdle, darkeningLightDebounceIdle, autoBrightnessResetAmbientLuxAfterWarmUp, ambientBrightnessThresholds, Loading Loading @@ -1473,17 +1475,22 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call mAutomaticBrightnessStrategy.setAutoBrightnessApplied(false); } // If there's an offload session and auto-brightness is on, we need to set the initial doze // brightness using the doze auto-brightness curve before the offload session starts // controlling the brightness. if (Float.isNaN(brightnessState) && mFlags.areAutoBrightnessModesEnabled() && mFlags.isDisplayOffloadEnabled() && mPowerRequest.policy == POLICY_DOZE && mDisplayOffloadSession != null && mAutomaticBrightnessController != null // If there's an offload session, we need to set the initial doze brightness before // the offload session starts controlling the brightness. if (Float.isNaN(brightnessState) && mFlags.isDisplayOffloadEnabled() && mPowerRequest.policy == POLICY_DOZE && mDisplayOffloadSession != null) { if (mAutomaticBrightnessController != null && mAutomaticBrightnessStrategy.shouldUseAutoBrightness()) { // Use the auto-brightness curve and the last observed lux rawBrightnessState = mAutomaticBrightnessController .getAutomaticScreenBrightnessBasedOnLastObservedLux(mTempBrightnessEvent); .getAutomaticScreenBrightnessBasedOnLastObservedLux( mTempBrightnessEvent); } else { rawBrightnessState = getDozeBrightnessForOffload(); mTempBrightnessEvent.setFlags(mTempBrightnessEvent.getFlags() | BrightnessEvent.FLAG_DOZE_SCALE); } if (BrightnessUtils.isValidBrightnessValue(rawBrightnessState)) { brightnessState = clampScreenBrightness(rawBrightnessState); mBrightnessReasonTemp.setReason(BrightnessReason.REASON_DOZE_INITIAL); Loading Loading @@ -2443,6 +2450,11 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call return mDisplayBrightnessController.getScreenBrightnessSetting(); } @Override public float getDozeBrightnessForOffload() { return mDisplayBrightnessController.getCurrentBrightness() * mDozeScaleFactor; } @Override public void setBrightness(float brightness) { mDisplayBrightnessController.setBrightness(clampScreenBrightness(brightness)); Loading Loading @@ -2596,6 +2608,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call } pw.println(" mDisplayBlanksAfterDozeConfig=" + mDisplayBlanksAfterDozeConfig); pw.println(" mBrightnessBucketsInDozeConfig=" + mBrightnessBucketsInDozeConfig); pw.println(" mDozeScaleFactor=" + mDozeScaleFactor); mHandler.runWithScissors(() -> dumpLocal(pw), 1000); } Loading