Loading services/core/java/com/android/server/display/AutomaticBrightnessController.java +1 −1 Original line number Diff line number Diff line Loading @@ -425,7 +425,7 @@ public class AutomaticBrightnessController { return mScreenAutoBrightness; } float getRawAutomaticScreenBrightness() { public float getRawAutomaticScreenBrightness() { return mRawScreenAutoBrightness; } Loading services/core/java/com/android/server/display/DisplayBrightnessState.java +36 −2 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package com.android.server.display; import android.text.TextUtils; import com.android.server.display.brightness.BrightnessEvent; import com.android.server.display.brightness.BrightnessReason; import java.util.Objects; Loading @@ -43,6 +44,8 @@ public final class DisplayBrightnessState { private final float mCustomAnimationRate; private final BrightnessEvent mBrightnessEvent; private DisplayBrightnessState(Builder builder) { mBrightness = builder.getBrightness(); mSdrBrightness = builder.getSdrBrightness(); Loading @@ -54,6 +57,7 @@ public final class DisplayBrightnessState { mMinBrightness = builder.getMinBrightness(); mCustomAnimationRate = builder.getCustomAnimationRate(); mShouldUpdateScreenBrightnessSetting = builder.shouldUpdateScreenBrightnessSetting(); mBrightnessEvent = builder.getBrightnessEvent(); } /** Loading Loading @@ -127,6 +131,13 @@ public final class DisplayBrightnessState { return mShouldUpdateScreenBrightnessSetting; } /** * @return The BrightnessEvent object */ public BrightnessEvent getBrightnessEvent() { return mBrightnessEvent; } @Override public String toString() { StringBuilder stringBuilder = new StringBuilder("DisplayBrightnessState:"); Loading @@ -144,6 +155,8 @@ public final class DisplayBrightnessState { stringBuilder.append("\n customAnimationRate:").append(mCustomAnimationRate); stringBuilder.append("\n shouldUpdateScreenBrightnessSetting:") .append(mShouldUpdateScreenBrightnessSetting); stringBuilder.append("\n mBrightnessEvent:") .append(Objects.toString(mBrightnessEvent, "null")); return stringBuilder.toString(); } Loading Loading @@ -173,7 +186,8 @@ public final class DisplayBrightnessState { && mMinBrightness == otherState.getMinBrightness() && mCustomAnimationRate == otherState.getCustomAnimationRate() && mShouldUpdateScreenBrightnessSetting == otherState.shouldUpdateScreenBrightnessSetting(); == otherState.shouldUpdateScreenBrightnessSetting() && Objects.equals(mBrightnessEvent, otherState.getBrightnessEvent()); } @Override Loading @@ -181,7 +195,7 @@ public final class DisplayBrightnessState { return Objects.hash(mBrightness, mSdrBrightness, mBrightnessReason, mShouldUseAutoBrightness, mIsSlowChange, mMaxBrightness, mMinBrightness, mCustomAnimationRate, mShouldUpdateScreenBrightnessSetting); mShouldUpdateScreenBrightnessSetting, mBrightnessEvent); } /** Loading @@ -206,6 +220,8 @@ public final class DisplayBrightnessState { private float mCustomAnimationRate = CUSTOM_ANIMATION_RATE_NOT_SET; private boolean mShouldUpdateScreenBrightnessSetting; private BrightnessEvent mBrightnessEvent; /** * Create a builder starting with the values from the specified {@link * DisplayBrightnessState}. Loading @@ -225,6 +241,7 @@ public final class DisplayBrightnessState { builder.setCustomAnimationRate(state.getCustomAnimationRate()); builder.setShouldUpdateScreenBrightnessSetting( state.shouldUpdateScreenBrightnessSetting()); builder.setBrightnessEvent(state.getBrightnessEvent()); return builder; } Loading Loading @@ -400,5 +417,22 @@ public final class DisplayBrightnessState { public DisplayBrightnessState build() { return new DisplayBrightnessState(this); } /** * This is used to get the BrightnessEvent object from its builder */ public BrightnessEvent getBrightnessEvent() { return mBrightnessEvent; } /** * This is used to set the BrightnessEvent object */ public Builder setBrightnessEvent(BrightnessEvent brightnessEvent) { mBrightnessEvent = brightnessEvent; return this; } } } services/core/java/com/android/server/display/DisplayPowerController.java +31 −15 Original line number Diff line number Diff line Loading @@ -83,7 +83,7 @@ import com.android.server.display.brightness.BrightnessReason; import com.android.server.display.brightness.BrightnessUtils; import com.android.server.display.brightness.DisplayBrightnessController; import com.android.server.display.brightness.clamper.BrightnessClamperController; import com.android.server.display.brightness.strategy.AutomaticBrightnessStrategy; import com.android.server.display.brightness.strategy.AutomaticBrightnessStrategy2; import com.android.server.display.color.ColorDisplayService.ColorDisplayServiceInternal; import com.android.server.display.color.ColorDisplayService.ReduceBrightColorsListener; import com.android.server.display.config.HysteresisLevels; Loading Loading @@ -440,7 +440,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call // Responsible for evaluating and tracking the automatic brightness relevant states. // Todo: This is a temporary workaround. Ideally DPC2 should never talk to the strategies private final AutomaticBrightnessStrategy mAutomaticBrightnessStrategy; private final AutomaticBrightnessStrategy2 mAutomaticBrightnessStrategy; // A record of state for skipping brightness ramps. private int mSkipRampState = RAMP_STATE_SKIP_NONE; Loading Loading @@ -1337,9 +1337,6 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call ? AUTO_BRIGHTNESS_MODE_DOZE : AUTO_BRIGHTNESS_MODE_DEFAULT); } final boolean userSetBrightnessChanged = mDisplayBrightnessController .updateUserSetScreenBrightness(); DisplayBrightnessState displayBrightnessState = mDisplayBrightnessController .updateBrightness(mPowerRequest, state); float brightnessState = displayBrightnessState.getBrightness(); Loading @@ -1348,7 +1345,11 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call boolean slowChange = displayBrightnessState.isSlowChange(); // custom transition duration float customAnimationRate = displayBrightnessState.getCustomAnimationRate(); final boolean userSetBrightnessChanged = mDisplayBrightnessController.getIsUserSetScreenBrightnessUpdated(); if (displayBrightnessState.getBrightnessEvent() != null) { mTempBrightnessEvent.copyFrom(displayBrightnessState.getBrightnessEvent()); } // Set up the ScreenOff controller used when coming out of SCREEN_OFF and the ALS sensor // doesn't yet have a valid lux value to use with auto-brightness. if (mScreenOffBrightnessSensorController != null) { Loading @@ -1364,11 +1365,13 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call // request changes. final boolean wasShortTermModelActive = mAutomaticBrightnessStrategy.isShortTermModelActive(); if (!mFlags.isRefactorDisplayPowerControllerEnabled()) { mAutomaticBrightnessStrategy.setAutoBrightnessState(state, mDisplayBrightnessController.isAllowAutoBrightnessWhileDozingConfig(), mBrightnessReasonTemp.getReason(), mPowerRequest.policy, mDisplayBrightnessController.getLastUserSetScreenBrightness(), userSetBrightnessChanged); } // If the brightness is already set then it's been overridden by something other than the // user, or is a temporary adjustment. Loading @@ -1390,9 +1393,22 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call float currentBrightnessSetting = mDisplayBrightnessController.getCurrentBrightness(); // Apply auto-brightness. int brightnessAdjustmentFlags = 0; // All the conditions inside this if block will be moved to AutomaticBrightnessStrategy if (mFlags.isRefactorDisplayPowerControllerEnabled() && displayBrightnessState.getBrightnessReason().getReason() == BrightnessReason.REASON_AUTOMATIC) { brightnessAdjustmentFlags = mAutomaticBrightnessStrategy.getAutoBrightnessAdjustmentReasonsFlags(); updateScreenBrightnessSetting = currentBrightnessSetting != brightnessState; mBrightnessReasonTemp.setReason(BrightnessReason.REASON_AUTOMATIC); if (mScreenOffBrightnessSensorController != null) { mScreenOffBrightnessSensorController.setLightSensorEnabled(false); } setBrightnessFromOffload(PowerManager.BRIGHTNESS_INVALID_FLOAT); } // AutomaticBrightnessStrategy has higher priority than OffloadBrightnessStrategy if (Float.isNaN(brightnessState) || mBrightnessReasonTemp.getReason() == BrightnessReason.REASON_OFFLOAD) { if (!mFlags.isRefactorDisplayPowerControllerEnabled() && (Float.isNaN(brightnessState) || mBrightnessReasonTemp.getReason() == BrightnessReason.REASON_OFFLOAD)) { if (mAutomaticBrightnessStrategy.isAutoBrightnessEnabled()) { brightnessState = mAutomaticBrightnessStrategy.getAutomaticScreenBrightness( mTempBrightnessEvent); Loading Loading @@ -1422,8 +1438,8 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call } } else { // Any non-auto-brightness values such as override or temporary should still be subject // to clamping so that they don't go beyond the current max as specified by HBM // Controller. // to clamping so that they don't go beyond the current max as specified by Brightness // Range Controller. brightnessState = clampScreenBrightness(brightnessState); mAutomaticBrightnessStrategy.setAutoBrightnessApplied(false); } Loading services/core/java/com/android/server/display/brightness/DisplayBrightnessController.java +48 −26 Original line number Diff line number Diff line Loading @@ -31,7 +31,7 @@ import com.android.server.display.AutomaticBrightnessController; import com.android.server.display.BrightnessMappingStrategy; import com.android.server.display.BrightnessSetting; import com.android.server.display.DisplayBrightnessState; import com.android.server.display.brightness.strategy.AutomaticBrightnessStrategy; import com.android.server.display.brightness.strategy.AutomaticBrightnessStrategy2; import com.android.server.display.brightness.strategy.DisplayBrightnessStrategy; import com.android.server.display.feature.DisplayManagerFlags; Loading Loading @@ -76,6 +76,10 @@ public final class DisplayBrightnessController { @GuardedBy("mLock") private float mLastUserSetScreenBrightness = PowerManager.BRIGHTNESS_INVALID_FLOAT; // Represents if the system has adjusted the brightness based on the user suggested value. Will // be false if the brightness change is coming from a non-user source private boolean mUserSetScreenBrightnessUpdated; // The listener which is to be notified everytime there is a change in the brightness in the // BrightnessSetting. private BrightnessSetting.BrightnessSettingListener mBrightnessSettingListener; Loading Loading @@ -138,7 +142,6 @@ public final class DisplayBrightnessController { public DisplayBrightnessState updateBrightness( DisplayManagerInternal.DisplayPowerRequest displayPowerRequest, int targetDisplayState) { DisplayBrightnessState state; synchronized (mLock) { mDisplayBrightnessStrategy = mDisplayBrightnessStrategySelector.selectStrategy( Loading Loading @@ -246,28 +249,14 @@ public final class DisplayBrightnessController { } /** * We want to return true if the user has set the screen brightness. * RBC on, off, and intensity changes will return false. * Slider interactions whilst in RBC will return true, just as when in non-rbc. * Returns if the system has adjusted the brightness based on the user suggested value. Will * be false if the brightness change is coming from a non-user source. * * Todo: 294444204 This is a temporary workaround, and should be moved to the manual brightness * strategy once that is introduced */ public boolean updateUserSetScreenBrightness() { synchronized (mLock) { if (!BrightnessUtils.isValidBrightnessValue(mPendingScreenBrightness)) { return false; } if (mCurrentScreenBrightness == mPendingScreenBrightness) { mPendingScreenBrightness = PowerManager.BRIGHTNESS_INVALID_FLOAT; setTemporaryBrightnessLocked(PowerManager.BRIGHTNESS_INVALID_FLOAT); return false; } setCurrentScreenBrightnessLocked(mPendingScreenBrightness); mLastUserSetScreenBrightness = mPendingScreenBrightness; mPendingScreenBrightness = PowerManager.BRIGHTNESS_INVALID_FLOAT; setTemporaryBrightnessLocked(PowerManager.BRIGHTNESS_INVALID_FLOAT); } notifyCurrentScreenBrightness(); return true; public boolean getIsUserSetScreenBrightnessUpdated() { return mUserSetScreenBrightnessUpdated; } /** Loading Loading @@ -355,7 +344,7 @@ public final class DisplayBrightnessController { /** * TODO(b/253226419): Remove once auto-brightness is a fully-functioning strategy. */ public AutomaticBrightnessStrategy getAutomaticBrightnessStrategy() { public AutomaticBrightnessStrategy2 getAutomaticBrightnessStrategy() { return mDisplayBrightnessStrategySelector.getAutomaticBrightnessStrategy(); } Loading Loading @@ -442,6 +431,33 @@ public final class DisplayBrightnessController { } } /** * We want to return true if the user has set the screen brightness. * RBC on, off, and intensity changes will return false. * Slider interactions whilst in RBC will return true, just as when in non-rbc. */ @VisibleForTesting boolean updateUserSetScreenBrightness() { mUserSetScreenBrightnessUpdated = false; synchronized (mLock) { if (!BrightnessUtils.isValidBrightnessValue(mPendingScreenBrightness)) { return false; } if (mCurrentScreenBrightness == mPendingScreenBrightness) { mPendingScreenBrightness = PowerManager.BRIGHTNESS_INVALID_FLOAT; setTemporaryBrightnessLocked(PowerManager.BRIGHTNESS_INVALID_FLOAT); return false; } setCurrentScreenBrightnessLocked(mPendingScreenBrightness); mLastUserSetScreenBrightness = mPendingScreenBrightness; mPendingScreenBrightness = PowerManager.BRIGHTNESS_INVALID_FLOAT; setTemporaryBrightnessLocked(PowerManager.BRIGHTNESS_INVALID_FLOAT); } notifyCurrentScreenBrightness(); mUserSetScreenBrightnessUpdated = true; return true; } @VisibleForTesting static class Injector { DisplayBrightnessStrategySelector getDisplayBrightnessStrategySelector(Context context, Loading Loading @@ -470,7 +486,7 @@ public final class DisplayBrightnessController { * TODO(b/253226419): Remove once auto-brightness is a fully-functioning strategy. */ private DisplayBrightnessState addAutomaticBrightnessState(DisplayBrightnessState state) { AutomaticBrightnessStrategy autoStrat = getAutomaticBrightnessStrategy(); AutomaticBrightnessStrategy2 autoStrat = getAutomaticBrightnessStrategy(); DisplayBrightnessState.Builder builder = DisplayBrightnessState.Builder.from(state); builder.setShouldUseAutoBrightness( Loading Loading @@ -526,6 +542,12 @@ public final class DisplayBrightnessController { private StrategySelectionRequest constructStrategySelectionRequest( DisplayManagerInternal.DisplayPowerRequest displayPowerRequest, int targetDisplayState) { return new StrategySelectionRequest(displayPowerRequest, targetDisplayState); boolean userSetBrightnessChanged = updateUserSetScreenBrightness(); float lastUserSetScreenBrightness; synchronized (mLock) { lastUserSetScreenBrightness = mLastUserSetScreenBrightness; } return new StrategySelectionRequest(displayPowerRequest, targetDisplayState, lastUserSetScreenBrightness, userSetBrightnessChanged); } } services/core/java/com/android/server/display/brightness/DisplayBrightnessStrategySelector.java +55 −8 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ import android.view.Display; import com.android.internal.R; import com.android.internal.annotations.VisibleForTesting; import com.android.server.display.brightness.strategy.AutomaticBrightnessStrategy; import com.android.server.display.brightness.strategy.AutomaticBrightnessStrategy2; import com.android.server.display.brightness.strategy.BoostBrightnessStrategy; import com.android.server.display.brightness.strategy.DisplayBrightnessStrategy; import com.android.server.display.brightness.strategy.DozeBrightnessStrategy; Loading Loading @@ -65,7 +66,16 @@ public class DisplayBrightnessStrategySelector { // The brightness strategy used to manage the brightness state when the request is invalid. private final InvalidBrightnessStrategy mInvalidBrightnessStrategy; // Controls brightness when automatic (adaptive) brightness is running. private final AutomaticBrightnessStrategy mAutomaticBrightnessStrategy; private final AutomaticBrightnessStrategy2 mAutomaticBrightnessStrategy; // The automatic strategy which controls the brightness when adaptive mode is ON. private final AutomaticBrightnessStrategy mAutomaticBrightnessStrategy1; // The deprecated AutomaticBrightnessStrategy. Avoid using it for any new features without // consulting with the display frameworks team. Use {@link AutomaticBrightnessStrategy} instead. // This will be removed once the flag // {@link DisplayManagerFlags#isRefactorDisplayPowerControllerEnabled is fully rolled out private final AutomaticBrightnessStrategy2 mAutomaticBrightnessStrategy2; // Controls the brightness if adaptive brightness is on and there exists an active offload // session. Brightness value is provided by the offload session. @Nullable Loading Loading @@ -101,7 +111,15 @@ public class DisplayBrightnessStrategySelector { mBoostBrightnessStrategy = injector.getBoostBrightnessStrategy(); mFollowerBrightnessStrategy = injector.getFollowerBrightnessStrategy(displayId); mInvalidBrightnessStrategy = injector.getInvalidBrightnessStrategy(); mAutomaticBrightnessStrategy = injector.getAutomaticBrightnessStrategy(context, displayId); mAutomaticBrightnessStrategy1 = (!mDisplayManagerFlags.isRefactorDisplayPowerControllerEnabled()) ? null : injector.getAutomaticBrightnessStrategy1(context, displayId); mAutomaticBrightnessStrategy2 = (mDisplayManagerFlags.isRefactorDisplayPowerControllerEnabled()) ? null : injector.getAutomaticBrightnessStrategy2(context, displayId); mAutomaticBrightnessStrategy = (mDisplayManagerFlags.isRefactorDisplayPowerControllerEnabled()) ? mAutomaticBrightnessStrategy1 : mAutomaticBrightnessStrategy2; if (flags.isDisplayOffloadEnabled()) { mOffloadBrightnessStrategy = injector.getOffloadBrightnessStrategy(); } else { Loading @@ -110,7 +128,7 @@ public class DisplayBrightnessStrategySelector { mDisplayBrightnessStrategies = new DisplayBrightnessStrategy[]{mInvalidBrightnessStrategy, mScreenOffBrightnessStrategy, mDozeBrightnessStrategy, mFollowerBrightnessStrategy, mBoostBrightnessStrategy, mOverrideBrightnessStrategy, mTemporaryBrightnessStrategy, mOffloadBrightnessStrategy}; mAutomaticBrightnessStrategy1, mOffloadBrightnessStrategy}; mAllowAutoBrightnessWhileDozingConfig = context.getResources().getBoolean( R.bool.config_allowAutoBrightnessWhileDozing); mOldBrightnessStrategyName = mInvalidBrightnessStrategy.getName(); Loading Loading @@ -142,6 +160,9 @@ public class DisplayBrightnessStrategySelector { } else if (BrightnessUtils.isValidBrightnessValue( mTemporaryBrightnessStrategy.getTemporaryScreenBrightness())) { displayBrightnessStrategy = mTemporaryBrightnessStrategy; } else if (mDisplayManagerFlags.isRefactorDisplayPowerControllerEnabled() && isAutomaticBrightnessStrategyValid(strategySelectionRequest)) { displayBrightnessStrategy = mAutomaticBrightnessStrategy1; } else if (mAutomaticBrightnessStrategy.shouldUseAutoBrightness() && mOffloadBrightnessStrategy != null && BrightnessUtils.isValidBrightnessValue( mOffloadBrightnessStrategy.getOffloadScreenBrightness())) { Loading @@ -149,7 +170,8 @@ public class DisplayBrightnessStrategySelector { } if (mDisplayManagerFlags.isRefactorDisplayPowerControllerEnabled()) { postProcess(constructStrategySelectionNotifyRequest(displayBrightnessStrategy)); postProcess(constructStrategySelectionNotifyRequest(displayBrightnessStrategy, strategySelectionRequest)); } if (!mOldBrightnessStrategyName.equals(displayBrightnessStrategy.getName())) { Loading @@ -170,7 +192,7 @@ public class DisplayBrightnessStrategySelector { return mFollowerBrightnessStrategy; } public AutomaticBrightnessStrategy getAutomaticBrightnessStrategy() { public AutomaticBrightnessStrategy2 getAutomaticBrightnessStrategy() { return mAutomaticBrightnessStrategy; } Loading Loading @@ -206,9 +228,28 @@ public class DisplayBrightnessStrategySelector { } } private boolean isAutomaticBrightnessStrategyValid( StrategySelectionRequest strategySelectionRequest) { mAutomaticBrightnessStrategy1.setAutoBrightnessState( strategySelectionRequest.getTargetDisplayState(), mAllowAutoBrightnessWhileDozingConfig, BrightnessReason.REASON_UNKNOWN, strategySelectionRequest.getDisplayPowerRequest().policy, strategySelectionRequest.getLastUserSetScreenBrightness(), strategySelectionRequest.isUserSetBrightnessChanged()); return mAutomaticBrightnessStrategy1.isAutoBrightnessValid(); } private StrategySelectionNotifyRequest constructStrategySelectionNotifyRequest( DisplayBrightnessStrategy selectedDisplayBrightnessStrategy) { return new StrategySelectionNotifyRequest(selectedDisplayBrightnessStrategy); DisplayBrightnessStrategy selectedDisplayBrightnessStrategy, StrategySelectionRequest strategySelectionRequest) { return new StrategySelectionNotifyRequest( strategySelectionRequest.getDisplayPowerRequest(), strategySelectionRequest.getTargetDisplayState(), selectedDisplayBrightnessStrategy, strategySelectionRequest.getLastUserSetScreenBrightness(), strategySelectionRequest.isUserSetBrightnessChanged(), isAllowAutoBrightnessWhileDozingConfig()); } private void postProcess(StrategySelectionNotifyRequest strategySelectionNotifyRequest) { Loading Loading @@ -263,10 +304,16 @@ public class DisplayBrightnessStrategySelector { return new InvalidBrightnessStrategy(); } AutomaticBrightnessStrategy getAutomaticBrightnessStrategy(Context context, int displayId) { AutomaticBrightnessStrategy getAutomaticBrightnessStrategy1(Context context, int displayId) { return new AutomaticBrightnessStrategy(context, displayId); } AutomaticBrightnessStrategy2 getAutomaticBrightnessStrategy2(Context context, int displayId) { return new AutomaticBrightnessStrategy2(context, displayId); } OffloadBrightnessStrategy getOffloadBrightnessStrategy() { return new OffloadBrightnessStrategy(); } Loading Loading
services/core/java/com/android/server/display/AutomaticBrightnessController.java +1 −1 Original line number Diff line number Diff line Loading @@ -425,7 +425,7 @@ public class AutomaticBrightnessController { return mScreenAutoBrightness; } float getRawAutomaticScreenBrightness() { public float getRawAutomaticScreenBrightness() { return mRawScreenAutoBrightness; } Loading
services/core/java/com/android/server/display/DisplayBrightnessState.java +36 −2 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package com.android.server.display; import android.text.TextUtils; import com.android.server.display.brightness.BrightnessEvent; import com.android.server.display.brightness.BrightnessReason; import java.util.Objects; Loading @@ -43,6 +44,8 @@ public final class DisplayBrightnessState { private final float mCustomAnimationRate; private final BrightnessEvent mBrightnessEvent; private DisplayBrightnessState(Builder builder) { mBrightness = builder.getBrightness(); mSdrBrightness = builder.getSdrBrightness(); Loading @@ -54,6 +57,7 @@ public final class DisplayBrightnessState { mMinBrightness = builder.getMinBrightness(); mCustomAnimationRate = builder.getCustomAnimationRate(); mShouldUpdateScreenBrightnessSetting = builder.shouldUpdateScreenBrightnessSetting(); mBrightnessEvent = builder.getBrightnessEvent(); } /** Loading Loading @@ -127,6 +131,13 @@ public final class DisplayBrightnessState { return mShouldUpdateScreenBrightnessSetting; } /** * @return The BrightnessEvent object */ public BrightnessEvent getBrightnessEvent() { return mBrightnessEvent; } @Override public String toString() { StringBuilder stringBuilder = new StringBuilder("DisplayBrightnessState:"); Loading @@ -144,6 +155,8 @@ public final class DisplayBrightnessState { stringBuilder.append("\n customAnimationRate:").append(mCustomAnimationRate); stringBuilder.append("\n shouldUpdateScreenBrightnessSetting:") .append(mShouldUpdateScreenBrightnessSetting); stringBuilder.append("\n mBrightnessEvent:") .append(Objects.toString(mBrightnessEvent, "null")); return stringBuilder.toString(); } Loading Loading @@ -173,7 +186,8 @@ public final class DisplayBrightnessState { && mMinBrightness == otherState.getMinBrightness() && mCustomAnimationRate == otherState.getCustomAnimationRate() && mShouldUpdateScreenBrightnessSetting == otherState.shouldUpdateScreenBrightnessSetting(); == otherState.shouldUpdateScreenBrightnessSetting() && Objects.equals(mBrightnessEvent, otherState.getBrightnessEvent()); } @Override Loading @@ -181,7 +195,7 @@ public final class DisplayBrightnessState { return Objects.hash(mBrightness, mSdrBrightness, mBrightnessReason, mShouldUseAutoBrightness, mIsSlowChange, mMaxBrightness, mMinBrightness, mCustomAnimationRate, mShouldUpdateScreenBrightnessSetting); mShouldUpdateScreenBrightnessSetting, mBrightnessEvent); } /** Loading @@ -206,6 +220,8 @@ public final class DisplayBrightnessState { private float mCustomAnimationRate = CUSTOM_ANIMATION_RATE_NOT_SET; private boolean mShouldUpdateScreenBrightnessSetting; private BrightnessEvent mBrightnessEvent; /** * Create a builder starting with the values from the specified {@link * DisplayBrightnessState}. Loading @@ -225,6 +241,7 @@ public final class DisplayBrightnessState { builder.setCustomAnimationRate(state.getCustomAnimationRate()); builder.setShouldUpdateScreenBrightnessSetting( state.shouldUpdateScreenBrightnessSetting()); builder.setBrightnessEvent(state.getBrightnessEvent()); return builder; } Loading Loading @@ -400,5 +417,22 @@ public final class DisplayBrightnessState { public DisplayBrightnessState build() { return new DisplayBrightnessState(this); } /** * This is used to get the BrightnessEvent object from its builder */ public BrightnessEvent getBrightnessEvent() { return mBrightnessEvent; } /** * This is used to set the BrightnessEvent object */ public Builder setBrightnessEvent(BrightnessEvent brightnessEvent) { mBrightnessEvent = brightnessEvent; return this; } } }
services/core/java/com/android/server/display/DisplayPowerController.java +31 −15 Original line number Diff line number Diff line Loading @@ -83,7 +83,7 @@ import com.android.server.display.brightness.BrightnessReason; import com.android.server.display.brightness.BrightnessUtils; import com.android.server.display.brightness.DisplayBrightnessController; import com.android.server.display.brightness.clamper.BrightnessClamperController; import com.android.server.display.brightness.strategy.AutomaticBrightnessStrategy; import com.android.server.display.brightness.strategy.AutomaticBrightnessStrategy2; import com.android.server.display.color.ColorDisplayService.ColorDisplayServiceInternal; import com.android.server.display.color.ColorDisplayService.ReduceBrightColorsListener; import com.android.server.display.config.HysteresisLevels; Loading Loading @@ -440,7 +440,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call // Responsible for evaluating and tracking the automatic brightness relevant states. // Todo: This is a temporary workaround. Ideally DPC2 should never talk to the strategies private final AutomaticBrightnessStrategy mAutomaticBrightnessStrategy; private final AutomaticBrightnessStrategy2 mAutomaticBrightnessStrategy; // A record of state for skipping brightness ramps. private int mSkipRampState = RAMP_STATE_SKIP_NONE; Loading Loading @@ -1337,9 +1337,6 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call ? AUTO_BRIGHTNESS_MODE_DOZE : AUTO_BRIGHTNESS_MODE_DEFAULT); } final boolean userSetBrightnessChanged = mDisplayBrightnessController .updateUserSetScreenBrightness(); DisplayBrightnessState displayBrightnessState = mDisplayBrightnessController .updateBrightness(mPowerRequest, state); float brightnessState = displayBrightnessState.getBrightness(); Loading @@ -1348,7 +1345,11 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call boolean slowChange = displayBrightnessState.isSlowChange(); // custom transition duration float customAnimationRate = displayBrightnessState.getCustomAnimationRate(); final boolean userSetBrightnessChanged = mDisplayBrightnessController.getIsUserSetScreenBrightnessUpdated(); if (displayBrightnessState.getBrightnessEvent() != null) { mTempBrightnessEvent.copyFrom(displayBrightnessState.getBrightnessEvent()); } // Set up the ScreenOff controller used when coming out of SCREEN_OFF and the ALS sensor // doesn't yet have a valid lux value to use with auto-brightness. if (mScreenOffBrightnessSensorController != null) { Loading @@ -1364,11 +1365,13 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call // request changes. final boolean wasShortTermModelActive = mAutomaticBrightnessStrategy.isShortTermModelActive(); if (!mFlags.isRefactorDisplayPowerControllerEnabled()) { mAutomaticBrightnessStrategy.setAutoBrightnessState(state, mDisplayBrightnessController.isAllowAutoBrightnessWhileDozingConfig(), mBrightnessReasonTemp.getReason(), mPowerRequest.policy, mDisplayBrightnessController.getLastUserSetScreenBrightness(), userSetBrightnessChanged); } // If the brightness is already set then it's been overridden by something other than the // user, or is a temporary adjustment. Loading @@ -1390,9 +1393,22 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call float currentBrightnessSetting = mDisplayBrightnessController.getCurrentBrightness(); // Apply auto-brightness. int brightnessAdjustmentFlags = 0; // All the conditions inside this if block will be moved to AutomaticBrightnessStrategy if (mFlags.isRefactorDisplayPowerControllerEnabled() && displayBrightnessState.getBrightnessReason().getReason() == BrightnessReason.REASON_AUTOMATIC) { brightnessAdjustmentFlags = mAutomaticBrightnessStrategy.getAutoBrightnessAdjustmentReasonsFlags(); updateScreenBrightnessSetting = currentBrightnessSetting != brightnessState; mBrightnessReasonTemp.setReason(BrightnessReason.REASON_AUTOMATIC); if (mScreenOffBrightnessSensorController != null) { mScreenOffBrightnessSensorController.setLightSensorEnabled(false); } setBrightnessFromOffload(PowerManager.BRIGHTNESS_INVALID_FLOAT); } // AutomaticBrightnessStrategy has higher priority than OffloadBrightnessStrategy if (Float.isNaN(brightnessState) || mBrightnessReasonTemp.getReason() == BrightnessReason.REASON_OFFLOAD) { if (!mFlags.isRefactorDisplayPowerControllerEnabled() && (Float.isNaN(brightnessState) || mBrightnessReasonTemp.getReason() == BrightnessReason.REASON_OFFLOAD)) { if (mAutomaticBrightnessStrategy.isAutoBrightnessEnabled()) { brightnessState = mAutomaticBrightnessStrategy.getAutomaticScreenBrightness( mTempBrightnessEvent); Loading Loading @@ -1422,8 +1438,8 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call } } else { // Any non-auto-brightness values such as override or temporary should still be subject // to clamping so that they don't go beyond the current max as specified by HBM // Controller. // to clamping so that they don't go beyond the current max as specified by Brightness // Range Controller. brightnessState = clampScreenBrightness(brightnessState); mAutomaticBrightnessStrategy.setAutoBrightnessApplied(false); } Loading
services/core/java/com/android/server/display/brightness/DisplayBrightnessController.java +48 −26 Original line number Diff line number Diff line Loading @@ -31,7 +31,7 @@ import com.android.server.display.AutomaticBrightnessController; import com.android.server.display.BrightnessMappingStrategy; import com.android.server.display.BrightnessSetting; import com.android.server.display.DisplayBrightnessState; import com.android.server.display.brightness.strategy.AutomaticBrightnessStrategy; import com.android.server.display.brightness.strategy.AutomaticBrightnessStrategy2; import com.android.server.display.brightness.strategy.DisplayBrightnessStrategy; import com.android.server.display.feature.DisplayManagerFlags; Loading Loading @@ -76,6 +76,10 @@ public final class DisplayBrightnessController { @GuardedBy("mLock") private float mLastUserSetScreenBrightness = PowerManager.BRIGHTNESS_INVALID_FLOAT; // Represents if the system has adjusted the brightness based on the user suggested value. Will // be false if the brightness change is coming from a non-user source private boolean mUserSetScreenBrightnessUpdated; // The listener which is to be notified everytime there is a change in the brightness in the // BrightnessSetting. private BrightnessSetting.BrightnessSettingListener mBrightnessSettingListener; Loading Loading @@ -138,7 +142,6 @@ public final class DisplayBrightnessController { public DisplayBrightnessState updateBrightness( DisplayManagerInternal.DisplayPowerRequest displayPowerRequest, int targetDisplayState) { DisplayBrightnessState state; synchronized (mLock) { mDisplayBrightnessStrategy = mDisplayBrightnessStrategySelector.selectStrategy( Loading Loading @@ -246,28 +249,14 @@ public final class DisplayBrightnessController { } /** * We want to return true if the user has set the screen brightness. * RBC on, off, and intensity changes will return false. * Slider interactions whilst in RBC will return true, just as when in non-rbc. * Returns if the system has adjusted the brightness based on the user suggested value. Will * be false if the brightness change is coming from a non-user source. * * Todo: 294444204 This is a temporary workaround, and should be moved to the manual brightness * strategy once that is introduced */ public boolean updateUserSetScreenBrightness() { synchronized (mLock) { if (!BrightnessUtils.isValidBrightnessValue(mPendingScreenBrightness)) { return false; } if (mCurrentScreenBrightness == mPendingScreenBrightness) { mPendingScreenBrightness = PowerManager.BRIGHTNESS_INVALID_FLOAT; setTemporaryBrightnessLocked(PowerManager.BRIGHTNESS_INVALID_FLOAT); return false; } setCurrentScreenBrightnessLocked(mPendingScreenBrightness); mLastUserSetScreenBrightness = mPendingScreenBrightness; mPendingScreenBrightness = PowerManager.BRIGHTNESS_INVALID_FLOAT; setTemporaryBrightnessLocked(PowerManager.BRIGHTNESS_INVALID_FLOAT); } notifyCurrentScreenBrightness(); return true; public boolean getIsUserSetScreenBrightnessUpdated() { return mUserSetScreenBrightnessUpdated; } /** Loading Loading @@ -355,7 +344,7 @@ public final class DisplayBrightnessController { /** * TODO(b/253226419): Remove once auto-brightness is a fully-functioning strategy. */ public AutomaticBrightnessStrategy getAutomaticBrightnessStrategy() { public AutomaticBrightnessStrategy2 getAutomaticBrightnessStrategy() { return mDisplayBrightnessStrategySelector.getAutomaticBrightnessStrategy(); } Loading Loading @@ -442,6 +431,33 @@ public final class DisplayBrightnessController { } } /** * We want to return true if the user has set the screen brightness. * RBC on, off, and intensity changes will return false. * Slider interactions whilst in RBC will return true, just as when in non-rbc. */ @VisibleForTesting boolean updateUserSetScreenBrightness() { mUserSetScreenBrightnessUpdated = false; synchronized (mLock) { if (!BrightnessUtils.isValidBrightnessValue(mPendingScreenBrightness)) { return false; } if (mCurrentScreenBrightness == mPendingScreenBrightness) { mPendingScreenBrightness = PowerManager.BRIGHTNESS_INVALID_FLOAT; setTemporaryBrightnessLocked(PowerManager.BRIGHTNESS_INVALID_FLOAT); return false; } setCurrentScreenBrightnessLocked(mPendingScreenBrightness); mLastUserSetScreenBrightness = mPendingScreenBrightness; mPendingScreenBrightness = PowerManager.BRIGHTNESS_INVALID_FLOAT; setTemporaryBrightnessLocked(PowerManager.BRIGHTNESS_INVALID_FLOAT); } notifyCurrentScreenBrightness(); mUserSetScreenBrightnessUpdated = true; return true; } @VisibleForTesting static class Injector { DisplayBrightnessStrategySelector getDisplayBrightnessStrategySelector(Context context, Loading Loading @@ -470,7 +486,7 @@ public final class DisplayBrightnessController { * TODO(b/253226419): Remove once auto-brightness is a fully-functioning strategy. */ private DisplayBrightnessState addAutomaticBrightnessState(DisplayBrightnessState state) { AutomaticBrightnessStrategy autoStrat = getAutomaticBrightnessStrategy(); AutomaticBrightnessStrategy2 autoStrat = getAutomaticBrightnessStrategy(); DisplayBrightnessState.Builder builder = DisplayBrightnessState.Builder.from(state); builder.setShouldUseAutoBrightness( Loading Loading @@ -526,6 +542,12 @@ public final class DisplayBrightnessController { private StrategySelectionRequest constructStrategySelectionRequest( DisplayManagerInternal.DisplayPowerRequest displayPowerRequest, int targetDisplayState) { return new StrategySelectionRequest(displayPowerRequest, targetDisplayState); boolean userSetBrightnessChanged = updateUserSetScreenBrightness(); float lastUserSetScreenBrightness; synchronized (mLock) { lastUserSetScreenBrightness = mLastUserSetScreenBrightness; } return new StrategySelectionRequest(displayPowerRequest, targetDisplayState, lastUserSetScreenBrightness, userSetBrightnessChanged); } }
services/core/java/com/android/server/display/brightness/DisplayBrightnessStrategySelector.java +55 −8 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ import android.view.Display; import com.android.internal.R; import com.android.internal.annotations.VisibleForTesting; import com.android.server.display.brightness.strategy.AutomaticBrightnessStrategy; import com.android.server.display.brightness.strategy.AutomaticBrightnessStrategy2; import com.android.server.display.brightness.strategy.BoostBrightnessStrategy; import com.android.server.display.brightness.strategy.DisplayBrightnessStrategy; import com.android.server.display.brightness.strategy.DozeBrightnessStrategy; Loading Loading @@ -65,7 +66,16 @@ public class DisplayBrightnessStrategySelector { // The brightness strategy used to manage the brightness state when the request is invalid. private final InvalidBrightnessStrategy mInvalidBrightnessStrategy; // Controls brightness when automatic (adaptive) brightness is running. private final AutomaticBrightnessStrategy mAutomaticBrightnessStrategy; private final AutomaticBrightnessStrategy2 mAutomaticBrightnessStrategy; // The automatic strategy which controls the brightness when adaptive mode is ON. private final AutomaticBrightnessStrategy mAutomaticBrightnessStrategy1; // The deprecated AutomaticBrightnessStrategy. Avoid using it for any new features without // consulting with the display frameworks team. Use {@link AutomaticBrightnessStrategy} instead. // This will be removed once the flag // {@link DisplayManagerFlags#isRefactorDisplayPowerControllerEnabled is fully rolled out private final AutomaticBrightnessStrategy2 mAutomaticBrightnessStrategy2; // Controls the brightness if adaptive brightness is on and there exists an active offload // session. Brightness value is provided by the offload session. @Nullable Loading Loading @@ -101,7 +111,15 @@ public class DisplayBrightnessStrategySelector { mBoostBrightnessStrategy = injector.getBoostBrightnessStrategy(); mFollowerBrightnessStrategy = injector.getFollowerBrightnessStrategy(displayId); mInvalidBrightnessStrategy = injector.getInvalidBrightnessStrategy(); mAutomaticBrightnessStrategy = injector.getAutomaticBrightnessStrategy(context, displayId); mAutomaticBrightnessStrategy1 = (!mDisplayManagerFlags.isRefactorDisplayPowerControllerEnabled()) ? null : injector.getAutomaticBrightnessStrategy1(context, displayId); mAutomaticBrightnessStrategy2 = (mDisplayManagerFlags.isRefactorDisplayPowerControllerEnabled()) ? null : injector.getAutomaticBrightnessStrategy2(context, displayId); mAutomaticBrightnessStrategy = (mDisplayManagerFlags.isRefactorDisplayPowerControllerEnabled()) ? mAutomaticBrightnessStrategy1 : mAutomaticBrightnessStrategy2; if (flags.isDisplayOffloadEnabled()) { mOffloadBrightnessStrategy = injector.getOffloadBrightnessStrategy(); } else { Loading @@ -110,7 +128,7 @@ public class DisplayBrightnessStrategySelector { mDisplayBrightnessStrategies = new DisplayBrightnessStrategy[]{mInvalidBrightnessStrategy, mScreenOffBrightnessStrategy, mDozeBrightnessStrategy, mFollowerBrightnessStrategy, mBoostBrightnessStrategy, mOverrideBrightnessStrategy, mTemporaryBrightnessStrategy, mOffloadBrightnessStrategy}; mAutomaticBrightnessStrategy1, mOffloadBrightnessStrategy}; mAllowAutoBrightnessWhileDozingConfig = context.getResources().getBoolean( R.bool.config_allowAutoBrightnessWhileDozing); mOldBrightnessStrategyName = mInvalidBrightnessStrategy.getName(); Loading Loading @@ -142,6 +160,9 @@ public class DisplayBrightnessStrategySelector { } else if (BrightnessUtils.isValidBrightnessValue( mTemporaryBrightnessStrategy.getTemporaryScreenBrightness())) { displayBrightnessStrategy = mTemporaryBrightnessStrategy; } else if (mDisplayManagerFlags.isRefactorDisplayPowerControllerEnabled() && isAutomaticBrightnessStrategyValid(strategySelectionRequest)) { displayBrightnessStrategy = mAutomaticBrightnessStrategy1; } else if (mAutomaticBrightnessStrategy.shouldUseAutoBrightness() && mOffloadBrightnessStrategy != null && BrightnessUtils.isValidBrightnessValue( mOffloadBrightnessStrategy.getOffloadScreenBrightness())) { Loading @@ -149,7 +170,8 @@ public class DisplayBrightnessStrategySelector { } if (mDisplayManagerFlags.isRefactorDisplayPowerControllerEnabled()) { postProcess(constructStrategySelectionNotifyRequest(displayBrightnessStrategy)); postProcess(constructStrategySelectionNotifyRequest(displayBrightnessStrategy, strategySelectionRequest)); } if (!mOldBrightnessStrategyName.equals(displayBrightnessStrategy.getName())) { Loading @@ -170,7 +192,7 @@ public class DisplayBrightnessStrategySelector { return mFollowerBrightnessStrategy; } public AutomaticBrightnessStrategy getAutomaticBrightnessStrategy() { public AutomaticBrightnessStrategy2 getAutomaticBrightnessStrategy() { return mAutomaticBrightnessStrategy; } Loading Loading @@ -206,9 +228,28 @@ public class DisplayBrightnessStrategySelector { } } private boolean isAutomaticBrightnessStrategyValid( StrategySelectionRequest strategySelectionRequest) { mAutomaticBrightnessStrategy1.setAutoBrightnessState( strategySelectionRequest.getTargetDisplayState(), mAllowAutoBrightnessWhileDozingConfig, BrightnessReason.REASON_UNKNOWN, strategySelectionRequest.getDisplayPowerRequest().policy, strategySelectionRequest.getLastUserSetScreenBrightness(), strategySelectionRequest.isUserSetBrightnessChanged()); return mAutomaticBrightnessStrategy1.isAutoBrightnessValid(); } private StrategySelectionNotifyRequest constructStrategySelectionNotifyRequest( DisplayBrightnessStrategy selectedDisplayBrightnessStrategy) { return new StrategySelectionNotifyRequest(selectedDisplayBrightnessStrategy); DisplayBrightnessStrategy selectedDisplayBrightnessStrategy, StrategySelectionRequest strategySelectionRequest) { return new StrategySelectionNotifyRequest( strategySelectionRequest.getDisplayPowerRequest(), strategySelectionRequest.getTargetDisplayState(), selectedDisplayBrightnessStrategy, strategySelectionRequest.getLastUserSetScreenBrightness(), strategySelectionRequest.isUserSetBrightnessChanged(), isAllowAutoBrightnessWhileDozingConfig()); } private void postProcess(StrategySelectionNotifyRequest strategySelectionNotifyRequest) { Loading Loading @@ -263,10 +304,16 @@ public class DisplayBrightnessStrategySelector { return new InvalidBrightnessStrategy(); } AutomaticBrightnessStrategy getAutomaticBrightnessStrategy(Context context, int displayId) { AutomaticBrightnessStrategy getAutomaticBrightnessStrategy1(Context context, int displayId) { return new AutomaticBrightnessStrategy(context, displayId); } AutomaticBrightnessStrategy2 getAutomaticBrightnessStrategy2(Context context, int displayId) { return new AutomaticBrightnessStrategy2(context, displayId); } OffloadBrightnessStrategy getOffloadBrightnessStrategy() { return new OffloadBrightnessStrategy(); } Loading