Skip to content

Commit

Permalink
Fix missing lock in power manager.
Browse files Browse the repository at this point in the history
The display wake lock and other internal state could become
out of sync if we happened to execute the power manager's update
function concurrently due to the missing lock.

This bug can be trigged due to display state changes or proximity
sensor updated.  Although it would be extremely rare, we have
some evidence of this happening on at least a few devices resulting
in rapid power drain with the screen off or a crash.

Bug: 9880044
Change-Id: I3c674ce429621a50cbb36c3a01883d5f388205b2
(cherry picked from commit d91e417)
  • Loading branch information
Jeff Brown authored and The Android Automerger committed Jul 17, 2013
1 parent 5892fc5 commit e6771c4
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions services/java/com/android/server/power/PowerManagerService.java
Expand Up @@ -1702,24 +1702,30 @@ private int getDesiredScreenPowerStateLocked() {
new DisplayPowerController.Callbacks() {
@Override
public void onStateChanged() {
mDirty |= DIRTY_ACTUAL_DISPLAY_POWER_STATE_UPDATED;
updatePowerStateLocked();
synchronized (mLock) {
mDirty |= DIRTY_ACTUAL_DISPLAY_POWER_STATE_UPDATED;
updatePowerStateLocked();
}
}

@Override
public void onProximityPositive() {
mProximityPositive = true;
mDirty |= DIRTY_PROXIMITY_POSITIVE;
updatePowerStateLocked();
synchronized (mLock) {
mProximityPositive = true;
mDirty |= DIRTY_PROXIMITY_POSITIVE;
updatePowerStateLocked();
}
}

@Override
public void onProximityNegative() {
mProximityPositive = false;
mDirty |= DIRTY_PROXIMITY_POSITIVE;
userActivityNoUpdateLocked(SystemClock.uptimeMillis(),
PowerManager.USER_ACTIVITY_EVENT_OTHER, 0, Process.SYSTEM_UID);
updatePowerStateLocked();
synchronized (mLock) {
mProximityPositive = false;
mDirty |= DIRTY_PROXIMITY_POSITIVE;
userActivityNoUpdateLocked(SystemClock.uptimeMillis(),
PowerManager.USER_ACTIVITY_EVENT_OTHER, 0, Process.SYSTEM_UID);
updatePowerStateLocked();
}
}
};

Expand Down

0 comments on commit e6771c4

Please sign in to comment.