summaryrefslogtreecommitdiff
path: root/java/com/android/dialer/blockreportspam
diff options
context:
space:
mode:
authorlinyuh <linyuh@google.com>2018-02-28 09:49:44 -0800
committerCopybara-Service <copybara-piper@google.com>2018-02-28 09:50:52 -0800
commit81670b01f8a43ee1036295f1c8b1c51398016b1e (patch)
tree356835e57e3e37e959ff951efe07604282a1a757 /java/com/android/dialer/blockreportspam
parentac3d0e58f15c1d38583f6bcecf20275cbbf17b35 (diff)
Group info needed to show a block/report spam dialog into a proto to avoid long method signatures.
Test: Existing tests PiperOrigin-RevId: 187338094 Change-Id: I0d7a5206d127931d322b5604b2bb81f5202b8de8
Diffstat (limited to 'java/com/android/dialer/blockreportspam')
-rw-r--r--java/com/android/dialer/blockreportspam/ShowBlockReportSpamDialogNotifier.java46
-rw-r--r--java/com/android/dialer/blockreportspam/ShowBlockReportSpamDialogReceiver.java66
-rw-r--r--java/com/android/dialer/blockreportspam/block_report_spam_dialog_info.proto30
3 files changed, 62 insertions, 80 deletions
diff --git a/java/com/android/dialer/blockreportspam/ShowBlockReportSpamDialogNotifier.java b/java/com/android/dialer/blockreportspam/ShowBlockReportSpamDialogNotifier.java
index fd81568a8..58e1988fb 100644
--- a/java/com/android/dialer/blockreportspam/ShowBlockReportSpamDialogNotifier.java
+++ b/java/com/android/dialer/blockreportspam/ShowBlockReportSpamDialogNotifier.java
@@ -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);
}
diff --git a/java/com/android/dialer/blockreportspam/ShowBlockReportSpamDialogReceiver.java b/java/com/android/dialer/blockreportspam/ShowBlockReportSpamDialogReceiver.java
index 75b624198..364736efd 100644
--- a/java/com/android/dialer/blockreportspam/ShowBlockReportSpamDialogReceiver.java
+++ b/java/com/android/dialer/blockreportspam/ShowBlockReportSpamDialogReceiver.java
@@ -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);
}
}
diff --git a/java/com/android/dialer/blockreportspam/block_report_spam_dialog_info.proto b/java/com/android/dialer/blockreportspam/block_report_spam_dialog_info.proto
new file mode 100644
index 000000000..3c5a61652
--- /dev/null
+++ b/java/com/android/dialer/blockreportspam/block_report_spam_dialog_info.proto
@@ -0,0 +1,30 @@
+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