resolve merge conflicts of 9d17528 to nyc-andromeda-dev
Change-Id: I6c6d75fe6630c8e28cb9d42bb39ee4fdd5adccaf
diff --git a/src/com/android/documentsui/DocumentClipper.java b/src/com/android/documentsui/DocumentClipper.java
index 908396c..51c47a4 100644
--- a/src/com/android/documentsui/DocumentClipper.java
+++ b/src/com/android/documentsui/DocumentClipper.java
@@ -35,7 +35,9 @@
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 @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 @@
// 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 @@
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
*/