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

Commit 50cc4c86 authored by Ricardo Cerqueira's avatar Ricardo Cerqueira Committed by Adnan
Browse files

ReverseLookup: Don't return OpenCNAM errors as caller IDs

Skip the API entirely for non-US numbers, and ignore any non-200
bodies to avoid names of the "Limit Exceeded" variety

PS2: Use constant from HttpStatus and don't check for null on normalizedNumber
Change-Id: I1ea107ba828e6dba44fa0828ad5fedecb8faf4de
parent 6b0cb568
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import android.util.Pair;

import android.provider.ContactsContract.CommonDataKinds.Phone;

import org.apache.commons.httpclient.HttpStatus;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
@@ -64,6 +65,11 @@ public class OpenCnamReverseLookup extends ReverseLookup {
    public Pair<ContactInfo, Object> lookupNumber(Context context,
            String normalizedNumber, String formattedNumber) {
        String displayName;

        if (normalizedNumber.startsWith("+") &&!normalizedNumber.startsWith("+1")) {
            // Any non-US number will return "We currently accept only US numbers"
            return null;
        }
        try {
            displayName = httpGetRequest(context, normalizedNumber);
            if (DEBUG) Log.d(TAG, "Reverse lookup returned name: " + displayName);
@@ -125,6 +131,10 @@ public class OpenCnamReverseLookup extends ReverseLookup {

        HttpResponse response = client.execute(request);

        if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
            throw new IOException();
        }

        ByteArrayOutputStream out = new ByteArrayOutputStream();
        response.getEntity().writeTo(out);