|
|
|
|
@@ -319,7 +319,7 @@ public class PowerManagerServiceTest {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void startSystem() {
|
|
|
|
|
mService.systemReady();
|
|
|
|
|
mService.onBootPhase(SystemService.PHASE_SYSTEM_SERVICES_READY);
|
|
|
|
|
|
|
|
|
|
// Grab the BatteryReceiver
|
|
|
|
|
ArgumentCaptor<BatteryReceiver> batCaptor = ArgumentCaptor.forClass(BatteryReceiver.class);
|
|
|
|
|
@@ -419,7 +419,7 @@ public class PowerManagerServiceTest {
|
|
|
|
|
@Test
|
|
|
|
|
public void testGetDesiredScreenPolicy_WithVR() {
|
|
|
|
|
createService();
|
|
|
|
|
mService.systemReady();
|
|
|
|
|
startSystem();
|
|
|
|
|
// Brighten up the screen
|
|
|
|
|
mService.setWakefulnessLocked(Display.DEFAULT_DISPLAY_GROUP, WAKEFULNESS_AWAKE, 0, 0, 0, 0,
|
|
|
|
|
null, null);
|
|
|
|
|
@@ -607,8 +607,7 @@ public class PowerManagerServiceTest {
|
|
|
|
|
public void testWasDeviceIdleFor_true() {
|
|
|
|
|
int interval = 1000;
|
|
|
|
|
createService();
|
|
|
|
|
mService.systemReady();
|
|
|
|
|
mService.onBootPhase(SystemService.PHASE_BOOT_COMPLETED);
|
|
|
|
|
startSystem();
|
|
|
|
|
mService.onUserActivity();
|
|
|
|
|
advanceTime(interval + 1 /* just a little more */);
|
|
|
|
|
assertThat(mService.wasDeviceIdleForInternal(interval)).isTrue();
|
|
|
|
|
@@ -618,8 +617,7 @@ public class PowerManagerServiceTest {
|
|
|
|
|
public void testWasDeviceIdleFor_false() {
|
|
|
|
|
int interval = 1000;
|
|
|
|
|
createService();
|
|
|
|
|
mService.systemReady();
|
|
|
|
|
mService.onBootPhase(SystemService.PHASE_BOOT_COMPLETED);
|
|
|
|
|
startSystem();
|
|
|
|
|
mService.onUserActivity();
|
|
|
|
|
assertThat(mService.wasDeviceIdleForInternal(interval)).isFalse();
|
|
|
|
|
}
|
|
|
|
|
@@ -627,8 +625,7 @@ public class PowerManagerServiceTest {
|
|
|
|
|
@Test
|
|
|
|
|
public void testForceSuspend_putsDeviceToSleep() {
|
|
|
|
|
createService();
|
|
|
|
|
mService.systemReady();
|
|
|
|
|
mService.onBootPhase(SystemService.PHASE_BOOT_COMPLETED);
|
|
|
|
|
startSystem();
|
|
|
|
|
|
|
|
|
|
// Verify that we start awake
|
|
|
|
|
assertThat(mService.getGlobalWakefulnessLocked()).isEqualTo(WAKEFULNESS_AWAKE);
|
|
|
|
|
@@ -673,8 +670,7 @@ public class PowerManagerServiceTest {
|
|
|
|
|
//
|
|
|
|
|
// TEST STARTS HERE
|
|
|
|
|
//
|
|
|
|
|
mService.systemReady();
|
|
|
|
|
mService.onBootPhase(SystemService.PHASE_BOOT_COMPLETED);
|
|
|
|
|
startSystem();
|
|
|
|
|
|
|
|
|
|
// Verify that we start awake
|
|
|
|
|
assertThat(mService.getGlobalWakefulnessLocked()).isEqualTo(WAKEFULNESS_AWAKE);
|
|
|
|
|
@@ -772,7 +768,7 @@ public class PowerManagerServiceTest {
|
|
|
|
|
createService();
|
|
|
|
|
assertTrue(isAcquired[0]);
|
|
|
|
|
|
|
|
|
|
mService.systemReady();
|
|
|
|
|
mService.onBootPhase(SystemService.PHASE_SYSTEM_SERVICES_READY);
|
|
|
|
|
assertTrue(isAcquired[0]);
|
|
|
|
|
|
|
|
|
|
mService.onBootPhase(SystemService.PHASE_BOOT_COMPLETED);
|
|
|
|
|
@@ -1146,7 +1142,7 @@ public class PowerManagerServiceTest {
|
|
|
|
|
public void testQuiescentBoot_WakeKeyBeforeBootCompleted_AwakeAfterBootCompleted() {
|
|
|
|
|
when(mSystemPropertiesMock.get(eq(SYSTEM_PROPERTY_QUIESCENT), any())).thenReturn("1");
|
|
|
|
|
createService();
|
|
|
|
|
mService.systemReady();
|
|
|
|
|
startSystem();
|
|
|
|
|
|
|
|
|
|
mService.getBinderServiceInstance().wakeUp(mClock.now(),
|
|
|
|
|
PowerManager.WAKE_REASON_UNKNOWN, "testing IPowerManager.wakeUp()", "pkg.name");
|
|
|
|
|
@@ -1359,7 +1355,7 @@ public class PowerManagerServiceTest {
|
|
|
|
|
@Test
|
|
|
|
|
public void testSetPowerBoost_redirectsCallToNativeWrapper() {
|
|
|
|
|
createService();
|
|
|
|
|
mService.systemReady();
|
|
|
|
|
startSystem();
|
|
|
|
|
|
|
|
|
|
mService.getBinderServiceInstance().setPowerBoost(Boost.INTERACTION, 1234);
|
|
|
|
|
|
|
|
|
|
@@ -1369,7 +1365,7 @@ public class PowerManagerServiceTest {
|
|
|
|
|
@Test
|
|
|
|
|
public void testSetPowerMode_redirectsCallToNativeWrapper() {
|
|
|
|
|
createService();
|
|
|
|
|
mService.systemReady();
|
|
|
|
|
startSystem();
|
|
|
|
|
|
|
|
|
|
// Enabled launch boost in BatterySaverController to allow setting launch mode.
|
|
|
|
|
when(mBatterySaverControllerMock.isLaunchBoostDisabled()).thenReturn(false);
|
|
|
|
|
@@ -1385,7 +1381,7 @@ public class PowerManagerServiceTest {
|
|
|
|
|
@Test
|
|
|
|
|
public void testSetPowerMode_withLaunchBoostDisabledAndModeLaunch_ignoresCallToEnable() {
|
|
|
|
|
createService();
|
|
|
|
|
mService.systemReady();
|
|
|
|
|
startSystem();
|
|
|
|
|
|
|
|
|
|
// Disables launch boost in BatterySaverController.
|
|
|
|
|
when(mBatterySaverControllerMock.isLaunchBoostDisabled()).thenReturn(true);
|
|
|
|
|
@@ -1401,7 +1397,7 @@ public class PowerManagerServiceTest {
|
|
|
|
|
@Test
|
|
|
|
|
public void testSetPowerModeChecked_returnsNativeCallResult() {
|
|
|
|
|
createService();
|
|
|
|
|
mService.systemReady();
|
|
|
|
|
startSystem();
|
|
|
|
|
|
|
|
|
|
// Disables launch boost in BatterySaverController.
|
|
|
|
|
when(mBatterySaverControllerMock.isLaunchBoostDisabled()).thenReturn(true);
|
|
|
|
|
@@ -1564,7 +1560,7 @@ public class PowerManagerServiceTest {
|
|
|
|
|
@Test
|
|
|
|
|
public void testGetFullPowerSavePolicy_returnsStateMachineResult() {
|
|
|
|
|
createService();
|
|
|
|
|
mService.systemReady();
|
|
|
|
|
startSystem();
|
|
|
|
|
BatterySaverPolicyConfig mockReturnConfig = new BatterySaverPolicyConfig.Builder().build();
|
|
|
|
|
when(mBatterySaverStateMachineMock.getFullBatterySaverPolicy())
|
|
|
|
|
.thenReturn(mockReturnConfig);
|
|
|
|
|
@@ -1579,7 +1575,7 @@ public class PowerManagerServiceTest {
|
|
|
|
|
@Test
|
|
|
|
|
public void testSetFullPowerSavePolicy_callsStateMachine() {
|
|
|
|
|
createService();
|
|
|
|
|
mService.systemReady();
|
|
|
|
|
startSystem();
|
|
|
|
|
BatterySaverPolicyConfig mockSetPolicyConfig =
|
|
|
|
|
new BatterySaverPolicyConfig.Builder().build();
|
|
|
|
|
when(mBatterySaverStateMachineMock.setFullBatterySaverPolicy(any())).thenReturn(true);
|
|
|
|
|
@@ -1593,7 +1589,7 @@ public class PowerManagerServiceTest {
|
|
|
|
|
@Test
|
|
|
|
|
public void testLowPowerStandby_whenInactive_FgsWakeLockEnabled() {
|
|
|
|
|
createService();
|
|
|
|
|
mService.systemReady();
|
|
|
|
|
startSystem();
|
|
|
|
|
WakeLock wakeLock = acquireWakeLock("fgsWakeLock", PowerManager.PARTIAL_WAKE_LOCK);
|
|
|
|
|
mService.updateUidProcStateInternal(wakeLock.mOwnerUid, PROCESS_STATE_FOREGROUND_SERVICE);
|
|
|
|
|
mService.setDeviceIdleModeInternal(true);
|
|
|
|
|
@@ -1604,7 +1600,7 @@ public class PowerManagerServiceTest {
|
|
|
|
|
@Test
|
|
|
|
|
public void testLowPowerStandby_whenActive_FgsWakeLockDisabled() {
|
|
|
|
|
createService();
|
|
|
|
|
mService.systemReady();
|
|
|
|
|
startSystem();
|
|
|
|
|
WakeLock wakeLock = acquireWakeLock("fgsWakeLock", PowerManager.PARTIAL_WAKE_LOCK);
|
|
|
|
|
mService.updateUidProcStateInternal(wakeLock.mOwnerUid, PROCESS_STATE_FOREGROUND_SERVICE);
|
|
|
|
|
mService.setDeviceIdleModeInternal(true);
|
|
|
|
|
@@ -1616,7 +1612,7 @@ public class PowerManagerServiceTest {
|
|
|
|
|
@Test
|
|
|
|
|
public void testLowPowerStandby_whenActive_FgsWakeLockEnabledIfAllowlisted() {
|
|
|
|
|
createService();
|
|
|
|
|
mService.systemReady();
|
|
|
|
|
startSystem();
|
|
|
|
|
WakeLock wakeLock = acquireWakeLock("fgsWakeLock", PowerManager.PARTIAL_WAKE_LOCK);
|
|
|
|
|
mService.updateUidProcStateInternal(wakeLock.mOwnerUid, PROCESS_STATE_FOREGROUND_SERVICE);
|
|
|
|
|
mService.setDeviceIdleModeInternal(true);
|
|
|
|
|
@@ -1629,7 +1625,7 @@ public class PowerManagerServiceTest {
|
|
|
|
|
@Test
|
|
|
|
|
public void testLowPowerStandby_whenActive_BoundTopWakeLockDisabled() {
|
|
|
|
|
createService();
|
|
|
|
|
mService.systemReady();
|
|
|
|
|
startSystem();
|
|
|
|
|
WakeLock wakeLock = acquireWakeLock("BoundTopWakeLock", PowerManager.PARTIAL_WAKE_LOCK);
|
|
|
|
|
mService.updateUidProcStateInternal(wakeLock.mOwnerUid, PROCESS_STATE_BOUND_TOP);
|
|
|
|
|
mService.setDeviceIdleModeInternal(true);
|
|
|
|
|
|