Allow call to phone numbers or voice mail numbers only am: 8b347325fa am: d067695cd8

Original change: https://android-review.googlesource.com/c/platform/packages/apps/Messaging/+/1331094

Change-Id: I4310dfdbf854572427d43d87a4c31702a36a1598
This commit is contained in:
Taesu Lee
2020-06-11 19:16:35 +00:00
committed by Automerger Merge Worker
2 changed files with 18 additions and 14 deletions
@@ -700,7 +700,7 @@ public class ConversationData extends BindableData {
final ParticipantData participant = this.getOtherParticipant(); final ParticipantData participant = this.getOtherParticipant();
if (participant != null) { if (participant != null) {
final String phoneNumber = participant.getSendDestination(); final String phoneNumber = participant.getSendDestination();
if (!TextUtils.isEmpty(phoneNumber) && MmsSmsUtils.isDialable(phoneNumber)) { if (!TextUtils.isEmpty(phoneNumber) && MmsSmsUtils.isPhoneNumber(phoneNumber)) {
return phoneNumber; return phoneNumber;
} }
} }
+17 -13
View File
@@ -100,25 +100,29 @@ public class MmsSmsUtils {
return match.matches(); return match.matches();
} }
/** True if c is ISO-LATIN characters 0-9, *, # , + */ /**
public static final boolean isDialable(char c) { * This pattern is intended for searching for carrier specific phone numbers starting with star
return (c >= '0' && c <= '9') || c == '*' || c == '#' || c == '+'; * sign and digits such as the voice mail number.
} * (e.g. *20 Chile Claro)
*/
private static final Pattern PHONE_NUMBER_STARTING_WITH_STAR_PATTERN =
Pattern.compile("\\*[0-9]+");
/** /**
* Returns true if the address is a dialable phone number. * Returns true if the number is a Phone number
* *
* @param address the input address to be tested * @param number the input number to be tested
* @return true if address is a dialable phone number * @return true if number is a Phone number
*/ */
public static boolean isDialable(final String address) { public static boolean isPhoneNumber(final String number) {
if (TextUtils.isEmpty(address)) { if (TextUtils.isEmpty(number)) {
return false; return false;
} }
for (int i = 0, count = address.length(); i < count; i++) {
if (!isDialable(address.charAt(i))) { Matcher match = Patterns.PHONE.matcher(number);
return false; if (!match.matches()) {
} match = PHONE_NUMBER_STARTING_WITH_STAR_PATTERN.matcher(number);
return match.matches();
} }
return true; return true;
} }