Loading core/java/android/os/PowerManager.java +7 −1 Original line number Diff line number Diff line Loading @@ -373,9 +373,15 @@ public final class PowerManager { public static final int GO_TO_SLEEP_REASON_INATTENTIVE = 9; /** * Go to sleep reason code: Going to sleep due to quiescent boot. * @hide */ public static final int GO_TO_SLEEP_REASON_MAX = GO_TO_SLEEP_REASON_INATTENTIVE; public static final int GO_TO_SLEEP_REASON_QUIESCENT = 10; /** * @hide */ public static final int GO_TO_SLEEP_REASON_MAX = GO_TO_SLEEP_REASON_QUIESCENT; /** * @hide Loading services/core/java/com/android/server/power/Notifier.java +14 −3 Original line number Diff line number Diff line Loading @@ -678,9 +678,20 @@ public class Notifier { final int powerState; synchronized (mLock) { if (mBroadcastedInteractiveState == INTERACTIVE_STATE_UNKNOWN) { // Broadcasted power state is unknown. Send wake up. // Broadcasted power state is unknown. // Send wake up or go to sleep. switch (mPendingInteractiveState) { case INTERACTIVE_STATE_ASLEEP: mPendingGoToSleepBroadcast = false; mBroadcastedInteractiveState = INTERACTIVE_STATE_ASLEEP; break; case INTERACTIVE_STATE_AWAKE: default: mPendingWakeUpBroadcast = false; mBroadcastedInteractiveState = INTERACTIVE_STATE_AWAKE; break; } } else if (mBroadcastedInteractiveState == INTERACTIVE_STATE_AWAKE) { // Broadcasted power state is awake. Send asleep if needed. if (mPendingWakeUpBroadcast || mPendingGoToSleepBroadcast Loading services/core/java/com/android/server/power/PowerManagerService.java +20 −8 Original line number Diff line number Diff line Loading @@ -347,6 +347,7 @@ public final class PowerManagerService extends SystemService private boolean mSystemReady; // True if boot completed occurred. We keep the screen on until this happens. // The screen will be off if we are in quiescent mode. private boolean mBootCompleted; // True if auto-suspend mode is enabled. Loading Loading @@ -864,6 +865,12 @@ public final class PowerManagerService extends SystemService mBatterySaverStateMachine.onBootCompleted(); userActivityNoUpdateLocked( now, PowerManager.USER_ACTIVITY_EVENT_OTHER, 0, Process.SYSTEM_UID); if (sQuiescent) { goToSleepNoUpdateLocked(SystemClock.uptimeMillis(), PowerManager.GO_TO_SLEEP_REASON_QUIESCENT, PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE, Process.SYSTEM_UID); } updatePowerStateLocked(); } } Loading Loading @@ -1430,8 +1437,7 @@ public final class PowerManagerService extends SystemService + ", uid=" + uid); } if (eventTime < mLastSleepTime || eventTime < mLastWakeTime || !mBootCompleted || !mSystemReady) { if (eventTime < mLastSleepTime || eventTime < mLastWakeTime || !mSystemReady) { return false; } Loading Loading @@ -1508,7 +1514,7 @@ public final class PowerManagerService extends SystemService } if (eventTime < mLastSleepTime || mWakefulness == WAKEFULNESS_AWAKE || !mBootCompleted || !mSystemReady || mForceSuspendActive) { || mForceSuspendActive || !mSystemReady) { return false; } Loading @@ -1530,6 +1536,10 @@ public final class PowerManagerService extends SystemService mNotifier.onWakeUp(reason, details, reasonUid, opPackageName, opUid); userActivityNoUpdateLocked( eventTime, PowerManager.USER_ACTIVITY_EVENT_OTHER, 0, reasonUid); if (sQuiescent) { mDirty |= DIRTY_QUIESCENT; } } finally { Trace.traceEnd(Trace.TRACE_TAG_POWER); } Loading Loading @@ -1561,7 +1571,8 @@ public final class PowerManagerService extends SystemService if (eventTime < mLastWakeTime || mWakefulness == WAKEFULNESS_ASLEEP || mWakefulness == WAKEFULNESS_DOZING || !mBootCompleted || !mSystemReady) { || !mSystemReady || !mBootCompleted) { return false; } Loading Loading @@ -2645,6 +2656,10 @@ public final class PowerManagerService extends SystemService | DIRTY_ACTUAL_DISPLAY_POWER_STATE_UPDATED | DIRTY_BOOT_COMPLETED | DIRTY_SETTINGS | DIRTY_SCREEN_BRIGHTNESS_BOOST | DIRTY_VR_MODE_CHANGED | DIRTY_QUIESCENT)) != 0) { if ((dirty & DIRTY_QUIESCENT) != 0) { sQuiescent = false; } mDisplayPowerRequest.policy = getDesiredScreenPolicyLocked(); // Determine appropriate screen brightness and auto-brightness adjustments. Loading Loading @@ -2694,9 +2709,6 @@ public final class PowerManagerService extends SystemService mRequestWaitForNegativeProximity); mRequestWaitForNegativeProximity = false; if ((dirty & DIRTY_QUIESCENT) != 0) { sQuiescent = false; } if (DEBUG_SPEW) { Slog.d(TAG, "updateDisplayPowerStateLocked: mDisplayReady=" + mDisplayReady + ", policy=" + mDisplayPowerRequest.policy Loading services/tests/servicestests/src/com/android/server/power/PowerManagerServiceTest.java +52 −0 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.ArgumentMatchers.eq; Loading Loading @@ -754,4 +755,55 @@ public class PowerManagerServiceTest { SystemClock.sleep(11); assertThat(mService.getWakefulness()).isEqualTo(WAKEFULNESS_ASLEEP); } @Test public void testBoot_ShouldBeAwake() throws Exception { createService(); startSystem(); assertThat(mService.getWakefulness()).isEqualTo(WAKEFULNESS_AWAKE); verify(mNotifierMock, never()).onWakefulnessChangeStarted(anyInt(), anyInt(), anyLong()); } @Test public void testBoot_DesiredScreenPolicyShouldBeBright() throws Exception { createService(); startSystem(); assertThat(mService.getDesiredScreenPolicyLocked()).isEqualTo( DisplayPowerRequest.POLICY_BRIGHT); } @Test public void testQuiescentBoot_ShouldBeAsleep() throws Exception { when(mSystemPropertiesMock.get(eq(SYSTEM_PROPERTY_QUIESCENT), any())).thenReturn("1"); createService(); startSystem(); assertThat(mService.getWakefulness()).isEqualTo(WAKEFULNESS_ASLEEP); verify(mNotifierMock).onWakefulnessChangeStarted(eq(WAKEFULNESS_ASLEEP), anyInt(), anyLong()); } @Test public void testQuiescentBoot_DesiredScreenPolicyShouldBeOff() throws Exception { when(mSystemPropertiesMock.get(eq(SYSTEM_PROPERTY_QUIESCENT), any())).thenReturn("1"); createService(); assertThat(mService.getDesiredScreenPolicyLocked()).isEqualTo( DisplayPowerRequest.POLICY_OFF); startSystem(); assertThat(mService.getDesiredScreenPolicyLocked()).isEqualTo( DisplayPowerRequest.POLICY_OFF); } @Test public void testQuiescentBoot_WakeUp_DesiredScreenPolicyShouldBeBright() throws Exception { when(mSystemPropertiesMock.get(eq(SYSTEM_PROPERTY_QUIESCENT), any())).thenReturn("1"); createService(); startSystem(); forceAwake(); assertThat(mService.getDesiredScreenPolicyLocked()).isEqualTo( DisplayPowerRequest.POLICY_BRIGHT); } } Loading
core/java/android/os/PowerManager.java +7 −1 Original line number Diff line number Diff line Loading @@ -373,9 +373,15 @@ public final class PowerManager { public static final int GO_TO_SLEEP_REASON_INATTENTIVE = 9; /** * Go to sleep reason code: Going to sleep due to quiescent boot. * @hide */ public static final int GO_TO_SLEEP_REASON_MAX = GO_TO_SLEEP_REASON_INATTENTIVE; public static final int GO_TO_SLEEP_REASON_QUIESCENT = 10; /** * @hide */ public static final int GO_TO_SLEEP_REASON_MAX = GO_TO_SLEEP_REASON_QUIESCENT; /** * @hide Loading
services/core/java/com/android/server/power/Notifier.java +14 −3 Original line number Diff line number Diff line Loading @@ -678,9 +678,20 @@ public class Notifier { final int powerState; synchronized (mLock) { if (mBroadcastedInteractiveState == INTERACTIVE_STATE_UNKNOWN) { // Broadcasted power state is unknown. Send wake up. // Broadcasted power state is unknown. // Send wake up or go to sleep. switch (mPendingInteractiveState) { case INTERACTIVE_STATE_ASLEEP: mPendingGoToSleepBroadcast = false; mBroadcastedInteractiveState = INTERACTIVE_STATE_ASLEEP; break; case INTERACTIVE_STATE_AWAKE: default: mPendingWakeUpBroadcast = false; mBroadcastedInteractiveState = INTERACTIVE_STATE_AWAKE; break; } } else if (mBroadcastedInteractiveState == INTERACTIVE_STATE_AWAKE) { // Broadcasted power state is awake. Send asleep if needed. if (mPendingWakeUpBroadcast || mPendingGoToSleepBroadcast Loading
services/core/java/com/android/server/power/PowerManagerService.java +20 −8 Original line number Diff line number Diff line Loading @@ -347,6 +347,7 @@ public final class PowerManagerService extends SystemService private boolean mSystemReady; // True if boot completed occurred. We keep the screen on until this happens. // The screen will be off if we are in quiescent mode. private boolean mBootCompleted; // True if auto-suspend mode is enabled. Loading Loading @@ -864,6 +865,12 @@ public final class PowerManagerService extends SystemService mBatterySaverStateMachine.onBootCompleted(); userActivityNoUpdateLocked( now, PowerManager.USER_ACTIVITY_EVENT_OTHER, 0, Process.SYSTEM_UID); if (sQuiescent) { goToSleepNoUpdateLocked(SystemClock.uptimeMillis(), PowerManager.GO_TO_SLEEP_REASON_QUIESCENT, PowerManager.GO_TO_SLEEP_FLAG_NO_DOZE, Process.SYSTEM_UID); } updatePowerStateLocked(); } } Loading Loading @@ -1430,8 +1437,7 @@ public final class PowerManagerService extends SystemService + ", uid=" + uid); } if (eventTime < mLastSleepTime || eventTime < mLastWakeTime || !mBootCompleted || !mSystemReady) { if (eventTime < mLastSleepTime || eventTime < mLastWakeTime || !mSystemReady) { return false; } Loading Loading @@ -1508,7 +1514,7 @@ public final class PowerManagerService extends SystemService } if (eventTime < mLastSleepTime || mWakefulness == WAKEFULNESS_AWAKE || !mBootCompleted || !mSystemReady || mForceSuspendActive) { || mForceSuspendActive || !mSystemReady) { return false; } Loading @@ -1530,6 +1536,10 @@ public final class PowerManagerService extends SystemService mNotifier.onWakeUp(reason, details, reasonUid, opPackageName, opUid); userActivityNoUpdateLocked( eventTime, PowerManager.USER_ACTIVITY_EVENT_OTHER, 0, reasonUid); if (sQuiescent) { mDirty |= DIRTY_QUIESCENT; } } finally { Trace.traceEnd(Trace.TRACE_TAG_POWER); } Loading Loading @@ -1561,7 +1571,8 @@ public final class PowerManagerService extends SystemService if (eventTime < mLastWakeTime || mWakefulness == WAKEFULNESS_ASLEEP || mWakefulness == WAKEFULNESS_DOZING || !mBootCompleted || !mSystemReady) { || !mSystemReady || !mBootCompleted) { return false; } Loading Loading @@ -2645,6 +2656,10 @@ public final class PowerManagerService extends SystemService | DIRTY_ACTUAL_DISPLAY_POWER_STATE_UPDATED | DIRTY_BOOT_COMPLETED | DIRTY_SETTINGS | DIRTY_SCREEN_BRIGHTNESS_BOOST | DIRTY_VR_MODE_CHANGED | DIRTY_QUIESCENT)) != 0) { if ((dirty & DIRTY_QUIESCENT) != 0) { sQuiescent = false; } mDisplayPowerRequest.policy = getDesiredScreenPolicyLocked(); // Determine appropriate screen brightness and auto-brightness adjustments. Loading Loading @@ -2694,9 +2709,6 @@ public final class PowerManagerService extends SystemService mRequestWaitForNegativeProximity); mRequestWaitForNegativeProximity = false; if ((dirty & DIRTY_QUIESCENT) != 0) { sQuiescent = false; } if (DEBUG_SPEW) { Slog.d(TAG, "updateDisplayPowerStateLocked: mDisplayReady=" + mDisplayReady + ", policy=" + mDisplayPowerRequest.policy Loading
services/tests/servicestests/src/com/android/server/power/PowerManagerServiceTest.java +52 −0 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.ArgumentMatchers.eq; Loading Loading @@ -754,4 +755,55 @@ public class PowerManagerServiceTest { SystemClock.sleep(11); assertThat(mService.getWakefulness()).isEqualTo(WAKEFULNESS_ASLEEP); } @Test public void testBoot_ShouldBeAwake() throws Exception { createService(); startSystem(); assertThat(mService.getWakefulness()).isEqualTo(WAKEFULNESS_AWAKE); verify(mNotifierMock, never()).onWakefulnessChangeStarted(anyInt(), anyInt(), anyLong()); } @Test public void testBoot_DesiredScreenPolicyShouldBeBright() throws Exception { createService(); startSystem(); assertThat(mService.getDesiredScreenPolicyLocked()).isEqualTo( DisplayPowerRequest.POLICY_BRIGHT); } @Test public void testQuiescentBoot_ShouldBeAsleep() throws Exception { when(mSystemPropertiesMock.get(eq(SYSTEM_PROPERTY_QUIESCENT), any())).thenReturn("1"); createService(); startSystem(); assertThat(mService.getWakefulness()).isEqualTo(WAKEFULNESS_ASLEEP); verify(mNotifierMock).onWakefulnessChangeStarted(eq(WAKEFULNESS_ASLEEP), anyInt(), anyLong()); } @Test public void testQuiescentBoot_DesiredScreenPolicyShouldBeOff() throws Exception { when(mSystemPropertiesMock.get(eq(SYSTEM_PROPERTY_QUIESCENT), any())).thenReturn("1"); createService(); assertThat(mService.getDesiredScreenPolicyLocked()).isEqualTo( DisplayPowerRequest.POLICY_OFF); startSystem(); assertThat(mService.getDesiredScreenPolicyLocked()).isEqualTo( DisplayPowerRequest.POLICY_OFF); } @Test public void testQuiescentBoot_WakeUp_DesiredScreenPolicyShouldBeBright() throws Exception { when(mSystemPropertiesMock.get(eq(SYSTEM_PROPERTY_QUIESCENT), any())).thenReturn("1"); createService(); startSystem(); forceAwake(); assertThat(mService.getDesiredScreenPolicyLocked()).isEqualTo( DisplayPowerRequest.POLICY_BRIGHT); } }