Loading services/core/java/com/android/server/display/AutomaticBrightnessController.java +15 −12 Original line number Diff line number Diff line Loading @@ -223,11 +223,11 @@ public class AutomaticBrightnessController { private final ShortTermModel mShortTermModel; private final ShortTermModel mPausedShortTermModel; // Controls High Brightness Mode. private HighBrightnessModeController mHbmController; // Controls Brightness range (including High Brightness Mode). private final BrightnessRangeController mBrightnessRangeController; // Throttles (caps) maximum allowed brightness private BrightnessThrottler mBrightnessThrottler; private final BrightnessThrottler mBrightnessThrottler; private boolean mIsBrightnessThrottled; // Context-sensitive brightness configurations require keeping track of the foreground app's Loading Loading @@ -257,7 +257,8 @@ public class AutomaticBrightnessController { HysteresisLevels screenBrightnessThresholds, HysteresisLevels ambientBrightnessThresholdsIdle, HysteresisLevels screenBrightnessThresholdsIdle, Context context, HighBrightnessModeController hbmController, BrightnessThrottler brightnessThrottler, BrightnessRangeController brightnessModeController, BrightnessThrottler brightnessThrottler, BrightnessMappingStrategy idleModeBrightnessMapper, int ambientLightHorizonShort, int ambientLightHorizonLong, float userLux, float userBrightness) { this(new Injector(), callbacks, looper, sensorManager, lightSensor, Loading @@ -267,7 +268,7 @@ public class AutomaticBrightnessController { darkeningLightDebounceConfig, resetAmbientLuxAfterWarmUpConfig, ambientBrightnessThresholds, screenBrightnessThresholds, ambientBrightnessThresholdsIdle, screenBrightnessThresholdsIdle, context, hbmController, brightnessThrottler, idleModeBrightnessMapper, brightnessModeController, brightnessThrottler, idleModeBrightnessMapper, ambientLightHorizonShort, ambientLightHorizonLong, userLux, userBrightness ); } Loading @@ -283,7 +284,8 @@ public class AutomaticBrightnessController { HysteresisLevels screenBrightnessThresholds, HysteresisLevels ambientBrightnessThresholdsIdle, HysteresisLevels screenBrightnessThresholdsIdle, Context context, HighBrightnessModeController hbmController, BrightnessThrottler brightnessThrottler, BrightnessRangeController brightnessModeController, BrightnessThrottler brightnessThrottler, BrightnessMappingStrategy idleModeBrightnessMapper, int ambientLightHorizonShort, int ambientLightHorizonLong, float userLux, float userBrightness) { mInjector = injector; Loading Loading @@ -326,7 +328,7 @@ public class AutomaticBrightnessController { mPendingForegroundAppPackageName = null; mForegroundAppCategory = ApplicationInfo.CATEGORY_UNDEFINED; mPendingForegroundAppCategory = ApplicationInfo.CATEGORY_UNDEFINED; mHbmController = hbmController; mBrightnessRangeController = brightnessModeController; mBrightnessThrottler = brightnessThrottler; mInteractiveModeBrightnessMapper = interactiveModeBrightnessMapper; mIdleModeBrightnessMapper = idleModeBrightnessMapper; Loading Loading @@ -606,10 +608,11 @@ public class AutomaticBrightnessController { pw.println(); pw.println(" mInteractiveMapper="); mInteractiveModeBrightnessMapper.dump(pw, mHbmController.getNormalBrightnessMax()); mInteractiveModeBrightnessMapper.dump(pw, mBrightnessRangeController.getNormalBrightnessMax()); if (mIdleModeBrightnessMapper != null) { pw.println(" mIdleMapper="); mIdleModeBrightnessMapper.dump(pw, mHbmController.getNormalBrightnessMax()); mIdleModeBrightnessMapper.dump(pw, mBrightnessRangeController.getNormalBrightnessMax()); } pw.println(); Loading Loading @@ -735,7 +738,7 @@ public class AutomaticBrightnessController { mAmbientDarkeningThreshold = mAmbientBrightnessThresholds.getDarkeningThreshold(lux); } mHbmController.onAmbientLuxChange(mAmbientLux); mBrightnessRangeController.onAmbientLuxChange(mAmbientLux); // If the short term model was invalidated and the change is drastic enough, reset it. Loading Loading @@ -975,9 +978,9 @@ public class AutomaticBrightnessController { // Clamps values with float range [0.0-1.0] private float clampScreenBrightness(float value) { final float minBrightness = Math.min(mHbmController.getCurrentBrightnessMin(), final float minBrightness = Math.min(mBrightnessRangeController.getCurrentBrightnessMin(), mBrightnessThrottler.getBrightnessCap()); final float maxBrightness = Math.min(mHbmController.getCurrentBrightnessMax(), final float maxBrightness = Math.min(mBrightnessRangeController.getCurrentBrightnessMax(), mBrightnessThrottler.getBrightnessCap()); return MathUtils.constrain(value, minBrightness, maxBrightness); } Loading services/core/java/com/android/server/display/BrightnessRangeController.java 0 → 100644 +112 −0 Original line number Diff line number Diff line /* * Copyright (C) 2023 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; import android.hardware.display.BrightnessInfo; import android.os.IBinder; import java.io.PrintWriter; class BrightnessRangeController { private static final boolean NBM_FEATURE_FLAG = false; private final HighBrightnessModeController mHbmController; private final NormalBrightnessModeController mNormalBrightnessModeController = new NormalBrightnessModeController(); private final Runnable mModeChangeCallback; BrightnessRangeController(HighBrightnessModeController hbmController, Runnable modeChangeCallback) { mHbmController = hbmController; mModeChangeCallback = modeChangeCallback; } void dump(PrintWriter pw) { mHbmController.dump(pw); } void onAmbientLuxChange(float ambientLux) { if (NBM_FEATURE_FLAG) { boolean nbmTransitionChanged = mNormalBrightnessModeController.onAmbientLuxChange( ambientLux); int previousHbm = mHbmController.getHighBrightnessMode(); mHbmController.onAmbientLuxChange(ambientLux); int nextHbm = mHbmController.getHighBrightnessMode(); // if hbm changed - callback was triggered in mHbmController.onAmbientLuxChange // if nbm transition not changed - no need to trigger callback if (previousHbm == nextHbm && nbmTransitionChanged) { mModeChangeCallback.run(); } } else { mHbmController.onAmbientLuxChange(ambientLux); } } float getNormalBrightnessMax() { return mHbmController.getNormalBrightnessMax(); } void loadFromConfig(HighBrightnessModeMetadata hbmMetadata, IBinder token, DisplayDeviceInfo info, DisplayDeviceConfig displayDeviceConfig) { mHbmController.setHighBrightnessModeMetadata(hbmMetadata); mHbmController.resetHbmData(info.width, info.height, token, info.uniqueId, displayDeviceConfig.getHighBrightnessModeData(), displayDeviceConfig::getHdrBrightnessFromSdr); } void stop() { mHbmController.stop(); } void setAutoBrightnessEnabled(int state) { mHbmController.setAutoBrightnessEnabled(state); } void onBrightnessChanged(float brightness, float unthrottledBrightness, @BrightnessInfo.BrightnessMaxReason int throttlingReason) { mHbmController.onBrightnessChanged(brightness, unthrottledBrightness, throttlingReason); } float getCurrentBrightnessMin() { return mHbmController.getCurrentBrightnessMin(); } float getCurrentBrightnessMax() { if (NBM_FEATURE_FLAG && mHbmController.getHighBrightnessMode() == BrightnessInfo.HIGH_BRIGHTNESS_MODE_OFF) { return Math.min(mHbmController.getCurrentBrightnessMax(), mNormalBrightnessModeController.getCurrentBrightnessMax()); } return mHbmController.getCurrentBrightnessMax(); } int getHighBrightnessMode() { return mHbmController.getHighBrightnessMode(); } float getHdrBrightnessValue() { return mHbmController.getHdrBrightnessValue(); } float getTransitionPoint() { return mHbmController.getTransitionPoint(); } } services/core/java/com/android/server/display/DisplayPowerController.java +42 −44 Original line number Diff line number Diff line Loading @@ -445,7 +445,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call private final ColorDisplayServiceInternal mCdsi; private float[] mNitsRange; private final HighBrightnessModeController mHbmController; private final BrightnessRangeController mBrightnessRangeController; private final HighBrightnessModeMetadata mHighBrightnessModeMetadata; private final BrightnessThrottler mBrightnessThrottler; Loading Loading @@ -654,8 +654,19 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call loadBrightnessRampRates(); mSkipScreenOnBrightnessRamp = resources.getBoolean( com.android.internal.R.bool.config_skipScreenOnBrightnessRamp); Runnable modeChangeCallback = () -> { sendUpdatePowerState(); postBrightnessChangeRunnable(); // TODO(b/192258832): Switch the HBMChangeCallback to a listener pattern. if (mAutomaticBrightnessController != null) { mAutomaticBrightnessController.update(); } }; HighBrightnessModeController hbmController = createHbmControllerLocked(modeChangeCallback); mHbmController = createHbmControllerLocked(); mBrightnessRangeController = new BrightnessRangeController(hbmController, modeChangeCallback); mBrightnessThrottler = createBrightnessThrottlerLocked(); Loading Loading @@ -802,7 +813,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call @Override public void setBrightnessToFollow(float leadDisplayBrightness, float nits, float ambientLux) { mHbmController.onAmbientLuxChange(ambientLux); mBrightnessRangeController.onAmbientLuxChange(ambientLux); if (nits < 0) { mBrightnessToFollow = leadDisplayBrightness; } else { Loading Loading @@ -1039,17 +1050,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call mBrightnessRampIncreaseMaxTimeMillis, mBrightnessRampDecreaseMaxTimeMillis); } mHbmController.setHighBrightnessModeMetadata(hbmMetadata); mHbmController.resetHbmData(info.width, info.height, token, info.uniqueId, mDisplayDeviceConfig.getHighBrightnessModeData(), new HighBrightnessModeController.HdrBrightnessDeviceConfig() { @Override public float getHdrBrightnessFromSdr( float sdrBrightness, float maxDesiredHdrSdrRatio) { return mDisplayDeviceConfig.getHdrBrightnessFromSdr( sdrBrightness, maxDesiredHdrSdrRatio); } }); mBrightnessRangeController.loadFromConfig(hbmMetadata, token, info, mDisplayDeviceConfig); mBrightnessThrottler.loadThermalBrightnessThrottlingDataFromDisplayDeviceConfig( mDisplayDeviceConfig.getThermalBrightnessThrottlingDataMapByThrottlingId(), mThermalBrightnessThrottlingDataId, mUniqueDisplayId); Loading Loading @@ -1264,7 +1265,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call darkeningLightDebounce, autoBrightnessResetAmbientLuxAfterWarmUp, ambientBrightnessThresholds, screenBrightnessThresholds, ambientBrightnessThresholdsIdle, screenBrightnessThresholdsIdle, mContext, mHbmController, mBrightnessThrottler, mIdleModeBrightnessMapper, mBrightnessRangeController, mBrightnessThrottler, mIdleModeBrightnessMapper, mDisplayDeviceConfig.getAmbientHorizonShort(), mDisplayDeviceConfig.getAmbientHorizonLong(), userLux, userBrightness); Loading Loading @@ -1364,7 +1365,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call /** Clean up all resources that are accessed via the {@link #mHandler} thread. */ private void cleanupHandlerThreadAfterStop() { setProximitySensorEnabled(false); mHbmController.stop(); mBrightnessRangeController.stop(); mBrightnessThrottler.stop(); mHandler.removeCallbacksAndMessages(null); Loading Loading @@ -1647,7 +1648,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call mShouldResetShortTermModel); mShouldResetShortTermModel = false; } mHbmController.setAutoBrightnessEnabled(mUseAutoBrightness mBrightnessRangeController.setAutoBrightnessEnabled(mUseAutoBrightness ? AutomaticBrightnessController.AUTO_BRIGHTNESS_ENABLED : AutomaticBrightnessController.AUTO_BRIGHTNESS_DISABLED); Loading Loading @@ -1820,7 +1821,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call // here instead of having HbmController listen to the brightness setting because certain // brightness sources (such as an app override) are not saved to the setting, but should be // reflected in HBM calculations. mHbmController.onBrightnessChanged(brightnessState, unthrottledBrightnessState, mBrightnessRangeController.onBrightnessChanged(brightnessState, unthrottledBrightnessState, mBrightnessThrottler.getBrightnessMaxReason()); // Animate the screen brightness when the screen is on or dozing. Loading Loading @@ -1874,13 +1875,14 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call float sdrAnimateValue = animateValue; // TODO(b/216365040): The decision to prevent HBM for HDR in low power mode should be // done in HighBrightnessModeController. if (mHbmController.getHighBrightnessMode() == BrightnessInfo.HIGH_BRIGHTNESS_MODE_HDR if (mBrightnessRangeController.getHighBrightnessMode() == BrightnessInfo.HIGH_BRIGHTNESS_MODE_HDR && (mBrightnessReasonTemp.getModifier() & BrightnessReason.MODIFIER_DIMMED) == 0 && (mBrightnessReasonTemp.getModifier() & BrightnessReason.MODIFIER_LOW_POWER) == 0) { // 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 = mHbmController.getHdrBrightnessValue(); animateValue = mBrightnessRangeController.getHdrBrightnessValue(); } final float currentBrightness = mPowerState.getScreenBrightness(); Loading Loading @@ -1942,8 +1944,8 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call mTempBrightnessEvent.setBrightness(brightnessState); mTempBrightnessEvent.setPhysicalDisplayId(mUniqueDisplayId); mTempBrightnessEvent.setReason(mBrightnessReason); mTempBrightnessEvent.setHbmMax(mHbmController.getCurrentBrightnessMax()); mTempBrightnessEvent.setHbmMode(mHbmController.getHighBrightnessMode()); mTempBrightnessEvent.setHbmMax(mBrightnessRangeController.getCurrentBrightnessMax()); mTempBrightnessEvent.setHbmMode(mBrightnessRangeController.getHighBrightnessMode()); mTempBrightnessEvent.setFlags(mTempBrightnessEvent.getFlags() | (mIsRbcActive ? BrightnessEvent.FLAG_RBC : 0) | (mPowerRequest.lowPowerMode ? BrightnessEvent.FLAG_LOW_POWER_MODE : 0)); Loading Loading @@ -2104,9 +2106,11 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call private boolean saveBrightnessInfo(float brightness, float adjustedBrightness) { synchronized (mCachedBrightnessInfo) { final float minBrightness = Math.min(mHbmController.getCurrentBrightnessMin(), final float minBrightness = Math.min( mBrightnessRangeController.getCurrentBrightnessMin(), mBrightnessThrottler.getBrightnessCap()); final float maxBrightness = Math.min(mHbmController.getCurrentBrightnessMax(), final float maxBrightness = Math.min( mBrightnessRangeController.getCurrentBrightnessMax(), mBrightnessThrottler.getBrightnessCap()); boolean changed = false; Loading @@ -2124,10 +2128,10 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call maxBrightness); changed |= mCachedBrightnessInfo.checkAndSetInt(mCachedBrightnessInfo.hbmMode, mHbmController.getHighBrightnessMode()); mBrightnessRangeController.getHighBrightnessMode()); changed |= mCachedBrightnessInfo.checkAndSetFloat(mCachedBrightnessInfo.hbmTransitionPoint, mHbmController.getTransitionPoint()); mBrightnessRangeController.getTransitionPoint()); changed |= mCachedBrightnessInfo.checkAndSetInt(mCachedBrightnessInfo.brightnessMaxReason, mBrightnessThrottler.getBrightnessMaxReason()); Loading @@ -2140,7 +2144,8 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call mHandler.post(mOnBrightnessChangeRunnable); } private HighBrightnessModeController createHbmControllerLocked() { private HighBrightnessModeController createHbmControllerLocked( Runnable modeChangeCallback) { final DisplayDevice device = mLogicalDisplay.getPrimaryDisplayDeviceLocked(); final DisplayDeviceConfig ddConfig = device.getDisplayDeviceConfig(); final IBinder displayToken = Loading @@ -2159,15 +2164,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call return mDisplayDeviceConfig.getHdrBrightnessFromSdr( sdrBrightness, maxDesiredHdrSdrRatio); } }, () -> { sendUpdatePowerState(); postBrightnessChangeRunnable(); // TODO(b/192258832): Switch the HBMChangeCallback to a listener pattern. if (mAutomaticBrightnessController != null) { mAutomaticBrightnessController.update(); } }, mHighBrightnessModeMetadata, mContext); }, modeChangeCallback, mHighBrightnessModeMetadata, mContext); } private BrightnessThrottler createBrightnessThrottlerLocked() { Loading Loading @@ -2328,8 +2325,8 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call if (Float.isNaN(value)) { value = PowerManager.BRIGHTNESS_MIN; } return MathUtils.constrain(value, mHbmController.getCurrentBrightnessMin(), mHbmController.getCurrentBrightnessMax()); return MathUtils.constrain(value, mBrightnessRangeController.getCurrentBrightnessMin(), mBrightnessRangeController.getCurrentBrightnessMax()); } // Checks whether the brightness is within the valid brightness range, not including off. Loading Loading @@ -3003,8 +3000,8 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call mScreenOffBrightnessSensorController.dump(pw); } if (mHbmController != null) { mHbmController.dump(pw); if (mBrightnessRangeController != null) { mBrightnessRangeController.dump(pw); } if (mBrightnessThrottler != null) { Loading Loading @@ -3471,7 +3468,8 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call HysteresisLevels screenBrightnessThresholds, HysteresisLevels ambientBrightnessThresholdsIdle, HysteresisLevels screenBrightnessThresholdsIdle, Context context, HighBrightnessModeController hbmController, BrightnessThrottler brightnessThrottler, BrightnessRangeController brightnessRangeController, BrightnessThrottler brightnessThrottler, BrightnessMappingStrategy idleModeBrightnessMapper, int ambientLightHorizonShort, int ambientLightHorizonLong, float userLux, float userBrightness) { return new AutomaticBrightnessController(callbacks, looper, sensorManager, lightSensor, Loading @@ -3480,9 +3478,9 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call brighteningLightDebounceConfig, darkeningLightDebounceConfig, resetAmbientLuxAfterWarmUpConfig, ambientBrightnessThresholds, screenBrightnessThresholds, ambientBrightnessThresholdsIdle, screenBrightnessThresholdsIdle, context, hbmController, brightnessThrottler, idleModeBrightnessMapper, ambientLightHorizonShort, ambientLightHorizonLong, userLux, userBrightness); screenBrightnessThresholdsIdle, context, brightnessRangeController, brightnessThrottler, idleModeBrightnessMapper, ambientLightHorizonShort, ambientLightHorizonLong, userLux, userBrightness); } BrightnessMappingStrategy getInteractiveModeBrightnessMapper(Resources resources, Loading services/core/java/com/android/server/display/DisplayPowerController2.java +47 −53 File changed.Preview size limit exceeded, changes collapsed. Show changes services/core/java/com/android/server/display/NormalBrightnessModeController.java 0 → 100644 +51 −0 Original line number Diff line number Diff line /* * Copyright (C) 2023 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; import android.os.PowerManager; import java.util.HashMap; import java.util.Map; class NormalBrightnessModeController { private Map<Float, Float> mTransitionPoints = new HashMap<>(); // brightness limit in normal brightness mode, based on ambient lux. private float mVirtualTransitionPoint = PowerManager.BRIGHTNESS_MAX; boolean onAmbientLuxChange(float ambientLux) { float currentAmbientBoundary = Float.MAX_VALUE; float currentTransitionPoint = PowerManager.BRIGHTNESS_MAX; for (Map.Entry<Float, Float> transitionPoint: mTransitionPoints.entrySet()) { float ambientBoundary = transitionPoint.getKey(); // find ambient lux upper boundary closest to current ambient lux if (ambientBoundary > ambientLux && ambientBoundary < currentAmbientBoundary) { currentTransitionPoint = transitionPoint.getValue(); currentAmbientBoundary = ambientBoundary; } } if (mVirtualTransitionPoint != currentTransitionPoint) { mVirtualTransitionPoint = currentTransitionPoint; return true; } return false; } float getCurrentBrightnessMax() { return mVirtualTransitionPoint; } } Loading
services/core/java/com/android/server/display/AutomaticBrightnessController.java +15 −12 Original line number Diff line number Diff line Loading @@ -223,11 +223,11 @@ public class AutomaticBrightnessController { private final ShortTermModel mShortTermModel; private final ShortTermModel mPausedShortTermModel; // Controls High Brightness Mode. private HighBrightnessModeController mHbmController; // Controls Brightness range (including High Brightness Mode). private final BrightnessRangeController mBrightnessRangeController; // Throttles (caps) maximum allowed brightness private BrightnessThrottler mBrightnessThrottler; private final BrightnessThrottler mBrightnessThrottler; private boolean mIsBrightnessThrottled; // Context-sensitive brightness configurations require keeping track of the foreground app's Loading Loading @@ -257,7 +257,8 @@ public class AutomaticBrightnessController { HysteresisLevels screenBrightnessThresholds, HysteresisLevels ambientBrightnessThresholdsIdle, HysteresisLevels screenBrightnessThresholdsIdle, Context context, HighBrightnessModeController hbmController, BrightnessThrottler brightnessThrottler, BrightnessRangeController brightnessModeController, BrightnessThrottler brightnessThrottler, BrightnessMappingStrategy idleModeBrightnessMapper, int ambientLightHorizonShort, int ambientLightHorizonLong, float userLux, float userBrightness) { this(new Injector(), callbacks, looper, sensorManager, lightSensor, Loading @@ -267,7 +268,7 @@ public class AutomaticBrightnessController { darkeningLightDebounceConfig, resetAmbientLuxAfterWarmUpConfig, ambientBrightnessThresholds, screenBrightnessThresholds, ambientBrightnessThresholdsIdle, screenBrightnessThresholdsIdle, context, hbmController, brightnessThrottler, idleModeBrightnessMapper, brightnessModeController, brightnessThrottler, idleModeBrightnessMapper, ambientLightHorizonShort, ambientLightHorizonLong, userLux, userBrightness ); } Loading @@ -283,7 +284,8 @@ public class AutomaticBrightnessController { HysteresisLevels screenBrightnessThresholds, HysteresisLevels ambientBrightnessThresholdsIdle, HysteresisLevels screenBrightnessThresholdsIdle, Context context, HighBrightnessModeController hbmController, BrightnessThrottler brightnessThrottler, BrightnessRangeController brightnessModeController, BrightnessThrottler brightnessThrottler, BrightnessMappingStrategy idleModeBrightnessMapper, int ambientLightHorizonShort, int ambientLightHorizonLong, float userLux, float userBrightness) { mInjector = injector; Loading Loading @@ -326,7 +328,7 @@ public class AutomaticBrightnessController { mPendingForegroundAppPackageName = null; mForegroundAppCategory = ApplicationInfo.CATEGORY_UNDEFINED; mPendingForegroundAppCategory = ApplicationInfo.CATEGORY_UNDEFINED; mHbmController = hbmController; mBrightnessRangeController = brightnessModeController; mBrightnessThrottler = brightnessThrottler; mInteractiveModeBrightnessMapper = interactiveModeBrightnessMapper; mIdleModeBrightnessMapper = idleModeBrightnessMapper; Loading Loading @@ -606,10 +608,11 @@ public class AutomaticBrightnessController { pw.println(); pw.println(" mInteractiveMapper="); mInteractiveModeBrightnessMapper.dump(pw, mHbmController.getNormalBrightnessMax()); mInteractiveModeBrightnessMapper.dump(pw, mBrightnessRangeController.getNormalBrightnessMax()); if (mIdleModeBrightnessMapper != null) { pw.println(" mIdleMapper="); mIdleModeBrightnessMapper.dump(pw, mHbmController.getNormalBrightnessMax()); mIdleModeBrightnessMapper.dump(pw, mBrightnessRangeController.getNormalBrightnessMax()); } pw.println(); Loading Loading @@ -735,7 +738,7 @@ public class AutomaticBrightnessController { mAmbientDarkeningThreshold = mAmbientBrightnessThresholds.getDarkeningThreshold(lux); } mHbmController.onAmbientLuxChange(mAmbientLux); mBrightnessRangeController.onAmbientLuxChange(mAmbientLux); // If the short term model was invalidated and the change is drastic enough, reset it. Loading Loading @@ -975,9 +978,9 @@ public class AutomaticBrightnessController { // Clamps values with float range [0.0-1.0] private float clampScreenBrightness(float value) { final float minBrightness = Math.min(mHbmController.getCurrentBrightnessMin(), final float minBrightness = Math.min(mBrightnessRangeController.getCurrentBrightnessMin(), mBrightnessThrottler.getBrightnessCap()); final float maxBrightness = Math.min(mHbmController.getCurrentBrightnessMax(), final float maxBrightness = Math.min(mBrightnessRangeController.getCurrentBrightnessMax(), mBrightnessThrottler.getBrightnessCap()); return MathUtils.constrain(value, minBrightness, maxBrightness); } Loading
services/core/java/com/android/server/display/BrightnessRangeController.java 0 → 100644 +112 −0 Original line number Diff line number Diff line /* * Copyright (C) 2023 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; import android.hardware.display.BrightnessInfo; import android.os.IBinder; import java.io.PrintWriter; class BrightnessRangeController { private static final boolean NBM_FEATURE_FLAG = false; private final HighBrightnessModeController mHbmController; private final NormalBrightnessModeController mNormalBrightnessModeController = new NormalBrightnessModeController(); private final Runnable mModeChangeCallback; BrightnessRangeController(HighBrightnessModeController hbmController, Runnable modeChangeCallback) { mHbmController = hbmController; mModeChangeCallback = modeChangeCallback; } void dump(PrintWriter pw) { mHbmController.dump(pw); } void onAmbientLuxChange(float ambientLux) { if (NBM_FEATURE_FLAG) { boolean nbmTransitionChanged = mNormalBrightnessModeController.onAmbientLuxChange( ambientLux); int previousHbm = mHbmController.getHighBrightnessMode(); mHbmController.onAmbientLuxChange(ambientLux); int nextHbm = mHbmController.getHighBrightnessMode(); // if hbm changed - callback was triggered in mHbmController.onAmbientLuxChange // if nbm transition not changed - no need to trigger callback if (previousHbm == nextHbm && nbmTransitionChanged) { mModeChangeCallback.run(); } } else { mHbmController.onAmbientLuxChange(ambientLux); } } float getNormalBrightnessMax() { return mHbmController.getNormalBrightnessMax(); } void loadFromConfig(HighBrightnessModeMetadata hbmMetadata, IBinder token, DisplayDeviceInfo info, DisplayDeviceConfig displayDeviceConfig) { mHbmController.setHighBrightnessModeMetadata(hbmMetadata); mHbmController.resetHbmData(info.width, info.height, token, info.uniqueId, displayDeviceConfig.getHighBrightnessModeData(), displayDeviceConfig::getHdrBrightnessFromSdr); } void stop() { mHbmController.stop(); } void setAutoBrightnessEnabled(int state) { mHbmController.setAutoBrightnessEnabled(state); } void onBrightnessChanged(float brightness, float unthrottledBrightness, @BrightnessInfo.BrightnessMaxReason int throttlingReason) { mHbmController.onBrightnessChanged(brightness, unthrottledBrightness, throttlingReason); } float getCurrentBrightnessMin() { return mHbmController.getCurrentBrightnessMin(); } float getCurrentBrightnessMax() { if (NBM_FEATURE_FLAG && mHbmController.getHighBrightnessMode() == BrightnessInfo.HIGH_BRIGHTNESS_MODE_OFF) { return Math.min(mHbmController.getCurrentBrightnessMax(), mNormalBrightnessModeController.getCurrentBrightnessMax()); } return mHbmController.getCurrentBrightnessMax(); } int getHighBrightnessMode() { return mHbmController.getHighBrightnessMode(); } float getHdrBrightnessValue() { return mHbmController.getHdrBrightnessValue(); } float getTransitionPoint() { return mHbmController.getTransitionPoint(); } }
services/core/java/com/android/server/display/DisplayPowerController.java +42 −44 Original line number Diff line number Diff line Loading @@ -445,7 +445,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call private final ColorDisplayServiceInternal mCdsi; private float[] mNitsRange; private final HighBrightnessModeController mHbmController; private final BrightnessRangeController mBrightnessRangeController; private final HighBrightnessModeMetadata mHighBrightnessModeMetadata; private final BrightnessThrottler mBrightnessThrottler; Loading Loading @@ -654,8 +654,19 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call loadBrightnessRampRates(); mSkipScreenOnBrightnessRamp = resources.getBoolean( com.android.internal.R.bool.config_skipScreenOnBrightnessRamp); Runnable modeChangeCallback = () -> { sendUpdatePowerState(); postBrightnessChangeRunnable(); // TODO(b/192258832): Switch the HBMChangeCallback to a listener pattern. if (mAutomaticBrightnessController != null) { mAutomaticBrightnessController.update(); } }; HighBrightnessModeController hbmController = createHbmControllerLocked(modeChangeCallback); mHbmController = createHbmControllerLocked(); mBrightnessRangeController = new BrightnessRangeController(hbmController, modeChangeCallback); mBrightnessThrottler = createBrightnessThrottlerLocked(); Loading Loading @@ -802,7 +813,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call @Override public void setBrightnessToFollow(float leadDisplayBrightness, float nits, float ambientLux) { mHbmController.onAmbientLuxChange(ambientLux); mBrightnessRangeController.onAmbientLuxChange(ambientLux); if (nits < 0) { mBrightnessToFollow = leadDisplayBrightness; } else { Loading Loading @@ -1039,17 +1050,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call mBrightnessRampIncreaseMaxTimeMillis, mBrightnessRampDecreaseMaxTimeMillis); } mHbmController.setHighBrightnessModeMetadata(hbmMetadata); mHbmController.resetHbmData(info.width, info.height, token, info.uniqueId, mDisplayDeviceConfig.getHighBrightnessModeData(), new HighBrightnessModeController.HdrBrightnessDeviceConfig() { @Override public float getHdrBrightnessFromSdr( float sdrBrightness, float maxDesiredHdrSdrRatio) { return mDisplayDeviceConfig.getHdrBrightnessFromSdr( sdrBrightness, maxDesiredHdrSdrRatio); } }); mBrightnessRangeController.loadFromConfig(hbmMetadata, token, info, mDisplayDeviceConfig); mBrightnessThrottler.loadThermalBrightnessThrottlingDataFromDisplayDeviceConfig( mDisplayDeviceConfig.getThermalBrightnessThrottlingDataMapByThrottlingId(), mThermalBrightnessThrottlingDataId, mUniqueDisplayId); Loading Loading @@ -1264,7 +1265,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call darkeningLightDebounce, autoBrightnessResetAmbientLuxAfterWarmUp, ambientBrightnessThresholds, screenBrightnessThresholds, ambientBrightnessThresholdsIdle, screenBrightnessThresholdsIdle, mContext, mHbmController, mBrightnessThrottler, mIdleModeBrightnessMapper, mBrightnessRangeController, mBrightnessThrottler, mIdleModeBrightnessMapper, mDisplayDeviceConfig.getAmbientHorizonShort(), mDisplayDeviceConfig.getAmbientHorizonLong(), userLux, userBrightness); Loading Loading @@ -1364,7 +1365,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call /** Clean up all resources that are accessed via the {@link #mHandler} thread. */ private void cleanupHandlerThreadAfterStop() { setProximitySensorEnabled(false); mHbmController.stop(); mBrightnessRangeController.stop(); mBrightnessThrottler.stop(); mHandler.removeCallbacksAndMessages(null); Loading Loading @@ -1647,7 +1648,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call mShouldResetShortTermModel); mShouldResetShortTermModel = false; } mHbmController.setAutoBrightnessEnabled(mUseAutoBrightness mBrightnessRangeController.setAutoBrightnessEnabled(mUseAutoBrightness ? AutomaticBrightnessController.AUTO_BRIGHTNESS_ENABLED : AutomaticBrightnessController.AUTO_BRIGHTNESS_DISABLED); Loading Loading @@ -1820,7 +1821,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call // here instead of having HbmController listen to the brightness setting because certain // brightness sources (such as an app override) are not saved to the setting, but should be // reflected in HBM calculations. mHbmController.onBrightnessChanged(brightnessState, unthrottledBrightnessState, mBrightnessRangeController.onBrightnessChanged(brightnessState, unthrottledBrightnessState, mBrightnessThrottler.getBrightnessMaxReason()); // Animate the screen brightness when the screen is on or dozing. Loading Loading @@ -1874,13 +1875,14 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call float sdrAnimateValue = animateValue; // TODO(b/216365040): The decision to prevent HBM for HDR in low power mode should be // done in HighBrightnessModeController. if (mHbmController.getHighBrightnessMode() == BrightnessInfo.HIGH_BRIGHTNESS_MODE_HDR if (mBrightnessRangeController.getHighBrightnessMode() == BrightnessInfo.HIGH_BRIGHTNESS_MODE_HDR && (mBrightnessReasonTemp.getModifier() & BrightnessReason.MODIFIER_DIMMED) == 0 && (mBrightnessReasonTemp.getModifier() & BrightnessReason.MODIFIER_LOW_POWER) == 0) { // 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 = mHbmController.getHdrBrightnessValue(); animateValue = mBrightnessRangeController.getHdrBrightnessValue(); } final float currentBrightness = mPowerState.getScreenBrightness(); Loading Loading @@ -1942,8 +1944,8 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call mTempBrightnessEvent.setBrightness(brightnessState); mTempBrightnessEvent.setPhysicalDisplayId(mUniqueDisplayId); mTempBrightnessEvent.setReason(mBrightnessReason); mTempBrightnessEvent.setHbmMax(mHbmController.getCurrentBrightnessMax()); mTempBrightnessEvent.setHbmMode(mHbmController.getHighBrightnessMode()); mTempBrightnessEvent.setHbmMax(mBrightnessRangeController.getCurrentBrightnessMax()); mTempBrightnessEvent.setHbmMode(mBrightnessRangeController.getHighBrightnessMode()); mTempBrightnessEvent.setFlags(mTempBrightnessEvent.getFlags() | (mIsRbcActive ? BrightnessEvent.FLAG_RBC : 0) | (mPowerRequest.lowPowerMode ? BrightnessEvent.FLAG_LOW_POWER_MODE : 0)); Loading Loading @@ -2104,9 +2106,11 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call private boolean saveBrightnessInfo(float brightness, float adjustedBrightness) { synchronized (mCachedBrightnessInfo) { final float minBrightness = Math.min(mHbmController.getCurrentBrightnessMin(), final float minBrightness = Math.min( mBrightnessRangeController.getCurrentBrightnessMin(), mBrightnessThrottler.getBrightnessCap()); final float maxBrightness = Math.min(mHbmController.getCurrentBrightnessMax(), final float maxBrightness = Math.min( mBrightnessRangeController.getCurrentBrightnessMax(), mBrightnessThrottler.getBrightnessCap()); boolean changed = false; Loading @@ -2124,10 +2128,10 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call maxBrightness); changed |= mCachedBrightnessInfo.checkAndSetInt(mCachedBrightnessInfo.hbmMode, mHbmController.getHighBrightnessMode()); mBrightnessRangeController.getHighBrightnessMode()); changed |= mCachedBrightnessInfo.checkAndSetFloat(mCachedBrightnessInfo.hbmTransitionPoint, mHbmController.getTransitionPoint()); mBrightnessRangeController.getTransitionPoint()); changed |= mCachedBrightnessInfo.checkAndSetInt(mCachedBrightnessInfo.brightnessMaxReason, mBrightnessThrottler.getBrightnessMaxReason()); Loading @@ -2140,7 +2144,8 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call mHandler.post(mOnBrightnessChangeRunnable); } private HighBrightnessModeController createHbmControllerLocked() { private HighBrightnessModeController createHbmControllerLocked( Runnable modeChangeCallback) { final DisplayDevice device = mLogicalDisplay.getPrimaryDisplayDeviceLocked(); final DisplayDeviceConfig ddConfig = device.getDisplayDeviceConfig(); final IBinder displayToken = Loading @@ -2159,15 +2164,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call return mDisplayDeviceConfig.getHdrBrightnessFromSdr( sdrBrightness, maxDesiredHdrSdrRatio); } }, () -> { sendUpdatePowerState(); postBrightnessChangeRunnable(); // TODO(b/192258832): Switch the HBMChangeCallback to a listener pattern. if (mAutomaticBrightnessController != null) { mAutomaticBrightnessController.update(); } }, mHighBrightnessModeMetadata, mContext); }, modeChangeCallback, mHighBrightnessModeMetadata, mContext); } private BrightnessThrottler createBrightnessThrottlerLocked() { Loading Loading @@ -2328,8 +2325,8 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call if (Float.isNaN(value)) { value = PowerManager.BRIGHTNESS_MIN; } return MathUtils.constrain(value, mHbmController.getCurrentBrightnessMin(), mHbmController.getCurrentBrightnessMax()); return MathUtils.constrain(value, mBrightnessRangeController.getCurrentBrightnessMin(), mBrightnessRangeController.getCurrentBrightnessMax()); } // Checks whether the brightness is within the valid brightness range, not including off. Loading Loading @@ -3003,8 +3000,8 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call mScreenOffBrightnessSensorController.dump(pw); } if (mHbmController != null) { mHbmController.dump(pw); if (mBrightnessRangeController != null) { mBrightnessRangeController.dump(pw); } if (mBrightnessThrottler != null) { Loading Loading @@ -3471,7 +3468,8 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call HysteresisLevels screenBrightnessThresholds, HysteresisLevels ambientBrightnessThresholdsIdle, HysteresisLevels screenBrightnessThresholdsIdle, Context context, HighBrightnessModeController hbmController, BrightnessThrottler brightnessThrottler, BrightnessRangeController brightnessRangeController, BrightnessThrottler brightnessThrottler, BrightnessMappingStrategy idleModeBrightnessMapper, int ambientLightHorizonShort, int ambientLightHorizonLong, float userLux, float userBrightness) { return new AutomaticBrightnessController(callbacks, looper, sensorManager, lightSensor, Loading @@ -3480,9 +3478,9 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call brighteningLightDebounceConfig, darkeningLightDebounceConfig, resetAmbientLuxAfterWarmUpConfig, ambientBrightnessThresholds, screenBrightnessThresholds, ambientBrightnessThresholdsIdle, screenBrightnessThresholdsIdle, context, hbmController, brightnessThrottler, idleModeBrightnessMapper, ambientLightHorizonShort, ambientLightHorizonLong, userLux, userBrightness); screenBrightnessThresholdsIdle, context, brightnessRangeController, brightnessThrottler, idleModeBrightnessMapper, ambientLightHorizonShort, ambientLightHorizonLong, userLux, userBrightness); } BrightnessMappingStrategy getInteractiveModeBrightnessMapper(Resources resources, Loading
services/core/java/com/android/server/display/DisplayPowerController2.java +47 −53 File changed.Preview size limit exceeded, changes collapsed. Show changes
services/core/java/com/android/server/display/NormalBrightnessModeController.java 0 → 100644 +51 −0 Original line number Diff line number Diff line /* * Copyright (C) 2023 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; import android.os.PowerManager; import java.util.HashMap; import java.util.Map; class NormalBrightnessModeController { private Map<Float, Float> mTransitionPoints = new HashMap<>(); // brightness limit in normal brightness mode, based on ambient lux. private float mVirtualTransitionPoint = PowerManager.BRIGHTNESS_MAX; boolean onAmbientLuxChange(float ambientLux) { float currentAmbientBoundary = Float.MAX_VALUE; float currentTransitionPoint = PowerManager.BRIGHTNESS_MAX; for (Map.Entry<Float, Float> transitionPoint: mTransitionPoints.entrySet()) { float ambientBoundary = transitionPoint.getKey(); // find ambient lux upper boundary closest to current ambient lux if (ambientBoundary > ambientLux && ambientBoundary < currentAmbientBoundary) { currentTransitionPoint = transitionPoint.getValue(); currentAmbientBoundary = ambientBoundary; } } if (mVirtualTransitionPoint != currentTransitionPoint) { mVirtualTransitionPoint = currentTransitionPoint; return true; } return false; } float getCurrentBrightnessMax() { return mVirtualTransitionPoint; } }