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

Commit f44c179d authored by linyuh's avatar linyuh Committed by android-build-merger
Browse files

Merge "Group info needed to show a block/report spam dialog into a proto to...

Merge "Group info needed to show a block/report spam dialog into a proto to avoid long method signatures."
am: d42fb78b

Change-Id: Ie88d5a75a7d86539aa1bf8504e9d0ceff87a0843
parents 2b310bbf d42fb78b
Loading
Loading
Loading
Loading
+8 −38
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@ import android.content.Context;
import android.content.Intent;
import android.support.v4.content.LocalBroadcastManager;
import com.android.dialer.common.LogUtil;
import com.android.dialer.logging.ReportingLocation;
import com.android.dialer.protos.ProtoParsers;

/**
 * Notifies that a dialog for blocking a number and/or marking it as spam/not spam should be shown.
@@ -31,20 +31,9 @@ public final class ShowBlockReportSpamDialogNotifier {

  /**
   * Notifies that a dialog for blocking a number and optionally report it as spam should be shown.
   *
   * @param context Context
   * @param normalizedNumber The number to be blocked/marked as spam
   * @param countryIso The ISO 3166-1 two letters country code for the number
   * @param callType Call type defined in {@link android.provider.CallLog.Calls}
   * @param reportingLocation The location where the number is reported. See {@link
   *     ReportingLocation.Type}.
   */
  public static void notifyShowDialogToBlockNumberAndOptionallyReportSpam(
      Context context,
      String normalizedNumber,
      String countryIso,
      int callType,
      ReportingLocation.Type reportingLocation) {
      Context context, BlockReportSpamDialogInfo blockReportSpamDialogInfo) {
    LogUtil.enterBlock(
        "ShowBlockReportSpamDialogNotifier.notifyShowDialogToBlockNumberAndOptionallyReportSpam");

@@ -52,40 +41,21 @@ public final class ShowBlockReportSpamDialogNotifier {
    intent.setAction(
        ShowBlockReportSpamDialogReceiver
            .ACTION_SHOW_DIALOG_TO_BLOCK_NUMBER_AND_OPTIONALLY_REPORT_SPAM);

    intent.putExtra(ShowBlockReportSpamDialogReceiver.EXTRA_NUMBER, normalizedNumber);
    intent.putExtra(ShowBlockReportSpamDialogReceiver.EXTRA_COUNTRY_ISO, countryIso);
    intent.putExtra(ShowBlockReportSpamDialogReceiver.EXTRA_CALL_TYPE, callType);
    intent.putExtra(
        ShowBlockReportSpamDialogReceiver.EXTRA_REPORTING_LOCATION, reportingLocation.getNumber());
    ProtoParsers.put(
        intent, ShowBlockReportSpamDialogReceiver.EXTRA_DIALOG_INFO, blockReportSpamDialogInfo);

    LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
  }

  /**
   * Notifies that a dialog for reporting a number as not spam should be shown.
   *
   * @param context Context
   * @param normalizedNumber The number to be reported as not spam
   * @param countryIso The ISO 3166-1 two letters country code for the number
   * @param callType Call type defined in {@link android.provider.CallLog.Calls}
   * @param reportingLocation The location where the number is reported. See {@link
   *     ReportingLocation.Type}.
   */
  /** Notifies that a dialog for reporting a number as not spam should be shown. */
  public static void notifyShowDialogToReportNotSpam(
      Context context,
      String normalizedNumber,
      String countryIso,
      int callType,
      ReportingLocation.Type reportingLocation) {
      Context context, BlockReportSpamDialogInfo blockReportSpamDialogInfo) {
    LogUtil.enterBlock("ShowBlockReportSpamDialogNotifier.notifyShowDialogToReportNotSpam");

    Intent intent = new Intent();
    intent.setAction(ShowBlockReportSpamDialogReceiver.ACTION_SHOW_DIALOG_TO_REPORT_NOT_SPAM);
    intent.putExtra(ShowBlockReportSpamDialogReceiver.EXTRA_NUMBER, normalizedNumber);
    intent.putExtra(ShowBlockReportSpamDialogReceiver.EXTRA_COUNTRY_ISO, countryIso);
    intent.putExtra(ShowBlockReportSpamDialogReceiver.EXTRA_CALL_TYPE, callType);
    intent.putExtra(ShowBlockReportSpamDialogReceiver.EXTRA_REPORTING_LOCATION, reportingLocation);
    ProtoParsers.put(
        intent, ShowBlockReportSpamDialogReceiver.EXTRA_DIALOG_INFO, blockReportSpamDialogInfo);

    LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
  }
+24 −42
Original line number Diff line number Diff line
@@ -29,7 +29,7 @@ import com.android.dialer.common.LogUtil;
import com.android.dialer.logging.ContactSource;
import com.android.dialer.logging.DialerImpression;
import com.android.dialer.logging.Logger;
import com.android.dialer.logging.ReportingLocation;
import com.android.dialer.protos.ProtoParsers;
import com.android.dialer.spam.Spam;
import com.android.dialer.spam.SpamComponent;
import java.util.Locale;
@@ -43,10 +43,7 @@ public final class ShowBlockReportSpamDialogReceiver extends BroadcastReceiver {
  static final String ACTION_SHOW_DIALOG_TO_BLOCK_NUMBER_AND_OPTIONALLY_REPORT_SPAM =
      "show_dialog_to_block_number_and_optionally_report_spam";
  static final String ACTION_SHOW_DIALOG_TO_REPORT_NOT_SPAM = "show_dialog_to_report_not_spam";
  static final String EXTRA_NUMBER = "number";
  static final String EXTRA_COUNTRY_ISO = "country_iso";
  static final String EXTRA_CALL_TYPE = "call_type";
  static final String EXTRA_REPORTING_LOCATION = "reporting_location";
  static final String EXTRA_DIALOG_INFO = "dialog_info";

  /** {@link FragmentManager} needed to show a {@link android.app.DialogFragment}. */
  private final FragmentManager fragmentManager;
@@ -85,19 +82,10 @@ public final class ShowBlockReportSpamDialogReceiver extends BroadcastReceiver {
    LogUtil.enterBlock(
        "ShowBlockReportSpamDialogReceiver.showDialogToBlockNumberAndOptionallyReportSpam");

    Assert.checkArgument(intent.hasExtra(EXTRA_NUMBER));
    Assert.checkArgument(intent.hasExtra(EXTRA_COUNTRY_ISO));
    Assert.checkArgument(intent.hasExtra(EXTRA_CALL_TYPE));
    Assert.checkArgument(intent.hasExtra(EXTRA_REPORTING_LOCATION));

    String normalizedNumber = intent.getStringExtra(EXTRA_NUMBER);
    String countryIso = intent.getStringExtra(EXTRA_COUNTRY_ISO);
    int callType = intent.getIntExtra(EXTRA_CALL_TYPE, 0);
    ReportingLocation.Type reportingLocation =
        ReportingLocation.Type.forNumber(
            intent.getIntExtra(
                EXTRA_REPORTING_LOCATION,
                ReportingLocation.Type.UNKNOWN_REPORTING_LOCATION.getNumber()));
    Assert.checkArgument(intent.hasExtra(EXTRA_DIALOG_INFO));
    BlockReportSpamDialogInfo dialogInfo =
        ProtoParsers.getTrusted(
            intent, EXTRA_DIALOG_INFO, BlockReportSpamDialogInfo.getDefaultInstance());

    Spam spam = SpamComponent.get(context).spam();

@@ -117,24 +105,27 @@ public final class ShowBlockReportSpamDialogReceiver extends BroadcastReceiver {
                    DialerImpression.Type
                        .REPORT_CALL_AS_SPAM_VIA_CALL_LOG_BLOCK_REPORT_SPAM_SENT_VIA_BLOCK_NUMBER_DIALOG);
            spam.reportSpamFromCallHistory(
                normalizedNumber,
                countryIso,
                callType,
                reportingLocation,
                dialogInfo.getNormalizedNumber(),
                dialogInfo.getCountryIso(),
                dialogInfo.getCallType(),
                dialogInfo.getReportingLocation(),
                ContactSource.Type.UNKNOWN_SOURCE_TYPE /* TODO(a bug): Fix. */);
          }

          // TODO(a bug): Block the number.
          Toast.makeText(
                  context,
                  String.format(Locale.ENGLISH, "TODO: " + "Block number %s.", normalizedNumber),
                  String.format(
                      Locale.ENGLISH,
                      "TODO: " + "Block number %s.",
                      dialogInfo.getNormalizedNumber()),
                  Toast.LENGTH_SHORT)
              .show();
        };

    // Create and show the dialog.
    BlockReportSpamDialogs.BlockReportSpamDialogFragment.newInstance(
            normalizedNumber,
            dialogInfo.getNormalizedNumber(),
            spam.isDialogReportSpamCheckedByDefault(),
            onSpamDialogClickListener,
            /* dismissListener = */ null)
@@ -144,19 +135,10 @@ public final class ShowBlockReportSpamDialogReceiver extends BroadcastReceiver {
  private void showDialogToReportNotSpam(Context context, Intent intent) {
    LogUtil.enterBlock("ShowBlockReportSpamDialogReceiver.showDialogToReportNotSpam");

    Assert.checkArgument(intent.hasExtra(EXTRA_NUMBER));
    Assert.checkArgument(intent.hasExtra(EXTRA_COUNTRY_ISO));
    Assert.checkArgument(intent.hasExtra(EXTRA_CALL_TYPE));
    Assert.checkArgument(intent.hasExtra(EXTRA_REPORTING_LOCATION));

    String normalizedNumber = intent.getStringExtra(EXTRA_NUMBER);
    String countryIso = intent.getStringExtra(EXTRA_COUNTRY_ISO);
    int callType = intent.getIntExtra(EXTRA_CALL_TYPE, 0);
    ReportingLocation.Type reportingLocation =
        ReportingLocation.Type.forNumber(
            intent.getIntExtra(
                EXTRA_REPORTING_LOCATION,
                ReportingLocation.Type.UNKNOWN_REPORTING_LOCATION.getNumber()));
    Assert.checkArgument(intent.hasExtra(EXTRA_DIALOG_INFO));
    BlockReportSpamDialogInfo dialogInfo =
        ProtoParsers.getTrusted(
            intent, EXTRA_DIALOG_INFO, BlockReportSpamDialogInfo.getDefaultInstance());

    // Set up the positive listener for the dialog.
    OnConfirmListener onConfirmListener =
@@ -168,17 +150,17 @@ public final class ShowBlockReportSpamDialogReceiver extends BroadcastReceiver {
            Logger.get(context)
                .logImpression(DialerImpression.Type.DIALOG_ACTION_CONFIRM_NUMBER_NOT_SPAM);
            spam.reportNotSpamFromCallHistory(
                normalizedNumber,
                countryIso,
                callType,
                reportingLocation,
                dialogInfo.getNormalizedNumber(),
                dialogInfo.getCountryIso(),
                dialogInfo.getCallType(),
                dialogInfo.getReportingLocation(),
                ContactSource.Type.UNKNOWN_SOURCE_TYPE /* TODO(a bug): Fix. */);
          }
        };

    // Create & show the dialog.
    BlockReportSpamDialogs.ReportNotSpamDialogFragment.newInstance(
            normalizedNumber, onConfirmListener, /* dismissListener = */ null)
            dialogInfo.getNormalizedNumber(), onConfirmListener, /* dismissListener = */ null)
        .show(fragmentManager, BlockReportSpamDialogs.NOT_SPAM_DIALOG_TAG);
  }
}
+30 −0
Original line number Diff line number Diff line
syntax = "proto2";

