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

Commit 92901b7c authored by Ats Jenk's avatar Ats Jenk
Browse files

Log bubble removed events from bubble bar

Check in bubble data if we are removing a bubble while bubble bar is
active if the removal reason matches one the defined reasons. If
criteria is met, log an event.

Bug: 349845968
Test: atest com.android.wm.shell.bubbles.BubbleDataTest
Test: manual, cancel a bubbled notif from the test app, observe that
  cancel event is logged
Test: manual, finish bubble activity using test app, observe that finish
  event is logged
Test: manual, turn off bubbles from settings for test app while having
  active bubbles, observe that blocked event is logged
Flag: com.android.wm.shell.enable_bubble_bar
Change-Id: I0480fd830f695f1fbdefa098039df275d2ec9522
parent e6a2f840
Loading
Loading
Loading
Loading
+24 −1
Original line number Diff line number Diff line
@@ -759,7 +759,9 @@ public class BubbleData {
                if (b != null) {
                    b.stopInflation();
                }
                mLogger.logOverflowRemove(b, reason);
                if (!mPositioner.isShowingInBubbleBar()) {
                    mLogger.logStackOverflowRemove(b, reason);
                }
                mOverflowBubbles.remove(b);
                mStateChange.bubbleRemoved(b, reason);
                mStateChange.removedOverflowBubble = b;
@@ -802,6 +804,27 @@ public class BubbleData {
            setNewSelectedIndex(indexToRemove);
        }
        maybeSendDeleteIntent(reason, bubbleToRemove);

        if (mPositioner.isShowingInBubbleBar()) {
            logBubbleBarBubbleRemoved(bubbleToRemove, reason);
        }
    }

    private void logBubbleBarBubbleRemoved(Bubble bubble, @DismissReason int reason) {
        switch (reason) {
            case Bubbles.DISMISS_NOTIF_CANCEL:
                mLogger.log(bubble, BubbleLogger.Event.BUBBLE_BAR_BUBBLE_REMOVED_CANCELED);
                break;
            case Bubbles.DISMISS_TASK_FINISHED:
                mLogger.log(bubble, BubbleLogger.Event.BUBBLE_BAR_BUBBLE_ACTIVITY_FINISH);
                break;
            case Bubbles.DISMISS_BLOCKED:
            case Bubbles.DISMISS_NO_LONGER_BUBBLE:
                mLogger.log(bubble, BubbleLogger.Event.BUBBLE_BAR_BUBBLE_REMOVED_BLOCKED);
                break;
            default:
                // skip logging other events
        }
    }

    private void setNewSelectedIndex(int indexOfSelected) {
+3 −1
Original line number Diff line number Diff line
@@ -182,10 +182,12 @@ public class BubbleLogger {
    }

    /**
     * Log when a bubble is removed from overflow in stack view
     *
     * @param b Bubble removed from overflow
     * @param r Reason that bubble was removed
     */
    public void logOverflowRemove(Bubble b, @Bubbles.DismissReason int r) {
    public void logStackOverflowRemove(Bubble b, @Bubbles.DismissReason int r) {
        if (r == Bubbles.DISMISS_NOTIF_CANCEL) {
            log(b, BubbleLogger.Event.BUBBLE_OVERFLOW_REMOVE_CANCEL);
        } else if (r == Bubbles.DISMISS_GROUP_CANCELLED) {
+7 −0
Original line number Diff line number Diff line
@@ -830,6 +830,13 @@ public class BubblePositioner {
        mShowingInBubbleBar = showingInBubbleBar;
    }

    /**
     * Whether bubbles ar showing in the bubble bar from launcher.
     */
    boolean isShowingInBubbleBar() {
        return mShowingInBubbleBar;
    }

    public void setBubbleBarLocation(BubbleBarLocation location) {
        mBubbleBarLocation = location;
    }
+58 −4
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ import android.view.WindowManager;

import androidx.test.filters.SmallTest;

import com.android.internal.logging.testing.UiEventLoggerFake;
import com.android.wm.shell.ShellTestCase;
import com.android.wm.shell.bubbles.BubbleData.TimeSource;
import com.android.wm.shell.common.ShellExecutor;
@@ -102,6 +103,7 @@ public class BubbleDataTest extends ShellTestCase {

    private BubbleData mBubbleData;
    private TestableBubblePositioner mPositioner;
    private UiEventLoggerFake mUiEventLogger;

    @Mock
    private TimeSource mTimeSource;
@@ -112,8 +114,6 @@ public class BubbleDataTest extends ShellTestCase {
    @Mock
    private PendingIntent mDeleteIntent;
    @Mock
    private BubbleLogger mBubbleLogger;
    @Mock
    private BubbleEducationController mEducationController;
    @Mock
    private ShellExecutor mMainExecutor;
@@ -196,10 +196,12 @@ public class BubbleDataTest extends ShellTestCase {
                mock(Icon.class),
                mMainExecutor, mBgExecutor);

        mUiEventLogger = new UiEventLoggerFake();

        mPositioner = new TestableBubblePositioner(mContext,
                mContext.getSystemService(WindowManager.class));
        mBubbleData = new BubbleData(getContext(), mBubbleLogger, mPositioner, mEducationController,
                mMainExecutor, mBgExecutor);
        mBubbleData = new BubbleData(getContext(), new BubbleLogger(mUiEventLogger), mPositioner,
                mEducationController, mMainExecutor, mBgExecutor);

        // Used by BubbleData to set lastAccessedTime
        when(mTimeSource.currentTimeMillis()).thenReturn(1000L);
@@ -296,6 +298,58 @@ public class BubbleDataTest extends ShellTestCase {
        assertThat(bubbleBarUpdate.removedBubbles).isEmpty();
    }

    @Test
    public void testRemoveBubbleFromBubbleBar_notifCancelled_logEvent() {
        mPositioner.setShowingInBubbleBar(true);

        sendUpdatedEntryAtTime(mEntryA1, 1000);
        mBubbleData.setListener(mListener);

        mBubbleData.dismissBubbleWithKey(mEntryA1.getKey(), Bubbles.DISMISS_NOTIF_CANCEL);
        assertThat(mUiEventLogger.numLogs()).isEqualTo(1);
        assertThat(mUiEventLogger.eventId(0)).isEqualTo(
                BubbleLogger.Event.BUBBLE_BAR_BUBBLE_REMOVED_CANCELED.getId());
    }

    @Test
    public void testRemoveBubbleFromBubbleBar_taskFinished_logEvent() {
        mPositioner.setShowingInBubbleBar(true);

        sendUpdatedEntryAtTime(mEntryA1, 1000);
        mBubbleData.setListener(mListener);

        mBubbleData.dismissBubbleWithKey(mEntryA1.getKey(), Bubbles.DISMISS_TASK_FINISHED);
        assertThat(mUiEventLogger.numLogs()).isEqualTo(1);
        assertThat(mUiEventLogger.eventId(0)).isEqualTo(
                BubbleLogger.Event.BUBBLE_BAR_BUBBLE_ACTIVITY_FINISH.getId());
    }

    @Test
    public void testRemoveBubbleFromBubbleBar_notifBlocked_logEvent() {
        mPositioner.setShowingInBubbleBar(true);

        sendUpdatedEntryAtTime(mEntryA1, 1000);
        mBubbleData.setListener(mListener);

        mBubbleData.dismissBubbleWithKey(mEntryA1.getKey(), Bubbles.DISMISS_BLOCKED);
        assertThat(mUiEventLogger.numLogs()).isEqualTo(1);
        assertThat(mUiEventLogger.eventId(0)).isEqualTo(
                BubbleLogger.Event.BUBBLE_BAR_BUBBLE_REMOVED_BLOCKED.getId());
    }

    @Test
    public void testRemoveBubbleFromBubbleBar_noLongerBubble_logEvent() {
        mPositioner.setShowingInBubbleBar(true);

        sendUpdatedEntryAtTime(mEntryA1, 1000);
        mBubbleData.setListener(mListener);

        mBubbleData.dismissBubbleWithKey(mEntryA1.getKey(), Bubbles.DISMISS_NO_LONGER_BUBBLE);
        assertThat(mUiEventLogger.numLogs()).isEqualTo(1);
        assertThat(mUiEventLogger.eventId(0)).isEqualTo(
                BubbleLogger.Event.BUBBLE_BAR_BUBBLE_REMOVED_BLOCKED.getId());
    }

    @Test
    public void ifSuppress_hideFlyout() {
        // Setup