diff options
4 files changed, 53 insertions, 1 deletions
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 f181ce004478..fa9d2baa78d9 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 @@ -18,6 +18,7 @@ package com.android.wm.shell.bubbles.bar  import android.app.ActivityManager  import android.content.Context +import android.content.pm.ShortcutInfo  import android.graphics.Insets  import android.graphics.Rect  import android.view.LayoutInflater @@ -45,11 +46,14 @@ import com.android.wm.shell.shared.handles.RegionSamplingHelper  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.util.concurrent.MoreExecutors.directExecutor  import org.junit.After  import org.junit.Before  import org.junit.Test  import org.junit.runner.RunWith  import org.mockito.kotlin.mock +import org.mockito.kotlin.spy +import org.mockito.kotlin.verify  import org.mockito.kotlin.whenever  import java.util.Collections  import java.util.concurrent.Executor @@ -72,14 +76,18 @@ class BubbleBarExpandedViewTest {      private lateinit var expandedViewManager: BubbleExpandedViewManager      private lateinit var positioner: BubblePositioner      private lateinit var bubbleTaskView: BubbleTaskView +    private lateinit var bubble: Bubble      private lateinit var bubbleExpandedView: BubbleBarExpandedView      private var testableRegionSamplingHelper: TestableRegionSamplingHelper? = null      private var regionSamplingProvider: TestRegionSamplingProvider? = null +    private val bubbleLogger = spy(BubbleLogger(UiEventLoggerFake())) +      @Before      fun setUp() {          ProtoLog.REQUIRE_PROTOLOGTOOL = false +        ProtoLog.init()          mainExecutor = TestExecutor()          bgExecutor = TestExecutor()          positioner = BubblePositioner(context, windowManager) @@ -108,7 +116,7 @@ class BubbleBarExpandedViewTest {          bubbleExpandedView.initialize(              expandedViewManager,              positioner, -            BubbleLogger(UiEventLoggerFake()), +            bubbleLogger,              false /* isOverflow */,              bubbleTaskView,              mainExecutor, @@ -121,6 +129,20 @@ class BubbleBarExpandedViewTest {              // Helper should be created once attached to window              testableRegionSamplingHelper = regionSamplingProvider!!.helper          }) + +        bubble = Bubble( +            "key", +            ShortcutInfo.Builder(context, "id").build(), +            100 /* desiredHeight */, +            0 /* desiredHeightResId */, +            "title", +            0 /* taskId */, +            null /* locus */, +            true /* isDismissable */, +            directExecutor(), +            directExecutor() +        ) {} +        bubbleExpandedView.update(bubble)      }      @After @@ -194,6 +216,16 @@ class BubbleBarExpandedViewTest {          assertThat(testableRegionSamplingHelper!!.isStopped).isTrue()      } +    @Test +    fun testEventLogging_dismissBubbleViaAppMenu() { +        getInstrumentation().runOnMainSync { bubbleExpandedView.handleView.performClick() } +        val dismissMenuItem = +            bubbleExpandedView.findViewWithTag<View>(BubbleBarMenuView.DISMISS_ACTION_TAG) +        assertThat(dismissMenuItem).isNotNull() +        getInstrumentation().runOnMainSync { dismissMenuItem.performClick() } +        verify(bubbleLogger).log(bubble, BubbleLogger.Event.BUBBLE_BAR_BUBBLE_DISMISSED_APP_MENU) +    } +      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 84405bbe5823..0ce651c3f1fe 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 @@ -252,6 +252,7 @@ public class BubbleBarExpandedView extends FrameLayout implements BubbleTaskView              @Override              public void onDismissBubble(Bubble bubble) {                  mManager.dismissBubble(bubble, Bubbles.DISMISS_USER_GESTURE); +                mBubbleLogger.log(bubble, BubbleLogger.Event.BUBBLE_BAR_BUBBLE_DISMISSED_APP_MENU);              }              @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 0300869cbbe1..52b807abddd6 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,6 +16,7 @@  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; @@ -41,6 +42,9 @@ import java.util.ArrayList;   * Bubble bar expanded view menu   */  public class BubbleBarMenuView extends LinearLayout { + +    public static final Object DISMISS_ACTION_TAG = new Object(); +      private ViewGroup mBubbleSectionView;      private ViewGroup mActionsSectionView;      private ImageView mBubbleIconView; @@ -119,6 +123,9 @@ public class BubbleBarMenuView extends LinearLayout {                      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);          }      } @@ -159,6 +166,8 @@ public class BubbleBarMenuView extends LinearLayout {          private Icon mIcon;          private @ColorInt int mTint;          private String mTitle; +        @Nullable +        private Object mTag;          private OnClickListener mOnClick;          MenuAction(Icon icon, String title, OnClickListener onClick) { @@ -171,5 +180,14 @@ public class BubbleBarMenuView extends LinearLayout {              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 514810745e10..5ed01b66ec67 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,6 +212,7 @@ class BubbleBarMenuViewController {                  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) {  |