From dbc43316cf2cf46bd928a957781b8cf73c3282a8 Mon Sep 17 00:00:00 2001 From: Taesu Lee Date: Mon, 25 May 2020 14:30:02 +0900 Subject: [PATCH] Check whether dialable only It allows to call to any sender such as *20(Voice Mail Number for Chile Claro). Test: Manual Signed-off-by: Taesu Lee Change-Id: Ifca83c5f05018de627fa38318fd4b6db20370910 --- .../datamodel/data/ConversationData.java | 2 +- .../android/messaging/sms/MmsSmsUtils.java | 24 ++++++++++++------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/com/android/messaging/datamodel/data/ConversationData.java b/src/com/android/messaging/datamodel/data/ConversationData.java index 55d5bfc..5bddfeb 100644 --- a/src/com/android/messaging/datamodel/data/ConversationData.java +++ b/src/com/android/messaging/datamodel/data/ConversationData.java @@ -700,7 +700,7 @@ public class ConversationData extends BindableData { final ParticipantData participant = this.getOtherParticipant(); if (participant != null) { final String phoneNumber = participant.getSendDestination(); - if (!TextUtils.isEmpty(phoneNumber) && MmsSmsUtils.isPhoneNumber(phoneNumber)) { + if (!TextUtils.isEmpty(phoneNumber) && MmsSmsUtils.isDialable(phoneNumber)) { return phoneNumber; } } diff --git a/src/com/android/messaging/sms/MmsSmsUtils.java b/src/com/android/messaging/sms/MmsSmsUtils.java index 1a0ef99..aa20395 100644 --- a/src/com/android/messaging/sms/MmsSmsUtils.java +++ b/src/com/android/messaging/sms/MmsSmsUtils.java @@ -100,19 +100,27 @@ public class MmsSmsUtils { return match.matches(); } + /** True if c is ISO-LATIN characters 0-9, *, # , + */ + public static final boolean isDialable(char c) { + return (c >= '0' && c <= '9') || c == '*' || c == '#' || c == '+'; + } + /** - * Returns true if the number is a Phone number + * Returns true if the address is a dialable phone number. * - * @param number the input number to be tested - * @return true if number is a Phone number + * @param address the input address to be tested + * @return true if address is a dialable phone number */ - public static boolean isPhoneNumber(final String number) { - if (TextUtils.isEmpty(number)) { + public static boolean isDialable(final String address) { + if (TextUtils.isEmpty(address)) { return false; } - - final Matcher match = Patterns.PHONE.matcher(number); - return match.matches(); + for (int i = 0, count = address.length(); i < count; i++) { + if (!isDialable(address.charAt(i))) { + return false; + } + } + return true; } /**