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

Commit dcf37b6e authored by Winson Chung's avatar Winson Chung
Browse files

Guard against drag and drop failures

- Hypothetical fix for the crash, if the drag listener logic is included
  in multiple views, it's possible that multiple views can try to listen
  to the drag, which will result in cleanup being called multiple times.
  Just in case, we also guard against cleaning up the surface if somehow
  the provided drag surface is not valid.

Fixes: 414168192
Flag: EXEMPT bugfix
Test: atest ExpandableNotificationRowDragControllerTest
Change-Id: I6c8a0b16503fe0964de8db2ecb63287f1360a521
parent 799e09d8
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();