Loading core/java/android/view/IWindowManager.aidl +2 −1 Original line number Diff line number Diff line Loading @@ -201,8 +201,9 @@ interface IWindowManager /** * 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). Loading core/java/android/view/WindowManagerPolicy.java +2 −7 Original line number Diff line number Diff line Loading @@ -1058,18 +1058,13 @@ public interface WindowManagerPolicy { * Called when we have started keeping the screen on because a window * requesting this has become visible. */ public void screenOnStartedLw(); public void keepScreenOnStartedLw(); /** * Called when we have stopped keeping the screen on because the last window * requesting this is no longer visible. */ public void screenOnStoppedLw(); /** * Return false to disable key repeat events from being generated. */ public boolean allowKeyRepeat(); public void keepScreenOnStoppedLw(); /** * Inform the policy that the user has chosen a preferred orientation ("rotation lock"). Loading policy/src/com/android/internal/policy/impl/PhoneWindowManager.java +70 −56 Original line number Diff line number Diff line Loading @@ -3580,7 +3580,7 @@ public class PhoneWindowManager implements WindowManagerPolicy { } }; /** {@inheritDoc} */ @Override public void screenTurnedOff(int why) { EventLog.writeEvent(70000, 0); synchronized (mLock) { Loading @@ -3596,7 +3596,7 @@ public class PhoneWindowManager implements WindowManagerPolicy { } } /** {@inheritDoc} */ @Override public void screenTurningOn(final ScreenOnListener screenOnListener) { EventLog.writeEvent(70000, 1); if (false) { Loading @@ -3604,60 +3604,79 @@ public class PhoneWindowManager implements WindowManagerPolicy { here.fillInStackTrace(); Slog.i(TAG, "Screen turning on...", here); } if (screenOnListener != null) { if (mKeyguardMediator != null) { synchronized (mLock) { mScreenOnEarly = true; updateOrientationListenerLp(); updateLockScreenTimeout(); } try { mWindowManager.setEventDispatching(true); } catch (RemoteException unhandled) { } mKeyguardMediator.onScreenTurnedOn(new KeyguardViewManager.ShowListener() { @Override public void onShown(IBinder windowToken) { 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; waitForKeyguard(screenOnListener); } 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 { Slog.i(TAG, "No lock screen!"); screenOnListener.onScreenOn(); synchronized (mLock) { mScreenOnFully = true; Slog.i(TAG, "No keyguard mediator!"); } 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 { if (mKeyguardMediator != null) { // Must set mScreenOn = true. mKeyguardMediator.onScreenTurnedOn(null); } catch (RemoteException ex) { // Can't happen in system process. } synchronized (mLock) { mScreenOnFully = true; } Slog.i(TAG, "No lock screen!"); finishScreenTurningOn(screenOnListener); } private void finishScreenTurningOn(ScreenOnListener screenOnListener) { synchronized (mLock) { mScreenOnEarly = true; updateOrientationListenerLp(); updateLockScreenTimeout(); mScreenOnFully = true; } if (screenOnListener != null) { screenOnListener.onScreenOn(); } } /** {@inheritDoc} */ @Override public boolean isScreenOnEarly() { return mScreenOnEarly; } /** {@inheritDoc} */ @Override public boolean isScreenOnFully() { return mScreenOnFully; } Loading Loading @@ -4237,22 +4256,17 @@ public class PhoneWindowManager implements WindowManagerPolicy { return true; } public void screenOnStartedLw() { @Override public void keepScreenOnStartedLw() { } public void screenOnStoppedLw() { if (mPowerManager.isScreenOn()) { @Override public void keepScreenOnStoppedLw() { if (mKeyguardMediator != null && !mKeyguardMediator.isShowingAndNotHidden()) { long curTime = SystemClock.uptimeMillis(); mPowerManager.userActivity(curTime, false); } } } public boolean allowKeyRepeat() { // disable key repeat when screen is off return mScreenOnEarly; } private int updateSystemUiVisibilityLw() { // If there is no window focused, there will be nobody to handle the events Loading services/java/com/android/server/power/DisplayPowerController.java +41 −13 Original line number Diff line number Diff line Loading @@ -531,6 +531,7 @@ final class DisplayPowerController { final boolean mustNotify; boolean mustInitialize = false; boolean updateAutoBrightness = mTwilightChanged; boolean screenOnWasBlocked = false; mTwilightChanged = false; synchronized (mLock) { Loading Loading @@ -588,7 +589,6 @@ final class DisplayPowerController { if (mScreenOffBecauseOfProximity && mProximity != PROXIMITY_POSITIVE) { mScreenOffBecauseOfProximity = false; setScreenOn(true); sendOnProximityNegative(); } } else { Loading Loading @@ -639,6 +639,12 @@ final class DisplayPowerController { // It is relatively short but if we cancel it and switch to the // on animation immediately then the results are pretty ugly. 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); if (USE_ELECTRON_BEAM_ON_ANIMATION) { if (!mElectronBeamOnAnimator.isStarted()) { Loading @@ -655,6 +661,23 @@ final class DisplayPowerController { 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 { // Want screen off. // Wait for previous on animation to complete beforehand. Loading @@ -677,12 +700,17 @@ final class DisplayPowerController { // We mostly care about the screen state here, ignoring brightness changes // which will be handled asynchronously. if (mustNotify && !screenOnWasBlocked && !mElectronBeamOnAnimator.isStarted() && !mElectronBeamOffAnimator.isStarted() && mPowerState.waitUntilClean(mCleanListener)) { synchronized (mLock) { if (!mPendingRequestChangedLocked) { mDisplayReadyLocked = true; if (DEBUG) { Slog.d(TAG, "Display ready!"); } } } sendOnStateChanged(); Loading services/java/com/android/server/power/DisplayPowerRequest.java +13 −2 Original line number Diff line number Diff line Loading @@ -52,12 +52,20 @@ final class DisplayPowerRequest { // If true, enables automatic brightness control. 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() { screenState = SCREEN_STATE_BRIGHT; useProximitySensor = false; screenBrightness = PowerManager.BRIGHTNESS_ON; screenAutoBrightnessAdjustment = 0.0f; useAutoBrightness = false; blockScreenOn = false; } public DisplayPowerRequest(DisplayPowerRequest other) { Loading @@ -70,6 +78,7 @@ final class DisplayPowerRequest { screenBrightness = other.screenBrightness; screenAutoBrightnessAdjustment = other.screenAutoBrightnessAdjustment; useAutoBrightness = other.useAutoBrightness; blockScreenOn = other.blockScreenOn; } @Override Loading @@ -84,7 +93,8 @@ final class DisplayPowerRequest { && useProximitySensor == other.useProximitySensor && screenBrightness == other.screenBrightness && screenAutoBrightnessAdjustment == other.screenAutoBrightnessAdjustment && useAutoBrightness == other.useAutoBrightness; && useAutoBrightness == other.useAutoBrightness && blockScreenOn == other.blockScreenOn; } @Override Loading @@ -98,6 +108,7 @@ final class DisplayPowerRequest { + ", useProximitySensor=" + useProximitySensor + ", screenBrightness=" + screenBrightness + ", screenAutoBrightnessAdjustment=" + screenAutoBrightnessAdjustment + ", useAutoBrightness=" + useAutoBrightness; + ", useAutoBrightness=" + useAutoBrightness + ", blockScreenOn=" + blockScreenOn; } } Loading
core/java/android/view/IWindowManager.aidl +2 −1 Original line number Diff line number Diff line Loading @@ -201,8 +201,9 @@ interface IWindowManager /** * 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). Loading
core/java/android/view/WindowManagerPolicy.java +2 −7 Original line number Diff line number Diff line Loading @@ -1058,18 +1058,13 @@ public interface WindowManagerPolicy { * Called when we have started keeping the screen on because a window * requesting this has become visible. */ public void screenOnStartedLw(); public void keepScreenOnStartedLw(); /** * Called when we have stopped keeping the screen on because the last window * requesting this is no longer visible. */ public void screenOnStoppedLw(); /** * Return false to disable key repeat events from being generated. */ public boolean allowKeyRepeat(); public void keepScreenOnStoppedLw(); /** * Inform the policy that the user has chosen a preferred orientation ("rotation lock"). Loading
policy/src/com/android/internal/policy/impl/PhoneWindowManager.java +70 −56 Original line number Diff line number Diff line Loading @@ -3580,7 +3580,7 @@ public class PhoneWindowManager implements WindowManagerPolicy { } }; /** {@inheritDoc} */ @Override public void screenTurnedOff(int why) { EventLog.writeEvent(70000, 0); synchronized (mLock) { Loading @@ -3596,7 +3596,7 @@ public class PhoneWindowManager implements WindowManagerPolicy { } } /** {@inheritDoc} */ @Override public void screenTurningOn(final ScreenOnListener screenOnListener) { EventLog.writeEvent(70000, 1); if (false) { Loading @@ -3604,60 +3604,79 @@ public class PhoneWindowManager implements WindowManagerPolicy { here.fillInStackTrace(); Slog.i(TAG, "Screen turning on...", here); } if (screenOnListener != null) { if (mKeyguardMediator != null) { synchronized (mLock) { mScreenOnEarly = true; updateOrientationListenerLp(); updateLockScreenTimeout(); } try { mWindowManager.setEventDispatching(true); } catch (RemoteException unhandled) { } mKeyguardMediator.onScreenTurnedOn(new KeyguardViewManager.ShowListener() { @Override public void onShown(IBinder windowToken) { 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; waitForKeyguard(screenOnListener); } 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 { Slog.i(TAG, "No lock screen!"); screenOnListener.onScreenOn(); synchronized (mLock) { mScreenOnFully = true; Slog.i(TAG, "No keyguard mediator!"); } 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 { if (mKeyguardMediator != null) { // Must set mScreenOn = true. mKeyguardMediator.onScreenTurnedOn(null); } catch (RemoteException ex) { // Can't happen in system process. } synchronized (mLock) { mScreenOnFully = true; } Slog.i(TAG, "No lock screen!"); finishScreenTurningOn(screenOnListener); } private void finishScreenTurningOn(ScreenOnListener screenOnListener) { synchronized (mLock) { mScreenOnEarly = true; updateOrientationListenerLp(); updateLockScreenTimeout(); mScreenOnFully = true; } if (screenOnListener != null) { screenOnListener.onScreenOn(); } } /** {@inheritDoc} */ @Override public boolean isScreenOnEarly() { return mScreenOnEarly; } /** {@inheritDoc} */ @Override public boolean isScreenOnFully() { return mScreenOnFully; } Loading Loading @@ -4237,22 +4256,17 @@ public class PhoneWindowManager implements WindowManagerPolicy { return true; } public void screenOnStartedLw() { @Override public void keepScreenOnStartedLw() { } public void screenOnStoppedLw() { if (mPowerManager.isScreenOn()) { @Override public void keepScreenOnStoppedLw() { if (mKeyguardMediator != null && !mKeyguardMediator.isShowingAndNotHidden()) { long curTime = SystemClock.uptimeMillis(); mPowerManager.userActivity(curTime, false); } } } public boolean allowKeyRepeat() { // disable key repeat when screen is off return mScreenOnEarly; } private int updateSystemUiVisibilityLw() { // If there is no window focused, there will be nobody to handle the events Loading
services/java/com/android/server/power/DisplayPowerController.java +41 −13 Original line number Diff line number Diff line Loading @@ -531,6 +531,7 @@ final class DisplayPowerController { final boolean mustNotify; boolean mustInitialize = false; boolean updateAutoBrightness = mTwilightChanged; boolean screenOnWasBlocked = false; mTwilightChanged = false; synchronized (mLock) { Loading Loading @@ -588,7 +589,6 @@ final class DisplayPowerController { if (mScreenOffBecauseOfProximity && mProximity != PROXIMITY_POSITIVE) { mScreenOffBecauseOfProximity = false; setScreenOn(true); sendOnProximityNegative(); } } else { Loading Loading @@ -639,6 +639,12 @@ final class DisplayPowerController { // It is relatively short but if we cancel it and switch to the // on animation immediately then the results are pretty ugly. 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); if (USE_ELECTRON_BEAM_ON_ANIMATION) { if (!mElectronBeamOnAnimator.isStarted()) { Loading @@ -655,6 +661,23 @@ final class DisplayPowerController { 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 { // Want screen off. // Wait for previous on animation to complete beforehand. Loading @@ -677,12 +700,17 @@ final class DisplayPowerController { // We mostly care about the screen state here, ignoring brightness changes // which will be handled asynchronously. if (mustNotify && !screenOnWasBlocked && !mElectronBeamOnAnimator.isStarted() && !mElectronBeamOffAnimator.isStarted() && mPowerState.waitUntilClean(mCleanListener)) { synchronized (mLock) { if (!mPendingRequestChangedLocked) { mDisplayReadyLocked = true; if (DEBUG) { Slog.d(TAG, "Display ready!"); } } } sendOnStateChanged(); Loading
services/java/com/android/server/power/DisplayPowerRequest.java +13 −2 Original line number Diff line number Diff line Loading @@ -52,12 +52,20 @@ final class DisplayPowerRequest { // If true, enables automatic brightness control. 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() { screenState = SCREEN_STATE_BRIGHT; useProximitySensor = false; screenBrightness = PowerManager.BRIGHTNESS_ON; screenAutoBrightnessAdjustment = 0.0f; useAutoBrightness = false; blockScreenOn = false; } public DisplayPowerRequest(DisplayPowerRequest other) { Loading @@ -70,6 +78,7 @@ final class DisplayPowerRequest { screenBrightness = other.screenBrightness; screenAutoBrightnessAdjustment = other.screenAutoBrightnessAdjustment; useAutoBrightness = other.useAutoBrightness; blockScreenOn = other.blockScreenOn; } @Override Loading @@ -84,7 +93,8 @@ final class DisplayPowerRequest { && useProximitySensor == other.useProximitySensor && screenBrightness == other.screenBrightness && screenAutoBrightnessAdjustment == other.screenAutoBrightnessAdjustment && useAutoBrightness == other.useAutoBrightness; && useAutoBrightness == other.useAutoBrightness && blockScreenOn == other.blockScreenOn; } @Override Loading @@ -98,6 +108,7 @@ final class DisplayPowerRequest { + ", useProximitySensor=" + useProximitySensor + ", screenBrightness=" + screenBrightness + ", screenAutoBrightnessAdjustment=" + screenAutoBrightnessAdjustment + ", useAutoBrightness=" + useAutoBrightness; + ", useAutoBrightness=" + useAutoBrightness + ", blockScreenOn=" + blockScreenOn; } }