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

Commit 116ec3b9 authored by Suprabh Shukla's avatar Suprabh Shukla
Browse files

RESTRICT AUTOMERGE Allowlist alarm-clock alarms from pre-S apps for FGS

FGS starts are allowed by default to apps targeting pre-S sdks. However,
on update their alarms may start getting denied if the app could not
reset its alarms.
Explicitly adding them to the allowlist to avoid this problem.

Test: atest FrameworksMockingServicesTests:AlarmManagerServiceTest
Test: Manual, using steps listed in b/238407723

Bug: 239098759
Bug: 238407723
Change-Id: I895901f0c870b161a8a4df92ebe93c873a55abc9
Merged-In: I895901f0c870b161a8a4df92ebe93c873a55abc9
parent 572a3587
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -2523,7 +2523,11 @@ public class AlarmManagerService extends SystemService {
                    changeDisabled = true;
                    needsPermission = false;
                    lowerQuota = allowWhileIdle;
                    idleOptions = allowWhileIdle ? mOptsWithFgs.toBundle() : null;
                    idleOptions = (allowWhileIdle || (alarmClock != null))
                        // This avoids exceptions on existing alarms when the app upgrades to
                        // target S. Note that FGS from pre-S apps isn't restricted anyway.
                        ? mOptsWithFgs.toBundle()
                        : null;
                }
                if (needsPermission && !hasScheduleExactAlarmInternal(callingPackage, callingUid)) {
                    if (!isExemptFromExactAlarmPermission(callingUid)) {
+7 −2
Original line number Diff line number Diff line
@@ -2204,10 +2204,15 @@ public class AlarmManagerServiceTest {
        mBinder.set(TEST_CALLING_PACKAGE, RTC_WAKEUP, 1234, WINDOW_EXACT, 0, 0,
                alarmPi, null, null, null, alarmClock);

        final ArgumentCaptor<Bundle> bundleCaptor = ArgumentCaptor.forClass(Bundle.class);
        verify(mService).setImpl(eq(RTC_WAKEUP), eq(1234L), eq(WINDOW_EXACT), eq(0L),
                eq(alarmPi), isNull(), isNull(), eq(FLAG_STANDALONE | FLAG_WAKE_FROM_IDLE),
                isNull(), eq(alarmClock), eq(TEST_CALLING_UID), eq(TEST_CALLING_PACKAGE), isNull(),
                eq(EXACT_ALLOW_REASON_COMPAT));
                isNull(), eq(alarmClock), eq(TEST_CALLING_UID), eq(TEST_CALLING_PACKAGE),
                bundleCaptor.capture(), eq(EXACT_ALLOW_REASON_COMPAT));

        final BroadcastOptions idleOptions = new BroadcastOptions(bundleCaptor.getValue());
        final int type = idleOptions.getTemporaryAppAllowlistType();
        assertEquals(TEMPORARY_ALLOWLIST_TYPE_FOREGROUND_SERVICE_ALLOWED, type);
    }

    @Test