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

Commit 8444a94b authored by Sean Stout's avatar Sean Stout
Browse files

Implement phase 1 of per-display power states

This CL updates some lower level components to be display ID aware.

Test: manual - boot device and toggle screen power
Bug: 138328918
Change-Id: Iaa4f10f0e4637fe06875f9c067586e1f7abf02fa
parent eb806d84
Loading
Loading
Loading
Loading
+4 −8
Original line number Original line Diff line number Diff line
@@ -208,7 +208,6 @@ class AutomaticBrightnessController {
    private PackageManager mPackageManager;
    private PackageManager mPackageManager;
    private Context mContext;
    private Context mContext;


    private DisplayDeviceConfig mDisplayDeviceConfig;
    private final Injector mInjector;
    private final Injector mInjector;


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


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


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


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


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


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


        final Resources resources = context.getResources();
        final Resources resources = context.getResources();


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


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


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


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


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


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


    private Runnable mCleanListener;
    private Runnable mCleanListener;


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


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


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