Skip to content

Commit d2c7ed7

Browse files
authored
Remove phone number validation on the client side (#840)
1 parent 145f789 commit d2c7ed7

File tree

2 files changed

+10
-40
lines changed

2 files changed

+10
-40
lines changed

auth/src/main/java/com/firebase/ui/auth/ui/phone/PhoneNumberUtils.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,6 @@ static void load() {
7070
*/
7171
@Nullable
7272
static String formatPhoneNumber(@NonNull String phoneNumber, @NonNull CountryInfo countryInfo) {
73-
74-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
75-
return android.telephony.PhoneNumberUtils
76-
.formatNumberToE164(phoneNumber, countryInfo.locale.getCountry());
77-
}
7873
return phoneNumber.startsWith("+")
7974
? phoneNumber
8075
: ("+" + String.valueOf(countryInfo.countryCode)
@@ -93,6 +88,16 @@ static String formatPhoneNumber(@NonNull String phoneNumber, @NonNull CountryInf
9388
static String formatPhoneNumberUsingCurrentCountry(
9489
@NonNull String phoneNumber, Context context) {
9590
final CountryInfo currentCountry = PhoneNumberUtils.getCurrentCountryInfo(context);
91+
92+
// TODO(samstern): Remove this call once the next version of Play servics is released
93+
// estimated timelime August 10th. It is a known issue that phone numbers
94+
// from the hint selector are susceptible to the false negatives of this
95+
// method.
96+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
97+
return android.telephony.PhoneNumberUtils
98+
.formatNumberToE164(phoneNumber, currentCountry.locale.getCountry());
99+
}
100+
96101
return formatPhoneNumber(phoneNumber, currentCountry);
97102
}
98103

auth/src/test/java/com/firebase/ui/auth/ui/phone/PhoneNumberUtilsTest.java

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import static com.firebase.ui.auth.ui.phone.PhoneNumberUtils.getPhoneNumber;
3737
import static com.firebase.ui.auth.ui.phone.PhoneTestConstants.RAW_PHONE;
3838
import static org.junit.Assert.assertEquals;
39-
import static org.junit.Assert.assertNull;
4039
import static org.mockito.Mockito.mock;
4140
import static org.mockito.Mockito.when;
4241

@@ -83,40 +82,6 @@ public void testGetCountryCode() throws Exception {
8382
assertEquals(null, getCountryCode(new Locale("", "DJJZ").getCountry()));
8483
}
8584

86-
@Test
87-
@Config(constants = BuildConfig.class, sdk = 21)
88-
public void testFormatNumberToE164_aboveApi21() {
89-
String validPhoneNumber = "+919994947354";
90-
CountryInfo indiaCountryInfo = new CountryInfo(new Locale("", "IN"), 91);
91-
//no leading plus
92-
assertEquals(validPhoneNumber, formatPhoneNumber("9994947354", indiaCountryInfo));
93-
//no country code
94-
assertEquals(validPhoneNumber, formatPhoneNumber("919994947354", indiaCountryInfo));
95-
//fully formatted
96-
assertEquals(validPhoneNumber, formatPhoneNumber("+919994947354", indiaCountryInfo));
97-
//with hyphens
98-
assertEquals(validPhoneNumber, formatPhoneNumber("+91-(999)-(49)-(47354)", indiaCountryInfo));
99-
//with spaces leading plus
100-
assertEquals(validPhoneNumber, formatPhoneNumber("+91 99949 47354", indiaCountryInfo));
101-
// space formatting
102-
assertEquals(validPhoneNumber, formatPhoneNumber("91 99949 47354", indiaCountryInfo));
103-
// parantheses and hyphens
104-
assertEquals(validPhoneNumber, formatPhoneNumber("(99949) 47-354", indiaCountryInfo));
105-
// mismatched country
106-
assertEquals(validPhoneNumber, formatPhoneNumber("+919994947354",
107-
new CountryInfo(
108-
new Locale("", "US"), 1)));
109-
// incorrect country with well formatted number
110-
assertNull(formatPhoneNumber("999474735", indiaCountryInfo));
111-
112-
// incorrect country with unformattednumber
113-
assertNull(validPhoneNumber, formatPhoneNumber(
114-
"919994947354", new CountryInfo(new Locale("", "US"), 1)));
115-
//incorrect country, incorrect phone number
116-
assertNull(formatPhoneNumber("+914349873457", new CountryInfo(
117-
new Locale("", "US"), 1)));
118-
}
119-
12085
@Test
12186
@Config(constants = BuildConfig.class, sdk = 16)
12287
public void testFormatNumberToE164_belowApi21() {

0 commit comments

Comments
 (0)