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

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

Merge changes I513e1111,Ie1b1f439 am: 683fdb16

am: 9b675ebd

Change-Id: Ib68758c5e736a997e9767b6c78529b430823da6f
parents e87def98 9b675ebd
Loading
Loading
Loading
Loading
+39 −2
Original line number Original line Diff line number Diff line
@@ -264,8 +264,8 @@ public final class BlockReportSpamDialogs {
  /**
  /**
   * Dialog for unblocking a number and marking it as not spam.
   * 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
   * <p>This dialog is used in the old call log, where unblocking a number will also mark it as not
   * not spam.
   * spam.
   */
   */
  public static class DialogFragmentForUnblockingNumberAndReportingAsNotSpam
  public static class DialogFragmentForUnblockingNumberAndReportingAsNotSpam
      extends CommonDialogsFragment {
      extends CommonDialogsFragment {
@@ -310,6 +310,43 @@ public final class BlockReportSpamDialogs {
    }
    }
  }
  }


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

    public static DialogFragment newInstance(
        String displayNumber,
        OnConfirmListener positiveListener,
        @Nullable DialogInterface.OnDismissListener dismissListener) {
      DialogFragmentForUnblockingNumberAndReportingAsNotSpam fragment =
          new DialogFragmentForUnblockingNumberAndReportingAsNotSpam();
      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);
      alertDialogBuilder.setMessage(
          getString(R.string.unblock_report_number_alert_title, displayNumber));
      Dialog dialog =
          alertDialogBuilder
              .setPositiveButton(
                  R.string.unblock_number_ok, createGenericOnClickListener(this, positiveListener))
              .create();
      dialog.setCanceledOnTouchOutside(true);
      return dialog;
    }
  }

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


+13 −0
Original line number Original line Diff line number Diff line
@@ -72,4 +72,17 @@ public final class ShowBlockReportSpamDialogNotifier {


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

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

    Intent intent = new Intent();
    intent.setAction(ShowBlockReportSpamDialogReceiver.ACTION_SHOW_DIALOG_TO_UNBLOCK_NUMBER);
    ProtoParsers.put(
        intent, ShowBlockReportSpamDialogReceiver.EXTRA_DIALOG_INFO, blockReportSpamDialogInfo);

    LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
  }
}
}
+109 −0
Original line number Original line Diff line number Diff line
@@ -21,19 +21,24 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Context;
import android.content.Intent;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.IntentFilter;
import android.support.annotation.Nullable;
import com.android.dialer.blocking.FilteredNumberAsyncQueryHandler;
import com.android.dialer.blocking.FilteredNumberAsyncQueryHandler;
import com.android.dialer.blockreportspam.BlockReportSpamDialogs.DialogFragmentForBlockingNumber;
import com.android.dialer.blockreportspam.BlockReportSpamDialogs.DialogFragmentForBlockingNumber;
import com.android.dialer.blockreportspam.BlockReportSpamDialogs.DialogFragmentForBlockingNumberAndOptionallyReportingAsSpam;
import com.android.dialer.blockreportspam.BlockReportSpamDialogs.DialogFragmentForBlockingNumberAndOptionallyReportingAsSpam;
import com.android.dialer.blockreportspam.BlockReportSpamDialogs.DialogFragmentForReportingNotSpam;
import com.android.dialer.blockreportspam.BlockReportSpamDialogs.DialogFragmentForReportingNotSpam;
import com.android.dialer.blockreportspam.BlockReportSpamDialogs.DialogFragmentForUnblockingNumber;
import com.android.dialer.blockreportspam.BlockReportSpamDialogs.OnConfirmListener;
import com.android.dialer.blockreportspam.BlockReportSpamDialogs.OnConfirmListener;
import com.android.dialer.blockreportspam.BlockReportSpamDialogs.OnSpamDialogClickListener;
import com.android.dialer.blockreportspam.BlockReportSpamDialogs.OnSpamDialogClickListener;
import com.android.dialer.common.Assert;
import com.android.dialer.common.Assert;
import com.android.dialer.common.LogUtil;
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.DialerImpression;
import com.android.dialer.logging.Logger;
import com.android.dialer.logging.Logger;
import com.android.dialer.protos.ProtoParsers;
import com.android.dialer.protos.ProtoParsers;
import com.android.dialer.spam.Spam;
import com.android.dialer.spam.Spam;
import com.android.dialer.spam.SpamComponent;
import com.android.dialer.spam.SpamComponent;
import com.google.auto.value.AutoValue;


