Show FSI HUN for 60 more seconds after update

Fixes: 269781055

Test: show forever
- Send FSI HUN (permission GRANTED)
- Send any HUN and expand it
- Send any HUN, tap reply button to focus input

Test: show 60s
- Send FSI HUN (permission DENIED)
- Update FSI HUN (permission DENIED) (shows for 60s since update)

Test: show 5s
- Send non-FSI HUN
- Send FSI hun after demotion

Test: call via duo, hang up => HUN hides (no regression)

Change-Id: Id30dbfa78c6973f0f019207a5f44151363d6c3aa
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/AlertingNotificationManager.java b/packages/SystemUI/src/com/android/systemui/statusbar/AlertingNotificationManager.java
index 84b40e0..77d98d2 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/AlertingNotificationManager.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/AlertingNotificationManager.java
@@ -234,7 +234,7 @@
 
     /**
      * @param key
-     * @return true if the entry is pinned
+     * @return true if the entry is (pinned and expanded) or (has an active remote input)
      */
     public boolean isSticky(String key) {
         AlertEntry alerting = mAlertEntries.get(key);
@@ -256,15 +256,6 @@
         return 0;
     }
 
-    @VisibleForTesting
-    public long getCalculatedEarliestRemovalTime(String key) {
-        AlertEntry alerting = mAlertEntries.get(key);
-        if (alerting != null) {
-            return alerting.mEarliestRemovaltime;
-        }
-        return 0;
-    }
-
     protected class AlertEntry implements Comparable<AlertEntry> {
         @Nullable public NotificationEntry mEntry;
         public long mPostTime;
@@ -285,11 +276,6 @@
             updateEntry(true /* updatePostTime */);
         }
 
-        @VisibleForTesting
-        long getEarliestRemovaltime() {
-            return mEarliestRemovaltime;
-        }
-
         /**
          * Updates an entry's removal time.
          * @param updatePostTime whether or not to refresh the post time
@@ -305,23 +291,26 @@
             }
             removeAutoRemovalCallbacks();
 
-            final long finishTime = calculateFinishTime();
-            final long timeRemaining = isSticky()
-                    ? finishTime - mClock.currentTimeMillis()
-                    : Math.max(finishTime - now, mMinimumDisplayTime);
-
-            mHandler.postDelayed(mRemoveAlertRunnable, timeRemaining);
+            if (!isSticky()) {
+                final long finishTime = calculateFinishTime();
+                final long timeLeft = Math.max(finishTime - now, mMinimumDisplayTime);
+                mHandler.postDelayed(mRemoveAlertRunnable, timeLeft);
+            }
         }
 
         /**
          * Whether or not the notification is "sticky" i.e. should stay on screen regardless
-         * of the timer and should be removed externally.
+         * of the timer (forever) and should be removed externally.
          * @return true if the notification is sticky
          */
         public boolean isSticky() {
             // This implementation is overridden by HeadsUpManager HeadsUpEntry #isSticky
-            // but we keep this here for use by unit tests.
-            return mEntry.isStickyAndNotDemoted();
+            return false;
+        }
+
+        public boolean isStickyForSomeTime() {
+            // This implementation is overridden by HeadsUpManager HeadsUpEntry #isStickyForSomeTime
+            return false;
         }
 
         /**
@@ -360,8 +349,9 @@
         public void removeAsSoonAsPossible() {
             if (mRemoveAlertRunnable != null) {
                 removeAutoRemovalCallbacks();
-                mHandler.postDelayed(mRemoveAlertRunnable,
-                        mEarliestRemovaltime - mClock.currentTimeMillis());
+
+                final long timeLeft = mEarliestRemovaltime - mClock.currentTimeMillis();
+                mHandler.postDelayed(mRemoveAlertRunnable, timeLeft);
             }
         }
 
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/HeadsUpManager.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/HeadsUpManager.java
index 3263c4e..1a4a311 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/HeadsUpManager.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/HeadsUpManager.java
@@ -410,11 +410,14 @@
 
         @Override
         public boolean isSticky() {
-            final boolean isSticky = (mEntry.isRowPinned() && expanded)
+            return (mEntry.isRowPinned() && expanded)
                     || remoteInputActive
-                    || hasFullScreenIntent(mEntry)
-                    || mEntry.isStickyAndNotDemoted();
-            return isSticky;
+                    || hasFullScreenIntent(mEntry);
+        }
+
+        @Override
+        public boolean isStickyForSomeTime() {
+            return mEntry.isStickyAndNotDemoted();
         }
 
         @Override
@@ -476,10 +479,10 @@
          */
         @Override
         protected long calculateFinishTime() {
-            if (isSticky()) {
-                return mEntry.mCreationElapsedRealTime + mStickyDisplayTime;
-            }
-            return mPostTime + getRecommendedHeadsUpTimeoutMs(mAutoDismissNotificationDecay);
+            final long duration = getRecommendedHeadsUpTimeoutMs(
+                    isStickyForSomeTime() ? mStickyDisplayTime : mAutoDismissNotificationDecay);
+
+            return mPostTime + duration;
         }
 
         /**