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

Commit 040d4972 authored by Vladislav Kaznacheev's avatar Vladislav Kaznacheev
Browse files

resolve merge conflicts of c1790bef to master

Change-Id: I4b758ba23cc7ae2363f553395fbb52da615effd1
parents 071c4545 c1790bef
Loading
Loading
Loading
Loading
+21 −1
Original line number Diff line number Diff line
@@ -35,7 +35,9 @@ import com.android.documentsui.services.FileOperationService.OpType;
import libcore.io.IoUtils;

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

/**
@@ -124,6 +126,7 @@ public final class DocumentClipper {
     */
    public @Nullable ClipData getClipDataForDocuments(List<DocumentInfo> docs, @OpType int opType) {
        final ContentResolver resolver = mContext.getContentResolver();
        final String[] mimeTypes = getMimeTypes(resolver, docs);
        ClipData clipData = null;
        for (DocumentInfo doc : docs) {
            assert(doc != null);
@@ -132,7 +135,7 @@ public final class DocumentClipper {
                // TODO: figure out what this string should be.
                // Currently it is not displayed anywhere in the UI, but this might change.
                final String clipLabel = "";
                clipData = ClipData.newUri(resolver, clipLabel, doc.derivedUri);
                clipData = new ClipData(clipLabel, mimeTypes, new ClipData.Item(doc.derivedUri));
                PersistableBundle bundle = new PersistableBundle();
                bundle.putInt(OP_TYPE_KEY, opType);
                clipData.getDescription().setExtras(bundle);
@@ -144,6 +147,23 @@ public final class DocumentClipper {
        return clipData;
    }

    private static String[] getMimeTypes(ContentResolver resolver, List<DocumentInfo> docs) {
        final HashSet<String> mimeTypes = new HashSet<>();
        for (DocumentInfo doc : docs) {
            assert(doc != null);
            assert(doc.derivedUri != null);
            final Uri uri = doc.derivedUri;
            if ("content".equals(uri.getScheme())) {
                mimeTypes.add(resolver.getType(uri));
                final String[] streamTypes = resolver.getStreamTypes(uri, "*/*");
                if (streamTypes != null) {
                    mimeTypes.addAll(Arrays.asList(streamTypes));
                }
            }
        }
        return mimeTypes.toArray(new String[0]);
    }

    /**
     * Puts {@code ClipData} in a primary clipboard, describing a copy operation
     */