Refactor bubble helper for clarity and KDoc.

This change refactors the BubbleFlickerTestHelper to improve code
clarity, adopt more idiomatic Kotlin, and add KDoc.

The dumpBubbles extension function has been renamed to describeAll to
better reflect its purpose. Its implementation is updated from a manual
StringBuilder loop to a more concise joinToString call.

Additionally, KDoc is added to the switchBubble method and the renamed
describeAll function to improve documentation. The code formatting
within switchBubble is also improved for better readability.

Bug: 387193964
Flag: EXEMPT TEST_ONLY
Test: atest WMShellExplicitFlickerTestsBubbles:SwitchBetweenBubblesTest
Change-Id: I0b4d4263faeedd5d585762cd2974f3e9dfefd6c0
diff --git a/libs/WindowManager/Shell/tests/e2e/bubbles/flicker-explicit/src/com/android/wm/shell/flicker/bubbles/utils/BubbleFlickerTestHelper.kt b/libs/WindowManager/Shell/tests/e2e/bubbles/flicker-explicit/src/com/android/wm/shell/flicker/bubbles/utils/BubbleFlickerTestHelper.kt
index adc88c4..64bc6ea 100644
--- a/libs/WindowManager/Shell/tests/e2e/bubbles/flicker-explicit/src/com/android/wm/shell/flicker/bubbles/utils/BubbleFlickerTestHelper.kt
+++ b/libs/WindowManager/Shell/tests/e2e/bubbles/flicker-explicit/src/com/android/wm/shell/flicker/bubbles/utils/BubbleFlickerTestHelper.kt
@@ -195,6 +195,13 @@
         waitAndAssertBubbleAppInExpandedState(testApp, wmHelper)
     }
 
+    /**
+     * Switches from one expanded bubble to another.
+     *
+     * @param appSwitchedFrom The app currently expanded in a bubble.
+     * @param appSwitchTo The app to switch to, which is in a collapsed bubble.
+     * @param wmHelper The [WindowManagerStateHelper].
+     */
     fun switchBubble(
         appSwitchedFrom: StandardAppHelper,
         appSwitchTo: StandardAppHelper,
@@ -204,23 +211,19 @@
         waitAndAssertBubbleAppInExpandedState(appSwitchedFrom, wmHelper)
 
         val bubbles = Root.get().expandedBubbleStack.bubbles
-        val bubbleAppIcon = bubbles.find { bubble ->
-            bubble.containsBubbleApp(appSwitchTo)
-        } ?: error(
-            "Can't find the bubble with ${appSwitchTo.packageName}. "
-                    + "Bubbles are ${bubbles.dumpBubbles()}"
-        )
+        val bubbleAppIcon =
+            bubbles.find { bubble -> bubble.containsBubbleApp(appSwitchTo) } ?: error(
+                "Can't find the bubble with ${appSwitchTo.packageName}. "
+                        + "Bubbles are ${bubbles.describeAll()}"
+            )
         bubbleAppIcon.click()
 
         waitAndAssertBubbleAppInExpandedState(appSwitchTo, wmHelper)
     }
 
-    private fun List<Bubble>.dumpBubbles(): String {
-        val builder = StringBuilder()
-        for (bubble in this) {
-            builder.append(bubble.contentDescription()).append(", ")
-        }
-        return builder.toString()
+    /** Returns a string describing all bubbles in the list for debugging messages. */
+    private fun List<Bubble>.describeAll(): String {
+        return joinToString(separator = ", ") { bubble -> bubble.contentDescription() }
     }
 
     /**
@@ -304,14 +307,13 @@
 
         when (from) {
             FROM_FLOATING_BUBBLE_ICON -> {
-                Root.get().expandedBubbleStack.bubbles.apply {
-                    find { bubble -> bubble.containsBubbleApp(testApp) }
+                val bubbles = Root.get().expandedBubbleStack.bubbles
+                bubbles.find { bubble -> bubble.containsBubbleApp(testApp) }
                     ?.dismiss()
                     ?: error(
                         "Can't find the bubble with ${testApp.packageName}. "
-                                + "Bubbles are ${dumpBubbles()}"
+                                + "Bubbles are ${bubbles.describeAll()}"
                     )
-                }
             }
             FROM_BUBBLE_BAR_HANDLE -> {
                 Root.get().expandedBubbleStack.bubbleBarHandle.dragToDismiss()