Loading core/java/android/view/WindowManagerPolicy.java +7 −2 Original line number Diff line number Diff line Loading @@ -955,14 +955,19 @@ public interface WindowManagerPolicy { */ public void screenTurningOn(ScreenOnListener screenOnListener); /** * Called when the device has turned the screen off. */ public void screenTurnedOff(); public interface ScreenOnListener { void onScreenOn(); } /** * Return whether the system is awake. * Return whether the default display is on and not blocked by a black surface. */ public boolean isAwake(); public boolean isScreenOn(); /** * Tell the policy that the lid switch has changed state. Loading policy/src/com/android/internal/policy/impl/PhoneWindowManager.java +128 −100 Original line number Diff line number Diff line Loading @@ -199,7 +199,7 @@ public class PhoneWindowManager implements WindowManagerPolicy { */ private WindowState mKeyguardScrim; private boolean mKeyguardHidden; private boolean mKeyguardDrawn; private boolean mKeyguardDrawnOnce; /* Table of Application Launch keys. Maps from key codes to intent categories. * Loading Loading @@ -284,10 +284,6 @@ public class PhoneWindowManager implements WindowManagerPolicy { boolean mBootMessageNeedsHiding; KeyguardServiceDelegate mKeyguardDelegate; // The following are only accessed on the mHandler thread. boolean mKeyguardDrawComplete; boolean mWindowManagerDrawComplete; ScreenOnListener mScreenOnListener; final Runnable mWindowManagerDrawCallback = new Runnable() { @Override public void run() { Loading Loading @@ -351,8 +347,12 @@ public class PhoneWindowManager implements WindowManagerPolicy { boolean mLidControlsSleep; int mShortPressOnPowerBehavior = -1; int mLongPressOnPowerBehavior = -1; boolean mAwakeEarly = false; boolean mAwakeFully = false; boolean mAwake; boolean mScreenOnEarly; boolean mScreenOnFully; ScreenOnListener mScreenOnListener; boolean mKeyguardDrawComplete; boolean mWindowManagerDrawComplete; boolean mOrientationSensorEnabled = false; int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; boolean mHasSoftInput = false; Loading Loading @@ -543,12 +543,10 @@ public class PhoneWindowManager implements WindowManagerPolicy { private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5; private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6; private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7; private static final int MSG_WAKING_UP = 8; private static final int MSG_DISPATCH_SHOW_RECENTS = 9; private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10; private static final int MSG_HIDE_BOOT_MESSAGE = 11; private static final int MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK = 12; private static final int MSG_SCREEN_TURNING_ON = 13; private class PolicyHandler extends Handler { @Override Loading Loading @@ -584,18 +582,12 @@ public class PhoneWindowManager implements WindowManagerPolicy { if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete"); finishWindowsDrawn(); break; case MSG_WAKING_UP: handleWakingUp(); break; case MSG_HIDE_BOOT_MESSAGE: handleHideBootMessage(); break; case MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK: launchVoiceAssistWithWakeLock(msg.arg1 != 0); break; case MSG_SCREEN_TURNING_ON: handleScreenTurningOn((ScreenOnListener)msg.obj); break; } } } Loading Loading @@ -766,11 +758,11 @@ public class PhoneWindowManager implements WindowManagerPolicy { } //Could have been invoked due to screen turning on or off or //change of the currently visible window's orientation if (localLOGV) Slog.v(TAG, "Screen status="+mAwakeEarly+ ", current orientation="+mCurrentAppOrientation+ ", SensorEnabled="+mOrientationSensorEnabled); if (localLOGV) Slog.v(TAG, "mScreenOnEarly=" + mScreenOnEarly + ", mAwake=" + mAwake + ", mCurrentAppOrientation=" + mCurrentAppOrientation + ", mOrientationSensorEnabled=" + mOrientationSensorEnabled); boolean disable = true; if (mAwakeEarly) { if (mScreenOnEarly && mAwake) { if (needSensorRunningLp()) { disable = false; //enable listener if not already enabled Loading Loading @@ -1332,7 +1324,7 @@ public class PhoneWindowManager implements WindowManagerPolicy { } private boolean shouldEnableWakeGestureLp() { return mWakeGestureEnabledSetting && !mAwakeEarly return mWakeGestureEnabledSetting && !mAwake && (!mLidControlsSleep || mLidState != LID_CLOSED) && mWakeGestureListener.isSupported(); } Loading Loading @@ -4728,45 +4720,51 @@ public class PhoneWindowManager implements WindowManagerPolicy { } } // Called on the PowerManager's Notifier thread. @Override public void goingToSleep(int why) { EventLog.writeEvent(70000, 0); if (DEBUG_WAKEUP) Slog.i(TAG, "Going to sleep..."); // We must get this work done here because the power manager will drop // the wake lock and let the system suspend once this function returns. synchronized (mLock) { mAwakeEarly = false; mAwakeFully = false; } if (mKeyguardDelegate != null) { mKeyguardDelegate.onScreenTurnedOff(why); } synchronized (mLock) { mAwake = false; mKeyguardDrawComplete = false; updateWakeGestureListenerLp(); updateOrientationListenerLp(); updateLockScreenTimeout(); } if (mKeyguardDelegate != null) { mKeyguardDelegate.onScreenTurnedOff(why); } } // Called on the PowerManager's Notifier thread. @Override public void wakingUp() { EventLog.writeEvent(70000, 1); if (DEBUG_WAKEUP) Slog.i(TAG, "Waking up..."); mHandler.obtainMessage(MSG_WAKING_UP).sendToTarget(); } // Called on the mHandler thread. private void handleWakingUp() { // Since goToSleep performs these functions synchronously, we must // do the same here. We cannot post this work to a handler because // that might cause it to become reordered with respect to what // may happen in a future call to goToSleep. synchronized (mLock) { mAwakeEarly = true; mAwake = true; mKeyguardDrawComplete = false; if (mKeyguardDelegate != null) { mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT); mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000); } updateWakeGestureListenerLp(); updateOrientationListenerLp(); updateLockScreenTimeout(); } mKeyguardDrawComplete = false; mWindowManagerDrawComplete = false; // wait for later call to screenTurningOn if (mKeyguardDelegate != null) { mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT); mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000); mKeyguardDelegate.onScreenTurnedOn(mKeyguardDelegateCallback); // ... eventually calls finishKeyguardDrawn } else { Loading @@ -4775,94 +4773,130 @@ public class PhoneWindowManager implements WindowManagerPolicy { } } // Called on the mHandler thread. private void finishKeyguardDrawn() { if (!mKeyguardDrawComplete) { synchronized (mLock) { if (!mAwake || mKeyguardDrawComplete) { return; // spurious } mKeyguardDrawComplete = true; if (mKeyguardDelegate != null) { mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT); } } finishScreenTurningOn(); } // Called on the DisplayManager's DisplayPowerController thread. @Override public void screenTurnedOff() { if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turned off..."); synchronized (mLock) { mScreenOnEarly = false; mScreenOnFully = false; mWindowManagerDrawComplete = false; mScreenOnListener = null; updateOrientationListenerLp(); } } // Called on the DisplayManager's DisplayPowerController thread. @Override public void screenTurningOn(final ScreenOnListener screenOnListener) { EventLog.writeEvent(70000, 1); if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on..."); mHandler.obtainMessage(MSG_SCREEN_TURNING_ON, screenOnListener).sendToTarget(); } // Called on the mHandler thread. private void handleScreenTurningOn(ScreenOnListener screenOnListener) { synchronized (mLock) { mScreenOnEarly = true; mScreenOnFully = false; mWindowManagerDrawComplete = false; mScreenOnListener = screenOnListener; updateOrientationListenerLp(); } mWindowManagerDrawComplete = false; mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback, WAITING_FOR_DRAWN_TIMEOUT); // ... eventually calls finishWindowsDrawn } // Called on the mHandler thread. private void finishWindowsDrawn() { if (!mWindowManagerDrawComplete) { synchronized (mLock) { if (!mScreenOnEarly || mWindowManagerDrawComplete) { return; // spurious } mWindowManagerDrawComplete = true; finishScreenTurningOn(); } finishScreenTurningOn(); } // Called on the mHandler thread. private void finishScreenTurningOn() { if (DEBUG_WAKEUP) Slog.d(TAG, "finishScreenTurningOn: mAwakeEarly=" + mAwakeEarly + " mKeyguardDrawComplete=" + mKeyguardDrawComplete + " mWindowManagerDrawComplete=" + mWindowManagerDrawComplete); boolean awake; final ScreenOnListener listener; final boolean enableScreen; synchronized (mLock) { if ((mAwakeEarly && !mKeyguardDrawComplete) || !mWindowManagerDrawComplete) { return; } if (DEBUG_WAKEUP) Slog.d(TAG, "finishScreenTurningOn: mAwake=" + mAwake + ", mScreenOnEarly=" + mScreenOnEarly + ", mScreenOnFully=" + mScreenOnFully + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete); if (mAwakeEarly) { mAwakeFully = true; } awake = mAwakeFully; if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete || (mAwake && !mKeyguardDrawComplete)) { return; // spurious or not ready yet } if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on..."); if (mScreenOnListener != null) { mScreenOnListener.onScreenOn(); listener = mScreenOnListener; mScreenOnListener = null; } if (awake) { setKeyguardDrawnFirstTime(); mScreenOnFully = true; // Remember the first time we draw the keyguard so we know when we're done with // the main part of booting and can enable the screen and hide boot messages. if (!mKeyguardDrawnOnce && mAwake) { mKeyguardDrawnOnce = true; enableScreen = true; if (mBootMessageNeedsHiding) { handleHideBootMessage(); mBootMessageNeedsHiding = false; hideBootMessages(); } } else { enableScreen = false; } } private void handleHideBootMessage() { if (mBootMsgDialog == null) { if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: boot message not up"); return; if (listener != null) { listener.onScreenOn(); } if (enableScreen) { try { mWindowManager.enableScreenIfNeeded(); } catch (RemoteException unhandled) { } if (!mKeyguardDrawComplete || !mWindowManagerDrawComplete) { if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: deferring until keyguard ready"); } } private void handleHideBootMessage() { synchronized (mLock) { if (!mKeyguardDrawnOnce) { mBootMessageNeedsHiding = true; return; return; // keyguard hasn't drawn the first time yet, not done booting } } if (mBootMsgDialog != null) { if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing"); mBootMsgDialog.dismiss(); mBootMsgDialog = null; } } @Override public boolean isAwake() { return mAwakeFully; public boolean isScreenOn() { return mScreenOnFully; } /** {@inheritDoc} */ Loading Loading @@ -4936,20 +4970,10 @@ public class PhoneWindowManager implements WindowManagerPolicy { } } private void setKeyguardDrawnFirstTime() { synchronized (mLock) { mKeyguardDrawn = true; } try { mWindowManager.enableScreenIfNeeded(); } catch (RemoteException unhandled) { } } @Override public boolean isKeyguardDrawnLw() { synchronized (mLock) { return mKeyguardDrawn; return mKeyguardDrawnOnce; } } Loading Loading @@ -5380,7 +5404,7 @@ public class PhoneWindowManager implements WindowManagerPolicy { private void updateLockScreenTimeout() { synchronized (mScreenLockTimeout) { boolean enable = (mAllowLockscreenWhenOn && mAwakeEarly && boolean enable = (mAllowLockscreenWhenOn && mAwake && mKeyguardDelegate != null && mKeyguardDelegate.isSecure()); if (mLockScreenTimerActive != enable) { if (enable) { Loading Loading @@ -5918,9 +5942,13 @@ public class PhoneWindowManager implements WindowManagerPolicy { pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior); pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior); pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput); pw.print(prefix); pw.print("mAwakeEarly="); pw.print(mAwakeEarly); pw.print(" mAwakeFully="); pw.print(mAwakeFully); pw.print(" mOrientationSensorEnabled="); pw.println(mOrientationSensorEnabled); pw.print(prefix); pw.print("mAwake="); pw.println(mAwake); pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly); pw.print(" mScreenOnFully="); pw.println(mScreenOnFully); pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete); pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete); pw.print(prefix); pw.print("mOrientationSensorEnabled="); pw.println(mOrientationSensorEnabled); pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft); pw.print(","); pw.print(mOverscanScreenTop); pw.print(") "); pw.print(mOverscanScreenWidth); Loading services/core/java/com/android/server/display/DisplayPowerController.java +90 −29 File changed.Preview size limit exceeded, changes collapsed. Show changes services/core/java/com/android/server/power/Notifier.java +1 −42 Original line number Diff line number Diff line Loading @@ -84,7 +84,6 @@ final class Notifier { private final IBatteryStats mBatteryStats; private final IAppOpsService mAppOps; private final SuspendBlocker mSuspendBlocker; private final ScreenOnBlocker mScreenOnBlocker; private final WindowManagerPolicy mPolicy; private final ActivityManagerInternal mActivityManagerInternal; private final InputManagerInternal mInputManagerInternal; Loading @@ -110,18 +109,13 @@ final class Notifier { // True if a user activity message should be sent. private boolean mUserActivityPending; // The currently active screen on listener. This field is non-null whenever the // ScreenOnBlocker has been acquired and we are awaiting a callback to release it. private ScreenOnUnblocker mPendingScreenOnUnblocker; public Notifier(Looper looper, Context context, IBatteryStats batteryStats, IAppOpsService appOps, SuspendBlocker suspendBlocker, ScreenOnBlocker screenOnBlocker, IAppOpsService appOps, SuspendBlocker suspendBlocker, WindowManagerPolicy policy) { mContext = context; mBatteryStats = batteryStats; mAppOps = appOps; mSuspendBlocker = suspendBlocker; mScreenOnBlocker = screenOnBlocker; mPolicy = policy; mActivityManagerInternal = LocalServices.getService(ActivityManagerInternal.class); mInputManagerInternal = LocalServices.getService(InputManagerInternal.class); Loading Loading @@ -332,21 +326,6 @@ final class Notifier { } } /** * Notifies that screen is about to be turned on (any state other than off). */ public void onScreenTurningOn() { synchronized (mLock) { final ScreenOnUnblocker unblocker = blockScreenOnLocked(); mHandler.post(new Runnable() { @Override public void run() { mPolicy.screenTurningOn(unblocker); } }); } } /** * Called when there has been user activity. */ Loading Loading @@ -470,26 +449,6 @@ final class Notifier { } } private ScreenOnUnblocker blockScreenOnLocked() { if (mPendingScreenOnUnblocker == null) { mScreenOnBlocker.acquire(); } mPendingScreenOnUnblocker = new ScreenOnUnblocker(); return mPendingScreenOnUnblocker; } private final class ScreenOnUnblocker implements WindowManagerPolicy.ScreenOnListener { @Override public void onScreenOn() { synchronized (mLock) { if (mPendingScreenOnUnblocker == this) { mPendingScreenOnUnblocker = null; mScreenOnBlocker.release(); } } } } private final BroadcastReceiver mWakeUpBroadcastDone = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { Loading services/core/java/com/android/server/power/PowerManagerService.java +3 −93 Original line number Diff line number Diff line Loading @@ -88,8 +88,6 @@ public final class PowerManagerService extends SystemService private static final int MSG_USER_ACTIVITY_TIMEOUT = 1; // Message: Sent when the device enters or exits a dreaming or dozing state. private static final int MSG_SANDMAN = 2; // Message: Sent when the screen on blocker is released. private static final int MSG_SCREEN_ON_BLOCKER_RELEASED = 3; // Dirty bit: mWakeLocks changed private static final int DIRTY_WAKE_LOCKS = 1 << 0; Loading @@ -111,10 +109,8 @@ public final class PowerManagerService extends SystemService private static final int DIRTY_BATTERY_STATE = 1 << 8; // Dirty bit: proximity state changed private static final int DIRTY_PROXIMITY_POSITIVE = 1 << 9; // Dirty bit: screen on blocker state became held or unheld private static final int DIRTY_SCREEN_ON_BLOCKER_RELEASED = 1 << 10; // Dirty bit: dock state changed private static final int DIRTY_DOCK_STATE = 1 << 11; private static final int DIRTY_DOCK_STATE = 1 << 10; // Wakefulness: The device is asleep and can only be awoken by a call to wakeUp(). // The screen should be off or in the process of being turned off by the display controller. Loading Loading @@ -244,10 +240,6 @@ public final class PowerManagerService extends SystemService // True if the display suspend blocker has been acquired. private boolean mHoldingDisplaySuspendBlocker; // The screen on blocker used to keep the screen from turning on while the lock // screen is coming up. private final ScreenOnBlockerImpl mScreenOnBlocker; // True if systemReady() has been called. private boolean mSystemReady; Loading Loading @@ -451,7 +443,6 @@ public final class PowerManagerService extends SystemService mHalAutoSuspendModeEnabled = false; mHalInteractiveModeEnabled = true; mScreenOnBlocker = new ScreenOnBlockerImpl(); mWakefulness = WAKEFULNESS_AWAKE; mInteractive = true; Loading Loading @@ -505,7 +496,7 @@ public final class PowerManagerService extends SystemService mBatteryStats = BatteryStatsService.getService(); mNotifier = new Notifier(Looper.getMainLooper(), mContext, mBatteryStats, mAppOps, createSuspendBlockerLocked("PowerManagerService.Broadcasts"), mScreenOnBlocker, mPolicy); mPolicy); mWirelessChargerDetector = new WirelessChargerDetector(sensorManager, createSuspendBlockerLocked("PowerManagerService.WirelessChargerDetector"), Loading Loading @@ -1745,13 +1736,6 @@ public final class PowerManagerService extends SystemService return true; } private void handleScreenOnBlockerReleased() { synchronized (mLock) { mDirty |= DIRTY_SCREEN_ON_BLOCKER_RELEASED; updatePowerStateLocked(); } } /** * Updates the display power state asynchronously. * When the update is finished, mDisplayReady will be set to true. The display Loading @@ -1766,8 +1750,7 @@ public final class PowerManagerService extends SystemService final boolean oldDisplayReady = mDisplayReady; if ((dirty & (DIRTY_WAKE_LOCKS | DIRTY_USER_ACTIVITY | DIRTY_WAKEFULNESS | DIRTY_ACTUAL_DISPLAY_POWER_STATE_UPDATED | DIRTY_BOOT_COMPLETED | DIRTY_SETTINGS | DIRTY_SCREEN_ON_BLOCKER_RELEASED)) != 0) { boolean wasBlockerNeeded = isScreenOnBlockerNeededLocked(mDisplayPowerRequest); | DIRTY_SETTINGS)) != 0) { mDisplayPowerRequest.policy = getDesiredScreenPolicyLocked(); int screenBrightness = mScreenBrightnessSettingDefault; Loading Loading @@ -1815,12 +1798,6 @@ public final class PowerManagerService extends SystemService mDisplayPowerRequest.dozeScreenBrightness = PowerManager.BRIGHTNESS_DEFAULT; } if (!wasBlockerNeeded && isScreenOnBlockerNeededLocked(mDisplayPowerRequest) && !mScreenOnBlocker.isHeld()) { mNotifier.onScreenTurningOn(); } mDisplayPowerRequest.blockScreenOn = mScreenOnBlocker.isHeld(); mDisplayReady = mDisplayManagerInternal.requestPowerState(mDisplayPowerRequest, mRequestWaitForNegativeProximity); mRequestWaitForNegativeProximity = false; Loading @@ -1837,17 +1814,6 @@ public final class PowerManagerService extends SystemService return mDisplayReady && !oldDisplayReady; } private static boolean isScreenOnBlockerNeededLocked(DisplayPowerRequest req) { switch (req.policy) { case DisplayPowerRequest.POLICY_OFF: return false; case DisplayPowerRequest.POLICY_DOZE: return req.dozeScreenState != Display.STATE_OFF; default: return true; } } private static boolean isValidBrightness(int value) { return value >= 0 && value <= 255; } Loading Loading @@ -2419,9 +2385,6 @@ public final class PowerManagerService extends SystemService pw.println(" " + sb); } pw.println(); pw.println("Screen On Blocker: " + mScreenOnBlocker); pw.println(); pw.println("Display Power: " + mDisplayPowerCallbacks); Loading Loading @@ -2530,9 +2493,6 @@ public final class PowerManagerService extends SystemService case MSG_SANDMAN: handleSandman(); break; case MSG_SCREEN_ON_BLOCKER_RELEASED: handleScreenOnBlockerReleased(); break; } } } Loading Loading @@ -2709,56 +2669,6 @@ public final class PowerManagerService extends SystemService } } private final class ScreenOnBlockerImpl implements ScreenOnBlocker { private static final String TRACE_NAME = "ScreenOnBlocker"; private int mNestCount; public boolean isHeld() { synchronized (this) { return mNestCount != 0; } } @Override public void acquire() { synchronized (this) { mNestCount += 1; if (DEBUG || true) { Slog.d(TAG, "Screen on blocked: mNestCount=" + mNestCount); } if (mNestCount == 1) { Trace.asyncTraceBegin(Trace.TRACE_TAG_POWER, TRACE_NAME, 0); } } } @Override public void release() { synchronized (this) { mNestCount -= 1; if (mNestCount == 0) { if (DEBUG || true) { Slog.d(TAG, "Screen on unblocked: mNestCount=" + mNestCount); } mHandler.sendEmptyMessage(MSG_SCREEN_ON_BLOCKER_RELEASED); Trace.asyncTraceEnd(Trace.TRACE_TAG_POWER, TRACE_NAME, 0); } else if (mNestCount < 0) { Slog.wtf(TAG, "Screen on blocker was released without being acquired!", new Throwable()); mNestCount = 0; } } } @Override public String toString() { synchronized (this) { return "held=" + (mNestCount != 0) + ", mNestCount=" + mNestCount; } } } private final class BinderService extends IPowerManager.Stub { @Override // Binder call public void acquireWakeLockWithUid(IBinder lock, int flags, String tag, Loading Loading
core/java/android/view/WindowManagerPolicy.java +7 −2 Original line number Diff line number Diff line Loading @@ -955,14 +955,19 @@ public interface WindowManagerPolicy { */ public void screenTurningOn(ScreenOnListener screenOnListener); /** * Called when the device has turned the screen off. */ public void screenTurnedOff(); public interface ScreenOnListener { void onScreenOn(); } /** * Return whether the system is awake. * Return whether the default display is on and not blocked by a black surface. */ public boolean isAwake(); public boolean isScreenOn(); /** * Tell the policy that the lid switch has changed state. Loading
policy/src/com/android/internal/policy/impl/PhoneWindowManager.java +128 −100 Original line number Diff line number Diff line Loading @@ -199,7 +199,7 @@ public class PhoneWindowManager implements WindowManagerPolicy { */ private WindowState mKeyguardScrim; private boolean mKeyguardHidden; private boolean mKeyguardDrawn; private boolean mKeyguardDrawnOnce; /* Table of Application Launch keys. Maps from key codes to intent categories. * Loading Loading @@ -284,10 +284,6 @@ public class PhoneWindowManager implements WindowManagerPolicy { boolean mBootMessageNeedsHiding; KeyguardServiceDelegate mKeyguardDelegate; // The following are only accessed on the mHandler thread. boolean mKeyguardDrawComplete; boolean mWindowManagerDrawComplete; ScreenOnListener mScreenOnListener; final Runnable mWindowManagerDrawCallback = new Runnable() { @Override public void run() { Loading Loading @@ -351,8 +347,12 @@ public class PhoneWindowManager implements WindowManagerPolicy { boolean mLidControlsSleep; int mShortPressOnPowerBehavior = -1; int mLongPressOnPowerBehavior = -1; boolean mAwakeEarly = false; boolean mAwakeFully = false; boolean mAwake; boolean mScreenOnEarly; boolean mScreenOnFully; ScreenOnListener mScreenOnListener; boolean mKeyguardDrawComplete; boolean mWindowManagerDrawComplete; boolean mOrientationSensorEnabled = false; int mCurrentAppOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; boolean mHasSoftInput = false; Loading Loading @@ -543,12 +543,10 @@ public class PhoneWindowManager implements WindowManagerPolicy { private static final int MSG_KEYGUARD_DRAWN_COMPLETE = 5; private static final int MSG_KEYGUARD_DRAWN_TIMEOUT = 6; private static final int MSG_WINDOW_MANAGER_DRAWN_COMPLETE = 7; private static final int MSG_WAKING_UP = 8; private static final int MSG_DISPATCH_SHOW_RECENTS = 9; private static final int MSG_DISPATCH_SHOW_GLOBAL_ACTIONS = 10; private static final int MSG_HIDE_BOOT_MESSAGE = 11; private static final int MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK = 12; private static final int MSG_SCREEN_TURNING_ON = 13; private class PolicyHandler extends Handler { @Override Loading Loading @@ -584,18 +582,12 @@ public class PhoneWindowManager implements WindowManagerPolicy { if (DEBUG_WAKEUP) Slog.w(TAG, "Setting mWindowManagerDrawComplete"); finishWindowsDrawn(); break; case MSG_WAKING_UP: handleWakingUp(); break; case MSG_HIDE_BOOT_MESSAGE: handleHideBootMessage(); break; case MSG_LAUNCH_VOICE_ASSIST_WITH_WAKE_LOCK: launchVoiceAssistWithWakeLock(msg.arg1 != 0); break; case MSG_SCREEN_TURNING_ON: handleScreenTurningOn((ScreenOnListener)msg.obj); break; } } } Loading Loading @@ -766,11 +758,11 @@ public class PhoneWindowManager implements WindowManagerPolicy { } //Could have been invoked due to screen turning on or off or //change of the currently visible window's orientation if (localLOGV) Slog.v(TAG, "Screen status="+mAwakeEarly+ ", current orientation="+mCurrentAppOrientation+ ", SensorEnabled="+mOrientationSensorEnabled); if (localLOGV) Slog.v(TAG, "mScreenOnEarly=" + mScreenOnEarly + ", mAwake=" + mAwake + ", mCurrentAppOrientation=" + mCurrentAppOrientation + ", mOrientationSensorEnabled=" + mOrientationSensorEnabled); boolean disable = true; if (mAwakeEarly) { if (mScreenOnEarly && mAwake) { if (needSensorRunningLp()) { disable = false; //enable listener if not already enabled Loading Loading @@ -1332,7 +1324,7 @@ public class PhoneWindowManager implements WindowManagerPolicy { } private boolean shouldEnableWakeGestureLp() { return mWakeGestureEnabledSetting && !mAwakeEarly return mWakeGestureEnabledSetting && !mAwake && (!mLidControlsSleep || mLidState != LID_CLOSED) && mWakeGestureListener.isSupported(); } Loading Loading @@ -4728,45 +4720,51 @@ public class PhoneWindowManager implements WindowManagerPolicy { } } // Called on the PowerManager's Notifier thread. @Override public void goingToSleep(int why) { EventLog.writeEvent(70000, 0); if (DEBUG_WAKEUP) Slog.i(TAG, "Going to sleep..."); // We must get this work done here because the power manager will drop // the wake lock and let the system suspend once this function returns. synchronized (mLock) { mAwakeEarly = false; mAwakeFully = false; } if (mKeyguardDelegate != null) { mKeyguardDelegate.onScreenTurnedOff(why); } synchronized (mLock) { mAwake = false; mKeyguardDrawComplete = false; updateWakeGestureListenerLp(); updateOrientationListenerLp(); updateLockScreenTimeout(); } if (mKeyguardDelegate != null) { mKeyguardDelegate.onScreenTurnedOff(why); } } // Called on the PowerManager's Notifier thread. @Override public void wakingUp() { EventLog.writeEvent(70000, 1); if (DEBUG_WAKEUP) Slog.i(TAG, "Waking up..."); mHandler.obtainMessage(MSG_WAKING_UP).sendToTarget(); } // Called on the mHandler thread. private void handleWakingUp() { // Since goToSleep performs these functions synchronously, we must // do the same here. We cannot post this work to a handler because // that might cause it to become reordered with respect to what // may happen in a future call to goToSleep. synchronized (mLock) { mAwakeEarly = true; mAwake = true; mKeyguardDrawComplete = false; if (mKeyguardDelegate != null) { mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT); mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000); } updateWakeGestureListenerLp(); updateOrientationListenerLp(); updateLockScreenTimeout(); } mKeyguardDrawComplete = false; mWindowManagerDrawComplete = false; // wait for later call to screenTurningOn if (mKeyguardDelegate != null) { mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT); mHandler.sendEmptyMessageDelayed(MSG_KEYGUARD_DRAWN_TIMEOUT, 1000); mKeyguardDelegate.onScreenTurnedOn(mKeyguardDelegateCallback); // ... eventually calls finishKeyguardDrawn } else { Loading @@ -4775,94 +4773,130 @@ public class PhoneWindowManager implements WindowManagerPolicy { } } // Called on the mHandler thread. private void finishKeyguardDrawn() { if (!mKeyguardDrawComplete) { synchronized (mLock) { if (!mAwake || mKeyguardDrawComplete) { return; // spurious } mKeyguardDrawComplete = true; if (mKeyguardDelegate != null) { mHandler.removeMessages(MSG_KEYGUARD_DRAWN_TIMEOUT); } } finishScreenTurningOn(); } // Called on the DisplayManager's DisplayPowerController thread. @Override public void screenTurnedOff() { if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turned off..."); synchronized (mLock) { mScreenOnEarly = false; mScreenOnFully = false; mWindowManagerDrawComplete = false; mScreenOnListener = null; updateOrientationListenerLp(); } } // Called on the DisplayManager's DisplayPowerController thread. @Override public void screenTurningOn(final ScreenOnListener screenOnListener) { EventLog.writeEvent(70000, 1); if (DEBUG_WAKEUP) Slog.i(TAG, "Screen turning on..."); mHandler.obtainMessage(MSG_SCREEN_TURNING_ON, screenOnListener).sendToTarget(); } // Called on the mHandler thread. private void handleScreenTurningOn(ScreenOnListener screenOnListener) { synchronized (mLock) { mScreenOnEarly = true; mScreenOnFully = false; mWindowManagerDrawComplete = false; mScreenOnListener = screenOnListener; updateOrientationListenerLp(); } mWindowManagerDrawComplete = false; mWindowManagerInternal.waitForAllWindowsDrawn(mWindowManagerDrawCallback, WAITING_FOR_DRAWN_TIMEOUT); // ... eventually calls finishWindowsDrawn } // Called on the mHandler thread. private void finishWindowsDrawn() { if (!mWindowManagerDrawComplete) { synchronized (mLock) { if (!mScreenOnEarly || mWindowManagerDrawComplete) { return; // spurious } mWindowManagerDrawComplete = true; finishScreenTurningOn(); } finishScreenTurningOn(); } // Called on the mHandler thread. private void finishScreenTurningOn() { if (DEBUG_WAKEUP) Slog.d(TAG, "finishScreenTurningOn: mAwakeEarly=" + mAwakeEarly + " mKeyguardDrawComplete=" + mKeyguardDrawComplete + " mWindowManagerDrawComplete=" + mWindowManagerDrawComplete); boolean awake; final ScreenOnListener listener; final boolean enableScreen; synchronized (mLock) { if ((mAwakeEarly && !mKeyguardDrawComplete) || !mWindowManagerDrawComplete) { return; } if (DEBUG_WAKEUP) Slog.d(TAG, "finishScreenTurningOn: mAwake=" + mAwake + ", mScreenOnEarly=" + mScreenOnEarly + ", mScreenOnFully=" + mScreenOnFully + ", mKeyguardDrawComplete=" + mKeyguardDrawComplete + ", mWindowManagerDrawComplete=" + mWindowManagerDrawComplete); if (mAwakeEarly) { mAwakeFully = true; } awake = mAwakeFully; if (mScreenOnFully || !mScreenOnEarly || !mWindowManagerDrawComplete || (mAwake && !mKeyguardDrawComplete)) { return; // spurious or not ready yet } if (DEBUG_WAKEUP) Slog.i(TAG, "Finished screen turning on..."); if (mScreenOnListener != null) { mScreenOnListener.onScreenOn(); listener = mScreenOnListener; mScreenOnListener = null; } if (awake) { setKeyguardDrawnFirstTime(); mScreenOnFully = true; // Remember the first time we draw the keyguard so we know when we're done with // the main part of booting and can enable the screen and hide boot messages. if (!mKeyguardDrawnOnce && mAwake) { mKeyguardDrawnOnce = true; enableScreen = true; if (mBootMessageNeedsHiding) { handleHideBootMessage(); mBootMessageNeedsHiding = false; hideBootMessages(); } } else { enableScreen = false; } } private void handleHideBootMessage() { if (mBootMsgDialog == null) { if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: boot message not up"); return; if (listener != null) { listener.onScreenOn(); } if (enableScreen) { try { mWindowManager.enableScreenIfNeeded(); } catch (RemoteException unhandled) { } if (!mKeyguardDrawComplete || !mWindowManagerDrawComplete) { if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: deferring until keyguard ready"); } } private void handleHideBootMessage() { synchronized (mLock) { if (!mKeyguardDrawnOnce) { mBootMessageNeedsHiding = true; return; return; // keyguard hasn't drawn the first time yet, not done booting } } if (mBootMsgDialog != null) { if (DEBUG_WAKEUP) Slog.d(TAG, "handleHideBootMessage: dismissing"); mBootMsgDialog.dismiss(); mBootMsgDialog = null; } } @Override public boolean isAwake() { return mAwakeFully; public boolean isScreenOn() { return mScreenOnFully; } /** {@inheritDoc} */ Loading Loading @@ -4936,20 +4970,10 @@ public class PhoneWindowManager implements WindowManagerPolicy { } } private void setKeyguardDrawnFirstTime() { synchronized (mLock) { mKeyguardDrawn = true; } try { mWindowManager.enableScreenIfNeeded(); } catch (RemoteException unhandled) { } } @Override public boolean isKeyguardDrawnLw() { synchronized (mLock) { return mKeyguardDrawn; return mKeyguardDrawnOnce; } } Loading Loading @@ -5380,7 +5404,7 @@ public class PhoneWindowManager implements WindowManagerPolicy { private void updateLockScreenTimeout() { synchronized (mScreenLockTimeout) { boolean enable = (mAllowLockscreenWhenOn && mAwakeEarly && boolean enable = (mAllowLockscreenWhenOn && mAwake && mKeyguardDelegate != null && mKeyguardDelegate.isSecure()); if (mLockScreenTimerActive != enable) { if (enable) { Loading Loading @@ -5918,9 +5942,13 @@ public class PhoneWindowManager implements WindowManagerPolicy { pw.print("mShortPressOnPowerBehavior="); pw.print(mShortPressOnPowerBehavior); pw.print(" mLongPressOnPowerBehavior="); pw.println(mLongPressOnPowerBehavior); pw.print(prefix); pw.print("mHasSoftInput="); pw.println(mHasSoftInput); pw.print(prefix); pw.print("mAwakeEarly="); pw.print(mAwakeEarly); pw.print(" mAwakeFully="); pw.print(mAwakeFully); pw.print(" mOrientationSensorEnabled="); pw.println(mOrientationSensorEnabled); pw.print(prefix); pw.print("mAwake="); pw.println(mAwake); pw.print(prefix); pw.print("mScreenOnEarly="); pw.print(mScreenOnEarly); pw.print(" mScreenOnFully="); pw.println(mScreenOnFully); pw.print(prefix); pw.print("mKeyguardDrawComplete="); pw.print(mKeyguardDrawComplete); pw.print(" mWindowManagerDrawComplete="); pw.println(mWindowManagerDrawComplete); pw.print(prefix); pw.print("mOrientationSensorEnabled="); pw.println(mOrientationSensorEnabled); pw.print(prefix); pw.print("mOverscanScreen=("); pw.print(mOverscanScreenLeft); pw.print(","); pw.print(mOverscanScreenTop); pw.print(") "); pw.print(mOverscanScreenWidth); Loading
services/core/java/com/android/server/display/DisplayPowerController.java +90 −29 File changed.Preview size limit exceeded, changes collapsed. Show changes
services/core/java/com/android/server/power/Notifier.java +1 −42 Original line number Diff line number Diff line Loading @@ -84,7 +84,6 @@ final class Notifier { private final IBatteryStats mBatteryStats; private final IAppOpsService mAppOps; private final SuspendBlocker mSuspendBlocker; private final ScreenOnBlocker mScreenOnBlocker; private final WindowManagerPolicy mPolicy; private final ActivityManagerInternal mActivityManagerInternal; private final InputManagerInternal mInputManagerInternal; Loading @@ -110,18 +109,13 @@ final class Notifier { // True if a user activity message should be sent. private boolean mUserActivityPending; // The currently active screen on listener. This field is non-null whenever the // ScreenOnBlocker has been acquired and we are awaiting a callback to release it. private ScreenOnUnblocker mPendingScreenOnUnblocker; public Notifier(Looper looper, Context context, IBatteryStats batteryStats, IAppOpsService appOps, SuspendBlocker suspendBlocker, ScreenOnBlocker screenOnBlocker, IAppOpsService appOps, SuspendBlocker suspendBlocker, WindowManagerPolicy policy) { mContext = context; mBatteryStats = batteryStats; mAppOps = appOps; mSuspendBlocker = suspendBlocker; mScreenOnBlocker = screenOnBlocker; mPolicy = policy; mActivityManagerInternal = LocalServices.getService(ActivityManagerInternal.class); mInputManagerInternal = LocalServices.getService(InputManagerInternal.class); Loading Loading @@ -332,21 +326,6 @@ final class Notifier { } } /** * Notifies that screen is about to be turned on (any state other than off). */ public void onScreenTurningOn() { synchronized (mLock) { final ScreenOnUnblocker unblocker = blockScreenOnLocked(); mHandler.post(new Runnable() { @Override public void run() { mPolicy.screenTurningOn(unblocker); } }); } } /** * Called when there has been user activity. */ Loading Loading @@ -470,26 +449,6 @@ final class Notifier { } } private ScreenOnUnblocker blockScreenOnLocked() { if (mPendingScreenOnUnblocker == null) { mScreenOnBlocker.acquire(); } mPendingScreenOnUnblocker = new ScreenOnUnblocker(); return mPendingScreenOnUnblocker; } private final class ScreenOnUnblocker implements WindowManagerPolicy.ScreenOnListener { @Override public void onScreenOn() { synchronized (mLock) { if (mPendingScreenOnUnblocker == this) { mPendingScreenOnUnblocker = null; mScreenOnBlocker.release(); } } } } private final BroadcastReceiver mWakeUpBroadcastDone = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { Loading
services/core/java/com/android/server/power/PowerManagerService.java +3 −93 Original line number Diff line number Diff line Loading @@ -88,8 +88,6 @@ public final class PowerManagerService extends SystemService private static final int MSG_USER_ACTIVITY_TIMEOUT = 1; // Message: Sent when the device enters or exits a dreaming or dozing state. private static final int MSG_SANDMAN = 2; // Message: Sent when the screen on blocker is released. private static final int MSG_SCREEN_ON_BLOCKER_RELEASED = 3; // Dirty bit: mWakeLocks changed private static final int DIRTY_WAKE_LOCKS = 1 << 0; Loading @@ -111,10 +109,8 @@ public final class PowerManagerService extends SystemService private static final int DIRTY_BATTERY_STATE = 1 << 8; // Dirty bit: proximity state changed private static final int DIRTY_PROXIMITY_POSITIVE = 1 << 9; // Dirty bit: screen on blocker state became held or unheld private static final int DIRTY_SCREEN_ON_BLOCKER_RELEASED = 1 << 10; // Dirty bit: dock state changed private static final int DIRTY_DOCK_STATE = 1 << 11; private static final int DIRTY_DOCK_STATE = 1 << 10; // Wakefulness: The device is asleep and can only be awoken by a call to wakeUp(). // The screen should be off or in the process of being turned off by the display controller. Loading Loading @@ -244,10 +240,6 @@ public final class PowerManagerService extends SystemService // True if the display suspend blocker has been acquired. private boolean mHoldingDisplaySuspendBlocker; // The screen on blocker used to keep the screen from turning on while the lock // screen is coming up. private final ScreenOnBlockerImpl mScreenOnBlocker; // True if systemReady() has been called. private boolean mSystemReady; Loading Loading @@ -451,7 +443,6 @@ public final class PowerManagerService extends SystemService mHalAutoSuspendModeEnabled = false; mHalInteractiveModeEnabled = true; mScreenOnBlocker = new ScreenOnBlockerImpl(); mWakefulness = WAKEFULNESS_AWAKE; mInteractive = true; Loading Loading @@ -505,7 +496,7 @@ public final class PowerManagerService extends SystemService mBatteryStats = BatteryStatsService.getService(); mNotifier = new Notifier(Looper.getMainLooper(), mContext, mBatteryStats, mAppOps, createSuspendBlockerLocked("PowerManagerService.Broadcasts"), mScreenOnBlocker, mPolicy); mPolicy); mWirelessChargerDetector = new WirelessChargerDetector(sensorManager, createSuspendBlockerLocked("PowerManagerService.WirelessChargerDetector"), Loading Loading @@ -1745,13 +1736,6 @@ public final class PowerManagerService extends SystemService return true; } private void handleScreenOnBlockerReleased() { synchronized (mLock) { mDirty |= DIRTY_SCREEN_ON_BLOCKER_RELEASED; updatePowerStateLocked(); } } /** * Updates the display power state asynchronously. * When the update is finished, mDisplayReady will be set to true. The display Loading @@ -1766,8 +1750,7 @@ public final class PowerManagerService extends SystemService final boolean oldDisplayReady = mDisplayReady; if ((dirty & (DIRTY_WAKE_LOCKS | DIRTY_USER_ACTIVITY | DIRTY_WAKEFULNESS | DIRTY_ACTUAL_DISPLAY_POWER_STATE_UPDATED | DIRTY_BOOT_COMPLETED | DIRTY_SETTINGS | DIRTY_SCREEN_ON_BLOCKER_RELEASED)) != 0) { boolean wasBlockerNeeded = isScreenOnBlockerNeededLocked(mDisplayPowerRequest); | DIRTY_SETTINGS)) != 0) { mDisplayPowerRequest.policy = getDesiredScreenPolicyLocked(); int screenBrightness = mScreenBrightnessSettingDefault; Loading Loading @@ -1815,12 +1798,6 @@ public final class PowerManagerService extends SystemService mDisplayPowerRequest.dozeScreenBrightness = PowerManager.BRIGHTNESS_DEFAULT; } if (!wasBlockerNeeded && isScreenOnBlockerNeededLocked(mDisplayPowerRequest) && !mScreenOnBlocker.isHeld()) { mNotifier.onScreenTurningOn(); } mDisplayPowerRequest.blockScreenOn = mScreenOnBlocker.isHeld(); mDisplayReady = mDisplayManagerInternal.requestPowerState(mDisplayPowerRequest, mRequestWaitForNegativeProximity); mRequestWaitForNegativeProximity = false; Loading @@ -1837,17 +1814,6 @@ public final class PowerManagerService extends SystemService return mDisplayReady && !oldDisplayReady; } private static boolean isScreenOnBlockerNeededLocked(DisplayPowerRequest req) { switch (req.policy) { case DisplayPowerRequest.POLICY_OFF: return false; case DisplayPowerRequest.POLICY_DOZE: return req.dozeScreenState != Display.STATE_OFF; default: return true; } } private static boolean isValidBrightness(int value) { return value >= 0 && value <= 255; } Loading Loading @@ -2419,9 +2385,6 @@ public final class PowerManagerService extends SystemService pw.println(" " + sb); } pw.println(); pw.println("Screen On Blocker: " + mScreenOnBlocker); pw.println(); pw.println("Display Power: " + mDisplayPowerCallbacks); Loading Loading @@ -2530,9 +2493,6 @@ public final class PowerManagerService extends SystemService case MSG_SANDMAN: handleSandman(); break; case MSG_SCREEN_ON_BLOCKER_RELEASED: handleScreenOnBlockerReleased(); break; } } } Loading Loading @@ -2709,56 +2669,6 @@ public final class PowerManagerService extends SystemService } } private final class ScreenOnBlockerImpl implements ScreenOnBlocker { private static final String TRACE_NAME = "ScreenOnBlocker"; private int mNestCount; public boolean isHeld() { synchronized (this) { return mNestCount != 0; } } @Override public void acquire() { synchronized (this) { mNestCount += 1; if (DEBUG || true) { Slog.d(TAG, "Screen on blocked: mNestCount=" + mNestCount); } if (mNestCount == 1) { Trace.asyncTraceBegin(Trace.TRACE_TAG_POWER, TRACE_NAME, 0); } } } @Override public void release() { synchronized (this) { mNestCount -= 1; if (mNestCount == 0) { if (DEBUG || true) { Slog.d(TAG, "Screen on unblocked: mNestCount=" + mNestCount); } mHandler.sendEmptyMessage(MSG_SCREEN_ON_BLOCKER_RELEASED); Trace.asyncTraceEnd(Trace.TRACE_TAG_POWER, TRACE_NAME, 0); } else if (mNestCount < 0) { Slog.wtf(TAG, "Screen on blocker was released without being acquired!", new Throwable()); mNestCount = 0; } } } @Override public String toString() { synchronized (this) { return "held=" + (mNestCount != 0) + ", mNestCount=" + mNestCount; } } } private final class BinderService extends IPowerManager.Stub { @Override // Binder call public void acquireWakeLockWithUid(IBinder lock, int flags, String tag, Loading