Delete AlertEntry references

Bug: 319721648
Test: SystemUITests
Test: use heads up notifications normally, no regressions
Flag: none

Change-Id: I742df1d0747928a88353c8b56558783d6683057b
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/AlertingNotificationManager.java b/packages/SystemUI/src/com/android/systemui/statusbar/AlertingNotificationManager.java
index ba26820..946943f 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/AlertingNotificationManager.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/AlertingNotificationManager.java
@@ -37,19 +37,9 @@
  */
 public abstract class AlertingNotificationManager {
     private static final String TAG = "AlertNotifManager";
-    protected final SystemClock mSystemClock;
-    protected final ArrayMap<String, AlertEntry> mAlertEntries = new ArrayMap<>();
-    protected final HeadsUpManagerLogger mLogger;
-    protected int mMinimumDisplayTime;
-    protected int mStickyForSomeTimeAutoDismissTime;
-    protected int mAutoDismissTime;
-    protected DelayableExecutor mExecutor;
 
     public AlertingNotificationManager(HeadsUpManagerLogger logger,
             SystemClock systemClock, @Main DelayableExecutor executor) {
-        mLogger = logger;
-        mExecutor = executor;
-        mSystemClock = systemClock;
     }
 
     public abstract void showNotification(@NonNull NotificationEntry entry);
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/HeadsUpManagerPhone.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/HeadsUpManagerPhone.java
index e66d9e8..f5983ed 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/HeadsUpManagerPhone.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/HeadsUpManagerPhone.java
@@ -375,9 +375,9 @@
     }
 
     @Override
