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

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

Merge "Implement logic for blocking a number from the new call log's bottom sheet." am: e67eb834

am: 822e98d6

Change-Id: If4c7d9e8e42b295738e065dd3e60f95f0fa95438
parents 34914377 822e98d6
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -22,6 +22,8 @@ import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import com.android.dialer.blocking.FilteredNumberAsyncQueryHandler;
import com.android.dialer.blockreportspam.BlockReportSpamDialogs;
import com.android.dialer.blockreportspam.BlockReportSpamDialogs.DialogFragmentForReportingNotSpam;
import com.android.dialer.blockreportspam.BlockReportSpamDialogs.DialogFragmentForUnblockingNumberAndReportingAsNotSpam;
import com.android.dialer.common.LogUtil;
import com.android.dialer.logging.ContactSource;
import com.android.dialer.logging.DialerImpression;
@@ -58,7 +60,7 @@ public class BlockReportSpamListener implements CallLogListItemViewHolder.OnClic
      final String countryIso,
      final int callType,
      @NonNull final ContactSource.Type contactSourceType) {
    BlockReportSpamDialogs.BlockReportSpamDialogFragment.newInstance(
    BlockReportSpamDialogs.DialogFragmentForBlockingNumberAndOptionallyReportingAsSpam.newInstance(
            displayNumber,
            spam.isDialogReportSpamCheckedByDefault(),
            isSpamChecked -> {
@@ -95,7 +97,7 @@ public class BlockReportSpamListener implements CallLogListItemViewHolder.OnClic
      final String countryIso,
      final int callType,
      @NonNull final ContactSource.Type contactSourceType) {
    BlockReportSpamDialogs.BlockDialogFragment.newInstance(
    BlockReportSpamDialogs.DialogFragmentForBlockingNumberAndReportingAsSpam.newInstance(
            displayNumber,
            spam.isSpamEnabled(),
            () -> {
@@ -134,7 +136,7 @@ public class BlockReportSpamListener implements CallLogListItemViewHolder.OnClic
      final ContactSource.Type contactSourceType,
      final boolean isSpam,
      final Integer blockId) {
    BlockReportSpamDialogs.UnblockDialogFragment.newInstance(
    DialogFragmentForUnblockingNumberAndReportingAsNotSpam.newInstance(
            displayNumber,
            isSpam,
            () -> {
@@ -168,7 +170,7 @@ public class BlockReportSpamListener implements CallLogListItemViewHolder.OnClic
      final String countryIso,
      final int callType,
      final ContactSource.Type contactSourceType) {
    BlockReportSpamDialogs.ReportNotSpamDialogFragment.newInstance(
    DialogFragmentForReportingNotSpam.newInstance(
            displayNumber,
            () -> {
              LogUtil.i("BlockReportSpamListener.onReportNotSpam", "onClick");
+79 −23
Original line number Diff line number Diff line
@@ -29,9 +29,7 @@ import android.widget.CheckBox;
import android.widget.TextView;
import com.android.dialer.blocking.FilteredNumberCompat;

/**
 * Helper class for creating dialog fragments to block a number and/or report it as spam/not spam.
 */
/** Creates dialog fragments to block a number and/or report it as spam/not spam. */
public final class BlockReportSpamDialogs {

  public static final String BLOCK_REPORT_SPAM_DIALOG_TAG = "BlockReportSpamDialog";
@@ -39,7 +37,7 @@ public final class BlockReportSpamDialogs {
  public static final String UNBLOCK_DIALOG_TAG = "UnblockDialog";
  public static final String NOT_SPAM_DIALOG_TAG = "NotSpamDialog";

  /** Creates a dialog with the default cancel button listener (dismisses dialog). */
  /** Creates a dialog with the default cancel button listener (which dismisses the dialog). */
  private static AlertDialog.Builder createDialogBuilder(
      Activity activity, final DialogFragment fragment) {
    return new AlertDialog.Builder(activity, R.style.AlertDialogTheme)
@@ -70,36 +68,36 @@ public final class BlockReportSpamDialogs {
  }

  /**
   * Listener passed to block/report spam dialog for positive click in {@link
   * BlockReportSpamDialogFragment}.
   * Positive listener for the "Block/Report spam" dialog {@link
   * DialogFragmentForBlockingNumberAndOptionallyReportingAsSpam}.
   */
  public interface OnSpamDialogClickListener {

    /**
     * Called when user clicks on positive button in block/report spam dialog.
     * Called when the user clicks on the positive button of the "Block/Report spam" dialog.
     *
     * @param isSpamChecked Whether the spam checkbox is checked.
     */
    void onClick(boolean isSpamChecked);
  }

  /** Listener passed to all dialogs except the block/report spam dialog for positive click. */
  /** Positive listener for dialogs other than the "Block/Report spam" dialog. */
  public interface OnConfirmListener {

    /** Called when user clicks on positive button in the dialog. */
    /** Called when the user clicks on the positive button of the dialog. */
    void onClick();
  }

  /** Contains the common attributes between all block/unblock/report spam dialog fragments. */
  /** Contains common attributes shared among all dialog fragments. */
  private abstract static class CommonDialogsFragment extends DialogFragment {

    /** The number to display in the dialog title. */
    protected String displayNumber;

    /** Called when dialog positive button is pressed. */
    /** Listener for the positive button. */
    protected OnConfirmListener positiveListener;

    /** Called when dialog is dismissed. */
    /** Listener for when the dialog is dismissed. */
    @Nullable protected DialogInterface.OnDismissListener dismissListener;

    @Override
@@ -121,8 +119,14 @@ public final class BlockReportSpamDialogs {
    }
  }

  /** Dialog for block/report spam with the mark as spam checkbox. */
  public static class BlockReportSpamDialogFragment extends CommonDialogsFragment {
  /**
   * Dialog for blocking a number and optionally reporting it as spam.
   *
   * <p>This dialog is for a number that is neither blocked nor marked as spam. It has a checkbox
   * that allows the user to report a number as spam when they block it.
   */
  public static class DialogFragmentForBlockingNumberAndOptionallyReportingAsSpam
      extends CommonDialogsFragment {

    /** Called when dialog positive button is pressed. */
    private OnSpamDialogClickListener onSpamDialogClickListener;
@@ -135,7 +139,8 @@ public final class BlockReportSpamDialogs {
        boolean spamChecked,
        OnSpamDialogClickListener onSpamDialogClickListener,
        @Nullable DialogInterface.OnDismissListener dismissListener) {
      BlockReportSpamDialogFragment fragment = new BlockReportSpamDialogFragment();
      DialogFragmentForBlockingNumberAndOptionallyReportingAsSpam fragment =
          new DialogFragmentForBlockingNumberAndOptionallyReportingAsSpam();
      fragment.spamChecked = spamChecked;
      fragment.displayNumber = displayNumber;
      fragment.onSpamDialogClickListener = onSpamDialogClickListener;
@@ -173,8 +178,14 @@ public final class BlockReportSpamDialogs {
    }
  }

  /** Dialog for blocking a number. */
  public static class BlockDialogFragment extends CommonDialogsFragment {
  /**
   * Dialog for blocking a number and reporting it as spam.
   *
   * <p>This dialog is for the migration of blocked numbers. Its positive action should block a
   * number, and also marks it as spam if the spam feature is enabled.
   */
  public static class DialogFragmentForBlockingNumberAndReportingAsSpam
      extends CommonDialogsFragment {

    private boolean isSpamEnabled;

@@ -183,7 +194,8 @@ public final class BlockReportSpamDialogs {
        boolean isSpamEnabled,
        OnConfirmListener positiveListener,
        @Nullable DialogInterface.OnDismissListener dismissListener) {
      BlockDialogFragment fragment = new BlockDialogFragment();
      DialogFragmentForBlockingNumberAndReportingAsSpam fragment =
          new DialogFragmentForBlockingNumberAndReportingAsSpam();
      fragment.displayNumber = displayNumber;
      fragment.positiveListener = positiveListener;
      fragment.dismissListener = dismissListener;
@@ -212,8 +224,51 @@ public final class BlockReportSpamDialogs {
    }
  }

  /** Dialog for unblocking a number. */
  public static class UnblockDialogFragment extends CommonDialogsFragment {
  /**
   * Dialog for blocking a number.
   *
   * <p>This dialog is for a spam number that hasn't been blocked. For example, if the user receives
   * a spam call, this dialog will be shown if they would like to block the number.
   */
  public static class DialogFragmentForBlockingNumber extends CommonDialogsFragment {

    public static DialogFragment newInstance(
        String displayNumber,
        OnConfirmListener positiveListener,
        @Nullable DialogInterface.OnDismissListener dismissListener) {
      DialogFragmentForBlockingNumberAndReportingAsSpam fragment =
          new DialogFragmentForBlockingNumberAndReportingAsSpam();
      fragment.displayNumber = displayNumber;
      fragment.positiveListener = positiveListener;
      fragment.dismissListener = dismissListener;
      return fragment;
    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
      super.onCreateDialog(savedInstanceState);
      // Return the newly created dialog
      AlertDialog.Builder alertDialogBuilder = createDialogBuilder(getActivity(), this);
      Dialog dialog =
          alertDialogBuilder
              .setTitle(getString(R.string.block_number_confirmation_title, displayNumber))
              .setMessage(getString(R.string.block_report_number_alert_details))
              .setPositiveButton(
                  R.string.block_number_ok, createGenericOnClickListener(this, positiveListener))
              .create();
      dialog.setCanceledOnTouchOutside(true);
      return dialog;
    }
  }

  /**
   * Dialog for unblocking a number and marking it as not spam.
   *
   * <p>This dialog is used in the old call log, where unblocking a number will also marking it as
   * not spam.
   */
  public static class DialogFragmentForUnblockingNumberAndReportingAsNotSpam
      extends CommonDialogsFragment {

    /** Whether or not the number is spam. */
    private boolean isSpam;
@@ -223,7 +278,8 @@ public final class BlockReportSpamDialogs {
        boolean isSpam,
        OnConfirmListener positiveListener,
        @Nullable DialogInterface.OnDismissListener dismissListener) {
      UnblockDialogFragment fragment = new UnblockDialogFragment();
      DialogFragmentForUnblockingNumberAndReportingAsNotSpam fragment =
          new DialogFragmentForUnblockingNumberAndReportingAsNotSpam();
      fragment.displayNumber = displayNumber;
      fragment.isSpam = isSpam;
      fragment.positiveListener = positiveListener;
@@ -255,13 +311,13 @@ public final class BlockReportSpamDialogs {
  }

  /** Dialog for reporting a number as not spam. */
  public static class ReportNotSpamDialogFragment extends CommonDialogsFragment {
  public static class DialogFragmentForReportingNotSpam extends CommonDialogsFragment {

    public static DialogFragment newInstance(
        String displayNumber,
        OnConfirmListener positiveListener,
        @Nullable DialogInterface.OnDismissListener dismissListener) {
      ReportNotSpamDialogFragment fragment = new ReportNotSpamDialogFragment();
      DialogFragmentForReportingNotSpam fragment = new DialogFragmentForReportingNotSpam();
      fragment.displayNumber = displayNumber;
      fragment.positiveListener = positiveListener;
      fragment.dismissListener = dismissListener;
+13 −0
Original line number Diff line number Diff line
@@ -47,6 +47,19 @@ public final class ShowBlockReportSpamDialogNotifier {
    LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
  }

  /** Notifies that a dialog for blocking a number should be shown. */
  public static void notifyShowDialogToBlockNumber(
      Context context, BlockReportSpamDialogInfo blockReportSpamDialogInfo) {
    LogUtil.enterBlock("ShowBlockReportSpamDialogNotifier.notifyShowDialogToBlockNumber");

    Intent intent = new Intent();
    intent.setAction(ShowBlockReportSpamDialogReceiver.ACTION_SHOW_DIALOG_TO_BLOCK_NUMBER);
    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. */
  public static void notifyShowDialogToReportNotSpam(
      Context context, BlockReportSpamDialogInfo blockReportSpamDialogInfo) {
+48 −13
Original line number Diff line number Diff line
@@ -21,7 +21,10 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.widget.Toast;
import com.android.dialer.blocking.FilteredNumberAsyncQueryHandler;
import com.android.dialer.blockreportspam.BlockReportSpamDialogs.DialogFragmentForBlockingNumber;
import com.android.dialer.blockreportspam.BlockReportSpamDialogs.DialogFragmentForBlockingNumberAndOptionallyReportingAsSpam;
import com.android.dialer.blockreportspam.BlockReportSpamDialogs.DialogFragmentForReportingNotSpam;
import com.android.dialer.blockreportspam.BlockReportSpamDialogs.OnConfirmListener;
import com.android.dialer.blockreportspam.BlockReportSpamDialogs.OnSpamDialogClickListener;
import com.android.dialer.common.Assert;
@@ -31,7 +34,6 @@ import com.android.dialer.logging.Logger;
import com.android.dialer.protos.ProtoParsers;
import com.android.dialer.spam.Spam;
import com.android.dialer.spam.SpamComponent;
import java.util.Locale;

/**
 * A {@link BroadcastReceiver} that shows an appropriate dialog upon receiving notifications from
@@ -39,6 +41,7 @@ import java.util.Locale;
 */
public final class ShowBlockReportSpamDialogReceiver extends BroadcastReceiver {

  static final String ACTION_SHOW_DIALOG_TO_BLOCK_NUMBER = "show_dialog_to_block_number";
  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";
@@ -51,6 +54,7 @@ public final class ShowBlockReportSpamDialogReceiver extends BroadcastReceiver {
  public static IntentFilter getIntentFilter() {
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(ACTION_SHOW_DIALOG_TO_BLOCK_NUMBER_AND_OPTIONALLY_REPORT_SPAM);
    intentFilter.addAction(ACTION_SHOW_DIALOG_TO_BLOCK_NUMBER);
    intentFilter.addAction(ACTION_SHOW_DIALOG_TO_REPORT_NOT_SPAM);
    return intentFilter;
  }
@@ -66,6 +70,9 @@ public final class ShowBlockReportSpamDialogReceiver extends BroadcastReceiver {
    String action = intent.getAction();

    switch (Assert.isNotNull(action)) {
      case ACTION_SHOW_DIALOG_TO_BLOCK_NUMBER:
        showDialogToBlockNumber(context, intent);
        break;
      case ACTION_SHOW_DIALOG_TO_BLOCK_NUMBER_AND_OPTIONALLY_REPORT_SPAM:
        showDialogToBlockNumberAndOptionallyReportSpam(context, intent);
        break;
@@ -87,6 +94,8 @@ public final class ShowBlockReportSpamDialogReceiver extends BroadcastReceiver {
            intent, EXTRA_DIALOG_INFO, BlockReportSpamDialogInfo.getDefaultInstance());

    Spam spam = SpamComponent.get(context).spam();
    FilteredNumberAsyncQueryHandler filteredNumberAsyncQueryHandler =
        new FilteredNumberAsyncQueryHandler(context);

    // Set up the positive listener for the dialog.
    OnSpamDialogClickListener onSpamDialogClickListener =
@@ -111,19 +120,16 @@ public final class ShowBlockReportSpamDialogReceiver extends BroadcastReceiver {
                dialogInfo.getContactSource());
          }

          // TODO(a bug): Block the number.
          Toast.makeText(
                  context,
                  String.format(
                      Locale.ENGLISH,
                      "TODO: " + "Block number %s.",
                      dialogInfo.getNormalizedNumber()),
                  Toast.LENGTH_SHORT)
              .show();
          filteredNumberAsyncQueryHandler.blockNumber(
              unused ->
                  Logger.get(context)
                      .logImpression(DialerImpression.Type.USER_ACTION_BLOCKED_NUMBER),
              dialogInfo.getNormalizedNumber(),
              dialogInfo.getCountryIso());
        };

    // Create and show the dialog.
    BlockReportSpamDialogs.BlockReportSpamDialogFragment.newInstance(
    DialogFragmentForBlockingNumberAndOptionallyReportingAsSpam.newInstance(
            dialogInfo.getNormalizedNumber(),
            spam.isDialogReportSpamCheckedByDefault(),
            onSpamDialogClickListener,
@@ -131,6 +137,35 @@ public final class ShowBlockReportSpamDialogReceiver extends BroadcastReceiver {
        .show(fragmentManager, BlockReportSpamDialogs.BLOCK_REPORT_SPAM_DIALOG_TAG);
  }

  private void showDialogToBlockNumber(Context context, Intent intent) {
    LogUtil.enterBlock("ShowBlockReportSpamDialogReceiver.showDialogToBlockNumber");

    Assert.checkArgument(intent.hasExtra(EXTRA_DIALOG_INFO));
    BlockReportSpamDialogInfo dialogInfo =
        ProtoParsers.getTrusted(
            intent, EXTRA_DIALOG_INFO, BlockReportSpamDialogInfo.getDefaultInstance());

    FilteredNumberAsyncQueryHandler filteredNumberAsyncQueryHandler =
        new FilteredNumberAsyncQueryHandler(context);

    // Set up the positive listener for the dialog.
    OnConfirmListener onConfirmListener =
        () -> {
          LogUtil.i("ShowBlockReportSpamDialogReceiver.showDialogToBlockNumber", "block number");
          filteredNumberAsyncQueryHandler.blockNumber(
              unused ->
                  Logger.get(context)
                      .logImpression(DialerImpression.Type.USER_ACTION_BLOCKED_NUMBER),
              dialogInfo.getNormalizedNumber(),
              dialogInfo.getCountryIso());
        };

    // Create and show the dialog.
    DialogFragmentForBlockingNumber.newInstance(
            dialogInfo.getNormalizedNumber(), onConfirmListener, /* dismissListener = */ null)
        .show(fragmentManager, BlockReportSpamDialogs.BLOCK_DIALOG_TAG);
  }

  private void showDialogToReportNotSpam(Context context, Intent intent) {
    LogUtil.enterBlock("ShowBlockReportSpamDialogReceiver.showDialogToReportNotSpam");

@@ -158,7 +193,7 @@ public final class ShowBlockReportSpamDialogReceiver extends BroadcastReceiver {
        };

    // Create & show the dialog.
    BlockReportSpamDialogs.ReportNotSpamDialogFragment.newInstance(
    DialogFragmentForReportingNotSpam.newInstance(
            dialogInfo.getNormalizedNumber(), onConfirmListener, /* dismissListener = */ null)
        .show(fragmentManager, BlockReportSpamDialogs.NOT_SPAM_DIALOG_TAG);
  }
+14 −9
Original line number Diff line number Diff line
@@ -187,15 +187,20 @@ public class SharedModules {

      @Override
      public boolean onClick() {
        if (!isBlocked) {
          ShowBlockReportSpamDialogNotifier.notifyShowDialogToBlockNumber(
              context, blockReportSpamDialogInfo);
        } else {
          // TODO(a bug): implement this method.
          Toast.makeText(
                  context,
                  String.format(
                      Locale.ENGLISH,
                    "TODO: " + (isBlocked ? "Unblock " : "Block ") + " number %s.",
                      "TODO: Unblock number %s.",
                      blockReportSpamDialogInfo.getNormalizedNumber()),
                  Toast.LENGTH_SHORT)
              .show();
        }
        return true; // Close the bottom sheet.
      }
    };
Loading