Merge "Guard against null clipdata objects." into nyc-dev
This commit is contained in:
@@ -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<DocumentInfo> getClippedDocuments() {
|
||||
return getDocumentsFromClipData(mClipboard.getPrimaryClip());
|
||||
ClipData data = mClipboard.getPrimaryClip();
|
||||
return data == null ? Collections.EMPTY_LIST : getDocumentsFromClipData(data);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user