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

Commit cc03ec43 authored by Matías Hernández's avatar Matías Hernández Committed by Automerger Merge Worker
Browse files

Merge "Fix notifications containing null entries in actions" into tm-qpr-dev...

Merge "Fix notifications containing null entries in actions" into tm-qpr-dev am: d56f705a am: c58f9946

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/21154285



Change-Id: If0d5f6c1ba5610e27426da8bde5bd87c3651de36
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 99c20c8b c58f9946
Loading
Loading
Loading
Loading
+25 −0
Original line number Diff line number Diff line
@@ -6707,6 +6707,31 @@ public class NotificationManagerService extends SystemService {
            }
        }
        // Ensure all actions are present
        if (notification.actions != null) {
            boolean hasNullActions = false;
            int nActions = notification.actions.length;
            for (int i = 0; i < nActions; i++) {
                if (notification.actions[i] == null) {
                    hasNullActions = true;
                    break;
                }
            }
            if (hasNullActions) {
                ArrayList<Notification.Action> nonNullActions = new ArrayList<>();
                for (int i = 0; i < nActions; i++) {
                    if (notification.actions[i] != null) {
                        nonNullActions.add(notification.actions[i]);
                    }
                }
                if (nonNullActions.size() != 0) {
                    notification.actions = nonNullActions.toArray(new Notification.Action[0]);
                } else {
                    notification.actions = null;
                }
            }
        }
        // Ensure CallStyle has all the correct actions
        if (notification.isStyle(Notification.CallStyle.class)) {
            Notification.Builder builder =
+40 −0
Original line number Diff line number Diff line
@@ -1645,6 +1645,46 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
                FLAG_FOREGROUND_SERVICE | FLAG_CAN_COLORIZE | FLAG_NO_CLEAR | FLAG_ONGOING_EVENT);
    }

    @Test
    public void testEnqueueNotificationWithTag_nullAction_fixed() throws Exception {
        Notification n = new Notification.Builder(mContext, mTestNotificationChannel.getId())
                .setContentTitle("foo")
                .setSmallIcon(android.R.drawable.sym_def_app_icon)
                .addAction(new Notification.Action.Builder(null, "one", null).build())
                .addAction(new Notification.Action.Builder(null, "two", null).build())
                .addAction(new Notification.Action.Builder(null, "three", null).build())
                .build();
        n.actions[1] = null;

        mBinderService.enqueueNotificationWithTag(PKG, PKG, "tag", 0, n, 0);
        waitForIdle();

        StatusBarNotification[] posted = mBinderService.getActiveNotifications(PKG);
        assertThat(posted).hasLength(1);
        assertThat(posted[0].getNotification().actions).hasLength(2);
        assertThat(posted[0].getNotification().actions[0].title.toString()).isEqualTo("one");
        assertThat(posted[0].getNotification().actions[1].title.toString()).isEqualTo("three");
    }

    @Test
    public void testEnqueueNotificationWithTag_allNullActions_fixed() throws Exception {
        Notification n = new Notification.Builder(mContext, mTestNotificationChannel.getId())
                .setContentTitle("foo")
                .setSmallIcon(android.R.drawable.sym_def_app_icon)
                .addAction(new Notification.Action.Builder(null, "one", null).build())
                .addAction(new Notification.Action.Builder(null, "two", null).build())
                .build();
        n.actions[0] = null;
        n.actions[1] = null;

        mBinderService.enqueueNotificationWithTag(PKG, PKG, "tag", 0, n, 0);
        waitForIdle();

        StatusBarNotification[] posted = mBinderService.getActiveNotifications(PKG);
        assertThat(posted).hasLength(1);
        assertThat(posted[0].getNotification().actions).isNull();
    }

    @Test
    public void testCancelNonexistentNotification() throws Exception {
        mBinderService.cancelNotificationWithTag(PKG, PKG,