Skip to content

Commit 0c44525

Browse files
jsharkeyAndroid (Google) Code Review
authored andcommitted
Merge "Copy EXTRA_STREAM into ClipData and grant."
2 parents 2cd24ec + 678d04f commit 0c44525

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

core/java/android/app/Instrumentation.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,6 +1381,7 @@ public ActivityResult execStartActivity(
13811381
}
13821382
try {
13831383
intent.setAllowFds(false);
1384+
intent.migrateExtraStreamToClipData();
13841385
int result = ActivityManagerNative.getDefault()
13851386
.startActivity(whoThread, intent,
13861387
intent.resolveTypeIfNeeded(who.getContentResolver()),
@@ -1479,6 +1480,7 @@ public ActivityResult execStartActivity(
14791480
}
14801481
try {
14811482
intent.setAllowFds(false);
1483+
intent.migrateExtraStreamToClipData();
14821484
int result = ActivityManagerNative.getDefault()
14831485
.startActivity(whoThread, intent,
14841486
intent.resolveTypeIfNeeded(who.getContentResolver()),

core/java/android/content/Intent.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6467,4 +6467,46 @@ public static String normalizeMimeType(String type) {
64676467
}
64686468
return type;
64696469
}
6470+
6471+
/**
6472+
* Migrate any {@link #EXTRA_STREAM} in {@link #ACTION_SEND} and
6473+
* {@link #ACTION_SEND_MULTIPLE} to {@link ClipData}.
6474+
*
6475+
* @hide
6476+
*/
6477+
public void migrateExtraStreamToClipData() {
6478+
// Refuse to touch if extras already parcelled
6479+
if (mExtras != null && mExtras.isParcelled()) return;
6480+
6481+
// Bail when someone already gave us ClipData
6482+
if (getClipData() != null) return;
6483+
6484+
final String action = getAction();
6485+
if (ACTION_SEND.equals(action)) {
6486+
final Uri stream = getParcelableExtra(EXTRA_STREAM);
6487+
if (stream != null) {
6488+
final ClipData clipData = new ClipData(
6489+
null, new String[] { getType() }, new ClipData.Item(stream));
6490+
6491+
setClipData(clipData);
6492+
addFlags(FLAG_GRANT_READ_URI_PERMISSION);
6493+
}
6494+
6495+
} else if (ACTION_SEND_MULTIPLE.equals(action)) {
6496+
final ArrayList<Uri> streams = getParcelableArrayListExtra(EXTRA_STREAM);
6497+
if (streams != null && streams.size() > 0) {
6498+
final Uri firstStream = streams.get(0);
6499+
final ClipData clipData = new ClipData(
6500+
null, new String[] { getType() }, new ClipData.Item(firstStream));
6501+
6502+
final int size = streams.size();
6503+
for (int i = 1; i < size; i++) {
6504+
clipData.addItem(new ClipData.Item(streams.get(i)));
6505+
}
6506+
6507+
setClipData(clipData);
6508+
addFlags(FLAG_GRANT_READ_URI_PERMISSION);
6509+
}
6510+
}
6511+
}
64706512
}

core/java/android/os/Bundle.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,13 @@ public Object clone() {
225225
mParcelledData = null;
226226
}
227227

228+
/**
229+
* @hide
230+
*/
231+
public boolean isParcelled() {
232+
return mParcelledData != null;
233+
}
234+
228235
/**
229236
* Returns the number of mappings contained in this Bundle.
230237
*

0 commit comments

Comments
 (0)