Copy EXTRA_STREAM into ClipData and grant.
When sending SEND or SEND_MULTIPLE intents, copy any EXTRA_STREAM
Uris to ClipData and set GRANT_READ_URI_PERMISSION flag.
Bug: 6216357
Change-Id: I3c9b0d1d4b7e0c4655b47c4192150b0c3641e0e8
diff --git a/core/java/android/app/Instrumentation.java b/core/java/android/app/Instrumentation.java
index 16299de..e4f7950 100644
--- a/core/java/android/app/Instrumentation.java
+++ b/core/java/android/app/Instrumentation.java
@@ -1381,6 +1381,7 @@
}
try {
intent.setAllowFds(false);
+ intent.migrateExtraStreamToClipData();
int result = ActivityManagerNative.getDefault()
.startActivity(whoThread, intent,
intent.resolveTypeIfNeeded(who.getContentResolver()),
@@ -1479,6 +1480,7 @@
}
try {
intent.setAllowFds(false);
+ intent.migrateExtraStreamToClipData();
int result = ActivityManagerNative.getDefault()
.startActivity(whoThread, intent,
intent.resolveTypeIfNeeded(who.getContentResolver()),
diff --git a/core/java/android/content/Intent.java b/core/java/android/content/Intent.java
index 6cf5b43..1c9ef38 100644
--- a/core/java/android/content/Intent.java
+++ b/core/java/android/content/Intent.java
@@ -6467,4 +6467,46 @@
}
return type;
}
+
+ /**
+ * Migrate any {@link #EXTRA_STREAM} in {@link #ACTION_SEND} and
+ * {@link #ACTION_SEND_MULTIPLE} to {@link ClipData}.
+ *
+ * @hide
+ */
+ public void migrateExtraStreamToClipData() {
+ // Refuse to touch if extras already parcelled
+ if (mExtras != null && mExtras.isParcelled()) return;
+
+ // Bail when someone already gave us ClipData
+ if (getClipData() != null) return;
+
+ final String action = getAction();
+ if (ACTION_SEND.equals(action)) {
+ final Uri stream = getParcelableExtra(EXTRA_STREAM);
+ if (stream != null) {
+ final ClipData clipData = new ClipData(
+ null, new String[] { getType() }, new ClipData.Item(stream));
+
+ setClipData(clipData);
+ addFlags(FLAG_GRANT_READ_URI_PERMISSION);
+ }
+
+ } else if (ACTION_SEND_MULTIPLE.equals(action)) {
+ final ArrayList<Uri> streams = getParcelableArrayListExtra(EXTRA_STREAM);
+ if (streams != null && streams.size() > 0) {
+ final Uri firstStream = streams.get(0);
+ final ClipData clipData = new ClipData(
+ null, new String[] { getType() }, new ClipData.Item(firstStream));
+
+ final int size = streams.size();
+ for (int i = 1; i < size; i++) {
+ clipData.addItem(new ClipData.Item(streams.get(i)));
+ }
+
+ setClipData(clipData);
+ addFlags(FLAG_GRANT_READ_URI_PERMISSION);
+ }
+ }
+ }
}
diff --git a/core/java/android/os/Bundle.java b/core/java/android/os/Bundle.java
index 28206b7..51cb91c8 100644
--- a/core/java/android/os/Bundle.java
+++ b/core/java/android/os/Bundle.java
@@ -226,6 +226,13 @@
}
/**
+ * @hide
+ */
+ public boolean isParcelled() {
+ return mParcelledData != null;
+ }
+
+ /**
* Returns the number of mappings contained in this Bundle.
*
* @return the number of mappings as an int.