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

Commit cef6d598 authored by Sudheer Shanka's avatar Sudheer Shanka Committed by Android (Google) Code Review
Browse files

Merge "Add "defer-until-active" policy to TIME_TICK broadcast."

parents 612275f6 14b9df23
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -1933,8 +1933,9 @@ public class AlarmManagerService extends SystemService {
                    Intent.FLAG_RECEIVER_REGISTERED_ONLY
                            | Intent.FLAG_RECEIVER_FOREGROUND
                            | Intent.FLAG_RECEIVER_VISIBLE_TO_INSTANT_APPS);
            mTimeTickOptions = BroadcastOptions
                    .makeRemovingMatchingFilter(new IntentFilter(Intent.ACTION_TIME_TICK))
            mTimeTickOptions = BroadcastOptions.makeBasic()
                    .setDeliveryGroupPolicy(BroadcastOptions.DELIVERY_GROUP_POLICY_MOST_RECENT)
                    .setDeferUntilActive(true)
                    .toBundle();
            mTimeTickTrigger = new IAlarmListener.Stub() {
                @Override
@@ -4252,8 +4253,8 @@ public class AlarmManagerService extends SystemService {
                    }
                }
                // And send a TIME_TICK right now, since it is important to get the UI updated.
                mHandler.post(() ->
                        getContext().sendBroadcastAsUser(mTimeTickIntent, UserHandle.ALL));
                mHandler.post(() -> getContext().sendBroadcastAsUser(mTimeTickIntent,
                        UserHandle.ALL, null, mTimeTickOptions));
            } else {
                mNonInteractiveStartTime = nowELAPSED;
            }
+24 −2
Original line number Diff line number Diff line
@@ -112,7 +112,6 @@ import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.when;

import android.Manifest;
import android.app.ActivityManager;
@@ -1265,7 +1264,30 @@ public class AlarmManagerServiceTest {
        mService.interactiveStateChangedLocked(false);
        mService.interactiveStateChangedLocked(true);
        runnableCaptor.getValue().run();
        verify(mMockContext).sendBroadcastAsUser(mService.mTimeTickIntent, UserHandle.ALL);
        final ArgumentCaptor<Bundle> optionsCaptor = ArgumentCaptor.forClass(Bundle.class);
        verify(mMockContext).sendBroadcastAsUser(eq(mService.mTimeTickIntent), eq(UserHandle.ALL),
                isNull(), optionsCaptor.capture());
        verifyTimeTickBroadcastOptions(optionsCaptor.getValue());
    }

    @Test
    public void sendsTimeTickOnAlarmTrigger() throws Exception {
        final ArgumentCaptor<Runnable> runnableCaptor = ArgumentCaptor.forClass(Runnable.class);
        // Stubbing so the handler doesn't actually run the runnable.
        doReturn(true).when(mService.mHandler).post(runnableCaptor.capture());
        mService.mTimeTickTrigger.doAlarm(mock(IAlarmCompleteListener.class));
        runnableCaptor.getValue().run();
        final ArgumentCaptor<Bundle> optionsCaptor = ArgumentCaptor.forClass(Bundle.class);
        verify(mMockContext).sendBroadcastAsUser(eq(mService.mTimeTickIntent), eq(UserHandle.ALL),
                isNull(), optionsCaptor.capture());
        verifyTimeTickBroadcastOptions(optionsCaptor.getValue());
    }

    private void verifyTimeTickBroadcastOptions(Bundle actualOptionsBundle) {
        final BroadcastOptions actualOptions = new BroadcastOptions(actualOptionsBundle);
        assertEquals(BroadcastOptions.DELIVERY_GROUP_POLICY_MOST_RECENT,
                actualOptions.getDeliveryGroupPolicy());
        assertTrue(actualOptions.isDeferUntilActive());
    }

    @Test