Skip to content

Commit c38c9be

Browse files
author
Jeff Brown
committed
Coordinate screen on with the window manager.
Bug: 7267457 Change-Id: Ic2c322253639e1f0b2e4e72a7b145025d0240f93
1 parent b290885 commit c38c9be

File tree

10 files changed

+292
-111
lines changed

10 files changed

+292
-111
lines changed

core/java/android/view/IWindowManager.aidl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,9 @@ interface IWindowManager
201201

202202
/**
203203
* Block until the given window has been drawn to the screen.
204+
* Returns true if really waiting, false if the window does not exist.
204205
*/
205-
void waitForWindowDrawn(IBinder token, in IRemoteCallback callback);
206+
boolean waitForWindowDrawn(IBinder token, in IRemoteCallback callback);
206207

207208
/**
208209
* Device has a software navigation bar (separate from the status bar).

core/java/android/view/WindowManagerPolicy.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,18 +1058,13 @@ interface OnKeyguardExitResult {
10581058
* Called when we have started keeping the screen on because a window
10591059
* requesting this has become visible.
10601060
*/
1061-
public void screenOnStartedLw();
1061+
public void keepScreenOnStartedLw();
10621062

10631063
/**
10641064
* Called when we have stopped keeping the screen on because the last window
10651065
* requesting this is no longer visible.
10661066
*/
1067-
public void screenOnStoppedLw();
1068-
1069-
/**
1070-
* Return false to disable key repeat events from being generated.
1071-
*/
1072-
public boolean allowKeyRepeat();
1067+
public void keepScreenOnStoppedLw();
10731068