option java_package = "com.android.dialer.blockreportspam";
option java_multiple_files = true;
option optimize_for = LITE_RUNTIME;


package com.android.dialer.blockreportspam;

import "java/com/android/dialer/logging/reporting_location.proto";

// Contains information needed in dialogs that allow a user to block a number
// and/or report it as spam/not spam.
// Next ID: 5
message BlockReportSpamDialogInfo {
  // A dialer-normalized version of the number used in the dialogs.
  // See DialerPhoneNumber#normalized_number.
  optional string normalized_number = 1;

  // The ISO 3166-1 two letters country code of the number.
  optional string country_iso = 2;

  // Type of the call to/from the number, as defined in
  // android.provider.CallLog.Calls
  optional int32 call_type = 3;

  // The location where the number is reported.
  optional com.android.dialer.logging.ReportingLocation.Type
      reporting_location = 4;
}
 No newline at end of file
+10 −5
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.content.Context;
import android.provider.CallLog.Calls;
import android.telecom.PhoneAccountHandle;
import android.text.TextUtils;
import com.android.dialer.blockreportspam.BlockReportSpamDialogInfo;
import com.android.dialer.calldetails.CallDetailsActivity;
import com.android.dialer.callintent.CallInitiationType;
import com.android.dialer.calllog.model.CoalescedRow;
@@ -83,15 +84,19 @@ final class Modules {
        modules.add(moduleForAddingToContacts.get());
      }

      BlockReportSpamDialogInfo blockReportSpamDialogInfo =
          BlockReportSpamDialogInfo.newBuilder()
              .setNormalizedNumber(row.number().getNormalizedNumber())
              .setCountryIso(row.number().getCountryIso())
              .setCallType(row.callType())
              .setReportingLocation(ReportingLocation.Type.CALL_LOG_HISTORY)
              .build();
      modules.addAll(
          SharedModules.createModulesHandlingBlockedOrSpamNumber(
              context,
              row.number().getNormalizedNumber(),
              row.number().getCountryIso(),
              row.callType(),
              blockReportSpamDialogInfo,
              row.numberAttributes().getIsBlocked(),
              row.numberAttributes().getIsSpam(),
              ReportingLocation.Type.CALL_LOG_HISTORY));
              row.numberAttributes().getIsSpam()));

      Optional<HistoryItemActionModule> moduleForCopyingNumber =
          SharedModules.createModuleForCopyingNumber(context, normalizedNumber);
