Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cd4ca00a authored by Ats Jenk's avatar Ats Jenk
Browse files

Log event when dismissing bubble from handle menu

Bug: 349845968
Test: atest BubbleBarExpandedViewTest
Flag: com.android.wm.shell.enable_bubble_bar
Change-Id: Ic5e0d7359dff4c485e04e767c2705343cfcb7c15
parent da70989e
Loading
Loading
Loading
Loading
+33 −1
Original line number Diff line number Diff line
@@ -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>()
+1 −0
Original line number Diff line number Diff line
@@ -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
+18 −0
Original line number Diff line number Diff line
@@ -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;
        }
    }
}
+1 −0
Original line number Diff line number Diff line
@@ -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) {