From e80d62229bb11a92f0db8d4e4bac6533bbed9b66 Mon Sep 17 00:00:00 2001 From: Nancy Chen Date: Wed, 8 Oct 2014 20:17:55 -0700 Subject: Enable use of phone accounts for voicemail info display. Call the "isVoicemailNumber(subId, number)" method instead of the one with just the number. This is because we need to check whether a number is the voicemail number for a specific phone account, otherwise the UI would never correctly display "voicemail" for the non-default SIM. Bug:17925501 Change-Id: If1d6cb1acfcb570aca5e639858af8804bac202c0 --- src/com/android/dialer/CallDetailActivity.java | 54 ++++++++++++---------- src/com/android/dialer/PhoneCallDetails.java | 29 ++++++------ src/com/android/dialer/PhoneCallDetailsHelper.java | 29 +++++++----- src/com/android/dialer/calllog/CallLogAdapter.java | 30 ++++++------ .../dialer/calllog/CallLogListItemHelper.java | 2 +- .../dialer/calllog/DefaultVoicemailNotifier.java | 24 ++++++++-- .../android/dialer/calllog/PhoneAccountUtils.java | 12 ++--- .../dialer/calllog/PhoneNumberDisplayHelper.java | 26 +++++++---- .../dialer/calllog/PhoneNumberUtilsWrapper.java | 31 +++++++------ 9 files changed, 134 insertions(+), 103 deletions(-) (limited to 'src/com/android') diff --git a/src/com/android/dialer/CallDetailActivity.java b/src/com/android/dialer/CallDetailActivity.java index e2ab13025..f6b88cd72 100644 --- a/src/com/android/dialer/CallDetailActivity.java +++ b/src/com/android/dialer/CallDetailActivity.java @@ -31,6 +31,7 @@ import android.provider.CallLog.Calls; import android.provider.ContactsContract.CommonDataKinds.Phone; import android.provider.VoicemailContract.Voicemails; import android.telecom.PhoneAccount; +import android.telecom.PhoneAccountHandle; import android.telephony.TelephonyManager; import android.text.BidiFormatter; import android.text.TextDirectionHeuristics; @@ -78,9 +79,6 @@ import java.util.List; public class CallDetailActivity extends AnalyticsActivity implements ProximitySensorAware { private static final String TAG = "CallDetail"; - private static final int LOADER_ID = 0; - private static final String BUNDLE_CONTACT_URI_EXTRA = "contact_uri_extra"; - private static final char LEFT_TO_RIGHT_EMBEDDING = '\u202A'; private static final char POP_DIRECTIONAL_FORMATTING = '\u202C'; @@ -238,7 +236,7 @@ public class CallDetailActivity extends AnalyticsActivity implements ProximitySe mResources = getResources(); mCallTypeHelper = new CallTypeHelper(getResources()); - mPhoneNumberHelper = new PhoneNumberDisplayHelper(mResources); + mPhoneNumberHelper = new PhoneNumberDisplayHelper(this, mResources); mVoicemailStatusHelper = new VoicemailStatusHelperImpl(); mAsyncQueryHandler = new CallDetailActivityQueryHandler(this); @@ -379,7 +377,7 @@ public class CallDetailActivity extends AnalyticsActivity implements ProximitySe /** * Update user interface with details of given call. * - * @param callUris URIs into {@link CallLog.Calls} of the calls to be displayed + * @param callUris URIs into {@link android.provider.CallLog.Calls} of the calls to be displayed */ private void updateData(final Uri... callUris) { class UpdateContactDetailsTask extends AsyncTask { @@ -403,9 +401,11 @@ public class CallDetailActivity extends AnalyticsActivity implements ProximitySe @Override public void onPostExecute(PhoneCallDetails[] details) { + Context context = CallDetailActivity.this; + if (details == null) { // Somewhere went wrong: we're going to bail out and show error to users. - Toast.makeText(CallDetailActivity.this, R.string.toast_call_detail_error, + Toast.makeText(context, R.string.toast_call_detail_error, Toast.LENGTH_SHORT).show(); finish(); return; @@ -418,24 +418,27 @@ public class CallDetailActivity extends AnalyticsActivity implements ProximitySe final int numberPresentation = firstDetails.numberPresentation; final Uri contactUri = firstDetails.contactUri; final Uri photoUri = firstDetails.photoUri; + final PhoneAccountHandle accountHandle = firstDetails.accountHandle; // Cache the details about the phone number. final boolean canPlaceCallsTo = PhoneNumberUtilsWrapper.canPlaceCallsTo(mNumber, numberPresentation); - final PhoneNumberUtilsWrapper phoneUtils = new PhoneNumberUtilsWrapper(); - final boolean isVoicemailNumber = phoneUtils.isVoicemailNumber(mNumber); - final boolean isSipNumber = phoneUtils.isSipNumber(mNumber); + final PhoneNumberUtilsWrapper phoneUtils = new PhoneNumberUtilsWrapper(context); + final boolean isVoicemailNumber = + phoneUtils.isVoicemailNumber(accountHandle, mNumber); + final boolean isSipNumber = PhoneNumberUtilsWrapper.isSipNumber(mNumber); final CharSequence callLocationOrType = getNumberTypeOrLocation(firstDetails); - final CharSequence displayNumber = mPhoneNumberHelper.getDisplayNumber( - firstDetails.number, - firstDetails.numberPresentation, - firstDetails.formattedNumber); + final CharSequence displayNumber = + mPhoneNumberHelper.getDisplayNumber( + firstDetails.accountHandle, + firstDetails.number, + firstDetails.numberPresentation, + firstDetails.formattedNumber); final String displayNumberStr = mBidiFormatter.unicodeWrap( displayNumber.toString(), TextDirectionHeuristics.LTR); - if (!TextUtils.isEmpty(firstDetails.name)) { mCallerName.setText(firstDetails.name); mCallerNumber.setText(callLocationOrType + " " + displayNumberStr); @@ -449,8 +452,9 @@ public class CallDetailActivity extends AnalyticsActivity implements ProximitySe } } - if (!TextUtils.isEmpty(firstDetails.accountLabel)) { - mAccountLabel.setText(firstDetails.accountLabel); + String accountLabel = PhoneAccountUtils.getAccountLabel(context, accountHandle); + if (!TextUtils.isEmpty(accountLabel)) { + mAccountLabel.setText(accountLabel); mAccountLabel.setVisibility(View.VISIBLE); } else { mAccountLabel.setVisibility(View.GONE); @@ -464,8 +468,7 @@ public class CallDetailActivity extends AnalyticsActivity implements ProximitySe ListView historyList = (ListView) findViewById(R.id.history); historyList.setAdapter( - new CallDetailHistoryAdapter(CallDetailActivity.this, mInflater, - mCallTypeHelper, details)); + new CallDetailHistoryAdapter(context, mInflater, mCallTypeHelper, details)); String lookupKey = contactUri == null ? null : ContactInfoHelper.getLookupKeyFromUri(contactUri); @@ -479,7 +482,9 @@ public class CallDetailActivity extends AnalyticsActivity implements ProximitySe String nameForDefaultImage; if (TextUtils.isEmpty(firstDetails.name)) { - nameForDefaultImage = mPhoneNumberHelper.getDisplayNumber(firstDetails.number, + nameForDefaultImage = mPhoneNumberHelper.getDisplayNumber( + firstDetails.accountHandle, + firstDetails.number, firstDetails.numberPresentation, firstDetails.formattedNumber).toString(); } else { @@ -535,10 +540,9 @@ public class CallDetailActivity extends AnalyticsActivity implements ProximitySe final String geocode = callCursor.getString(GEOCODED_LOCATION_COLUMN_INDEX); final String transcription = callCursor.getString(TRANSCRIPTION_COLUMN_INDEX); - final String accountLabel = PhoneAccountUtils.getAccountLabel(this, - PhoneAccountUtils.getAccount( + final PhoneAccountHandle accountHandle = PhoneAccountUtils.getAccount( callCursor.getString(ACCOUNT_COMPONENT_NAME), - callCursor.getString(ACCOUNT_ID))); + callCursor.getString(ACCOUNT_ID)); if (TextUtils.isEmpty(countryIso)) { countryIso = mDefaultCountryIso; @@ -556,11 +560,11 @@ public class CallDetailActivity extends AnalyticsActivity implements ProximitySe // If this is not a regular number, there is no point in looking it up in the contacts. ContactInfo info = PhoneNumberUtilsWrapper.canPlaceCallsTo(number, numberPresentation) - && !new PhoneNumberUtilsWrapper().isVoicemailNumber(number) + && !new PhoneNumberUtilsWrapper(this).isVoicemailNumber(accountHandle, number) ? mContactInfoHelper.lookupNumber(number, countryIso) : null; if (info == null) { - formattedNumber = mPhoneNumberHelper.getDisplayNumber(number, + formattedNumber = mPhoneNumberHelper.getDisplayNumber(accountHandle, number, numberPresentation, null); nameText = ""; numberType = 0; @@ -586,7 +590,7 @@ public class CallDetailActivity extends AnalyticsActivity implements ProximitySe formattedNumber, countryIso, geocode, new int[]{ callType }, date, duration, nameText, numberType, numberLabel, lookupUri, photoUri, sourceType, - accountLabel, null, features, dataUsage, transcription); + accountHandle, features, dataUsage, transcription); } finally { if (callCursor != null) { callCursor.close(); diff --git a/src/com/android/dialer/PhoneCallDetails.java b/src/com/android/dialer/PhoneCallDetails.java index ba049a2d7..ec9657ed8 100644 --- a/src/com/android/dialer/PhoneCallDetails.java +++ b/src/com/android/dialer/PhoneCallDetails.java @@ -22,6 +22,7 @@ import android.graphics.drawable.Drawable; import android.net.Uri; import android.provider.CallLog.Calls; import android.provider.ContactsContract.CommonDataKinds.Phone; +import android.telecom.PhoneAccountHandle; /** * The details of a phone call to be shown in the UI. @@ -66,14 +67,11 @@ public class PhoneCallDetails { * The source type of the contact associated with this call. */ public final int sourceType; + /** * The unique identifier for the account associated with the call. */ - public final String accountLabel; - /** - * The icon for the account associated with the call. - */ - public final Drawable accountIcon; + public final PhoneAccountHandle accountHandle; /** * Features applicable to this call. */ @@ -96,26 +94,26 @@ public class PhoneCallDetails { CharSequence formattedNumber, String countryIso, String geocode, int[] callTypes, long date, long duration) { this (number, numberPresentation, formattedNumber, countryIso, geocode, - callTypes, date, duration, "", 0, "", null, null, 0, null, null, 0, null, null); + callTypes, date, duration, "", 0, "", null, null, 0, null, 0, null, null); } /** Create the details for a call with a number not associated with a contact. */ public PhoneCallDetails(CharSequence number, int numberPresentation, CharSequence formattedNumber, String countryIso, String geocode, - int[] callTypes, long date, long duration, String accountLabel, Drawable accountIcon, - int features, Long dataUsage, String transcription) { - this(number, numberPresentation, formattedNumber, countryIso, geocode, - callTypes, date, duration, "", 0, "", null, null, 0, accountLabel, accountIcon, - features, dataUsage, transcription); + int[] callTypes, long date, long duration, + PhoneAccountHandle accountHandle, int features, Long dataUsage, String transcription) { + this(number, numberPresentation, formattedNumber, countryIso, geocode, callTypes, date, + duration, "", 0, "", null, null, 0, accountHandle, features, dataUsage, + transcription); } /** Create the details for a call with a number associated with a contact. */ public PhoneCallDetails(CharSequence number, int numberPresentation, CharSequence formattedNumber, String countryIso, String geocode, int[] callTypes, long date, long duration, CharSequence name, - int numberType, CharSequence numberLabel, Uri contactUri, - Uri photoUri, int sourceType, String accountLabel, Drawable accountIcon, int features, - Long dataUsage, String transcription) { + int numberType, CharSequence numberLabel, Uri contactUri, Uri photoUri, + int sourceType, PhoneAccountHandle accountHandle, int features, Long dataUsage, + String transcription) { this.number = number; this.numberPresentation = numberPresentation; this.formattedNumber = formattedNumber; @@ -130,8 +128,7 @@ public class PhoneCallDetails { this.contactUri = contactUri; this.photoUri = photoUri; this.sourceType = sourceType; - this.accountLabel = accountLabel; - this.accountIcon = accountIcon; + this.accountHandle = accountHandle; this.features = features; this.dataUsage = dataUsage; this.transcription = transcription; diff --git a/src/com/android/dialer/PhoneCallDetailsHelper.java b/src/com/android/dialer/PhoneCallDetailsHelper.java index c5f2fb675..e8884319c 100644 --- a/src/com/android/dialer/PhoneCallDetailsHelper.java +++ b/src/com/android/dialer/PhoneCallDetailsHelper.java @@ -16,7 +16,9 @@ package com.android.dialer; +import android.content.Context; import android.content.res.Resources; +import android.graphics.drawable.Drawable; import android.provider.CallLog; import android.provider.CallLog.Calls; import android.provider.ContactsContract.CommonDataKinds.Phone; @@ -28,8 +30,8 @@ import android.widget.TextView; import com.android.contacts.common.CallUtil; import com.android.contacts.common.testing.NeededForTesting; import com.android.contacts.common.util.PhoneNumberHelper; -import com.android.dialer.calllog.CallTypeHelper; import com.android.dialer.calllog.ContactInfo; +import com.android.dialer.calllog.PhoneAccountUtils; import com.android.dialer.calllog.PhoneNumberDisplayHelper; import com.android.dialer.calllog.PhoneNumberUtilsWrapper; import com.android.dialer.util.DialerUtils; @@ -44,6 +46,7 @@ public class PhoneCallDetailsHelper { /** The maximum number of icons will be shown to represent the call types in a group. */ private static final int MAX_CALL_TYPE_ICONS = 3; + private final Context mContext; private final Resources mResources; /** The injected current time in milliseconds since the epoch. Used only by tests. */ private Long mCurrentTimeMillisForTest; @@ -63,11 +66,12 @@ public class PhoneCallDetailsHelper { * * @param resources used to look up strings */ - public PhoneCallDetailsHelper(Resources resources, CallTypeHelper callTypeHelper, + public PhoneCallDetailsHelper(Context context, Resources resources, PhoneNumberUtilsWrapper phoneUtils) { + mContext = context; mResources = resources; mPhoneNumberUtilsWrapper = phoneUtils; - mPhoneNumberHelper = new PhoneNumberDisplayHelper(mPhoneNumberUtilsWrapper, resources); + mPhoneNumberHelper = new PhoneNumberDisplayHelper(context, resources, phoneUtils); } /** Fills the call details views with content. */ @@ -103,16 +107,17 @@ public class PhoneCallDetailsHelper { setCallCountAndDate(views, callCount, callLocationAndDate); // set the account icon if it exists - if (details.accountIcon != null) { + Drawable accountIcon = PhoneAccountUtils.getAccountIcon(mContext, details.accountHandle); + if (accountIcon != null) { views.callAccountIcon.setVisibility(View.VISIBLE); - views.callAccountIcon.setImageDrawable(details.accountIcon); + views.callAccountIcon.setImageDrawable(accountIcon); } else { views.callAccountIcon.setVisibility(View.GONE); } final CharSequence nameText; final CharSequence displayNumber = - mPhoneNumberHelper.getDisplayNumber(details.number, + mPhoneNumberHelper.getDisplayNumber(details.accountHandle, details.number, details.numberPresentation, details.formattedNumber); if (TextUtils.isEmpty(details.name)) { nameText = displayNumber; @@ -169,7 +174,8 @@ public class PhoneCallDetailsHelper { // Only show a label if the number is shown and it is not a SIP address. if (!TextUtils.isEmpty(details.number) && !PhoneNumberHelper.isUriNumber(details.number.toString()) - && !mPhoneNumberUtilsWrapper.isVoicemailNumber(details.number)) { + && !mPhoneNumberUtilsWrapper.isVoicemailNumber(details.accountHandle, + details.number)) { if (details.numberLabel == ContactInfo.GEOCODE_AS_LABEL) { numberFormattedLabel = details.geocode; @@ -180,8 +186,8 @@ public class PhoneCallDetailsHelper { } if (!TextUtils.isEmpty(details.name) && TextUtils.isEmpty(numberFormattedLabel)) { - numberFormattedLabel = mPhoneNumberHelper.getDisplayNumber(details.number, - details.numberPresentation, details.formattedNumber); + numberFormattedLabel = mPhoneNumberHelper.getDisplayNumber(details.accountHandle, + details.number, details.numberPresentation, details.formattedNumber); } return numberFormattedLabel; } @@ -204,8 +210,9 @@ public class PhoneCallDetailsHelper { public void setCallDetailsHeader(TextView nameView, PhoneCallDetails details) { final CharSequence nameText; final CharSequence displayNumber = - mPhoneNumberHelper.getDisplayNumber(details.number, details.numberPresentation, - mResources.getString(R.string.recentCalls_addToContact)); + mPhoneNumberHelper.getDisplayNumber(details.accountHandle, details.number, + details.numberPresentation, + mResources.getString(R.string.recentCalls_addToContact)); if (TextUtils.isEmpty(details.name)) { nameText = displayNumber; } else { diff --git a/src/com/android/dialer/calllog/CallLogAdapter.java b/src/com/android/dialer/calllog/CallLogAdapter.java index dcd2de3c0..792d27ab1 100644 --- a/src/com/android/dialer/calllog/CallLogAdapter.java +++ b/src/com/android/dialer/calllog/CallLogAdapter.java @@ -248,6 +248,8 @@ public class CallLogAdapter extends GroupingListAdapter private final ContactPhotoManager mContactPhotoManager; /** Helper to parse and process phone numbers. */ private PhoneNumberDisplayHelper mPhoneNumberHelper; + /** Helper to access Telephony phone number utils class */ + protected final PhoneNumberUtilsWrapper mPhoneNumberUtilsWrapper; /** Helper to group call log entries. */ private final CallLogGroupBuilder mCallLogGroupBuilder; @@ -365,9 +367,10 @@ public class CallLogAdapter extends GroupingListAdapter mExpandedTranslationZ = resources.getDimension(R.dimen.call_log_expanded_translation_z); mContactPhotoManager = ContactPhotoManager.getInstance(mContext); - mPhoneNumberHelper = new PhoneNumberDisplayHelper(resources); - PhoneCallDetailsHelper phoneCallDetailsHelper = new PhoneCallDetailsHelper( - resources, callTypeHelper, new PhoneNumberUtilsWrapper()); + mPhoneNumberHelper = new PhoneNumberDisplayHelper(mContext, resources); + mPhoneNumberUtilsWrapper = new PhoneNumberUtilsWrapper(mContext); + PhoneCallDetailsHelper phoneCallDetailsHelper = + new PhoneCallDetailsHelper(mContext, resources, mPhoneNumberUtilsWrapper); mCallLogViewsHelper = new CallLogListItemHelper( phoneCallDetailsHelper, mPhoneNumberHelper, resources); @@ -641,8 +644,6 @@ public class CallLogAdapter extends GroupingListAdapter final PhoneAccountHandle accountHandle = PhoneAccountUtils.getAccount( c.getString(CallLogQuery.ACCOUNT_COMPONENT_NAME), c.getString(CallLogQuery.ACCOUNT_ID)); - final Drawable accountIcon = PhoneAccountUtils.getAccountIcon(mContext, - accountHandle); final String countryIso = c.getString(CallLogQuery.COUNTRY_ISO); final long rowId = c.getLong(CallLogQuery.ID); @@ -677,7 +678,7 @@ public class CallLogAdapter extends GroupingListAdapter final ContactInfo cachedContactInfo = getContactInfoFromCallLog(c); final boolean isVoicemailNumber = - PhoneNumberUtilsWrapper.INSTANCE.isVoicemailNumber(number); + mPhoneNumberUtilsWrapper.isVoicemailNumber(accountHandle, number); // Where binding and not in the call log, use default behaviour of invoking a call when // tapping the primary view. @@ -769,14 +770,13 @@ public class CallLogAdapter extends GroupingListAdapter expandOrCollapseActions(callLogItemView, isExpanded(rowId)); if (TextUtils.isEmpty(name)) { - details = new PhoneCallDetails(number, numberPresentation, - formattedNumber, countryIso, geocode, callTypes, date, - duration, null, accountIcon, features, dataUsage, transcription); + details = new PhoneCallDetails(number, numberPresentation, formattedNumber, countryIso, + geocode, callTypes, date, duration, accountHandle, features, dataUsage, + transcription); } else { - details = new PhoneCallDetails(number, numberPresentation, - formattedNumber, countryIso, geocode, callTypes, date, - duration, name, ntype, label, lookupUri, photoUri, sourceType, - null, accountIcon, features, dataUsage, transcription); + details = new PhoneCallDetails(number, numberPresentation, formattedNumber, countryIso, + geocode, callTypes, date, duration, name, ntype, label, lookupUri, photoUri, + sourceType, accountHandle, features, dataUsage, transcription); } mCallLogViewsHelper.setPhoneCallDetails(mContext, views, details); @@ -794,8 +794,8 @@ public class CallLogAdapter extends GroupingListAdapter String nameForDefaultImage = null; if (TextUtils.isEmpty(name)) { - nameForDefaultImage = mPhoneNumberHelper.getDisplayNumber(details.number, - details.numberPresentation, details.formattedNumber).toString(); + nameForDefaultImage = mPhoneNumberHelper.getDisplayNumber(details.accountHandle, + details.number, details.numberPresentation, details.formattedNumber).toString(); } else { nameForDefaultImage = name; } diff --git a/src/com/android/dialer/calllog/CallLogListItemHelper.java b/src/com/android/dialer/calllog/CallLogListItemHelper.java index 68ca7a8dc..1eb25fbfa 100644 --- a/src/com/android/dialer/calllog/CallLogListItemHelper.java +++ b/src/com/android/dialer/calllog/CallLogListItemHelper.java @@ -222,7 +222,7 @@ import com.android.dialer.R; if (!TextUtils.isEmpty(details.name)) { recipient = details.name; } else { - recipient = mPhoneNumberHelper.getDisplayNumber( + recipient = mPhoneNumberHelper.getDisplayNumber(details.accountHandle, details.number, details.numberPresentation, details.formattedNumber); } return recipient; diff --git a/src/com/android/dialer/calllog/DefaultVoicemailNotifier.java b/src/com/android/dialer/calllog/DefaultVoicemailNotifier.java index 837cfba67..970cad6a6 100644 --- a/src/com/android/dialer/calllog/DefaultVoicemailNotifier.java +++ b/src/com/android/dialer/calllog/DefaultVoicemailNotifier.java @@ -28,12 +28,14 @@ import android.database.Cursor; import android.net.Uri; import android.provider.CallLog.Calls; import android.provider.ContactsContract.PhoneLookup; +import android.telecom.PhoneAccountHandle; import android.text.TextUtils; import android.util.Log; import com.android.common.io.MoreCloseables; import com.android.dialer.CallDetailActivity; import com.android.dialer.R; +import com.android.dialer.calllog.PhoneAccountUtils; import com.google.common.collect.Maps; import java.util.Map; @@ -118,7 +120,10 @@ public class DefaultVoicemailNotifier implements VoicemailNotifier { // Check if we already know the name associated with this number. String name = names.get(newCall.number); if (name == null) { - name = mPhoneNumberHelper.getDisplayName(newCall.number, + PhoneAccountHandle accountHandle = PhoneAccountUtils.getAccount( + newCall.accountComponentName, + newCall.accountId); + name = mPhoneNumberHelper.getDisplayName(accountHandle, newCall.number, newCall.numberPresentation).toString(); // If we cannot lookup the contact, use the number instead. if (TextUtils.isEmpty(name)) { @@ -214,13 +219,17 @@ public class DefaultVoicemailNotifier implements VoicemailNotifier { public final Uri voicemailUri; public final String number; public final int numberPresentation; + public final String accountComponentName; + public final String accountId; public NewCall(Uri callsUri, Uri voicemailUri, String number, - int numberPresentation) { + int numberPresentation, String accountComponentName, String accountId) { this.callsUri = callsUri; this.voicemailUri = voicemailUri; this.number = number; this.numberPresentation = numberPresentation; + this.accountComponentName = accountComponentName; + this.accountId = accountId; } } @@ -243,12 +252,15 @@ public class DefaultVoicemailNotifier implements VoicemailNotifier { */ private static final class DefaultNewCallsQuery implements NewCallsQuery { private static final String[] PROJECTION = { - Calls._ID, Calls.NUMBER, Calls.VOICEMAIL_URI, Calls.NUMBER_PRESENTATION + Calls._ID, Calls.NUMBER, Calls.VOICEMAIL_URI, Calls.NUMBER_PRESENTATION, + Calls.PHONE_ACCOUNT_COMPONENT_NAME, Calls.PHONE_ACCOUNT_ID }; private static final int ID_COLUMN_INDEX = 0; private static final int NUMBER_COLUMN_INDEX = 1; private static final int VOICEMAIL_URI_COLUMN_INDEX = 2; private static final int NUMBER_PRESENTATION_COLUMN_INDEX = 3; + private static final int PHONE_ACCOUNT_COMPONENT_NAME_COLUMN_INDEX = 4; + private static final int PHONE_ACCOUNT_ID_COLUMN_INDEX = 5; private final ContentResolver mContentResolver; @@ -284,7 +296,9 @@ public class DefaultVoicemailNotifier implements VoicemailNotifier { Calls.CONTENT_URI_WITH_VOICEMAIL, cursor.getLong(ID_COLUMN_INDEX)); Uri voicemailUri = voicemailUriString == null ? null : Uri.parse(voicemailUriString); return new NewCall(callsUri, voicemailUri, cursor.getString(NUMBER_COLUMN_INDEX), - cursor.getInt(NUMBER_PRESENTATION_COLUMN_INDEX)); + cursor.getInt(NUMBER_PRESENTATION_COLUMN_INDEX), + cursor.getString(PHONE_ACCOUNT_COMPONENT_NAME_COLUMN_INDEX), + cursor.getString(PHONE_ACCOUNT_ID_COLUMN_INDEX)); } } @@ -343,6 +357,6 @@ public class DefaultVoicemailNotifier implements VoicemailNotifier { * called from the main thread. */ public static PhoneNumberDisplayHelper createPhoneNumberHelper(Context context) { - return new PhoneNumberDisplayHelper(context.getResources()); + return new PhoneNumberDisplayHelper(context, context.getResources()); } } diff --git a/src/com/android/dialer/calllog/PhoneAccountUtils.java b/src/com/android/dialer/calllog/PhoneAccountUtils.java index d716aee49..20b81d87d 100644 --- a/src/com/android/dialer/calllog/PhoneAccountUtils.java +++ b/src/com/android/dialer/calllog/PhoneAccountUtils.java @@ -29,10 +29,9 @@ import android.text.TextUtils; */ public class PhoneAccountUtils { /** - * Generate account info from data in Telecomm database + * Compose PhoneAccount object from component name and account id */ - public static PhoneAccountHandle getAccount(String componentString, - String accountId) { + public static PhoneAccountHandle getAccount(String componentString, String accountId) { if (TextUtils.isEmpty(componentString) || TextUtils.isEmpty(accountId)) { return null; } @@ -41,7 +40,7 @@ public class PhoneAccountUtils { } /** - * Generate account icon from data in Telecomm database + * Extract account icon from PhoneAccount object */ public static Drawable getAccountIcon(Context context, PhoneAccountHandle phoneAccount) { final PhoneAccount account = getAccountOrNull(context, phoneAccount); @@ -52,7 +51,7 @@ public class PhoneAccountUtils { } /** - * Generate account label from data in Telecomm database + * Extract account label from PhoneAccount object */ public static String getAccountLabel(Context context, PhoneAccountHandle phoneAccount) { final PhoneAccount account = getAccountOrNull(context, phoneAccount); @@ -66,8 +65,7 @@ public class PhoneAccountUtils { * Retrieve the account metadata, but if the account does not exist or the device has only a * single registered and enabled account, return null. */ - private static PhoneAccount getAccountOrNull(Context context, - PhoneAccountHandle phoneAccount) { + private static PhoneAccount getAccountOrNull(Context context, PhoneAccountHandle phoneAccount) { final TelecomManager telecomManager = (TelecomManager) context.getSystemService(Context.TELECOM_SERVICE); final PhoneAccount account = telecomManager.getPhoneAccount(phoneAccount); diff --git a/src/com/android/dialer/calllog/PhoneNumberDisplayHelper.java b/src/com/android/dialer/calllog/PhoneNumberDisplayHelper.java index 5d7ce7ea9..0dffd868a 100644 --- a/src/com/android/dialer/calllog/PhoneNumberDisplayHelper.java +++ b/src/com/android/dialer/calllog/PhoneNumberDisplayHelper.java @@ -16,8 +16,10 @@ package com.android.dialer.calllog; +import android.content.Context; import android.content.res.Resources; import android.provider.CallLog.Calls; +import android.telecom.PhoneAccountHandle; import android.text.TextUtils; import android.util.Log; @@ -27,20 +29,25 @@ import com.android.dialer.R; * Helper for formatting and managing the display of phone numbers. */ public class PhoneNumberDisplayHelper { - private final PhoneNumberUtilsWrapper mPhoneNumberUtils; + private final Context mContext; private final Resources mResources; + private final PhoneNumberUtilsWrapper mPhoneNumberUtilsWrapper; - public PhoneNumberDisplayHelper(Resources resources) { + public PhoneNumberDisplayHelper(Context context, Resources resources) { + mContext = context; mResources = resources; - mPhoneNumberUtils = new PhoneNumberUtilsWrapper(); + mPhoneNumberUtilsWrapper = new PhoneNumberUtilsWrapper(context); } - public PhoneNumberDisplayHelper(PhoneNumberUtilsWrapper phoneNumberUtils, Resources resources) { - mPhoneNumberUtils = phoneNumberUtils; + public PhoneNumberDisplayHelper(Context context, Resources resources, + PhoneNumberUtilsWrapper phoneNumberUtils) { + mContext = context; mResources = resources; + mPhoneNumberUtilsWrapper = phoneNumberUtils; } - /* package */ CharSequence getDisplayName(CharSequence number, int presentation) { + /* package */ CharSequence getDisplayName(PhoneAccountHandle accountHandle, CharSequence number, + int presentation) { if (presentation == Calls.PRESENTATION_UNKNOWN) { return mResources.getString(R.string.unknown); } @@ -50,7 +57,7 @@ public class PhoneNumberDisplayHelper { if (presentation == Calls.PRESENTATION_PAYPHONE) { return mResources.getString(R.string.payphone); } - if (mPhoneNumberUtils.isVoicemailNumber(number)) { + if (mPhoneNumberUtilsWrapper.isVoicemailNumber(accountHandle, number)) { return mResources.getString(R.string.voicemail); } if (PhoneNumberUtilsWrapper.isLegacyUnknownNumbers(number)) { @@ -62,13 +69,14 @@ public class PhoneNumberDisplayHelper { /** * Returns the string to display for the given phone number. * + * @param accountHandle The handle for the account corresponding to the call * @param number the number to display * @param formattedNumber the formatted number if available, may be null */ - public CharSequence getDisplayNumber(CharSequence number, + public CharSequence getDisplayNumber(PhoneAccountHandle accountHandle, CharSequence number, int presentation, CharSequence formattedNumber) { - final CharSequence displayName = getDisplayName(number, presentation); + final CharSequence displayName = getDisplayName(accountHandle, number, presentation); if (!TextUtils.isEmpty(displayName)) { return displayName; } diff --git a/src/com/android/dialer/calllog/PhoneNumberUtilsWrapper.java b/src/com/android/dialer/calllog/PhoneNumberUtilsWrapper.java index 00a260a25..11f4a67f6 100644 --- a/src/com/android/dialer/calllog/PhoneNumberUtilsWrapper.java +++ b/src/com/android/dialer/calllog/PhoneNumberUtilsWrapper.java @@ -16,7 +16,10 @@ package com.android.dialer.calllog; +import android.content.Context; import android.provider.CallLog; +import android.telecom.PhoneAccountHandle; +import android.telecom.TelecomManager; import android.telephony.PhoneNumberUtils; import android.text.TextUtils; @@ -30,8 +33,12 @@ import java.util.Set; * */ public class PhoneNumberUtilsWrapper { - public static final PhoneNumberUtilsWrapper INSTANCE = new PhoneNumberUtilsWrapper(); private static final Set LEGACY_UNKNOWN_NUMBERS = Sets.newHashSet("-1", "-2", "-3"); + private final Context mContext; + + public PhoneNumberUtilsWrapper(Context context) { + mContext = context; + } /** Returns true if it is possible to place a call to the given number. */ public static boolean canPlaceCallsTo(CharSequence number, int presentation) { @@ -39,31 +46,27 @@ public class PhoneNumberUtilsWrapper { && !TextUtils.isEmpty(number) && !isLegacyUnknownNumbers(number); } - /** - * Returns true if it is possible to send an SMS to the given number. - */ - public boolean canSendSmsTo(CharSequence number, int presentation) { - return canPlaceCallsTo(number, presentation) && !isVoicemailNumber(number) && !isSipNumber( - number); - } - /** * Returns true if the given number is the number of the configured voicemail. To be able to * mock-out this, it is not a static method. */ - public boolean isVoicemailNumber(CharSequence number) { - return number!= null && PhoneNumberUtils.isVoiceMailNumber(number.toString()); + public boolean isVoicemailNumber(PhoneAccountHandle accountHandle, + CharSequence number) { + final TelecomManager telecomManager = + (TelecomManager) mContext.getSystemService(Context.TELECOM_SERVICE); + return number!= null && telecomManager.isVoiceMailNumber(accountHandle, number.toString()); } /** * Returns true if the given number is a SIP address. To be able to mock-out this, it is not a * static method. */ - public boolean isSipNumber(CharSequence number) { + public static boolean isSipNumber(CharSequence number) { return number != null && PhoneNumberHelper.isUriNumber(number.toString()); } - public static boolean isUnknownNumberThatCanBeLookedUp(CharSequence number, int presentation) { + public boolean isUnknownNumberThatCanBeLookedUp(PhoneAccountHandle accountHandle, + CharSequence number, int presentation) { if (presentation == CallLog.Calls.PRESENTATION_UNKNOWN) { return false; } @@ -76,7 +79,7 @@ public class PhoneNumberUtilsWrapper { if (TextUtils.isEmpty(number)) { return false; } - if (INSTANCE.isVoicemailNumber(number)) { + if (isVoicemailNumber(accountHandle, number)) { return false; } if (isLegacyUnknownNumbers(number)) { -- cgit v1.2.3