From 4039ba86ff3f9eb52f330608c3ffcb972d439c57 Mon Sep 17 00:00:00 2001 From: Miranda Kephart Date: Fri, 5 Aug 2022 10:42:10 -0400 Subject: [PATCH] Only send uri in share intent if present in clip Currently we always set the EXTRA_URI value in the share intent, even if a uri was not present (null) in the original clip. This causes some receiving apps to throw an error, since they're expecting content from the extra that isn't actually present. Update to only set the extra if we're actually sending content. Bug: 239854368 Fix: 239854368 Test: sent text content to Keep, verified that "Error importing data" toast appeared (before the fix) and did not appear after Change-Id: I39813d9eb512209bc0164c1ecc2fd09e823dc53a --- .../clipboardoverlay/ClipboardOverlayController.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/clipboardoverlay/ClipboardOverlayController.java b/packages/SystemUI/src/com/android/systemui/clipboardoverlay/ClipboardOverlayController.java index e16ac08c88f8e..62c9611903062 100644 --- a/packages/SystemUI/src/com/android/systemui/clipboardoverlay/ClipboardOverlayController.java +++ b/packages/SystemUI/src/com/android/systemui/clipboardoverlay/ClipboardOverlayController.java @@ -522,11 +522,13 @@ public class ClipboardOverlayController { private void shareContent(ClipData clip) { mUiEventLogger.log(CLIPBOARD_OVERLAY_SHARE_TAPPED); Intent shareIntent = new Intent(Intent.ACTION_SEND); - shareIntent.putExtra(Intent.EXTRA_TEXT, clip.getItemAt(0).getText().toString()); shareIntent.setDataAndType( clip.getItemAt(0).getUri(), clip.getDescription().getMimeType(0)); - shareIntent.putExtra(Intent.EXTRA_STREAM, clip.getItemAt(0).getUri()); - shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); + shareIntent.putExtra(Intent.EXTRA_TEXT, clip.getItemAt(0).getText().toString()); + if (clip.getItemAt(0).getUri() != null) { + shareIntent.putExtra(Intent.EXTRA_STREAM, clip.getItemAt(0).getUri()); + shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); + } Intent chooserIntent = Intent.createChooser(shareIntent, null) .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK) .addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);