Add logging to NotifCollection for lifetime extension

Test: atest, manual
Bug: 112656837
Change-Id: I8990bf4888b30b7512d969d0e3cf8631c67715db
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotifCollection.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotifCollection.java
index c9cc670..9c2cac7 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotifCollection.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotifCollection.java
@@ -504,6 +504,11 @@
                             extender));
         }
 
+        mLogger.logLifetimeExtensionEnded(
+                entry.getKey(),
+                extender,
+                entry.mLifetimeExtenders.size());
+
         if (!isLifetimeExtended(entry)) {
             if (tryRemoveNotification(entry)) {
                 dispatchEventsAndRebuildList();
@@ -529,6 +534,7 @@
         mAmDispatchingToOtherCode = true;
         for (NotifLifetimeExtender extender : mLifetimeExtenders) {
             if (extender.shouldExtendLifetime(entry, entry.mCancellationReason)) {
+                mLogger.logLifetimeExtended(entry.getKey(), extender);
                 entry.mLifetimeExtenders.add(extender);
             }
         }
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/notifcollection/NotifCollectionLogger.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/notifcollection/NotifCollectionLogger.kt
index ef302f6..c69882d 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/notifcollection/NotifCollectionLogger.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/notifcollection/NotifCollectionLogger.kt
@@ -111,6 +111,29 @@
             "RemoteException while attempting to clear all notifications:\n$str1"
         })
     }
+
+    fun logLifetimeExtended(key: String, extender: NotifLifetimeExtender) {
+        buffer.log(TAG, INFO, {
+            str1 = key
+            str2 = extender.name
+        }, {
+            "LIFETIME EXTENDED: $str1 by $str2"
+        })
+    }
+
+    fun logLifetimeExtensionEnded(
+        key: String,
+        extender: NotifLifetimeExtender,
+        totalExtenders: Int
+    ) {
+        buffer.log(TAG, INFO, {
+            str1 = key
+            str2 = extender.name
+            int1 = totalExtenders
+        }, {
+            "LIFETIME EXTENSION ENDED for $str1 by '$str2'; $int1 remaining extensions"
+        })
+    }
 }
 
 private const val TAG = "NotifCollection"