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

Commit a2295e65 authored by Makoto Onuki's avatar Makoto Onuki
Browse files

Enterprise caller-id: framework/base/Telephony

It's basically equivalent to http://ag/500455 and http://ag/499160.

Now "Send to voicemail" and the missed call notification uses the enterprise
lookup; they now work with a corp contact too.

Bug 15779911

Change-Id: I8a87f45ba7299cfbc516eb44326e02258e38cf63
parent e00c0c67
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -408,7 +408,7 @@ public class CallLog {
                values.put(CACHED_NUMBER_LABEL, ci.numberLabel);
            }

            if ((ci != null) && (ci.person_id > 0)) {
            if ((ci != null) && (ci.contactIdOrZero > 0)) {
                // Update usage information for the number associated with the contact ID.
                // We need to use both the number and the ID for obtaining a data ID since other
                // contacts may have the same number.
@@ -422,7 +422,8 @@ public class CallLog {
                    cursor = resolver.query(Phone.CONTENT_URI,
                            new String[] { Phone._ID },
                            Phone.CONTACT_ID + " =? AND " + Phone.NORMALIZED_NUMBER + " =?",
                            new String[] { String.valueOf(ci.person_id), normalizedPhoneNumber},
                            new String[] { String.valueOf(ci.contactIdOrZero),
                                    normalizedPhoneNumber},
                            null);
                } else {
                    final String phoneNumber = ci.phoneNumber != null ? ci.phoneNumber : number;
@@ -431,7 +432,7 @@ public class CallLog {
                                    Uri.encode(phoneNumber)),
                            new String[] { Phone._ID },
                            Phone.CONTACT_ID + " =?",
                            new String[] { String.valueOf(ci.person_id) },
                            new String[] { String.valueOf(ci.contactIdOrZero) },
                            null);
                }

+32 −42
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.location.Country;
import android.location.CountryDetector;
import android.net.Uri;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.provider.ContactsContract.Contacts;
import android.provider.ContactsContract.Data;
import android.provider.ContactsContract.PhoneLookup;
import android.provider.ContactsContract.RawContacts;
@@ -96,10 +97,18 @@ public class CallerInfo {
    public String numberLabel;

    public int photoResource;
    public long person_id;

    // Contact ID, which will be 0 if a contact comes from the corp CP2.
    public long contactIdOrZero;
    public boolean needUpdate;
    public Uri contactRefUri;

    /**
     * Contact display photo URI.  If a contact has no display photo but a thumbnail, it'll be
     * the thumbnail URI instead.
     */
    public Uri contactDisplayPhotoUri;

    // fields to hold individual contact preference data,
    // including the send to voicemail flag and the ringtone
    // uri reference.
@@ -209,16 +218,29 @@ public class CallerInfo {
                // Look for the person_id.
                columnIndex = getColumnIndexForPersonId(contactRef, cursor);
                if (columnIndex != -1) {
                    info.person_id = cursor.getLong(columnIndex);
                    if (VDBG) Rlog.v(TAG, "==> got info.person_id: " + info.person_id);
                    final long contactId = cursor.getLong(columnIndex);
                    if (contactId != 0 && !Contacts.isCorpContactId(contactId)) {
                        info.contactIdOrZero = contactId;
                        if (VDBG) {
                            Rlog.v(TAG, "==> got info.contactIdOrZero: " + info.contactIdOrZero);
                        }
                    }
                } else {
                    // No valid columnIndex, so we can't look up person_id.
                    Rlog.w(TAG, "Couldn't find person_id column for " + contactRef);
                    Rlog.w(TAG, "Couldn't find contact_id column for " + contactRef);
                    // Watch out: this means that anything that depends on
                    // person_id will be broken (like contact photo lookups in
                    // the in-call UI, for example.)
                }

                // Display photo URI.
                columnIndex = cursor.getColumnIndex(PhoneLookup.PHOTO_URI);
                if ((columnIndex != -1) && (cursor.getString(columnIndex) != null)) {
                    info.contactDisplayPhotoUri = Uri.parse(cursor.getString(columnIndex));
                } else {
                    info.contactDisplayPhotoUri = null;
                }

                // look for the custom ringtone, create from the string stored
                // in the database.
                columnIndex = cursor.getColumnIndex(PhoneLookup.CUSTOM_RINGTONE);
@@ -303,7 +325,8 @@ public class CallerInfo {
            return new CallerInfo().markAsVoiceMail();
        }

        Uri contactUri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number));
        Uri contactUri = Uri.withAppendedPath(PhoneLookup.ENTERPRISE_CONTENT_FILTER_URI,
                Uri.encode(number));

        CallerInfo info = getCallerInfo(context, contactUri);
        info = doSecondaryLookupIfNecessary(context, number, info);
@@ -334,46 +357,13 @@ public class CallerInfo {
            String username = PhoneNumberUtils.getUsernameFromUriNumber(number);
            if (PhoneNumberUtils.isGlobalPhoneNumber(username)) {
                previousResult = getCallerInfo(context,
                        Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI,
                        Uri.withAppendedPath(PhoneLookup.ENTERPRISE_CONTENT_FILTER_URI,
                                Uri.encode(username)));
            }
        }
        return previousResult;
    }

    /**
     * getCallerId: a convenience method to get the caller id for a given
     * number.
     *
     * @param context the context used to get the ContentResolver.
     * @param number a phone number.
     * @return if the number belongs to a contact, the contact's name is
     * returned; otherwise, the number itself is returned.
     *
     * TODO NOTE: This MAY need to refer to the Asynchronous Query API
     * [startQuery()], instead of getCallerInfo, but since it looks like
     * it is only being used by the provider calls in the messaging app:
     *   1. android.provider.Telephony.Mms.getDisplayAddress()
     *   2. android.provider.Telephony.Sms.getDisplayAddress()
     * We may not need to make the change.
     */
    public static String getCallerId(Context context, String number) {
        CallerInfo info = getCallerInfo(context, number);
        String callerID = null;

        if (info != null) {
            String name = info.name;

            if (!TextUtils.isEmpty(name)) {
                callerID = name;
            } else {
                callerID = number;
            }
        }

        return callerID;
    }

    // Accessors

    /**
@@ -636,10 +626,10 @@ public class CallerInfo {
                    .append("\nnumberType: " + numberType)
                    .append("\nnumberLabel: " + numberLabel)
                    .append("\nphotoResource: " + photoResource)
                    .append("\nperson_id: " + person_id)
                    .append("\ncontactIdOrZero: " + contactIdOrZero)
                    .append("\nneedUpdate: " + needUpdate)
                    .append("\ncontactRefUri: " + contactRefUri)
                    .append("\ncontactRingtoneUri: " + contactRefUri)
                    .append("\ncontactRingtoneUri: " + contactRingtoneUri)
                    .append("\ncontactDisplayPhotoUri: " + contactDisplayPhotoUri)
                    .append("\nshouldSendToVoicemail: " + shouldSendToVoicemail)
                    .append("\ncachedPhoto: " + cachedPhoto)
                    .append("\nisCachedPhotoCurrent: " + isCachedPhotoCurrent)
+7 −44
Original line number Diff line number Diff line
@@ -376,51 +376,14 @@ public class CallerInfoAsyncQuery {

        // Construct the URI object and query params, and start the query.

        Uri contactRef;
        String selection;
        String[] selectionArgs;

        if (PhoneNumberUtils.isUriNumber(number)) {
            // "number" is really a SIP address.
            if (DBG) Rlog.d(LOG_TAG, "  - Treating number as a SIP address: " + /*number*/ "xxxxxxx");

            // We look up SIP addresses directly in the Data table:
            contactRef = Data.CONTENT_URI;

            // Note Data.DATA1 and SipAddress.SIP_ADDRESS are equivalent.
            //
            // Also note we use "upper(data1)" in the WHERE clause, and
            // uppercase the incoming SIP address, in order to do a
            // case-insensitive match.
            //
            // TODO: need to confirm that the use of upper() doesn't
            // prevent us from using the index!  (Linear scan of the whole
            // contacts DB can be very slow.)
            //
            // TODO: May also need to normalize by adding "sip:" as a
            // prefix, if we start storing SIP addresses that way in the
            // database.

            selection = "upper(" + Data.DATA1 + ")=?"
                    + " AND "
                    + Data.MIMETYPE + "='" + SipAddress.CONTENT_ITEM_TYPE + "'";
            selectionArgs = new String[] { number.toUpperCase() };

        } else {
            // "number" is a regular phone number.  Use the PhoneLookup table:
            contactRef = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number));
            selection = null;
            selectionArgs = null;
        }
        final Uri contactRef = PhoneLookup.ENTERPRISE_CONTENT_FILTER_URI.buildUpon()
                .appendPath(number)
                .appendQueryParameter(PhoneLookup.QUERY_PARAMETER_SIP_ADDRESS,
                        String.valueOf(PhoneNumberUtils.isUriNumber(number)))
                .build();

        if (DBG) {
            Rlog.d(LOG_TAG, "==> contactRef: " + sanitizeUriToString(contactRef));
            Rlog.d(LOG_TAG, "==> selection: " + selection);
            if (selectionArgs != null) {
                for (int i = 0; i < selectionArgs.length; i++) {
                    Rlog.d(LOG_TAG, "==> selectionArgs[" + i + "]: " + selectionArgs[i]);
                }
            }
        }

        CallerInfoAsyncQuery c = new CallerInfoAsyncQuery();
@@ -446,8 +409,8 @@ public class CallerInfoAsyncQuery {
                              cw,  // cookie
                              contactRef,  // uri
                              null,  // projection
                              selection,  // selection
                              selectionArgs,  // selectionArgs
                              null,  // selection
                              null,  // selectionArgs
                              null);  // orderBy
        return c;
    }