@@ -98,6 +98,8 @@ public final class PowerManagerService extends IPowerManager.Stub
9898 private static final int DIRTY_STAY_ON = 1 << 7 ;
9999 // Dirty bit: battery state changed
100100 private static final int DIRTY_BATTERY_STATE = 1 << 8 ;
101+ // Dirty bit: proximity state changed
102+ private static final int DIRTY_PROXIMITY_POSITIVE = 1 << 9 ;
101103
102104 // Wakefulness: The device is asleep and can only be awoken by a call to wakeUp().
103105 // The screen should be off or in the process of being turned off by the display controller.
@@ -258,6 +260,9 @@ public final class PowerManagerService extends IPowerManager.Stub
258260 // True if the device should stay on.
259261 private boolean mStayOn ;
260262
263+ // True if the proximity sensor reads a positive result.
264+ private boolean mProximityPositive ;
265+
261266 // Screen brightness setting limits.
262267 private int mScreenBrightnessSettingMinimum ;
263268 private int mScreenBrightnessSettingMaximum ;
@@ -1101,12 +1106,17 @@ private boolean shouldWakeUpWhenPluggedOrUnpluggedLocked(boolean wasPowered, int
11011106 */
11021107 private void updateStayOnLocked (int dirty ) {
11031108 if ((dirty & (DIRTY_BATTERY_STATE | DIRTY_SETTINGS )) != 0 ) {
1109+ final boolean wasStayOn = mStayOn ;
11041110 if (mStayOnWhilePluggedInSetting != 0
11051111 && !isMaximumScreenOffTimeoutFromDeviceAdminEnforcedLocked ()) {
11061112 mStayOn = mBatteryService .isPowered (mStayOnWhilePluggedInSetting );
11071113 } else {
11081114 mStayOn = false ;
11091115 }
1116+
1117+ if (mStayOn != wasStayOn ) {
1118+ mDirty |= DIRTY_STAY_ON ;
1119+ }
11101120 }
11111121 }
11121122
@@ -1265,7 +1275,7 @@ private int getScreenDimDurationLocked(int screenOffTimeout) {
12651275 private boolean updateWakefulnessLocked (int dirty ) {
12661276 boolean changed = false ;
12671277 if ((dirty & (DIRTY_WAKE_LOCKS | DIRTY_USER_ACTIVITY | DIRTY_BOOT_COMPLETED
1268- | DIRTY_WAKEFULNESS | DIRTY_STAY_ON )) != 0 ) {
1278+ | DIRTY_WAKEFULNESS | DIRTY_STAY_ON | DIRTY_PROXIMITY_POSITIVE )) != 0 ) {
12691279 if (mWakefulness == WAKEFULNESS_AWAKE && isItBedTimeYetLocked ()) {
12701280 if (DEBUG_SPEW ) {
12711281 Slog .d (TAG , "updateWakefulnessLocked: Bed time..." );
@@ -1288,17 +1298,17 @@ private boolean updateWakefulnessLocked(int dirty) {
12881298 * to being fully awake or else go to sleep for good.
12891299 */
12901300 private boolean isItBedTimeYetLocked () {
1291- return mBootCompleted && !isScreenBeingKeptOnLocked ();
1301+ return mBootCompleted && !isBeingKeptAwakeLocked ();
12921302 }
12931303
12941304 /**
1295- * Returns true if the screen is being kept on by a wake lock, user activity
1305+ * Returns true if the device is being kept awake by a wake lock, user activity
12961306 * or the stay on while powered setting.
12971307 */
1298- private boolean isScreenBeingKeptOnLocked () {
1308+ private boolean isBeingKeptAwakeLocked () {
12991309 return mStayOn
1300- || ( mWakeLockSummary & ( WAKE_LOCK_SCREEN_BRIGHT | WAKE_LOCK_SCREEN_DIM
1301- | WAKE_LOCK_PROXIMITY_SCREEN_OFF )) != 0
1310+ || mProximityPositive
1311+ || ( mWakeLockSummary & ( WAKE_LOCK_SCREEN_BRIGHT | WAKE_LOCK_SCREEN_DIM )) != 0
13021312 || (mUserActivitySummary & (USER_ACTIVITY_SCREEN_BRIGHT
13031313 | USER_ACTIVITY_SCREEN_DIM )) != 0 ;
13041314 }
@@ -1314,6 +1324,7 @@ private void updateDreamLocked(int dirty) {
13141324 | DIRTY_SETTINGS
13151325 | DIRTY_IS_POWERED
13161326 | DIRTY_STAY_ON
1327+ | DIRTY_PROXIMITY_POSITIVE
13171328 | DIRTY_BATTERY_STATE )) != 0 ) {
13181329 scheduleSandmanLocked ();
13191330 }
@@ -1401,7 +1412,7 @@ private boolean canDreamLocked() {
14011412 && mDreamsEnabledSetting
14021413 && mDisplayPowerRequest .screenState != DisplayPowerRequest .SCREEN_STATE_OFF
14031414 && mBootCompleted
1404- && (mIsPowered || isScreenBeingKeptOnLocked ());
1415+ && (mIsPowered || isBeingKeptAwakeLocked ());
14051416 }
14061417
14071418 /**
@@ -1527,8 +1538,17 @@ public void onStateChanged() {
15271538 updatePowerStateLocked ();
15281539 }
15291540
1541+ @ Override
1542+ public void onProximityPositive () {
1543+ mProximityPositive = true ;
1544+ mDirty |= DIRTY_PROXIMITY_POSITIVE ;
1545+ updatePowerStateLocked ();
1546+ }
1547+
15301548 @ Override
15311549 public void onProximityNegative () {
1550+ mProximityPositive = false ;
1551+ mDirty |= DIRTY_PROXIMITY_POSITIVE ;
15321552 userActivityNoUpdateLocked (SystemClock .uptimeMillis (),
15331553 PowerManager .USER_ACTIVITY_EVENT_OTHER , 0 , Process .SYSTEM_UID );
15341554 updatePowerStateLocked ();
@@ -1986,6 +2006,7 @@ protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
19862006 pw .println (" mIsPowered=" + mIsPowered );
19872007 pw .println (" mPlugType=" + mPlugType );
19882008 pw .println (" mStayOn=" + mStayOn );
2009+ pw .println (" mProximityPositive=" + mProximityPositive );
19892010 pw .println (" mBootCompleted=" + mBootCompleted );
19902011 pw .println (" mSystemReady=" + mSystemReady );
19912012 pw .println (" mWakeLockSummary=0x" + Integer .toHexString (mWakeLockSummary ));
0 commit comments