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

Commit 3ce73f07 authored by Julia Reynolds's avatar Julia Reynolds
Browse files

Migrate drag logging to EntryAdapter

Test: ExpandableNotificationRowDragControllerTest
Bug: 395857098
Flag: com.android.systemui.notification_bundle_ui
Change-Id: I3578f0ced0f9f4af51b31fdfda691943e3f21492
parent d04635b1
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.systemui.statusbar.notification.logging;

import com.android.systemui.statusbar.notification.collection.EntryAdapter;
import com.android.systemui.statusbar.notification.collection.NotificationEntry;
import com.android.systemui.statusbar.notification.logging.nano.Notifications;

@@ -49,6 +50,11 @@ public class NotificationPanelLoggerFake implements NotificationPanelLogger {
    public void logNotificationDrag(NotificationEntry draggedNotification) {
    }

    @Override
    public void logNotificationDrag(EntryAdapter draggedNotification) {

    }

    public static class CallRecord {
        public boolean isLockscreen;
        public Notifications.NotificationList list;
+24 −4
Original line number Diff line number Diff line
@@ -40,9 +40,12 @@ import androidx.test.filters.SmallTest;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.plugins.statusbar.NotificationMenuRowPlugin;
import com.android.systemui.shade.ShadeController;
import com.android.systemui.statusbar.notification.collection.EntryAdapter;
import com.android.systemui.statusbar.notification.collection.NotificationEntry;
import com.android.systemui.statusbar.notification.headsup.PinnedStatus;
import com.android.systemui.statusbar.notification.logging.NotificationPanelLogger;
import com.android.systemui.statusbar.notification.headsup.HeadsUpManager;
import com.android.systemui.statusbar.notification.shared.NotificationBundleUi;

import org.junit.Before;
import org.junit.Test;
@@ -99,7 +102,13 @@ public class ExpandableNotificationRowDragControllerTest extends SysuiTestCase {
        mRow.doDragCallback(0, 0);
        verify(controller).startDragAndDrop(mRow);
        verify(mHeadsUpManager, times(1)).releaseAllImmediately();
        verify(mNotificationPanelLogger, times(1)).logNotificationDrag(any());
        if (NotificationBundleUi.isEnabled()) {
            verify(mNotificationPanelLogger, times(1))
                    .logNotificationDrag(any(EntryAdapter.class));
        } else {
            verify(mNotificationPanelLogger, times(1))
                    .logNotificationDrag(any(NotificationEntry.class));
        }
    }

    @Test
@@ -111,7 +120,13 @@ public class ExpandableNotificationRowDragControllerTest extends SysuiTestCase {
        verify(controller).startDragAndDrop(mRow);
        verify(mShadeController).animateCollapseShade(eq(0), eq(true),
                eq(false), anyFloat());
        verify(mNotificationPanelLogger, times(1)).logNotificationDrag(any());
        if (NotificationBundleUi.isEnabled()) {
            verify(mNotificationPanelLogger, times(1))
                    .logNotificationDrag(any(EntryAdapter.class));
        } else {
            verify(mNotificationPanelLogger, times(1))
                    .logNotificationDrag(any(NotificationEntry.class));
        }
    }

    @Test
@@ -129,8 +144,13 @@ public class ExpandableNotificationRowDragControllerTest extends SysuiTestCase {

        // Verify that we never start the actual drag since there is no content
        verify(mRow, never()).startDragAndDrop(any(), any(), any(), anyInt());
        verify(mNotificationPanelLogger, never()).logNotificationDrag(any());
    }
        if (NotificationBundleUi.isEnabled()) {
            verify(mNotificationPanelLogger, never())
                    .logNotificationDrag(any(EntryAdapter.class));
        } else {
            verify(mNotificationPanelLogger, never())
                    .logNotificationDrag(any(NotificationEntry.class));
        }    }

    private ExpandableNotificationRowDragController createSpyController() {
        return spy(mController);
+1 −1
Original line number Diff line number Diff line
@@ -73,7 +73,7 @@ public class NotificationGroupingUtil {
                }
                return null;
            } else {
                return row.getEntry().getSbn().getNotification();
                return row.getEntryLegacy().getSbn().getNotification();
            }
        }
    };
