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

Commit eaff57eb authored by Jan Althaus's avatar Jan Althaus
Browse files

Fixing URL encoding of geo intent links

Bug: 73106770
Test: Added test and manually verified
Change-Id: Ia86450e1f6721cd50567628e4dcdcc34bca0bdf7
parent 29ff057e
Loading
Loading
Loading
Loading
+11 −2
Original line number Diff line number Diff line
@@ -47,7 +47,9 @@ import com.android.internal.util.Preconditions;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.lang.ref.WeakReference;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
@@ -633,8 +635,15 @@ public final class TextClassifierImpl implements TextClassifier {

        @NonNull
        private static List<Intent> createForAddress(String text) {
            return Arrays.asList(new Intent(Intent.ACTION_VIEW)
                    .setData(Uri.parse(String.format("geo:0,0?q=%s", text))));
            final List<Intent> intents = new ArrayList<>();
            try {
                final String encText = URLEncoder.encode(text, "UTF-8");
                intents.add(new Intent(Intent.ACTION_VIEW)
                        .setData(Uri.parse(String.format("geo:0,0?q=%s", encText))));
            } catch (UnsupportedEncodingException e) {
                Log.e(LOG_TAG, "Could not encode address", e);
            }
            return intents;
        }

        @NonNull
+18 −0
Original line number Diff line number Diff line
@@ -147,6 +147,20 @@ public class TextClassificationManagerTest {
                        "http://" + classifiedText));
    }

    @Test
    public void testTextClassifyText_address() {
        if (isTextClassifierDisabled()) return;

        String text = "Brandschenkestrasse 110, Zürich, Switzerland";
        TextClassification classification = mClassifier.classifyText(
                text, 0, text.length(), mClassificationOptions);
        assertThat(classification,
                isTextClassification(
                        text,
                        TextClassifier.TYPE_ADDRESS,
                        "geo:0,0?q=Brandschenkestrasse+110%2C+Z%C3%BCrich%2C+Switzerland"));
    }

    @Test
    public void testTextClassifyText_url_inCaps() {
        if (isTextClassifierDisabled()) return;
@@ -315,6 +329,10 @@ public class TextClassificationManagerTest {
                            typeRequirementSatisfied = "http".equals(scheme)
                                    || "https".equals(scheme);
                            break;
                        case TextClassifier.TYPE_ADDRESS:
                            scheme = result.getIntent().getData().getScheme();
                            typeRequirementSatisfied = "geo".equals(scheme);
                            break;
                        default:
                            typeRequirementSatisfied = true;
                    }