Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3675a20f authored by Suprabh Shukla's avatar Suprabh Shukla
Browse files

Initializing charging state in AlarmManager

The charging state denoted by mAppStandbyParole was always false, which
would be incorrect if the device was plugged in on boot.

Test: atest FrameworksMockingServicesTests:AlarmManagerServiceTest

Fixes: 187500081
Change-Id: I422aca3c181733ba908e70decbbd43d62723337a
parent 162255ae
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -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();
            }
+6 −0
Original line number Diff line number Diff line
@@ -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