/**
/**
 * A {@link BroadcastReceiver} that shows an appropriate dialog upon receiving notifications from
 * A {@link BroadcastReceiver} that shows an appropriate dialog upon receiving notifications from
@@ -45,6 +50,7 @@ public final class ShowBlockReportSpamDialogReceiver extends BroadcastReceiver {
  static final String ACTION_SHOW_DIALOG_TO_BLOCK_NUMBER_AND_OPTIONALLY_REPORT_SPAM =
  static final String ACTION_SHOW_DIALOG_TO_BLOCK_NUMBER_AND_OPTIONALLY_REPORT_SPAM =
      "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 ACTION_SHOW_DIALOG_TO_REPORT_NOT_SPAM = "show_dialog_to_report_not_spam";
  static final String ACTION_SHOW_DIALOG_TO_UNBLOCK_NUMBER = "show_dialog_to_unblock_number";
  static final String EXTRA_DIALOG_INFO = "dialog_info";
  static final String EXTRA_DIALOG_INFO = "dialog_info";


  /** {@link FragmentManager} needed to show a {@link android.app.DialogFragment}. */
  /** {@link FragmentManager} needed to show a {@link android.app.DialogFragment}. */
@@ -56,6 +62,7 @@ public final class ShowBlockReportSpamDialogReceiver extends BroadcastReceiver {
    intentFilter.addAction(ACTION_SHOW_DIALOG_TO_BLOCK_NUMBER_AND_OPTIONALLY_REPORT_SPAM);
    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_BLOCK_NUMBER);
    intentFilter.addAction(ACTION_SHOW_DIALOG_TO_REPORT_NOT_SPAM);
    intentFilter.addAction(ACTION_SHOW_DIALOG_TO_REPORT_NOT_SPAM);
    intentFilter.addAction(ACTION_SHOW_DIALOG_TO_UNBLOCK_NUMBER);
    return intentFilter;
    return intentFilter;
  }
  }


@@ -79,6 +86,9 @@ public final class ShowBlockReportSpamDialogReceiver extends BroadcastReceiver {
      case ACTION_SHOW_DIALOG_TO_REPORT_NOT_SPAM:
      case ACTION_SHOW_DIALOG_TO_REPORT_NOT_SPAM:
        showDialogToReportNotSpam(context, intent);
        showDialogToReportNotSpam(context, intent);
        break;
        break;
      case ACTION_SHOW_DIALOG_TO_UNBLOCK_NUMBER:
        showDialogToUnblockNumber(context, intent);
        break;
      default:
      default:
        throw new IllegalStateException("Unsupported action: " + action);
        throw new IllegalStateException("Unsupported action: " + action);
    }
    }
