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

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

Log event when tapping on app settings

Log an event when tapping on app settings menu item in bubble menu.

Bug: 349845968
Test: atest BubbleBarExpandedViewTest
Flag: com.android.wm.shell.enable_bubble_bar
Change-Id: I7935231d223f97cebfc5faca74d3419232963f47
parent ca7ba1eb
Loading
Loading
Loading
Loading
+28 −2
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ 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.truth.Truth.assertWithMessage
import com.google.common.util.concurrent.MoreExecutors.directExecutor
import java.util.Collections
import java.util.concurrent.Executor
@@ -147,6 +148,7 @@ class BubbleBarExpandedViewTest {
    @After
    fun tearDown() {
        testableRegionSamplingHelper?.stopAndDestroy()
        getInstrumentation().waitForIdleSync()
    }

    @Test
@@ -218,8 +220,8 @@ class BubbleBarExpandedViewTest {
    @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,30 @@ class BubbleBarExpandedViewTest {
        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)
    }

    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>()
+1 −0
Original line number Diff line number Diff line
@@ -247,6 +247,7 @@ public class BubbleBarExpandedView extends FrameLayout implements BubbleTaskView
            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
+0 −17
Original line number Diff line number Diff line
@@ -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 @@ import java.util.ArrayList;
 */
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 @@ 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);
        }
    }
@@ -166,8 +160,6 @@ 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) {
@@ -180,14 +172,5 @@ 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;
        }
    }
}
+0 −1
Original line number Diff line number Diff line
@@ -212,7 +212,6 @@ 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) {