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

Commit 422ec51d authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fixing URL encoding of geo intent links"

parents 33ff3147 eaff57eb
Loading
Loading
Loading
Loading
+11 −2
Original line number Original line Diff line number Diff line
@@ -47,7 +47,9 @@ import com.android.internal.util.Preconditions;
import java.io.File;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.lang.ref.WeakReference;
import java.lang.ref.WeakReference;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Calendar;
@@ -633,8 +635,15 @@ public final class TextClassifierImpl implements TextClassifier {


        @NonNull
        @NonNull
        private static List<Intent> createForAddress(String text) {
        private static List<Intent> createForAddress(String text) {
            return Arrays.asList(new Intent(Intent.ACTION_VIEW)
            final List<Intent> intents = new ArrayList<>();
                    .setData(Uri.parse(String.format("geo:0,0?q=%s", text))));
            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
        @NonNull
+18 −0
Original line number Original line Diff line number Diff line
@@ -147,6 +147,20 @@ public class TextClassificationManagerTest {
                        "http://" + classifiedText));
                        "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
    @Test
    public void testTextClassifyText_url_inCaps() {
    public void testTextClassifyText_url_inCaps() {
        if (isTextClassifierDisabled()) return;
        if (isTextClassifierDisabled()) return;
@@ -315,6 +329,10 @@ public class TextClassificationManagerTest {
                            typeRequirementSatisfied = "http".equals(scheme)
                            typeRequirementSatisfied = "http".equals(scheme)
                                    || "https".equals(scheme);
                                    || "https".equals(scheme);
                            break;
                            break;
                        case TextClassifier.TYPE_ADDRESS:
                            scheme = result.getIntent().getData().getScheme();
                            typeRequirementSatisfied = "geo".equals(scheme);
                            break;
                        default:
                        default:
                            typeRequirementSatisfied = true;
                            typeRequirementSatisfied = true;
                    }
                    }