Loading services/core/java/com/android/server/power/PowerManagerService.java +2 −2 Original line number Diff line number Diff line Loading @@ -2029,7 +2029,7 @@ public final class PowerManagerService extends SystemService private boolean dozePowerGroupLocked(final PowerGroup powerGroup, long eventTime, int reason, int uid) { if (DEBUG_SPEW) { Slog.d(TAG, "sleepDisplayGroupNoUpdateLocked: eventTime=" + eventTime Slog.d(TAG, "dozePowerGroup: eventTime=" + eventTime + ", groupId=" + powerGroup.getGroupId() + ", reason=" + reason + ", uid=" + uid); } Loading Loading @@ -3158,7 +3158,7 @@ public final class PowerManagerService extends SystemService Message msg = mHandler.obtainMessage(MSG_SANDMAN); msg.arg1 = powerGroup.getGroupId(); msg.setAsynchronous(true); mHandler.sendMessage(msg); mHandler.sendMessageAtTime(msg, mClock.uptimeMillis()); } } } Loading services/tests/servicestests/src/com/android/server/power/PowerManagerServiceTest.java +49 −0 Original line number Diff line number Diff line Loading @@ -210,6 +210,8 @@ public class PowerManagerServiceTest { Settings.Global.putInt(mContextSpy.getContentResolver(), Settings.Global.STAY_ON_WHILE_PLUGGED_IN, 0); Settings.Secure.putInt(mContextSpy.getContentResolver(), Settings.Secure.SCREENSAVER_ACTIVATE_ON_SLEEP, 0); mClock = new OffsettableClock.Stopped(); mTestLooper = new TestLooper(mClock::now); Loading Loading @@ -709,6 +711,48 @@ public class PowerManagerServiceTest { assertThat(mService.getBinderServiceInstance().forceSuspend()).isFalse(); } @SuppressWarnings("GuardedBy") @Test public void testScreensaverActivateOnSleepDisabled_powered_afterTimeout_goesToDozing() { when(mBatteryManagerInternalMock.isPowered(anyInt())).thenReturn(true); doAnswer(inv -> { when(mDreamManagerInternalMock.isDreaming()).thenReturn(true); return null; }).when(mDreamManagerInternalMock).startDream(anyBoolean()); setMinimumScreenOffTimeoutConfig(5); createService(); startSystem(); assertThat(mService.getGlobalWakefulnessLocked()).isEqualTo(WAKEFULNESS_AWAKE); advanceTime(15000); assertThat(mService.getGlobalWakefulnessLocked()).isEqualTo(WAKEFULNESS_DOZING); } @SuppressWarnings("GuardedBy") @Test public void testScreensaverActivateOnSleepEnabled_powered_afterTimeout_goesToDreaming() { when(mBatteryManagerInternalMock.isPowered(anyInt())).thenReturn(true); Settings.Secure.putInt(mContextSpy.getContentResolver(), Settings.Secure.SCREENSAVER_ACTIVATE_ON_SLEEP, 1); doAnswer(inv -> { when(mDreamManagerInternalMock.isDreaming()).thenReturn(true); return null; }).when(mDreamManagerInternalMock).startDream(anyBoolean()); setMinimumScreenOffTimeoutConfig(5); createService(); startSystem(); assertThat(mService.getGlobalWakefulnessLocked()).isEqualTo(WAKEFULNESS_AWAKE); advanceTime(15000); assertThat(mService.getGlobalWakefulnessLocked()).isEqualTo(WAKEFULNESS_DREAMING); } @Test public void testSetDozeOverrideFromDreamManager_triggersSuspendBlocker() { final String suspendBlockerName = "PowerManagerService.Display"; Loading Loading @@ -1136,6 +1180,11 @@ public class PowerManagerServiceTest { info.displayGroupId = nonDefaultDisplayGroupId; when(mDisplayManagerInternalMock.getDisplayInfo(nonDefaultDisplay)).thenReturn(info); doAnswer(inv -> { when(mDreamManagerInternalMock.isDreaming()).thenReturn(true); return null; }).when(mDreamManagerInternalMock).startDream(anyBoolean()); final String pkg = mContextSpy.getOpPackageName(); final Binder token = new Binder(); final String tag = "testRemovedDisplayGroupWakeLock_affectsNoDisplayGroups"; Loading Loading
services/core/java/com/android/server/power/PowerManagerService.java +2 −2 Original line number Diff line number Diff line Loading @@ -2029,7 +2029,7 @@ public final class PowerManagerService extends SystemService private boolean dozePowerGroupLocked(final PowerGroup powerGroup, long eventTime, int reason, int uid) { if (DEBUG_SPEW) { Slog.d(TAG, "sleepDisplayGroupNoUpdateLocked: eventTime=" + eventTime Slog.d(TAG, "dozePowerGroup: eventTime=" + eventTime + ", groupId=" + powerGroup.getGroupId() + ", reason=" + reason + ", uid=" + uid); } Loading Loading @@ -3158,7 +3158,7 @@ public final class PowerManagerService extends SystemService Message msg = mHandler.obtainMessage(MSG_SANDMAN); msg.arg1 = powerGroup.getGroupId(); msg.setAsynchronous(true); mHandler.sendMessage(msg); mHandler.sendMessageAtTime(msg, mClock.uptimeMillis()); } } } Loading
services/tests/servicestests/src/com/android/server/power/PowerManagerServiceTest.java +49 −0 Original line number Diff line number Diff line Loading @@ -210,6 +210,8 @@ public class PowerManagerServiceTest { Settings.Global.putInt(mContextSpy.getContentResolver(), Settings.Global.STAY_ON_WHILE_PLUGGED_IN, 0); Settings.Secure.putInt(mContextSpy.getContentResolver(), Settings.Secure.SCREENSAVER_ACTIVATE_ON_SLEEP, 0); mClock = new OffsettableClock.Stopped(); mTestLooper = new TestLooper(mClock::now); Loading Loading @@ -709,6 +711,48 @@ public class PowerManagerServiceTest { assertThat(mService.getBinderServiceInstance().forceSuspend()).isFalse(); } @SuppressWarnings("GuardedBy") @Test public void testScreensaverActivateOnSleepDisabled_powered_afterTimeout_goesToDozing() { when(mBatteryManagerInternalMock.isPowered(anyInt())).thenReturn(true); doAnswer(inv -> { when(mDreamManagerInternalMock.isDreaming()).thenReturn(true); return null; }).when(mDreamManagerInternalMock).startDream(anyBoolean()); setMinimumScreenOffTimeoutConfig(5); createService(); startSystem(); assertThat(mService.getGlobalWakefulnessLocked()).isEqualTo(WAKEFULNESS_AWAKE); advanceTime(15000); assertThat(mService.getGlobalWakefulnessLocked()).isEqualTo(WAKEFULNESS_DOZING); } @SuppressWarnings("GuardedBy") @Test public void testScreensaverActivateOnSleepEnabled_powered_afterTimeout_goesToDreaming() { when(mBatteryManagerInternalMock.isPowered(anyInt())).thenReturn(true); Settings.Secure.putInt(mContextSpy.getContentResolver(), Settings.Secure.SCREENSAVER_ACTIVATE_ON_SLEEP, 1); doAnswer(inv -> { when(mDreamManagerInternalMock.isDreaming()).thenReturn(true); return null; }).when(mDreamManagerInternalMock).startDream(anyBoolean()); setMinimumScreenOffTimeoutConfig(5); createService(); startSystem(); assertThat(mService.getGlobalWakefulnessLocked()).isEqualTo(WAKEFULNESS_AWAKE); advanceTime(15000); assertThat(mService.getGlobalWakefulnessLocked()).isEqualTo(WAKEFULNESS_DREAMING); } @Test public void testSetDozeOverrideFromDreamManager_triggersSuspendBlocker() { final String suspendBlockerName = "PowerManagerService.Display"; Loading Loading @@ -1136,6 +1180,11 @@ public class PowerManagerServiceTest { info.displayGroupId = nonDefaultDisplayGroupId; when(mDisplayManagerInternalMock.getDisplayInfo(nonDefaultDisplay)).thenReturn(info); doAnswer(inv -> { when(mDreamManagerInternalMock.isDreaming()).thenReturn(true); return null; }).when(mDreamManagerInternalMock).startDream(anyBoolean()); final String pkg = mContextSpy.getOpPackageName(); final Binder token = new Binder(); final String tag = "testRemovedDisplayGroupWakeLock_affectsNoDisplayGroups"; Loading