+17 −50
Original line number Diff line number Diff line
@@ -24,9 +24,9 @@ import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.widget.Toast;
import com.android.dialer.DialerPhoneNumber;
import com.android.dialer.blockreportspam.BlockReportSpamDialogInfo;
import com.android.dialer.blockreportspam.ShowBlockReportSpamDialogNotifier;
import com.android.dialer.clipboard.ClipboardUtils;
import com.android.dialer.logging.ReportingLocation;
import com.android.dialer.util.IntentUtil;
import com.android.dialer.util.UriUtils;
import com.google.common.base.Optional;
@@ -114,63 +114,42 @@ public class SharedModules {
  }

  /**
   * Add modules related to blocking/unblocking a number and/or reporting it as spam/not spam.
   *
   * @param normalizedNumber The number to be blocked / unblocked / marked as spam/not spam
   * @param countryIso The ISO 3166-1 two letters country code for the number
   * @param callType Call type defined in {@link android.provider.CallLog.Calls}
   * @param reportingLocation The location where the number is reported. See {@link
   *     ReportingLocation.Type}.
   * Create modules related to blocking/unblocking a number and/or reporting it as spam/not spam.
   */
  public static List<HistoryItemActionModule> createModulesHandlingBlockedOrSpamNumber(
      Context context,
      String normalizedNumber,
      String countryIso,
      int callType,
      BlockReportSpamDialogInfo blockReportSpamDialogInfo,
      boolean isBlocked,
      boolean isSpam,
      ReportingLocation.Type reportingLocation) {
      boolean isSpam) {
    List<HistoryItemActionModule> modules = new ArrayList<>();

    // For a spam number, add two options:
    // (1) "Not spam" and "Block", or
    // (2) "Not spam" and "Unblock".
    if (isSpam) {
      modules.add(createModuleForMarkingNumberAsNonSpam(context, blockReportSpamDialogInfo));
      modules.add(
          createModuleForMarkingNumberAsNonSpam(
              context, normalizedNumber, countryIso, callType, reportingLocation));
      modules.add(createModuleForBlockingOrUnblockingNumber(context, normalizedNumber, isBlocked));
          createModuleForBlockingOrUnblockingNumber(context, blockReportSpamDialogInfo, isBlocked));
      return modules;
    }

    // For a blocked non-spam number, add "Unblock" option.
    if (isBlocked) {
      modules.add(createModuleForBlockingOrUnblockingNumber(context, normalizedNumber, isBlocked));
      modules.add(
          createModuleForBlockingOrUnblockingNumber(context, blockReportSpamDialogInfo, isBlocked));
      return modules;
    }

    // For a number that is neither a spam number nor blocked, add "Block/Report spam" option.
    modules.add(
        createModuleForBlockingNumberAndOptionallyReportingSpam(
            context, normalizedNumber, countryIso, callType, reportingLocation));
            context, blockReportSpamDialogInfo));
    return modules;
  }

  /**
   * Add "Not spam" module.
   *
   * @param normalizedNumber The number to be marked as not spam
   * @param countryIso The ISO 3166-1 two letters country code for the number
   * @param callType Call type defined in {@link android.provider.CallLog.Calls}
   * @param reportingLocation The location where the number is reported. See {@link
   *     ReportingLocation.Type}.
   */
  /** Create "Not spam" module. */
  private static HistoryItemActionModule createModuleForMarkingNumberAsNonSpam(
      Context context,
      String normalizedNumber,
      String countryIso,
      int callType,
      ReportingLocation.Type reportingLocation) {
      Context context, BlockReportSpamDialogInfo blockReportSpamDialogInfo) {
    return new HistoryItemActionModule() {
      @Override
      public int getStringId() {
@@ -185,14 +164,14 @@ public class SharedModules {
      @Override
      public boolean onClick() {
        ShowBlockReportSpamDialogNotifier.notifyShowDialogToReportNotSpam(
            context, normalizedNumber, countryIso, callType, reportingLocation);
            context, blockReportSpamDialogInfo);
        return true; // Close the bottom sheet.
      }
    };
  }

  private static HistoryItemActionModule createModuleForBlockingOrUnblockingNumber(
      Context context, String normalizedNumber, boolean isBlocked) {
      Context context, BlockReportSpamDialogInfo blockReportSpamDialogInfo, boolean isBlocked) {
    return new HistoryItemActionModule() {
      @Override
      public int getStringId() {
@@ -214,7 +193,7 @@ public class SharedModules {
                String.format(
                    Locale.ENGLISH,
                    "TODO: " + (isBlocked ? "Unblock " : "Block ") + " number %s.",
                    normalizedNumber),
                    blockReportSpamDialogInfo.getNormalizedNumber()),
                Toast.LENGTH_SHORT)
            .show();
        return true; // Close the bottom sheet.
@@ -222,21 +201,9 @@ public class SharedModules {
    };
  }

  /**
   * Add "Block/Report spam" module
   *
   * @param normalizedNumber The number to be blocked / unblocked / marked as spam/not spam
   * @param countryIso The ISO 3166-1 two letters country code for the number
   * @param callType Call type defined in {@link android.provider.CallLog.Calls}
   * @param reportingLocation The location where the number is reported. See {@link
   *     ReportingLocation.Type}.
   */
  /** Create "Block/Report spam" module */
  private static HistoryItemActionModule createModuleForBlockingNumberAndOptionallyReportingSpam(
      Context context,
      String normalizedNumber,
      String countryIso,
      int callType,
      ReportingLocation.Type reportingLocation) {
      Context context, BlockReportSpamDialogInfo blockReportSpamDialogInfo) {
    return new HistoryItemActionModule() {
      @Override
      public int getStringId() {
@@ -251,7 +218,7 @@ public class SharedModules {
      @Override
      public boolean onClick() {
        ShowBlockReportSpamDialogNotifier.notifyShowDialogToBlockNumberAndOptionallyReportSpam(
            context, normalizedNumber, countryIso, callType, reportingLocation);
            context, blockReportSpamDialogInfo);
        return true; // Close the bottom sheet.
      }
    };
Loading