[Chipbar] Add logs at the exact time WindowManager calls are made.

Bug: 271411294
Test: Verified logs occurred at the correct times when the chipbar
appeared and disappered

Change-Id: I3c1f0ebb72407ff4b2a073ea927f5a0ab0e71250
diff --git a/packages/SystemUI/src/com/android/systemui/temporarydisplay/TemporaryViewDisplayController.kt b/packages/SystemUI/src/com/android/systemui/temporarydisplay/TemporaryViewDisplayController.kt
index c6cb79a..59122af 100644
--- a/packages/SystemUI/src/com/android/systemui/temporarydisplay/TemporaryViewDisplayController.kt
+++ b/packages/SystemUI/src/com/android/systemui/temporarydisplay/TemporaryViewDisplayController.kt
@@ -274,6 +274,7 @@
             it.title = newInfo.windowTitle
         }
         newView.keepScreenOn = true
+        logger.logViewAddedToWindowManager(displayInfo.info, newView)
         windowManager.addView(newView, paramsWithTitle)
         animateViewIn(newView)
     }
@@ -286,6 +287,11 @@
         val view = checkNotNull(currentDisplayInfo.view) {
             "First item in activeViews list must have a valid view"
         }
+        logger.logViewRemovedFromWindowManager(
+            currentDisplayInfo.info,
+            view,
+            isReinflation = true,
+        )
         windowManager.removeView(view)
         inflateAndUpdateView(currentDisplayInfo)
     }
@@ -382,6 +388,7 @@
         }
         displayInfo.view = null // Need other places??
         animateViewOut(view, removalReason) {
+            logger.logViewRemovedFromWindowManager(displayInfo.info, view)
             windowManager.removeView(view)
             displayInfo.wakeLock?.release(displayInfo.info.wakeReason)
         }
diff --git a/packages/SystemUI/src/com/android/systemui/temporarydisplay/TemporaryViewLogger.kt b/packages/SystemUI/src/com/android/systemui/temporarydisplay/TemporaryViewLogger.kt
index 899b0c2..667e22a 100644
--- a/packages/SystemUI/src/com/android/systemui/temporarydisplay/TemporaryViewLogger.kt
+++ b/packages/SystemUI/src/com/android/systemui/temporarydisplay/TemporaryViewLogger.kt
@@ -16,6 +16,7 @@
 
 package com.android.systemui.temporarydisplay
 
+import android.view.View
 import com.android.systemui.plugins.log.LogBuffer
 import com.android.systemui.plugins.log.LogLevel
 
@@ -141,4 +142,46 @@
             { "Removal of view with id=$str2 is ignored because $str1" }
         )
     }
+
+    fun logViewAddedToWindowManager(info: T, view: View) {
+        buffer.log(
+            tag,
+            LogLevel.DEBUG,
+            {
+                str1 = info.id
+                str2 = info.windowTitle
+                str3 = view.javaClass.name
+                int1 = view.getIdForLogging()
+            },
+            {
+                "Adding view to window manager. " +
+                    "id=$str1 window=$str2 view=$str3(id=${Integer.toHexString(int1)})"
+            }
+        )
+    }
+
+    fun logViewRemovedFromWindowManager(info: T, view: View, isReinflation: Boolean = false) {
+        buffer.log(
+            tag,
+            LogLevel.DEBUG,
+            {
+                str1 = info.id
+                str2 = info.windowTitle
+                str3 = view.javaClass.name
+                int1 = view.getIdForLogging()
+                bool1 = isReinflation
+            },
+            {
+                "Removing view from window manager${if (bool1) " due to reinflation" else ""}. " +
+                    "id=$str1 window=$str2 view=$str3(id=${Integer.toHexString(int1)})"
+            }
+        )
+    }
+
+    companion object {
+        private fun View.getIdForLogging(): Int {
+            // The identityHashCode is guaranteed to be constant for the lifetime of the object.
+            return System.identityHashCode(this)
+        }
+    }
 }