diff options
author | linyuh <linyuh@google.com> | 2018-01-24 14:07:05 -0800 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-01-24 15:26:19 -0800 |
commit | 9e04310a9902a4dbf593060baaf41c37919fd7fe (patch) | |
tree | 0503b23642f1e4aaba3aa4d94769c6289e571215 | |
parent | 988044789fb70eca91c6a6e1f2526131f376b751 (diff) |
Define methods in Spam interface to be used later in the PhoneLookup for spam features.
Bug: 70989534
Test: ApdlSpamTest, InAppSpamTest
PiperOrigin-RevId: 183138320
Change-Id: I647568c31e234995f44d6cbeb2f97f73952db6bb
-rw-r--r-- | java/com/android/dialer/spam/Spam.java | 25 | ||||
-rw-r--r-- | java/com/android/dialer/spam/SpamStub.java | 32 |
2 files changed, 55 insertions, 2 deletions
diff --git a/java/com/android/dialer/spam/Spam.java b/java/com/android/dialer/spam/Spam.java index b1240c69a..ea1ea138e 100644 --- a/java/com/android/dialer/spam/Spam.java +++ b/java/com/android/dialer/spam/Spam.java @@ -18,9 +18,13 @@ package com.android.dialer.spam; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import com.android.dialer.DialerPhoneNumber; import com.android.dialer.logging.ContactLookupResult; import com.android.dialer.logging.ContactSource; import com.android.dialer.logging.ReportingLocation; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.util.concurrent.ListenableFuture; /** Allows the container application to mark calls as spam. */ public interface Spam { @@ -39,7 +43,17 @@ public interface Spam { int percentOfNonSpamNotificationsToShow(); /** - * Checks if the given number is suspected of being a spamer. + * Checks if each of numbers in the given list is suspected of being a spam. + * + * @param dialerPhoneNumbers A list of {@link DialerPhoneNumber}. + * @return A {@link ListenableFuture} of a map that maps each number to its spam status + * (true/false). + */ + ListenableFuture<ImmutableMap<DialerPhoneNumber, Boolean>> batchCheckSpamStatus( + ImmutableList<DialerPhoneNumber> dialerPhoneNumbers); + + /** + * Checks if the given number is suspected of being a spam. * * @param number The phone number of the call. * @param countryIso The country ISO of the call. @@ -81,6 +95,15 @@ public interface Spam { boolean checkSpamStatusSynchronous(String number, String countryIso); /** + * Returns a {@link ListenableFuture} indicating whether the spam data have been updated since + * {@code timestampMillis}. + * + * <p>It is the caller's responsibility to ensure the timestamp is in milliseconds. Failure to do + * so will result in undefined behavior. + */ + ListenableFuture<Boolean> dataUpdatedSince(long timestampMillis); + + /** * Reports number as spam. * * @param number The number to be reported. diff --git a/java/com/android/dialer/spam/SpamStub.java b/java/com/android/dialer/spam/SpamStub.java index daa475c4a..ac2e94359 100644 --- a/java/com/android/dialer/spam/SpamStub.java +++ b/java/com/android/dialer/spam/SpamStub.java @@ -16,16 +16,27 @@ package com.android.dialer.spam; +import com.android.dialer.DialerPhoneNumber; +import com.android.dialer.common.concurrent.Annotations.BackgroundExecutor; import com.android.dialer.logging.ContactLookupResult; import com.android.dialer.logging.ContactSource; import com.android.dialer.logging.ReportingLocation; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.util.concurrent.Futures; +import com.google.common.util.concurrent.ListenableFuture; +import com.google.common.util.concurrent.ListeningExecutorService; import javax.inject.Inject; /** Default implementation of Spam. */ public class SpamStub implements Spam { + private final ListeningExecutorService backgroundExecutorService; + @Inject - public SpamStub() {} + public SpamStub(@BackgroundExecutor ListeningExecutorService backgroundExecutorService) { + this.backgroundExecutorService = backgroundExecutorService; + } @Override public boolean isSpamEnabled() { @@ -58,6 +69,20 @@ public class SpamStub implements Spam { } @Override + public ListenableFuture<ImmutableMap<DialerPhoneNumber, Boolean>> batchCheckSpamStatus( + ImmutableList<DialerPhoneNumber> dialerPhoneNumbers) { + return backgroundExecutorService.submit( + () -> { + ImmutableMap.Builder<DialerPhoneNumber, Boolean> resultBuilder = + new ImmutableMap.Builder<>(); + for (DialerPhoneNumber dialerPhoneNumber : dialerPhoneNumbers) { + resultBuilder.put(dialerPhoneNumber, false); + } + return resultBuilder.build(); + }); + } + + @Override public void checkSpamStatus(String number, String countryIso, Listener listener) { listener.onComplete(false); } @@ -83,6 +108,11 @@ public class SpamStub implements Spam { } @Override + public ListenableFuture<Boolean> dataUpdatedSince(long timestampMillis) { + return Futures.immediateFuture(false); + } + + @Override public void reportSpamFromAfterCallNotification( String number, String countryIso, |