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

Commit c38c9be0 authored by Jeff Brown's avatar Jeff Brown
Browse files

Coordinate screen on with the window manager.

Bug: 7267457
Change-Id: Ic2c322253639e1f0b2e4e72a7b145025d0240f93
parent b2908854
Loading
Loading
Loading
Loading
+2 −1
Original line number Original line Diff line number Diff line
@@ -201,8 +201,9 @@ interface IWindowManager


    /**
    /**
     * Block until the given window has been drawn to the screen.
     * Block until the given window has been drawn to the screen.
     * Returns true if really waiting, false if the window does not exist.
     */
     */
    void waitForWindowDrawn(IBinder token, in IRemoteCallback callback);
    boolean waitForWindowDrawn(IBinder token, in IRemoteCallback callback);


    /**
    /**
     * Device has a software navigation bar (separate from the status bar).
     * Device has a software navigation bar (separate from the status bar).
+2 −7
Original line number Original line Diff line number Diff line
@@ -1058,18 +1058,13 @@ public interface WindowManagerPolicy {
     * Called when we have started keeping the screen on because a window
     * Called when we have started keeping the screen on because a window
     * requesting this has become visible.
     * requesting this has become visible.
     */
     */
    public void screenOnStartedLw();
    public void keepScreenOnStartedLw();


    /**
    /**
     * Called when we have stopped keeping the screen on because the last window
     * Called when we have stopped keeping the screen on because the last window
     * requesting this is no longer visible.
     * requesting this is no longer visible.
     */
     */
    public void screenOnStoppedLw();
    public void keepScreenOnStoppedLw();

    /**
     * Return false to disable key repeat events from being generated.
     */
    public boolean allowKeyRepeat();


    /**
    /**
     * Inform the policy that the user has chosen a preferred orientation ("rotation lock"). 
     * Inform the policy that the user has chosen a preferred orientation ("rotation lock"). 
+70 −56
Original line number Original line Diff line number Diff line
@@ -3580,7 +3580,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        }
        }
    };
    };


    /** {@inheritDoc} */
    @Override
    public void screenTurnedOff(int why) {
    public void screenTurnedOff(int why) {
        EventLog.writeEvent(70000, 0);
        EventLog.writeEvent(70000, 0);
        synchronized (mLock) {
        synchronized (mLock) {
@@ -3596,7 +3596,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        }
        }
    }
    }


    /** {@inheritDoc} */
    @Override
    public void screenTurningOn(final ScreenOnListener screenOnListener) {
    public void screenTurningOn(final ScreenOnListener screenOnListener) {
        EventLog.writeEvent(70000, 1);
        EventLog.writeEvent(70000, 1);
        if (false) {
        if (false) {
@@ -3604,60 +3604,79 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            here.fillInStackTrace();
            here.fillInStackTrace();
            Slog.i(TAG, "Screen turning on...", here);
            Slog.i(TAG, "Screen turning on...", here);
        }
        }
        if (screenOnListener != null) {

            if (mKeyguardMediator != null) {
        synchronized (mLock) {
            mScreenOnEarly = true;
            updateOrientationListenerLp();
            updateLockScreenTimeout();
        }

        try {
        try {
            mWindowManager.setEventDispatching(true);
            mWindowManager.setEventDispatching(true);
        } catch (RemoteException unhandled) {
        } catch (RemoteException unhandled) {
        }
        }
                mKeyguardMediator.onScreenTurnedOn(new KeyguardViewManager.ShowListener() {

                    @Override public void onShown(IBinder windowToken) {
        waitForKeyguard(screenOnListener);
                        if (windowToken != null) {
                            try {
                                mWindowManager.waitForWindowDrawn(windowToken,
                                        new IRemoteCallback.Stub() {
                                    @Override public void sendResult(Bundle data) {
                                        Slog.i(TAG, "Lock screen displayed!");
                                        screenOnListener.onScreenOn();
                                        synchronized (mLock) {
                                            mScreenOnFully = true;
    }
    }

    private void waitForKeyguard(final ScreenOnListener screenOnListener) {
        if (mKeyguardMediator != null) {
            if (screenOnListener != null) {
                mKeyguardMediator.onScreenTurnedOn(new KeyguardViewManager.ShowListener() {
                    @Override
                    public void onShown(IBinder windowToken) {
                        waitForKeyguardWindowDrawn(windowToken, screenOnListener);
                    }
                    }
                });
                });
                            } catch (RemoteException e) {
                return;
            } else {
                mKeyguardMediator.onScreenTurnedOn(null);
            }
            }
        } else {
        } else {
                            Slog.i(TAG, "No lock screen!");
            Slog.i(TAG, "No keyguard mediator!");
                            screenOnListener.onScreenOn();
                            synchronized (mLock) {
                                mScreenOnFully = true;
        }
        }
        finishScreenTurningOn(screenOnListener);
    }
    }

    private void waitForKeyguardWindowDrawn(IBinder windowToken,
            final ScreenOnListener screenOnListener) {
        if (windowToken != null) {
            try {
                if (mWindowManager.waitForWindowDrawn(
                        windowToken, new IRemoteCallback.Stub() {
                    @Override
                    public void sendResult(Bundle data) {
                        Slog.i(TAG, "Lock screen displayed!");
                        finishScreenTurningOn(screenOnListener);
                    }
                    }
                });
                })) {
                    return;
                }
                }
        } else {
            } catch (RemoteException ex) {
            if (mKeyguardMediator != null) {
                // Can't happen in system process.
                // Must set mScreenOn = true.
                mKeyguardMediator.onScreenTurnedOn(null);
            }
            }
            synchronized (mLock) {
                mScreenOnFully = true;
        }
        }

        Slog.i(TAG, "No lock screen!");
        finishScreenTurningOn(screenOnListener);
    }
    }

    private void finishScreenTurningOn(ScreenOnListener screenOnListener) {
        synchronized (mLock) {
        synchronized (mLock) {
            mScreenOnEarly = true;
            mScreenOnFully = true;
            updateOrientationListenerLp();
        }
            updateLockScreenTimeout();

        if (screenOnListener != null) {
            screenOnListener.onScreenOn();
        }
        }
    }
    }


    /** {@inheritDoc} */
    @Override
    public boolean isScreenOnEarly() {
    public boolean isScreenOnEarly() {
        return mScreenOnEarly;
        return mScreenOnEarly;
    }
    }


    /** {@inheritDoc} */
    @Override
    public boolean isScreenOnFully() {
    public boolean isScreenOnFully() {
        return mScreenOnFully;
        return mScreenOnFully;
    }
    }
