1/*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.internal.telephony;
18
19import android.content.Context;
20import android.database.Cursor;
21import android.graphics.Bitmap;
22import android.graphics.drawable.Drawable;
23import android.location.Country;
24import android.location.CountryDetector;
25import android.net.Uri;
26import android.provider.ContactsContract.CommonDataKinds.Phone;
27import android.provider.ContactsContract.Contacts;
28import android.provider.ContactsContract.Data;
29import android.provider.ContactsContract.PhoneLookup;
30import android.provider.ContactsContract.RawContacts;
31import android.telephony.PhoneNumberUtils;
32import android.telephony.TelephonyManager;
33import android.text.TextUtils;
34import android.telephony.Rlog;
35import android.util.Log;
36
37import com.android.i18n.phonenumbers.geocoding.PhoneNumberOfflineGeocoder;
38import com.android.i18n.phonenumbers.NumberParseException;
39import com.android.i18n.phonenumbers.PhoneNumberUtil;
40import com.android.i18n.phonenumbers.Phonenumber.PhoneNumber;
41import android.telephony.SubscriptionManager;
42
43import java.util.Locale;
44
45
46/**
47 * Looks up caller information for the given phone number.
48 *
49 * {@hide}
50 */
51public class CallerInfo {
52    private static final String TAG = "CallerInfo";
53    private static final boolean VDBG = Rlog.isLoggable(TAG, Log.VERBOSE);
54
55    /**
56     * Please note that, any one of these member variables can be null,
57     * and any accesses to them should be prepared to handle such a case.
58     *
59     * Also, it is implied that phoneNumber is more often populated than
60     * name is, (think of calls being dialed/received using numbers where
61     * names are not known to the device), so phoneNumber should serve as
62     * a dependable fallback when name is unavailable.
63     *
64     * One other detail here is that this CallerInfo object reflects
65     * information found on a connection, it is an OUTPUT that serves
66     * mainly to display information to the user.  In no way is this object
67     * used as input to make a connection, so we can choose to display
68     * whatever human-readable text makes sense to the user for a
69     * connection.  This is especially relevant for the phone number field,
70     * since it is the one field that is most likely exposed to the user.
71     *
72     * As an example:
73     *   1. User dials "911"
74     *   2. Device recognizes that this is an emergency number
75     *   3. We use the "Emergency Number" string instead of "911" in the
76     *     phoneNumber field.
77     *
78     * What we're really doing here is treating phoneNumber as an essential
79     * field here, NOT name.  We're NOT always guaranteed to have a name
80     * for a connection, but the number should be displayable.
81     */
82    public String name;
83    public String phoneNumber;
84    public String normalizedNumber;
85    public String geoDescription;
86
87    public String cnapName;
88    public int numberPresentation;
89    public int namePresentation;
90    public boolean contactExists;
91
92    public String phoneLabel;
93    /* Split up the phoneLabel into number type and label name */
94    public int    numberType;
95    public String numberLabel;
96
97    public int photoResource;
98
99    // Contact ID, which will be 0 if a contact comes from the corp CP2.
100    public long contactIdOrZero;
101    public boolean needUpdate;
102    public Uri contactRefUri;
103    public String lookupKey;
104
105    /**
106     * Contact display photo URI.  If a contact has no display photo but a thumbnail, it'll be
107     * the thumbnail URI instead.
108     */
109    public Uri contactDisplayPhotoUri;
110
111    // fields to hold individual contact preference data,
112    // including the send to voicemail flag and the ringtone
113    // uri reference.
114    public Uri contactRingtoneUri;
115    public boolean shouldSendToVoicemail;
116
117    /**
118     * Drawable representing the caller image.  This is essentially
119     * a cache for the image data tied into the connection /
120     * callerinfo object.
121     *
122     * This might be a high resolution picture which is more suitable
123     * for full-screen image view than for smaller icons used in some
124     * kinds of notifications.
125     *
126     * The {@link #isCachedPhotoCurrent} flag indicates if the image
127     * data needs to be reloaded.
128     */
129    public Drawable cachedPhoto;
130    /**
131     * Bitmap representing the caller image which has possibly lower
132     * resolution than {@link #cachedPhoto} and thus more suitable for
133     * icons (like notification icons).
134     *
135     * In usual cases this is just down-scaled image of {@link #cachedPhoto}.
136     * If the down-scaling fails, this will just become null.
137     *
138     * The {@link #isCachedPhotoCurrent} flag indicates if the image
139     * data needs to be reloaded.
140     */
141    public Bitmap cachedPhotoIcon;
142    /**
143     * Boolean which indicates if {@link #cachedPhoto} and
144     * {@link #cachedPhotoIcon} is fresh enough. If it is false,
145     * those images aren't pointing to valid objects.
146     */
147    public boolean isCachedPhotoCurrent;
148
149    private boolean mIsEmergency;
150    private boolean mIsVoiceMail;
151
152    public CallerInfo() {
153        // TODO: Move all the basic initialization here?
154        mIsEmergency = false;
155        mIsVoiceMail = false;
156    }
157
158    /**
159     * getCallerInfo given a Cursor.
160     * @param context the context used to retrieve string constants
161     * @param contactRef the URI to attach to this CallerInfo object
162     * @param cursor the first object in the cursor is used to build the CallerInfo object.
163     * @return the CallerInfo which contains the caller id for the given
164     * number. The returned CallerInfo is null if no number is supplied.
165     */
166    public static CallerInfo getCallerInfo(Context context, Uri contactRef, Cursor cursor) {
167        CallerInfo info = new CallerInfo();
168        info.photoResource = 0;
169        info.phoneLabel = null;
170        info.numberType = 0;
171        info.numberLabel = null;
172        info.cachedPhoto = null;
173        info.isCachedPhotoCurrent = false;
174        info.contactExists = false;
175
176        if (VDBG) Rlog.v(TAG, "getCallerInfo() based on cursor...");
177
178        if (cursor != null) {
179            if (cursor.moveToFirst()) {
180                // TODO: photo_id is always available but not taken
181                // care of here. Maybe we should store it in the
182                // CallerInfo object as well.
183
184                int columnIndex;
185
186                // Look for the name
187                columnIndex = cursor.getColumnIndex(PhoneLookup.DISPLAY_NAME);
188                if (columnIndex != -1) {
189                    info.name = cursor.getString(columnIndex);
190                }
191
192                // Look for the number
193                columnIndex = cursor.getColumnIndex(PhoneLookup.NUMBER);
194                if (columnIndex != -1) {
195                    info.phoneNumber = cursor.getString(columnIndex);
196                }
197
198                // Look for the normalized number
199                columnIndex = cursor.getColumnIndex(PhoneLookup.NORMALIZED_NUMBER);
200                if (columnIndex != -1) {
201                    info.normalizedNumber = cursor.getString(columnIndex);
202                }
203
204                // Look for the label/type combo
205                columnIndex = cursor.getColumnIndex(PhoneLookup.LABEL);
206                if (columnIndex != -1) {
207                    int typeColumnIndex = cursor.getColumnIndex(PhoneLookup.TYPE);
208                    if (typeColumnIndex != -1) {
209                        info.numberType = cursor.getInt(typeColumnIndex);
210                        info.numberLabel = cursor.getString(columnIndex);
211                        info.phoneLabel = Phone.getDisplayLabel(context,
212                                info.numberType, info.numberLabel)
213                                .toString();
214                    }
215                }
216
217                // Look for the person_id.
218                columnIndex = getColumnIndexForPersonId(contactRef, cursor);
219                if (columnIndex != -1) {
220                    final long contactId = cursor.getLong(columnIndex);
221                    if (contactId != 0 && !Contacts.isEnterpriseContactId(contactId)) {
222                        info.contactIdOrZero = contactId;
223                        if (VDBG) {
224                            Rlog.v(TAG, "==> got info.contactIdOrZero: " + info.contactIdOrZero);
225                        }
226                    }
227                } else {
228                    // No valid columnIndex, so we can't look up person_id.
229                    Rlog.w(TAG, "Couldn't find contact_id column for " + contactRef);
230                    // Watch out: this means that anything that depends on
231                    // person_id will be broken (like contact photo lookups in
232                    // the in-call UI, for example.)
233                }
234
235                // Contact lookupKey
236                columnIndex = cursor.getColumnIndex(PhoneLookup.LOOKUP_KEY);
237                if (columnIndex != -1) {
238                    info.lookupKey = cursor.getString(columnIndex);
239                }
240
241                // Display photo URI.
242                columnIndex = cursor.getColumnIndex(PhoneLookup.PHOTO_URI);
243                if ((columnIndex != -1) && (cursor.getString(columnIndex) != null)) {
244                    info.contactDisplayPhotoUri = Uri.parse(cursor.getString(columnIndex));
245                } else {
246                    info.contactDisplayPhotoUri = null;
247                }
248
249                // look for the custom ringtone, create from the string stored
250                // in the database.
251                columnIndex = cursor.getColumnIndex(PhoneLookup.CUSTOM_RINGTONE);
252                if ((columnIndex != -1) && (cursor.getString(columnIndex) != null)) {
253                    info.contactRingtoneUri = Uri.parse(cursor.getString(columnIndex));
254                } else {
255                    info.contactRingtoneUri = null;
256                }
257
258                // look for the send to voicemail flag, set it to true only
259                // under certain circumstances.
260                columnIndex = cursor.getColumnIndex(PhoneLookup.SEND_TO_VOICEMAIL);
261                info.shouldSendToVoicemail = (columnIndex != -1) &&
262                        ((cursor.getInt(columnIndex)) == 1);
263                info.contactExists = true;
264            }
265            cursor.close();
266            cursor = null;
267        }
268
269        info.needUpdate = false;
270        info.name = normalize(info.name);
271        info.contactRefUri = contactRef;
272
273        return info;
274    }
275
276    /**
277     * getCallerInfo given a URI, look up in the call-log database
278     * for the uri unique key.
279     * @param context the context used to get the ContentResolver
280     * @param contactRef the URI used to lookup caller id
281     * @return the CallerInfo which contains the caller id for the given
282     * number. The returned CallerInfo is null if no number is supplied.
283     */
284    public static CallerInfo getCallerInfo(Context context, Uri contactRef) {
285
286        return getCallerInfo(context, contactRef,
287                CallerInfoAsyncQuery.getCurrentProfileContentResolver(context)
288                        .query(contactRef, null, null, null, null));
289    }
290
291    /**
292     * getCallerInfo given a phone number, look up in the call-log database
293     * for the matching caller id info.
294     * @param context the context used to get the ContentResolver
295     * @param number the phone number used to lookup caller id
296     * @return the CallerInfo which contains the caller id for the given
297     * number. The returned CallerInfo is null if no number is supplied. If
298     * a matching number is not found, then a generic caller info is returned,
299     * with all relevant fields empty or null.
300     */
301    public static CallerInfo getCallerInfo(Context context, String number) {
302        if (VDBG) Rlog.v(TAG, "getCallerInfo() based on number...");
303
304        int subId = SubscriptionManager.getDefaultSubId();
305        return getCallerInfo(context, number, subId);
306    }
307
308    /**
309     * getCallerInfo given a phone number and subscription, look up in the call-log database
310     * for the matching caller id info.
311     * @param context the context used to get the ContentResolver
312     * @param number the phone number used to lookup caller id
313     * @param subId the subscription for checking for if voice mail number or not
314     * @return the CallerInfo which contains the caller id for the given
315     * number. The returned CallerInfo is null if no number is supplied. If
316     * a matching number is not found, then a generic caller info is returned,
317     * with all relevant fields empty or null.
318     */
319    public static CallerInfo getCallerInfo(Context context, String number, int subId) {
320
321        if (TextUtils.isEmpty(number)) {
322            return null;
323        }
324
325        // Change the callerInfo number ONLY if it is an emergency number
326        // or if it is the voicemail number.  If it is either, take a
327        // shortcut and skip the query.
328        if (PhoneNumberUtils.isLocalEmergencyNumber(context, number)) {
329            return new CallerInfo().markAsEmergency(context);
330        } else if (PhoneNumberUtils.isVoiceMailNumber(subId, number)) {
331            return new CallerInfo().markAsVoiceMail();
332        }
333
334        Uri contactUri = Uri.withAppendedPath(PhoneLookup.ENTERPRISE_CONTENT_FILTER_URI,
335                Uri.encode(number));
336
337        CallerInfo info = getCallerInfo(context, contactUri);
338        info = doSecondaryLookupIfNecessary(context, number, info);
339
340        // if no query results were returned with a viable number,
341        // fill in the original number value we used to query with.
342        if (TextUtils.isEmpty(info.phoneNumber)) {
343            info.phoneNumber = number;
344        }
345
346        return info;
347    }
348
349    /**
350     * Performs another lookup if previous lookup fails and it's a SIP call
351     * and the peer's username is all numeric. Look up the username as it
352     * could be a PSTN number in the contact database.
353     *
354     * @param context the query context
355     * @param number the original phone number, could be a SIP URI
356     * @param previousResult the result of previous lookup
357     * @return previousResult if it's not the case
358     */
359    static CallerInfo doSecondaryLookupIfNecessary(Context context,
360            String number, CallerInfo previousResult) {
361        if (!previousResult.contactExists
362                && PhoneNumberUtils.isUriNumber(number)) {
363            String username = PhoneNumberUtils.getUsernameFromUriNumber(number);
364            if (PhoneNumberUtils.isGlobalPhoneNumber(username)) {
365                previousResult = getCallerInfo(context,
366                        Uri.withAppendedPath(PhoneLookup.ENTERPRISE_CONTENT_FILTER_URI,
367                                Uri.encode(username)));
368            }
369        }
370        return previousResult;
371    }
372
373    // Accessors
374
375    /**
376     * @return true if the caller info is an emergency number.
377     */
378    public boolean isEmergencyNumber() {
379        return mIsEmergency;
380    }
381
382    /**
383     * @return true if the caller info is a voicemail number.
384     */
385    public boolean isVoiceMailNumber() {
386        return mIsVoiceMail;
387    }
388
389    /**
390     * Mark this CallerInfo as an emergency call.
391     * @param context To lookup the localized 'Emergency Number' string.
392     * @return this instance.
393     */
394    // TODO: Note we're setting the phone number here (refer to
395    // javadoc comments at the top of CallerInfo class) to a localized
396    // string 'Emergency Number'. This is pretty bad because we are
397    // making UI work here instead of just packaging the data. We
398    // should set the phone number to the dialed number and name to
399    // 'Emergency Number' and let the UI make the decision about what
400    // should be displayed.
401    /* package */ CallerInfo markAsEmergency(Context context) {
402        phoneNumber = context.getString(
403            com.android.internal.R.string.emergency_call_dialog_number_for_display);
404        photoResource = com.android.internal.R.drawable.picture_emergency;
405        mIsEmergency = true;
406        return this;
407    }
408
409
410    /**
411     * Mark this CallerInfo as a voicemail call. The voicemail label
412     * is obtained from the telephony manager. Caller must hold the
413     * READ_PHONE_STATE permission otherwise the phoneNumber will be
414     * set to null.
415     * @return this instance.
416     */
417    // TODO: As in the emergency number handling, we end up writing a
418    // string in the phone number field.
419    /* package */ CallerInfo markAsVoiceMail() {
420
421        int subId = SubscriptionManager.getDefaultSubId();
422        return markAsVoiceMail(subId);
423
424    }
425
426    /* package */ CallerInfo markAsVoiceMail(int subId) {
427        mIsVoiceMail = true;
428
429        try {
430            String voiceMailLabel = TelephonyManager.getDefault().getVoiceMailAlphaTag(subId);
431
432            phoneNumber = voiceMailLabel;
433        } catch (SecurityException se) {
434            // Should never happen: if this process does not have
435            // permission to retrieve VM tag, it should not have
436            // permission to retrieve VM number and would not call
437            // this method.
438            // Leave phoneNumber untouched.
439            Rlog.e(TAG, "Cannot access VoiceMail.", se);
440        }
441        // TODO: There is no voicemail picture?
442        // FIXME: FIND ANOTHER ICON
443        // photoResource = android.R.drawable.badge_voicemail;
444        return this;
445    }
446
447    private static String normalize(String s) {
448        if (s == null || s.length() > 0) {
449            return s;
450        } else {
451            return null;
452        }
453    }
454
455    /**
456     * Returns the column index to use to find the "person_id" field in
457     * the specified cursor, based on the contact URI that was originally
458     * queried.
459     *
460     * This is a helper function for the getCallerInfo() method that takes
461     * a Cursor.  Looking up the person_id is nontrivial (compared to all
462     * the other CallerInfo fields) since the column we need to use
463     * depends on what query we originally ran.
464     *
465     * Watch out: be sure to not do any database access in this method, since
466     * it's run from the UI thread (see comments below for more info.)
467     *
468     * @return the columnIndex to use (with cursor.getLong()) to get the
469     * person_id, or -1 if we couldn't figure out what colum to use.
470     *
471     * TODO: Add a unittest for this method.  (This is a little tricky to
472     * test, since we'll need a live contacts database to test against,
473     * preloaded with at least some phone numbers and SIP addresses.  And
474     * we'll probably have to hardcode the column indexes we expect, so
475     * the test might break whenever the contacts schema changes.  But we
476     * can at least make sure we handle all the URI patterns we claim to,
477     * and that the mime types match what we expect...)
478     */
479    private static int getColumnIndexForPersonId(Uri contactRef, Cursor cursor) {
480        // TODO: This is pretty ugly now, see bug 2269240 for
481        // more details. The column to use depends upon the type of URL:
482        // - content://com.android.contacts/data/phones ==> use the "contact_id" column
483        // - content://com.android.contacts/phone_lookup ==> use the "_ID" column
484        // - content://com.android.contacts/data ==> use the "contact_id" column
485        // If it's none of the above, we leave columnIndex=-1 which means
486        // that the person_id field will be left unset.
487        //
488        // The logic here *used* to be based on the mime type of contactRef
489        // (for example Phone.CONTENT_ITEM_TYPE would tell us to use the
490        // RawContacts.CONTACT_ID column).  But looking up the mime type requires
491        // a call to context.getContentResolver().getType(contactRef), which
492        // isn't safe to do from the UI thread since it can cause an ANR if
493        // the contacts provider is slow or blocked (like during a sync.)
494        //
495        // So instead, figure out the column to use for person_id by just
496        // looking at the URI itself.
497
498        if (VDBG) Rlog.v(TAG, "- getColumnIndexForPersonId: contactRef URI = '"
499                        + contactRef + "'...");
500        // Warning: Do not enable the following logging (due to ANR risk.)
501        // if (VDBG) Rlog.v(TAG, "- MIME type: "
502        //                 + context.getContentResolver().getType(contactRef));
503
504        String url = contactRef.toString();
505        String columnName = null;
506        if (url.startsWith("content://com.android.contacts/data/phones")) {
507            // Direct lookup in the Phone table.
508            // MIME type: Phone.CONTENT_ITEM_TYPE (= "vnd.android.cursor.item/phone_v2")
509            if (VDBG) Rlog.v(TAG, "'data/phones' URI; using RawContacts.CONTACT_ID");
510            columnName = RawContacts.CONTACT_ID;
511        } else if (url.startsWith("content://com.android.contacts/data")) {
512            // Direct lookup in the Data table.
513            // MIME type: Data.CONTENT_TYPE (= "vnd.android.cursor.dir/data")
514            if (VDBG) Rlog.v(TAG, "'data' URI; using Data.CONTACT_ID");
515            // (Note Data.CONTACT_ID and RawContacts.CONTACT_ID are equivalent.)
516            columnName = Data.CONTACT_ID;
517        } else if (url.startsWith("content://com.android.contacts/phone_lookup")) {
518            // Lookup in the PhoneLookup table, which provides "fuzzy matching"
519            // for phone numbers.
520            // MIME type: PhoneLookup.CONTENT_TYPE (= "vnd.android.cursor.dir/phone_lookup")
521            if (VDBG) Rlog.v(TAG, "'phone_lookup' URI; using PhoneLookup._ID");
522            columnName = PhoneLookup._ID;
523        } else {
524            Rlog.w(TAG, "Unexpected prefix for contactRef '" + url + "'");
525        }
526        int columnIndex = (columnName != null) ? cursor.getColumnIndex(columnName) : -1;
527        if (VDBG) Rlog.v(TAG, "==> Using column '" + columnName
528                        + "' (columnIndex = " + columnIndex + ") for person_id lookup...");
529        return columnIndex;
530    }
531
532    /**
533     * Updates this CallerInfo's geoDescription field, based on the raw
534     * phone number in the phoneNumber field.
535     *
536     * (Note that the various getCallerInfo() methods do *not* set the
537     * geoDescription automatically; you need to call this method
538     * explicitly to get it.)
539     *
540     * @param context the context used to look up the current locale / country
541     * @param fallbackNumber if this CallerInfo's phoneNumber field is empty,
542     *        this specifies a fallback number to use instead.
543     */
544    public void updateGeoDescription(Context context, String fallbackNumber) {
545        String number = TextUtils.isEmpty(phoneNumber) ? fallbackNumber : phoneNumber;
546        geoDescription = getGeoDescription(context, number);
547    }
548
549    /**
550     * @return a geographical description string for the specified number.
551     * @see com.android.i18n.phonenumbers.PhoneNumberOfflineGeocoder
552     */
553    private static String getGeoDescription(Context context, String number) {
554        if (VDBG) Rlog.v(TAG, "getGeoDescription('" + number + "')...");
555
556        if (TextUtils.isEmpty(number)) {
557            return null;
558        }
559
560        PhoneNumberUtil util = PhoneNumberUtil.getInstance();
561        PhoneNumberOfflineGeocoder geocoder = PhoneNumberOfflineGeocoder.getInstance();
562
563        Locale locale = context.getResources().getConfiguration().locale;
564        String countryIso = getCurrentCountryIso(context, locale);
565        PhoneNumber pn = null;
566        try {
567            if (VDBG) Rlog.v(TAG, "parsing '" + number
568                            + "' for countryIso '" + countryIso + "'...");
569            pn = util.parse(number, countryIso);
570            if (VDBG) Rlog.v(TAG, "- parsed number: " + pn);
571        } catch (NumberParseException e) {
572            Rlog.w(TAG, "getGeoDescription: NumberParseException for incoming number '" + number + "'");
573        }
574
575        if (pn != null) {
576            String description = geocoder.getDescriptionForNumber(pn, locale);
577            if (VDBG) Rlog.v(TAG, "- got description: '" + description + "'");
578            return description;
579        } else {
580            return null;
581        }
582    }
583
584    /**
585     * @return The ISO 3166-1 two letters country code of the country the user
586     *         is in.
587     */
588    private static String getCurrentCountryIso(Context context, Locale locale) {
589        String countryIso = null;
590        CountryDetector detector = (CountryDetector) context.getSystemService(
591                Context.COUNTRY_DETECTOR);
592        if (detector != null) {
593            Country country = detector.detectCountry();
594            if (country != null) {
595                countryIso = country.getCountryIso();
596            } else {
597                Rlog.e(TAG, "CountryDetector.detectCountry() returned null.");
598            }
599        }
600        if (countryIso == null) {
601            countryIso = locale.getCountry();
602            Rlog.w(TAG, "No CountryDetector; falling back to countryIso based on locale: "
603                    + countryIso);
604        }
605        return countryIso;
606    }
607
608    protected static String getCurrentCountryIso(Context context) {
609        return getCurrentCountryIso(context, Locale.getDefault());
610    }
611
612    /**
613     * @return a string debug representation of this instance.
614     */
615    public String toString() {
616        // Warning: never check in this file with VERBOSE_DEBUG = true
617        // because that will result in PII in the system log.
618        final boolean VERBOSE_DEBUG = false;
619
620        if (VERBOSE_DEBUG) {
621            return new StringBuilder(384)
622                    .append(super.toString() + " { ")
623                    .append("\nname: " + name)
624                    .append("\nphoneNumber: " + phoneNumber)
625                    .append("\nnormalizedNumber: " + normalizedNumber)
626                    .append("\ngeoDescription: " + geoDescription)
627                    .append("\ncnapName: " + cnapName)
628                    .append("\nnumberPresentation: " + numberPresentation)
629                    .append("\nnamePresentation: " + namePresentation)
630                    .append("\ncontactExits: " + contactExists)
631                    .append("\nphoneLabel: " + phoneLabel)
632                    .append("\nnumberType: " + numberType)
633                    .append("\nnumberLabel: " + numberLabel)
634                    .append("\nphotoResource: " + photoResource)
635                    .append("\ncontactIdOrZero: " + contactIdOrZero)
636                    .append("\nneedUpdate: " + needUpdate)
637                    .append("\ncontactRingtoneUri: " + contactRingtoneUri)
638                    .append("\ncontactDisplayPhotoUri: " + contactDisplayPhotoUri)
639                    .append("\nshouldSendToVoicemail: " + shouldSendToVoicemail)
640                    .append("\ncachedPhoto: " + cachedPhoto)
641                    .append("\nisCachedPhotoCurrent: " + isCachedPhotoCurrent)
642                    .append("\nemergency: " + mIsEmergency)
643                    .append("\nvoicemail " + mIsVoiceMail)
644                    .append("\ncontactExists " + contactExists)
645                    .append(" }")
646                    .toString();
647        } else {
648            return new StringBuilder(128)
649                    .append(super.toString() + " { ")
650                    .append("name " + ((name == null) ? "null" : "non-null"))
651                    .append(", phoneNumber " + ((phoneNumber == null) ? "null" : "non-null"))
652                    .append(" }")
653                    .toString();
654        }
655    }
656}
657