10741069
/**
10751070
* Inform the policy that the user has chosen a preferred orientation ("rotation lock").

policy/src/com/android/internal/policy/impl/PhoneWindowManager.java

Lines changed: 70 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -3580,7 +3580,7 @@ public void onReceive(Context context, Intent intent) {
35803580
}
35813581
};
35823582

3583-
/** {@inheritDoc} */
3583+
@Override
35843584
public void screenTurnedOff(int why) {
35853585
EventLog.writeEvent(70000, 0);
35863586
synchronized (mLock) {
@@ -3596,72 +3596,91 @@ public void screenTurnedOff(int why) {
35963596
}
35973597
}
35983598

3599-
/** {@inheritDoc} */
3599+
@Override
36003600
public void screenTurningOn(final ScreenOnListener screenOnListener) {
36013601
EventLog.writeEvent(70000, 1);
36023602
if (false) {
36033603
RuntimeException here = new RuntimeException("here");
36043604
here.fillInStackTrace();
36053605
Slog.i(TAG, "Screen turning on...", here);
36063606
}
3607-
if (screenOnListener != null) {
3608-
if (mKeyguardMediator != null) {
3609-
try {
3610-
mWindowManager.setEventDispatching(true);
3611-
} catch (RemoteException unhandled) {
3612-
}
3607+
3608+
synchronized (mLock) {
3609+
mScreenOnEarly = true;
3610+
updateOrientationListenerLp();
3611+
updateLockScreenTimeout();
3612+
}
3613+
3614+
try {
3615+
mWindowManager.setEventDispatching(true);
3616+
} catch (RemoteException unhandled) {
3617+
}
3618+
3619+
waitForKeyguard(screenOnListener);
3620+
}
3621+
3622+
private void waitForKeyguard(final ScreenOnListener screenOnListener) {
3623+
if (mKeyguardMediator != null) {
3624+
if (screenOnListener != null) {
36133625
mKeyguardMediator.onScreenTurnedOn(new KeyguardViewManager.ShowListener() {
3614-
@Override public void onShown(IBinder windowToken) {
3615-
if (windowToken != null) {
3616-
try {
3617-
mWindowManager.waitForWindowDrawn(windowToken,
3618-
new IRemoteCallback.Stub() {
3619-
@Override public void sendResult(Bundle data) {
3620-
Slog.i(TAG, "Lock screen displayed!");
3621-
screenOnListener.onScreenOn();
3622-
synchronized (mLock) {
3623-
mScreenOnFully = true;
3624-
}
3625-
}
3626-
});
3627-
} catch (RemoteException e) {
3628-
}
3629-
} else {
3630-
Slog.i(TAG, "No lock screen!");
3631-
screenOnListener.onScreenOn();
3632-
synchronized (mLock) {
3633-
mScreenOnFully = true;
3634-
}
3635-
}
3626+
@Override
3627+
public void onShown(IBinder windowToken) {
3628+
waitForKeyguardWindowDrawn(windowToken, screenOnListener);
36363629
}
36373630
});
3638-
}
3639-
} else {
3640-
if (mKeyguardMediator != null) {
3641-
// Must set mScreenOn = true.
3631+
return;
3632+
} else {
36423633
mKeyguardMediator.onScreenTurnedOn(null);
36433634
}
3644-
synchronized (mLock) {
3645-
mScreenOnFully = true;
3635+
} else {
3636+
Slog.i(TAG, "No keyguard mediator!");
3637+
}
3638+
finishScreenTurningOn(screenOnListener);
3639+
}
3640+
3641+
private void waitForKeyguardWindowDrawn(IBinder windowToken,
3642+
final ScreenOnListener screenOnListener) {
3643+
if (windowToken != null) {
3644+
try {
3645+
if (mWindowManager.waitForWindowDrawn(
3646+
windowToken, new IRemoteCallback.Stub() {
3647+
@Override
3648+
public void sendResult(Bundle data) {
3649+
Slog.i(TAG, "Lock screen displayed!");
3650+
finishScreenTurningOn(screenOnListener);
3651+
}
3652+
})) {
3653+
return;
3654+
}
3655+
} catch (RemoteException ex) {
3656+
// Can't happen in system process.
36463657
}
36473658
}
3659+
3660+
Slog.i(TAG, "No lock screen!");
3661+
finishScreenTurningOn(screenOnListener);
3662+
}
3663+
3664+
private void finishScreenTurningOn(ScreenOnListener screenOnListener) {
36483665
synchronized (mLock) {
3649-
mScreenOnEarly = true;
3650-
updateOrientationListenerLp();
3651-
updateLockScreenTimeout();
3666+
mScreenOnFully = true;
3667+
}
3668+
3669+
if (screenOnListener != null) {
3670+
screenOnListener.onScreenOn();
36523671
}
36533672
}
36543673

3655-
/** {@inheritDoc} */
3674+
@Override
36563675
public boolean isScreenOnEarly() {
36573676
return mScreenOnEarly;
36583677
}
3659-
3660-
/** {@inheritDoc} */
3678+
3679+
@Override
36613680
public boolean isScreenOnFully() {
36623681
return mScreenOnFully;
36633682
}
3664-
3683+
36653684
/** {@inheritDoc} */
36663685
public void enableKeyguard(boolean enabled) {
36673686
if (mKeyguardMediator != null) {
@@ -4236,22 +4255,17 @@ public boolean performHapticFeedbackLw(WindowState win, int effectId, boolean al
42364255
}
42374256
return true;
42384257
}
4239-
4240-
public void screenOnStartedLw() {
4241-
}
42424258

4243-
public void screenOnStoppedLw() {
4244-
if (mPowerManager.isScreenOn()) {
4245-
if (mKeyguardMediator != null && !mKeyguardMediator.isShowingAndNotHidden()) {
4246-
long curTime = SystemClock.uptimeMillis();
4247-
mPowerManager.userActivity(curTime, false);
4248-
}
4249-
}
4259+
@Override
4260+
public void keepScreenOnStartedLw() {
42504261
}
42514262

4252-
public boolean allowKeyRepeat() {
4253-
// disable key repeat when screen is off
4254-
return mScreenOnEarly;
4263+
@Override
4264+
public void keepScreenOnStoppedLw() {
4265+
if (mKeyguardMediator != null && !mKeyguardMediator.isShowingAndNotHidden()) {
4266+
long curTime = SystemClock.uptimeMillis();
4267+
mPowerManager.userActivity(curTime, false);
4268+
}
42554269
}
42564270

42574271
private int updateSystemUiVisibilityLw() {

services/java/com/android/server/power/DisplayPowerController.java

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,7 @@ private void updatePowerState() {
531531
final boolean mustNotify;
532532
boolean mustInitialize = false;
533533
boolean updateAutoBrightness = mTwilightChanged;
534+
boolean screenOnWasBlocked = false;
534535
mTwilightChanged = false;
535536

536537
synchronized (mLock) {
@@ -588,7 +589,6 @@ private void updatePowerState() {
588589
if (mScreenOffBecauseOfProximity
589590
&& mProximity != PROXIMITY_POSITIVE) {
590591
mScreenOffBecauseOfProximity = false;
591-
setScreenOn(true);
592592
sendOnProximityNegative();
593593
}
594594
} else {
@@ -639,20 +639,43 @@ private void updatePowerState() {
639639
// It is relatively short but if we cancel it and switch to the
640640
// on animation immediately then the results are pretty ugly.
641641
if (!mElectronBeamOffAnimator.isStarted()) {
642-
setScreenOn(true);
643-
if (USE_ELECTRON_BEAM_ON_ANIMATION) {
644-
if (!mElectronBeamOnAnimator.isStarted()) {
645-
if (mPowerState.getElectronBeamLevel() == 1.0f) {
646-
mPowerState.dismissElectronBeam();
647-
} else if (mPowerState.prepareElectronBeam(true)) {
648-
mElectronBeamOnAnimator.start();
649-
} else {
650-
mElectronBeamOnAnimator.end();
651-
}
642+
if (mPowerRequest.blockScreenOn && !mPowerState.isScreenOn()) {
643+
if (DEBUG) {
644+
Slog.d(TAG, "Blocked screen on while screen currently off.");
652645
}
646+
screenOnWasBlocked = true;
653647
} else {
654-
mPowerState.setElectronBeamLevel(1.0f);
655-
mPowerState.dismissElectronBeam();
648+
setScreenOn(true);
649+
if (USE_ELECTRON_BEAM_ON_ANIMATION) {
650+
if (!mElectronBeamOnAnimator.isStarted()) {
651+
if (mPowerState.getElectronBeamLevel() == 1.0f) {
652+
mPowerState.dismissElectronBeam();
653+
} else if (mPowerState.prepareElectronBeam(true)) {
654+
mElectronBeamOnAnimator.start();
655+
} else {
656+
mElectronBeamOnAnimator.end();
657+
}
658+
}
659+
} else {
660+
mPowerState.setElectronBeamLevel(1.0f);
661+
mPowerState.dismissElectronBeam();
662+
}
663+
}
664+
} else {
665+
// FIXME: If the electron beam off animation is playing then we have a bit
666+
// of a problem. The window manager policy would only have requested
667+
// to block screen on if it was about to start preparing the keyguard.
668+
// It's already too late to do anything about that. Ideally we would
669+
// let the animation play out first but that would require making
670+
// some pretty deep changes to the power manager and we don't have
671+
// time just now. For now, short-circuit the animation and get ready.
672+
if (mPowerRequest.blockScreenOn) {
673+
if (DEBUG) {
674+
Slog.d(TAG, "Blocked screen on while screen off animation running.");
675+
}
676+
screenOnWasBlocked = true;
677+
setScreenOn(false);
678+
mElectronBeamOffAnimator.end();
656679
}
657680
}
658681
} else {
@@ -677,12 +700,17 @@ private void updatePowerState() {
677700
// We mostly care about the screen state here, ignoring brightness changes
678701
// which will be handled asynchronously.
679702
if (mustNotify
703+
&& !screenOnWasBlocked
680704
&& !mElectronBeamOnAnimator.isStarted()
681705
&& !mElectronBeamOffAnimator.isStarted()
682706
&& mPowerState.waitUntilClean(mCleanListener)) {
683707
synchronized (mLock) {
684708
if (!mPendingRequestChangedLocked) {
685709
mDisplayReadyLocked = true;
710+
711+
if (DEBUG) {
712+
Slog.d(TAG, "Display ready!");
713+
}
686714
}
687715
}
688716
sendOnStateChanged();

services/java/com/android/server/power/DisplayPowerRequest.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,20 @@ final class DisplayPowerRequest {
5252
// If true, enables automatic brightness control.
5353
public boolean useAutoBrightness;
5454

55+
// If true, prevents the screen from turning on if it is currently off.
56+
// The display does not enter a "ready" state if this flag is true and the screen
57+
// is off and is being prevented from turning on. The window manager policy blocks
58+
// screen on while it prepares the keyguard to prevent the user from seeing
59+
// intermediate updates.
60+
public boolean blockScreenOn;
61+
5562
public DisplayPowerRequest() {
5663
screenState = SCREEN_STATE_BRIGHT;
5764
useProximitySensor = false;
5865
screenBrightness = PowerManager.BRIGHTNESS_ON;
5966
screenAutoBrightnessAdjustment = 0.0f;
6067
useAutoBrightness = false;
68+
blockScreenOn = false;
6169
}
6270

6371
public DisplayPowerRequest(DisplayPowerRequest other) {
@@ -70,6 +78,7 @@ public void copyFrom(DisplayPowerRequest other) {
7078
screenBrightness = other.screenBrightness;
7179
screenAutoBrightnessAdjustment = other.screenAutoBrightnessAdjustment;
7280
useAutoBrightness = other.useAutoBrightness;
81+
blockScreenOn = other.blockScreenOn;
7382
}
7483

7584
@Override
@@ -84,7 +93,8 @@ public boolean equals(DisplayPowerRequest other) {
8493
&& useProximitySensor == other.useProximitySensor
8594
&& screenBrightness == other.screenBrightness
8695
&& screenAutoBrightnessAdjustment == other.screenAutoBrightnessAdjustment
87-
&& useAutoBrightness == other.useAutoBrightness;
96+
&& useAutoBrightness == other.useAutoBrightness
97+
&& blockScreenOn == other.blockScreenOn;
8898
}
8999

90100
@Override
@@ -98,6 +108,7 @@ public String toString() {
98108
+ ", useProximitySensor=" + useProximitySensor
99109
+ ", screenBrightness=" + screenBrightness
100110
+ ", screenAutoBrightnessAdjustment=" + screenAutoBrightnessAdjustment
101-
+ ", useAutoBrightness=" + useAutoBrightness;
111+
+ ", useAutoBrightness=" + useAutoBrightness
112+
+ ", blockScreenOn=" + blockScreenOn;
102113
}
103114
}

0 commit comments

Comments
 (0)