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

Commit 09f2a480 authored by Julia Reynolds's avatar Julia Reynolds
Browse files

Don't let allowlist override user choice

Test: PreferencesHelperTest
Test: NotificationManagerServiceTest
Test: NotificationManagerTest
Flag: android.app.api_rich_ongoing
Fixes: 367741426
Change-Id: Id2c8ea81d0787a89545ac3636ab6431441295101
parent d4ea4434
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -258,7 +258,7 @@ interface INotificationManager
    @EnforcePermission(allOf={"INTERACT_ACROSS_USERS", "ACCESS_NOTIFICATIONS"})
    void unregisterCallNotificationEventListener(String packageName, in UserHandle userHandle, in ICallNotificationEventCallback listener);

    void setCanBePromoted(String pkg, int uid, boolean promote);
    void setCanBePromoted(String pkg, int uid, boolean promote, boolean fromUser);
    boolean appCanBePromoted(String pkg, int uid);
    boolean canBePromoted(String pkg);
}
+1 −1
Original line number Diff line number Diff line
@@ -976,7 +976,7 @@ public class NotificationManager {
    public void setCanPostPromotedNotifications(@NonNull String pkg, int uid, boolean allowed) {
        INotificationManager service = getService();
        try {
            service.setCanBePromoted(pkg, uid, allowed);
            service.setCanBePromoted(pkg, uid, allowed, true);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
+6 −2
Original line number Diff line number Diff line
@@ -4136,14 +4136,18 @@ public class NotificationManagerService extends SystemService {
        }
        /**
         * Any changes from SystemUI or Settings should be fromUser == true. Any changes the
         * allowlist should be fromUser == false.
         */
        @Override
        @FlaggedApi(android.app.Flags.FLAG_API_RICH_ONGOING)
        public void setCanBePromoted(String pkg, int uid, boolean promote) {
        public void setCanBePromoted(String pkg, int uid, boolean promote, boolean fromUser) {
            checkCallerIsSystemOrSystemUiOrShell();
            if (!android.app.Flags.apiRichOngoing()) {
                return;
            }
            boolean changed = mPreferencesHelper.setCanBePromoted(pkg, uid, promote);
            boolean changed = mPreferencesHelper.setCanBePromoted(pkg, uid, promote, fromUser);
            if (changed) {
                // check for pending/posted notifs from this app and update the flag
                synchronized (mNotificationLock) {
+15 −5
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ import static com.android.internal.util.FrameworkStatsLog.PACKAGE_NOTIFICATION_P
import static com.android.internal.util.FrameworkStatsLog.PACKAGE_NOTIFICATION_PREFERENCES__FSI_STATE__DENIED;
import static com.android.internal.util.FrameworkStatsLog.PACKAGE_NOTIFICATION_PREFERENCES__FSI_STATE__GRANTED;
import static com.android.internal.util.FrameworkStatsLog.PACKAGE_NOTIFICATION_PREFERENCES__FSI_STATE__NOT_REQUESTED;
import static com.android.server.notification.PreferencesHelper.LockableAppFields.USER_LOCKED_PROMOTABLE;

import android.annotation.FlaggedApi;
import android.annotation.IntDef;
@@ -192,10 +193,13 @@ public class PreferencesHelper implements RankingConfig {
    /**
     * All user-lockable fields for a given application.
     */
    @IntDef({LockableAppFields.USER_LOCKED_IMPORTANCE})
    @IntDef({LockableAppFields.USER_LOCKED_IMPORTANCE,
            LockableAppFields.USER_LOCKED_BUBBLE,
            LockableAppFields.USER_LOCKED_PROMOTABLE})
    public @interface LockableAppFields {
        int USER_LOCKED_IMPORTANCE = 0x00000001;
        int USER_LOCKED_BUBBLE = 0x00000002;
        int USER_LOCKED_PROMOTABLE = 0x00000004;
    }

    private final Object mLock = new Object();
@@ -858,15 +862,21 @@ public class PreferencesHelper implements RankingConfig {
    }

    @FlaggedApi(android.app.Flags.FLAG_API_RICH_ONGOING)
    public boolean setCanBePromoted(String packageName, int uid, boolean promote) {
    public boolean setCanBePromoted(String packageName, int uid, boolean promote,
            boolean fromUser) {
        boolean changed = false;
        synchronized (mLock) {
            PackagePreferences pkgPrefs = getOrCreatePackagePreferencesLocked(packageName, uid);
            if (fromUser || ((pkgPrefs.lockedAppFields & USER_LOCKED_PROMOTABLE) == 0)) {
                if (pkgPrefs.canHavePromotedNotifs != promote) {
                    pkgPrefs.canHavePromotedNotifs = promote;
                    if (fromUser) {
                        pkgPrefs.lockedAppFields |= USER_LOCKED_PROMOTABLE;
                    }
                    changed = true;
                }
            }
        }
        // no need to send a ranking update because we need to update the flag value on all pending
        // and posted notifs and NMS will take care of that
        return changed;
+10 −10
Original line number Diff line number Diff line
@@ -16611,7 +16611,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
        mService.addNotification(r);
        mService.addEnqueuedNotification(r1);
        mBinderService.setCanBePromoted(mPkg, mUid, true);
        mBinderService.setCanBePromoted(mPkg, mUid, true, true);
        waitForIdle();
@@ -16651,9 +16651,9 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
        mService.addNotification(r);
        mBinderService.setCanBePromoted(mPkg, mUid, true);
        mBinderService.setCanBePromoted(mPkg, mUid, true, true);
        waitForIdle();
        mBinderService.setCanBePromoted(mPkg, mUid, true);
        mBinderService.setCanBePromoted(mPkg, mUid, true, true);
        waitForIdle();
        ArgumentCaptor<NotificationRecord> captor =
@@ -16668,7 +16668,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
        mContext.getTestablePermissions().setPermission(
                android.Manifest.permission.USE_COLORIZED_NOTIFICATIONS, PERMISSION_GRANTED);
        // start from true state
        mBinderService.setCanBePromoted(mPkg, mUid, true);
        mBinderService.setCanBePromoted(mPkg, mUid, true, true);
        // qualifying posted notification
        Notification n = new Notification.Builder(mContext, mTestNotificationChannel.getId())
@@ -16709,7 +16709,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
        mService.addNotification(r);
        mService.addEnqueuedNotification(r1);
        mBinderService.setCanBePromoted(mPkg, mUid, false);
        mBinderService.setCanBePromoted(mPkg, mUid, false, true);
        waitForIdle();
@@ -16733,7 +16733,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
        mContext.getTestablePermissions().setPermission(
                android.Manifest.permission.USE_COLORIZED_NOTIFICATIONS, PERMISSION_GRANTED);
        // start from true state
        mBinderService.setCanBePromoted(mPkg, mUid, true);
        mBinderService.setCanBePromoted(mPkg, mUid, true, true);
        // qualifying posted notification
        Notification n = new Notification.Builder(mContext, mTestNotificationChannel.getId())
@@ -16751,9 +16751,9 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
        mService.addNotification(r);
        mBinderService.setCanBePromoted(mPkg, mUid, false);
        mBinderService.setCanBePromoted(mPkg, mUid, false, true);
        waitForIdle();
        mBinderService.setCanBePromoted(mPkg, mUid, false);
        mBinderService.setCanBePromoted(mPkg, mUid, false, true);
        waitForIdle();
        ArgumentCaptor<NotificationRecord> captor =
@@ -16765,7 +16765,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
    @Test
    @EnableFlags(android.app.Flags.FLAG_API_RICH_ONGOING)
    public void testPostPromotableNotification() throws Exception {
        mBinderService.setCanBePromoted(mPkg, mUid, true);
        mBinderService.setCanBePromoted(mPkg, mUid, true, true);
        assertThat(mBinderService.appCanBePromoted(mPkg, mUid)).isTrue();
        mContext.getTestablePermissions().setPermission(
                android.Manifest.permission.USE_COLORIZED_NOTIFICATIONS, PERMISSION_GRANTED);
@@ -16823,7 +16823,7 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
    @Test
    @EnableFlags(android.app.Flags.FLAG_API_RICH_ONGOING)
    public void testPostPromotableNotification_unimportantNotification() throws Exception {
        mBinderService.setCanBePromoted(mPkg, mUid, true);
        mBinderService.setCanBePromoted(mPkg, mUid, true, true);
        mContext.getTestablePermissions().setPermission(
                android.Manifest.permission.USE_COLORIZED_NOTIFICATIONS, PERMISSION_GRANTED);
        Notification n = new Notification.Builder(mContext, mMinChannel.getId())
Loading