blob: fd9855f24584be227d3f5a98d8bb0fb4a409b388 [file] [log] [blame]
Eric Erfanianccca3152017-02-22 16:32:36 -08001/*
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.incallui;
18
19import android.content.Context;
20import android.database.Cursor;
21import android.graphics.Bitmap;
22import android.graphics.drawable.Drawable;
23import android.net.Uri;
24import android.os.Build.VERSION;
25import android.os.Build.VERSION_CODES;
26import android.provider.ContactsContract;
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.support.annotation.RequiresApi;
33import android.telephony.PhoneNumberUtils;
34import android.text.TextUtils;
35import com.android.contacts.common.ContactsUtils;
36import com.android.contacts.common.ContactsUtils.UserType;
37import com.android.contacts.common.util.TelephonyManagerUtils;
wangqi262b6f22018-03-16 12:27:56 -070038import com.android.dialer.logging.ContactLookupResult;
Eric Erfanianccca3152017-02-22 16:32:36 -080039import com.android.dialer.phonenumbercache.ContactInfoHelper;
40import com.android.dialer.phonenumbercache.PhoneLookupUtil;
41import com.android.dialer.phonenumberutil.PhoneNumberHelper;
42
43/**
44 * Looks up caller information for the given phone number. This is intermediate data and should NOT
45 * be used by any UI.
46 */
47public class CallerInfo {
48
49 private static final String TAG = "CallerInfo";
50
51 // We should always use this projection starting from N onward.
52 @RequiresApi(VERSION_CODES.N)
53 private static final String[] DEFAULT_PHONELOOKUP_PROJECTION =
54 new String[] {
55 PhoneLookup.CONTACT_ID,
56 PhoneLookup.DISPLAY_NAME,
57 PhoneLookup.LOOKUP_KEY,
58 PhoneLookup.NUMBER,
59 PhoneLookup.NORMALIZED_NUMBER,
60 PhoneLookup.LABEL,
61 PhoneLookup.TYPE,
62 PhoneLookup.PHOTO_URI,
63 PhoneLookup.CUSTOM_RINGTONE,
64 PhoneLookup.SEND_TO_VOICEMAIL
65 };
66
67 // In pre-N, contact id is stored in {@link PhoneLookup._ID} in non-sip query.
68 private static final String[] BACKWARD_COMPATIBLE_NON_SIP_DEFAULT_PHONELOOKUP_PROJECTION =
69 new String[] {
70 PhoneLookup._ID,
71 PhoneLookup.DISPLAY_NAME,
72 PhoneLookup.LOOKUP_KEY,
73 PhoneLookup.NUMBER,
74 PhoneLookup.NORMALIZED_NUMBER,
75 PhoneLookup.LABEL,
76 PhoneLookup.TYPE,
77 PhoneLookup.PHOTO_URI,
78 PhoneLookup.CUSTOM_RINGTONE,
79 PhoneLookup.SEND_TO_VOICEMAIL
80 };
81 /**
82 * Please note that, any one of these member variables can be null, and any accesses to them
83 * should be prepared to handle such a case.
84 *
85 * <p>Also, it is implied that phoneNumber is more often populated than name is, (think of calls
86 * being dialed/received using numbers where names are not known to the device), so phoneNumber
87 * should serve as a dependable fallback when name is unavailable.
88 *
89 * <p>One other detail here is that this CallerInfo object reflects information found on a
90 * connection, it is an OUTPUT that serves mainly to display information to the user. In no way is
91 * this object used as input to make a connection, so we can choose to display whatever
92 * human-readable text makes sense to the user for a connection. This is especially relevant for
93 * the phone number field, since it is the one field that is most likely exposed to the user.
94 *
95 * <p>As an example: 1. User dials "911" 2. Device recognizes that this is an emergency number 3.
96 * We use the "Emergency Number" string instead of "911" in the phoneNumber field.
97 *
98 * <p>What we're really doing here is treating phoneNumber as an essential field here, NOT name.
99 * We're NOT always guaranteed to have a name for a connection, but the number should be
100 * displayable.
101 */
102 public String name;
103
104 public String nameAlternative;
105 public String phoneNumber;
106 public String normalizedNumber;
107 public String forwardingNumber;
108 public String geoDescription;
Eric Erfaniand8046e52017-04-06 09:41:50 -0700109 boolean shouldShowGeoDescription;
Eric Erfanianccca3152017-02-22 16:32:36 -0800110 public String cnapName;
111 public int numberPresentation;
112 public int namePresentation;
113 public boolean contactExists;
wangqi262b6f22018-03-16 12:27:56 -0700114 public ContactLookupResult.Type contactLookupResultType = ContactLookupResult.Type.NOT_FOUND;
Eric Erfanianccca3152017-02-22 16:32:36 -0800115 public String phoneLabel;
116 /* Split up the phoneLabel into number type and label name */
117 public int numberType;
118 public String numberLabel;
119 public int photoResource;
120 // Contact ID, which will be 0 if a contact comes from the corp CP2.
121 public long contactIdOrZero;
122 public String lookupKeyOrNull;
123 public boolean needUpdate;
124 public Uri contactRefUri;
125 public @UserType long userType;
126 /**
127 * Contact display photo URI. If a contact has no display photo but a thumbnail, it'll be the
128 * thumbnail URI instead.
129 */
130 public Uri contactDisplayPhotoUri;
131 // fields to hold individual contact preference data,
132 // including the send to voicemail flag and the ringtone
133 // uri reference.
134 public Uri contactRingtoneUri;
135 public boolean shouldSendToVoicemail;
136 /**
137 * Drawable representing the caller image. This is essentially a cache for the image data tied
138 * into the connection / callerinfo object.
139 *
140 * <p>This might be a high resolution picture which is more suitable for full-screen image view
141 * than for smaller icons used in some kinds of notifications.
142 *
143 * <p>The {@link #isCachedPhotoCurrent} flag indicates if the image data needs to be reloaded.
144 */
145 public Drawable cachedPhoto;
146 /**
147 * Bitmap representing the caller image which has possibly lower resolution than {@link
148 * #cachedPhoto} and thus more suitable for icons (like notification icons).
149 *
150 * <p>In usual cases this is just down-scaled image of {@link #cachedPhoto}. If the down-scaling
151 * fails, this will just become null.
152 *
153 * <p>The {@link #isCachedPhotoCurrent} flag indicates if the image data needs to be reloaded.
154 */
155 public Bitmap cachedPhotoIcon;
156 /**
157 * Boolean which indicates if {@link #cachedPhoto} and {@link #cachedPhotoIcon} is fresh enough.
158 * If it is false, those images aren't pointing to valid objects.
159 */
160 public boolean isCachedPhotoCurrent;
161 /**
162 * String which holds the call subject sent as extra from the lower layers for this call. This is
163 * used to display the no-caller ID reason for restricted/unknown number presentation.
164 */
165 public String callSubject;
166
wangqi1420a222017-09-21 09:37:40 -0700167 public String countryIso;
168
linyuh183cb712017-12-27 17:02:37 -0800169 private boolean isEmergency;
170 private boolean isVoiceMail;
Eric Erfanianccca3152017-02-22 16:32:36 -0800171
172 public CallerInfo() {
173 // TODO: Move all the basic initialization here?
linyuh183cb712017-12-27 17:02:37 -0800174 isEmergency = false;
175 isVoiceMail = false;
Eric Erfanianccca3152017-02-22 16:32:36 -0800176 userType = ContactsUtils.USER_TYPE_CURRENT;
177 }
178
179 public static String[] getDefaultPhoneLookupProjection(Uri phoneLookupUri) {
180 if (VERSION.SDK_INT >= VERSION_CODES.N) {
181 return DEFAULT_PHONELOOKUP_PROJECTION;
182 }
183 // Pre-N
184 boolean isSip =
185 phoneLookupUri.getBooleanQueryParameter(
186 ContactsContract.PhoneLookup.QUERY_PARAMETER_SIP_ADDRESS, false);
187 return (isSip)
188 ? DEFAULT_PHONELOOKUP_PROJECTION
189 : BACKWARD_COMPATIBLE_NON_SIP_DEFAULT_PHONELOOKUP_PROJECTION;
190 }
191
192 /**
193 * getCallerInfo given a Cursor.
194 *
195 * @param context the context used to retrieve string constants
196 * @param contactRef the URI to attach to this CallerInfo object
linyuhbdef88b2017-12-12 14:30:08 -0800197 * @param cursor the first object in the cursor is used to build the CallerInfo object.
Eric Erfanianccca3152017-02-22 16:32:36 -0800198 * @return the CallerInfo which contains the caller id for the given number. The returned
199 * CallerInfo is null if no number is supplied.
200 */
201 public static CallerInfo getCallerInfo(Context context, Uri contactRef, Cursor cursor) {
202 CallerInfo info = new CallerInfo();
linyuhbdef88b2017-12-12 14:30:08 -0800203 info.cachedPhoto = null;
linyuhbdef88b2017-12-12 14:30:08 -0800204 info.contactExists = false;
linyuhe7ea93d2017-12-12 22:50:06 -0800205 info.contactRefUri = contactRef;
206 info.isCachedPhotoCurrent = false;
207 info.name = null;
208 info.needUpdate = false;
209 info.numberLabel = null;
210 info.numberType = 0;
211 info.phoneLabel = null;
212 info.photoResource = 0;
Eric Erfanianccca3152017-02-22 16:32:36 -0800213 info.userType = ContactsUtils.USER_TYPE_CURRENT;
214
215 Log.v(TAG, "getCallerInfo() based on cursor...");
216
linyuhe7ea93d2017-12-12 22:50:06 -0800217 if (cursor == null || !cursor.moveToFirst()) {
218 return info;
linyuh6f78d932017-10-17 13:31:27 -0700219 }
220
linyuhe7ea93d2017-12-12 22:50:06 -0800221 // TODO: photo_id is always available but not taken
222 // care of here. Maybe we should store it in the
223 // CallerInfo object as well.
224
225 long contactId = 0L;
226 int columnIndex;
227
linyuh2d5167b2017-12-14 12:34:31 -0800228 // Look for the number
229 columnIndex = cursor.getColumnIndex(PhoneLookup.NUMBER);
230 if (columnIndex != -1) {
231 // The Contacts provider ignores special characters in phone numbers when searching for a
232 // contact. For example, number "123" is considered a match with a contact with number "#123".
233 // We need to check whether the result contains a number that truly matches the query and move
234 // the cursor to that position before filling in the fields in CallerInfo.
235 boolean hasNumberMatch =
236 PhoneNumberHelper.updateCursorToMatchContactLookupUri(cursor, columnIndex, contactRef);
237 if (hasNumberMatch) {
238 info.phoneNumber = cursor.getString(columnIndex);
239 } else {
240 return info;
241 }
242 }
243
linyuhe7ea93d2017-12-12 22:50:06 -0800244 // Look for the name
245 columnIndex = cursor.getColumnIndex(PhoneLookup.DISPLAY_NAME);
246 if (columnIndex != -1) {
247 info.name = normalize(cursor.getString(columnIndex));
248 }
249
linyuhe7ea93d2017-12-12 22:50:06 -0800250 // Look for the normalized number
251 columnIndex = cursor.getColumnIndex(PhoneLookup.NORMALIZED_NUMBER);
252 if (columnIndex != -1) {
253 info.normalizedNumber = cursor.getString(columnIndex);
254 }
255
256 // Look for the label/type combo
257 columnIndex = cursor.getColumnIndex(PhoneLookup.LABEL);
258 if (columnIndex != -1) {
259 int typeColumnIndex = cursor.getColumnIndex(PhoneLookup.TYPE);
260 if (typeColumnIndex != -1) {
261 info.numberType = cursor.getInt(typeColumnIndex);
262 info.numberLabel = cursor.getString(columnIndex);
263 info.phoneLabel =
264 Phone.getTypeLabel(context.getResources(), info.numberType, info.numberLabel)
265 .toString();
266 }
267 }
268
269 // cache the lookup key for later use to create lookup URIs
270 columnIndex = cursor.getColumnIndex(PhoneLookup.LOOKUP_KEY);
271 if (columnIndex != -1) {
272 info.lookupKeyOrNull = cursor.getString(columnIndex);
273 }
274
275 // Look for the person_id.
276 columnIndex = getColumnIndexForPersonId(contactRef, cursor);
277 if (columnIndex != -1) {
278 contactId = cursor.getLong(columnIndex);
279 // QuickContacts in M doesn't support enterprise contact id
280 if (contactId != 0
281 && (VERSION.SDK_INT >= VERSION_CODES.N || !Contacts.isEnterpriseContactId(contactId))) {
282 info.contactIdOrZero = contactId;
283 Log.v(TAG, "==> got info.contactIdOrZero: " + info.contactIdOrZero);
284 }
285 } else {
286 // No valid columnIndex, so we can't look up person_id.
287 Log.v(TAG, "Couldn't find contactId column for " + contactRef);
288 // Watch out: this means that anything that depends on
289 // person_id will be broken (like contact photo lookups in
290 // the in-call UI, for example.)
291 }
292
293 // Display photo URI.
294 columnIndex = cursor.getColumnIndex(PhoneLookup.PHOTO_URI);
295 if ((columnIndex != -1) && (cursor.getString(columnIndex) != null)) {
296 info.contactDisplayPhotoUri = Uri.parse(cursor.getString(columnIndex));
297 } else {
298 info.contactDisplayPhotoUri = null;
299 }
300
301 // look for the custom ringtone, create from the string stored
302 // in the database.
303 columnIndex = cursor.getColumnIndex(PhoneLookup.CUSTOM_RINGTONE);
304 if ((columnIndex != -1) && (cursor.getString(columnIndex) != null)) {
305 if (TextUtils.isEmpty(cursor.getString(columnIndex))) {
306 // make it consistent with frameworks/base/.../CallerInfo.java
307 info.contactRingtoneUri = Uri.EMPTY;
308 } else {
309 info.contactRingtoneUri = Uri.parse(cursor.getString(columnIndex));
310 }
311 } else {
312 info.contactRingtoneUri = null;
313 }
314
315 // look for the send to voicemail flag, set it to true only
316 // under certain circumstances.
317 columnIndex = cursor.getColumnIndex(PhoneLookup.SEND_TO_VOICEMAIL);
318 info.shouldSendToVoicemail = (columnIndex != -1) && ((cursor.getInt(columnIndex)) == 1);
319 info.contactExists = true;
wangqi262b6f22018-03-16 12:27:56 -0700320 info.contactLookupResultType = ContactLookupResult.Type.LOCAL_CONTACT;
linyuhe7ea93d2017-12-12 22:50:06 -0800321
322 // Determine userType by directoryId and contactId
323 final String directory =
324 contactRef == null
325 ? null
326 : contactRef.getQueryParameter(ContactsContract.DIRECTORY_PARAM_KEY);
327 Long directoryId = null;
328 if (directory != null) {
329 try {
330 directoryId = Long.parseLong(directory);
331 } catch (NumberFormatException e) {
332 // do nothing
333 }
334 }
335 info.userType = ContactsUtils.determineUserType(directoryId, contactId);
336
337 info.nameAlternative =
338 ContactInfoHelper.lookUpDisplayNameAlternative(
339 context, info.lookupKeyOrNull, info.userType, directoryId);
340 cursor.close();
Eric Erfanianccca3152017-02-22 16:32:36 -0800341
342 return info;
343 }
344
345 /**
346 * getCallerInfo given a URI, look up in the call-log database for the uri unique key.
347 *
348 * @param context the context used to get the ContentResolver
349 * @param contactRef the URI used to lookup caller id
350 * @return the CallerInfo which contains the caller id for the given number. The returned
351 * CallerInfo is null if no number is supplied.
352 */
353 private static CallerInfo getCallerInfo(Context context, Uri contactRef) {
354
355 return getCallerInfo(
356 context,
357 contactRef,
358 context.getContentResolver().query(contactRef, null, null, null, null));
359 }
360
361 /**
362 * Performs another lookup if previous lookup fails and it's a SIP call and the peer's username is
363 * all numeric. Look up the username as it could be a PSTN number in the contact database.
364 *
365 * @param context the query context
366 * @param number the original phone number, could be a SIP URI
367 * @param previousResult the result of previous lookup
368 * @return previousResult if it's not the case
369 */
370 static CallerInfo doSecondaryLookupIfNecessary(
371 Context context, String number, CallerInfo previousResult) {
372 if (!previousResult.contactExists && PhoneNumberHelper.isUriNumber(number)) {
373 String username = PhoneNumberHelper.getUsernameFromUriNumber(number);
374 if (PhoneNumberUtils.isGlobalPhoneNumber(username)) {
375 previousResult =
376 getCallerInfo(
377 context,
378 Uri.withAppendedPath(
379 PhoneLookup.ENTERPRISE_CONTENT_FILTER_URI, Uri.encode(username)));
380 }
381 }
382 return previousResult;
383 }
384
385 // Accessors
386
387 private static String normalize(String s) {
388 if (s == null || s.length() > 0) {
389 return s;
390 } else {
391 return null;
392 }
393 }
394
395 /**
396 * Returns the column index to use to find the "person_id" field in the specified cursor, based on
397 * the contact URI that was originally queried.
398 *
399 * <p>This is a helper function for the getCallerInfo() method that takes a Cursor. Looking up the
400 * person_id is nontrivial (compared to all the other CallerInfo fields) since the column we need
401 * to use depends on what query we originally ran.
402 *
403 * <p>Watch out: be sure to not do any database access in this method, since it's run from the UI
404 * thread (see comments below for more info.)
405 *
406 * @return the columnIndex to use (with cursor.getLong()) to get the person_id, or -1 if we
407 * couldn't figure out what colum to use.
408 * <p>TODO: Add a unittest for this method. (This is a little tricky to test, since we'll need
409 * a live contacts database to test against, preloaded with at least some phone numbers and
410 * SIP addresses. And we'll probably have to hardcode the column indexes we expect, so the
411 * test might break whenever the contacts schema changes. But we can at least make sure we
412 * handle all the URI patterns we claim to, and that the mime types match what we expect...)
413 */
414 private static int getColumnIndexForPersonId(Uri contactRef, Cursor cursor) {
415 // TODO: This is pretty ugly now, see bug 2269240 for
416 // more details. The column to use depends upon the type of URL:
417 // - content://com.android.contacts/data/phones ==> use the "contact_id" column
418 // - content://com.android.contacts/phone_lookup ==> use the "_ID" column
419 // - content://com.android.contacts/data ==> use the "contact_id" column
420 // If it's none of the above, we leave columnIndex=-1 which means
421 // that the person_id field will be left unset.
422 //
423 // The logic here *used* to be based on the mime type of contactRef
424 // (for example Phone.CONTENT_ITEM_TYPE would tell us to use the
425 // RawContacts.CONTACT_ID column). But looking up the mime type requires
426 // a call to context.getContentResolver().getType(contactRef), which
427 // isn't safe to do from the UI thread since it can cause an ANR if
428 // the contacts provider is slow or blocked (like during a sync.)
429 //
430 // So instead, figure out the column to use for person_id by just
431 // looking at the URI itself.
432
433 Log.v(TAG, "- getColumnIndexForPersonId: contactRef URI = '" + contactRef + "'...");
434 // Warning: Do not enable the following logging (due to ANR risk.)
435 // if (VDBG) Rlog.v(TAG, "- MIME type: "
436 // + context.getContentResolver().getType(contactRef));
437
438 String url = contactRef.toString();
439 String columnName = null;
440 if (url.startsWith("content://com.android.contacts/data/phones")) {
441 // Direct lookup in the Phone table.
442 // MIME type: Phone.CONTENT_ITEM_TYPE (= "vnd.android.cursor.item/phone_v2")
443 Log.v(TAG, "'data/phones' URI; using RawContacts.CONTACT_ID");
444 columnName = RawContacts.CONTACT_ID;
445 } else if (url.startsWith("content://com.android.contacts/data")) {
446 // Direct lookup in the Data table.
447 // MIME type: Data.CONTENT_TYPE (= "vnd.android.cursor.dir/data")
448 Log.v(TAG, "'data' URI; using Data.CONTACT_ID");
449 // (Note Data.CONTACT_ID and RawContacts.CONTACT_ID are equivalent.)
450 columnName = Data.CONTACT_ID;
451 } else if (url.startsWith("content://com.android.contacts/phone_lookup")) {
452 // Lookup in the PhoneLookup table, which provides "fuzzy matching"
453 // for phone numbers.
454 // MIME type: PhoneLookup.CONTENT_TYPE (= "vnd.android.cursor.dir/phone_lookup")
455 Log.v(TAG, "'phone_lookup' URI; using PhoneLookup._ID");
456 columnName = PhoneLookupUtil.getContactIdColumnNameForUri(contactRef);
457 } else {
458 Log.v(TAG, "Unexpected prefix for contactRef '" + url + "'");
459 }
460 int columnIndex = (columnName != null) ? cursor.getColumnIndex(columnName) : -1;
461 Log.v(
462 TAG,
463 "==> Using column '"
464 + columnName
465 + "' (columnIndex = "
466 + columnIndex
467 + ") for person_id lookup...");
468 return columnIndex;
469 }
470
471 /** @return true if the caller info is an emergency number. */
472 public boolean isEmergencyNumber() {
linyuh183cb712017-12-27 17:02:37 -0800473 return isEmergency;
Eric Erfanianccca3152017-02-22 16:32:36 -0800474 }
475
476 /** @return true if the caller info is a voicemail number. */
477 public boolean isVoiceMailNumber() {
linyuh183cb712017-12-27 17:02:37 -0800478 return isVoiceMail;
Eric Erfanianccca3152017-02-22 16:32:36 -0800479 }
480
481 /**
482 * Mark this CallerInfo as an emergency call.
483 *
484 * @param context To lookup the localized 'Emergency Number' string.
485 * @return this instance.
486 */
487 /* package */ CallerInfo markAsEmergency(Context context) {
488 name = context.getString(R.string.emergency_call_dialog_number_for_display);
489 phoneNumber = null;
490
linyuh183cb712017-12-27 17:02:37 -0800491 isEmergency = true;
Eric Erfanianccca3152017-02-22 16:32:36 -0800492 return this;
493 }
494
495 /**
496 * Mark this CallerInfo as a voicemail call. The voicemail label is obtained from the telephony
497 * manager. Caller must hold the READ_PHONE_STATE permission otherwise the phoneNumber will be set
498 * to null.
499 *
500 * @return this instance.
501 */
502 /* package */ CallerInfo markAsVoiceMail(Context context) {
linyuh183cb712017-12-27 17:02:37 -0800503 isVoiceMail = true;
Eric Erfanianccca3152017-02-22 16:32:36 -0800504
505 try {
506 // For voicemail calls, we display the voice mail tag
507 // instead of the real phone number in the "number"
508 // field.
509 name = TelephonyManagerUtils.getVoiceMailAlphaTag(context);
510 phoneNumber = null;
511 } catch (SecurityException se) {
512 // Should never happen: if this process does not have
513 // permission to retrieve VM tag, it should not have
514 // permission to retrieve VM number and would not call
515 // this method.
516 // Leave phoneNumber untouched.
517 Log.e(TAG, "Cannot access VoiceMail.", se);
518 }
519 // TODO: There is no voicemail picture?
Eric Erfanianccca3152017-02-22 16:32:36 -0800520 // photoResource = android.R.drawable.badge_voicemail;
521 return this;
522 }
523
524 /**
525 * Updates this CallerInfo's geoDescription field, based on the raw phone number in the
526 * phoneNumber field.
527 *
528 * <p>(Note that the various getCallerInfo() methods do *not* set the geoDescription
529 * automatically; you need to call this method explicitly to get it.)
530 *
531 * @param context the context used to look up the current locale / country
532 * @param fallbackNumber if this CallerInfo's phoneNumber field is empty, this specifies a
533 * fallback number to use instead.
534 */
535 public void updateGeoDescription(Context context, String fallbackNumber) {
536 String number = TextUtils.isEmpty(phoneNumber) ? fallbackNumber : phoneNumber;
wangqi1420a222017-09-21 09:37:40 -0700537 geoDescription = PhoneNumberHelper.getGeoDescription(context, number, countryIso);
Eric Erfanianccca3152017-02-22 16:32:36 -0800538 }
539
540 /** @return a string debug representation of this instance. */
541 @Override
542 public String toString() {
543 // Warning: never check in this file with VERBOSE_DEBUG = true
544 // because that will result in PII in the system log.
545 final boolean VERBOSE_DEBUG = false;
546
547 if (VERBOSE_DEBUG) {
548 return new StringBuilder(384)
549 .append(super.toString() + " { ")
550 .append("\nname: " + name)
551 .append("\nphoneNumber: " + phoneNumber)
552 .append("\nnormalizedNumber: " + normalizedNumber)
553 .append("\forwardingNumber: " + forwardingNumber)
554 .append("\ngeoDescription: " + geoDescription)
555 .append("\ncnapName: " + cnapName)
556 .append("\nnumberPresentation: " + numberPresentation)
557 .append("\nnamePresentation: " + namePresentation)
558 .append("\ncontactExists: " + contactExists)
559 .append("\nphoneLabel: " + phoneLabel)
560 .append("\nnumberType: " + numberType)
561 .append("\nnumberLabel: " + numberLabel)
562 .append("\nphotoResource: " + photoResource)
563 .append("\ncontactIdOrZero: " + contactIdOrZero)
564 .append("\nneedUpdate: " + needUpdate)
565 .append("\ncontactRefUri: " + contactRefUri)
566 .append("\ncontactRingtoneUri: " + contactRingtoneUri)
567 .append("\ncontactDisplayPhotoUri: " + contactDisplayPhotoUri)
568 .append("\nshouldSendToVoicemail: " + shouldSendToVoicemail)
569 .append("\ncachedPhoto: " + cachedPhoto)
570 .append("\nisCachedPhotoCurrent: " + isCachedPhotoCurrent)
linyuh183cb712017-12-27 17:02:37 -0800571 .append("\nemergency: " + isEmergency)
572 .append("\nvoicemail: " + isVoiceMail)
Eric Erfanianccca3152017-02-22 16:32:36 -0800573 .append("\nuserType: " + userType)
574 .append(" }")
575 .toString();
576 } else {
577 return new StringBuilder(128)
578 .append(super.toString() + " { ")
579 .append("name " + ((name == null) ? "null" : "non-null"))
580 .append(", phoneNumber " + ((phoneNumber == null) ? "null" : "non-null"))
581 .append(" }")
582 .toString();
583 }
584 }
585}