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

Commit bd195919 authored by Winson Chung's avatar Winson Chung Committed by Android (Google) Code Review
Browse files

Merge "Guard against drag and drop failures" into main

parents 94f0108c dcf37b6e
Loading
Loading
Loading
Loading
+19 −1
Original line number Diff line number Diff line
@@ -135,7 +135,25 @@ public class ExpandableNotificationRowDragControllerTest extends SysuiTestCase {
        } else {
            verify(mNotificationPanelLogger, never())
                    .logNotificationDrag(any(NotificationEntry.class));
        }    }
        }
    }

    @Test
    public void testCleanUpDragListenerOnDragFailed() {
        ExpandableNotificationRowDragController controller = createSpyController();
        mRow.setDragController(controller);
        mRow.setHeadsUp(true);
        mRow.setPinnedStatus(PinnedStatus.PinnedBySystem);

        // Simulate a failure to initiate drag and drop
        doReturn(false).when(mRow).startDragAndDrop(any(), any(), any(), anyInt());

        mRow.doLongClickCallback(0, 0);
        mRow.doDragCallback(0, 0);

        // Verify that we've reset the listener
        verify(mRow).setOnDragListener(null);
    }

    private ExpandableNotificationRowDragController createSpyController() {
        return spy(mController);
+7 −0
Original line number Diff line number Diff line
@@ -144,6 +144,7 @@ public class ExpandableNotificationRowDragController {
        boolean result = view.startDragAndDrop(dragData, myShadow, null, View.DRAG_FLAG_GLOBAL
                | View.DRAG_FLAG_REQUEST_SURFACE_FOR_RETURN_ANIMATION);
        if (result) {
            Log.d(TAG, "Starting drag from notification view=" + view);
            // Log notification drag only if it succeeds
            if (NotificationBundleUi.isEnabled()) {
                mNotificationPanelLogger.logNotificationDrag(enr.getEntryAdapter());
@@ -156,6 +157,9 @@ public class ExpandableNotificationRowDragController {
            } else {
                dismissShade();
            }
        } else {
            Log.w(TAG, "Failed to starting drag from notification view=" + view);
            view.setOnDragListener(null);
        }
    }

@@ -255,6 +259,9 @@ public class ExpandableNotificationRowDragController {
            }

            private void cleanUpSurface() {
                if (!dragSurface.isValid()) {
                    return;
                }
                tx.remove(dragSurface);
                tx.apply();
                tx.close();