Merge "Initializing charging state in AlarmManager" into tm-dev

This commit is contained in:
TreeHugger Robot
2022-03-24 21:25:25 +00:00
committed by Android (Google) Code Review
2 changed files with 11 additions and 1 deletions

View File

@@ -348,7 +348,8 @@ public class AlarmManagerService extends SystemService {
new SparseArray<>();
private AppStateTrackerImpl mAppStateTracker;
private boolean mAppStandbyParole;
@VisibleForTesting
boolean mAppStandbyParole;
/**
* A container to keep rolling window history of previous times when an alarm was sent to
@@ -1891,6 +1892,9 @@ public class AlarmManagerService extends SystemService {
(AppStateTrackerImpl) LocalServices.getService(AppStateTracker.class);
mAppStateTracker.addListener(mForceAppStandbyListener);
final BatteryManager bm = getContext().getSystemService(BatteryManager.class);
mAppStandbyParole = bm.isCharging();
mClockReceiver.scheduleTimeTickEvent();
mClockReceiver.scheduleDateChangedEvent();
}

View File

@@ -217,6 +217,8 @@ public class AlarmManagerServiceTest {
@Mock
private AppOpsManager mAppOpsManager;
@Mock
private BatteryManager mBatteryManager;
@Mock
private DeviceIdleInternal mDeviceIdleInternal;
@Mock
private PermissionManagerServiceInternal mPermissionManagerInternal;
@@ -453,6 +455,7 @@ public class AlarmManagerServiceTest {
eq(Manifest.permission.USE_EXACT_ALARM), anyInt(), anyInt(), anyString()));
when(mMockContext.getSystemService(Context.APP_OPS_SERVICE)).thenReturn(mAppOpsManager);
when(mMockContext.getSystemService(BatteryManager.class)).thenReturn(mBatteryManager);
registerAppIds(new String[]{TEST_CALLING_PACKAGE},
new Integer[]{UserHandle.getAppId(TEST_CALLING_UID)});
@@ -477,6 +480,8 @@ public class AlarmManagerServiceTest {
// Other boot phases don't matter
mService.onBootPhase(SystemService.PHASE_SYSTEM_SERVICES_READY);
verify(mBatteryManager).isCharging();
setTareEnabled(false);
mAppStandbyWindow = mService.mConstants.APP_STANDBY_WINDOW;
mAllowWhileIdleWindow = mService.mConstants.ALLOW_WHILE_IDLE_WINDOW;
@@ -1101,6 +1106,7 @@ public class AlarmManagerServiceTest {
new Intent(parole ? BatteryManager.ACTION_CHARGING
: BatteryManager.ACTION_DISCHARGING));
assertAndHandleMessageSync(CHARGING_STATUS_CHANGED);
assertEquals(parole, mService.mAppStandbyParole);
}
@Test