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

Commit 00a6ab64 authored by Winson Chung's avatar Winson Chung
Browse files

Fix NPE due to null clip descriptions

- Some apps start drags without clip descriptions, any logging should
  account for that as well

Flag: EXEMPT bugfix
Bug: 385901897
Test: atest WMShellUnitTests:DragAndDropControllerTest
Change-Id: I0aaa9484b440bb0553d09e485f12759bf46c706b
parent 8c66db85
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -107,8 +107,11 @@ public class DragUtils {
    /**
     * Returns a list of the mime types provided in the clip description.
     */
    public static String getMimeTypesConcatenated(ClipDescription description) {
    public static String getMimeTypesConcatenated(@Nullable ClipDescription description) {
        String mimeTypes = "";
        if (description == null) {
            return mimeTypes;
        }
        for (int i = 0; i < description.getMimeTypeCount(); i++) {
            if (i > 0) {
                mimeTypes += ", ";
+2 −3
Original line number Diff line number Diff line
@@ -152,17 +152,16 @@ public class DragAndDropControllerTest extends ShellTestCase {
    }

    @Test
    public void testOnDragStarted_withNoClipData() {
    public void testOnDragStarted_withNoClipDataOrDescription() {
        final View dragLayout = mock(View.class);
        final Display display = mock(Display.class);
        doReturn(display).when(dragLayout).getDisplay();
        doReturn(DEFAULT_DISPLAY).when(display).getDisplayId();

        final ClipData clipData = createAppClipData(MIMETYPE_APPLICATION_SHORTCUT);
        final DragEvent event = mock(DragEvent.class);
        doReturn(ACTION_DRAG_STARTED).when(event).getAction();
        doReturn(null).when(event).getClipData();
        doReturn(clipData.getDescription()).when(event).getClipDescription();
        doReturn(null).when(event).getClipDescription();

        // Ensure there's a target so that onDrag will execute
        mController.addDisplayDropTarget(0, mContext, mock(WindowManager.class),