diff options
author | Jim Miller <jaggies@google.com> | 2014-07-01 17:10:21 -0700 |
---|---|---|
committer | Jim Miller <jaggies@google.com> | 2014-07-09 21:12:09 +0000 |
commit | c522d1646ac353aec302252fa53976c1fa46ad3d (patch) | |
tree | 4bab7f0da4eb2a9af27912ddcde58f2d9b4dd549 /services/core/java/com/android/server/power | |
parent | 8f2e74cac282afa0bcf98f5d7131268147d12efe (diff) | |
download | frameworks_base-c522d1646ac353aec302252fa53976c1fa46ad3d.zip frameworks_base-c522d1646ac353aec302252fa53976c1fa46ad3d.tar.gz frameworks_base-c522d1646ac353aec302252fa53976c1fa46ad3d.tar.bz2 |
Decouple critical policy power update from SCREEN_ON broadcast
This attempts to fix a bug where ordered broadcasts like
ACTION_SCREEN_ON are substantially delayed by misbehaving
receivers. Instead, we immediately send the state to mPolicy
so that it can wake/sleep the device without delay.
Fixes bug 14313639
Change-Id: I21a191f90e0a19f1ee75c160ecc4e63e8def709e
Diffstat (limited to 'services/core/java/com/android/server/power')
-rw-r--r-- | services/core/java/com/android/server/power/Notifier.java | 52 |
1 files changed, 28 insertions, 24 deletions
diff --git a/services/core/java/com/android/server/power/Notifier.java b/services/core/java/com/android/server/power/Notifier.java index e244bde..e272f38 100644 --- a/services/core/java/com/android/server/power/Notifier.java +++ b/services/core/java/com/android/server/power/Notifier.java @@ -243,7 +243,7 @@ final class Notifier { /** * Notifies that the device is changing interactive state. */ - public void onInteractiveStateChangeStarted(boolean interactive, int reason) { + public void onInteractiveStateChangeStarted(boolean interactive, final int reason) { if (DEBUG) { Slog.d(TAG, "onInteractiveChangeStarted: interactive=" + interactive + ", reason=" + reason); @@ -259,6 +259,14 @@ final class Notifier { mScreenOnBlockerAcquired = true; mScreenOnBlocker.acquire(); } + mHandler.post(new Runnable() { + @Override + public void run() { + EventLog.writeEvent(EventLogTags.POWER_SCREEN_STATE, 1, 0, 0, 0); + mPolicy.wakingUp(mScreenOnListener); + mActivityManagerInternal.wakingUp(); + } + }); updatePendingBroadcastLocked(); } } else { @@ -298,6 +306,23 @@ final class Notifier { mUserActivityPending = false; mHandler.removeMessages(MSG_USER_ACTIVITY); } + mHandler.post(new Runnable() { + @Override + public void run() { + int why = WindowManagerPolicy.OFF_BECAUSE_OF_USER; + switch (mLastGoToSleepReason) { + case PowerManager.GO_TO_SLEEP_REASON_DEVICE_ADMIN: + why = WindowManagerPolicy.OFF_BECAUSE_OF_ADMIN; + break; + case PowerManager.GO_TO_SLEEP_REASON_TIMEOUT: + why = WindowManagerPolicy.OFF_BECAUSE_OF_TIMEOUT; + break; + } + EventLog.writeEvent(EventLogTags.POWER_SCREEN_STATE, 0, why, 0, 0); + mPolicy.goingToSleep(why); + mActivityManagerInternal.goingToSleep(); + } + }); updatePendingBroadcastLocked(); } } @@ -409,7 +434,6 @@ final class Notifier { mBroadcastStartTime = SystemClock.uptimeMillis(); powerState = mBroadcastedPowerState; - goToSleepReason = mLastGoToSleepReason; } EventLog.writeEvent(EventLogTags.POWER_SCREEN_BROADCAST_SEND, 1); @@ -417,7 +441,7 @@ final class Notifier { if (powerState == POWER_STATE_AWAKE) { sendWakeUpBroadcast(); } else { - sendGoToSleepBroadcast(goToSleepReason); + sendGoToSleepBroadcast(); } } @@ -426,11 +450,6 @@ final class Notifier { Slog.d(TAG, "Sending wake up broadcast."); } - EventLog.writeEvent(EventLogTags.POWER_SCREEN_STATE, 1, 0, 0, 0); - - mPolicy.wakingUp(mScreenOnListener); - mActivityManagerInternal.wakingUp(); - if (ActivityManagerNative.isSystemReady()) { mContext.sendOrderedBroadcastAsUser(mScreenOnIntent, UserHandle.ALL, null, mWakeUpBroadcastDone, mHandler, 0, null, null); @@ -462,26 +481,11 @@ final class Notifier { } }; - private void sendGoToSleepBroadcast(int reason) { + private void sendGoToSleepBroadcast() { if (DEBUG) { Slog.d(TAG, "Sending go to sleep broadcast."); } - int why = WindowManagerPolicy.OFF_BECAUSE_OF_USER; - switch (reason) { - case PowerManager.GO_TO_SLEEP_REASON_DEVICE_ADMIN: - why = WindowManagerPolicy.OFF_BECAUSE_OF_ADMIN; - break; - case PowerManager.GO_TO_SLEEP_REASON_TIMEOUT: - why = WindowManagerPolicy.OFF_BECAUSE_OF_TIMEOUT; - break; - } - - EventLog.writeEvent(EventLogTags.POWER_SCREEN_STATE, 0, why, 0, 0); - - mPolicy.goingToSleep(why); - mActivityManagerInternal.goingToSleep(); - if (ActivityManagerNative.isSystemReady()) { mContext.sendOrderedBroadcastAsUser(mScreenOffIntent, UserHandle.ALL, null, mGoToSleepBroadcastDone, mHandler, 0, null, null); |