-    protected void onAlertEntryRemoved(AlertEntry alertEntry) {
-        super.onAlertEntryRemoved(alertEntry);
-        mEntryPool.release((HeadsUpEntryPhone) alertEntry);
+    protected void onAlertEntryRemoved(HeadsUpEntry headsUpEntry) {
+        super.onAlertEntryRemoved(headsUpEntry);
+        mEntryPool.release((HeadsUpEntryPhone) headsUpEntry);
     }
 
     @Override
@@ -529,7 +529,7 @@
             mStatusBarState = newState;
             if (wasKeyguard && !isKeyguard && mBypassController.getBypassEnabled()) {
                 ArrayList<String> keysToRemove = new ArrayList<>();
-                for (AlertEntry entry : mAlertEntries.values()) {
+                for (HeadsUpEntry entry : mAlertEntries.values()) {
                     if (entry.mEntry != null && entry.mEntry.isBubble() && !entry.isSticky()) {
                         keysToRemove.add(entry.mEntry.getKey());
                     }
@@ -545,7 +545,7 @@
             if (!isDozing) {
                 // Let's make sure all huns we got while dozing time out within the normal timeout
                 // duration. Otherwise they could get stuck for a very long time
-                for (AlertEntry entry : mAlertEntries.values()) {
+                for (HeadsUpEntry entry : mAlertEntries.values()) {
                     entry.updateEntry(true /* updatePostTime */, "onDozingChanged(false)");
                 }
             }
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/BaseHeadsUpManager.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/BaseHeadsUpManager.java
index b38d749..a5fd559 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/BaseHeadsUpManager.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/BaseHeadsUpManager.java
@@ -37,7 +37,6 @@
 import com.android.systemui.EventLogTags;
 import com.android.systemui.dagger.qualifiers.Main;
 import com.android.systemui.res.R;
-import com.android.systemui.statusbar.AlertingNotificationManager;
 import com.android.systemui.statusbar.notification.collection.NotificationEntry;
 import com.android.systemui.statusbar.notification.row.NotificationRowContentBinder.InflationFlag;
 import com.android.systemui.util.ListenerSet;
@@ -52,8 +51,7 @@
  * A manager which handles heads up notifications which is a special mode where
  * they simply peek from the top of the screen.
  */
-public abstract class BaseHeadsUpManager extends AlertingNotificationManager implements
-        HeadsUpManager {
+public abstract class BaseHeadsUpManager implements HeadsUpManager {
     private static final String TAG = "BaseHeadsUpManager";
     private static final String SETTING_HEADS_UP_SNOOZE_LENGTH_MS = "heads_up_snooze_length_ms";
 
@@ -71,6 +69,14 @@
 
     private final UiEventLogger mUiEventLogger;
 
+    protected final SystemClock mSystemClock;
+    protected final ArrayMap<String, HeadsUpEntry> mAlertEntries = new ArrayMap<>();
+    protected final HeadsUpManagerLogger mLogger;
+    protected int mMinimumDisplayTime;
+    protected int mStickyForSomeTimeAutoDismissTime;
+    protected int mAutoDismissTime;
+    protected DelayableExecutor mExecutor;
+
     /**
      * Enum entry for notification peek logged from this class.
      */
@@ -95,7 +101,9 @@
             @Main DelayableExecutor executor,
             AccessibilityManagerWrapper accessibilityManagerWrapper,
             UiEventLogger uiEventLogger) {
-        super(logger, systemClock, executor);
+        mLogger = logger;
+        mExecutor = executor;
+        mSystemClock = systemClock;
         mContext = context;
         mAccessibilityMgr = accessibilityManagerWrapper;
         mUiEventLogger = uiEventLogger;
@@ -165,14 +173,14 @@
     @Override
     public boolean removeNotification(@NonNull String key, boolean releaseImmediately) {
         mLogger.logRemoveNotification(key, releaseImmediately);
-        AlertEntry alertEntry = mAlertEntries.get(key);
-        if (alertEntry == null) {
+        HeadsUpEntry headsUpEntry = mAlertEntries.get(key);
+        if (headsUpEntry == null) {
             return true;
         }
         if (releaseImmediately || canRemoveImmediately(key)) {
             removeAlertEntry(key);
         } else {
-            alertEntry.removeAsSoonAsPossible();
+            headsUpEntry.removeAsSoonAsPossible();
             return false;
         }
         return true;
@@ -186,19 +194,18 @@
      *              removal time
      */
     public void updateNotification(@NonNull String key, boolean alert) {
-        AlertEntry alertEntry = mAlertEntries.get(key);
-        mLogger.logUpdateNotification(key, alert, alertEntry != null);
-        if (alertEntry == null) {
+        HeadsUpEntry headsUpEntry = mAlertEntries.get(key);
+        mLogger.logUpdateNotification(key, alert, headsUpEntry != null);
+        if (headsUpEntry == null) {
             // the entry was released before this update (i.e by a listener) This can happen
             // with the groupmanager
             return;
         }
 
-        alertEntry.mEntry.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
-        HeadsUpEntry headsUpEntry = getHeadsUpEntry(key);
+        headsUpEntry.mEntry.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
 
         if (alert) {
-            alertEntry.updateEntry(true /* updatePostTime */, "updateNotification");
+            headsUpEntry.updateEntry(true /* updatePostTime */, "updateNotification");
             if (headsUpEntry != null) {
                 setEntryPinned(headsUpEntry, shouldHeadsUpBecomePinned(headsUpEntry.mEntry));
             }
@@ -225,8 +232,8 @@
      */
     @Nullable
     public NotificationEntry getEntry(@NonNull String key) {
-        AlertEntry entry = mAlertEntries.get(key);
-        return entry != null ? entry.mEntry : null;
+        HeadsUpEntry headsUpEntry = mAlertEntries.get(key);
+        return headsUpEntry != null ? headsUpEntry.mEntry : null;
     }
 
     /**
@@ -262,9 +269,9 @@
      */
     @Override
     public long getEarliestRemovalTime(String key) {
-        AlertEntry alerting = mAlertEntries.get(key);
-        if (alerting != null) {
-            return Math.max(0, alerting.mEarliestRemovalTime - mSystemClock.elapsedRealtime());
+        HeadsUpEntry entry = mAlertEntries.get(key);
+        if (entry != null) {
+            return Math.max(0, entry.mEarliestRemovalTime - mSystemClock.elapsedRealtime());
         }
         return 0;
     }
@@ -317,25 +324,24 @@
      * @param entry the entry to add
      */
     protected final void addAlertEntry(@NonNull NotificationEntry entry) {
-        AlertEntry alertEntry = createAlertEntry();
-        alertEntry.setEntry(entry);
-        mAlertEntries.put(entry.getKey(), alertEntry);
-        onAlertEntryAdded(alertEntry);
+        HeadsUpEntry headsUpEntry = createAlertEntry();
+        headsUpEntry.setEntry(entry);
+        mAlertEntries.put(entry.getKey(), headsUpEntry);
+        onAlertEntryAdded(headsUpEntry);
         entry.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
         entry.setIsAlerting(true);
     }
 
     /**
      * Manager-specific logic that should occur when an entry is added.
-     * @param alertEntry alert entry added
+     * @param headsUpEntry entry added
      */
-    @Override
-    protected void onAlertEntryAdded(AlertEntry alertEntry) {
-        NotificationEntry entry = alertEntry.mEntry;
+    protected void onAlertEntryAdded(HeadsUpEntry headsUpEntry) {
+        NotificationEntry entry = headsUpEntry.mEntry;
         entry.setHeadsUp(true);
 
         final boolean shouldPin = shouldHeadsUpBecomePinned(entry);
-        setEntryPinned((HeadsUpEntry) alertEntry, shouldPin);
+        setEntryPinned(headsUpEntry, shouldPin);
         EventLogTags.writeSysuiHeadsUpStatus(entry.getKey(), 1 /* visible */);
         for (OnHeadsUpChangedListener listener : mListeners) {
             listener.onHeadsUpStateChanged(entry, true);
@@ -346,13 +352,12 @@
      * Remove a notification and reset the alert entry.
      * @param key key of notification to remove
      */
-    @Override
     protected final void removeAlertEntry(@NonNull String key) {
-        AlertEntry alertEntry = mAlertEntries.get(key);
-        if (alertEntry == null) {
+        HeadsUpEntry headsUpEntry = mAlertEntries.get(key);
+        if (headsUpEntry == null) {
             return;
         }
-        NotificationEntry entry = alertEntry.mEntry;
+        NotificationEntry entry = headsUpEntry.mEntry;
 
         // If the notification is animating, we will remove it at the end of the animation.
         if (entry != null && entry.isExpandAnimationRunning()) {
@@ -360,20 +365,19 @@
         }
         entry.demoteStickyHun();
         mAlertEntries.remove(key);
-        onAlertEntryRemoved(alertEntry);
+        onAlertEntryRemoved(headsUpEntry);
         entry.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
-        alertEntry.reset();
+        headsUpEntry.reset();
     }
 
     /**
      * Manager-specific logic that should occur when an alert entry is removed.
-     * @param alertEntry alert entry removed
+     * @param headsUpEntry entry removed
      */
-    @Override
-    protected void onAlertEntryRemoved(AlertEntry alertEntry) {
-        NotificationEntry entry = alertEntry.mEntry;
+    protected void onAlertEntryRemoved(HeadsUpEntry headsUpEntry) {
+        NotificationEntry entry = headsUpEntry.mEntry;
         entry.setHeadsUp(false);
-        setEntryPinned((HeadsUpEntry) alertEntry, false /* isPinned */);
+        setEntryPinned(headsUpEntry, false /* isPinned */);
         EventLogTags.writeSysuiHeadsUpStatus(entry.getKey(), 0 /* visible */);
         mLogger.logNotificationActuallyRemoved(entry);
         for (OnHeadsUpChangedListener listener : mListeners) {
@@ -418,7 +422,7 @@
      */
     public void snooze() {
         for (String key : mAlertEntries.keySet()) {
-            AlertEntry entry = getHeadsUpEntry(key);
+            HeadsUpEntry entry = getHeadsUpEntry(key);
             String packageName = entry.mEntry.getSbn().getPackageName();
             String snoozeKey = snoozeKey(packageName, mUser);
             mLogger.logPackageSnoozed(snoozeKey);
@@ -451,7 +455,7 @@
             return null;
         }
         HeadsUpEntry topEntry = null;
-        for (AlertEntry entry: mAlertEntries.values()) {
+        for (HeadsUpEntry entry: mAlertEntries.values()) {
             if (topEntry == null || entry.compareTo(topEntry) < 0) {
                 topEntry = (HeadsUpEntry) entry;
             }
@@ -482,7 +486,7 @@
         pw.print("  mSnoozeLengthMs="); pw.println(mSnoozeLengthMs);
         pw.print("  now="); pw.println(mSystemClock.elapsedRealtime());
         pw.print("  mUser="); pw.println(mUser);
-        for (AlertEntry entry: mAlertEntries.values()) {
+        for (HeadsUpEntry entry: mAlertEntries.values()) {
             pw.print("  HeadsUpEntry="); pw.println(entry.mEntry);
         }
         int n = mSnoozedPackages.size();
@@ -502,7 +506,7 @@
 
     private boolean hasPinnedNotificationInternal() {
         for (String key : mAlertEntries.keySet()) {
-            AlertEntry entry = getHeadsUpEntry(key);
+            HeadsUpEntry entry = getHeadsUpEntry(key);
             if (entry.mEntry.isRowPinned()) {
                 return true;
             }
@@ -550,8 +554,8 @@
         if (a == null || b == null) {
             return Boolean.compare(a == null, b == null);
         }
-        AlertEntry aEntry = getHeadsUpEntry(a.getKey());
-        AlertEntry bEntry = getHeadsUpEntry(b.getKey());
+        HeadsUpEntry aEntry = getHeadsUpEntry(a.getKey());
+        HeadsUpEntry bEntry = getHeadsUpEntry(b.getKey());
         if (aEntry == null || bEntry == null) {
             return Boolean.compare(aEntry == null, bEntry == null);
         }
@@ -597,9 +601,8 @@
         if (headsUpEntry != null && headsUpEntry.mUserActionMayIndirectlyRemove) {
             return true;
         }
-        AlertEntry alertEntry = mAlertEntries.get(key);
-        return alertEntry == null || alertEntry.wasShownLongEnough()
-                || alertEntry.mEntry.isRowDismissed();
+        return headsUpEntry == null || headsUpEntry.wasShownLongEnough()
+                || headsUpEntry.mEntry.isRowDismissed();
     }
 
     /**
@@ -608,15 +611,14 @@
      */
     @Override
     public boolean isSticky(String key) {
-        AlertEntry alerting = mAlertEntries.get(key);
-        if (alerting != null) {
-            return alerting.isSticky();
+        HeadsUpEntry headsUpEntry = mAlertEntries.get(key);
+        if (headsUpEntry != null) {
+            return headsUpEntry.isSticky();
         }
         return false;
     }
 
     @NonNull
-    @Override
     protected HeadsUpEntry createAlertEntry() {
         return new HeadsUpEntry();
     }
@@ -638,7 +640,7 @@
      * This represents a notification and how long it is in a heads up mode. It also manages its
      * lifecycle automatically when created.
      */
-    protected class HeadsUpEntry extends AlertEntry {
+    protected class HeadsUpEntry implements Comparable<HeadsUpEntry> {
         public boolean mRemoteInputActive;
         public boolean mUserActionMayIndirectlyRemove;
 
@@ -653,12 +655,10 @@
 
         @Nullable private Runnable mCancelRemoveAlertRunnable;
 
-        @Override
         public void setEntry(@NonNull final NotificationEntry entry) {
             setEntry(entry, () -> removeAlertEntry(entry.getKey()));
         }
 
-        @Override
         public void setEntry(@NonNull final NotificationEntry entry,
                 @Nullable Runnable removeAlertRunnable) {
             mEntry = entry;
@@ -672,7 +672,6 @@
          * Updates an entry's removal time.
          * @param updatePostTime whether or not to refresh the post time
          */
-        @Override
         public void updateEntry(boolean updatePostTime, @Nullable String reason) {
             mLogger.logUpdateEntry(mEntry, updatePostTime, reason);
 
@@ -698,30 +697,25 @@
          * of the timer (forever) and should be removed externally.
          * @return true if the notification is sticky
          */
-        @Override
         public boolean isSticky() {
             return (mEntry.isRowPinned() && mExpanded)
                     || mRemoteInputActive
                     || hasFullScreenIntent(mEntry);
         }
 
-        @Override
         public boolean isStickyForSomeTime() {
             return mEntry.isStickyAndNotDemoted();
         }
 
         /**
-         * Whether the notification has befen on screen long enough and can be removed.
+         * Whether the notification has been on screen long enough and can be removed.
          * @return true if the notification has been on screen long enough
          */
-        @Override
         public boolean wasShownLongEnough() {
             return mEarliestRemovalTime < mSystemClock.elapsedRealtime();
         }
 
-        @Override
-        public int compareTo(@NonNull AlertEntry alertEntry) {
-            HeadsUpEntry headsUpEntry = (HeadsUpEntry) alertEntry;
+        public int compareTo(@NonNull HeadsUpEntry headsUpEntry) {
             boolean isPinned = mEntry.isRowPinned();
             boolean otherPinned = headsUpEntry.mEntry.isRowPinned();
             if (isPinned && !otherPinned) {
@@ -752,10 +746,10 @@
                 return 1;
             }
 
-            if (mPostTime > alertEntry.mPostTime) {
+            if (mPostTime > headsUpEntry.mPostTime) {
                 return -1;
-            } else if (mPostTime == alertEntry.mPostTime) {
-                return mEntry.getKey().compareTo(alertEntry.mEntry.getKey());
+            } else if (mPostTime == headsUpEntry.mPostTime) {
+                return mEntry.getKey().compareTo(headsUpEntry.mEntry.getKey());
             } else {
                 return 1;
             }
@@ -765,7 +759,6 @@
             this.mExpanded = expanded;
         }
 
-        @Override
         public void reset() {
             removeAutoRemovalCallbacks("reset()");
             mEntry = null;
@@ -777,7 +770,6 @@
         /**
          * Clear any pending removal runnables.
          */
-        @Override
         public void removeAutoRemovalCallbacks(@Nullable String reason) {
             final boolean removed = removeAutoRemovalCallbackInternal();
 
@@ -786,7 +778,6 @@
             }
         }
 
-        @Override
         public void scheduleAutoRemovalCallback(long delayMillis, @NonNull String reason) {
             if (mRemoveAlertRunnable == null) {
                 Log.wtf(TAG, "scheduleAutoRemovalCallback with no callback set");
@@ -805,7 +796,6 @@
                     delayMillis);
         }
 
-        @Override
         public boolean removeAutoRemovalCallbackInternal() {
             final boolean scheduled = (mCancelRemoveAlertRunnable != null);
 
@@ -831,7 +821,6 @@
          * Calculate what the post time of a notification is at some current time.
          * @return the post time
          */
-        @Override
         protected long calculatePostTime() {
             // The actual post time will be just after the heads-up really slided in
             return mSystemClock.elapsedRealtime() + mTouchAcceptanceDelay;
@@ -841,7 +830,6 @@
          * @return When the notification should auto-dismiss itself, based on
          * {@link SystemClock#elapsedRealtime()}
          */
-        @Override
         protected long calculateFinishTime() {
             final long duration = getRecommendedHeadsUpTimeoutMs(
                     isStickyForSomeTime() ? mStickyForSomeTimeAutoDismissTime : mAutoDismissTime);