Loading services/core/java/com/android/server/power/PowerManagerService.java +21 −9 Original line number Diff line number Diff line Loading @@ -120,7 +120,7 @@ public final class PowerManagerService extends SystemService implements Watchdog.Monitor { private static final String TAG = "PowerManagerService"; private static final boolean DEBUG = false; private static final boolean DEBUG = true; private static final boolean DEBUG_SPEW = DEBUG && true; // Message: Sent when a user activity timeout occurs to update the power state. Loading Loading @@ -1569,14 +1569,17 @@ public final class PowerManagerService extends SystemService return true; } private void setWakefulnessLocked(int wakefulness, int reason) { @VisibleForTesting void setWakefulnessLocked(int wakefulness, int reason) { if (mWakefulness != wakefulness) { mWakefulness = wakefulness; mWakefulnessChanging = true; mDirty |= DIRTY_WAKEFULNESS; if (mNotifier != null) { mNotifier.onWakefulnessChangeStarted(wakefulness, reason); } } } /** * Logs the time the device would have spent awake before user activity timeout, Loading Loading @@ -2432,11 +2435,8 @@ public final class PowerManagerService extends SystemService return value >= -1.0f && value <= 1.0f; } private int getDesiredScreenPolicyLocked() { if (mIsVrModeEnabled) { return DisplayPowerRequest.POLICY_VR; } @VisibleForTesting int getDesiredScreenPolicyLocked() { if (mWakefulness == WAKEFULNESS_ASLEEP || sQuiescent) { return DisplayPowerRequest.POLICY_OFF; } Loading @@ -2452,6 +2452,13 @@ public final class PowerManagerService extends SystemService // doze after screen off. This causes the screen off transition to be skipped. } // It is important that POLICY_VR check happens after the wakefulness checks above so // that VR-mode does not prevent displays from transitioning to the correct state when // dozing or sleeping. if (mIsVrModeEnabled) { return DisplayPowerRequest.POLICY_VR; } if ((mWakeLockSummary & WAKE_LOCK_SCREEN_BRIGHT) != 0 || (mUserActivitySummary & USER_ACTIVITY_SCREEN_BRIGHT) != 0 || !mBootCompleted Loading Loading @@ -3113,6 +3120,11 @@ public final class PowerManagerService extends SystemService } } @VisibleForTesting void setVrModeEnabled(boolean enabled) { mIsVrModeEnabled = enabled; } private void powerHintInternal(int hintId, int data) { nativeSendPowerHint(hintId, data); } Loading Loading @@ -3810,7 +3822,7 @@ public final class PowerManagerService extends SystemService synchronized (mLock) { if (mIsVrModeEnabled != enabled) { mIsVrModeEnabled = enabled; setVrModeEnabled(enabled); mDirty |= DIRTY_VR_MODE_CHANGED; updatePowerStateLocked(); } Loading services/tests/servicestests/src/com/android/server/power/PowerManagerServiceTest.java +33 −0 Original line number Diff line number Diff line Loading @@ -32,6 +32,10 @@ import org.junit.rules.TemporaryFolder; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import static android.os.PowerManagerInternal.WAKEFULNESS_ASLEEP; import static android.os.PowerManagerInternal.WAKEFULNESS_AWAKE; import static android.os.PowerManagerInternal.WAKEFULNESS_DOZING; import static android.os.PowerManagerInternal.WAKEFULNESS_DREAMING; import static com.google.common.truth.Truth.assertThat; import static org.mockito.Matchers.anyBoolean; import static org.mockito.Matchers.eq; Loading Loading @@ -92,4 +96,33 @@ public class PowerManagerServiceTest extends AndroidTestCase { int reason = mService.getLastShutdownReasonInternal(mTempReason); assertThat(reason).isEqualTo(PowerManager.SHUTDOWN_REASON_THERMAL_SHUTDOWN); } @SmallTest public void testGetDesiredScreenPolicy_WithVR() throws Exception { // Brighten up the screen mService.setWakefulnessLocked(WAKEFULNESS_AWAKE, 0); assertThat(mService.getDesiredScreenPolicyLocked()).isEqualTo( DisplayPowerRequest.POLICY_BRIGHT); // Move to VR mService.setVrModeEnabled(true); assertThat(mService.getDesiredScreenPolicyLocked()).isEqualTo( DisplayPowerRequest.POLICY_VR); // Then take a nap mService.setWakefulnessLocked(WAKEFULNESS_ASLEEP, 0); assertThat(mService.getDesiredScreenPolicyLocked()).isEqualTo( DisplayPowerRequest.POLICY_OFF); // Wake up to VR mService.setWakefulnessLocked(WAKEFULNESS_AWAKE, 0); assertThat(mService.getDesiredScreenPolicyLocked()).isEqualTo( DisplayPowerRequest.POLICY_VR); // And back to normal mService.setVrModeEnabled(false); assertThat(mService.getDesiredScreenPolicyLocked()).isEqualTo( DisplayPowerRequest.POLICY_BRIGHT); } } Loading
services/core/java/com/android/server/power/PowerManagerService.java +21 −9 Original line number Diff line number Diff line Loading @@ -120,7 +120,7 @@ public final class PowerManagerService extends SystemService implements Watchdog.Monitor { private static final String TAG = "PowerManagerService"; private static final boolean DEBUG = false; private static final boolean DEBUG = true; private static final boolean DEBUG_SPEW = DEBUG && true; // Message: Sent when a user activity timeout occurs to update the power state. Loading Loading @@ -1569,14 +1569,17 @@ public final class PowerManagerService extends SystemService return true; } private void setWakefulnessLocked(int wakefulness, int reason) { @VisibleForTesting void setWakefulnessLocked(int wakefulness, int reason) { if (mWakefulness != wakefulness) { mWakefulness = wakefulness; mWakefulnessChanging = true; mDirty |= DIRTY_WAKEFULNESS; if (mNotifier != null) { mNotifier.onWakefulnessChangeStarted(wakefulness, reason); } } } /** * Logs the time the device would have spent awake before user activity timeout, Loading Loading @@ -2432,11 +2435,8 @@ public final class PowerManagerService extends SystemService return value >= -1.0f && value <= 1.0f; } private int getDesiredScreenPolicyLocked() { if (mIsVrModeEnabled) { return DisplayPowerRequest.POLICY_VR; } @VisibleForTesting int getDesiredScreenPolicyLocked() { if (mWakefulness == WAKEFULNESS_ASLEEP || sQuiescent) { return DisplayPowerRequest.POLICY_OFF; } Loading @@ -2452,6 +2452,13 @@ public final class PowerManagerService extends SystemService // doze after screen off. This causes the screen off transition to be skipped. } // It is important that POLICY_VR check happens after the wakefulness checks above so // that VR-mode does not prevent displays from transitioning to the correct state when // dozing or sleeping. if (mIsVrModeEnabled) { return DisplayPowerRequest.POLICY_VR; } if ((mWakeLockSummary & WAKE_LOCK_SCREEN_BRIGHT) != 0 || (mUserActivitySummary & USER_ACTIVITY_SCREEN_BRIGHT) != 0 || !mBootCompleted Loading Loading @@ -3113,6 +3120,11 @@ public final class PowerManagerService extends SystemService } } @VisibleForTesting void setVrModeEnabled(boolean enabled) { mIsVrModeEnabled = enabled; } private void powerHintInternal(int hintId, int data) { nativeSendPowerHint(hintId, data); } Loading Loading @@ -3810,7 +3822,7 @@ public final class PowerManagerService extends SystemService synchronized (mLock) { if (mIsVrModeEnabled != enabled) { mIsVrModeEnabled = enabled; setVrModeEnabled(enabled); mDirty |= DIRTY_VR_MODE_CHANGED; updatePowerStateLocked(); } Loading
services/tests/servicestests/src/com/android/server/power/PowerManagerServiceTest.java +33 −0 Original line number Diff line number Diff line Loading @@ -32,6 +32,10 @@ import org.junit.rules.TemporaryFolder; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import static android.os.PowerManagerInternal.WAKEFULNESS_ASLEEP; import static android.os.PowerManagerInternal.WAKEFULNESS_AWAKE; import static android.os.PowerManagerInternal.WAKEFULNESS_DOZING; import static android.os.PowerManagerInternal.WAKEFULNESS_DREAMING; import static com.google.common.truth.Truth.assertThat; import static org.mockito.Matchers.anyBoolean; import static org.mockito.Matchers.eq; Loading Loading @@ -92,4 +96,33 @@ public class PowerManagerServiceTest extends AndroidTestCase { int reason = mService.getLastShutdownReasonInternal(mTempReason); assertThat(reason).isEqualTo(PowerManager.SHUTDOWN_REASON_THERMAL_SHUTDOWN); } @SmallTest public void testGetDesiredScreenPolicy_WithVR() throws Exception { // Brighten up the screen mService.setWakefulnessLocked(WAKEFULNESS_AWAKE, 0); assertThat(mService.getDesiredScreenPolicyLocked()).isEqualTo( DisplayPowerRequest.POLICY_BRIGHT); // Move to VR mService.setVrModeEnabled(true); assertThat(mService.getDesiredScreenPolicyLocked()).isEqualTo( DisplayPowerRequest.POLICY_VR); // Then take a nap mService.setWakefulnessLocked(WAKEFULNESS_ASLEEP, 0); assertThat(mService.getDesiredScreenPolicyLocked()).isEqualTo( DisplayPowerRequest.POLICY_OFF); // Wake up to VR mService.setWakefulnessLocked(WAKEFULNESS_AWAKE, 0); assertThat(mService.getDesiredScreenPolicyLocked()).isEqualTo( DisplayPowerRequest.POLICY_VR); // And back to normal mService.setVrModeEnabled(false); assertThat(mService.getDesiredScreenPolicyLocked()).isEqualTo( DisplayPowerRequest.POLICY_BRIGHT); } }