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

Commit 761af0d7 authored by Ned Burns's avatar Ned Burns
Browse files

Fix NPE in NotificationLogger for real this time

Previous nullcheck just caused another NPE. Actually checking the
null value and adding a test this time.

Bug: 122169343
Test: atest
Change-Id: I4acc055b8d5039ea65fded43526780be883eaf74
parent c54ffd28
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -174,7 +174,7 @@ public class NotificationLogger implements StateListener {
                    NotificationVisibility visibility,
                    boolean lifetimeExtended,
                    boolean removedByUser) {
                if (removedByUser && visibility != null && entry.notification != null) {
                if (removedByUser && visibility != null && entry != null) {
                    logNotificationClear(key, entry.notification, visibility);
                }
            }
+12 −0
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ import com.android.systemui.UiOffloadThread;
import com.android.systemui.statusbar.NotificationListener;
import com.android.systemui.statusbar.StatusBarStateController;
import com.android.systemui.statusbar.notification.NotificationData;
import com.android.systemui.statusbar.notification.NotificationEntryListener;
import com.android.systemui.statusbar.notification.NotificationEntryManager;
import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;
import com.android.systemui.statusbar.notification.stack.NotificationListContainer;
@@ -51,6 +52,8 @@ import com.google.android.collect.Lists;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
@@ -72,9 +75,11 @@ public class NotificationLoggerTest extends SysuiTestCase {
    // Dependency mocks:
    @Mock private NotificationEntryManager mEntryManager;
    @Mock private NotificationListener mListener;
    @Captor private ArgumentCaptor<NotificationEntryListener> mEntryListenerCaptor;

    private NotificationData.Entry mEntry;
    private TestableNotificationLogger mLogger;
    private NotificationEntryListener mNotificationEntryListener;
    private ConcurrentLinkedQueue<AssertionError> mErrorQueue = new ConcurrentLinkedQueue<>();

    @Before
@@ -94,6 +99,8 @@ public class NotificationLoggerTest extends SysuiTestCase {
        mLogger = new TestableNotificationLogger(mListener, Dependency.get(UiOffloadThread.class),
                mEntryManager, mock(StatusBarStateController.class), mBarService);
        mLogger.setUpWithContainer(mListContainer);
        verify(mEntryManager).addNotificationEntryListener(mEntryListenerCaptor.capture());
        mNotificationEntryListener = mEntryListenerCaptor.getValue();
    }

    @Test
@@ -152,6 +159,11 @@ public class NotificationLoggerTest extends SysuiTestCase {
        verify(mBarService, times(1)).onNotificationVisibilityChanged(any(), any());
    }

    @Test
    public void testHandleNullEntryOnEntryRemoved() {
        mNotificationEntryListener.onEntryRemoved(null, "foobar", null, null, false, false);
    }

    private class TestableNotificationLogger extends NotificationLogger {

        TestableNotificationLogger(NotificationListener notificationListener,