Merge changes Ib8b3a874,I7935231d into main

* changes:
  Log event when tapping on do not bubble convo
  Log event when tapping on app settings
diff --git a/libs/WindowManager/Shell/multivalentTests/src/com/android/wm/shell/bubbles/bar/BubbleBarExpandedViewTest.kt b/libs/WindowManager/Shell/multivalentTests/src/com/android/wm/shell/bubbles/bar/BubbleBarExpandedViewTest.kt
index 08d647d..0d742cc 100644
--- a/libs/WindowManager/Shell/multivalentTests/src/com/android/wm/shell/bubbles/bar/BubbleBarExpandedViewTest.kt
+++ b/libs/WindowManager/Shell/multivalentTests/src/com/android/wm/shell/bubbles/bar/BubbleBarExpandedViewTest.kt
@@ -47,6 +47,7 @@
 import com.android.wm.shell.taskview.TaskView
 import com.android.wm.shell.taskview.TaskViewTaskController
 import com.google.common.truth.Truth.assertThat
+import com.google.common.truth.Truth.assertWithMessage
 import com.google.common.util.concurrent.MoreExecutors.directExecutor
 import java.util.Collections
 import java.util.concurrent.Executor
@@ -147,6 +148,7 @@
     @After
     fun tearDown() {
         testableRegionSamplingHelper?.stopAndDestroy()
+        getInstrumentation().waitForIdleSync()
     }
 
     @Test
@@ -218,8 +220,8 @@
     @Test
     fun testEventLogging_dismissBubbleViaAppMenu() {
         getInstrumentation().runOnMainSync { bubbleExpandedView.handleView.performClick() }
-        val dismissMenuItem =
-            bubbleExpandedView.findViewWithTag<View>(BubbleBarMenuView.DISMISS_ACTION_TAG)
+        val dismissMenuItem = bubbleExpandedView.menuView()
+            .actionViewWithText(context.getString(R.string.bubble_dismiss_text))
         assertThat(dismissMenuItem).isNotNull()
         getInstrumentation().runOnMainSync { dismissMenuItem.performClick() }
         assertThat(uiEventLoggerFake.numLogs()).isEqualTo(1)
@@ -228,6 +230,42 @@
         assertThat(uiEventLoggerFake.logs[0]).hasBubbleInfo(bubble)
     }
 
