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
This commit is contained in:
Miranda Kephart
2022-09-28 11:44:15 -04:00
parent 354ad8b465
commit 531745b291
2 changed files with 18 additions and 4 deletions

View File

@@ -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)

View File

@@ -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);