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

Commit dc778c1a authored by Yorke Lee's avatar Yorke Lee Committed by Android (Google) Code Review
Browse files

Merge "Add URI for unknown contacts to enable quick contact badge" into klp-dev

parents a3b62d1a 58ebe5d3
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -55,6 +55,8 @@ import com.android.contacts.common.ContactPhotoManager;
import com.android.contacts.common.CallUtil;
import com.android.contacts.common.ClipboardUtils;
import com.android.contacts.common.GeoUtil;
import com.android.contacts.common.util.Constants;
import com.android.contacts.common.util.UriUtils;
import com.android.dialer.BackScrollManager.ScrollableHeader;
import com.android.dialer.calllog.CallDetailHistoryAdapter;
import com.android.dialer.calllog.CallTypeHelper;
@@ -450,7 +452,7 @@ public class CallDetailActivity extends Activity implements ProximitySensorAware
                    nameOrNumber = firstDetails.number;
                }

                if (contactUri != null) {
                if (contactUri != null && !UriUtils.isEncodedContactUri(contactUri)) {
                    mainActionIntent = new Intent(Intent.ACTION_VIEW, contactUri);
                    // This will launch People's detail contact screen, so we probably want to
                    // treat it as a separate People task.
+42 −0
Original line number Diff line number Diff line
@@ -19,15 +19,25 @@ package com.android.dialer.calllog;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.provider.ContactsContract;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.provider.ContactsContract.Contacts;
import android.provider.ContactsContract.Directory;
import android.provider.ContactsContract.DisplayNameSources;
import android.provider.ContactsContract.PhoneLookup;
import android.telephony.PhoneNumberUtils;
import android.text.TextUtils;
import android.util.Log;

import com.android.contacts.common.util.Constants;
import com.android.contacts.common.util.UriUtils;
import com.android.dialer.service.CachedNumberLookupService;
import com.android.dialer.service.CachedNumberLookupService.CachedContactInfo;
import com.android.dialerbind.ServiceFactory;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * Utility class to look up the contact information for a given number.
 */
@@ -92,6 +102,7 @@ public class ContactInfoHelper {
                updatedInfo = new ContactInfo();
                updatedInfo.number = number;
                updatedInfo.formattedNumber = formatPhoneNumber(number, null, countryIso);
                updatedInfo.lookupUri = createTemporaryContactUri(number);
            } else {
                updatedInfo = info;
            }
@@ -99,6 +110,37 @@ public class ContactInfoHelper {
        return updatedInfo;
    }

    /**
     * Creates a JSON-encoded lookup uri for a unknown number without an associated contact
     *
     * @param number - Unknown phone number
     * @return JSON-encoded URI that can be used to perform a lookup when clicking
     * on the quick contact card.
     */
    private static Uri createTemporaryContactUri(String number) {
        try {
            final JSONObject contactRows = new JSONObject()
                    .put(Phone.CONTENT_ITEM_TYPE, new JSONObject()
                            .put(Phone.NUMBER, number)
                                    .put(Phone.TYPE, Phone.TYPE_CUSTOM));

            final String jsonString = new JSONObject()
                    .put(Contacts.DISPLAY_NAME, number)
                            .put(Contacts.DISPLAY_NAME_SOURCE, DisplayNameSources.PHONE)
                            .put(Contacts.CONTENT_ITEM_TYPE, contactRows)
                            .toString();

            return Contacts.CONTENT_LOOKUP_URI.buildUpon()
                    .appendPath(Constants.LOOKUP_URI_ENCODED)
                    .appendQueryParameter(Constants.LOOKUP_URI_JSON, jsonString)
                    .appendQueryParameter(ContactsContract.DIRECTORY_PARAM_KEY,
                            String.valueOf(Long.MAX_VALUE))
                    .build();
        } catch (JSONException e) {
            return null;
        }
    }

    /**
     * Looks up a contact using the given URI.
     * <p>