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

Commit 4440d49f authored by Jeff DeCew's avatar Jeff DeCew
Browse files

Allow use of CallStyle even if user denied FullScreenIntent permission to app.

Change-Id: I693e98e3d8ad77bb821903bd4b6eba2b48cf562a
Fixes: 278770218
Test: atest NotificationManagerServiceTest
parent b5c0e284
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -6986,7 +6986,7 @@ public class Notification implements Parcelable
     */
    public boolean isColorized() {
        return extras.getBoolean(EXTRA_COLORIZED)
                && (hasColorizedPermission() || isForegroundService());
                && (hasColorizedPermission() || isFgsOrUij());
    }
    /**
+4 −4
Original line number Diff line number Diff line
@@ -7205,12 +7205,12 @@ public class NotificationManagerService extends SystemService {
        }
        if (n.isStyle(Notification.CallStyle.class)) {
            boolean isForegroundService = (n.flags & FLAG_FOREGROUND_SERVICE) != 0;
            boolean hasFullScreenIntent = n.fullScreenIntent != null;
            if (!isForegroundService && !hasFullScreenIntent) {
            boolean requestedFullScreenIntent = (n.flags & FLAG_FSI_REQUESTED_BUT_DENIED) != 0;
            if (!n.isFgsOrUij() && !hasFullScreenIntent && !requestedFullScreenIntent) {
                throw new IllegalArgumentException(r.getKey() + " Not posted."
                        + " CallStyle notifications must either be for a foreground Service or"
                        + " use a fullScreenIntent.");
                        + " CallStyle notifications must be for a foreground service or"
                        + " user initated job or use a fullScreenIntent.");
            }
        }
+84 −0
Original line number Diff line number Diff line
@@ -10565,6 +10565,90 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
        assertFalse(n.hasColorizedPermission());
    }
    @Test
    public void checkCallStyleNotification_withoutAnyValidUseCase_throws() throws Exception {
        Person person = new Person.Builder().setName("caller").build();
        Notification n = new Notification.Builder(mContext, "test")
                .setStyle(Notification.CallStyle.forOngoingCall(
                        person, mock(PendingIntent.class)))
                .build();
        StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, 8, "tag", mUid, 0,
                n, UserHandle.getUserHandleForUid(mUid), null, 0);
        NotificationRecord r = new NotificationRecord(mContext, sbn, mTestNotificationChannel);
        try {
            mService.checkDisqualifyingFeatures(r.getUserId(), r.getUid(),
                    r.getSbn().getId(), r.getSbn().getTag(), r, false);
            assertFalse("CallStyle should not be allowed without a valid use case", true);
        } catch (IllegalArgumentException error) {
            assertThat(error.getMessage()).contains("CallStyle");
        }
    }
    @Test
    public void checkCallStyleNotification_allowedForFgs() throws Exception {
        Person person = new Person.Builder().setName("caller").build();
        Notification n = new Notification.Builder(mContext, "test")
                .setFlag(FLAG_FOREGROUND_SERVICE, true)
                .setStyle(Notification.CallStyle.forOngoingCall(
                        person, mock(PendingIntent.class)))
                .build();
        StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, 8, "tag", mUid, 0,
                n, UserHandle.getUserHandleForUid(mUid), null, 0);
        NotificationRecord r = new NotificationRecord(mContext, sbn, mTestNotificationChannel);
        assertThat(mService.checkDisqualifyingFeatures(r.getUserId(), r.getUid(),
                r.getSbn().getId(), r.getSbn().getTag(), r, false)).isTrue();
    }
    @Test
    public void checkCallStyleNotification_allowedForUij() throws Exception {
        Person person = new Person.Builder().setName("caller").build();
        Notification n = new Notification.Builder(mContext, "test")
                .setFlag(FLAG_USER_INITIATED_JOB, true)
                .setStyle(Notification.CallStyle.forOngoingCall(
                        person, mock(PendingIntent.class)))
                .build();
        StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, 8, "tag", mUid, 0,
                n, UserHandle.getUserHandleForUid(mUid), null, 0);
        NotificationRecord r = new NotificationRecord(mContext, sbn, mTestNotificationChannel);
        assertThat(mService.checkDisqualifyingFeatures(r.getUserId(), r.getUid(),
                r.getSbn().getId(), r.getSbn().getTag(), r, false)).isTrue();
    }
    @Test
    public void checkCallStyleNotification_allowedForFsiAllowed() throws Exception {
        Person person = new Person.Builder().setName("caller").build();
        Notification n = new Notification.Builder(mContext, "test")
                .setFullScreenIntent(mock(PendingIntent.class), true)
                .setStyle(Notification.CallStyle.forOngoingCall(
                        person, mock(PendingIntent.class)))
                .build();
        StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, 8, "tag", mUid, 0,
                n, UserHandle.getUserHandleForUid(mUid), null, 0);
        NotificationRecord r = new NotificationRecord(mContext, sbn, mTestNotificationChannel);
        assertThat(mService.checkDisqualifyingFeatures(r.getUserId(), r.getUid(),
                r.getSbn().getId(), r.getSbn().getTag(), r, false)).isTrue();
    }
    @Test
    public void checkCallStyleNotification_allowedForFsiDenied() throws Exception {
        Person person = new Person.Builder().setName("caller").build();
        Notification n = new Notification.Builder(mContext, "test")
                .setFlag(Notification.FLAG_FSI_REQUESTED_BUT_DENIED, true)
                .setStyle(Notification.CallStyle.forOngoingCall(
                        person, mock(PendingIntent.class)))
                .build();
        StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, 8, "tag", mUid, 0,
                n, UserHandle.getUserHandleForUid(mUid), null, 0);
        NotificationRecord r = new NotificationRecord(mContext, sbn, mTestNotificationChannel);
        assertThat(mService.checkDisqualifyingFeatures(r.getUserId(), r.getUid(),
                r.getSbn().getId(), r.getSbn().getTag(), r, false)).isTrue();
    }
    @Test
    public void fixSystemNotification_withOnGoingFlag_shouldBeDismissible()
            throws Exception {