From 9e04310a9902a4dbf593060baaf41c37919fd7fe Mon Sep 17 00:00:00 2001 From: linyuh Date: Wed, 24 Jan 2018 14:07:05 -0800 Subject: 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 --- java/com/android/dialer/spam/Spam.java | 25 ++++++++++++++++++++++- 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> batchCheckSpamStatus( + ImmutableList 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. @@ -80,6 +94,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}. + * + *

It is the caller's responsibility to ensure the timestamp is in milliseconds. Failure to do + * so will result in undefined behavior. + */ + ListenableFuture dataUpdatedSince(long timestampMillis); + /** * Reports number as spam. * 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() { @@ -57,6 +68,20 @@ public class SpamStub implements Spam { return 0; } + @Override + public ListenableFuture> batchCheckSpamStatus( + ImmutableList dialerPhoneNumbers) { + return backgroundExecutorService.submit( + () -> { + ImmutableMap.Builder 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); @@ -82,6 +107,11 @@ public class SpamStub implements Spam { return false; } + @Override + public ListenableFuture dataUpdatedSince(long timestampMillis) { + return Futures.immediateFuture(false); + } + @Override public void reportSpamFromAfterCallNotification( String number, -- cgit v1.2.3