From 2ee642d42907e76de3ffb7b13f12961b82892a9a Mon Sep 17 00:00:00 2001 From: maxwelb Date: Fri, 6 Oct 2017 14:51:18 -0700 Subject: Adding Future method for DialerPhoneNumberUtil This CL adds a method to DialerPhoneNumberUtil which returns a Future holding the result of parsing a number into the DialerPhoneNumber proto. This will be used in the APDL integration as it will use Futures as well. The CL also changes DialerExecutors.lowPriorityThreadPool to be an ExecutorService instead of an Executor (the super type) so it can be used in MoreExecutors.listeningDecorator. Test: TAP PiperOrigin-RevId: 171347542 Change-Id: I620aacf3304d625f57af6d2b89a36f11b44008dd --- .../phonenumberproto/DialerPhoneNumberUtil.java | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'java/com/android/dialer/phonenumberproto') diff --git a/java/com/android/dialer/phonenumberproto/DialerPhoneNumberUtil.java b/java/com/android/dialer/phonenumberproto/DialerPhoneNumberUtil.java index cc509f41b..a00ee75bf 100644 --- a/java/com/android/dialer/phonenumberproto/DialerPhoneNumberUtil.java +++ b/java/com/android/dialer/phonenumberproto/DialerPhoneNumberUtil.java @@ -16,6 +16,7 @@ package com.android.dialer.phonenumberproto; +import android.support.annotation.AnyThread; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.annotation.WorkerThread; @@ -24,6 +25,8 @@ import com.android.dialer.DialerPhoneNumber; import com.android.dialer.DialerPhoneNumber.RawInput; import com.android.dialer.common.Assert; import com.android.dialer.common.LogUtil; +import com.google.common.util.concurrent.ListenableFuture; +import com.google.common.util.concurrent.ListeningExecutorService; import com.google.i18n.phonenumbers.NumberParseException; import com.google.i18n.phonenumbers.PhoneNumberUtil; import com.google.i18n.phonenumbers.PhoneNumberUtil.MatchType; @@ -46,7 +49,7 @@ public class DialerPhoneNumberUtil { /** * Parses the provided raw phone number into a {@link DialerPhoneNumber}. * - * @see PhoneNumberUtil#parse(String, String) + * @see PhoneNumberUtil#parse(CharSequence, String) */ @WorkerThread public DialerPhoneNumber parse(@Nullable String numberToParse, @Nullable String defaultRegion) { @@ -72,6 +75,21 @@ public class DialerPhoneNumberUtil { return dialerPhoneNumber.build(); } + /** + * Parses the provided raw phone number into a Future result of {@link DialerPhoneNumber}. + * + *

Work is run on the provided {@link ListeningExecutorService}. + * + * @see PhoneNumberUtil#parse(CharSequence, String) + */ + @AnyThread + public ListenableFuture parse( + @Nullable String numberToParse, + @Nullable String defaultRegion, + @NonNull ListeningExecutorService service) { + return service.submit(() -> parse(numberToParse, defaultRegion)); + } + /** * Returns true if the two numbers were parseable by libphonenumber and are an {@link * MatchType#EXACT_MATCH} or if they have the same raw input. -- cgit v1.2.3