summaryrefslogtreecommitdiff
path: root/java
diff options
context:
space:
mode:
authorTreehugger Robot <treehugger-gerrit@google.com>2018-03-02 00:42:19 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2018-03-02 00:42:19 +0000
commit8ddc801874663e67e662ec7ea2f185579ce22b89 (patch)
tree8269029d0678b4c8f00c3d09f12014b0d22d0494 /java
parent9bd89a3096dcb434d3cf278ddc066d9b0c328ddd (diff)
parentb06d00924123aa13086be564fee6404215fcc0d5 (diff)
Merge "Disable phone number formatting for devices with Argentinian SIMs."
Diffstat (limited to 'java')
-rw-r--r--java/com/android/contacts/common/compat/PhoneNumberUtilsCompat.java46
-rw-r--r--java/com/android/contacts/common/list/ContactListItemView.java7
-rw-r--r--java/com/android/contacts/common/model/ContactLoader.java2
-rw-r--r--java/com/android/contacts/common/model/dataitem/PhoneDataItem.java12
-rw-r--r--java/com/android/contacts/common/util/ContactDisplayUtils.java4
-rw-r--r--java/com/android/contacts/common/widget/SelectPhoneAccountDialogFragment.java1
-rw-r--r--java/com/android/dialer/app/calllog/CallLogAdapter.java3
-rw-r--r--java/com/android/dialer/app/calllog/CallLogListItemViewHolder.java3
-rw-r--r--java/com/android/dialer/app/calllog/CallLogNotificationsQueryHelper.java3
-rw-r--r--java/com/android/dialer/app/calllog/LegacyVoicemailNotifier.java6
-rw-r--r--java/com/android/dialer/app/calllog/MissedCallNotifier.java6
-rw-r--r--java/com/android/dialer/app/filterednumber/BlockedNumbersAdapter.java4
-rw-r--r--java/com/android/dialer/app/list/BlockedListSearchFragment.java4
-rw-r--r--java/com/android/dialer/app/list/DialerPhoneNumberListAdapter.java4
-rw-r--r--java/com/android/dialer/calllogutils/PhoneNumberDisplayUtil.java6
-rw-r--r--java/com/android/dialer/dialpadview/DialpadFragment.java6
-rw-r--r--java/com/android/dialer/phonenumbercache/ContactInfoHelper.java2
-rw-r--r--java/com/android/dialer/phonenumberutil/PhoneNumberHelper.java35
-rw-r--r--java/com/android/dialer/speeddial/SuggestionViewHolder.java4
-rw-r--r--java/com/android/incallui/CallCardPresenter.java2
-rw-r--r--java/com/android/incallui/ConferenceParticipantListAdapter.java4
-rw-r--r--java/com/android/incallui/ContactInfoCache.java6
-rw-r--r--java/com/android/incallui/DialpadFragment.java4
-rw-r--r--java/com/android/incallui/contactgrid/ContactGridManager.java4
-rw-r--r--java/com/android/incallui/spam/SpamCallListListener.java7
-rw-r--r--java/com/android/incallui/spam/SpamNotificationActivity.java6
26 files changed, 86 insertions, 105 deletions
diff --git a/java/com/android/contacts/common/compat/PhoneNumberUtilsCompat.java b/java/com/android/contacts/common/compat/PhoneNumberUtilsCompat.java
deleted file mode 100644
index a6cfe07cd..000000000
--- a/java/com/android/contacts/common/compat/PhoneNumberUtilsCompat.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright (C) 2015 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.contacts.common.compat;
-
-import android.telephony.PhoneNumberUtils;
-import android.text.style.TtsSpan;
-
-/**
- * This class contains static utility methods extracted from PhoneNumberUtils, and the methods were
- * added in API level 23. In this way, we could enable the corresponding functionality for pre-M
- * devices. We need maintain this class and keep it synced with PhoneNumberUtils. Another thing to
- * keep in mind is that we use com.google.i18n rather than com.android.i18n in here, so we need make
- * sure the application behavior is preserved.
- */
-public class PhoneNumberUtilsCompat {
-
- /** Not instantiable. */
- private PhoneNumberUtilsCompat() {}
-
- public static String formatNumber(
- String phoneNumber, String phoneNumberE164, String defaultCountryIso) {
- return PhoneNumberUtils.formatNumber(phoneNumber, phoneNumberE164, defaultCountryIso);
- }
-
- public static CharSequence createTtsSpannable(CharSequence phoneNumber) {
- return PhoneNumberUtils.createTtsSpannable(phoneNumber);
- }
-
- public static TtsSpan createTtsSpan(String phoneNumber) {
- return PhoneNumberUtils.createTtsSpan(phoneNumber);
- }
-}
diff --git a/java/com/android/contacts/common/list/ContactListItemView.java b/java/com/android/contacts/common/list/ContactListItemView.java
index 0a5bf094b..409aa1b9e 100644
--- a/java/com/android/contacts/common/list/ContactListItemView.java
+++ b/java/com/android/contacts/common/list/ContactListItemView.java
@@ -32,6 +32,7 @@ import android.provider.ContactsContract.SearchSnippets;
import android.support.annotation.IntDef;
import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat;
+import android.telephony.PhoneNumberUtils;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.TextUtils;
@@ -50,7 +51,6 @@ import android.widget.TextView;
import com.android.contacts.common.ContactPresenceIconUtil;
import com.android.contacts.common.ContactStatusUtil;
import com.android.contacts.common.R;
-import com.android.contacts.common.compat.PhoneNumberUtilsCompat;
import com.android.contacts.common.format.TextHighlighter;
import com.android.contacts.common.list.PhoneNumberListAdapter.Listener;
import com.android.contacts.common.util.ContactDisplayUtils;
@@ -1111,7 +1111,7 @@ public class ContactListItemView extends ViewGroup implements SelectionBoundsAdj
mSnippetView.setVisibility(VISIBLE);
if (ContactDisplayUtils.isPossiblePhoneNumber(text)) {
// Give the text-to-speech engine a hint that it's a phone number
- mSnippetView.setContentDescription(PhoneNumberUtilsCompat.createTtsSpannable(text));
+ mSnippetView.setContentDescription(PhoneNumberUtils.createTtsSpannable(text));
} else {
mSnippetView.setContentDescription(null);
}
@@ -1232,8 +1232,7 @@ public class ContactListItemView extends ViewGroup implements SelectionBoundsAdj
if (ContactDisplayUtils.isPossiblePhoneNumber(name)) {
// Give the text-to-speech engine a hint that it's a phone number
mNameTextView.setTextDirection(View.TEXT_DIRECTION_LTR);
- mNameTextView.setContentDescription(
- PhoneNumberUtilsCompat.createTtsSpannable(name.toString()));
+ mNameTextView.setContentDescription(PhoneNumberUtils.createTtsSpannable(name.toString()));
} else {
// Remove span tags of highlighting for talkback to avoid reading highlighting and rest
// of the name into two separate parts.
diff --git a/java/com/android/contacts/common/model/ContactLoader.java b/java/com/android/contacts/common/model/ContactLoader.java
index 51b8e3efc..12cca4f13 100644
--- a/java/com/android/contacts/common/model/ContactLoader.java
+++ b/java/com/android/contacts/common/model/ContactLoader.java
@@ -669,7 +669,7 @@ public class ContactLoader extends AsyncTaskLoader<Contact> {
final DataItem dataItem = dataItems.get(dataIndex);
if (dataItem instanceof PhoneDataItem) {
final PhoneDataItem phoneDataItem = (PhoneDataItem) dataItem;
- phoneDataItem.computeFormattedPhoneNumber(countryIso);
+ phoneDataItem.computeFormattedPhoneNumber(getContext(), countryIso);
}
}
}
diff --git a/java/com/android/contacts/common/model/dataitem/PhoneDataItem.java b/java/com/android/contacts/common/model/dataitem/PhoneDataItem.java
index e1f56456a..ed3212490 100644
--- a/java/com/android/contacts/common/model/dataitem/PhoneDataItem.java
+++ b/java/com/android/contacts/common/model/dataitem/PhoneDataItem.java
@@ -19,15 +19,15 @@ package com.android.contacts.common.model.dataitem;
import android.content.ContentValues;
import android.content.Context;
import android.provider.ContactsContract.CommonDataKinds.Phone;
-import com.android.contacts.common.compat.PhoneNumberUtilsCompat;
+import com.android.dialer.phonenumberutil.PhoneNumberHelper;
/**
* Represents a phone data item, wrapping the columns in {@link
- * ContactsContract.CommonDataKinds.Phone}.
+ * android.provider.ContactsContract.CommonDataKinds.Phone}.
*/
public class PhoneDataItem extends DataItem {
- public static final String KEY_FORMATTED_PHONE_NUMBER = "formattedPhoneNumber";
+ private static final String KEY_FORMATTED_PHONE_NUMBER = "formattedPhoneNumber";
/* package */ PhoneDataItem(ContentValues values) {
super(values);
@@ -50,12 +50,12 @@ public class PhoneDataItem extends DataItem {
return getContentValues().getAsString(Phone.LABEL);
}
- public void computeFormattedPhoneNumber(String defaultCountryIso) {
+ public void computeFormattedPhoneNumber(Context context, String defaultCountryIso) {
final String phoneNumber = getNumber();
if (phoneNumber != null) {
final String formattedPhoneNumber =
- PhoneNumberUtilsCompat.formatNumber(
- phoneNumber, getNormalizedNumber(), defaultCountryIso);
+ PhoneNumberHelper.formatNumber(
+ context, phoneNumber, getNormalizedNumber(), defaultCountryIso);
getContentValues().put(KEY_FORMATTED_PHONE_NUMBER, formattedPhoneNumber);
}
}
diff --git a/java/com/android/contacts/common/util/ContactDisplayUtils.java b/java/com/android/contacts/common/util/ContactDisplayUtils.java
index a45394f50..7d428e102 100644
--- a/java/com/android/contacts/common/util/ContactDisplayUtils.java
+++ b/java/com/android/contacts/common/util/ContactDisplayUtils.java
@@ -21,13 +21,13 @@ import android.content.res.Resources;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
+import android.telephony.PhoneNumberUtils;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.TextUtils;
import android.text.style.TtsSpan;
import android.util.Patterns;
import com.android.contacts.common.R;
-import com.android.contacts.common.compat.PhoneNumberUtilsCompat;
import com.android.contacts.common.preference.ContactsPreferences;
import com.android.dialer.common.LogUtil;
import java.util.Objects;
@@ -219,7 +219,7 @@ public class ContactDisplayUtils {
int start = TextUtils.isEmpty(phoneNumber) ? -1 : message.indexOf(phoneNumber);
while (start >= 0) {
final int end = start + phoneNumber.length();
- final TtsSpan ttsSpan = PhoneNumberUtilsCompat.createTtsSpan(phoneNumber);
+ final TtsSpan ttsSpan = PhoneNumberUtils.createTtsSpan(phoneNumber);
spannable.setSpan(
ttsSpan,
start,
diff --git a/java/com/android/contacts/common/widget/SelectPhoneAccountDialogFragment.java b/java/com/android/contacts/common/widget/SelectPhoneAccountDialogFragment.java
index 07891a069..295aa963a 100644
--- a/java/com/android/contacts/common/widget/SelectPhoneAccountDialogFragment.java
+++ b/java/com/android/contacts/common/widget/SelectPhoneAccountDialogFragment.java
@@ -325,6 +325,7 @@ public class SelectPhoneAccountDialogFragment extends DialogFragment {
holder.numberTextView.setVisibility(View.VISIBLE);
holder.numberTextView.setText(
PhoneNumberHelper.formatNumberForDisplay(
+ getContext(),
account.getAddress().getSchemeSpecificPart(),
getCountryIso(getContext(), accountHandle)));
}
diff --git a/java/com/android/dialer/app/calllog/CallLogAdapter.java b/java/com/android/dialer/app/calllog/CallLogAdapter.java
index baca590b5..4b860fea1 100644
--- a/java/com/android/dialer/app/calllog/CallLogAdapter.java
+++ b/java/com/android/dialer/app/calllog/CallLogAdapter.java
@@ -52,7 +52,6 @@ import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import com.android.contacts.common.ContactsUtils;
-import com.android.contacts.common.compat.PhoneNumberUtilsCompat;
import com.android.contacts.common.preference.ContactsPreferences;
import com.android.dialer.app.DialtactsActivity;
import com.android.dialer.app.R;
@@ -1057,7 +1056,7 @@ public class CallLogAdapter extends GroupingListAdapter
CharSequence formattedNumber =
info.formattedNumber == null
? null
- : PhoneNumberUtilsCompat.createTtsSpannable(info.formattedNumber);
+ : PhoneNumberUtils.createTtsSpannable(info.formattedNumber);
details.updateDisplayNumber(activity, formattedNumber, isVoicemailNumber);
views.displayNumber = details.displayNumber;
diff --git a/java/com/android/dialer/app/calllog/CallLogListItemViewHolder.java b/java/com/android/dialer/app/calllog/CallLogListItemViewHolder.java
index 5c9411180..4c187faed 100644
--- a/java/com/android/dialer/app/calllog/CallLogListItemViewHolder.java
+++ b/java/com/android/dialer/app/calllog/CallLogListItemViewHolder.java
@@ -52,7 +52,6 @@ import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
-import com.android.contacts.common.compat.PhoneNumberUtilsCompat;
import com.android.contacts.common.dialog.CallSubjectDialog;
import com.android.dialer.app.DialtactsActivity;
import com.android.dialer.app.R;
@@ -1222,7 +1221,7 @@ public final class CallLogListItemViewHolder extends RecyclerView.ViewHolder
menu.setHeaderTitle(context.getResources().getText(R.string.voicemail));
} else {
menu.setHeaderTitle(
- PhoneNumberUtilsCompat.createTtsSpannable(
+ PhoneNumberUtils.createTtsSpannable(
BidiFormatter.getInstance().unicodeWrap(number, TextDirectionHeuristics.LTR)));
}
diff --git a/java/com/android/dialer/app/calllog/CallLogNotificationsQueryHelper.java b/java/com/android/dialer/app/calllog/CallLogNotificationsQueryHelper.java
index d20ddd0e5..3afb6bb87 100644
--- a/java/com/android/dialer/app/calllog/CallLogNotificationsQueryHelper.java
+++ b/java/com/android/dialer/app/calllog/CallLogNotificationsQueryHelper.java
@@ -43,6 +43,7 @@ import com.android.dialer.configprovider.ConfigProviderBindings;
import com.android.dialer.location.GeoUtil;
import com.android.dialer.phonenumbercache.ContactInfo;
import com.android.dialer.phonenumbercache.ContactInfoHelper;
+import com.android.dialer.phonenumberutil.PhoneNumberHelper;
import com.android.dialer.util.PermissionsUtil;
import java.util.ArrayList;
import java.util.Arrays;
@@ -199,7 +200,7 @@ public class CallLogNotificationsQueryHelper {
number = (number == null) ? "" : number;
ContactInfo contactInfo = new ContactInfo();
contactInfo.number = number;
- contactInfo.formattedNumber = PhoneNumberUtils.formatNumber(number, countryIso);
+ contactInfo.formattedNumber = PhoneNumberHelper.formatNumber(context, number, countryIso);
// contactInfo.normalizedNumber is not PhoneNumberUtils.normalizeNumber. Read ContactInfo.
contactInfo.normalizedNumber = PhoneNumberUtils.formatNumberToE164(number, countryIso);
diff --git a/java/com/android/dialer/app/calllog/LegacyVoicemailNotifier.java b/java/com/android/dialer/app/calllog/LegacyVoicemailNotifier.java
index 0ddfb9f3b..7b1536b37 100644
--- a/java/com/android/dialer/app/calllog/LegacyVoicemailNotifier.java
+++ b/java/com/android/dialer/app/calllog/LegacyVoicemailNotifier.java
@@ -27,14 +27,15 @@ import android.telecom.PhoneAccount;
import android.telecom.PhoneAccountHandle;
import android.telecom.TelecomManager;
import android.telephony.CarrierConfigManager;
-import android.telephony.PhoneNumberUtils;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import com.android.dialer.app.R;
import com.android.dialer.common.Assert;
import com.android.dialer.common.LogUtil;
+import com.android.dialer.location.GeoUtil;
import com.android.dialer.notification.DialerNotificationManager;
import com.android.dialer.notification.NotificationChannelManager;
+import com.android.dialer.phonenumberutil.PhoneNumberHelper;
import com.android.dialer.telecom.TelecomUtil;
/** Shows a notification in the status bar for legacy vociemail. */
@@ -144,7 +145,8 @@ public final class LegacyVoicemailNotifier {
} else {
return String.format(
context.getString(R.string.notification_voicemail_text_format),
- PhoneNumberUtils.formatNumber(voicemailNumber));
+ PhoneNumberHelper.formatNumber(
+ context, voicemailNumber, GeoUtil.getCurrentCountryIso(context)));
}
}
diff --git a/java/com/android/dialer/app/calllog/MissedCallNotifier.java b/java/com/android/dialer/app/calllog/MissedCallNotifier.java
index 14bbdfa56..80901ce88 100644
--- a/java/com/android/dialer/app/calllog/MissedCallNotifier.java
+++ b/java/com/android/dialer/app/calllog/MissedCallNotifier.java
@@ -36,12 +36,12 @@ import android.support.v4.util.Pair;
import android.telecom.PhoneAccount;
import android.telecom.PhoneAccountHandle;
import android.telecom.TelecomManager;
+import android.telephony.PhoneNumberUtils;
import android.text.BidiFormatter;
import android.text.TextDirectionHeuristics;
import android.text.TextUtils;
import android.util.ArraySet;
import com.android.contacts.common.ContactsUtils;
-import com.android.contacts.common.compat.PhoneNumberUtilsCompat;
import com.android.dialer.app.DialtactsActivity;
import com.android.dialer.app.MainComponent;
import com.android.dialer.app.R;
@@ -171,7 +171,7 @@ public class MissedCallNotifier implements Worker<Pair<Integer, String>, Void> {
if (TextUtils.equals(contactInfo.name, contactInfo.formattedNumber)
|| TextUtils.equals(contactInfo.name, contactInfo.number)) {
expandedText =
- PhoneNumberUtilsCompat.createTtsSpannable(
+ PhoneNumberUtils.createTtsSpannable(
BidiFormatter.getInstance()
.unicodeWrap(contactInfo.name, TextDirectionHeuristics.LTR));
} else {
@@ -328,7 +328,7 @@ public class MissedCallNotifier implements Worker<Pair<Integer, String>, Void> {
if (TextUtils.equals(contactInfo.name, contactInfo.formattedNumber)
|| TextUtils.equals(contactInfo.name, contactInfo.number)) {
expandedText =
- PhoneNumberUtilsCompat.createTtsSpannable(
+ PhoneNumberUtils.createTtsSpannable(
BidiFormatter.getInstance()
.unicodeWrap(contactInfo.name, TextDirectionHeuristics.LTR));
} else {
diff --git a/java/com/android/dialer/app/filterednumber/BlockedNumbersAdapter.java b/java/com/android/dialer/app/filterednumber/BlockedNumbersAdapter.java
index 4f8bc66a9..603c06fd3 100644
--- a/java/com/android/dialer/app/filterednumber/BlockedNumbersAdapter.java
+++ b/java/com/android/dialer/app/filterednumber/BlockedNumbersAdapter.java
@@ -18,7 +18,6 @@ package com.android.dialer.app.filterednumber;
import android.app.FragmentManager;
import android.content.Context;
import android.database.Cursor;
-import android.telephony.PhoneNumberUtils;
import android.view.View;
import com.android.dialer.app.R;
import com.android.dialer.blocking.BlockNumberDialogFragment;
@@ -28,6 +27,7 @@ import com.android.dialer.location.GeoUtil;
import com.android.dialer.logging.InteractionEvent;
import com.android.dialer.logging.Logger;
import com.android.dialer.phonenumbercache.ContactInfoHelper;
+import com.android.dialer.phonenumberutil.PhoneNumberHelper;
/** TODO(calderwoodra): documentation */
public class BlockedNumbersAdapter extends NumbersAdapter {
@@ -66,7 +66,7 @@ public class BlockedNumbersAdapter extends NumbersAdapter {
id,
number,
countryIso,
- PhoneNumberUtils.formatNumber(number, countryIso),
+ PhoneNumberHelper.formatNumber(getContext(), number, countryIso),
R.id.blocked_numbers_activity_container,
getFragmentManager(),
new BlockNumberDialogFragment.Callback() {
diff --git a/java/com/android/dialer/app/list/BlockedListSearchFragment.java b/java/com/android/dialer/app/list/BlockedListSearchFragment.java
index de9dbaee6..ce812af6e 100644
--- a/java/com/android/dialer/app/list/BlockedListSearchFragment.java
+++ b/java/com/android/dialer/app/list/BlockedListSearchFragment.java
@@ -19,7 +19,6 @@ import android.app.Activity;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
-import android.telephony.PhoneNumberUtils;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
@@ -39,6 +38,7 @@ import com.android.dialer.common.LogUtil;
import com.android.dialer.location.GeoUtil;
import com.android.dialer.logging.InteractionEvent;
import com.android.dialer.logging.Logger;
+import com.android.dialer.phonenumberutil.PhoneNumberHelper;
/** TODO(calderwoodra): documentation */
public class BlockedListSearchFragment extends RegularSearchFragment
@@ -174,7 +174,7 @@ public class BlockedListSearchFragment extends RegularSearchFragment
id,
number,
countryIso,
- PhoneNumberUtils.formatNumber(number, countryIso),
+ PhoneNumberHelper.formatNumber(getContext(), number, countryIso),
R.id.blocked_numbers_activity_container,
getFragmentManager(),
BlockedListSearchFragment.this);
diff --git a/java/com/android/dialer/app/list/DialerPhoneNumberListAdapter.java b/java/com/android/dialer/app/list/DialerPhoneNumberListAdapter.java
index 3711e6e75..d5609b856 100644
--- a/java/com/android/dialer/app/list/DialerPhoneNumberListAdapter.java
+++ b/java/com/android/dialer/app/list/DialerPhoneNumberListAdapter.java
@@ -31,6 +31,7 @@ import com.android.contacts.common.list.PhoneNumberListAdapter;
import com.android.contacts.common.util.ContactDisplayUtils;
import com.android.dialer.app.R;
import com.android.dialer.location.GeoUtil;
+import com.android.dialer.phonenumberutil.PhoneNumberHelper;
/**
* {@link PhoneNumberListAdapter} with the following added shortcuts, that are displayed as list
@@ -228,7 +229,8 @@ public class DialerPhoneNumberListAdapter extends PhoneNumberListAdapter {
@Override
public void setQueryString(String queryString) {
formattedQueryString =
- PhoneNumberUtils.formatNumber(PhoneNumberUtils.normalizeNumber(queryString), countryIso);
+ PhoneNumberHelper.formatNumber(
+ getContext(), PhoneNumberUtils.normalizeNumber(queryString), countryIso);
super.setQueryString(queryString);
}
}
diff --git a/java/com/android/dialer/calllogutils/PhoneNumberDisplayUtil.java b/java/com/android/dialer/calllogutils/PhoneNumberDisplayUtil.java
index f0f696396..6fe3a82c8 100644
--- a/java/com/android/dialer/calllogutils/PhoneNumberDisplayUtil.java
+++ b/java/com/android/dialer/calllogutils/PhoneNumberDisplayUtil.java
@@ -18,10 +18,10 @@ package com.android.dialer.calllogutils;
import android.content.Context;
import android.provider.CallLog.Calls;
+import android.telephony.PhoneNumberUtils;
import android.text.BidiFormatter;
import android.text.TextDirectionHeuristics;
import android.text.TextUtils;
-import com.android.contacts.common.compat.PhoneNumberUtilsCompat;
import com.android.dialer.phonenumberutil.PhoneNumberHelper;
import com.google.common.base.Optional;
@@ -86,8 +86,8 @@ public class PhoneNumberDisplayUtil {
}
/** Returns number annotated as phone number in LTR direction. */
- public static CharSequence getTtsSpannableLtrNumber(CharSequence number) {
- return PhoneNumberUtilsCompat.createTtsSpannable(
+ private static CharSequence getTtsSpannableLtrNumber(CharSequence number) {
+ return PhoneNumberUtils.createTtsSpannable(
BidiFormatter.getInstance().unicodeWrap(number.toString(), TextDirectionHeuristics.LTR));
}
}
diff --git a/java/com/android/dialer/dialpadview/DialpadFragment.java b/java/com/android/dialer/dialpadview/DialpadFragment.java
index f09333280..eeab6c428 100644
--- a/java/com/android/dialer/dialpadview/DialpadFragment.java
+++ b/java/com/android/dialer/dialpadview/DialpadFragment.java
@@ -88,6 +88,7 @@ import com.android.dialer.location.GeoUtil;
import com.android.dialer.logging.UiAction;
import com.android.dialer.oem.MotorolaUtils;
import com.android.dialer.performancereport.PerformanceReport;
+import com.android.dialer.phonenumberutil.PhoneNumberHelper;
import com.android.dialer.precall.PreCall;
import com.android.dialer.proguard.UsedByReflection;
import com.android.dialer.telecom.TelecomUtil;
@@ -220,8 +221,7 @@ public class DialpadFragment extends Fragment
* @return the provided string of digits as a formatted phone number, retaining any post-dial
* portion of the string.
*/
- @VisibleForTesting
- static String getFormattedDigits(String dialString, String normalizedNumber, String countryIso) {
+ String getFormattedDigits(String dialString, String normalizedNumber, String countryIso) {
String number = PhoneNumberUtils.extractNetworkPortion(dialString);
// Also retrieve the post dial portion of the provided data, so that the entire dial
// string can be reconstituted later.
@@ -231,7 +231,7 @@ public class DialpadFragment extends Fragment
return postDial;
}
- number = PhoneNumberUtils.formatNumber(number, normalizedNumber, countryIso);
+ number = PhoneNumberHelper.formatNumber(getContext(), number, normalizedNumber, countryIso);
if (TextUtils.isEmpty(postDial)) {
return number;
diff --git a/java/com/android/dialer/phonenumbercache/ContactInfoHelper.java b/java/com/android/dialer/phonenumbercache/ContactInfoHelper.java
index f094be8a5..01f9669cb 100644
--- a/java/com/android/dialer/phonenumbercache/ContactInfoHelper.java
+++ b/java/com/android/dialer/phonenumbercache/ContactInfoHelper.java
@@ -475,7 +475,7 @@ public class ContactInfoHelper {
if (TextUtils.isEmpty(countryIso)) {
countryIso = currentCountryIso;
}
- return PhoneNumberUtils.formatNumber(number, normalizedNumber, countryIso);
+ return PhoneNumberHelper.formatNumber(context, number, normalizedNumber, countryIso);
}
/**
diff --git a/java/com/android/dialer/phonenumberutil/PhoneNumberHelper.java b/java/com/android/dialer/phonenumberutil/PhoneNumberHelper.java
index b58739d94..f5e634670 100644
--- a/java/com/android/dialer/phonenumberutil/PhoneNumberHelper.java
+++ b/java/com/android/dialer/phonenumberutil/PhoneNumberHelper.java
@@ -35,6 +35,7 @@ import com.android.dialer.compat.CompatUtils;
import com.android.dialer.compat.telephony.TelephonyManagerCompat;
import com.android.dialer.phonenumbergeoutil.PhoneNumberGeoUtilComponent;
import com.android.dialer.telecom.TelecomUtil;
+import com.google.common.base.Ascii;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
@@ -224,28 +225,50 @@ public class PhoneNumberHelper {
}
/**
- * @return Formatted phone number. e.g. 1-123-456-7890. Returns the original number if formatting
- * failed.
+ * An enhanced version of {@link PhoneNumberUtils#formatNumber(String, String, String)}.
+ *
+ * <p>The {@link Context} parameter allows us to tweak formatting according to device properties.
+ *
+ * <p>Returns the formatted phone number (e.g, 1-123-456-7890) or the original number if
+ * formatting fails or is intentionally ignored.
*/
- public static String formatNumber(@Nullable String number, String countryIso) {
+ public static String formatNumber(
+ Context context, @Nullable String number, @Nullable String numberE164, String countryIso) {
// The number can be null e.g. schema is voicemail and uri content is empty.
if (number == null) {
return null;
}
- String formattedNumber = PhoneNumberUtils.formatNumber(number, countryIso);
+
+ // Argentina phone number formats are complex and PhoneNumberUtils doesn't format all Argentina
+ // numbers correctly.
+ // To ensure consistent user experience, we disable phone number formatting for all numbers
+ // (not just Argentinian ones) for devices with Argentinian SIMs.
+ TelephonyManager telephonyManager =
+ (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
+ if (telephonyManager != null
+ && "AR".equals(Ascii.toUpperCase(telephonyManager.getSimCountryIso()))) {
+ return number;
+ }
+
+ String formattedNumber = PhoneNumberUtils.formatNumber(number, numberE164, countryIso);
return formattedNumber != null ? formattedNumber : number;
}
+ /** @see #formatNumber(Context, String, String, String). */
+ public static String formatNumber(Context context, @Nullable String number, String countryIso) {
+ return formatNumber(context, number, /* numberE164 = */ null, countryIso);
+ }
+
@Nullable
public static CharSequence formatNumberForDisplay(
- @Nullable String number, @NonNull String countryIso) {
+ Context context, @Nullable String number, @NonNull String countryIso) {
if (number == null) {
return null;
}
return PhoneNumberUtils.createTtsSpannable(
BidiFormatter.getInstance()
- .unicodeWrap(formatNumber(number, countryIso), TextDirectionHeuristics.LTR));
+ .unicodeWrap(formatNumber(context, number, countryIso), TextDirectionHeuristics.LTR));
}
/**
diff --git a/java/com/android/dialer/speeddial/SuggestionViewHolder.java b/java/com/android/dialer/speeddial/SuggestionViewHolder.java
index 70df30706..68c0ce4c3 100644
--- a/java/com/android/dialer/speeddial/SuggestionViewHolder.java
+++ b/java/com/android/dialer/speeddial/SuggestionViewHolder.java
@@ -23,7 +23,6 @@ import android.net.Uri;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.provider.ContactsContract.Contacts;
import android.support.v7.widget.RecyclerView;
-import android.telephony.PhoneNumberUtils;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
@@ -32,6 +31,7 @@ import android.widget.TextView;
import com.android.dialer.contactphoto.ContactPhotoManager;
import com.android.dialer.lettertile.LetterTileDrawable;
import com.android.dialer.location.GeoUtil;
+import com.android.dialer.phonenumberutil.PhoneNumberHelper;
/** ViewHolder for displaying suggested contacts in {@link SpeedDialFragment}. */
public class SuggestionViewHolder extends RecyclerView.ViewHolder implements OnClickListener {
@@ -56,7 +56,7 @@ public class SuggestionViewHolder extends RecyclerView.ViewHolder implements OnC
public void bind(Context context, Cursor cursor) {
number = cursor.getString(StrequentContactsCursorLoader.PHONE_NUMBER);
- number = PhoneNumberUtils.formatNumber(number, GeoUtil.getCurrentCountryIso(context));
+ number = PhoneNumberHelper.formatNumber(context, number, GeoUtil.getCurrentCountryIso(context));
String name = cursor.getString(StrequentContactsCursorLoader.PHONE_DISPLAY_NAME);
String label = getLabel(context.getResources(), cursor);
diff --git a/java/com/android/incallui/CallCardPresenter.java b/java/com/android/incallui/CallCardPresenter.java
index c60da63d6..8eb07c579 100644
--- a/java/com/android/incallui/CallCardPresenter.java
+++ b/java/com/android/incallui/CallCardPresenter.java
@@ -483,7 +483,7 @@ public class CallCardPresenter
.setCallSubject(shouldShowCallSubject(primary) ? primary.getCallSubject() : null)
.setCallbackNumber(
PhoneNumberHelper.formatNumber(
- primary.getCallbackNumber(), primary.getSimCountryIso()))
+ context, primary.getCallbackNumber(), primary.getSimCountryIso()))
.setIsWifi(primary.hasProperty(Details.PROPERTY_WIFI))
.setIsConference(
primary.isConferenceCall()
diff --git a/java/com/android/incallui/ConferenceParticipantListAdapter.java b/java/com/android/incallui/ConferenceParticipantListAdapter.java
index d4579b1ed..4780974ef 100644
--- a/java/com/android/incallui/ConferenceParticipantListAdapter.java
+++ b/java/com/android/incallui/ConferenceParticipantListAdapter.java
@@ -20,6 +20,7 @@ import android.content.Context;
import android.net.Uri;
import android.support.annotation.Nullable;
import android.support.v4.util.ArrayMap;
+import android.telephony.PhoneNumberUtils;
import android.text.BidiFormatter;
import android.text.TextDirectionHeuristics;
import android.text.TextUtils;
@@ -32,7 +33,6 @@ import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
-import com.android.contacts.common.compat.PhoneNumberUtilsCompat;
import com.android.contacts.common.preference.ContactsPreferences;
import com.android.contacts.common.util.ContactDisplayUtils;
import com.android.dialer.common.LogUtil;
@@ -341,7 +341,7 @@ public class ConferenceParticipantListAdapter extends BaseAdapter {
} else {
numberTextView.setVisibility(View.VISIBLE);
numberTextView.setText(
- PhoneNumberUtilsCompat.createTtsSpannable(
+ PhoneNumberUtils.createTtsSpannable(
BidiFormatter.getInstance().unicodeWrap(callerNumber, TextDirectionHeuristics.LTR)));
}
}
diff --git a/java/com/android/incallui/ContactInfoCache.java b/java/com/android/incallui/ContactInfoCache.java
index d2ae70939..90513381e 100644
--- a/java/com/android/incallui/ContactInfoCache.java
+++ b/java/com/android/incallui/ContactInfoCache.java
@@ -214,7 +214,7 @@ public class ContactInfoCache implements OnImageLoadCompleteListener {
// No name, but we do have a valid CNAP name, so use that.
displayName = info.cnapName;
info.name = info.cnapName;
- displayNumber = PhoneNumberHelper.formatNumber(number, info.countryIso);
+ displayNumber = PhoneNumberHelper.formatNumber(context, number, info.countryIso);
Log.d(
TAG,
" ==> cnapName available: displayName '"
@@ -227,7 +227,7 @@ public class ContactInfoCache implements OnImageLoadCompleteListener {
// case when an incoming call doesn't match any contact,
// or if you manually dial an outgoing number using the
// dialpad.
- displayNumber = PhoneNumberHelper.formatNumber(number, info.countryIso);
+ displayNumber = PhoneNumberHelper.formatNumber(context, number, info.countryIso);
Log.d(
TAG,
@@ -252,7 +252,7 @@ public class ContactInfoCache implements OnImageLoadCompleteListener {
// later determine whether to use the name or nameAlternative when presenting
displayName = info.name;
cce.nameAlternative = info.nameAlternative;
- displayNumber = PhoneNumberHelper.formatNumber(number, info.countryIso);
+ displayNumber = PhoneNumberHelper.formatNumber(context, number, info.countryIso);
label = info.phoneLabel;
Log.d(
TAG,
diff --git a/java/com/android/incallui/DialpadFragment.java b/java/com/android/incallui/DialpadFragment.java
index c5b9d785f..44eaf212a 100644
--- a/java/com/android/incallui/DialpadFragment.java
+++ b/java/com/android/incallui/DialpadFragment.java
@@ -18,6 +18,7 @@ package com.android.incallui;
import android.content.Context;
import android.os.Bundle;
+import android.telephony.PhoneNumberUtils;
import android.util.ArrayMap;
import android.util.AttributeSet;
import android.view.KeyEvent;
@@ -29,7 +30,6 @@ import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
-import com.android.contacts.common.compat.PhoneNumberUtilsCompat;
import com.android.dialer.common.LogUtil;
import com.android.dialer.dialpadview.DialpadKeyButton;
import com.android.dialer.dialpadview.DialpadKeyButton.OnPressedListener;
@@ -199,7 +199,7 @@ public class DialpadFragment extends BaseFragment<DialpadPresenter, DialpadUi>
* @param text Text to set Dialpad EditText to.
*/
public void setDtmfText(String text) {
- dtmfDialerField.setText(PhoneNumberUtilsCompat.createTtsSpannable(text));
+ dtmfDialerField.setText(PhoneNumberUtils.createTtsSpannable(text));
}
/** Starts the slide up animation for the Dialpad keys when the Dialpad is revealed. */
diff --git a/java/com/android/incallui/contactgrid/ContactGridManager.java b/java/com/android/incallui/contactgrid/ContactGridManager.java
index 1b76958dc..327eaf2b8 100644
--- a/java/com/android/incallui/contactgrid/ContactGridManager.java
+++ b/java/com/android/incallui/contactgrid/ContactGridManager.java
@@ -22,6 +22,7 @@ import android.graphics.drawable.Drawable;
import android.os.SystemClock;
import android.support.annotation.Nullable;
import android.support.v4.view.ViewCompat;
+import android.telephony.PhoneNumberUtils;
import android.text.TextUtils;
import android.view.View;
import android.view.accessibility.AccessibilityEvent;
@@ -30,7 +31,6 @@ import android.widget.ImageView;
import android.widget.Space;
import android.widget.TextView;
import android.widget.ViewAnimator;
-import com.android.contacts.common.compat.PhoneNumberUtilsCompat;
import com.android.dialer.common.Assert;
import com.android.dialer.common.LogUtil;
import com.android.dialer.lettertile.LetterTileDrawable;
@@ -276,7 +276,7 @@ public class ContactGridManager {
} else {
contactNameTextView.setText(
primaryInfo.nameIsNumber()
- ? PhoneNumberUtilsCompat.createTtsSpannable(primaryInfo.name())
+ ? PhoneNumberUtils.createTtsSpannable(primaryInfo.name())
: primaryInfo.name());
// Set direction of the name field
diff --git a/java/com/android/incallui/spam/SpamCallListListener.java b/java/com/android/incallui/spam/SpamCallListListener.java
index c7fa498e1..22b383332 100644
--- a/java/com/android/incallui/spam/SpamCallListListener.java
+++ b/java/com/android/incallui/spam/SpamCallListListener.java
@@ -34,7 +34,6 @@ import android.support.v4.os.BuildCompat;
import android.telecom.DisconnectCause;
import android.telephony.PhoneNumberUtils;
import android.text.TextUtils;
-import com.android.contacts.common.compat.PhoneNumberUtilsCompat;
import com.android.dialer.blocking.FilteredNumberCompat;
import com.android.dialer.blocking.FilteredNumbersUtil;
import com.android.dialer.common.Assert;
@@ -47,6 +46,7 @@ import com.android.dialer.logging.DialerImpression;
import com.android.dialer.logging.Logger;
import com.android.dialer.notification.DialerNotificationManager;
import com.android.dialer.notification.NotificationChannelId;
+import com.android.dialer.phonenumberutil.PhoneNumberHelper;
import com.android.dialer.spam.SpamComponent;
import com.android.dialer.telecom.TelecomUtil;
import com.android.dialer.util.PermissionsUtil;
@@ -267,8 +267,9 @@ public class SpamCallListListener implements CallList.Listener {
private CharSequence getDisplayNumber(DialerCall call) {
String formattedNumber =
- PhoneNumberUtils.formatNumber(call.getNumber(), GeoUtil.getCurrentCountryIso(context));
- return PhoneNumberUtilsCompat.createTtsSpannable(formattedNumber);
+ PhoneNumberHelper.formatNumber(
+ context, call.getNumber(), GeoUtil.getCurrentCountryIso(context));
+ return PhoneNumberUtils.createTtsSpannable(formattedNumber);
}
/** Display a notification with two actions: "add contact" and "report spam". */
diff --git a/java/com/android/incallui/spam/SpamNotificationActivity.java b/java/com/android/incallui/spam/SpamNotificationActivity.java
index 6ba7c30f8..8919dc713 100644
--- a/java/com/android/incallui/spam/SpamNotificationActivity.java
+++ b/java/com/android/incallui/spam/SpamNotificationActivity.java
@@ -27,7 +27,6 @@ import android.provider.CallLog;
import android.provider.ContactsContract;
import android.support.v4.app.FragmentActivity;
import android.telephony.PhoneNumberUtils;
-import com.android.contacts.common.compat.PhoneNumberUtilsCompat;
import com.android.dialer.blocking.BlockedNumbersMigrator;
import com.android.dialer.blocking.FilteredNumberAsyncQueryHandler;
import com.android.dialer.blocking.FilteredNumberCompat;
@@ -39,6 +38,7 @@ import com.android.dialer.logging.DialerImpression;
import com.android.dialer.logging.Logger;
import com.android.dialer.logging.ReportingLocation;
import com.android.dialer.notification.DialerNotificationManager;
+import com.android.dialer.phonenumberutil.PhoneNumberHelper;
import com.android.dialer.spam.SpamComponent;
import com.android.incallui.call.DialerCall;
@@ -109,8 +109,8 @@ public class SpamNotificationActivity extends FragmentActivity {
/** Returns the formatted version of the given number. */
private static String getFormattedNumber(String number, Context context) {
String formattedNumber =
- PhoneNumberUtils.formatNumber(number, GeoUtil.getCurrentCountryIso(context));
- return PhoneNumberUtilsCompat.createTtsSpannable(formattedNumber).toString();
+ PhoneNumberHelper.formatNumber(context, number, GeoUtil.getCurrentCountryIso(context));
+ return PhoneNumberUtils.createTtsSpannable(formattedNumber).toString();
}
private void logCallImpression(DialerImpression.Type impression) {