Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7518e291 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Implement phase 1 of per-display power states"

parents c03a038a 8444a94b
Loading
Loading
Loading
Loading
+4 −8
Original line number Diff line number Diff line
@@ -208,7 +208,6 @@ class AutomaticBrightnessController {
    private PackageManager mPackageManager;
    private Context mContext;

    private DisplayDeviceConfig mDisplayDeviceConfig;
    private final Injector mInjector;

    AutomaticBrightnessController(Callbacks callbacks, Looper looper,
@@ -217,14 +216,13 @@ class AutomaticBrightnessController {
            float dozeScaleFactor, int lightSensorRate, int initialLightSensorRate,
            long brighteningLightDebounceConfig, long darkeningLightDebounceConfig,
            boolean resetAmbientLuxAfterWarmUpConfig, HysteresisLevels ambientBrightnessThresholds,
            HysteresisLevels screenBrightnessThresholds, Context context, DisplayDeviceConfig
            displayDeviceConfig) {
            HysteresisLevels screenBrightnessThresholds, Context context) {
        this(new Injector(), callbacks, looper, sensorManager, lightSensor, mapper,
                lightSensorWarmUpTime, brightnessMin, brightnessMax, dozeScaleFactor,
                lightSensorRate, initialLightSensorRate, brighteningLightDebounceConfig,
                darkeningLightDebounceConfig, resetAmbientLuxAfterWarmUpConfig,
                ambientBrightnessThresholds, screenBrightnessThresholds, context,
                displayDeviceConfig);
                ambientBrightnessThresholds, screenBrightnessThresholds, context
        );
    }

    @VisibleForTesting
@@ -234,8 +232,7 @@ class AutomaticBrightnessController {
            float dozeScaleFactor, int lightSensorRate, int initialLightSensorRate,
            long brighteningLightDebounceConfig, long darkeningLightDebounceConfig,
            boolean resetAmbientLuxAfterWarmUpConfig, HysteresisLevels ambientBrightnessThresholds,
            HysteresisLevels screenBrightnessThresholds, Context context, DisplayDeviceConfig
            displayDeviceConfig) {
            HysteresisLevels screenBrightnessThresholds, Context context) {
        mInjector = injector;
        mContext = context;
        mCallbacks = callbacks;
@@ -257,7 +254,6 @@ class AutomaticBrightnessController {
        mScreenBrightnessThresholds = screenBrightnessThresholds;
        mShortTermModelValid = true;
        mShortTermModelAnchor = -1;
        mDisplayDeviceConfig = displayDeviceConfig;
        mHandler = new AutomaticBrightnessHandler(looper);
        mAmbientLightRingBuffer =
            new AmbientLightRingBuffer(mNormalLightSensorRate, mAmbientLightHorizon);
+1 −1
Original line number Diff line number Diff line
@@ -20,5 +20,5 @@ package com.android.server.display;
 * Interface used to update the actual display state.
 */
public interface DisplayBlanker {
    void requestDisplayState(int state, float brightness);
    void requestDisplayState(int displayId, int state, float brightness);
}
+3 −5
Original line number Diff line number Diff line
@@ -2382,7 +2382,7 @@ public final class DisplayManagerService extends SystemService {
            synchronized (mSyncRoot) {
                DisplayBlanker blanker = new DisplayBlanker() {
                    @Override
                    public void requestDisplayState(int state, float brightness) {
                    public void requestDisplayState(int displayId, int state, float brightness) {
                        // The order of operations is important for legacy reasons.
                        if (state == Display.STATE_OFF) {
                            requestGlobalDisplayStateInternal(state, brightness);
@@ -2395,11 +2395,9 @@ public final class DisplayManagerService extends SystemService {
                        }
                    }
                };
                LogicalDisplay defaultDisplay =
                        mLogicalDisplayMapper.getLocked(Display.DEFAULT_DISPLAY);
                DisplayDevice defaultDevice = defaultDisplay.getPrimaryDisplayDeviceLocked();
                mDisplayPowerController = new DisplayPowerController(
                        mContext, callbacks, handler, sensorManager, blanker, defaultDevice);
                        mContext, callbacks, handler, sensorManager, blanker,
                        Display.DEFAULT_DISPLAY);
                mSensorManager = sensorManager;
            }

+11 −12
Original line number Diff line number Diff line
@@ -163,8 +163,8 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
    // The display blanker.
    private final DisplayBlanker mBlanker;

    // The display device.
    private final DisplayDevice mDisplayDevice;
    // The ID of the LogicalDisplay tied to this DisplayPowerController.
    private final int mDisplayId;

    // Tracker for brightness changes.
    private final BrightnessTracker mBrightnessTracker;
@@ -406,7 +406,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
     */
    public DisplayPowerController(Context context,
            DisplayPowerCallbacks callbacks, Handler handler,
            SensorManager sensorManager, DisplayBlanker blanker, DisplayDevice displayDevice) {
            SensorManager sensorManager, DisplayBlanker blanker, int displayId) {
        mHandler = new DisplayControllerHandler(handler.getLooper());
        mBrightnessTracker = new BrightnessTracker(context, null);
        mSettingsObserver = new SettingsObserver(mHandler);
@@ -417,10 +417,9 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
        mBlanker = blanker;
        mContext = context;
        mBrightnessSynchronizer = new BrightnessSynchronizer(context);
        mDisplayDevice = displayDevice;
        mDisplayId = displayId;

        PowerManager pm =  context.getSystemService(PowerManager.class);
        DisplayDeviceConfig displayDeviceConfig = mDisplayDevice.getDisplayDeviceConfig();

        final Resources resources = context.getResources();

@@ -515,7 +514,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
                        mScreenBrightnessRangeMaximum, dozeScaleFactor, lightSensorRate,
                        initialLightSensorRate, brighteningLightDebounce, darkeningLightDebounce,
                        autoBrightnessResetAmbientLuxAfterWarmUp, ambientBrightnessThresholds,
                        screenBrightnessThresholds, context, displayDeviceConfig);
                        screenBrightnessThresholds, context);
            } else {
                mUseSoftwareAutoBrightnessConfig = false;
            }
@@ -684,7 +683,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
        // Initialize the power state object for the default display.
        // In the future, we might manage multiple displays independently.
        mPowerState = new DisplayPowerState(mBlanker,
                mColorFadeEnabled ? new ColorFade(Display.DEFAULT_DISPLAY) : null);
                mColorFadeEnabled ? new ColorFade(mDisplayId) : null, mDisplayId);

        if (mColorFadeEnabled) {
            mColorFadeOnAnimator = ObjectAnimator.ofFloat(
@@ -1153,7 +1152,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
        if (ready && state != Display.STATE_OFF
                && mReportedScreenStateToPolicy == REPORTED_TO_POLICY_SCREEN_TURNING_ON) {
            setReportedScreenState(REPORTED_TO_POLICY_SCREEN_ON);
            mWindowManagerPolicy.screenTurnedOn();
            mWindowManagerPolicy.screenTurnedOn(mDisplayId);
        }

        // Grab a wake lock if we have unfinished business.
@@ -1277,7 +1276,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
                if (mReportedScreenStateToPolicy == REPORTED_TO_POLICY_SCREEN_ON) {
                    setReportedScreenState(REPORTED_TO_POLICY_SCREEN_TURNING_OFF);
                    blockScreenOff();
                    mWindowManagerPolicy.screenTurningOff(mPendingScreenOffUnblocker);
                    mWindowManagerPolicy.screenTurningOff(mDisplayId, mPendingScreenOffUnblocker);
                    unblockScreenOff();
                } else if (mPendingScreenOffUnblocker != null) {
                    // Abort doing the state change until screen off is unblocked.
@@ -1309,14 +1308,14 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
                && !mScreenOffBecauseOfProximity) {
            setReportedScreenState(REPORTED_TO_POLICY_SCREEN_OFF);
            unblockScreenOn();
            mWindowManagerPolicy.screenTurnedOff();
            mWindowManagerPolicy.screenTurnedOff(mDisplayId);
        } else if (!isOff
                && mReportedScreenStateToPolicy == REPORTED_TO_POLICY_SCREEN_TURNING_OFF) {

            // We told policy already that screen was turning off, but now we changed our minds.
            // Complete the full state transition on -> turningOff -> off.
            unblockScreenOff();
            mWindowManagerPolicy.screenTurnedOff();
            mWindowManagerPolicy.screenTurnedOff(mDisplayId);
            setReportedScreenState(REPORTED_TO_POLICY_SCREEN_OFF);
        }
        if (!isOff && mReportedScreenStateToPolicy == REPORTED_TO_POLICY_SCREEN_OFF) {
@@ -1326,7 +1325,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call
            } else {
                unblockScreenOn();
            }
            mWindowManagerPolicy.screenTurningOn(mPendingScreenOnUnblocker);
            mWindowManagerPolicy.screenTurningOn(mDisplayId, mPendingScreenOnUnblocker);
        }

        // Return true if the screen isn't blocked.
+5 −3
Original line number Diff line number Diff line
@@ -58,6 +58,7 @@ final class DisplayPowerState {
    private final DisplayBlanker mBlanker;
    private final ColorFade mColorFade;
    private final PhotonicModulator mPhotonicModulator;
    private final int mDisplayId;

    private int mScreenState;
    private float mScreenBrightness;
@@ -71,13 +72,14 @@ final class DisplayPowerState {

    private Runnable mCleanListener;

    public DisplayPowerState(DisplayBlanker blanker, ColorFade colorFade) {
    public DisplayPowerState(DisplayBlanker blanker, ColorFade colorFade, int displayId) {
        mHandler = new Handler(true /*async*/);
        mChoreographer = Choreographer.getInstance();
        mBlanker = blanker;
        mColorFade = colorFade;
        mPhotonicModulator = new PhotonicModulator();
        mPhotonicModulator.start();
        mDisplayId = displayId;

        // At boot time, we know that the screen is on and the electron beam
        // animation is not playing.  We don't know the screen's brightness though,
@@ -434,10 +436,10 @@ final class DisplayPowerState {

                // Apply pending change.
                if (DEBUG) {
                    Slog.d(TAG, "Updating screen state: state="
                    Slog.d(TAG, "Updating screen state: id=" + mDisplayId +  ", state="
                            + Display.stateToString(state) + ", backlight=" + brightnessState);
                }
                mBlanker.requestDisplayState(state, brightnessState);
                mBlanker.requestDisplayState(mDisplayId, state, brightnessState);
            }
        }
    }
Loading