From fb0a934ad90f1855787563eb80f2c8fff7f640ac Mon Sep 17 00:00:00 2001 From: Chiao Cheng Date: Fri, 13 Sep 2013 17:27:42 -0700 Subject: Follow up on build break to fix unit tests. Change-Id: I82b7fa50601f6dad60038fd1b9c5f0aad2f374f5 --- src/com/android/dialer/CallDetailActivity.java | 17 ++--- src/com/android/dialer/PhoneCallDetailsHelper.java | 9 ++- src/com/android/dialer/calllog/CallLogAdapter.java | 6 +- .../android/dialer/calllog/CallLogFragment.java | 7 +- .../dialer/calllog/CallLogListItemHelper.java | 4 +- .../android/dialer/calllog/PhoneNumberHelper.java | 49 +------------- .../dialer/calllog/PhoneNumberUtilsWrapper.java | 76 ++++++++++++++++++++++ 7 files changed, 100 insertions(+), 68 deletions(-) create mode 100644 src/com/android/dialer/calllog/PhoneNumberUtilsWrapper.java (limited to 'src/com') diff --git a/src/com/android/dialer/CallDetailActivity.java b/src/com/android/dialer/CallDetailActivity.java index 24b59fb3e..7a0870827 100644 --- a/src/com/android/dialer/CallDetailActivity.java +++ b/src/com/android/dialer/CallDetailActivity.java @@ -55,7 +55,6 @@ import com.android.contacts.common.ContactPhotoManager; import com.android.contacts.common.CallUtil; import com.android.contacts.common.ClipboardUtils; import com.android.contacts.common.GeoUtil; -import com.android.contacts.common.util.Constants; import com.android.contacts.common.util.UriUtils; import com.android.dialer.BackScrollManager.ScrollableHeader; import com.android.dialer.calllog.CallDetailHistoryAdapter; @@ -63,6 +62,7 @@ import com.android.dialer.calllog.CallTypeHelper; import com.android.dialer.calllog.ContactInfo; import com.android.dialer.calllog.ContactInfoHelper; import com.android.dialer.calllog.PhoneNumberHelper; +import com.android.dialer.calllog.PhoneNumberUtilsWrapper; import com.android.dialer.util.AsyncTaskExecutor; import com.android.dialer.util.AsyncTaskExecutors; import com.android.dialer.voicemail.VoicemailPlaybackFragment; @@ -266,7 +266,7 @@ public class CallDetailActivity extends Activity implements ProximitySensorAware mCallTypeHelper = new CallTypeHelper(getResources()); mPhoneNumberHelper = new PhoneNumberHelper(mResources); mPhoneCallDetailsHelper = new PhoneCallDetailsHelper(mResources, mCallTypeHelper, - mPhoneNumberHelper); + new PhoneNumberUtilsWrapper()); mVoicemailStatusHelper = new VoicemailStatusHelperImpl(); mAsyncQueryHandler = new CallDetailActivityQueryHandler(this); mHeaderTextView = (TextView) findViewById(R.id.header_text); @@ -435,9 +435,10 @@ public class CallDetailActivity extends Activity implements ProximitySensorAware // Cache the details about the phone number. final boolean canPlaceCallsTo = - PhoneNumberHelper.canPlaceCallsTo(mNumber, numberPresentation); - final boolean isVoicemailNumber = PhoneNumberHelper.isVoicemailNumber(mNumber); - final boolean isSipNumber = mPhoneNumberHelper.isSipNumber(mNumber); + PhoneNumberUtilsWrapper.canPlaceCallsTo(mNumber, numberPresentation); + final PhoneNumberUtilsWrapper phoneUtils = new PhoneNumberUtilsWrapper(); + final boolean isVoicemailNumber = phoneUtils.isVoicemailNumber(mNumber); + final boolean isSipNumber = phoneUtils.isSipNumber(mNumber); // Let user view contact details if they exist, otherwise add option to create new // contact from this number. @@ -536,7 +537,7 @@ public class CallDetailActivity extends Activity implements ProximitySensorAware // The secondary action allows to send an SMS to the number that placed the // call. - if (mPhoneNumberHelper.canSendSmsTo(mNumber, numberPresentation)) { + if (phoneUtils.canSendSmsTo(mNumber, numberPresentation)) { entry.setSecondaryAction( R.drawable.ic_text_holo_light, new Intent(Intent.ACTION_SENDTO, @@ -630,8 +631,8 @@ public class CallDetailActivity extends Activity implements ProximitySensorAware final Uri lookupUri; // If this is not a regular number, there is no point in looking it up in the contacts. ContactInfo info = - PhoneNumberHelper.canPlaceCallsTo(number, numberPresentation) - && !PhoneNumberHelper.isVoicemailNumber(number) + PhoneNumberUtilsWrapper.canPlaceCallsTo(number, numberPresentation) + && new PhoneNumberUtilsWrapper().isVoicemailNumber(number) ? mContactInfoHelper.lookupNumber(number, countryIso) : null; if (info == null) { diff --git a/src/com/android/dialer/PhoneCallDetailsHelper.java b/src/com/android/dialer/PhoneCallDetailsHelper.java index d882eb686..340168e8b 100644 --- a/src/com/android/dialer/PhoneCallDetailsHelper.java +++ b/src/com/android/dialer/PhoneCallDetailsHelper.java @@ -34,6 +34,7 @@ import com.android.contacts.common.test.NeededForTesting; import com.android.dialer.calllog.CallTypeHelper; import com.android.dialer.calllog.ContactInfo; import com.android.dialer.calllog.PhoneNumberHelper; +import com.android.dialer.calllog.PhoneNumberUtilsWrapper; /** * Helper class to fill in the views in {@link PhoneCallDetailsViews}. @@ -48,6 +49,7 @@ public class PhoneCallDetailsHelper { // Helper classes. private final CallTypeHelper mCallTypeHelper; private final PhoneNumberHelper mPhoneNumberHelper; + private final PhoneNumberUtilsWrapper mPhoneNumberUtilsWrapper; /** * Creates a new instance of the helper. @@ -57,10 +59,11 @@ public class PhoneCallDetailsHelper { * @param resources used to look up strings */ public PhoneCallDetailsHelper(Resources resources, CallTypeHelper callTypeHelper, - PhoneNumberHelper phoneNumberHelper) { + PhoneNumberUtilsWrapper phoneUtils) { mResources = resources; mCallTypeHelper = callTypeHelper; - mPhoneNumberHelper = phoneNumberHelper; + mPhoneNumberHelper = new PhoneNumberHelper(resources); + mPhoneNumberUtilsWrapper = phoneUtils; } /** Fills the call details views with content. */ @@ -117,7 +120,7 @@ public class PhoneCallDetailsHelper { if (TextUtils.isEmpty(details.name)) { nameText = displayNumber; if (TextUtils.isEmpty(details.geocode) - || PhoneNumberHelper.isVoicemailNumber(details.number)) { + || mPhoneNumberUtilsWrapper.isVoicemailNumber(details.number)) { numberText = mResources.getString(R.string.call_log_empty_gecode); } else { numberText = details.geocode; diff --git a/src/com/android/dialer/calllog/CallLogAdapter.java b/src/com/android/dialer/calllog/CallLogAdapter.java index 136899eaf..8b7e27d5a 100644 --- a/src/com/android/dialer/calllog/CallLogAdapter.java +++ b/src/com/android/dialer/calllog/CallLogAdapter.java @@ -249,7 +249,7 @@ public class CallLogAdapter extends GroupingListAdapter mContactPhotoManager = ContactPhotoManager.getInstance(mContext); mPhoneNumberHelper = new PhoneNumberHelper(resources); PhoneCallDetailsHelper phoneCallDetailsHelper = new PhoneCallDetailsHelper( - resources, callTypeHelper, mPhoneNumberHelper); + resources, callTypeHelper, new PhoneNumberUtilsWrapper()); mCallLogViewsHelper = new CallLogListItemHelper( phoneCallDetailsHelper, mPhoneNumberHelper, resources); @@ -541,8 +541,8 @@ public class CallLogAdapter extends GroupingListAdapter ExpirableCache.CachedValue cachedInfo = mContactInfoCache.getCachedValue(numberCountryIso); ContactInfo info = cachedInfo == null ? null : cachedInfo.getValue(); - if (!PhoneNumberHelper.canPlaceCallsTo(number, numberPresentation) - || PhoneNumberHelper.isVoicemailNumber(number)) { + if (!PhoneNumberUtilsWrapper.canPlaceCallsTo(number, numberPresentation) + || new PhoneNumberUtilsWrapper().isVoicemailNumber(number)) { // If this is a number that cannot be dialed, there is no point in looking up a contact // for it. info = ContactInfo.EMPTY; diff --git a/src/com/android/dialer/calllog/CallLogFragment.java b/src/com/android/dialer/calllog/CallLogFragment.java index d0d34d897..ce27ab72a 100644 --- a/src/com/android/dialer/calllog/CallLogFragment.java +++ b/src/com/android/dialer/calllog/CallLogFragment.java @@ -31,7 +31,6 @@ import android.provider.CallLog.Calls; import android.provider.ContactsContract; import android.telephony.PhoneNumberUtils; import android.telephony.TelephonyManager; -import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -132,8 +131,8 @@ public class CallLogFragment extends ListFragment this, mLogLimit); mKeyguardManager = (KeyguardManager) getActivity().getSystemService(Context.KEYGUARD_SERVICE); - getActivity().getContentResolver().registerContentObserver( - CallLog.CONTENT_URI, true, mCallLogObserver); + getActivity().getContentResolver().registerContentObserver(CallLog.CONTENT_URI, true, + mCallLogObserver); getActivity().getContentResolver().registerContentObserver( ContactsContract.Contacts.CONTENT_URI, true, mContactsObserver); setHasOptionsMenu(true); @@ -363,7 +362,7 @@ public class CallLogFragment extends ListFragment if (cursor != null) { String number = cursor.getString(CallLogQuery.NUMBER); int numberPresentation = cursor.getInt(CallLogQuery.NUMBER_PRESENTATION); - if (!PhoneNumberHelper.canPlaceCallsTo(number, numberPresentation)) { + if (!PhoneNumberUtilsWrapper.canPlaceCallsTo(number, numberPresentation)) { // This number can't be called, do nothing return; } diff --git a/src/com/android/dialer/calllog/CallLogListItemHelper.java b/src/com/android/dialer/calllog/CallLogListItemHelper.java index 813d59fac..576a432ac 100644 --- a/src/com/android/dialer/calllog/CallLogListItemHelper.java +++ b/src/com/android/dialer/calllog/CallLogListItemHelper.java @@ -60,8 +60,8 @@ import com.android.dialer.R; boolean isHighlighted, boolean useCallAsPrimaryAction) { mPhoneCallDetailsHelper.setPhoneCallDetails(views.phoneCallDetailsViews, details, isHighlighted); - boolean canCall = PhoneNumberHelper.canPlaceCallsTo(details.number, - details.numberPresentation); + boolean canCall = PhoneNumberUtilsWrapper.canPlaceCallsTo(details.number, + details.numberPresentation); boolean canPlay = details.callTypes[0] == Calls.VOICEMAIL_TYPE; if (canPlay) { diff --git a/src/com/android/dialer/calllog/PhoneNumberHelper.java b/src/com/android/dialer/calllog/PhoneNumberHelper.java index b89c727a7..9e1d816b2 100644 --- a/src/com/android/dialer/calllog/PhoneNumberHelper.java +++ b/src/com/android/dialer/calllog/PhoneNumberHelper.java @@ -33,18 +33,6 @@ public class PhoneNumberHelper { mResources = resources; } - /** Returns true if it is possible to place a call to the given number. */ - public static boolean canPlaceCallsTo(CharSequence number, int presentation) { - return presentation == Calls.PRESENTATION_ALLOWED - && !TextUtils.isEmpty(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 the string to display for the given phone number. * @@ -65,7 +53,7 @@ public class PhoneNumberHelper { if (TextUtils.isEmpty(number)) { return ""; } - if (isVoicemailNumber(number)) { + if (new PhoneNumberUtilsWrapper().isVoicemailNumber(number)) { return mResources.getString(R.string.voicemail); } if (TextUtils.isEmpty(formattedNumber)) { @@ -74,39 +62,4 @@ public class PhoneNumberHelper { return formattedNumber; } } - - public static boolean isUnknownNumberThatCanBeLookedUp(CharSequence number, int presentation) { - if (presentation == Calls.PRESENTATION_UNKNOWN) { - return false; - } - if (presentation == Calls.PRESENTATION_RESTRICTED) { - return false; - } - if (presentation == Calls.PRESENTATION_PAYPHONE) { - return false; - } - if (TextUtils.isEmpty(number)) { - return false; - } - if (isVoicemailNumber(number)) { - return false; - } - return true; - } - - /** - * 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 static boolean isVoicemailNumber(CharSequence number) { - return PhoneNumberUtils.isVoiceMailNumber(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) { - return PhoneNumberUtils.isUriNumber(number.toString()); - } } diff --git a/src/com/android/dialer/calllog/PhoneNumberUtilsWrapper.java b/src/com/android/dialer/calllog/PhoneNumberUtilsWrapper.java new file mode 100644 index 000000000..c397f0a31 --- /dev/null +++ b/src/com/android/dialer/calllog/PhoneNumberUtilsWrapper.java @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +package com.android.dialer.calllog; + +import android.provider.CallLog; +import android.telephony.PhoneNumberUtils; +import android.text.TextUtils; + +/** + * + */ +public class PhoneNumberUtilsWrapper { + + /** Returns true if it is possible to place a call to the given number. */ + public static boolean canPlaceCallsTo(CharSequence number, int presentation) { + return presentation == CallLog.Calls.PRESENTATION_ALLOWED + && !TextUtils.isEmpty(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 PhoneNumberUtils.isVoiceMailNumber(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) { + return PhoneNumberUtils.isUriNumber(number.toString()); + } + + public static boolean isUnknownNumberThatCanBeLookedUp(CharSequence number, int presentation) { + if (presentation == CallLog.Calls.PRESENTATION_UNKNOWN) { + return false; + } + if (presentation == CallLog.Calls.PRESENTATION_RESTRICTED) { + return false; + } + if (presentation == CallLog.Calls.PRESENTATION_PAYPHONE) { + return false; + } + if (TextUtils.isEmpty(number)) { + return false; + } + if (new PhoneNumberUtilsWrapper().isVoicemailNumber(number)) { + return false; + } + return true; + } +} -- cgit v1.2.3