Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b06d0092 authored by linyuh's avatar linyuh Committed by Copybara-Service
Browse files

Disable phone number formatting for devices with Argentinian SIMs.

Bug: 73718977
Test: PhoneNumberHelperTest
PiperOrigin-RevId: 187540382
Change-Id: I814ec62b2215c24b8cde3442c5dc83d98ad87164
parent 9bd89a30
Loading
Loading
Loading
Loading
+0 −46
Original line number Diff line number Diff line
/*
 * 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);
  }
}
+3 −4
Original line number Diff line number Diff line
@@ -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.
+1 −1
Original line number Diff line number Diff line
@@ -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);
        }
      }
    }
+6 −6
Original line number Diff line number Diff line
@@ -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);
    }
  }
+2 −2
Original line number Diff line number Diff line
@@ -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,
Loading