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

Commit b500efc0 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge changes Ie04496dc,Ib2998f03,I6cf53e50,Id6eaaad2

* changes:
  Delete voicemails when disabling visual voicemail
  Switching to alarms and exponential backoff while polling for transcription result
  Format number for SIM selection
  Disable phone number formatting on the dialpad when making domestic call to Argentina mobile numbers.
parents 0e029e7f b9ca335d
Loading
Loading
Loading
Loading
+19 −3
Original line number Diff line number Diff line
@@ -25,11 +25,13 @@ import android.content.DialogInterface;
import android.os.Bundle;
import android.os.Handler;
import android.os.ResultReceiver;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.VisibleForTesting;
import android.telecom.PhoneAccount;
import android.telecom.PhoneAccountHandle;
import android.telecom.TelecomManager;
import android.telephony.SubscriptionInfo;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
@@ -43,7 +45,10 @@ import android.widget.ListAdapter;
import android.widget.TextView;
import com.android.contacts.common.R;
import com.android.contacts.common.compat.PhoneAccountCompat;
import com.android.contacts.common.compat.PhoneNumberUtilsCompat;
import com.android.dialer.location.GeoUtil;
import com.android.dialer.phonenumberutil.PhoneNumberHelper;
import com.android.dialer.telecom.TelecomUtil;
import com.google.common.base.Optional;
import java.util.ArrayList;
import java.util.List;

@@ -319,8 +324,9 @@ public class SelectPhoneAccountDialogFragment extends DialogFragment {
      } else {
        holder.numberTextView.setVisibility(View.VISIBLE);
        holder.numberTextView.setText(
            PhoneNumberUtilsCompat.createTtsSpannable(
                account.getAddress().getSchemeSpecificPart()));
            PhoneNumberHelper.formatNumberForDisplay(
                account.getAddress().getSchemeSpecificPart(),
                getCountryIso(getContext(), accountHandle)));
      }
      holder.imageView.setImageDrawable(
          PhoneAccountCompat.createIconDrawable(account, getContext()));
