Fix issue #4279860: previous UI flashes before showing lock screen...
...(when turning display on after recently turning it off)
Also clean up when we decide to turn the screen on to improve that
transition. There are still problems here with turning it on
before the wallpaper gets dispayed.
Change-Id: I2bc56c12e5ad75a1ce5a0546f43a845bf0823e66
diff --git a/services/java/com/android/server/PowerManagerService.java b/services/java/com/android/server/PowerManagerService.java
index d80a2cd..cbd986f 100644
--- a/services/java/com/android/server/PowerManagerService.java
+++ b/services/java/com/android/server/PowerManagerService.java
@@ -161,6 +161,7 @@
private int mStayOnConditions = 0;
private final int[] mBroadcastQueue = new int[] { -1, -1, -1 };
private final int[] mBroadcastWhy = new int[3];
+ private boolean mBroadcastingScreenOff = false;
private int mPartialCount = 0;
private int mPowerState;
// mScreenOffReason can be WindowManagerPolicy.OFF_BECAUSE_OF_USER,
@@ -1342,6 +1343,10 @@
mBroadcastWakeLock.release();
}
+ // The broadcast queue has changed; make sure the screen is on if it
+ // is now possible for it to be.
+ updateNativePowerStateLocked();
+
// Now send the message.
if (index >= 0) {
// Acquire the broadcast wake lock before changing the power
@@ -1370,6 +1375,9 @@
mBroadcastWhy[i] = mBroadcastWhy[i+1];
}
policy = getPolicyLocked();
+ if (value == 0) {
+ mBroadcastingScreenOff = true;
+ }
}
if (value == 1) {
mScreenOnStart = SystemClock.uptimeMillis();
@@ -1412,6 +1420,8 @@
synchronized (mLocks) {
EventLog.writeEvent(EventLogTags.POWER_SCREEN_BROADCAST_STOP, 3,
mBroadcastWakeLock.mCount);
+ mBroadcastingScreenOff = false;
+ updateNativePowerStateLocked();
mBroadcastWakeLock.release();
}
}
@@ -1442,6 +1452,10 @@
synchronized (mLocks) {
EventLog.writeEvent(EventLogTags.POWER_SCREEN_BROADCAST_DONE, 0,
SystemClock.uptimeMillis() - mScreenOffStart, mBroadcastWakeLock.mCount);
+ synchronized (mLocks) {
+ mBroadcastingScreenOff = false;
+ updateNativePowerStateLocked();
+ }
mBroadcastWakeLock.release();
}
}
@@ -1768,6 +1782,22 @@
}
private void updateNativePowerStateLocked() {
+ if ((mPowerState & SCREEN_ON_BIT) != 0) {
+ // Don't turn screen on if we are currently reporting a screen off.
+ // This is to avoid letting the screen go on before things like the
+ // lock screen have been displayed due to it going off.
+ if (mBroadcastingScreenOff) {
+ // Currently broadcasting that the screen is off. Don't
+ // allow screen to go on until that is done.
+ return;
+ }
+ for (int i=0; i<mBroadcastQueue.length; i++) {
+ if (mBroadcastQueue[i] == 0) {
+ // A screen off is currently enqueued.
+ return;
+ }
+ }
+ }
nativeSetPowerState(
(mPowerState & SCREEN_ON_BIT) != 0,
(mPowerState & SCREEN_BRIGHT) == SCREEN_BRIGHT);
diff --git a/services/java/com/android/server/am/ActivityManagerService.java b/services/java/com/android/server/am/ActivityManagerService.java
index b817598..c935733 100644
--- a/services/java/com/android/server/am/ActivityManagerService.java
+++ b/services/java/com/android/server/am/ActivityManagerService.java
@@ -6564,7 +6564,7 @@
i--;
}
}
-
+
for (int i=0; i<ris.size(); i++) {
ActivityInfo ai = ris.get(i).activityInfo;
ComponentName comp = new ComponentName(ai.packageName, ai.name);
diff --git a/services/java/com/android/server/am/ActivityStack.java b/services/java/com/android/server/am/ActivityStack.java
index 6f0779f..4ad0f45 100644
--- a/services/java/com/android/server/am/ActivityStack.java
+++ b/services/java/com/android/server/am/ActivityStack.java
@@ -3163,7 +3163,7 @@
//Slog.i(TAG, "IDLE: mBooted=" + mBooted + ", fromTimeout=" + fromTimeout);
if (mMainStack) {
- if (!mService.mBooted && !fromTimeout) {
+ if (!mService.mBooted) {
mService.mBooted = true;
enableScreen = true;
}
diff --git a/services/java/com/android/server/wm/WindowManagerService.java b/services/java/com/android/server/wm/WindowManagerService.java
index dc5555e..3df94a6 100644
--- a/services/java/com/android/server/wm/WindowManagerService.java
+++ b/services/java/com/android/server/wm/WindowManagerService.java
@@ -50,11 +50,9 @@
import android.Manifest;
import android.app.ActivityManagerNative;
import android.app.IActivityManager;
-import android.app.ProgressDialog;
import android.app.StatusBarManager;
import android.app.admin.DevicePolicyManager;
import android.content.BroadcastReceiver;
-import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
@@ -164,6 +162,7 @@
static final boolean DEBUG_REORDER = false;
static final boolean DEBUG_WALLPAPER = false;
static final boolean DEBUG_DRAG = false;
+ static final boolean DEBUG_SCREEN_ON = false;
static final boolean SHOW_SURFACE_ALLOC = false;
static final boolean SHOW_TRANSACTIONS = false;
static final boolean HIDE_STACK_CRAWLS = true;
@@ -408,6 +407,7 @@
boolean mSafeMode;
boolean mDisplayEnabled = false;
boolean mSystemBooted = false;
+ boolean mForceDisplayEnabled = false;
boolean mShowingBootMessages = false;
int mInitialDisplayWidth = 0;
int mInitialDisplayHeight = 0;
@@ -2189,7 +2189,7 @@
// to hold off on removing the window until the animation is done.
// If the display is frozen, just remove immediately, since the
// animation wouldn't be seen.
- if (win.mSurface != null && !mDisplayFrozen && mPolicy.isScreenOn()) {
+ if (win.mSurface != null && !mDisplayFrozen && mDisplayEnabled && mPolicy.isScreenOn()) {
// If we are not currently running the exit animation, we
// need to see about starting one.
if (wasVisible=win.isWinVisibleLw()) {
@@ -2536,6 +2536,12 @@
win.mRelayoutCalled = true;
final int oldVisibility = win.mViewVisibility;
win.mViewVisibility = viewVisibility;
+ if (DEBUG_SCREEN_ON) {
+ RuntimeException stack = new RuntimeException();
+ stack.fillInStackTrace();
+ Slog.i(TAG, "Relayout " + win + ": oldVis=" + oldVisibility
+ + " newVis=" + viewVisibility, stack);
+ }
if (viewVisibility == View.VISIBLE &&
(win.mAppToken == null || !win.mAppToken.clientHidden)) {
displayed = !win.isVisibleLw();
@@ -2556,7 +2562,7 @@
if (displayed) {
if (win.mSurface != null && !win.mDrawPending
&& !win.mCommitDrawPending && !mDisplayFrozen
- && mPolicy.isScreenOn()) {
+ && mDisplayEnabled && mPolicy.isScreenOn()) {
applyEnterAnimationLocked(win);
}
if ((win.mAttrs.flags
@@ -2849,7 +2855,7 @@
// frozen, there is no reason to animate and it can cause strange
// artifacts when we unfreeze the display if some different animation
// is running.
- if (!mDisplayFrozen && mPolicy.isScreenOn()) {
+ if (!mDisplayFrozen && mDisplayEnabled && mPolicy.isScreenOn()) {
int anim = mPolicy.selectAnimationLw(win, transit);
int attr = -1;
Animation a = null;
@@ -2935,7 +2941,7 @@
// frozen, there is no reason to animate and it can cause strange
// artifacts when we unfreeze the display if some different animation
// is running.
- if (!mDisplayFrozen && mPolicy.isScreenOn()) {
+ if (!mDisplayFrozen && mDisplayEnabled && mPolicy.isScreenOn()) {
Animation a;
if (mNextAppTransitionPackage != null) {
a = loadAnimation(mNextAppTransitionPackage, enter ?
@@ -3501,7 +3507,7 @@
if (DEBUG_APP_TRANSITIONS) Slog.v(
TAG, "Prepare app transition: transit=" + transit
+ " mNextAppTransition=" + mNextAppTransition);
- if (!mDisplayFrozen && mPolicy.isScreenOn()) {
+ if (!mDisplayFrozen && mDisplayEnabled && mPolicy.isScreenOn()) {
if (mNextAppTransition == WindowManagerPolicy.TRANSIT_UNSET
|| mNextAppTransition == WindowManagerPolicy.TRANSIT_NONE) {
mNextAppTransition = transit;
@@ -3585,7 +3591,7 @@
// If the display is frozen, we won't do anything until the
// actual window is displayed so there is no reason to put in
// the starting window.
- if (mDisplayFrozen || !mPolicy.isScreenOn()) {
+ if (mDisplayFrozen || !mDisplayEnabled || !mPolicy.isScreenOn()) {
return;
}
@@ -3867,7 +3873,7 @@
// If we are preparing an app transition, then delay changing
// the visibility of this token until we execute that transition.
- if (!mDisplayFrozen && mPolicy.isScreenOn()
+ if (!mDisplayFrozen && mDisplayEnabled && mPolicy.isScreenOn()
&& mNextAppTransition != WindowManagerPolicy.TRANSIT_UNSET) {
// Already in requested state, don't do anything more.
if (wtoken.hiddenRequested != visible) {
@@ -4688,6 +4694,10 @@
}
mSystemBooted = true;
hideBootMessagesLocked();
+ // If the screen still doesn't come up after 30 seconds, give
+ // up and turn it on.
+ Message msg = mH.obtainMessage(H.BOOT_TIMEOUT);
+ mH.sendMessageDelayed(msg, 30*1000);
}
performEnableScreen();
@@ -4703,6 +4713,17 @@
mH.sendMessage(mH.obtainMessage(H.ENABLE_SCREEN));
}
+ public void performBootTimeout() {
+ synchronized(mWindowMap) {
+ if (mDisplayEnabled) {
+ return;
+ }
+ Slog.w(TAG, "***** BOOT TIMEOUT: forcing display enabled");
+ mForceDisplayEnabled = true;
+ }
+ performEnableScreen();
+ }
+
public void performEnableScreen() {
synchronized(mWindowMap) {
if (mDisplayEnabled) {
@@ -4712,19 +4733,55 @@
return;
}
- // Don't enable the screen until all existing windows
- // have been drawn.
- final int N = mWindows.size();
- for (int i=0; i<N; i++) {
- WindowState w = mWindows.get(i);
- if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
+ if (!mForceDisplayEnabled) {
+ // Don't enable the screen until all existing windows
+ // have been drawn.
+ boolean haveBootMsg = false;
+ boolean haveApp = false;
+ boolean haveWallpaper = false;
+ boolean haveKeyguard = false;
+ final int N = mWindows.size();
+ for (int i=0; i<N; i++) {
+ WindowState w = mWindows.get(i);
+ if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
+ return;
+ }
+ if (w.isDrawnLw()) {
+ if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_BOOT_PROGRESS) {
+ haveBootMsg = true;
+ } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_APPLICATION) {
+ haveApp = true;
+ } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER) {
+ haveWallpaper = true;
+ } else if (w.mAttrs.type == WindowManager.LayoutParams.TYPE_KEYGUARD) {
+ haveKeyguard = true;
+ }
+ }
+ }
+
+ if (DEBUG_SCREEN_ON) {
+ Slog.i(TAG, "******** booted=" + mSystemBooted + " msg=" + mShowingBootMessages
+ + " haveBoot=" + haveBootMsg + " haveApp=" + haveApp
+ + " haveWall=" + haveWallpaper + " haveKeyguard=" + haveKeyguard);
+ }
+
+ // If we are turning on the screen to show the boot message,
+ // don't do it until the boot message is actually displayed.
+ if (!mSystemBooted && !haveBootMsg) {
+ return;
+ }
+
+ // If we are turning on the screen after the boot is completed
+ // normally, don't do so until we have the application and
+ // wallpaper.
+ if (mSystemBooted && ((!haveApp && !haveKeyguard) || !haveWallpaper)) {
return;
}
}
mDisplayEnabled = true;
+ if (DEBUG_SCREEN_ON) Slog.i(TAG, "******************** ENABLING SCREEN!");
if (false) {
- Slog.i(TAG, "ENABLING SCREEN!");
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
this.dump(null, pw, null);
@@ -6239,6 +6296,7 @@
public static final int DRAG_START_TIMEOUT = 20;
public static final int DRAG_END_TIMEOUT = 21;
public static final int REPORT_HARD_KEYBOARD_STATUS_CHANGE = 22;
+ public static final int BOOT_TIMEOUT = 23;
private Session mLastReportedHold;
@@ -6549,6 +6607,11 @@
break;
}
+ case BOOT_TIMEOUT: {
+ performBootTimeout();
+ break;
+ }
+
case APP_FREEZE_TIMEOUT: {
synchronized (mWindowMap) {
Slog.w(TAG, "App freeze timeout expired.");
@@ -8300,7 +8363,7 @@
if (mDimAnimator != null && mDimAnimator.mDimShown) {
animating |= mDimAnimator.updateSurface(dimming, currentTime,
- mDisplayFrozen || !mPolicy.isScreenOn());
+ mDisplayFrozen || !mDisplayEnabled || !mPolicy.isScreenOn());
}
if (!blurring && mBlurShown) {
@@ -8498,12 +8561,44 @@
mH.sendEmptyMessage(H.SEND_NEW_CONFIGURATION);
}
}
-
+
+ mWindowMap.notifyAll();
+
// Check to see if we are now in a state where the screen should
// be enabled, because the window obscured flags have changed.
enableScreenIfNeededLocked();
}
-
+
+ public void waitForAllDrawn() {
+ synchronized (mWindowMap) {
+ while (true) {
+ final int N = mWindows.size();
+ boolean okay = true;
+ for (int i=0; i<N && okay; i++) {
+ WindowState w = mWindows.get(i);
+ if (DEBUG_SCREEN_ON) {
+ Slog.i(TAG, "Window " + w + " vis=" + w.isVisibleLw()
+ + " obscured=" + w.mObscured + " drawn=" + w.isDrawnLw());
+ }
+ if (w.isVisibleLw() && !w.mObscured && !w.isDrawnLw()) {
+ if (DEBUG_SCREEN_ON) {
+ Slog.i(TAG, "Window not yet drawn: " + w);
+ }
+ okay = false;
+ break;
+ }
+ }
+ if (okay) {
+ return;
+ }
+ try {
+ mWindowMap.wait();
+ } catch (InterruptedException e) {
+ }
+ }
+ }
+ }
+
/**
* Must be called with the main window manager lock held.
*/