Search in sources :

Example 26 with DialerPhoneNumber

use of com.android.dialer.DialerPhoneNumber in project android_packages_apps_Dialer by LineageOS.

the class DialerPhoneNumberUtil method isMatch.

/**
 * Returns true if the two numbers:
 *
 * <ul>
 *   <li>were parseable by libphonenumber (see {@link #parse(String, String)}),
 *   <li>are a {@link MatchType#SHORT_NSN_MATCH}, {@link MatchType#NSN_MATCH}, or {@link
 *       MatchType#EXACT_MATCH}, and
 *   <li>have the same post-dial digits.
 * </ul>
 *
 * <p>If either number is not parseable, returns true if their raw inputs have the same network
 * and post-dial portions.
 *
 * <p>An empty number is never considered to match another number.
 *
 * @see PhoneNumberUtil#isNumberMatch(PhoneNumber, PhoneNumber)
 */
@WorkerThread
public boolean isMatch(@NonNull DialerPhoneNumber firstNumberIn, @NonNull DialerPhoneNumber secondNumberIn) {
    Assert.isWorkerThread();
    // An empty number should not be combined with any other number.
    if (firstNumberIn.getNormalizedNumber().isEmpty() || secondNumberIn.getNormalizedNumber().isEmpty()) {
        return false;
    }
    // Two numbers with different countries should not match.
    if (!firstNumberIn.getCountryIso().equals(secondNumberIn.getCountryIso())) {
        return false;
    }
    PhoneNumber phoneNumber1 = null;
    try {
        phoneNumber1 = phoneNumberUtil.parse(firstNumberIn.getNormalizedNumber(), firstNumberIn.getCountryIso());
    } catch (NumberParseException e) {
    // fall through
    }
    PhoneNumber phoneNumber2 = null;
    try {
        phoneNumber2 = phoneNumberUtil.parse(secondNumberIn.getNormalizedNumber(), secondNumberIn.getCountryIso());
    } catch (NumberParseException e) {
    // fall through
    }
    // fallback to basic textual matching.
    if (isServiceNumber(firstNumberIn.getNormalizedNumber()) || isServiceNumber(secondNumberIn.getNormalizedNumber()) || phoneNumber1 == null || phoneNumber2 == null) {
        return firstNumberIn.getNormalizedNumber().equals(secondNumberIn.getNormalizedNumber());
    }
    // doesn't match "55555" (due to those being a SHORT_NSN_MATCH below).
    if (shortNumberInfo.isPossibleShortNumber(phoneNumber1) || shortNumberInfo.isPossibleShortNumber(phoneNumber2)) {
        return firstNumberIn.getNormalizedNumber().equals(secondNumberIn.getNormalizedNumber());
    }
    // Both numbers are parseable, use more sophisticated libphonenumber matching.
    MatchType matchType = phoneNumberUtil.isNumberMatch(phoneNumber1, phoneNumber2);
    return (matchType == MatchType.SHORT_NSN_MATCH || matchType == MatchType.NSN_MATCH || matchType == MatchType.EXACT_MATCH) && firstNumberIn.getPostDialPortion().equals(secondNumberIn.getPostDialPortion());
}
Also used : MatchType(com.google.i18n.phonenumbers.PhoneNumberUtil.MatchType) DialerPhoneNumber(com.android.dialer.DialerPhoneNumber) PhoneNumber(com.google.i18n.phonenumbers.Phonenumber.PhoneNumber) NumberParseException(com.google.i18n.phonenumbers.NumberParseException) WorkerThread(android.support.annotation.WorkerThread)

Aggregations

DialerPhoneNumber (com.android.dialer.DialerPhoneNumber)26 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)8 ContentValues (android.content.ContentValues)7 Cursor (android.database.Cursor)7 ImmutableMap (com.google.common.collect.ImmutableMap)7 ArrayList (java.util.ArrayList)7 ArraySet (android.support.v4.util.ArraySet)6 PhoneLookupInfo (com.android.dialer.phonelookup.PhoneLookupInfo)6 Cp2ContactInfo (com.android.dialer.phonelookup.PhoneLookupInfo.Cp2Info.Cp2ContactInfo)6 ImmutableSet (com.google.common.collect.ImmutableSet)6 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)6 Set (java.util.Set)6 PartitionedNumbers (com.android.dialer.phonenumberproto.PartitionedNumbers)5 ListeningExecutorService (com.google.common.util.concurrent.ListeningExecutorService)5 Context (android.content.Context)4 ArraySet (android.util.ArraySet)4 LogUtil (com.android.dialer.common.LogUtil)4 BackgroundExecutor (com.android.dialer.common.concurrent.Annotations.BackgroundExecutor)4 ApplicationContext (com.android.dialer.inject.ApplicationContext)4 PhoneLookup (com.android.dialer.phonelookup.PhoneLookup)4