Guard against apps breaking CHOOSER contract.
Bug: 6520937
Change-Id: I677a644cf7765bbb046f9c82e1ebd8a40968cee6
diff --git a/core/java/android/content/Intent.java b/core/java/android/content/Intent.java
index 718a917..edd509b 100644
--- a/core/java/android/content/Intent.java
+++ b/core/java/android/content/Intent.java
@@ -6653,17 +6653,20 @@
final String action = getAction();
if (ACTION_CHOOSER.equals(action)) {
- // Inspect target intent to see if we need to migrate
- final Intent target = getParcelableExtra(EXTRA_INTENT);
- if (target.migrateExtraStreamToClipData()) {
- // Since we migrated in child, we need to promote ClipData and
- // flags to ourselves to grant.
- setClipData(target.getClipData());
- addFlags(target.getFlags()
- & (FLAG_GRANT_READ_URI_PERMISSION | FLAG_GRANT_WRITE_URI_PERMISSION));
- return true;
- } else {
- return false;
+ try {
+ // Inspect target intent to see if we need to migrate
+ final Intent target = getParcelableExtra(EXTRA_INTENT);
+ if (target != null && target.migrateExtraStreamToClipData()) {
+ // Since we migrated in child, we need to promote ClipData
+ // and flags to ourselves to grant.
+ setClipData(target.getClipData());
+ addFlags(target.getFlags()
+ & (FLAG_GRANT_READ_URI_PERMISSION | FLAG_GRANT_WRITE_URI_PERMISSION));
+ return true;
+ } else {
+ return false;
+ }
+ } catch (ClassCastException e) {
}
} else if (ACTION_SEND.equals(action)) {