diff options
author | Android Dialer <noreply@google.com> | 2018-03-09 11:09:34 -0800 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-03-09 11:11:32 -0800 |
commit | 43ae8e25c687acd896f59cd2a9249b7a3ae7e037 (patch) | |
tree | 1bc265ea249c697d56d1e35487272cce83bc7704 /java | |
parent | 93d27d0a5db53bc7cb7b03c58889667887d5816b (diff) |
Add spam blocking setting in spam module.
Test: InAppSpamTest,ApdlSpamTest,VisualVoicemailUpdateTaskTest
PiperOrigin-RevId: 188509191
Change-Id: I8b9c07dcc1c7b3b80ffc914ec99f4e6d80d50985
Diffstat (limited to 'java')
4 files changed, 67 insertions, 13 deletions
diff --git a/java/com/android/dialer/app/calllog/VisualVoicemailUpdateTask.java b/java/com/android/dialer/app/calllog/VisualVoicemailUpdateTask.java index 2e12cecf7..6d2581f46 100644 --- a/java/com/android/dialer/app/calllog/VisualVoicemailUpdateTask.java +++ b/java/com/android/dialer/app/calllog/VisualVoicemailUpdateTask.java @@ -32,8 +32,12 @@ import com.android.dialer.common.Assert; import com.android.dialer.common.LogUtil; import com.android.dialer.common.concurrent.DialerExecutor.Worker; import com.android.dialer.common.concurrent.DialerExecutorComponent; +import com.android.dialer.logging.DialerImpression; +import com.android.dialer.logging.Logger; import com.android.dialer.notification.DialerNotificationManager; import com.android.dialer.phonenumbercache.ContactInfo; +import com.android.dialer.spam.Spam; +import com.android.dialer.spam.SpamComponent; import com.android.dialer.telecom.TelecomUtil; import java.util.ArrayList; import java.util.List; @@ -44,7 +48,7 @@ class VisualVoicemailUpdateTask implements Worker<VisualVoicemailUpdateTask.Inpu @Nullable @Override public Void doInBackground(@NonNull Input input) throws Throwable { - updateNotification(input.context, input.queryHelper, input.queryHandler); + updateNotification(input.context, input.queryHelper, input.queryHandler, input.spam); return null; } @@ -58,7 +62,8 @@ class VisualVoicemailUpdateTask implements Worker<VisualVoicemailUpdateTask.Inpu private static void updateNotification( Context context, CallLogNotificationsQueryHelper queryHelper, - FilteredNumberAsyncQueryHandler queryHandler) { + FilteredNumberAsyncQueryHandler queryHandler, + Spam spam) { Assert.isWorkerThread(); LogUtil.enterBlock("VisualVoicemailUpdateTask.updateNotification"); @@ -67,7 +72,15 @@ class VisualVoicemailUpdateTask implements Worker<VisualVoicemailUpdateTask.Inpu // Query failed, just return return; } - voicemailsToNotify = filterBlockedNumbers(context, queryHandler, voicemailsToNotify); + + if (FilteredNumbersUtil.hasRecentEmergencyCall(context)) { + LogUtil.i( + "VisualVoicemailUpdateTask.updateNotification", + "not filtering due to recent emergency call"); + } else { + voicemailsToNotify = filterBlockedNumbers(context, queryHandler, voicemailsToNotify); + voicemailsToNotify = filterSpamNumbers(context, spam, voicemailsToNotify); + } boolean shouldAlert = !voicemailsToNotify.isEmpty() && voicemailsToNotify.size() > getExistingNotificationCount(context); @@ -166,13 +179,6 @@ class VisualVoicemailUpdateTask implements Worker<VisualVoicemailUpdateTask.Inpu private static List<NewCall> filterBlockedNumbers( Context context, FilteredNumberAsyncQueryHandler queryHandler, List<NewCall> newCalls) { Assert.isWorkerThread(); - if (FilteredNumbersUtil.hasRecentEmergencyCall(context)) { - LogUtil.i( - "VisualVoicemailUpdateTask.filterBlockedNumbers", - "not filtering due to recent emergency call"); - return newCalls; - } - List<NewCall> result = new ArrayList<>(); for (NewCall newCall : newCalls) { if (queryHandler.getBlockedIdSynchronous(newCall.number, newCall.countryIso) != null) { @@ -190,6 +196,30 @@ class VisualVoicemailUpdateTask implements Worker<VisualVoicemailUpdateTask.Inpu return result; } + @WorkerThread + private static List<NewCall> filterSpamNumbers( + Context context, Spam spam, List<NewCall> newCalls) { + Assert.isWorkerThread(); + if (!spam.isSpamBlockingEnabled()) { + return newCalls; + } + + List<NewCall> result = new ArrayList<>(); + for (NewCall newCall : newCalls) { + Logger.get(context).logImpression(DialerImpression.Type.INCOMING_VOICEMAIL_SCREENED); + if (spam.checkSpamStatusSynchronous(newCall.number, newCall.countryIso)) { + LogUtil.i( + "VisualVoicemailUpdateTask.filterSpamNumbers", + "found voicemail from spam number, suppressing notification"); + Logger.get(context) + .logImpression(DialerImpression.Type.INCOMING_VOICEMAIL_AUTO_BLOCKED_AS_SPAM); + } else { + result.add(newCall); + } + } + return result; + } + /** Updates the voicemail notifications displayed. */ static void scheduleTask(@NonNull Context context, @NonNull Runnable callback) { Assert.isNotNull(context); @@ -204,7 +234,8 @@ class VisualVoicemailUpdateTask implements Worker<VisualVoicemailUpdateTask.Inpu new Input( context, CallLogNotificationsQueryHelper.getInstance(context), - new FilteredNumberAsyncQueryHandler(context)); + new FilteredNumberAsyncQueryHandler(context), + SpamComponent.get(context).spam()); DialerExecutorComponent.get(context) .dialerExecutorFactory() .createNonUiTaskBuilder(new VisualVoicemailUpdateTask()) @@ -226,14 +257,17 @@ class VisualVoicemailUpdateTask implements Worker<VisualVoicemailUpdateTask.Inpu @NonNull final Context context; @NonNull final CallLogNotificationsQueryHelper queryHelper; @NonNull final FilteredNumberAsyncQueryHandler queryHandler; + @NonNull final Spam spam; Input( Context context, CallLogNotificationsQueryHelper queryHelper, - FilteredNumberAsyncQueryHandler queryHandler) { + FilteredNumberAsyncQueryHandler queryHandler, + Spam spam) { this.context = context; this.queryHelper = queryHelper; this.queryHandler = queryHandler; + this.spam = spam; } } } diff --git a/java/com/android/dialer/logging/dialer_impression.proto b/java/com/android/dialer/logging/dialer_impression.proto index 8af807fd7..d16efb664 100644 --- a/java/com/android/dialer/logging/dialer_impression.proto +++ b/java/com/android/dialer/logging/dialer_impression.proto @@ -12,7 +12,7 @@ message DialerImpression { // Event enums to be used for Impression Logging in Dialer. // It's perfectly acceptable for this enum to be large // Values should be from 1000 to 100000. - // Next Tag: 1352 + // Next Tag: 1358 enum Type { UNKNOWN_AOSP_EVENT_TYPE = 1000; @@ -695,5 +695,18 @@ message DialerImpression { MAIN_OPEN_WITH_TAB_CONTACTS = 1349; MAIN_OPEN_WITH_TAB_VOICEMAIL = 1350; MAIN_OPEN_WITH_DIALPAD = 1351; + + // Incoming call screened for spam auto blocking + INCOMING_CALL_SCREENED = 1352; + // Incoming call auto blocked as spam + INCOMING_CALL_AUTO_BLOCKED_AS_SPAM = 1353; + // Incoming voicemail screened for spam auto blocking + INCOMING_VOICEMAIL_SCREENED = 1354; + // Incoming voicemail auto blocked as spam + INCOMING_VOICEMAIL_AUTO_BLOCKED_AS_SPAM = 1355; + // User reported auto blocked spam call as spam + AUTO_BLOCKED_SPAM_CALL_REPORTED_AS_SPAM = 1356; + // User reported auto blocked spam call as not spam + AUTO_BLOCKED_SPAM_CALL_REPORTED_AS_NOT_SPAM = 1357; } } diff --git a/java/com/android/dialer/spam/Spam.java b/java/com/android/dialer/spam/Spam.java index 5924d56ab..99deb13b2 100644 --- a/java/com/android/dialer/spam/Spam.java +++ b/java/com/android/dialer/spam/Spam.java @@ -33,6 +33,8 @@ public interface Spam { boolean isSpamNotificationEnabled(); + boolean isSpamBlockingEnabled(); + boolean isDialogEnabledForSpamNotification(); boolean isDialogReportSpamCheckedByDefault(); diff --git a/java/com/android/dialer/spam/SpamStub.java b/java/com/android/dialer/spam/SpamStub.java index b171d0db4..15d9d7649 100644 --- a/java/com/android/dialer/spam/SpamStub.java +++ b/java/com/android/dialer/spam/SpamStub.java @@ -50,6 +50,11 @@ public class SpamStub implements Spam { } @Override + public boolean isSpamBlockingEnabled() { + return false; + } + + @Override public boolean isDialogEnabledForSpamNotification() { return false; } |