summaryrefslogtreecommitdiff
path: root/java
diff options
context:
space:
mode:
authorTreehugger Robot <treehugger-gerrit@google.com>2018-02-28 19:16:20 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2018-02-28 19:16:20 +0000
commitd42fb78b9b5c2d42ab490df16c76c226d91040c8 (patch)
tree356835e57e3e37e959ff951efe07604282a1a757 /java
parentac3d0e58f15c1d38583f6bcecf20275cbbf17b35 (diff)
parent81670b01f8a43ee1036295f1c8b1c51398016b1e (diff)
Merge "Group info needed to show a block/report spam dialog into a proto to avoid long method signatures."
Diffstat (limited to 'java')
-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
-rw-r--r--java/com/android/dialer/calllog/ui/menu/Modules.java15
-rw-r--r--java/com/android/dialer/historyitemactions/SharedModules.java67
-rw-r--r--java/com/android/dialer/voicemail/listui/menu/Modules.java15
6 files changed, 99 insertions, 140 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
diff --git a/java/com/android/dialer/calllog/ui/menu/Modules.java b/java/com/android/dialer/calllog/ui/menu/Modules.java
index 147972710..9df122331 100644
--- a/java/com/android/dialer/calllog/ui/menu/Modules.java
+++ b/java/com/android/dialer/calllog/ui/menu/Modules.java
@@ -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);
diff --git a/java/com/android/dialer/historyitemactions/SharedModules.java b/java/com/android/dialer/historyitemactions/SharedModules.java
index 7cfee37bb..c0460862b 100644
--- a/java/com/android/dialer/historyitemactions/SharedModules.java
+++ b/java/com/android/dialer/historyitemactions/SharedModules.java
@@ -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.
}
};
diff --git a/java/com/android/dialer/voicemail/listui/menu/Modules.java b/java/com/android/dialer/voicemail/listui/menu/Modules.java
index 9473b80e1..cc7bcbe6d 100644
--- a/java/com/android/dialer/voicemail/listui/menu/Modules.java
+++ b/java/com/android/dialer/voicemail/listui/menu/Modules.java
@@ -17,6 +17,7 @@
package com.android.dialer.voicemail.listui.menu;
import android.content.Context;
+import com.android.dialer.blockreportspam.BlockReportSpamDialogInfo;
import com.android.dialer.historyitemactions.DividerModule;
import com.android.dialer.historyitemactions.HistoryItemActionModule;
import com.android.dialer.historyitemactions.SharedModules;
@@ -64,15 +65,19 @@ final class Modules {
modules.add(new DividerModule());
}
+ BlockReportSpamDialogInfo blockReportSpamDialogInfo =
+ BlockReportSpamDialogInfo.newBuilder()
+ .setNormalizedNumber(voicemailEntry.number().getNormalizedNumber())
+ .setCountryIso(voicemailEntry.number().getCountryIso())
+ .setCallType(voicemailEntry.callType())
+ .setReportingLocation(ReportingLocation.Type.VOICEMAIL_HISTORY)
+ .build();
modules.addAll(
SharedModules.createModulesHandlingBlockedOrSpamNumber(
context,
- voicemailEntry.number().getNormalizedNumber(),
- voicemailEntry.number().getCountryIso(),
- voicemailEntry.callType(),
+ blockReportSpamDialogInfo,
voicemailEntry.numberAttributes().getIsBlocked(),
- voicemailEntry.numberAttributes().getIsSpam(),
- ReportingLocation.Type.VOICEMAIL_HISTORY));
+ voicemailEntry.numberAttributes().getIsSpam()));
// TODO(zachh): Module for CallComposer.
Optional<HistoryItemActionModule> moduleForCopyingNumber =