diff --git a/packages/DocumentsUI/src/com/android/documentsui/DocumentClipper.java b/packages/DocumentsUI/src/com/android/documentsui/DocumentClipper.java index 15bfc3b930875..059b5e09cc908 100644 --- a/packages/DocumentsUI/src/com/android/documentsui/DocumentClipper.java +++ b/packages/DocumentsUI/src/com/android/documentsui/DocumentClipper.java @@ -32,6 +32,7 @@ import com.android.documentsui.model.DocumentInfo; import libcore.io.IoUtils; import java.util.ArrayList; +import java.util.Collections; import java.util.List; /** @@ -76,7 +77,8 @@ public final class DocumentClipper { * This should be run from inside an AsyncTask. */ public List getClippedDocuments() { - return getDocumentsFromClipData(mClipboard.getPrimaryClip()); + ClipData data = mClipboard.getPrimaryClip(); + return data == null ? Collections.EMPTY_LIST : getDocumentsFromClipData(data); } /** diff --git a/packages/DocumentsUI/src/com/android/documentsui/dirlist/DirectoryFragment.java b/packages/DocumentsUI/src/com/android/documentsui/dirlist/DirectoryFragment.java index 22454ad9d16f3..ccb2886ff0247 100644 --- a/packages/DocumentsUI/src/com/android/documentsui/dirlist/DirectoryFragment.java +++ b/packages/DocumentsUI/src/com/android/documentsui/dirlist/DirectoryFragment.java @@ -1179,14 +1179,23 @@ public class DirectoryFragment extends Fragment case DragEvent.ACTION_DROP: // After a drop event, always stop highlighting the target. setDropTargetHighlight(v, false); + + ClipData clipData = event.getClipData(); + if (clipData == null) { + Log.w(TAG, "Received invalid drop event with null clipdata. Ignoring."); + return false; + } + // Don't copy from the cwd into the cwd. Note: this currently doesn't work for // multi-window drag, because localState isn't carried over from one process to // another. Object src = event.getLocalState(); DocumentInfo dst = getDestination(v); if (Objects.equals(src, dst)) { + if (DEBUG) Log.d(TAG, "Drop target same as source. Ignoring."); return false; } + // Recognize multi-window drag and drop based on the fact that localState is not // carried between processes. It will stop working when the localsState behavior // is changed. The info about window should be passed in the localState then. @@ -1195,7 +1204,8 @@ public class DirectoryFragment extends Fragment Metrics.logUserAction(getContext(), src == null ? Metrics.USER_ACTION_DRAG_N_DROP_MULTI_WINDOW : Metrics.USER_ACTION_DRAG_N_DROP); - copyFromClipData(event.getClipData(), dst); + + copyFromClipData(clipData, dst); return true; } return false;