Loading services/core/java/com/android/server/power/PowerManagerService.java +7 −14 Original line number Diff line number Diff line Loading @@ -2701,7 +2701,7 @@ public final class PowerManagerService extends SystemService mHandler.removeMessages(MSG_ATTENTIVE_TIMEOUT); if (isBeingKeptFromShowingInattentiveSleepWarningLocked()) { if (isBeingKeptFromInattentiveSleepLocked()) { return; } Loading @@ -2717,10 +2717,6 @@ public final class PowerManagerService extends SystemService } mInattentiveSleepWarningOverlayController.show(); nextTimeout = goToSleepTime; } else { if (DEBUG && getWakefulnessLocked() != WAKEFULNESS_ASLEEP) { Slog.i(TAG, "Going to sleep now due to long user inactivity"); } } if (nextTimeout >= 0) { Loading @@ -2739,7 +2735,7 @@ public final class PowerManagerService extends SystemService if (getWakefulnessLocked() != WAKEFULNESS_AWAKE) { mInattentiveSleepWarningOverlayController.dismiss(false); return true; } else if (attentiveTimeout < 0 || isBeingKeptFromShowingInattentiveSleepWarningLocked() } else if (attentiveTimeout < 0 || isBeingKeptFromInattentiveSleepLocked() || now < showWarningTime) { mInattentiveSleepWarningOverlayController.dismiss(true); return true; Loading Loading @@ -2861,6 +2857,9 @@ public final class PowerManagerService extends SystemService Slog.d(TAG, "updateWakefulnessLocked: Bed time for group " + id); } if (isAttentiveTimeoutExpired(id, time)) { if (DEBUG) { Slog.i(TAG, "Going to sleep now due to long user inactivity"); } changed = sleepDisplayGroupNoUpdateLocked(id, time, PowerManager.GO_TO_SLEEP_REASON_TIMEOUT, PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE, Process.SYSTEM_UID); Loading Loading @@ -2898,7 +2897,7 @@ public final class PowerManagerService extends SystemService long now = mClock.uptimeMillis(); if (isAttentiveTimeoutExpired(groupId, now)) { return !isBeingKeptFromInattentiveSleepLocked(groupId); return !isBeingKeptFromInattentiveSleepLocked(); } else { return !isBeingKeptAwakeLocked(groupId); } Loading Loading @@ -2928,13 +2927,7 @@ public final class PowerManagerService extends SystemService * a phone call. This function only controls whether the device will go to sleep which is * independent of whether it will be allowed to suspend. */ private boolean isBeingKeptFromInattentiveSleepLocked(int groupId) { return mStayOn || mScreenBrightnessBoostInProgress || mProximityPositive || (mDisplayGroupPowerStateMapper.getUserActivitySummaryLocked(groupId) & ( USER_ACTIVITY_SCREEN_BRIGHT | USER_ACTIVITY_SCREEN_DIM)) != 0; } private boolean isBeingKeptFromShowingInattentiveSleepWarningLocked() { private boolean isBeingKeptFromInattentiveSleepLocked() { return mStayOn || mScreenBrightnessBoostInProgress || mProximityPositive || !mBootCompleted; } Loading services/tests/servicestests/src/com/android/server/power/PowerManagerServiceTest.java +68 −0 Original line number Diff line number Diff line Loading @@ -888,6 +888,74 @@ public class PowerManagerServiceTest { assertThat(mService.getWakefulnessLocked()).isEqualTo(WAKEFULNESS_ASLEEP); } @Test public void testInattentiveSleep_wakeLockOnAfterRelease_inattentiveSleepTimeoutNotAffected() throws Exception { final DisplayInfo info = new DisplayInfo(); info.displayGroupId = Display.DEFAULT_DISPLAY_GROUP; when(mDisplayManagerInternalMock.getDisplayInfo(Display.DEFAULT_DISPLAY)).thenReturn(info); final String pkg = mContextSpy.getOpPackageName(); final Binder token = new Binder(); final String tag = "testInattentiveSleep_wakeLockOnAfterRelease"; setMinimumScreenOffTimeoutConfig(5); setAttentiveTimeout(2000); createService(); startSystem(); mService.getBinderServiceInstance().acquireWakeLock(token, PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, tag, pkg, null /* workSource */, null /* historyTag */, Display.DEFAULT_DISPLAY); advanceTime(1500); mService.getBinderServiceInstance().releaseWakeLock(token, 0 /* flags */); advanceTime(520); assertThat(mService.getWakefulnessLocked()).isEqualTo(WAKEFULNESS_ASLEEP); } @Test public void testInattentiveSleep_userActivityNoChangeLights_inattentiveSleepTimeoutNotAffected() throws Exception { final DisplayInfo info = new DisplayInfo(); info.displayGroupId = Display.DEFAULT_DISPLAY_GROUP; when(mDisplayManagerInternalMock.getDisplayInfo(Display.DEFAULT_DISPLAY)).thenReturn(info); setMinimumScreenOffTimeoutConfig(5); setAttentiveTimeout(2000); createService(); startSystem(); advanceTime(1500); mService.getBinderServiceInstance().userActivity(Display.DEFAULT_DISPLAY, mClock.now(), PowerManager.USER_ACTIVITY_EVENT_OTHER, PowerManager.USER_ACTIVITY_FLAG_NO_CHANGE_LIGHTS); advanceTime(520); assertThat(mService.getWakefulnessLocked()).isEqualTo(WAKEFULNESS_ASLEEP); } @Test public void testInattentiveSleep_userActivity_inattentiveSleepTimeoutExtended() throws Exception { final DisplayInfo info = new DisplayInfo(); info.displayGroupId = Display.DEFAULT_DISPLAY_GROUP; when(mDisplayManagerInternalMock.getDisplayInfo(Display.DEFAULT_DISPLAY)).thenReturn(info); setMinimumScreenOffTimeoutConfig(5); setAttentiveTimeout(2000); createService(); startSystem(); advanceTime(1500); mService.getBinderServiceInstance().userActivity(Display.DEFAULT_DISPLAY, mClock.now(), PowerManager.USER_ACTIVITY_EVENT_OTHER, 0 /* flags */); advanceTime(520); assertThat(mService.getWakefulnessLocked()).isNotEqualTo(WAKEFULNESS_ASLEEP); } @Test public void testWakeLock_affectsProperDisplayGroup() throws Exception { final int nonDefaultDisplayGroupId = Display.DEFAULT_DISPLAY_GROUP + 1; Loading Loading
services/core/java/com/android/server/power/PowerManagerService.java +7 −14 Original line number Diff line number Diff line Loading @@ -2701,7 +2701,7 @@ public final class PowerManagerService extends SystemService mHandler.removeMessages(MSG_ATTENTIVE_TIMEOUT); if (isBeingKeptFromShowingInattentiveSleepWarningLocked()) { if (isBeingKeptFromInattentiveSleepLocked()) { return; } Loading @@ -2717,10 +2717,6 @@ public final class PowerManagerService extends SystemService } mInattentiveSleepWarningOverlayController.show(); nextTimeout = goToSleepTime; } else { if (DEBUG && getWakefulnessLocked() != WAKEFULNESS_ASLEEP) { Slog.i(TAG, "Going to sleep now due to long user inactivity"); } } if (nextTimeout >= 0) { Loading @@ -2739,7 +2735,7 @@ public final class PowerManagerService extends SystemService if (getWakefulnessLocked() != WAKEFULNESS_AWAKE) { mInattentiveSleepWarningOverlayController.dismiss(false); return true; } else if (attentiveTimeout < 0 || isBeingKeptFromShowingInattentiveSleepWarningLocked() } else if (attentiveTimeout < 0 || isBeingKeptFromInattentiveSleepLocked() || now < showWarningTime) { mInattentiveSleepWarningOverlayController.dismiss(true); return true; Loading Loading @@ -2861,6 +2857,9 @@ public final class PowerManagerService extends SystemService Slog.d(TAG, "updateWakefulnessLocked: Bed time for group " + id); } if (isAttentiveTimeoutExpired(id, time)) { if (DEBUG) { Slog.i(TAG, "Going to sleep now due to long user inactivity"); } changed = sleepDisplayGroupNoUpdateLocked(id, time, PowerManager.GO_TO_SLEEP_REASON_TIMEOUT, PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE, Process.SYSTEM_UID); Loading Loading @@ -2898,7 +2897,7 @@ public final class PowerManagerService extends SystemService long now = mClock.uptimeMillis(); if (isAttentiveTimeoutExpired(groupId, now)) { return !isBeingKeptFromInattentiveSleepLocked(groupId); return !isBeingKeptFromInattentiveSleepLocked(); } else { return !isBeingKeptAwakeLocked(groupId); } Loading Loading @@ -2928,13 +2927,7 @@ public final class PowerManagerService extends SystemService * a phone call. This function only controls whether the device will go to sleep which is * independent of whether it will be allowed to suspend. */ private boolean isBeingKeptFromInattentiveSleepLocked(int groupId) { return mStayOn || mScreenBrightnessBoostInProgress || mProximityPositive || (mDisplayGroupPowerStateMapper.getUserActivitySummaryLocked(groupId) & ( USER_ACTIVITY_SCREEN_BRIGHT | USER_ACTIVITY_SCREEN_DIM)) != 0; } private boolean isBeingKeptFromShowingInattentiveSleepWarningLocked() { private boolean isBeingKeptFromInattentiveSleepLocked() { return mStayOn || mScreenBrightnessBoostInProgress || mProximityPositive || !mBootCompleted; } Loading
services/tests/servicestests/src/com/android/server/power/PowerManagerServiceTest.java +68 −0 Original line number Diff line number Diff line Loading @@ -888,6 +888,74 @@ public class PowerManagerServiceTest { assertThat(mService.getWakefulnessLocked()).isEqualTo(WAKEFULNESS_ASLEEP); } @Test public void testInattentiveSleep_wakeLockOnAfterRelease_inattentiveSleepTimeoutNotAffected() throws Exception { final DisplayInfo info = new DisplayInfo(); info.displayGroupId = Display.DEFAULT_DISPLAY_GROUP; when(mDisplayManagerInternalMock.getDisplayInfo(Display.DEFAULT_DISPLAY)).thenReturn(info); final String pkg = mContextSpy.getOpPackageName(); final Binder token = new Binder(); final String tag = "testInattentiveSleep_wakeLockOnAfterRelease"; setMinimumScreenOffTimeoutConfig(5); setAttentiveTimeout(2000); createService(); startSystem(); mService.getBinderServiceInstance().acquireWakeLock(token, PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, tag, pkg, null /* workSource */, null /* historyTag */, Display.DEFAULT_DISPLAY); advanceTime(1500); mService.getBinderServiceInstance().releaseWakeLock(token, 0 /* flags */); advanceTime(520); assertThat(mService.getWakefulnessLocked()).isEqualTo(WAKEFULNESS_ASLEEP); } @Test public void testInattentiveSleep_userActivityNoChangeLights_inattentiveSleepTimeoutNotAffected() throws Exception { final DisplayInfo info = new DisplayInfo(); info.displayGroupId = Display.DEFAULT_DISPLAY_GROUP; when(mDisplayManagerInternalMock.getDisplayInfo(Display.DEFAULT_DISPLAY)).thenReturn(info); setMinimumScreenOffTimeoutConfig(5); setAttentiveTimeout(2000); createService(); startSystem(); advanceTime(1500); mService.getBinderServiceInstance().userActivity(Display.DEFAULT_DISPLAY, mClock.now(), PowerManager.USER_ACTIVITY_EVENT_OTHER, PowerManager.USER_ACTIVITY_FLAG_NO_CHANGE_LIGHTS); advanceTime(520); assertThat(mService.getWakefulnessLocked()).isEqualTo(WAKEFULNESS_ASLEEP); } @Test public void testInattentiveSleep_userActivity_inattentiveSleepTimeoutExtended() throws Exception { final DisplayInfo info = new DisplayInfo(); info.displayGroupId = Display.DEFAULT_DISPLAY_GROUP; when(mDisplayManagerInternalMock.getDisplayInfo(Display.DEFAULT_DISPLAY)).thenReturn(info); setMinimumScreenOffTimeoutConfig(5); setAttentiveTimeout(2000); createService(); startSystem(); advanceTime(1500); mService.getBinderServiceInstance().userActivity(Display.DEFAULT_DISPLAY, mClock.now(), PowerManager.USER_ACTIVITY_EVENT_OTHER, 0 /* flags */); advanceTime(520); assertThat(mService.getWakefulnessLocked()).isNotEqualTo(WAKEFULNESS_ASLEEP); } @Test public void testWakeLock_affectsProperDisplayGroup() throws Exception { final int nonDefaultDisplayGroupId = Display.DEFAULT_DISPLAY_GROUP + 1; Loading