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

Commit 34117946 authored by Julia Reynolds's avatar Julia Reynolds Committed by Android (Google) Code Review
Browse files

Merge "Fix tests and align error logging" into main

parents 923f969d 0e0f231a
Loading
Loading
Loading
Loading
+9 −5
Original line number Diff line number Diff line
@@ -11953,8 +11953,10 @@ public class NotificationManagerService extends SystemService {
                            assistant.onNotificationEnqueuedWithChannel(sbnHolder, r.getChannel(),
                                    update);
                        }
                    } catch (DeadObjectException ex) {
                        Slog.wtf(TAG, "unable to notify assistant (enqueued): " + info, ex);
                    } catch (RemoteException ex) {
                        Slog.e(TAG, "unable to notify assistant (enqueued): " + assistant, ex);
                        Slog.e(TAG, "unable to notify assistant (enqueued): " + info, ex);
                    }
                }
            }
@@ -12075,19 +12077,21 @@ public class NotificationManagerService extends SystemService {
                    r.getSbn(),
                    r.getNotificationType(),
                    true /* sameUserOnly */,
                    (assistant, sbnToPost) -> {
                    (info, sbnToPost) -> {
                        try {
                            if (android.app.Flags.noSbnholder()) {
                                assistant.onNotificationSnoozedUntilContextFull(
                                info.onNotificationSnoozedUntilContextFull(
                                        sbnToPost, snoozeCriterionId);
                            } else {
                                final StatusBarNotificationHolder sbnHolder =
                                        new StatusBarNotificationHolder(sbnToPost);
                                assistant.onNotificationSnoozedUntilContext(
                                info.onNotificationSnoozedUntilContext(
                                        sbnHolder, snoozeCriterionId);
                            }
                        } catch (DeadObjectException ex) {
                            Slog.wtf(TAG, "unable to notify assistant (snoozed): " + info, ex);
                        } catch (RemoteException ex) {
                            Slog.e(TAG, "unable to notify assistant (snoozed): " + assistant, ex);
                            Slog.e(TAG, "unable to notify assistant (snoozed): " + info, ex);
                        }
                    });
        }
+51 −17
Original line number Diff line number Diff line
@@ -907,10 +907,18 @@ public class NotificationListenersTest extends UiServiceTestCase {
        ArgumentCaptor<Runnable> runnableCaptor = ArgumentCaptor.forClass(Runnable.class);
        verify(mNm.mHandler, times(1)).post(runnableCaptor.capture());
        runnableCaptor.getValue().run();
        StatusBarNotification sbnResult = null;
        if (android.app.Flags.noSbnholder()) {
            ArgumentCaptor<StatusBarNotification> sbnCaptor =
                    ArgumentCaptor.forClass(StatusBarNotification.class);
            verify(sysuiListener, times(1)).onNotificationPostedFull(sbnCaptor.capture(), any());
            sbnResult = sbnCaptor.getValue();
        } else {
            ArgumentCaptor<IStatusBarNotificationHolder> sbnCaptor =
                    ArgumentCaptor.forClass(IStatusBarNotificationHolder.class);
            verify(sysuiListener, times(1)).onNotificationPosted(sbnCaptor.capture(), any());
        StatusBarNotification sbnResult = sbnCaptor.getValue().get();
            sbnResult = sbnCaptor.getValue().get();
        }
        assertThat(sbnResult.getNotification()
                .extras.getCharSequence(Notification.EXTRA_TITLE).toString())
                .isEqualTo("new title");
@@ -920,7 +928,7 @@ public class NotificationListenersTest extends UiServiceTestCase {
    }

    @Test
    public void testListenerPostLifeimteExtension_postsToAppropriateListeners() throws Exception {
    public void testListenerPostLifetimeExtension_postsToAppropriateListeners() throws Exception {
        mSetFlagsRule.enableFlags(android.app.Flags.FLAG_LIFETIME_EXTENSION_REFACTOR);

        // Create original notification, with FLAG_LIFETIME_EXTENDED_BY_DIRECT_REPLY.
@@ -998,17 +1006,30 @@ public class NotificationListenersTest extends UiServiceTestCase {
            r.run();
        }

        StatusBarNotification sbnResult = null;
        if (android.app.Flags.noSbnholder()) {
            ArgumentCaptor<StatusBarNotification> sbnCaptor =
                    ArgumentCaptor.forClass(StatusBarNotification.class);
            verify(sysuiListener, times(1)).onNotificationPostedFull(sbnCaptor.capture(), any());
            sbnResult = sbnCaptor.getValue();
        } else {
            ArgumentCaptor<IStatusBarNotificationHolder> sbnCaptor =
                    ArgumentCaptor.forClass(IStatusBarNotificationHolder.class);
            verify(sysuiListener, times(1)).onNotificationPosted(sbnCaptor.capture(), any());
        StatusBarNotification sbnResult = sbnCaptor.getValue().get();
            sbnResult = sbnCaptor.getValue().get();
        }
        assertThat(sbnResult.getNotification()
                .extras.getCharSequence(Notification.EXTRA_TITLE).toString())
                .isEqualTo("new title");

        if (android.app.Flags.noSbnholder()) {
            verify(otherListener1, times(1)).onNotificationPostedFull(any(), any());
            verify(otherListener2, times(1)).onNotificationPostedFull(any(), any());
        } else {
            verify(otherListener1, times(1)).onNotificationPosted(any(), any());
            verify(otherListener2, times(1)).onNotificationPosted(any(), any());
        }
    }

    @Test
    public void testNotifyPostedLocked_postsToAppropriateListeners() throws Exception {
@@ -1083,17 +1104,30 @@ public class NotificationListenersTest extends UiServiceTestCase {
            r.run();
        }

        StatusBarNotification sbnResult = null;
        if (android.app.Flags.noSbnholder()) {
            ArgumentCaptor<StatusBarNotification> sbnCaptor =
                    ArgumentCaptor.forClass(StatusBarNotification.class);
            verify(sysuiListener, times(1)).onNotificationPostedFull(sbnCaptor.capture(), any());
            sbnResult = sbnCaptor.getValue();
        } else {
            ArgumentCaptor<IStatusBarNotificationHolder> sbnCaptor =
                    ArgumentCaptor.forClass(IStatusBarNotificationHolder.class);
            verify(sysuiListener, times(1)).onNotificationPosted(sbnCaptor.capture(), any());
        StatusBarNotification sbnResult = sbnCaptor.getValue().get();
            sbnResult = sbnCaptor.getValue().get();
        }
        assertThat(sbnResult.getNotification()
                .extras.getCharSequence(Notification.EXTRA_TITLE).toString())
                .isEqualTo("new title");

        if (android.app.Flags.noSbnholder()) {
            verify(otherListener1, times(1)).onNotificationPostedFull(any(), any());
            verify(otherListener2, times(1)).onNotificationPostedFull(any(), any());
        } else {
            verify(otherListener1, times(1)).onNotificationPosted(any(), any());
            verify(otherListener2, times(1)).onNotificationPosted(any(), any());
        }
    }

    /**
     * Helper method to test the thread safety of some operations.