+    @Test
+    fun testEventLogging_openAppSettings() {
+        getInstrumentation().runOnMainSync { bubbleExpandedView.handleView.performClick() }
+        val appMenuItem = bubbleExpandedView.menuView()
+            .actionViewWithText(context.getString(R.string.bubbles_app_settings, bubble.appName))
+        getInstrumentation().runOnMainSync { appMenuItem.performClick() }
+        assertThat(uiEventLoggerFake.numLogs()).isEqualTo(1)
+        assertThat(uiEventLoggerFake.logs[0].eventId)
+            .isEqualTo(BubbleLogger.Event.BUBBLE_BAR_APP_MENU_GO_TO_SETTINGS.id)
+        assertThat(uiEventLoggerFake.logs[0]).hasBubbleInfo(bubble)
+    }
+
+    @Test
+    fun testEventLogging_unBubbleConversation() {
+        getInstrumentation().runOnMainSync { bubbleExpandedView.handleView.performClick() }
+        val menuItem = bubbleExpandedView.menuView()
+            .actionViewWithText(context.getString(R.string.bubbles_dont_bubble_conversation))
+        getInstrumentation().runOnMainSync { menuItem.performClick() }
+        assertThat(uiEventLoggerFake.numLogs()).isEqualTo(1)
+        assertThat(uiEventLoggerFake.logs[0].eventId)
+            .isEqualTo(BubbleLogger.Event.BUBBLE_BAR_APP_MENU_OPT_OUT.id)
+        assertThat(uiEventLoggerFake.logs[0]).hasBubbleInfo(bubble)
+    }
+
+    private fun BubbleBarExpandedView.menuView(): BubbleBarMenuView {
+        return findViewByPredicate { it is BubbleBarMenuView }
+    }
+
+    private fun BubbleBarMenuView.actionViewWithText(text: CharSequence): View {
+        val views = ArrayList<View>()
+        findViewsWithText(views, text, View.FIND_VIEWS_WITH_TEXT)
+        assertWithMessage("Expecting a single action with text '$text'").that(views).hasSize(1)
+        // findViewsWithText returns the TextView, but the click listener is on the parent container
+        return views.first().parent as View
+    }
+
     private inner class FakeBubbleTaskViewFactory : BubbleTaskViewFactory {
         override fun create(): BubbleTaskView {
             val taskViewTaskController = mock<TaskViewTaskController>()
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/bar/BubbleBarExpandedView.java b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/bar/BubbleBarExpandedView.java
index 0ce651c..2a50e4d0 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/bar/BubbleBarExpandedView.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/bar/BubbleBarExpandedView.java
@@ -241,12 +241,14 @@
                 if (mListener != null) {
                     mListener.onUnBubbleConversation(bubble.getKey());
                 }
+                mBubbleLogger.log(bubble, BubbleLogger.Event.BUBBLE_BAR_APP_MENU_OPT_OUT);
             }
 
             @Override
             public void onOpenAppSettings(Bubble bubble) {
                 mManager.collapseStack();
                 mContext.startActivityAsUser(bubble.getSettingsIntent(mContext), bubble.getUser());
+                mBubbleLogger.log(bubble, BubbleLogger.Event.BUBBLE_BAR_APP_MENU_GO_TO_SETTINGS);
             }
 
             @Override
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/bar/BubbleBarMenuView.java b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/bar/BubbleBarMenuView.java
index 52b807a..0ee20ef 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/bar/BubbleBarMenuView.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/bar/BubbleBarMenuView.java
@@ -16,7 +16,6 @@
 package com.android.wm.shell.bubbles.bar;
 
 import android.annotation.ColorInt;
-import android.annotation.Nullable;
 import android.content.Context;
 import android.content.res.ColorStateList;
 import android.content.res.TypedArray;
@@ -43,8 +42,6 @@
  */
 public class BubbleBarMenuView extends LinearLayout {
 
-    public static final Object DISMISS_ACTION_TAG = new Object();
-
     private ViewGroup mBubbleSectionView;
     private ViewGroup mActionsSectionView;
     private ImageView mBubbleIconView;
@@ -123,9 +120,6 @@
                     R.layout.bubble_bar_menu_item, mActionsSectionView, false);
             itemView.update(action.mIcon, action.mTitle, action.mTint);
             itemView.setOnClickListener(action.mOnClick);
-            if (action.mTag != null) {
-                itemView.setTag(action.mTag);
-            }
             mActionsSectionView.addView(itemView);
         }
     }
@@ -166,8 +160,6 @@
         private Icon mIcon;
         private @ColorInt int mTint;
         private String mTitle;
-        @Nullable
-        private Object mTag;
         private OnClickListener mOnClick;
 
         MenuAction(Icon icon, String title, OnClickListener onClick) {
@@ -180,14 +172,5 @@
             this.mTint = tint;
             this.mOnClick = onClick;
         }
-
-        MenuAction(Icon icon, String title, @ColorInt int tint, @Nullable Object tag,
-                OnClickListener onClick) {
-            this.mIcon = icon;
-            this.mTitle = title;
-            this.mTint = tint;
-            this.mTag = tag;
-            this.mOnClick = onClick;
-        }
     }
 }
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/bar/BubbleBarMenuViewController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/bar/BubbleBarMenuViewController.java
index 5ed01b6..5148107 100644
--- a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/bar/BubbleBarMenuViewController.java
+++ b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/bar/BubbleBarMenuViewController.java
@@ -212,7 +212,6 @@
                 Icon.createWithResource(resources, R.drawable.ic_remove_no_shadow),
                 resources.getString(R.string.bubble_dismiss_text),
                 tintColor,
-                BubbleBarMenuView.DISMISS_ACTION_TAG,
                 view -> {
                     hideMenu(true /* animated */);
                     if (mListener != null) {