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

Commit 22b35a75 authored by Steve McKay's avatar Steve McKay
Browse files

Guard against null clipdata objects.

Bug: 28074897
Change-Id: I7f0e520d6f1ce40e6db2fbead21ee4bb37aa3a61
parent ba20e81c
Loading
Loading
Loading
Loading
+3 −1
Original line number Original line Diff line number Diff line
@@ -32,6 +32,7 @@ import com.android.documentsui.model.DocumentInfo;
import libcore.io.IoUtils;
import libcore.io.IoUtils;


import java.util.ArrayList;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.List;


/**
/**
@@ -76,7 +77,8 @@ public final class DocumentClipper {
     * This should be run from inside an AsyncTask.
     * This should be run from inside an AsyncTask.
     */
     */
    public List<DocumentInfo> getClippedDocuments() {
    public List<DocumentInfo> getClippedDocuments() {
        return getDocumentsFromClipData(mClipboard.getPrimaryClip());
        ClipData data = mClipboard.getPrimaryClip();
        return data == null ? Collections.EMPTY_LIST : getDocumentsFromClipData(data);
    }
    }


    /**
    /**
+11 −1
Original line number Original line Diff line number Diff line
@@ -1176,14 +1176,23 @@ public class DirectoryFragment extends Fragment
                case DragEvent.ACTION_DROP:
                case DragEvent.ACTION_DROP:
                    // After a drop event, always stop highlighting the target.
                    // After a drop event, always stop highlighting the target.
                    setDropTargetHighlight(v, false);
                    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
                    // 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
                    // multi-window drag, because localState isn't carried over from one process to
                    // another.
                    // another.
                    Object src = event.getLocalState();
                    Object src = event.getLocalState();
                    DocumentInfo dst = getDestination(v);
                    DocumentInfo dst = getDestination(v);
                    if (Objects.equals(src, dst)) {
                    if (Objects.equals(src, dst)) {
                        if (DEBUG) Log.d(TAG, "Drop target same as source. Ignoring.");
                        return false;
                        return false;
                    }
                    }

                    // Recognize multi-window drag and drop based on the fact that localState is not
                    // 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
                    // carried between processes. It will stop working when the localsState behavior
                    // is changed. The info about window should be passed in the localState then.
                    // is changed. The info about window should be passed in the localState then.
@@ -1192,7 +1201,8 @@ public class DirectoryFragment extends Fragment
                    Metrics.logUserAction(getContext(),
                    Metrics.logUserAction(getContext(),
                            src == null ? Metrics.USER_ACTION_DRAG_N_DROP_MULTI_WINDOW
                            src == null ? Metrics.USER_ACTION_DRAG_N_DROP_MULTI_WINDOW
                                    : Metrics.USER_ACTION_DRAG_N_DROP);
                                    : Metrics.USER_ACTION_DRAG_N_DROP);
                    copyFromClipData(event.getClipData(), dst);

                    copyFromClipData(clipData, dst);
                    return true;
                    return true;
            }
            }
            return false;
            return false;