From 531745b291df9e5895fef35aece4291d5addb819 Mon Sep 17 00:00:00 2001 From: Miranda Kephart Date: Wed, 28 Sep 2022 11:44:15 -0400 Subject: [PATCH] Force share intents to use Strings instead of SpannableString Fix: 238837981 Test: copy text, go to edit, recopy, click share, attempt to copy (this is a simple way of getting a SpannableString, since the text from the editor is underlined) atest IntentCreatorTest Change-Id: Ice6c22a53abf149befa9065f478e45d161dfb5bd --- .../clipboardoverlay/IntentCreator.java | 3 ++- .../clipboardoverlay/IntentCreatorTest.java | 19 ++++++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/clipboardoverlay/IntentCreator.java b/packages/SystemUI/src/com/android/systemui/clipboardoverlay/IntentCreator.java index 3d5e601f18f53..e342ac2f320dc 100644 --- a/packages/SystemUI/src/com/android/systemui/clipboardoverlay/IntentCreator.java +++ b/packages/SystemUI/src/com/android/systemui/clipboardoverlay/IntentCreator.java @@ -47,7 +47,8 @@ class IntentCreator { shareIntent.putExtra(Intent.EXTRA_STREAM, clipData.getItemAt(0).getUri()); shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); } else { - shareIntent.putExtra(Intent.EXTRA_TEXT, clipData.getItemAt(0).coerceToText(context)); + shareIntent.putExtra( + Intent.EXTRA_TEXT, clipData.getItemAt(0).coerceToText(context).toString()); shareIntent.setType("text/plain"); } Intent chooserIntent = Intent.createChooser(shareIntent, null) diff --git a/packages/SystemUI/tests/src/com/android/systemui/clipboardoverlay/IntentCreatorTest.java b/packages/SystemUI/tests/src/com/android/systemui/clipboardoverlay/IntentCreatorTest.java index 08fe7c4865297..2a4c0eb18d024 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/clipboardoverlay/IntentCreatorTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/clipboardoverlay/IntentCreatorTest.java @@ -16,13 +16,14 @@ package com.android.systemui.clipboardoverlay; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import android.content.ClipData; import android.content.ComponentName; import android.content.Intent; import android.net.Uri; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import android.text.SpannableString; import androidx.test.filters.SmallTest; import androidx.test.runner.AndroidJUnit4; @@ -129,6 +130,18 @@ public class IntentCreatorTest extends SysuiTestCase { assertEquals("image/png", target.getType()); } + @Test + public void test_getShareIntent_spannableText() { + ClipData clipData = ClipData.newPlainText("Test", new SpannableString("Test Item")); + Intent intent = IntentCreator.getShareIntent(clipData, getContext()); + + assertEquals(Intent.ACTION_CHOOSER, intent.getAction()); + assertFlags(intent, EXTERNAL_INTENT_FLAGS); + Intent target = intent.getParcelableExtra(Intent.EXTRA_INTENT, Intent.class); + assertEquals("Test Item", target.getStringExtra(Intent.EXTRA_TEXT)); + assertEquals("text/plain", target.getType()); + } + // Assert that the given flags are set private void assertFlags(Intent intent, int flags) { assertTrue((intent.getFlags() & flags) == flags);