Index: chrome/android/java/src/org/chromium/chrome/browser/payments/AddressEditor.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/payments/AddressEditor.java b/chrome/android/java/src/org/chromium/chrome/browser/payments/AddressEditor.java |
index 804186b826fa310271e1c379236ff673cd97a597..0929e9152b7ed9481aa4d8014be0a42a2d74608f 100644 |
--- a/chrome/android/java/src/org/chromium/chrome/browser/payments/AddressEditor.java |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/payments/AddressEditor.java |
@@ -6,6 +6,7 @@ package org.chromium.chrome.browser.payments; |
import android.app.ProgressDialog; |
import android.os.Handler; |
+import android.text.TextUtils; |
import android.util.Pair; |
import org.chromium.base.Callback; |
@@ -57,11 +58,15 @@ public class AddressEditor |
/** |
* Adds the given phone number to the autocomplete set, if it's valid. |
+ * Note that here we consider all non-null and non-empty numbers as valid |
+ * since we are doing strict validation of Autofill data. |
* |
* @param phoneNumber The phone number to possibly add. |
*/ |
public void addPhoneNumberIfValid(@Nullable CharSequence phoneNumber) { |
- if (getPhoneValidator().isValid(phoneNumber)) mPhoneNumbers.add(phoneNumber); |
+ if (TextUtils.isEmpty(phoneNumber)) { |
+ mPhoneNumbers.add(phoneNumber.toString()); |
+ } |
} |
/** |
@@ -123,6 +128,7 @@ public class AddressEditor |
mEditor.removeAllFields(); |
showProgressDialog(); |
mRecentlySelectedCountry = eventData.first; |
+ mEditorDialog.updateCountryOfPhoneFormatter(mRecentlySelectedCountry); |
mCountryChangeCallback = eventData.second; |
loadAdminAreasForCountry(mRecentlySelectedCountry); |
} |
@@ -131,6 +137,7 @@ public class AddressEditor |
// Country dropdown is cached, so the selected item needs to be updated for the new profile |
// that's being edited. This will not fire the dropdown callback. |
mCountryField.setValue(AutofillAddress.getCountryCode(mProfile)); |
+ mEditorDialog.updateCountryOfPhoneFormatter(mCountryField.getValue().toString()); |
// There's a finite number of fields for address editing. Changing the country will re-order |
// and relabel the fields. The meaning of each field remains the same. |
@@ -161,7 +168,7 @@ public class AddressEditor |
if (mPhoneField == null) { |
mPhoneField = EditorFieldModel.createTextInput(EditorFieldModel.INPUT_TYPE_HINT_PHONE, |
mContext.getString(R.string.autofill_profile_editor_phone_number), |
- mPhoneNumbers, getPhoneValidator(), null, |
+ mPhoneNumbers, getPhoneValidator(mCountryField), null, |
mContext.getString(R.string.payments_field_required_validation_message), |
mContext.getString(R.string.payments_phone_invalid_validation_message), null); |
} |
@@ -390,12 +397,17 @@ public class AddressEditor |
mEditor.addField(mPhoneField); |
} |
- private EditorFieldValidator getPhoneValidator() { |
+ private EditorFieldValidator getPhoneValidator(final EditorFieldModel countryCodeField) { |
if (mPhoneValidator == null) { |
mPhoneValidator = new EditorFieldValidator() { |
@Override |
public boolean isValid(@Nullable CharSequence value) { |
- return value != null && PhoneNumberUtil.isValidNumber(value.toString()); |
+ String countryToValidateAgainst = (countryCodeField.getValue() == null) |
+ ? null |
+ : countryCodeField.getValue().toString(); |
+ return value != null |
+ && PhoneNumberUtil.isValidNumber( |
+ value.toString(), countryToValidateAgainst); |
} |
@Override |