@@ -197,4 +207,103 @@ public final class ShowBlockReportSpamDialogReceiver extends BroadcastReceiver {
            dialogInfo.getNormalizedNumber(), onConfirmListener, /* dismissListener = */ null)
            dialogInfo.getNormalizedNumber(), onConfirmListener, /* dismissListener = */ null)
        .show(fragmentManager, BlockReportSpamDialogs.NOT_SPAM_DIALOG_TAG);
        .show(fragmentManager, BlockReportSpamDialogs.NOT_SPAM_DIALOG_TAG);
  }
  }

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

    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.showDialogToUnblockNumber", "confirmed");

          DialerExecutorComponent.get(context)
              .dialerExecutorFactory()
              .createNonUiTaskBuilder(
                  new GetIdForBlockedNumberWorker(filteredNumberAsyncQueryHandler))
              .onSuccess(
                  idForBlockedNumber -> {
                    LogUtil.i(
                        "ShowBlockReportSpamDialogReceiver.showDialogToUnblockNumber",
                        "ID for the blocked number retrieved");
                    if (idForBlockedNumber == null) {
                      throw new IllegalStateException("ID for a blocked number is null.");
                    }

                    LogUtil.i(
                        "ShowBlockReportSpamDialogReceiver.showDialogToUnblockNumber",
                        "unblocking number");
                    filteredNumberAsyncQueryHandler.unblock(
                        (rows, values) ->
                            Logger.get(context)
                                .logImpression(DialerImpression.Type.USER_ACTION_UNBLOCKED_NUMBER),
                        idForBlockedNumber);
                  })
              .onFailure(
                  throwable -> {
                    throw new RuntimeException(throwable);
                  })
              .build()
              .executeSerial(
                  NumberInfo.newBuilder()
                      .setNormalizedNumber(dialogInfo.getNormalizedNumber())
                      .setCountryIso(dialogInfo.getCountryIso())
                      .build());
        };

    // Create & show the dialog.
    DialogFragmentForUnblockingNumber.newInstance(
            dialogInfo.getNormalizedNumber(), onConfirmListener, /* dismissListener = */ null)
        .show(fragmentManager, BlockReportSpamDialogs.UNBLOCK_DIALOG_TAG);
  }

  /** A {@link Worker} that retrieves the ID of a blocked number from the database. */
  private static final class GetIdForBlockedNumberWorker implements Worker<NumberInfo, Integer> {

    private final FilteredNumberAsyncQueryHandler filteredNumberAsyncQueryHandler;

    GetIdForBlockedNumberWorker(FilteredNumberAsyncQueryHandler filteredNumberAsyncQueryHandler) {
      this.filteredNumberAsyncQueryHandler = filteredNumberAsyncQueryHandler;
    }

    @Nullable
    @Override
    public Integer doInBackground(NumberInfo input) throws Throwable {
      LogUtil.enterBlock("GetIdForBlockedNumberWorker.doInBackground");

      return filteredNumberAsyncQueryHandler.getBlockedIdSynchronous(
          input.getNormalizedNumber(), input.getCountryIso());
    }
  }

  /**
   * Contains information about a number and serves as the input to {@link
   * GetIdForBlockedNumberWorker}.
   */
  @AutoValue
  abstract static class NumberInfo {
    static Builder newBuilder() {
      return new AutoValue_ShowBlockReportSpamDialogReceiver_NumberInfo.Builder();
    }

    abstract String getNormalizedNumber();

    abstract String getCountryIso();

    @AutoValue.Builder
    abstract static class Builder {
      abstract Builder setNormalizedNumber(String normalizedNumber);

      abstract Builder setCountryIso(String countryIso);

      abstract NumberInfo build();
    }
  }
}
}
+4 −13
Original line number Original line Diff line number Diff line
@@ -22,7 +22,6 @@ import android.net.Uri;
import android.provider.ContactsContract;
import android.provider.ContactsContract;
import android.support.annotation.Nullable;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.text.TextUtils;
import android.widget.Toast;
import com.android.dialer.DialerPhoneNumber;
import com.android.dialer.DialerPhoneNumber;
import com.android.dialer.blockreportspam.BlockReportSpamDialogInfo;
import com.android.dialer.blockreportspam.BlockReportSpamDialogInfo;
import com.android.dialer.blockreportspam.ShowBlockReportSpamDialogNotifier;
import com.android.dialer.blockreportspam.ShowBlockReportSpamDialogNotifier;
@@ -32,7 +31,6 @@ import com.android.dialer.util.UriUtils;
import com.google.common.base.Optional;
import com.google.common.base.Optional;
import java.util.ArrayList;
import java.util.ArrayList;
import java.util.List;
import java.util.List;
import java.util.Locale;


/**
/**
 * Modules for the bottom sheet that are shared between NewVoicemailFragment and NewCallLogFragment
 * Modules for the bottom sheet that are shared between NewVoicemailFragment and NewCallLogFragment
@@ -187,19 +185,12 @@ public class SharedModules {


      @Override
      @Override
      public boolean onClick() {
      public boolean onClick() {
        if (!isBlocked) {
        if (isBlocked) {
          ShowBlockReportSpamDialogNotifier.notifyShowDialogToBlockNumber(
          ShowBlockReportSpamDialogNotifier.notifyShowDialogToUnblockNumber(
              context, blockReportSpamDialogInfo);
              context, blockReportSpamDialogInfo);
        } else {
        } else {
          // TODO(a bug): implement this method.
          ShowBlockReportSpamDialogNotifier.notifyShowDialogToBlockNumber(
          Toast.makeText(
              context, blockReportSpamDialogInfo);
                  context,
                  String.format(
                      Locale.ENGLISH,
                      "TODO: Unblock number %s.",
                      blockReportSpamDialogInfo.getNormalizedNumber()),
                  Toast.LENGTH_SHORT)
              .show();
        }
        }
        return true; // Close the bottom sheet.
        return true; // Close the bottom sheet.
      }
      }
+0 −21
Original line number Original line Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
  ~ Copyright (C) 2018 The Android Open Source Project
  ~
  ~ Licensed under the Apache License, Version 2.0 (the "License");
  ~ you may not use this file except in compliance with the License.
  ~ You may obtain a copy of the License at
  ~
  ~      http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License
  -->

<resources>
  <!-- Flag to control whether to disable phone number formatting -->
  <bool name="motorola_disable_phone_number_formatting">true</bool>
</resources>
Loading