@@ -4237,22 +4256,17 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        return true;
        return true;
    }
    }


    public void screenOnStartedLw() {
    @Override
    public void keepScreenOnStartedLw() {
    }
    }


    public void screenOnStoppedLw() {
    @Override
        if (mPowerManager.isScreenOn()) {
    public void keepScreenOnStoppedLw() {
        if (mKeyguardMediator != null && !mKeyguardMediator.isShowingAndNotHidden()) {
        if (mKeyguardMediator != null && !mKeyguardMediator.isShowingAndNotHidden()) {
            long curTime = SystemClock.uptimeMillis();
            long curTime = SystemClock.uptimeMillis();
            mPowerManager.userActivity(curTime, false);
            mPowerManager.userActivity(curTime, false);
        }
        }
    }
    }
    }

    public boolean allowKeyRepeat() {
        // disable key repeat when screen is off
        return mScreenOnEarly;
    }


    private int updateSystemUiVisibilityLw() {
    private int updateSystemUiVisibilityLw() {
        // If there is no window focused, there will be nobody to handle the events
        // If there is no window focused, there will be nobody to handle the events
+41 −13
Original line number Original line Diff line number Diff line
@@ -531,6 +531,7 @@ final class DisplayPowerController {
        final boolean mustNotify;
        final boolean mustNotify;
        boolean mustInitialize = false;
        boolean mustInitialize = false;
        boolean updateAutoBrightness = mTwilightChanged;
        boolean updateAutoBrightness = mTwilightChanged;
        boolean screenOnWasBlocked = false;
        mTwilightChanged = false;
        mTwilightChanged = false;


        synchronized (mLock) {
        synchronized (mLock) {
@@ -588,7 +589,6 @@ final class DisplayPowerController {
            if (mScreenOffBecauseOfProximity
            if (mScreenOffBecauseOfProximity
                    && mProximity != PROXIMITY_POSITIVE) {
                    && mProximity != PROXIMITY_POSITIVE) {
                mScreenOffBecauseOfProximity = false;
                mScreenOffBecauseOfProximity = false;
                setScreenOn(true);
                sendOnProximityNegative();
                sendOnProximityNegative();
            }
            }
        } else {
        } else {
@@ -639,6 +639,12 @@ final class DisplayPowerController {
                // It is relatively short but if we cancel it and switch to the
                // It is relatively short but if we cancel it and switch to the
                // on animation immediately then the results are pretty ugly.
                // on animation immediately then the results are pretty ugly.
                if (!mElectronBeamOffAnimator.isStarted()) {
                if (!mElectronBeamOffAnimator.isStarted()) {
                    if (mPowerRequest.blockScreenOn && !mPowerState.isScreenOn()) {
                        if (DEBUG) {
                            Slog.d(TAG, "Blocked screen on while screen currently off.");
                        }
                        screenOnWasBlocked = true;
                    } else {
                        setScreenOn(true);
                        setScreenOn(true);
                        if (USE_ELECTRON_BEAM_ON_ANIMATION) {
                        if (USE_ELECTRON_BEAM_ON_ANIMATION) {
                            if (!mElectronBeamOnAnimator.isStarted()) {
                            if (!mElectronBeamOnAnimator.isStarted()) {
@@ -655,6 +661,23 @@ final class DisplayPowerController {
                            mPowerState.dismissElectronBeam();
                            mPowerState.dismissElectronBeam();
                        }
                        }
                    }
                    }
                } else {
                    // FIXME: If the electron beam off animation is playing then we have a bit
                    // of a problem.  The window manager policy would only have requested
                    // to block screen on if it was about to start preparing the keyguard.
                    // It's already too late to do anything about that.  Ideally we would
                    // let the animation play out first but that would require making
                    // some pretty deep changes to the power manager and we don't have
                    // time just now.  For now, short-circuit the animation and get ready.
                    if (mPowerRequest.blockScreenOn) {
                        if (DEBUG) {
                            Slog.d(TAG, "Blocked screen on while screen off animation running.");
                        }
                        screenOnWasBlocked = true;
                        setScreenOn(false);
                        mElectronBeamOffAnimator.end();
                    }
                }
            } else {
            } else {
                // Want screen off.
                // Want screen off.
                // Wait for previous on animation to complete beforehand.
                // Wait for previous on animation to complete beforehand.
@@ -677,12 +700,17 @@ final class DisplayPowerController {
        // We mostly care about the screen state here, ignoring brightness changes
        // We mostly care about the screen state here, ignoring brightness changes
        // which will be handled asynchronously.
        // which will be handled asynchronously.
        if (mustNotify
        if (mustNotify
                && !screenOnWasBlocked
                && !mElectronBeamOnAnimator.isStarted()
                && !mElectronBeamOnAnimator.isStarted()
                && !mElectronBeamOffAnimator.isStarted()
                && !mElectronBeamOffAnimator.isStarted()
                && mPowerState.waitUntilClean(mCleanListener)) {
                && mPowerState.waitUntilClean(mCleanListener)) {
            synchronized (mLock) {
            synchronized (mLock) {
                if (!mPendingRequestChangedLocked) {
                if (!mPendingRequestChangedLocked) {
                    mDisplayReadyLocked = true;
                    mDisplayReadyLocked = true;

                    if (DEBUG) {
                        Slog.d(TAG, "Display ready!");
                    }
                }
                }
            }
            }
            sendOnStateChanged();
            sendOnStateChanged();
+13 −2
Original line number Original line Diff line number Diff line
@@ -52,12 +52,20 @@ final class DisplayPowerRequest {
    // If true, enables automatic brightness control.
    // If true, enables automatic brightness control.
    public boolean useAutoBrightness;
    public boolean useAutoBrightness;


    // If true, prevents the screen from turning on if it is currently off.
    // The display does not enter a "ready" state if this flag is true and the screen
    // is off and is being prevented from turning on.  The window manager policy blocks
    // screen on while it prepares the keyguard to prevent the user from seeing
    // intermediate updates.
    public boolean blockScreenOn;

    public DisplayPowerRequest() {
    public DisplayPowerRequest() {
        screenState = SCREEN_STATE_BRIGHT;
        screenState = SCREEN_STATE_BRIGHT;
        useProximitySensor = false;
        useProximitySensor = false;
        screenBrightness = PowerManager.BRIGHTNESS_ON;
        screenBrightness = PowerManager.BRIGHTNESS_ON;
        screenAutoBrightnessAdjustment = 0.0f;
        screenAutoBrightnessAdjustment = 0.0f;
        useAutoBrightness = false;
        useAutoBrightness = false;
        blockScreenOn = false;
    }
    }


    public DisplayPowerRequest(DisplayPowerRequest other) {
    public DisplayPowerRequest(DisplayPowerRequest other) {
@@ -70,6 +78,7 @@ final class DisplayPowerRequest {
        screenBrightness = other.screenBrightness;
        screenBrightness = other.screenBrightness;
        screenAutoBrightnessAdjustment = other.screenAutoBrightnessAdjustment;
        screenAutoBrightnessAdjustment = other.screenAutoBrightnessAdjustment;
        useAutoBrightness = other.useAutoBrightness;
        useAutoBrightness = other.useAutoBrightness;
        blockScreenOn = other.blockScreenOn;
    }
    }


    @Override
    @Override
@@ -84,7 +93,8 @@ final class DisplayPowerRequest {
                && useProximitySensor == other.useProximitySensor
                && useProximitySensor == other.useProximitySensor
                && screenBrightness == other.screenBrightness
                && screenBrightness == other.screenBrightness
                && screenAutoBrightnessAdjustment == other.screenAutoBrightnessAdjustment
                && screenAutoBrightnessAdjustment == other.screenAutoBrightnessAdjustment
                && useAutoBrightness == other.useAutoBrightness;
                && useAutoBrightness == other.useAutoBrightness
                && blockScreenOn == other.blockScreenOn;
    }
    }


    @Override
    @Override
@@ -98,6 +108,7 @@ final class DisplayPowerRequest {
                + ", useProximitySensor=" + useProximitySensor
                + ", useProximitySensor=" + useProximitySensor
                + ", screenBrightness=" + screenBrightness
                + ", screenBrightness=" + screenBrightness
                + ", screenAutoBrightnessAdjustment=" + screenAutoBrightnessAdjustment
                + ", screenAutoBrightnessAdjustment=" + screenAutoBrightnessAdjustment
                + ", useAutoBrightness=" + useAutoBrightness;
                + ", useAutoBrightness=" + useAutoBrightness
                + ", blockScreenOn=" + blockScreenOn;
    }
    }
}
}
Loading