Mark entry in onEntryRemoved as @Nullable

We should eventually modify logic so entry can never be null.

Bug: 122169343
Test: Manual, SystemUITests
Change-Id: Ib4312b7ddff4c6b7bf35e2ea3d5462cfc12b1e11
(cherry picked from commit 1dd6b40b9b81e98200ffe719848382bb73c50775)
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationMediaManager.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationMediaManager.java
index 25837e1..1bf101c 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationMediaManager.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationMediaManager.java
@@ -157,7 +157,7 @@
         notificationEntryManager.addNotificationEntryListener(new NotificationEntryListener() {
             @Override
             public void onEntryRemoved(
-                    Entry entry,
+                    @Nullable Entry entry,
                     String key,
                     StatusBarNotification old,
                     NotificationVisibility visibility,
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationRemoteInputManager.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationRemoteInputManager.java
index 674e262..886d99e 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationRemoteInputManager.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationRemoteInputManager.java
@@ -20,6 +20,7 @@
 import static com.android.systemui.Dependency.MAIN_HANDLER_NAME;
 
 import android.annotation.NonNull;
+import android.annotation.Nullable;
 import android.app.ActivityManager;
 import android.app.ActivityOptions;
 import android.app.KeyguardManager;
@@ -252,13 +253,13 @@
         notificationEntryManager.addNotificationEntryListener(new NotificationEntryListener() {
             @Override
             public void onEntryRemoved(
-                    NotificationData.Entry entry,
+                    @Nullable NotificationData.Entry entry,
                     String key,
                     StatusBarNotification old,
                     NotificationVisibility visibility,
                     boolean lifetimeExtended,
                     boolean removedByUser) {
-                if (removedByUser) {
+                if (removedByUser && entry != null) {
                     onPerformRemoveNotification(entry, key);
                 }
             }
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationAlertingManager.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationAlertingManager.java
index dbc6f43..7b42dd9 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationAlertingManager.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationAlertingManager.java
@@ -20,6 +20,7 @@
 import static com.android.systemui.statusbar.notification.row.NotificationInflater.FLAG_CONTENT_VIEW_AMBIENT;
 import static com.android.systemui.statusbar.notification.row.NotificationInflater.FLAG_CONTENT_VIEW_HEADS_UP;
 
+import android.annotation.Nullable;
 import android.app.Notification;
 import android.service.notification.StatusBarNotification;
 import android.util.Log;
@@ -82,7 +83,7 @@
 
             @Override
             public void onEntryRemoved(
-                    NotificationData.Entry entry,
+                    @Nullable NotificationData.Entry entry,
                     String key,
                     StatusBarNotification old,
                     NotificationVisibility visibility,
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationEntryListener.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationEntryListener.java
index 72f1d5b..1d06ce0 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationEntryListener.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationEntryListener.java
@@ -80,7 +80,7 @@
      * @param removedByUser true if the notification was removed by a user action
      */
     default void onEntryRemoved(
-            NotificationData.Entry entry,
+            @Nullable NotificationData.Entry entry,
             String key,
             StatusBarNotification old,
             @Nullable NotificationVisibility visibility,
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/logging/NotificationLogger.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/logging/NotificationLogger.java
index 060e755..32acb8d 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/logging/NotificationLogger.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/logging/NotificationLogger.java
@@ -15,6 +15,7 @@
  */
 package com.android.systemui.statusbar.notification.logging;
 
+import android.annotation.Nullable;
 import android.content.Context;
 import android.os.Handler;
 import android.os.RemoteException;
@@ -167,13 +168,13 @@
         entryManager.addNotificationEntryListener(new NotificationEntryListener() {
             @Override
             public void onEntryRemoved(
-                    NotificationData.Entry entry,
+                    @Nullable NotificationData.Entry entry,
                     String key,
                     StatusBarNotification old,
                     NotificationVisibility visibility,
                     boolean lifetimeExtended,
                     boolean removedByUser) {
-                if (removedByUser && visibility != null) {
+                if (removedByUser && visibility != null && entry.notification != null) {
                     logNotificationClear(key, entry.notification, visibility);
                 }
             }
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationGroupAlertTransferHelper.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationGroupAlertTransferHelper.java
index 9fe30db..3839ed5 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationGroupAlertTransferHelper.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationGroupAlertTransferHelper.java
@@ -17,6 +17,7 @@
 package com.android.systemui.statusbar.phone;
 
 import android.annotation.NonNull;
+import android.annotation.Nullable;
 import android.app.Notification;
 import android.os.SystemClock;
 import android.service.notification.StatusBarNotification;
@@ -218,7 +219,7 @@
 
         @Override
         public void onEntryRemoved(
-                Entry entry,
+                @Nullable Entry entry,
                 String key,
                 StatusBarNotification old,
                 NotificationVisibility visibility,
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarNotificationPresenter.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarNotificationPresenter.java
index 7b6fef3..7b7bcb4 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarNotificationPresenter.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarNotificationPresenter.java
@@ -20,6 +20,7 @@
 import static com.android.systemui.statusbar.phone.StatusBar.MULTIUSER_DEBUG;
 import static com.android.systemui.statusbar.phone.StatusBar.SPEW;
 
+import android.annotation.Nullable;
 import android.app.KeyguardManager;
 import android.content.Context;
 import android.content.pm.PackageManager;
@@ -193,7 +194,7 @@
 
                 @Override
                 public void onEntryRemoved(
-                        Entry entry,
+                        @Nullable Entry entry,
                         String key,
                         StatusBarNotification old,
                         NotificationVisibility visibility,