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

Commit bb499406 authored by Dave Mankoff's avatar Dave Mankoff Committed by Steve Elliott
Browse files

Remove UiEventLogger from NSSL

Move the UiEventLogger from NotificactionStackScrollLayout to the
NotificactionStackScrollLayoutController. The controller now adds
a listener to the NSSL so it knows when to alert.

Bug: 147245740
Test: atest SystemUITests && manual
Change-Id: Ia2cc3110d2b4f943f69f07573f9ff9fcd21c2c30
parent e1e8f218
Loading
Loading
Loading
Loading
+13 −39
Original line number Diff line number Diff line
@@ -74,8 +74,6 @@ import android.widget.ScrollView;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.graphics.ColorUtils;
import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.UiEvent;
import com.android.internal.logging.UiEventLogger;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.keyguard.KeyguardSliceView;
import com.android.settingslib.Utils;
@@ -450,10 +448,10 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
    private int mHeadsUpInset;
    private HeadsUpAppearanceController mHeadsUpAppearanceController;
    private final Rect mTmpRect = new Rect();
    private DismissListener mDismissListener;
    private DismissAllAnimationListener mDismissAllAnimationListener;
    @VisibleForTesting
    protected final MetricsLogger mMetricsLogger = Dependency.get(MetricsLogger.class);
    protected final UiEventLogger mUiEventLogger;
    private final NotificationRemoteInputManager mRemoteInputManager =
            Dependency.get(NotificationRemoteInputManager.class);

