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

Commit 3207e2fc authored by Julia Reynolds's avatar Julia Reynolds
Browse files

Fix NPE onNotificationRemoved

- Handle it just in case
- Pass through stats in progress for notifications canceled
due to error

Test: atest
Change-Id: I0b55305532a57dcd242af0b4e2e0713e88ffbd2a
Fixes: 119552458
parent 95334134
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -294,7 +294,7 @@ public class Assistant extends NotificationAssistantService {
            synchronized (mkeyToImpressions) {
                ChannelImpressions ci = mkeyToImpressions.getOrDefault(key,
                        createChannelImpressionsWithThresholds());
                if (stats.hasSeen()) {
                if (stats != null && stats.hasSeen()) {
                    ci.incrementViews();
                    updatedImpressions = true;
                }
+1 −1
Original line number Diff line number Diff line
@@ -4939,7 +4939,7 @@ public class NotificationManagerService extends SystemService {
                        Slog.e(TAG, "Not posting notification without small icon: " + notification);
                        if (old != null && !old.isCanceled) {
                            mListeners.notifyRemovedLocked(r,
                                    NotificationListenerService.REASON_ERROR, null);
                                    NotificationListenerService.REASON_ERROR, r.getStats());
                            mHandler.post(new Runnable() {
                                @Override
                                public void run() {
+22 −0
Original line number Diff line number Diff line
@@ -3849,4 +3849,26 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
        mService.reportSeen(r);
        verify(mAppUsageStats, times(1)).reportEvent(anyString(), anyInt(), anyInt());
    }

    @Test
    public void testNotificationStats_notificationError() {
        NotificationRecord r = generateNotificationRecord(mTestNotificationChannel);
        mService.addNotification(r);

        StatusBarNotification sbn = new StatusBarNotification(PKG, PKG, 1, "tag", mUid, 0,
                new Notification.Builder(mContext, mTestNotificationChannel.getId()).build(),
                new UserHandle(mUid), null, 0);
        NotificationRecord update = new NotificationRecord(mContext, sbn, mTestNotificationChannel);
        mService.addEnqueuedNotification(update);
        assertNull(update.sbn.getNotification().getSmallIcon());

        NotificationManagerService.PostNotificationRunnable runnable =
                mService.new PostNotificationRunnable(update.getKey());
        runnable.run();
        waitForIdle();

        ArgumentCaptor<NotificationStats> captor = ArgumentCaptor.forClass(NotificationStats.class);
        verify(mListeners).notifyRemovedLocked(any(), anyInt(), captor.capture());
        assertNotNull(captor.getValue());
    }
}