summaryrefslogtreecommitdiff
path: root/java/com/android/dialer/historyitemactions/HistoryItemActionModulesBuilder.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/com/android/dialer/historyitemactions/HistoryItemActionModulesBuilder.java')
-rw-r--r--java/com/android/dialer/historyitemactions/HistoryItemActionModulesBuilder.java132
1 files changed, 122 insertions, 10 deletions
diff --git a/java/com/android/dialer/historyitemactions/HistoryItemActionModulesBuilder.java b/java/com/android/dialer/historyitemactions/HistoryItemActionModulesBuilder.java
index 0e78d70f5..917aa953d 100644
--- a/java/com/android/dialer/historyitemactions/HistoryItemActionModulesBuilder.java
+++ b/java/com/android/dialer/historyitemactions/HistoryItemActionModulesBuilder.java
@@ -21,6 +21,7 @@ import android.content.Intent;
import android.net.Uri;
import android.provider.CallLog.Calls;
import android.provider.ContactsContract;
+import android.support.annotation.IntDef;
import android.text.TextUtils;
import com.android.dialer.blockreportspam.BlockReportSpamDialogInfo;
import com.android.dialer.callintent.CallInitiationType;
@@ -29,13 +30,19 @@ import com.android.dialer.clipboard.ClipboardUtils;
import com.android.dialer.common.Assert;
import com.android.dialer.duo.Duo;
import com.android.dialer.duo.DuoComponent;
+import com.android.dialer.logging.DialerImpression;
import com.android.dialer.logging.ReportingLocation;
import com.android.dialer.spam.Spam;
import com.android.dialer.util.CallUtil;
import com.android.dialer.util.PermissionsUtil;
import com.android.dialer.util.UriUtils;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.List;
+import java.util.Optional;
/**
* Builds a list of {@link HistoryItemActionModule HistoryItemActionModules}.
@@ -76,6 +83,54 @@ import java.util.List;
*/
public final class HistoryItemActionModulesBuilder {
+ /** Represents events when a module is tapped by the user. */
+ @Retention(RetentionPolicy.SOURCE)
+ @IntDef({
+ Event.ADD_TO_CONTACT,
+ Event.BLOCK_NUMBER,
+ Event.BLOCK_NUMBER_AND_REPORT_SPAM,
+ Event.REPORT_NOT_SPAM,
+ Event.REQUEST_CARRIER_VIDEO_CALL,
+ Event.REQUEST_DUO_VIDEO_CALL,
+ Event.REQUEST_DUO_VIDEO_CALL_FOR_NON_CONTACT,
+ Event.SEND_TEXT_MESSAGE,
+ Event.UNBLOCK_NUMBER
+ })
+ @interface Event {
+ int ADD_TO_CONTACT = 1;
+ int BLOCK_NUMBER = 2;
+ int BLOCK_NUMBER_AND_REPORT_SPAM = 3;
+ int REPORT_NOT_SPAM = 4;
+ int REQUEST_CARRIER_VIDEO_CALL = 5;
+ int REQUEST_DUO_VIDEO_CALL = 6;
+ int REQUEST_DUO_VIDEO_CALL_FOR_NON_CONTACT = 7;
+ int SEND_TEXT_MESSAGE = 8;
+ int UNBLOCK_NUMBER = 9;
+ }
+
+ /**
+ * Maps each {@link Event} to a {@link DialerImpression.Type} to be logged when the modules are
+ * hosted by the call log.
+ */
+ private static final ImmutableMap<Integer, DialerImpression.Type> CALL_LOG_IMPRESSIONS =
+ new ImmutableMap.Builder<Integer, DialerImpression.Type>()
+ .put(Event.ADD_TO_CONTACT, DialerImpression.Type.ADD_TO_A_CONTACT_FROM_CALL_LOG)
+ .put(Event.BLOCK_NUMBER, DialerImpression.Type.CALL_LOG_BLOCK_NUMBER)
+ .put(Event.BLOCK_NUMBER_AND_REPORT_SPAM, DialerImpression.Type.CALL_LOG_BLOCK_REPORT_SPAM)
+ .put(Event.REPORT_NOT_SPAM, DialerImpression.Type.CALL_LOG_REPORT_AS_NOT_SPAM)
+ .put(
+ Event.REQUEST_CARRIER_VIDEO_CALL,
+ DialerImpression.Type.IMS_VIDEO_REQUESTED_FROM_CALL_LOG)
+ .put(
+ Event.REQUEST_DUO_VIDEO_CALL,
+ DialerImpression.Type.LIGHTBRINGER_VIDEO_REQUESTED_FROM_CALL_LOG)
+ .put(
+ Event.REQUEST_DUO_VIDEO_CALL_FOR_NON_CONTACT,
+ DialerImpression.Type.LIGHTBRINGER_NON_CONTACT_VIDEO_REQUESTED_FROM_CALL_LOG)
+ .put(Event.SEND_TEXT_MESSAGE, DialerImpression.Type.CALL_LOG_SEND_MESSAGE)
+ .put(Event.UNBLOCK_NUMBER, DialerImpression.Type.CALL_LOG_UNBLOCK_NUMBER)
+ .build();
+
private final Context context;
private final HistoryItemActionModuleInfo moduleInfo;
private final List<HistoryItemActionModule> modules;
@@ -158,7 +213,14 @@ public final class HistoryItemActionModulesBuilder {
// If the module info is for a video call, add an appropriate video call module.
if ((moduleInfo.getFeatures() & Calls.FEATURES_VIDEO) == Calls.FEATURES_VIDEO) {
- modules.add(IntentModule.newCallModule(context, callIntentBuilder.setIsDuoCall(isDuoCall())));
+ boolean isDuoCall = isDuoCall();
+ modules.add(
+ IntentModule.newCallModule(
+ context,
+ callIntentBuilder.setIsDuoCall(isDuoCall),
+ isDuoCall
+ ? getImpressionsForDuoVideoCall()
+ : getImpressions(Event.REQUEST_CARRIER_VIDEO_CALL)));
return this;
}
@@ -167,14 +229,29 @@ public final class HistoryItemActionModulesBuilder {
//
// The carrier video call module takes precedence over the Duo module.
if (canPlaceCarrierVideoCall()) {
- modules.add(IntentModule.newCallModule(context, callIntentBuilder));
+ modules.add(
+ IntentModule.newCallModule(
+ context, callIntentBuilder, getImpressions(Event.REQUEST_CARRIER_VIDEO_CALL)));
} else if (canPlaceDuoCall()) {
- modules.add(IntentModule.newCallModule(context, callIntentBuilder.setIsDuoCall(true)));
+ modules.add(
+ IntentModule.newCallModule(
+ context, callIntentBuilder.setIsDuoCall(true), getImpressionsForDuoVideoCall()));
}
return this;
}
/**
+ * Returns a list of impressions to be logged when the user taps the module that attempts to
+ * initiate a Duo video call.
+ */
+ private ImmutableList<DialerImpression.Type> getImpressionsForDuoVideoCall() {
+ return isExistingContact()
+ ? getImpressions(Event.REQUEST_DUO_VIDEO_CALL)
+ : getImpressions(
+ Event.REQUEST_DUO_VIDEO_CALL, Event.REQUEST_DUO_VIDEO_CALL_FOR_NON_CONTACT);
+ }
+
+ /**
* Adds a module for sending text messages.
*
* <p>The method is a no-op if
@@ -199,7 +276,8 @@ public final class HistoryItemActionModulesBuilder {
}
modules.add(
- IntentModule.newModuleForSendingTextMessage(context, moduleInfo.getNormalizedNumber()));
+ IntentModule.newModuleForSendingTextMessage(
+ context, moduleInfo.getNormalizedNumber(), getImpressions(Event.SEND_TEXT_MESSAGE)));
return this;
}
@@ -256,7 +334,8 @@ public final class HistoryItemActionModulesBuilder {
context,
intent,
R.string.add_to_contacts,
- R.drawable.quantum_ic_person_add_vd_theme_24));
+ R.drawable.quantum_ic_person_add_vd_theme_24,
+ getImpressions(Event.ADD_TO_CONTACT)));
return this;
}
@@ -302,11 +381,13 @@ public final class HistoryItemActionModulesBuilder {
if (Spam.shouldShowAsSpam(moduleInfo.getIsSpam(), moduleInfo.getCallType())) {
modules.add(
BlockReportSpamModules.moduleForMarkingNumberAsNotSpam(
- context, blockReportSpamDialogInfo));
+ context, blockReportSpamDialogInfo, getImpression(Event.REPORT_NOT_SPAM)));
modules.add(
moduleInfo.getIsBlocked()
- ? BlockReportSpamModules.moduleForUnblockingNumber(context, blockReportSpamDialogInfo)
- : BlockReportSpamModules.moduleForBlockingNumber(context, blockReportSpamDialogInfo));
+ ? BlockReportSpamModules.moduleForUnblockingNumber(
+ context, blockReportSpamDialogInfo, getImpression(Event.UNBLOCK_NUMBER))
+ : BlockReportSpamModules.moduleForBlockingNumber(
+ context, blockReportSpamDialogInfo, getImpression(Event.BLOCK_NUMBER)));
return this;
}
@@ -314,7 +395,8 @@ public final class HistoryItemActionModulesBuilder {
// "Unblock" module.
if (moduleInfo.getIsBlocked()) {
modules.add(
- BlockReportSpamModules.moduleForUnblockingNumber(context, blockReportSpamDialogInfo));
+ BlockReportSpamModules.moduleForUnblockingNumber(
+ context, blockReportSpamDialogInfo, getImpression(Event.UNBLOCK_NUMBER)));
return this;
}
@@ -322,7 +404,7 @@ public final class HistoryItemActionModulesBuilder {
// spam, add the "Block/Report spam" module.
modules.add(
BlockReportSpamModules.moduleForBlockingNumberAndOptionallyReportingSpam(
- context, blockReportSpamDialogInfo));
+ context, blockReportSpamDialogInfo, getImpression(Event.BLOCK_NUMBER_AND_REPORT_SPAM)));
return this;
}
@@ -437,4 +519,34 @@ public final class HistoryItemActionModulesBuilder {
String.format("Unsupported host: %s", moduleInfo.getHost()));
}
}
+
+ /** Returns a list of impressions to be logged for the given {@link Event events}. */
+ private ImmutableList<DialerImpression.Type> getImpressions(@Event int... events) {
+ Assert.isNotNull(events);
+
+ ImmutableList.Builder<DialerImpression.Type> impressionListBuilder =
+ new ImmutableList.Builder<>();
+ for (@Event int event : events) {
+ getImpression(event).ifPresent(impressionListBuilder::add);
+ }
+
+ return impressionListBuilder.build();
+ }
+
+ /**
+ * Returns an impression to be logged for the given {@link Event}, or {@link Optional#empty()} if
+ * no impression is available for the event.
+ */
+ private Optional<DialerImpression.Type> getImpression(@Event int event) {
+ switch (moduleInfo.getHost()) {
+ case CALL_LOG:
+ return Optional.of(CALL_LOG_IMPRESSIONS.get(event));
+ case VOICEMAIL:
+ // TODO(a bug): Return proper impressions for voicemail.
+ return Optional.empty();
+ default:
+ throw Assert.createUnsupportedOperationFailException(
+ String.format("Unsupported host: %s", moduleInfo.getHost()));
+ }
+ }
}