+39 −0
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import android.service.notification.StatusBarNotification;

import com.android.internal.logging.UiEvent;
import com.android.internal.logging.UiEventLogger;
import com.android.systemui.statusbar.notification.collection.EntryAdapter;
import com.android.systemui.statusbar.notification.collection.NotificationEntry;
import com.android.systemui.statusbar.notification.logging.nano.Notifications;
import com.android.systemui.statusbar.notification.stack.PriorityBucket;
@@ -64,6 +65,8 @@ public interface NotificationPanelLogger {
     */
    void logNotificationDrag(NotificationEntry draggedNotification);

    void logNotificationDrag(EntryAdapter draggedNotification);

    enum NotificationPanelEvent implements UiEventLogger.UiEventEnum {
        @UiEvent(doc = "Notification panel shown from status bar.")
        NOTIFICATION_PANEL_OPEN_STATUS_BAR(200),
@@ -122,6 +125,42 @@ public interface NotificationPanelLogger {
        return notificationList;
    }

    /**
     * Composes a NotificationsList proto from the list of visible notifications.
     * @param visibleNotifications as provided by NotificationEntryManager.getVisibleNotifications()
     * @return NotificationList proto suitable for SysUiStatsLog.write(NOTIFICATION_PANEL_REPORTED)
     */
    static Notifications.NotificationList adapterToNotificationProto(
            @Nullable List<EntryAdapter> visibleNotifications) {
        Notifications.NotificationList notificationList = new Notifications.NotificationList();
        if (visibleNotifications == null) {
            return notificationList;
        }
        final Notifications.Notification[] proto_array =
                new Notifications.Notification[visibleNotifications.size()];
        int i = 0;
        for (EntryAdapter ne : visibleNotifications) {
            final StatusBarNotification n = ne.getSbn();
            if (n != null) {
                final Notifications.Notification proto = new Notifications.Notification();
                proto.uid = n.getUid();
                proto.packageName = n.getPackageName();
                if (n.getInstanceId() != null) {
                    proto.instanceId = n.getInstanceId().getId();
                }
                // TODO set np.groupInstanceId
                if (n.getNotification() != null) {
                    proto.isGroupSummary = n.getNotification().isGroupSummary();
                }
                proto.section = toNotificationSection(ne.getSectionBucket());
                proto_array[i] = proto;
            }
            ++i;
        }
        notificationList.notifications = proto_array;
        return notificationList;
    }

    /**
     * Maps PriorityBucket enum to Notification.SECTION constant. The two lists should generally
     * use matching names, but the values may differ, because PriorityBucket order changes from
+12 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.systemui.statusbar.notification.logging;
import static com.android.systemui.statusbar.notification.logging.NotificationPanelLogger.NotificationPanelEvent.NOTIFICATION_DRAG;

import com.android.systemui.shared.system.SysUiStatsLog;
import com.android.systemui.statusbar.notification.collection.EntryAdapter;
import com.android.systemui.statusbar.notification.collection.NotificationEntry;
import com.android.systemui.statusbar.notification.logging.nano.Notifications;
import com.android.systemui.statusbar.notification.shared.NotificationsLiveDataStoreRefactor;
@@ -62,4 +63,15 @@ public class NotificationPanelLoggerImpl implements NotificationPanelLogger {
                /* num_notifications = */ proto.notifications.length,
                /* notifications = */ MessageNano.toByteArray(proto));
    }

    @Override
    public void logNotificationDrag(EntryAdapter draggedNotification) {
        final Notifications.NotificationList proto =
                NotificationPanelLogger.adapterToNotificationProto(
                Collections.singletonList(draggedNotification));
        SysUiStatsLog.write(SysUiStatsLog.NOTIFICATION_PANEL_REPORTED,
                /* event_id = */ NOTIFICATION_DRAG.getId(),
                /* num_notifications = */ proto.notifications.length,
                /* notifications = */ MessageNano.toByteArray(proto));
    }
}
Loading