summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChiao Cheng <chiaocheng@google.com>2013-09-14 14:07:22 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2013-09-14 14:07:22 -0700
commit3027da2f2c54fd3600bd07c94f7a4be89ff82b00 (patch)
tree409188c7460355143b2f31c676d3d30f136d12c7
parentc5ccceb49fa0811f64940bad1d1a9efe0cf4a719 (diff)
parent84897e62f817be1843f8b71de4429eb11cdacdd9 (diff)
am 84897e62: am 02741d62: Merge "Follow up on build break to fix unit tests." into klp-dev
* commit '84897e62f817be1843f8b71de4429eb11cdacdd9': Follow up on build break to fix unit tests.
-rw-r--r--src/com/android/dialer/CallDetailActivity.java17
-rw-r--r--src/com/android/dialer/PhoneCallDetailsHelper.java9
-rw-r--r--src/com/android/dialer/calllog/CallLogAdapter.java6
-rw-r--r--src/com/android/dialer/calllog/CallLogFragment.java7
-rw-r--r--src/com/android/dialer/calllog/CallLogListItemHelper.java4
-rw-r--r--src/com/android/dialer/calllog/PhoneNumberHelper.java49
-rw-r--r--src/com/android/dialer/calllog/PhoneNumberUtilsWrapper.java76
-rw-r--r--tests/src/com/android/dialer/PhoneCallDetailsHelperTest.java10
-rw-r--r--tests/src/com/android/dialer/calllog/CallLogListItemHelperTest.java5
-rw-r--r--tests/src/com/android/dialer/calllog/TestPhoneNumberUtilsWrapper.java (renamed from tests/src/com/android/dialer/calllog/TestPhoneNumberHelper.java)17
10 files changed, 117 insertions, 83 deletions
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<ContactInfo> 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;
+ }
+}
diff --git a/tests/src/com/android/dialer/PhoneCallDetailsHelperTest.java b/tests/src/com/android/dialer/PhoneCallDetailsHelperTest.java
index 05c59a77f..6a9817f26 100644
--- a/tests/src/com/android/dialer/PhoneCallDetailsHelperTest.java
+++ b/tests/src/com/android/dialer/PhoneCallDetailsHelperTest.java
@@ -26,8 +26,7 @@ import android.view.View;
import android.widget.TextView;
import com.android.dialer.calllog.CallTypeHelper;
-import com.android.dialer.calllog.PhoneNumberHelper;
-import com.android.dialer.calllog.TestPhoneNumberHelper;
+import com.android.dialer.calllog.TestPhoneNumberUtilsWrapper;
import com.android.dialer.util.LocaleTestUtils;
import java.util.GregorianCalendar;
@@ -58,7 +57,6 @@ public class PhoneCallDetailsHelperTest extends AndroidTestCase {
/** The views to fill. */
private PhoneCallDetailsViews mViews;
private TextView mNameView;
- private PhoneNumberHelper mPhoneNumberHelper;
private LocaleTestUtils mLocaleTestUtils;
@Override
@@ -67,8 +65,9 @@ public class PhoneCallDetailsHelperTest extends AndroidTestCase {
Context context = getContext();
Resources resources = context.getResources();
CallTypeHelper callTypeHelper = new CallTypeHelper(resources);
- mPhoneNumberHelper = new TestPhoneNumberHelper(resources, TEST_VOICEMAIL_NUMBER);
- mHelper = new PhoneCallDetailsHelper(resources, callTypeHelper, mPhoneNumberHelper);
+ final TestPhoneNumberUtilsWrapper phoneUtils = new TestPhoneNumberUtilsWrapper(
+ TEST_VOICEMAIL_NUMBER);
+ mHelper = new PhoneCallDetailsHelper(resources, callTypeHelper, phoneUtils);
mHelper.setCurrentTimeForTest(
new GregorianCalendar(2011, 5, 4, 13, 0, 0).getTimeInMillis());
mViews = PhoneCallDetailsViews.createForTest(context);
@@ -83,7 +82,6 @@ public class PhoneCallDetailsHelperTest extends AndroidTestCase {
mNameView = null;
mViews = null;
mHelper = null;
- mPhoneNumberHelper = null;
super.tearDown();
}
diff --git a/tests/src/com/android/dialer/calllog/CallLogListItemHelperTest.java b/tests/src/com/android/dialer/calllog/CallLogListItemHelperTest.java
index 1b793bc65..bb940edca 100644
--- a/tests/src/com/android/dialer/calllog/CallLogListItemHelperTest.java
+++ b/tests/src/com/android/dialer/calllog/CallLogListItemHelperTest.java
@@ -57,9 +57,10 @@ public class CallLogListItemHelperTest extends AndroidTestCase {
Context context = getContext();
Resources resources = context.getResources();
CallTypeHelper callTypeHelper = new CallTypeHelper(resources);
- mPhoneNumberHelper = new TestPhoneNumberHelper(resources, TEST_VOICEMAIL_NUMBER);
+ final TestPhoneNumberUtilsWrapper phoneUtils = new TestPhoneNumberUtilsWrapper(
+ TEST_VOICEMAIL_NUMBER);
PhoneCallDetailsHelper phoneCallDetailsHelper = new PhoneCallDetailsHelper(
- resources, callTypeHelper, mPhoneNumberHelper);
+ resources, callTypeHelper, phoneUtils);
mHelper = new CallLogListItemHelper(phoneCallDetailsHelper, mPhoneNumberHelper, resources);
mViews = CallLogListItemViews.createForTest(context);
}
diff --git a/tests/src/com/android/dialer/calllog/TestPhoneNumberHelper.java b/tests/src/com/android/dialer/calllog/TestPhoneNumberUtilsWrapper.java
index 2671a7151..0dbd91479 100644
--- a/tests/src/com/android/dialer/calllog/TestPhoneNumberHelper.java
+++ b/tests/src/com/android/dialer/calllog/TestPhoneNumberUtilsWrapper.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2011 The Android Open Source Project
+ * 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.
@@ -11,7 +11,7 @@
* 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.
+ * limitations under the License
*/
package com.android.dialer.calllog;
@@ -19,15 +19,18 @@ package com.android.dialer.calllog;
import android.content.res.Resources;
/**
- * Modified version of {@link PhoneNumberHelper} to be used in tests that allows injecting the
- * voicemail number.
+ * Modified version of {@link com.android.dialer.calllog.PhoneNumberHelper} to be used in tests
+ * that allows injecting the voicemail number.
*/
-public final class TestPhoneNumberHelper extends PhoneNumberHelper {
+public final class TestPhoneNumberUtilsWrapper extends PhoneNumberUtilsWrapper {
private CharSequence mVoicemailNumber;
- public TestPhoneNumberHelper(Resources resources, CharSequence voicemailNumber) {
- super(resources);
+ public TestPhoneNumberUtilsWrapper(CharSequence voicemailNumber) {
mVoicemailNumber = voicemailNumber;
}
+ @Override
+ public boolean isVoicemailNumber(CharSequence number) {
+ return mVoicemailNumber.equals(number);
+ }
}