Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 531745b2 authored by Miranda Kephart's avatar Miranda Kephart
Browse files

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
parent 354ad8b4
Loading
Loading
Loading
Loading
+2 −1
Original line number Original line Diff line number Diff line
@@ -47,7 +47,8 @@ class IntentCreator {
            shareIntent.putExtra(Intent.EXTRA_STREAM, clipData.getItemAt(0).getUri());
            shareIntent.putExtra(Intent.EXTRA_STREAM, clipData.getItemAt(0).getUri());
            shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        } else {
        } 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");
            shareIntent.setType("text/plain");
        }
        }
        Intent chooserIntent = Intent.createChooser(shareIntent, null)
        Intent chooserIntent = Intent.createChooser(shareIntent, null)
+16 −3
Original line number Original line Diff line number Diff line
@@ -16,13 +16,14 @@


package com.android.systemui.clipboardoverlay;
package com.android.systemui.clipboardoverlay;


import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import android.content.ClipData;
import android.content.ClipData;
import android.content.ComponentName;
import android.content.ComponentName;
import android.content.Intent;
import android.content.Intent;
import android.net.Uri;
import android.net.Uri;

import android.text.SpannableString;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;


import androidx.test.filters.SmallTest;
import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;
import androidx.test.runner.AndroidJUnit4;
@@ -129,6 +130,18 @@ public class IntentCreatorTest extends SysuiTestCase {
        assertEquals("image/png", target.getType());
        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
    // Assert that the given flags are set
    private void assertFlags(Intent intent, int flags) {
    private void assertFlags(Intent intent, int flags) {
        assertTrue((intent.getFlags() & flags) == flags);
        assertTrue((intent.getFlags() & flags) == flags);