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