NormalBrightnessModeController structure

Introducing NormalBrightnessModeController. No functional changes in this CL, only refactoring to enable NBMController related logic.

Bug: b/277877297
Test: atest DisplayPowerController2Test, atest AutomaticBrightnessControllerTest
Change-Id: I738151e3cb269f3408db731e8edeced59535c3cc
Merged-In: I738151e3cb269f3408db731e8edeced59535c3cc
This commit is contained in:
petsjonkin
2023-05-19 16:05:57 +00:00
committed by Peter Lin
parent cc77216572
commit ac0d75f2d2
8 changed files with 279 additions and 118 deletions

View File

@@ -223,11 +223,11 @@ public class AutomaticBrightnessController {
private final ShortTermModel mShortTermModel; private final ShortTermModel mShortTermModel;
private final ShortTermModel mPausedShortTermModel; private final ShortTermModel mPausedShortTermModel;
// Controls High Brightness Mode. // Controls Brightness range (including High Brightness Mode).
private HighBrightnessModeController mHbmController; private final BrightnessRangeController mBrightnessRangeController;
// Throttles (caps) maximum allowed brightness // Throttles (caps) maximum allowed brightness
private BrightnessThrottler mBrightnessThrottler; private final BrightnessThrottler mBrightnessThrottler;
private boolean mIsBrightnessThrottled; private boolean mIsBrightnessThrottled;
// Context-sensitive brightness configurations require keeping track of the foreground app's // Context-sensitive brightness configurations require keeping track of the foreground app's
@@ -257,7 +257,8 @@ public class AutomaticBrightnessController {
HysteresisLevels screenBrightnessThresholds, HysteresisLevels screenBrightnessThresholds,
HysteresisLevels ambientBrightnessThresholdsIdle, HysteresisLevels ambientBrightnessThresholdsIdle,
HysteresisLevels screenBrightnessThresholdsIdle, Context context, HysteresisLevels screenBrightnessThresholdsIdle, Context context,
HighBrightnessModeController hbmController, BrightnessThrottler brightnessThrottler, BrightnessRangeController brightnessModeController,
BrightnessThrottler brightnessThrottler,
BrightnessMappingStrategy idleModeBrightnessMapper, int ambientLightHorizonShort, BrightnessMappingStrategy idleModeBrightnessMapper, int ambientLightHorizonShort,
int ambientLightHorizonLong, float userLux, float userBrightness) { int ambientLightHorizonLong, float userLux, float userBrightness) {
this(new Injector(), callbacks, looper, sensorManager, lightSensor, this(new Injector(), callbacks, looper, sensorManager, lightSensor,
@@ -267,7 +268,7 @@ public class AutomaticBrightnessController {
darkeningLightDebounceConfig, resetAmbientLuxAfterWarmUpConfig, darkeningLightDebounceConfig, resetAmbientLuxAfterWarmUpConfig,
ambientBrightnessThresholds, screenBrightnessThresholds, ambientBrightnessThresholds, screenBrightnessThresholds,
ambientBrightnessThresholdsIdle, screenBrightnessThresholdsIdle, context, ambientBrightnessThresholdsIdle, screenBrightnessThresholdsIdle, context,
hbmController, brightnessThrottler, idleModeBrightnessMapper, brightnessModeController, brightnessThrottler, idleModeBrightnessMapper,
ambientLightHorizonShort, ambientLightHorizonLong, userLux, userBrightness ambientLightHorizonShort, ambientLightHorizonLong, userLux, userBrightness
); );
} }
@@ -283,7 +284,8 @@ public class AutomaticBrightnessController {
HysteresisLevels screenBrightnessThresholds, HysteresisLevels screenBrightnessThresholds,
HysteresisLevels ambientBrightnessThresholdsIdle, HysteresisLevels ambientBrightnessThresholdsIdle,
HysteresisLevels screenBrightnessThresholdsIdle, Context context, HysteresisLevels screenBrightnessThresholdsIdle, Context context,
HighBrightnessModeController hbmController, BrightnessThrottler brightnessThrottler, BrightnessRangeController brightnessModeController,
BrightnessThrottler brightnessThrottler,
BrightnessMappingStrategy idleModeBrightnessMapper, int ambientLightHorizonShort, BrightnessMappingStrategy idleModeBrightnessMapper, int ambientLightHorizonShort,
int ambientLightHorizonLong, float userLux, float userBrightness) { int ambientLightHorizonLong, float userLux, float userBrightness) {
mInjector = injector; mInjector = injector;
@@ -326,7 +328,7 @@ public class AutomaticBrightnessController {
mPendingForegroundAppPackageName = null; mPendingForegroundAppPackageName = null;
mForegroundAppCategory = ApplicationInfo.CATEGORY_UNDEFINED; mForegroundAppCategory = ApplicationInfo.CATEGORY_UNDEFINED;
mPendingForegroundAppCategory = ApplicationInfo.CATEGORY_UNDEFINED; mPendingForegroundAppCategory = ApplicationInfo.CATEGORY_UNDEFINED;
mHbmController = hbmController; mBrightnessRangeController = brightnessModeController;
mBrightnessThrottler = brightnessThrottler; mBrightnessThrottler = brightnessThrottler;
mInteractiveModeBrightnessMapper = interactiveModeBrightnessMapper; mInteractiveModeBrightnessMapper = interactiveModeBrightnessMapper;
mIdleModeBrightnessMapper = idleModeBrightnessMapper; mIdleModeBrightnessMapper = idleModeBrightnessMapper;
@@ -607,10 +609,11 @@ public class AutomaticBrightnessController {
pw.println(); pw.println();
pw.println(" mInteractiveMapper="); pw.println(" mInteractiveMapper=");
mInteractiveModeBrightnessMapper.dump(pw, mHbmController.getNormalBrightnessMax()); mInteractiveModeBrightnessMapper.dump(pw,
mBrightnessRangeController.getNormalBrightnessMax());
if (mIdleModeBrightnessMapper != null) { if (mIdleModeBrightnessMapper != null) {
pw.println(" mIdleMapper="); pw.println(" mIdleMapper=");
mIdleModeBrightnessMapper.dump(pw, mHbmController.getNormalBrightnessMax()); mIdleModeBrightnessMapper.dump(pw, mBrightnessRangeController.getNormalBrightnessMax());
} }
pw.println(); pw.println();
@@ -736,7 +739,7 @@ public class AutomaticBrightnessController {
mAmbientDarkeningThreshold = mAmbientDarkeningThreshold =
mAmbientBrightnessThresholds.getDarkeningThreshold(lux); mAmbientBrightnessThresholds.getDarkeningThreshold(lux);
} }
mHbmController.onAmbientLuxChange(mAmbientLux); mBrightnessRangeController.onAmbientLuxChange(mAmbientLux);
// If the short term model was invalidated and the change is drastic enough, reset it. // If the short term model was invalidated and the change is drastic enough, reset it.
@@ -976,9 +979,9 @@ public class AutomaticBrightnessController {
// Clamps values with float range [0.0-1.0] // Clamps values with float range [0.0-1.0]
private float clampScreenBrightness(float value) { private float clampScreenBrightness(float value) {
final float minBrightness = Math.min(mHbmController.getCurrentBrightnessMin(), final float minBrightness = Math.min(mBrightnessRangeController.getCurrentBrightnessMin(),
mBrightnessThrottler.getBrightnessCap()); mBrightnessThrottler.getBrightnessCap());
final float maxBrightness = Math.min(mHbmController.getCurrentBrightnessMax(), final float maxBrightness = Math.min(mBrightnessRangeController.getCurrentBrightnessMax(),
mBrightnessThrottler.getBrightnessCap()); mBrightnessThrottler.getBrightnessCap());
return MathUtils.constrain(value, minBrightness, maxBrightness); return MathUtils.constrain(value, minBrightness, maxBrightness);
} }

View File

@@ -0,0 +1,112 @@
/*
* 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();
}
}

View File

@@ -445,7 +445,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
private final ColorDisplayServiceInternal mCdsi; private final ColorDisplayServiceInternal mCdsi;
private float[] mNitsRange; private float[] mNitsRange;
private final HighBrightnessModeController mHbmController; private final BrightnessRangeController mBrightnessRangeController;
private final HighBrightnessModeMetadata mHighBrightnessModeMetadata; private final HighBrightnessModeMetadata mHighBrightnessModeMetadata;
private final BrightnessThrottler mBrightnessThrottler; private final BrightnessThrottler mBrightnessThrottler;
@@ -654,8 +654,19 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
loadBrightnessRampRates(); loadBrightnessRampRates();
mSkipScreenOnBrightnessRamp = resources.getBoolean( mSkipScreenOnBrightnessRamp = resources.getBoolean(
com.android.internal.R.bool.config_skipScreenOnBrightnessRamp); 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();
}
};
mHbmController = createHbmControllerLocked(); HighBrightnessModeController hbmController = createHbmControllerLocked(modeChangeCallback);
mBrightnessRangeController = new BrightnessRangeController(hbmController,
modeChangeCallback);
mBrightnessThrottler = createBrightnessThrottlerLocked(); mBrightnessThrottler = createBrightnessThrottlerLocked();
@@ -802,7 +813,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
@Override @Override
public void setBrightnessToFollow(float leadDisplayBrightness, float nits, float ambientLux) { public void setBrightnessToFollow(float leadDisplayBrightness, float nits, float ambientLux) {
mHbmController.onAmbientLuxChange(ambientLux); mBrightnessRangeController.onAmbientLuxChange(ambientLux);
if (nits < 0) { if (nits < 0) {
mBrightnessToFollow = leadDisplayBrightness; mBrightnessToFollow = leadDisplayBrightness;
} else { } else {
@@ -1039,17 +1050,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
mBrightnessRampIncreaseMaxTimeMillis, mBrightnessRampIncreaseMaxTimeMillis,
mBrightnessRampDecreaseMaxTimeMillis); mBrightnessRampDecreaseMaxTimeMillis);
} }
mHbmController.setHighBrightnessModeMetadata(hbmMetadata); mBrightnessRangeController.loadFromConfig(hbmMetadata, token, info, mDisplayDeviceConfig);
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);
}
});
mBrightnessThrottler.loadThermalBrightnessThrottlingDataFromDisplayDeviceConfig( mBrightnessThrottler.loadThermalBrightnessThrottlingDataFromDisplayDeviceConfig(
mDisplayDeviceConfig.getThermalBrightnessThrottlingDataMapByThrottlingId(), mDisplayDeviceConfig.getThermalBrightnessThrottlingDataMapByThrottlingId(),
mThermalBrightnessThrottlingDataId, mUniqueDisplayId); mThermalBrightnessThrottlingDataId, mUniqueDisplayId);
@@ -1264,7 +1265,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
darkeningLightDebounce, autoBrightnessResetAmbientLuxAfterWarmUp, darkeningLightDebounce, autoBrightnessResetAmbientLuxAfterWarmUp,
ambientBrightnessThresholds, screenBrightnessThresholds, ambientBrightnessThresholds, screenBrightnessThresholds,
ambientBrightnessThresholdsIdle, screenBrightnessThresholdsIdle, mContext, ambientBrightnessThresholdsIdle, screenBrightnessThresholdsIdle, mContext,
mHbmController, mBrightnessThrottler, mIdleModeBrightnessMapper, mBrightnessRangeController, mBrightnessThrottler, mIdleModeBrightnessMapper,
mDisplayDeviceConfig.getAmbientHorizonShort(), mDisplayDeviceConfig.getAmbientHorizonShort(),
mDisplayDeviceConfig.getAmbientHorizonLong(), userLux, userBrightness); mDisplayDeviceConfig.getAmbientHorizonLong(), userLux, userBrightness);
@@ -1364,7 +1365,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
/** Clean up all resources that are accessed via the {@link #mHandler} thread. */ /** Clean up all resources that are accessed via the {@link #mHandler} thread. */
private void cleanupHandlerThreadAfterStop() { private void cleanupHandlerThreadAfterStop() {
setProximitySensorEnabled(false); setProximitySensorEnabled(false);
mHbmController.stop(); mBrightnessRangeController.stop();
mBrightnessThrottler.stop(); mBrightnessThrottler.stop();
mHandler.removeCallbacksAndMessages(null); mHandler.removeCallbacksAndMessages(null);
@@ -1647,7 +1648,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
mShouldResetShortTermModel); mShouldResetShortTermModel);
mShouldResetShortTermModel = false; mShouldResetShortTermModel = false;
} }
mHbmController.setAutoBrightnessEnabled(mUseAutoBrightness mBrightnessRangeController.setAutoBrightnessEnabled(mUseAutoBrightness
? AutomaticBrightnessController.AUTO_BRIGHTNESS_ENABLED ? AutomaticBrightnessController.AUTO_BRIGHTNESS_ENABLED
: AutomaticBrightnessController.AUTO_BRIGHTNESS_DISABLED); : AutomaticBrightnessController.AUTO_BRIGHTNESS_DISABLED);
@@ -1820,7 +1821,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
// here instead of having HbmController listen to the brightness setting because certain // 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 // brightness sources (such as an app override) are not saved to the setting, but should be
// reflected in HBM calculations. // reflected in HBM calculations.
mHbmController.onBrightnessChanged(brightnessState, unthrottledBrightnessState, mBrightnessRangeController.onBrightnessChanged(brightnessState, unthrottledBrightnessState,
mBrightnessThrottler.getBrightnessMaxReason()); mBrightnessThrottler.getBrightnessMaxReason());
// Animate the screen brightness when the screen is on or dozing. // Animate the screen brightness when the screen is on or dozing.
@@ -1874,13 +1875,14 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
float sdrAnimateValue = animateValue; float sdrAnimateValue = animateValue;
// TODO(b/216365040): The decision to prevent HBM for HDR in low power mode should be // TODO(b/216365040): The decision to prevent HBM for HDR in low power mode should be
// done in HighBrightnessModeController. // 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_DIMMED) == 0
&& (mBrightnessReasonTemp.getModifier() & BrightnessReason.MODIFIER_LOW_POWER) && (mBrightnessReasonTemp.getModifier() & BrightnessReason.MODIFIER_LOW_POWER)
== 0) { == 0) {
// We want to scale HDR brightness level with the SDR level, we also need to restore // 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. // SDR brightness immediately when entering dim or low power mode.
animateValue = mHbmController.getHdrBrightnessValue(); animateValue = mBrightnessRangeController.getHdrBrightnessValue();
} }
final float currentBrightness = mPowerState.getScreenBrightness(); final float currentBrightness = mPowerState.getScreenBrightness();
@@ -1942,8 +1944,8 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
mTempBrightnessEvent.setBrightness(brightnessState); mTempBrightnessEvent.setBrightness(brightnessState);
mTempBrightnessEvent.setPhysicalDisplayId(mUniqueDisplayId); mTempBrightnessEvent.setPhysicalDisplayId(mUniqueDisplayId);
mTempBrightnessEvent.setReason(mBrightnessReason); mTempBrightnessEvent.setReason(mBrightnessReason);
mTempBrightnessEvent.setHbmMax(mHbmController.getCurrentBrightnessMax()); mTempBrightnessEvent.setHbmMax(mBrightnessRangeController.getCurrentBrightnessMax());
mTempBrightnessEvent.setHbmMode(mHbmController.getHighBrightnessMode()); mTempBrightnessEvent.setHbmMode(mBrightnessRangeController.getHighBrightnessMode());
mTempBrightnessEvent.setFlags(mTempBrightnessEvent.getFlags() mTempBrightnessEvent.setFlags(mTempBrightnessEvent.getFlags()
| (mIsRbcActive ? BrightnessEvent.FLAG_RBC : 0) | (mIsRbcActive ? BrightnessEvent.FLAG_RBC : 0)
| (mPowerRequest.lowPowerMode ? BrightnessEvent.FLAG_LOW_POWER_MODE : 0)); | (mPowerRequest.lowPowerMode ? BrightnessEvent.FLAG_LOW_POWER_MODE : 0));
@@ -2104,9 +2106,11 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
private boolean saveBrightnessInfo(float brightness, float adjustedBrightness) { private boolean saveBrightnessInfo(float brightness, float adjustedBrightness) {
synchronized (mCachedBrightnessInfo) { synchronized (mCachedBrightnessInfo) {
final float minBrightness = Math.min(mHbmController.getCurrentBrightnessMin(), final float minBrightness = Math.min(
mBrightnessRangeController.getCurrentBrightnessMin(),
mBrightnessThrottler.getBrightnessCap()); mBrightnessThrottler.getBrightnessCap());
final float maxBrightness = Math.min(mHbmController.getCurrentBrightnessMax(), final float maxBrightness = Math.min(
mBrightnessRangeController.getCurrentBrightnessMax(),
mBrightnessThrottler.getBrightnessCap()); mBrightnessThrottler.getBrightnessCap());
boolean changed = false; boolean changed = false;
@@ -2124,10 +2128,10 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
maxBrightness); maxBrightness);
changed |= changed |=
mCachedBrightnessInfo.checkAndSetInt(mCachedBrightnessInfo.hbmMode, mCachedBrightnessInfo.checkAndSetInt(mCachedBrightnessInfo.hbmMode,
mHbmController.getHighBrightnessMode()); mBrightnessRangeController.getHighBrightnessMode());
changed |= changed |=
mCachedBrightnessInfo.checkAndSetFloat(mCachedBrightnessInfo.hbmTransitionPoint, mCachedBrightnessInfo.checkAndSetFloat(mCachedBrightnessInfo.hbmTransitionPoint,
mHbmController.getTransitionPoint()); mBrightnessRangeController.getTransitionPoint());
changed |= changed |=
mCachedBrightnessInfo.checkAndSetInt(mCachedBrightnessInfo.brightnessMaxReason, mCachedBrightnessInfo.checkAndSetInt(mCachedBrightnessInfo.brightnessMaxReason,
mBrightnessThrottler.getBrightnessMaxReason()); mBrightnessThrottler.getBrightnessMaxReason());
@@ -2140,7 +2144,8 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
mHandler.post(mOnBrightnessChangeRunnable); mHandler.post(mOnBrightnessChangeRunnable);
} }
private HighBrightnessModeController createHbmControllerLocked() { private HighBrightnessModeController createHbmControllerLocked(
Runnable modeChangeCallback) {
final DisplayDevice device = mLogicalDisplay.getPrimaryDisplayDeviceLocked(); final DisplayDevice device = mLogicalDisplay.getPrimaryDisplayDeviceLocked();
final DisplayDeviceConfig ddConfig = device.getDisplayDeviceConfig(); final DisplayDeviceConfig ddConfig = device.getDisplayDeviceConfig();
final IBinder displayToken = final IBinder displayToken =
@@ -2159,15 +2164,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
return mDisplayDeviceConfig.getHdrBrightnessFromSdr( return mDisplayDeviceConfig.getHdrBrightnessFromSdr(
sdrBrightness, maxDesiredHdrSdrRatio); sdrBrightness, maxDesiredHdrSdrRatio);
} }
}, }, modeChangeCallback, mHighBrightnessModeMetadata, mContext);
() -> {
sendUpdatePowerState();
postBrightnessChangeRunnable();
// TODO(b/192258832): Switch the HBMChangeCallback to a listener pattern.
if (mAutomaticBrightnessController != null) {
mAutomaticBrightnessController.update();
}
}, mHighBrightnessModeMetadata, mContext);
} }
private BrightnessThrottler createBrightnessThrottlerLocked() { private BrightnessThrottler createBrightnessThrottlerLocked() {
@@ -2328,8 +2325,8 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
if (Float.isNaN(value)) { if (Float.isNaN(value)) {
value = PowerManager.BRIGHTNESS_MIN; value = PowerManager.BRIGHTNESS_MIN;
} }
return MathUtils.constrain(value, return MathUtils.constrain(value, mBrightnessRangeController.getCurrentBrightnessMin(),
mHbmController.getCurrentBrightnessMin(), mHbmController.getCurrentBrightnessMax()); mBrightnessRangeController.getCurrentBrightnessMax());
} }
// Checks whether the brightness is within the valid brightness range, not including off. // Checks whether the brightness is within the valid brightness range, not including off.
@@ -3003,8 +3000,8 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
mScreenOffBrightnessSensorController.dump(pw); mScreenOffBrightnessSensorController.dump(pw);
} }
if (mHbmController != null) { if (mBrightnessRangeController != null) {
mHbmController.dump(pw); mBrightnessRangeController.dump(pw);
} }
if (mBrightnessThrottler != null) { if (mBrightnessThrottler != null) {
@@ -3471,7 +3468,8 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
HysteresisLevels screenBrightnessThresholds, HysteresisLevels screenBrightnessThresholds,
HysteresisLevels ambientBrightnessThresholdsIdle, HysteresisLevels ambientBrightnessThresholdsIdle,
HysteresisLevels screenBrightnessThresholdsIdle, Context context, HysteresisLevels screenBrightnessThresholdsIdle, Context context,
HighBrightnessModeController hbmController, BrightnessThrottler brightnessThrottler, BrightnessRangeController brightnessRangeController,
BrightnessThrottler brightnessThrottler,
BrightnessMappingStrategy idleModeBrightnessMapper, int ambientLightHorizonShort, BrightnessMappingStrategy idleModeBrightnessMapper, int ambientLightHorizonShort,
int ambientLightHorizonLong, float userLux, float userBrightness) { int ambientLightHorizonLong, float userLux, float userBrightness) {
return new AutomaticBrightnessController(callbacks, looper, sensorManager, lightSensor, return new AutomaticBrightnessController(callbacks, looper, sensorManager, lightSensor,
@@ -3480,9 +3478,9 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
brighteningLightDebounceConfig, darkeningLightDebounceConfig, brighteningLightDebounceConfig, darkeningLightDebounceConfig,
resetAmbientLuxAfterWarmUpConfig, ambientBrightnessThresholds, resetAmbientLuxAfterWarmUpConfig, ambientBrightnessThresholds,
screenBrightnessThresholds, ambientBrightnessThresholdsIdle, screenBrightnessThresholds, ambientBrightnessThresholdsIdle,
screenBrightnessThresholdsIdle, context, hbmController, brightnessThrottler, screenBrightnessThresholdsIdle, context, brightnessRangeController,
idleModeBrightnessMapper, ambientLightHorizonShort, ambientLightHorizonLong, brightnessThrottler, idleModeBrightnessMapper, ambientLightHorizonShort,
userLux, userBrightness); ambientLightHorizonLong, userLux, userBrightness);
} }
BrightnessMappingStrategy getInteractiveModeBrightnessMapper(Resources resources, BrightnessMappingStrategy getInteractiveModeBrightnessMapper(Resources resources,

View File

@@ -376,8 +376,7 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
private final ColorDisplayServiceInternal mCdsi; private final ColorDisplayServiceInternal mCdsi;
private float[] mNitsRange; private float[] mNitsRange;
private final HighBrightnessModeController mHbmController; private final BrightnessRangeController mBrightnessRangeController;
private final HighBrightnessModeMetadata mHighBrightnessModeMetadata;
private final BrightnessThrottler mBrightnessThrottler; private final BrightnessThrottler mBrightnessThrottler;
@@ -489,7 +488,6 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
mDisplayPowerProximityStateController = mInjector.getDisplayPowerProximityStateController( mDisplayPowerProximityStateController = mInjector.getDisplayPowerProximityStateController(
mWakelockController, mDisplayDeviceConfig, mHandler.getLooper(), mWakelockController, mDisplayDeviceConfig, mHandler.getLooper(),
() -> updatePowerState(), mDisplayId, mSensorManager); () -> updatePowerState(), mDisplayId, mSensorManager);
mHighBrightnessModeMetadata = hbmMetadata;
mDisplayStateController = new DisplayStateController(mDisplayPowerProximityStateController); mDisplayStateController = new DisplayStateController(mDisplayPowerProximityStateController);
mAutomaticBrightnessStrategy = new AutomaticBrightnessStrategy(context, mDisplayId); mAutomaticBrightnessStrategy = new AutomaticBrightnessStrategy(context, mDisplayId);
mTag = "DisplayPowerController2[" + mDisplayId + "]"; mTag = "DisplayPowerController2[" + mDisplayId + "]";
@@ -532,9 +530,22 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
mSkipScreenOnBrightnessRamp = resources.getBoolean( mSkipScreenOnBrightnessRamp = resources.getBoolean(
R.bool.config_skipScreenOnBrightnessRamp); R.bool.config_skipScreenOnBrightnessRamp);
mHbmController = createHbmControllerLocked(); Runnable modeChangeCallback = () -> {
sendUpdatePowerState();
postBrightnessChangeRunnable();
// TODO(b/192258832): Switch the HBMChangeCallback to a listener pattern.
if (mAutomaticBrightnessController != null) {
mAutomaticBrightnessController.update();
}
};
HighBrightnessModeController hbmController = createHbmControllerLocked(hbmMetadata,
modeChangeCallback);
mBrightnessThrottler = createBrightnessThrottlerLocked(); mBrightnessThrottler = createBrightnessThrottlerLocked();
mBrightnessRangeController = new BrightnessRangeController(hbmController,
modeChangeCallback);
mDisplayBrightnessController = mDisplayBrightnessController =
new DisplayBrightnessController(context, null, new DisplayBrightnessController(context, null,
mDisplayId, mLogicalDisplay.getDisplayInfoLocked().brightnessDefault, mDisplayId, mLogicalDisplay.getDisplayInfoLocked().brightnessDefault,
@@ -848,17 +859,8 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
mBrightnessRampIncreaseMaxTimeMillis, mBrightnessRampIncreaseMaxTimeMillis,
mBrightnessRampDecreaseMaxTimeMillis); mBrightnessRampDecreaseMaxTimeMillis);
} }
mHbmController.setHighBrightnessModeMetadata(hbmMetadata);
mHbmController.resetHbmData(info.width, info.height, token, info.uniqueId, mBrightnessRangeController.loadFromConfig(hbmMetadata, token, info, mDisplayDeviceConfig);
mDisplayDeviceConfig.getHighBrightnessModeData(),
new HighBrightnessModeController.HdrBrightnessDeviceConfig() {
@Override
public float getHdrBrightnessFromSdr(
float sdrBrightness, float maxDesiredHdrSdrRatio) {
return mDisplayDeviceConfig.getHdrBrightnessFromSdr(
sdrBrightness, maxDesiredHdrSdrRatio);
}
});
mBrightnessThrottler.loadThermalBrightnessThrottlingDataFromDisplayDeviceConfig( mBrightnessThrottler.loadThermalBrightnessThrottlingDataFromDisplayDeviceConfig(
mDisplayDeviceConfig.getThermalBrightnessThrottlingDataMapByThrottlingId(), mDisplayDeviceConfig.getThermalBrightnessThrottlingDataMapByThrottlingId(),
mThermalBrightnessThrottlingDataId, mUniqueDisplayId); mThermalBrightnessThrottlingDataId, mUniqueDisplayId);
@@ -1076,7 +1078,7 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
darkeningLightDebounce, autoBrightnessResetAmbientLuxAfterWarmUp, darkeningLightDebounce, autoBrightnessResetAmbientLuxAfterWarmUp,
ambientBrightnessThresholds, screenBrightnessThresholds, ambientBrightnessThresholds, screenBrightnessThresholds,
ambientBrightnessThresholdsIdle, screenBrightnessThresholdsIdle, mContext, ambientBrightnessThresholdsIdle, screenBrightnessThresholdsIdle, mContext,
mHbmController, mBrightnessThrottler, mIdleModeBrightnessMapper, mBrightnessRangeController, mBrightnessThrottler, mIdleModeBrightnessMapper,
mDisplayDeviceConfig.getAmbientHorizonShort(), mDisplayDeviceConfig.getAmbientHorizonShort(),
mDisplayDeviceConfig.getAmbientHorizonLong(), userLux, userBrightness); mDisplayDeviceConfig.getAmbientHorizonLong(), userLux, userBrightness);
mDisplayBrightnessController.setAutomaticBrightnessController( mDisplayBrightnessController.setAutomaticBrightnessController(
@@ -1180,7 +1182,7 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
/** Clean up all resources that are accessed via the {@link #mHandler} thread. */ /** Clean up all resources that are accessed via the {@link #mHandler} thread. */
private void cleanupHandlerThreadAfterStop() { private void cleanupHandlerThreadAfterStop() {
mDisplayPowerProximityStateController.cleanup(); mDisplayPowerProximityStateController.cleanup();
mHbmController.stop(); mBrightnessRangeController.stop();
mBrightnessThrottler.stop(); mBrightnessThrottler.stop();
mHandler.removeCallbacksAndMessages(null); mHandler.removeCallbacksAndMessages(null);
@@ -1295,7 +1297,7 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
&& (mAutomaticBrightnessStrategy.getAutoBrightnessAdjustmentChanged() && (mAutomaticBrightnessStrategy.getAutoBrightnessAdjustmentChanged()
|| userSetBrightnessChanged); || userSetBrightnessChanged);
mHbmController.setAutoBrightnessEnabled(mAutomaticBrightnessStrategy mBrightnessRangeController.setAutoBrightnessEnabled(mAutomaticBrightnessStrategy
.shouldUseAutoBrightness() .shouldUseAutoBrightness()
? AutomaticBrightnessController.AUTO_BRIGHTNESS_ENABLED ? AutomaticBrightnessController.AUTO_BRIGHTNESS_ENABLED
: AutomaticBrightnessController.AUTO_BRIGHTNESS_DISABLED); : AutomaticBrightnessController.AUTO_BRIGHTNESS_DISABLED);
@@ -1452,7 +1454,7 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
// here instead of having HbmController listen to the brightness setting because certain // 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 // brightness sources (such as an app override) are not saved to the setting, but should be
// reflected in HBM calculations. // reflected in HBM calculations.
mHbmController.onBrightnessChanged(brightnessState, unthrottledBrightnessState, mBrightnessRangeController.onBrightnessChanged(brightnessState, unthrottledBrightnessState,
mBrightnessThrottler.getBrightnessMaxReason()); mBrightnessThrottler.getBrightnessMaxReason());
// Animate the screen brightness when the screen is on or dozing. // Animate the screen brightness when the screen is on or dozing.
@@ -1509,13 +1511,14 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
float sdrAnimateValue = animateValue; float sdrAnimateValue = animateValue;
// TODO(b/216365040): The decision to prevent HBM for HDR in low power mode should be // TODO(b/216365040): The decision to prevent HBM for HDR in low power mode should be
// done in HighBrightnessModeController. // 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_DIMMED) == 0
&& (mBrightnessReasonTemp.getModifier() & BrightnessReason.MODIFIER_LOW_POWER) && (mBrightnessReasonTemp.getModifier() & BrightnessReason.MODIFIER_LOW_POWER)
== 0) { == 0) {
// We want to scale HDR brightness level with the SDR level, we also need to restore // 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. // SDR brightness immediately when entering dim or low power mode.
animateValue = mHbmController.getHdrBrightnessValue(); animateValue = mBrightnessRangeController.getHdrBrightnessValue();
} }
final float currentBrightness = mPowerState.getScreenBrightness(); final float currentBrightness = mPowerState.getScreenBrightness();
@@ -1579,8 +1582,8 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
mTempBrightnessEvent.setBrightness(brightnessState); mTempBrightnessEvent.setBrightness(brightnessState);
mTempBrightnessEvent.setPhysicalDisplayId(mUniqueDisplayId); mTempBrightnessEvent.setPhysicalDisplayId(mUniqueDisplayId);
mTempBrightnessEvent.setReason(mBrightnessReason); mTempBrightnessEvent.setReason(mBrightnessReason);
mTempBrightnessEvent.setHbmMax(mHbmController.getCurrentBrightnessMax()); mTempBrightnessEvent.setHbmMax(mBrightnessRangeController.getCurrentBrightnessMax());
mTempBrightnessEvent.setHbmMode(mHbmController.getHighBrightnessMode()); mTempBrightnessEvent.setHbmMode(mBrightnessRangeController.getHighBrightnessMode());
mTempBrightnessEvent.setFlags(mTempBrightnessEvent.getFlags() mTempBrightnessEvent.setFlags(mTempBrightnessEvent.getFlags()
| (mIsRbcActive ? BrightnessEvent.FLAG_RBC : 0) | (mIsRbcActive ? BrightnessEvent.FLAG_RBC : 0)
| (mPowerRequest.lowPowerMode ? BrightnessEvent.FLAG_LOW_POWER_MODE : 0)); | (mPowerRequest.lowPowerMode ? BrightnessEvent.FLAG_LOW_POWER_MODE : 0));
@@ -1750,9 +1753,11 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
private boolean saveBrightnessInfo(float brightness, float adjustedBrightness) { private boolean saveBrightnessInfo(float brightness, float adjustedBrightness) {
synchronized (mCachedBrightnessInfo) { synchronized (mCachedBrightnessInfo) {
final float minBrightness = Math.min(mHbmController.getCurrentBrightnessMin(), final float minBrightness = Math.min(
mBrightnessRangeController.getCurrentBrightnessMin(),
mBrightnessThrottler.getBrightnessCap()); mBrightnessThrottler.getBrightnessCap());
final float maxBrightness = Math.min(mHbmController.getCurrentBrightnessMax(), final float maxBrightness = Math.min(
mBrightnessRangeController.getCurrentBrightnessMax(),
mBrightnessThrottler.getBrightnessCap()); mBrightnessThrottler.getBrightnessCap());
boolean changed = false; boolean changed = false;
@@ -1770,10 +1775,10 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
maxBrightness); maxBrightness);
changed |= changed |=
mCachedBrightnessInfo.checkAndSetInt(mCachedBrightnessInfo.hbmMode, mCachedBrightnessInfo.checkAndSetInt(mCachedBrightnessInfo.hbmMode,
mHbmController.getHighBrightnessMode()); mBrightnessRangeController.getHighBrightnessMode());
changed |= changed |=
mCachedBrightnessInfo.checkAndSetFloat(mCachedBrightnessInfo.hbmTransitionPoint, mCachedBrightnessInfo.checkAndSetFloat(mCachedBrightnessInfo.hbmTransitionPoint,
mHbmController.getTransitionPoint()); mBrightnessRangeController.getTransitionPoint());
changed |= changed |=
mCachedBrightnessInfo.checkAndSetInt(mCachedBrightnessInfo.brightnessMaxReason, mCachedBrightnessInfo.checkAndSetInt(mCachedBrightnessInfo.brightnessMaxReason,
mBrightnessThrottler.getBrightnessMaxReason()); mBrightnessThrottler.getBrightnessMaxReason());
@@ -1786,7 +1791,8 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
mHandler.post(mOnBrightnessChangeRunnable); mHandler.post(mOnBrightnessChangeRunnable);
} }
private HighBrightnessModeController createHbmControllerLocked() { private HighBrightnessModeController createHbmControllerLocked(
HighBrightnessModeMetadata hbmMetadata, Runnable modeChangeCallback) {
final DisplayDevice device = mLogicalDisplay.getPrimaryDisplayDeviceLocked(); final DisplayDevice device = mLogicalDisplay.getPrimaryDisplayDeviceLocked();
final DisplayDeviceConfig ddConfig = device.getDisplayDeviceConfig(); final DisplayDeviceConfig ddConfig = device.getDisplayDeviceConfig();
final IBinder displayToken = final IBinder displayToken =
@@ -1798,22 +1804,9 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
final DisplayDeviceInfo info = device.getDisplayDeviceInfoLocked(); final DisplayDeviceInfo info = device.getDisplayDeviceInfoLocked();
return new HighBrightnessModeController(mHandler, info.width, info.height, displayToken, return new HighBrightnessModeController(mHandler, info.width, info.height, displayToken,
displayUniqueId, PowerManager.BRIGHTNESS_MIN, PowerManager.BRIGHTNESS_MAX, hbmData, displayUniqueId, PowerManager.BRIGHTNESS_MIN, PowerManager.BRIGHTNESS_MAX, hbmData,
new HighBrightnessModeController.HdrBrightnessDeviceConfig() { (sdrBrightness, maxDesiredHdrSdrRatio) ->
@Override mDisplayDeviceConfig.getHdrBrightnessFromSdr(sdrBrightness,
public float getHdrBrightnessFromSdr( maxDesiredHdrSdrRatio), modeChangeCallback, hbmMetadata, mContext);
float sdrBrightness, float maxDesiredHdrSdrRatio) {
return mDisplayDeviceConfig.getHdrBrightnessFromSdr(
sdrBrightness, maxDesiredHdrSdrRatio);
}
},
() -> {
sendUpdatePowerState();
postBrightnessChangeRunnable();
// TODO(b/192258832): Switch the HBMChangeCallback to a listener pattern.
if (mAutomaticBrightnessController != null) {
mAutomaticBrightnessController.update();
}
}, mHighBrightnessModeMetadata, mContext);
} }
private BrightnessThrottler createBrightnessThrottlerLocked() { private BrightnessThrottler createBrightnessThrottlerLocked() {
@@ -1960,8 +1953,8 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
if (Float.isNaN(value)) { if (Float.isNaN(value)) {
value = PowerManager.BRIGHTNESS_MIN; value = PowerManager.BRIGHTNESS_MIN;
} }
return MathUtils.constrain(value, return MathUtils.constrain(value, mBrightnessRangeController.getCurrentBrightnessMin(),
mHbmController.getCurrentBrightnessMin(), mHbmController.getCurrentBrightnessMax()); mBrightnessRangeController.getCurrentBrightnessMax());
} }
private void animateScreenBrightness(float target, float sdrTarget, float rate) { private void animateScreenBrightness(float target, float sdrTarget, float rate) {
@@ -2195,7 +2188,7 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
@Override @Override
public void setBrightnessToFollow(float leadDisplayBrightness, float nits, float ambientLux) { public void setBrightnessToFollow(float leadDisplayBrightness, float nits, float ambientLux) {
mHbmController.onAmbientLuxChange(ambientLux); mBrightnessRangeController.onAmbientLuxChange(ambientLux);
if (nits < 0) { if (nits < 0) {
mDisplayBrightnessController.setBrightnessToFollow(leadDisplayBrightness); mDisplayBrightnessController.setBrightnessToFollow(leadDisplayBrightness);
} else { } else {
@@ -2374,8 +2367,8 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
dumpRbcEvents(pw); dumpRbcEvents(pw);
if (mHbmController != null) { if (mBrightnessRangeController != null) {
mHbmController.dump(pw); mBrightnessRangeController.dump(pw);
} }
if (mBrightnessThrottler != null) { if (mBrightnessThrottler != null) {
@@ -2840,7 +2833,8 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
HysteresisLevels screenBrightnessThresholds, HysteresisLevels screenBrightnessThresholds,
HysteresisLevels ambientBrightnessThresholdsIdle, HysteresisLevels ambientBrightnessThresholdsIdle,
HysteresisLevels screenBrightnessThresholdsIdle, Context context, HysteresisLevels screenBrightnessThresholdsIdle, Context context,
HighBrightnessModeController hbmController, BrightnessThrottler brightnessThrottler, BrightnessRangeController brightnessModeController,
BrightnessThrottler brightnessThrottler,
BrightnessMappingStrategy idleModeBrightnessMapper, int ambientLightHorizonShort, BrightnessMappingStrategy idleModeBrightnessMapper, int ambientLightHorizonShort,
int ambientLightHorizonLong, float userLux, float userBrightness) { int ambientLightHorizonLong, float userLux, float userBrightness) {
return new AutomaticBrightnessController(callbacks, looper, sensorManager, lightSensor, return new AutomaticBrightnessController(callbacks, looper, sensorManager, lightSensor,
@@ -2849,9 +2843,9 @@ final class DisplayPowerController2 implements AutomaticBrightnessController.Cal
brighteningLightDebounceConfig, darkeningLightDebounceConfig, brighteningLightDebounceConfig, darkeningLightDebounceConfig,
resetAmbientLuxAfterWarmUpConfig, ambientBrightnessThresholds, resetAmbientLuxAfterWarmUpConfig, ambientBrightnessThresholds,
screenBrightnessThresholds, ambientBrightnessThresholdsIdle, screenBrightnessThresholds, ambientBrightnessThresholdsIdle,
screenBrightnessThresholdsIdle, context, hbmController, brightnessThrottler, screenBrightnessThresholdsIdle, context, brightnessModeController,
idleModeBrightnessMapper, ambientLightHorizonShort, ambientLightHorizonLong, brightnessThrottler, idleModeBrightnessMapper, ambientLightHorizonShort,
userLux, userBrightness); ambientLightHorizonLong, userLux, userBrightness);
} }
BrightnessMappingStrategy getInteractiveModeBrightnessMapper(Resources resources, BrightnessMappingStrategy getInteractiveModeBrightnessMapper(Resources resources,

View File

@@ -0,0 +1,51 @@
/*
* 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;
}
}

View File

@@ -813,7 +813,7 @@ public final class DisplayPowerController2Test {
any(HysteresisLevels.class), any(HysteresisLevels.class),
any(HysteresisLevels.class), any(HysteresisLevels.class),
eq(mContext), eq(mContext),
any(HighBrightnessModeController.class), any(BrightnessRangeController.class),
any(BrightnessThrottler.class), any(BrightnessThrottler.class),
isNull(), isNull(),
anyInt(), anyInt(),
@@ -1062,7 +1062,7 @@ public final class DisplayPowerController2Test {
HysteresisLevels screenBrightnessThresholds, HysteresisLevels screenBrightnessThresholds,
HysteresisLevels ambientBrightnessThresholdsIdle, HysteresisLevels ambientBrightnessThresholdsIdle,
HysteresisLevels screenBrightnessThresholdsIdle, Context context, HysteresisLevels screenBrightnessThresholdsIdle, Context context,
HighBrightnessModeController hbmController, BrightnessRangeController brightnessRangeController,
BrightnessThrottler brightnessThrottler, BrightnessThrottler brightnessThrottler,
BrightnessMappingStrategy idleModeBrightnessMapper, BrightnessMappingStrategy idleModeBrightnessMapper,
int ambientLightHorizonShort, int ambientLightHorizonLong, float userLux, int ambientLightHorizonShort, int ambientLightHorizonLong, float userLux,

View File

@@ -819,7 +819,7 @@ public final class DisplayPowerControllerTest {
any(HysteresisLevels.class), any(HysteresisLevels.class),
any(HysteresisLevels.class), any(HysteresisLevels.class),
eq(mContext), eq(mContext),
any(HighBrightnessModeController.class), any(BrightnessRangeController.class),
any(BrightnessThrottler.class), any(BrightnessThrottler.class),
isNull(), isNull(),
anyInt(), anyInt(),
@@ -1038,7 +1038,7 @@ public final class DisplayPowerControllerTest {
HysteresisLevels screenBrightnessThresholds, HysteresisLevels screenBrightnessThresholds,
HysteresisLevels ambientBrightnessThresholdsIdle, HysteresisLevels ambientBrightnessThresholdsIdle,
HysteresisLevels screenBrightnessThresholdsIdle, Context context, HysteresisLevels screenBrightnessThresholdsIdle, Context context,
HighBrightnessModeController hbmController, BrightnessRangeController brightnessRangeController,
BrightnessThrottler brightnessThrottler, BrightnessThrottler brightnessThrottler,
BrightnessMappingStrategy idleModeBrightnessMapper, BrightnessMappingStrategy idleModeBrightnessMapper,
int ambientLightHorizonShort, int ambientLightHorizonLong, float userLux, int ambientLightHorizonShort, int ambientLightHorizonLong, float userLux,

View File

@@ -85,7 +85,7 @@ public class AutomaticBrightnessControllerTest {
@Mock HysteresisLevels mAmbientBrightnessThresholdsIdle; @Mock HysteresisLevels mAmbientBrightnessThresholdsIdle;
@Mock HysteresisLevels mScreenBrightnessThresholdsIdle; @Mock HysteresisLevels mScreenBrightnessThresholdsIdle;
@Mock Handler mNoOpHandler; @Mock Handler mNoOpHandler;
@Mock HighBrightnessModeController mHbmController; @Mock BrightnessRangeController mBrightnessRangeController;
@Mock BrightnessThrottler mBrightnessThrottler; @Mock BrightnessThrottler mBrightnessThrottler;
@Before @Before
@@ -134,12 +134,15 @@ public class AutomaticBrightnessControllerTest {
DARKENING_LIGHT_DEBOUNCE_CONFIG, RESET_AMBIENT_LUX_AFTER_WARMUP_CONFIG, DARKENING_LIGHT_DEBOUNCE_CONFIG, RESET_AMBIENT_LUX_AFTER_WARMUP_CONFIG,
mAmbientBrightnessThresholds, mScreenBrightnessThresholds, mAmbientBrightnessThresholds, mScreenBrightnessThresholds,
mAmbientBrightnessThresholdsIdle, mScreenBrightnessThresholdsIdle, mAmbientBrightnessThresholdsIdle, mScreenBrightnessThresholdsIdle,
mContext, mHbmController, mBrightnessThrottler, mIdleBrightnessMappingStrategy, mContext, mBrightnessRangeController, mBrightnessThrottler,
AMBIENT_LIGHT_HORIZON_SHORT, AMBIENT_LIGHT_HORIZON_LONG, userLux, userBrightness mIdleBrightnessMappingStrategy, AMBIENT_LIGHT_HORIZON_SHORT,
AMBIENT_LIGHT_HORIZON_LONG, userLux, userBrightness
); );
when(mHbmController.getCurrentBrightnessMax()).thenReturn(BRIGHTNESS_MAX_FLOAT); when(mBrightnessRangeController.getCurrentBrightnessMax()).thenReturn(
when(mHbmController.getCurrentBrightnessMin()).thenReturn(BRIGHTNESS_MIN_FLOAT); BRIGHTNESS_MAX_FLOAT);
when(mBrightnessRangeController.getCurrentBrightnessMin()).thenReturn(
BRIGHTNESS_MIN_FLOAT);
// Disable brightness throttling by default. Individual tests can enable it as needed. // Disable brightness throttling by default. Individual tests can enable it as needed.
when(mBrightnessThrottler.getBrightnessCap()).thenReturn(BRIGHTNESS_MAX_FLOAT); when(mBrightnessThrottler.getBrightnessCap()).thenReturn(BRIGHTNESS_MAX_FLOAT);
when(mBrightnessThrottler.isThrottled()).thenReturn(false); when(mBrightnessThrottler.isThrottled()).thenReturn(false);