@@ -535,8 +533,7 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
            ForegroundServiceSectionController fgsSectionController,
            ForegroundServiceDismissalFeatureController fgsFeatureController,
            GroupMembershipManager groupMembershipManager,
            GroupExpansionManager groupExpansionManager,
            UiEventLogger uiEventLogger
            GroupExpansionManager groupExpansionManager
    ) {
        super(context, attrs, 0, 0);
        Resources res = getResources();
@@ -590,7 +587,6 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
        mGroupExpansionManager = groupExpansionManager;
        mStatusbarStateController = statusbarStateController;
        initializeForegroundServiceSection(fgsFeatureController);
        mUiEventLogger = uiEventLogger;
    }

    private void initializeForegroundServiceSection(
@@ -5393,8 +5389,9 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
            }
        }

        // Log dismiss event even if there's nothing to dismiss
        mUiEventLogger.log(NotificationPanelEvent.fromSelection(selection));
        if (mDismissListener != null) {
            mDismissListener.onDismiss(selection);
        }

        if (viewsToRemove.isEmpty()) {
            if (closeShade) {
@@ -5701,6 +5698,10 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
        return mCheckForLeavebehind;
    }

    void setDismissListener (DismissListener listener) {
        mDismissListener = listener;
    }

    void setDismissAllAnimationListener(DismissAllAnimationListener dismissAllAnimationListener) {
        mDismissAllAnimationListener = dismissAllAnimationListener;
    }
@@ -6312,41 +6313,14 @@ public class NotificationStackScrollLayout extends ViewGroup implements Dumpable
    /** Only rows where entry.isHighPriority() is false. */
    public static final int ROWS_GENTLE = 2;

    /**
     * Enum for UiEvent logged from this class
     */
    enum NotificationPanelEvent implements UiEventLogger.UiEventEnum {
        INVALID(0),
        @UiEvent(doc = "User dismissed all notifications from notification panel.")
        DISMISS_ALL_NOTIFICATIONS_PANEL(312),
        @UiEvent(doc = "User dismissed all silent notifications from notification panel.")
        DISMISS_SILENT_NOTIFICATIONS_PANEL(314);
        private final int mId;
        NotificationPanelEvent(int id) {
            mId = id;
        }
        @Override public int getId() {
            return mId;
        }

        public static UiEventLogger.UiEventEnum fromSelection(@SelectedRows int selection) {
            if (selection == ROWS_ALL) {
                return DISMISS_ALL_NOTIFICATIONS_PANEL;
            }
            if (selection == ROWS_GENTLE) {
                return DISMISS_SILENT_NOTIFICATIONS_PANEL;
            }
            if (NotificationStackScrollLayout.DEBUG) {
                throw new IllegalArgumentException("Unexpected selection" + selection);
            }
            return INVALID;
        }
    }

    interface KeyguardBypassEnabledProvider {
        boolean getBypassEnabled();
    }

    interface DismissListener {
        void onDismiss(@SelectedRows int selectedRows);
    }

    interface DismissAllAnimationListener {
        void onAnimationEnd(
                List<ExpandableNotificationRow> viewsToRemove, @SelectedRows int selectedRows);
+40 −2
Original line number Diff line number Diff line
@@ -47,6 +47,8 @@ import android.widget.FrameLayout;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.UiEvent;
import com.android.internal.logging.UiEventLogger;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.internal.statusbar.IStatusBarService;
import com.android.internal.statusbar.NotificationVisibility;
@@ -74,7 +76,6 @@ import com.android.systemui.statusbar.notification.DynamicPrivacyController;
import com.android.systemui.statusbar.notification.NotificationActivityStarter;
import com.android.systemui.statusbar.notification.NotificationEntryListener;
import com.android.systemui.statusbar.notification.NotificationEntryManager;
import com.android.systemui.statusbar.notification.ShadeViewRefactor;
import com.android.systemui.statusbar.notification.collection.NotifCollection;
import com.android.systemui.statusbar.notification.collection.NotifPipeline;
import com.android.systemui.statusbar.notification.collection.NotificationEntry;
@@ -122,6 +123,7 @@ import kotlin.Unit;
@StatusBarComponent.StatusBarScope
public class NotificationStackScrollLayoutController {
    private static final String TAG = "StackScrollerController";
    private static final boolean DEBUG = false;

    private final boolean mAllowLongPress;
    private final NotificationGutsManager mNotificationGutsManager;
@@ -142,6 +144,7 @@ public class NotificationStackScrollLayoutController {
    private final NotifCollection mNotifCollection;
    private final NotificationEntryManager mNotificationEntryManager;
    private final IStatusBarService mIStatusBarService;
    private final UiEventLogger mUiEventLogger;
    private final KeyguardMediaController mKeyguardMediaController;
    private final SysuiStatusBarStateController mStatusBarStateController;
    private final KeyguardBypassController mKeyguardBypassController;
@@ -558,7 +561,8 @@ public class NotificationStackScrollLayoutController {
            NotifPipeline notifPipeline,
            NotifCollection notifCollection,
            NotificationEntryManager notificationEntryManager,
            IStatusBarService iStatusBarService) {
            IStatusBarService iStatusBarService,
            UiEventLogger uiEventLogger) {
        mAllowLongPress = allowLongPress;
        mNotificationGutsManager = notificationGutsManager;
        mHeadsUpManager = headsUpManager;
@@ -599,6 +603,7 @@ public class NotificationStackScrollLayoutController {
        mNotifCollection = notifCollection;
        mNotificationEntryManager = notificationEntryManager;
        mIStatusBarService = iStatusBarService;
        mUiEventLogger = uiEventLogger;
    }

    public void attach(NotificationStackScrollLayout view) {
@@ -607,6 +612,8 @@ public class NotificationStackScrollLayoutController {
        mView.setTouchHandler(new TouchHandler());
        mView.setStatusBar(mStatusBar);
        mView.setDismissAllAnimationListener(this::onAnimationEnd);
        mView.setDismissListener((selection) -> mUiEventLogger.log(
                NotificationPanelEvent.fromSelection(selection)));

        mSwipeHelper = mNotificationSwipeHelperBuilder
                .setSwipeDirection(SwipeHelper.X)
@@ -1293,6 +1300,37 @@ public class NotificationStackScrollLayoutController {
        return mDynamicPrivacyController.isInLockedDownShade();
    }

    /**
     * Enum for UiEvent logged from this class
     */
    enum NotificationPanelEvent implements UiEventLogger.UiEventEnum {
        INVALID(0),
        @UiEvent(doc = "User dismissed all notifications from notification panel.")
        DISMISS_ALL_NOTIFICATIONS_PANEL(312),
        @UiEvent(doc = "User dismissed all silent notifications from notification panel.")
        DISMISS_SILENT_NOTIFICATIONS_PANEL(314);
        private final int mId;
        NotificationPanelEvent(int id) {
            mId = id;
        }
        @Override public int getId() {
            return mId;
        }

        public static UiEventLogger.UiEventEnum fromSelection(@SelectedRows int selection) {
            if (selection == ROWS_ALL) {
                return DISMISS_ALL_NOTIFICATIONS_PANEL;
            }
            if (selection == NotificationStackScrollLayout.ROWS_GENTLE) {
                return DISMISS_SILENT_NOTIFICATIONS_PANEL;
            }
            if (NotificationStackScrollLayoutController.DEBUG) {
                throw new IllegalArgumentException("Unexpected selection" + selection);
            }
            return INVALID;
        }
    }

    private class NotificationListContainerImpl implements NotificationListContainer {

        @Override
+20 −11
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ import static android.provider.Settings.Secure.NOTIFICATION_HISTORY_ENABLED;
import static android.provider.Settings.Secure.NOTIFICATION_NEW_INTERRUPTION_MODEL;

import static com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayout.ROWS_ALL;
import static com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayout.ROWS_GENTLE;

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
@@ -44,7 +45,6 @@ import androidx.test.annotation.UiThreadTest;
import androidx.test.filters.SmallTest;

import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.testing.UiEventLoggerFake;
import com.android.systemui.ExpandHelper;
import com.android.systemui.R;
import com.android.systemui.SysuiTestCase;
@@ -106,8 +106,6 @@ public class NotificationStackScrollLayoutTest extends SysuiTestCase {
    @Mock private NotificationSwipeHelper mNotificationSwipeHelper;
    @Mock private NotificationStackScrollLayoutController mStackScrollLayoutController;
    private int mOriginalInterruptionModelSetting;
    private UiEventLoggerFake mUiEventLoggerFake = new UiEventLoggerFake();


    @Before
    @UiThreadTest
@@ -154,8 +152,7 @@ public class NotificationStackScrollLayoutTest extends SysuiTestCase {
                mock(ForegroundServiceSectionController.class),
                mock(ForegroundServiceDismissalFeatureController.class),
                mGroupMembershipManger,
                mGroupExpansionManager,
                mUiEventLoggerFake
                mGroupExpansionManager
        );
        mStackScrollerInternal.initView(getContext(), mKeyguardBypassEnabledProvider,
                mNotificationSwipeHelper);
@@ -380,18 +377,30 @@ public class NotificationStackScrollLayoutTest extends SysuiTestCase {

    @Test
    public void testClearNotifications_All() {
        final int[] numCalls = {0};
        final int[] selected = {-1};
        mStackScroller.setDismissListener(selectedRows -> {
            numCalls[0]++;
            selected[0] = selectedRows;
        });

        mStackScroller.clearNotifications(ROWS_ALL, true);
        assertEquals(1, mUiEventLoggerFake.numLogs());
        assertEquals(NotificationStackScrollLayout.NotificationPanelEvent
                .DISMISS_ALL_NOTIFICATIONS_PANEL.getId(), mUiEventLoggerFake.eventId(0));
        assertEquals(1, numCalls[0]);
        assertEquals(ROWS_ALL, selected[0]);
    }

    @Test
    public void testClearNotifications_Gentle() {
        final int[] numCalls = {0};
        final int[] selected = {-1};
        mStackScroller.setDismissListener(selectedRows -> {
            numCalls[0]++;
            selected[0] = selectedRows;
        });

        mStackScroller.clearNotifications(NotificationStackScrollLayout.ROWS_GENTLE, false);
        assertEquals(1, mUiEventLoggerFake.numLogs());
        assertEquals(NotificationStackScrollLayout.NotificationPanelEvent
                .DISMISS_SILENT_NOTIFICATIONS_PANEL.getId(), mUiEventLoggerFake.eventId(0));
        assertEquals(1, numCalls[0]);
        assertEquals(ROWS_GENTLE, selected[0]);
    }

    @Test
+24 −7
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.systemui.statusbar.notification.stack;

import static com.android.systemui.statusbar.StatusBarState.KEYGUARD;
import static com.android.systemui.statusbar.StatusBarState.SHADE;
import static com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayout.ROWS_ALL;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
@@ -36,6 +37,7 @@ import android.testing.AndroidTestingRunner;
import androidx.test.filters.SmallTest;

import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.UiEventLogger;
import com.android.internal.logging.nano.MetricsProto;
import com.android.internal.statusbar.IStatusBarService;
import com.android.systemui.SysuiTestCase;
@@ -57,6 +59,7 @@ import com.android.systemui.statusbar.notification.collection.legacy.Notificatio
import com.android.systemui.statusbar.notification.collection.render.SectionHeaderController;
import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;
import com.android.systemui.statusbar.notification.row.NotificationGutsManager;
import com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayoutController.NotificationPanelEvent;
import com.android.systemui.statusbar.phone.HeadsUpManagerPhone;
import com.android.systemui.statusbar.phone.KeyguardBypassController;
import com.android.systemui.statusbar.phone.ScrimController;
@@ -111,6 +114,7 @@ public class NotificationStackScrollerControllerTest extends SysuiTestCase {
    @Mock private NotifCollection mNotifCollection;
    @Mock private NotificationEntryManager mEntryManager;
    @Mock private IStatusBarService mIStatusBarService;
    @Mock private UiEventLogger mUiEventLogger;

    @Captor
    private ArgumentCaptor<StatusBarStateController.StateListener> mStateListenerArgumentCaptor;
@@ -152,13 +156,13 @@ public class NotificationStackScrollerControllerTest extends SysuiTestCase {
                mNotifPipeline,
                mNotifCollection,
                mEntryManager,
                mIStatusBarService
                mIStatusBarService,
                mUiEventLogger
        );

        when(mNotificationStackScrollLayout.isAttachedToWindow()).thenReturn(true);
    }


    @Test
    public void testAttach_viewAlreadyAttached() {
        mController.attach(mNotificationStackScrollLayout);
@@ -270,15 +274,12 @@ public class NotificationStackScrollerControllerTest extends SysuiTestCase {
        verify(mNotificationStackScrollLayout).updateSensitiveness(false, true);
    }


    @Test
    public void testOnMenuShownLogging() { ;

    public void testOnMenuShownLogging() {
        ExpandableNotificationRow row = mock(ExpandableNotificationRow.class, RETURNS_DEEP_STUBS);
        when(row.getEntry().getSbn().getLogMaker()).thenReturn(new LogMaker(
                MetricsProto.MetricsEvent.VIEW_UNKNOWN));


        ArgumentCaptor<OnMenuEventListener> onMenuEventListenerArgumentCaptor =
                ArgumentCaptor.forClass(OnMenuEventListener.class);

@@ -300,7 +301,6 @@ public class NotificationStackScrollerControllerTest extends SysuiTestCase {
        when(row.getEntry().getSbn().getLogMaker()).thenReturn(new LogMaker(
                MetricsProto.MetricsEvent.VIEW_UNKNOWN));


        ArgumentCaptor<OnMenuEventListener> onMenuEventListenerArgumentCaptor =
                ArgumentCaptor.forClass(OnMenuEventListener.class);

@@ -317,6 +317,23 @@ public class NotificationStackScrollerControllerTest extends SysuiTestCase {
                MetricsProto.MetricsEvent.TYPE_ACTION));
    }

    @Test
    public void testDismissListener() {
        ArgumentCaptor<NotificationStackScrollLayout.DismissListener>
                dismissListenerArgumentCaptor = ArgumentCaptor.forClass(
                NotificationStackScrollLayout.DismissListener.class);

        mController.attach(mNotificationStackScrollLayout);

        verify(mNotificationStackScrollLayout).setDismissListener(
                dismissListenerArgumentCaptor.capture());
        NotificationStackScrollLayout.DismissListener dismissListener =
                dismissListenerArgumentCaptor.getValue();

        dismissListener.onDismiss(ROWS_ALL);
        verify(mUiEventLogger).log(NotificationPanelEvent.fromSelection(ROWS_ALL));
    }

    private LogMaker logMatcher(int category, int type) {
        return argThat(new LogMatcher(category, type));
    }