Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e30d0d35 authored by Android Dialer's avatar Android Dialer Committed by android-build-merger
Browse files

Merge "Add spam blocking setting in spam module." am: c7d8b13a

am: 37445cb1

Change-Id: I9299f7b36768a886b7e79ded5e195590f7a999c5
parents ca6464b8 37445cb1
Loading
Loading
Loading
Loading
+46 −12
Original line number Diff line number Diff line
@@ -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;
    }

    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;
    }
  }
}
+14 −1
Original line number Diff line number Diff line
@@ -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;
  }
}
+2 −0
Original line number Diff line number Diff line
@@ -33,6 +33,8 @@ public interface Spam {

  boolean isSpamNotificationEnabled();

  boolean isSpamBlockingEnabled();

  boolean isDialogEnabledForSpamNotification();

  boolean isDialogReportSpamCheckedByDefault();
+5 −0
Original line number Diff line number Diff line
@@ -49,6 +49,11 @@ public class SpamStub implements Spam {
    return false;
  }

  @Override
  public boolean isSpamBlockingEnabled() {
    return false;
  }

  @Override
  public boolean isDialogEnabledForSpamNotification() {
    return false;