@@ -339,6 +345,16 @@ public class SelectPhoneAccountDialogFragment extends DialogFragment {
      return rowView;
    }

    private static String getCountryIso(
        Context context, @NonNull PhoneAccountHandle phoneAccountHandle) {
      Optional<SubscriptionInfo> info =
          TelecomUtil.getSubscriptionInfo(context, phoneAccountHandle);
      if (!info.isPresent()) {
        return GeoUtil.getCurrentCountryIso(context);
      }
      return info.get().getCountryIso().toUpperCase();
    }

    private static final class ViewHolder {

      TextView labelTextView;
+198 −13
Original line number Diff line number Diff line
@@ -89,8 +89,11 @@ import com.android.dialer.telecom.TelecomUtil;
import com.android.dialer.util.CallUtil;
import com.android.dialer.util.PermissionsUtil;
import com.android.dialer.widget.FloatingActionButtonController;
import com.google.common.base.Optional;
import java.util.HashSet;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/** Fragment that displays a twelve-key phone dialpad. */
public class DialpadFragment extends Fragment
@@ -129,6 +132,9 @@ public class DialpadFragment extends Fragment
  private static final String EXTRA_SEND_EMPTY_FLASH = "com.android.phone.extra.SEND_EMPTY_FLASH";

  private static final String PREF_DIGITS_FILLED_BY_INTENT = "pref_digits_filled_by_intent";

  private static Optional<String> currentCountryIsoForTesting = Optional.absent();

  private final Object mToneGeneratorLock = new Object();
  /** Set of dialpad keys that are currently being pressed */
  private final HashSet<View> mPressedDialpadKeys = new HashSet<>(12);
@@ -156,7 +162,6 @@ public class DialpadFragment extends Fragment

  // determines if we want to playback local DTMF tones.
  private boolean mDTMFToneEnabled;
  private String mCurrentCountryIso;
  private CallStateReceiver mCallStateReceiver;
  private boolean mWasEmptyBeforeTextChange;
  /**
@@ -324,8 +329,6 @@ public class DialpadFragment extends Fragment

    mFirstLaunch = state == null;

    mCurrentCountryIso = GeoUtil.getCurrentCountryIso(getActivity());

    mProhibitedPhoneNumberRegexp =
        getResources().getString(R.string.config_prohibited_phone_number_regexp);

@@ -377,8 +380,7 @@ public class DialpadFragment extends Fragment
    mDigits.addTextChangedListener(this);
    mDigits.setElegantTextHeight(false);

    initPhoneNumberFormattingTextWatcherExecutor.executeSerial(
        GeoUtil.getCurrentCountryIso(getActivity()));
    initPhoneNumberFormattingTextWatcherExecutor.executeSerial(getCurrentCountryIso());

    // Check for the presence of the keypad
    View oneButton = fragmentView.findViewById(R.id.one);
@@ -422,6 +424,19 @@ public class DialpadFragment extends Fragment
    return fragmentView;
  }

  private String getCurrentCountryIso() {
    if (currentCountryIsoForTesting.isPresent()) {
      return currentCountryIsoForTesting.get();
    }

    return GeoUtil.getCurrentCountryIso(getActivity());
  }

  @VisibleForTesting(otherwise = VisibleForTesting.NONE)
  public static void setCurrentCountryIsoForTesting(String countryCode) {
    currentCountryIsoForTesting = Optional.of(countryCode);
  }

  private boolean isLayoutReady() {
    return mDigits != null;
  }
@@ -561,7 +576,7 @@ public class DialpadFragment extends Fragment

  /** Sets formatted digits to digits field. */
  private void setFormattedDigits(String data, String normalizedNumber) {
    final String formatted = getFormattedDigits(data, normalizedNumber, mCurrentCountryIso);
    final String formatted = getFormattedDigits(data, normalizedNumber, getCurrentCountryIso());
    if (!TextUtils.isEmpty(formatted)) {
      Editable digits = mDigits.getText();
      digits.replace(0, digits.length(), formatted);
@@ -1717,19 +1732,189 @@ public class DialpadFragment extends Fragment
  }

  /**
   * Input: the ISO 3166-1 two letters country code of the country the user is in
   * A worker that helps formatting the phone number as the user types it in.
   *
   * <p>Output: PhoneNumberFormattingTextWatcher. Note: It is unusual to return a non-data value
   * from a worker, but it is a limitation in libphonenumber API that the watcher cannot be
   * initialized on the main thread.
   * <p>Input: the ISO 3166-1 two-letter country code of the country the user is in.
   *
   * <p>Output: an instance of {@link DialerPhoneNumberFormattingTextWatcher}. Note: It is unusual
   * to return a non-data value from a worker. But {@link DialerPhoneNumberFormattingTextWatcher}
   * depends on libphonenumber API, which cannot be initialized on the main thread.
   */
  private static class InitPhoneNumberFormattingTextWatcherWorker
      implements Worker<String, PhoneNumberFormattingTextWatcher> {
      implements Worker<String, DialerPhoneNumberFormattingTextWatcher> {

    @Nullable
    @Override
    public PhoneNumberFormattingTextWatcher doInBackground(@Nullable String countryCode) {
      return new PhoneNumberFormattingTextWatcher(countryCode);
    public DialerPhoneNumberFormattingTextWatcher doInBackground(@Nullable String countryCode) {
      return new DialerPhoneNumberFormattingTextWatcher(countryCode);
    }
  }

  /**
   * An extension of Android telephony's {@link PhoneNumberFormattingTextWatcher}. This watcher
   * skips formatting Argentina mobile numbers for domestic calls.
   *
   * <p>As of Nov. 28, 2017, the as-you-type-formatting provided by libphonenumber's
   * AsYouTypeFormatter (which {@link PhoneNumberFormattingTextWatcher} depends on) can't correctly
   * format Argentina mobile numbers for domestic calls (a bug). We temporarily disable the
   * formatting for such numbers until libphonenumber is fixed (which will come as early as the next
   * Android release).
   */
  @VisibleForTesting
  public static class DialerPhoneNumberFormattingTextWatcher
      extends PhoneNumberFormattingTextWatcher {
    private static final Pattern AR_DOMESTIC_CALL_MOBILE_NUMBER_PATTERN;

    // This static initialization block builds a pattern for domestic calls to Argentina mobile
    // numbers:
    // (1) Local calls: 15 <local number>
    // (2) Long distance calls: <area code> 15 <local number>
    // See https://en.wikipedia.org/wiki/Telephone_numbers_in_Argentina for detailed explanations.
    static {
      String regex =
          "0?("
              + "  ("
              + "   11|"
              + "   2("
              + "     2("
              + "       02?|"
              + "       [13]|"
              + "       2[13-79]|"
              + "       4[1-6]|"
              + "       5[2457]|"
              + "       6[124-8]|"
              + "       7[1-4]|"
              + "       8[13-6]|"
              + "       9[1267]"
              + "     )|"
              + "     3("
              + "       02?|"
              + "       1[467]|"
              + "       2[03-6]|"
              + "       3[13-8]|"
              + "       [49][2-6]|"
              + "       5[2-8]|"
              + "       [67]"
              + "     )|"
              + "     4("
              + "       7[3-578]|"
              + "       9"
              + "     )|"
              + "     6("
              + "       [0136]|"
              + "       2[24-6]|"
              + "       4[6-8]?|"
              + "       5[15-8]"
              + "     )|"
              + "     80|"
              + "     9("
              + "       0[1-3]|"
              + "       [19]|"
              + "       2\\d|"
              + "       3[1-6]|"
              + "       4[02568]?|"
              + "       5[2-4]|"
              + "       6[2-46]|"
              + "       72?|"
              + "       8[23]?"
              + "     )"
              + "   )|"
              + "   3("
              + "     3("
              + "       2[79]|"
              + "       6|"
              + "       8[2578]"
              + "     )|"
              + "     4("
              + "       0[0-24-9]|"
              + "       [12]|"
              + "       3[5-8]?|"
              + "       4[24-7]|"
              + "       5[4-68]?|"
              + "       6[02-9]|"
              + "       7[126]|"
              + "       8[2379]?|"
              + "       9[1-36-8]"
              + "     )|"
              + "     5("
              + "       1|"
              + "       2[1245]|"
              + "       3[237]?|"
              + "       4[1-46-9]|"
              + "       6[2-4]|"
              + "       7[1-6]|"
              + "       8[2-5]?"
              + "     )|"
              + "     6[24]|"
              + "     7("
              + "       [069]|"
              + "       1[1568]|"
              + "       2[15]|"
              + "       3[145]|"
              + "       4[13]|"
              + "       5[14-8]|"
              + "       7[2-57]|"
              + "       8[126]"
              + "     )|"
              + "     8("
              + "       [01]|"
              + "       2[15-7]|"
              + "       3[2578]?|"
              + "       4[13-6]|"
              + "       5[4-8]?|"
              + "       6[1-357-9]|"
              + "       7[36-8]?|"
              + "       8[5-8]?|"
              + "       9[124]"
              + "     )"
              + "   )"
              + " )?15"
              + ").*";
      AR_DOMESTIC_CALL_MOBILE_NUMBER_PATTERN = Pattern.compile(regex.replaceAll("\\s+", ""));
    }

    private final String countryCode;

    DialerPhoneNumberFormattingTextWatcher(String countryCode) {
      super(countryCode);
      this.countryCode = countryCode;
    }

    @Override
    public synchronized void afterTextChanged(Editable s) {
      super.afterTextChanged(s);

      if (!"AR".equals(countryCode)) {
        return;
      }

      String rawNumber = getRawNumber(s);

      // As modifying the input will trigger another call to afterTextChanged(Editable), we must
      // check whether the input's format has already been removed and return if it has
      // been to avoid infinite recursion.
      if (rawNumber.contentEquals(s)) {
        return;
      }

      Matcher matcher = AR_DOMESTIC_CALL_MOBILE_NUMBER_PATTERN.matcher(rawNumber);
      if (matcher.matches()) {
        s.replace(0, s.length(), rawNumber);
        PhoneNumberUtils.addTtsSpan(s, 0 /* start */, s.length() /* endExclusive */);
      }
    }

    private static String getRawNumber(Editable s) {
      StringBuilder rawNumberBuilder = new StringBuilder();

      for (int i = 0; i < s.length(); i++) {
        char c = s.charAt(i);
        if (PhoneNumberUtils.isNonSeparator(c)) {
          rawNumberBuilder.append(c);
        }
      }

      return rawNumberBuilder.toString();
    }
  }
}
+14 −0
Original line number Diff line number Diff line
@@ -26,6 +26,8 @@ import android.support.annotation.Nullable;
import android.telecom.PhoneAccountHandle;
import android.telephony.PhoneNumberUtils;
import android.telephony.TelephonyManager;
import android.text.BidiFormatter;
import android.text.TextDirectionHeuristics;
import android.text.TextUtils;
import android.util.SparseIntArray;
import com.android.dialer.common.Assert;
@@ -337,6 +339,18 @@ public class PhoneNumberHelper {
    return formattedNumber != null ? formattedNumber : number;
  }

  @Nullable
  public static CharSequence formatNumberForDisplay(
      @Nullable String number, @NonNull String countryIso) {
    if (number == null) {
      return null;
    }

    return PhoneNumberUtils.createTtsSpannable(
        BidiFormatter.getInstance()
            .unicodeWrap(formatNumber(number, countryIso), TextDirectionHeuristics.LTR));
  }

  /**
   * Determines if the specified number is actually a URI (i.e. a SIP address) rather than a regular
   * PSTN phone number, based on whether or not the number contains an "@" character.
+52 −9
Original line number Diff line number Diff line
@@ -14,6 +14,8 @@
package com.android.dialer.voicemail.settings;

import android.annotation.TargetApi;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Build.VERSION_CODES;
import android.os.Bundle;
@@ -226,16 +228,13 @@ public class VoicemailSettingsFragment extends PreferenceFragment
    LogUtil.d(TAG, "onPreferenceChange: \"" + preference + "\" changed to \"" + objValue + "\"");
    if (preference.getKey().equals(voicemailVisualVoicemail.getKey())) {
      boolean isEnabled = (boolean) objValue;
      voicemailClient.setVoicemailEnabled(getContext(), phoneAccountHandle, isEnabled);

      if (isEnabled) {
        Logger.get(getContext()).logImpression(DialerImpression.Type.VVM_USER_ENABLED_IN_SETTINGS);
      if (!isEnabled) {
        showDisableConfirmationDialog();
        // Don't let the preference setting proceed.
        return false;
      } else {
        Logger.get(getContext()).logImpression(DialerImpression.Type.VVM_USER_DISABLED_IN_SETTINGS);
        updateVoicemailEnabled(true);
      }

      updateChangePin();
      updateDonateVoicemail();
    } else if (preference.getKey().equals(autoArchiveSwitchPreference.getKey())) {
      logArchiveToggle((boolean) objValue);
      voicemailClient.setVoicemailArchiveEnabled(
@@ -246,10 +245,24 @@ public class VoicemailSettingsFragment extends PreferenceFragment
          getContext(), phoneAccountHandle, (boolean) objValue);
    }

    // Always let the preference setting proceed.
    // Let the preference setting proceed.
    return true;
  }

  private void updateVoicemailEnabled(boolean isEnabled) {
    voicemailClient.setVoicemailEnabled(getContext(), phoneAccountHandle, isEnabled);
    voicemailVisualVoicemail.setChecked(isEnabled);

    if (isEnabled) {
      Logger.get(getContext()).logImpression(DialerImpression.Type.VVM_USER_ENABLED_IN_SETTINGS);
    } else {
      Logger.get(getContext()).logImpression(DialerImpression.Type.VVM_USER_DISABLED_IN_SETTINGS);
    }

    updateChangePin();
    updateDonateVoicemail();
  }

  private void updateChangePin() {
    if (!voicemailClient.isVoicemailEnabled(getContext(), phoneAccountHandle)) {
      voicemailChangePinPreference.setSummary(
@@ -305,4 +318,34 @@ public class VoicemailSettingsFragment extends PreferenceFragment
        .putExtra(Settings.EXTRA_CHANNEL_ID, channelId)
        .putExtra(Settings.EXTRA_APP_PACKAGE, getContext().getPackageName());
  }

  private void showDisableConfirmationDialog() {
    LogUtil.i(TAG, "showDisableConfirmationDialog");
    AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
    builder.setTitle(R.string.confirm_disable_voicemail_dialog_title);
    builder.setMessage(R.string.confirm_disable_voicemail_dialog_message);
    builder.setPositiveButton(
        R.string.confirm_disable_voicemail_accept_dialog_label,
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {
            LogUtil.i(TAG, "showDisableConfirmationDialog, confirmed");
            updateVoicemailEnabled(false);
            dialog.dismiss();
          }
        });

    builder.setNegativeButton(
        android.R.string.cancel,
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {
            LogUtil.i(TAG, "showDisableConfirmationDialog, cancelled");
            dialog.dismiss();
          }
        });

    builder.setCancelable(true);
    builder.show();
  }
}
+7 −0
Original line number Diff line number Diff line
@@ -118,4 +118,11 @@
  <!-- Summary information for visual voicemail donation setting [CHAR LIMIT=NONE] -->
  <string name="voicemail_donate_preference_summary_info">Let Google review your voicemail messages to improve transcription quality</string>

  <!-- Title for disable visual voicemail confirmation dialog [CHAR LIMIT=40] -->
  <string name="confirm_disable_voicemail_dialog_title">Turn off visual voicemail</string>
  <!-- Message explaining the implictions of disabling visual voicemail [CHAR LIMIT=NONE] -->
  <string name="confirm_disable_voicemail_dialog_message">This will delete any voicemail and Google transcripts stored within this app. Your carrier may keep its own copies.</string>
  <!-- The label for the confirm-disable-voicemail button [CHAR LIMIT=16] -->
  <string name="confirm_disable_voicemail_accept_dialog_label">TURN OFF</string>

</resources>
Loading