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

Commit 5e42441a authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Revert "Clear the BAL allowlist duration"" into main

parents 4d0fb74a 2e971059
Loading
Loading
Loading
Loading
+1 −11
Original line number Diff line number Diff line
@@ -305,10 +305,6 @@ public final class PendingIntentRecord extends IIntentSender.Stub {
        this.stringName = null;
    }

    @VisibleForTesting TempAllowListDuration getAllowlistDurationLocked(IBinder allowlistToken) {
        return mAllowlistDuration.get(allowlistToken);
    }

    void setAllowBgActivityStarts(IBinder token, int flags) {
        if (token == null) return;
        if ((flags & FLAG_ACTIVITY_SENDER) != 0) {
@@ -327,12 +323,6 @@ public final class PendingIntentRecord extends IIntentSender.Stub {
        mAllowBgActivityStartsForActivitySender.remove(token);
        mAllowBgActivityStartsForBroadcastSender.remove(token);
        mAllowBgActivityStartsForServiceSender.remove(token);
        if (mAllowlistDuration != null) {
            mAllowlistDuration.remove(token);
            if (mAllowlistDuration.isEmpty()) {
                mAllowlistDuration = null;
            }
        }
    }

    public void registerCancelListenerLocked(IResultReceiver receiver) {
@@ -713,7 +703,7 @@ public final class PendingIntentRecord extends IIntentSender.Stub {
        return res;
    }

    @VisibleForTesting BackgroundStartPrivileges getBackgroundStartPrivilegesForActivitySender(
    private BackgroundStartPrivileges getBackgroundStartPrivilegesForActivitySender(
            IBinder allowlistToken) {
        return mAllowBgActivityStartsForActivitySender.contains(allowlistToken)
                ? BackgroundStartPrivileges.allowBackgroundActivityStarts(allowlistToken)
+0 −34
Original line number Diff line number Diff line
@@ -16,8 +16,6 @@

package com.android.server.am;

import static android.os.PowerWhitelistManager.REASON_NOTIFICATION_SERVICE;
import static android.os.PowerWhitelistManager.TEMPORARY_ALLOWLIST_TYPE_FOREGROUND_SERVICE_ALLOWED;
import static android.os.Process.INVALID_UID;

import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn;
@@ -29,11 +27,9 @@ import static com.android.server.am.PendingIntentRecord.CANCEL_REASON_OWNER_CANC
import static com.android.server.am.PendingIntentRecord.CANCEL_REASON_OWNER_FORCE_STOPPED;
import static com.android.server.am.PendingIntentRecord.CANCEL_REASON_SUPERSEDED;
import static com.android.server.am.PendingIntentRecord.CANCEL_REASON_USER_STOPPED;
import static com.android.server.am.PendingIntentRecord.FLAG_ACTIVITY_SENDER;
import static com.android.server.am.PendingIntentRecord.cancelReasonToString;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.eq;
@@ -43,11 +39,9 @@ import static org.mockito.Mockito.when;
import android.app.ActivityManager;
import android.app.ActivityManagerInternal;
import android.app.AppGlobals;
import android.app.BackgroundStartPrivileges;
import android.app.PendingIntent;
import android.content.Intent;
import android.content.pm.IPackageManager;
import android.os.Binder;
import android.os.Looper;
import android.os.UserHandle;

@@ -185,34 +179,6 @@ public class PendingIntentControllerTest {
        }
    }

    @Test
    public void testClearAllowBgActivityStartsClearsToken() {
        final PendingIntentRecord pir = createPendingIntentRecord(0);
        Binder token = new Binder();
        pir.setAllowBgActivityStarts(token, FLAG_ACTIVITY_SENDER);
        assertEquals(BackgroundStartPrivileges.allowBackgroundActivityStarts(token),
                pir.getBackgroundStartPrivilegesForActivitySender(token));
        pir.clearAllowBgActivityStarts(token);
        assertEquals(BackgroundStartPrivileges.NONE,
                pir.getBackgroundStartPrivilegesForActivitySender(token));
    }

    @Test
    public void testClearAllowBgActivityStartsClearsDuration() {
        final PendingIntentRecord pir = createPendingIntentRecord(0);
        Binder token = new Binder();
        pir.setAllowlistDurationLocked(token, 1000,
                TEMPORARY_ALLOWLIST_TYPE_FOREGROUND_SERVICE_ALLOWED, REASON_NOTIFICATION_SERVICE,
                "NotificationManagerService");
        PendingIntentRecord.TempAllowListDuration allowlistDurationLocked =
                pir.getAllowlistDurationLocked(token);
        assertEquals(1000, allowlistDurationLocked.duration);
        pir.clearAllowBgActivityStarts(token);
        PendingIntentRecord.TempAllowListDuration allowlistDurationLockedAfterClear =
                pir.getAllowlistDurationLocked(token);
        assertNull(allowlistDurationLockedAfterClear);
    }

    private void assertCancelReason(int expectedReason, int actualReason) {
        final String errMsg = "Expected: " + cancelReasonToString(expectedReason)
                + "; Actual: " + cancelReasonToString(actualReason);