Skip to content

Commit

Permalink
[VCN][M2] Metrics for Clank
Browse files Browse the repository at this point in the history
This CL adds VCN metrics for Clank:
1. Enrollment / unenrollment metrics from Clank settings page.
2. Infobar metrics via the native controller.

(cherry picked from commit a5aa93a)

Bug: 1302747
Change-Id: I43d83a274d7ad362b2b5f2e0bf6d0b100ebb3c06
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3497535
Reviewed-by: Siyu An <siyua@chromium.org>
Reviewed-by: Siddharth Shah <siashah@chromium.org>
Reviewed-by: Ioana Pandele <ioanap@chromium.org>
Reviewed-by: Mohamed Amir Yosef <mamir@chromium.org>
Reviewed-by: Jared Saul <jsaul@google.com>
Commit-Queue: Vishwas Uppoor <vishwasuppoor@google.com>
Cr-Original-Commit-Position: refs/heads/main@{#981328}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3531468
Reviewed-by: Krishna Govind <govind@chromium.org>
Commit-Queue: Krishna Govind <govind@chromium.org>
Owners-Override: Krishna Govind <govind@chromium.org>
Cr-Commit-Position: refs/branch-heads/4896@{#677}
Cr-Branched-From: 1f63ff4-refs/heads/main@{#972766}
  • Loading branch information
Vishwas Uppoor authored and Chromium LUCI CQ committed Mar 18, 2022
1 parent 237202a commit 3911a4b
Show file tree
Hide file tree
Showing 9 changed files with 251 additions and 24 deletions.
Expand Up @@ -32,9 +32,9 @@
import androidx.core.widget.TextViewCompat;

import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.Callback;
import org.chromium.base.ContextUtils;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.customtabs.CustomTabActivity;
import org.chromium.chrome.browser.feedback.HelpAndFeedbackLauncherImpl;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.ui.text.NoUnderlineClickableSpan;
Expand Down Expand Up @@ -77,6 +77,18 @@ public interface OffsetProvider {
int NONE = 7;
}

// Constants used to log UMA "enum" histograms about the type of links clicked in mobile virtual
// card dialogs. Entries should not be renumbered and numeric values should never be reused.
@IntDef({VirtualCardDialogLink.EDUCATION_TEXT, VirtualCardDialogLink.GOOGLE_LEGAL_MESSAGE,
VirtualCardDialogLink.ISSUER_LEGAL_MESSAGE, VirtualCardDialogLink.NUM_ENTRIES})
@Retention(RetentionPolicy.SOURCE)
public @interface VirtualCardDialogLink {
int EDUCATION_TEXT = 0;
int GOOGLE_LEGAL_MESSAGE = 1;
int ISSUER_LEGAL_MESSAGE = 2;
int NUM_ENTRIES = 3;
}

/**
* Launches the Autofill help page on top of the current @{link android.app.Activity} and
* current @{link Profile}.
Expand Down Expand Up @@ -389,16 +401,17 @@ public static void inlineTitleStringWithLogo(
*
* @param context The context used for fetching the required resources.
* @param legalMessageLines The list of LegalMessageLines to be represented as a string.
* @param onClickCallback The callback for the link clicks.
* @return A {@link SpannableStringBuilder} that can directly be set on a TextView.
*/
public static SpannableStringBuilder getSpannableStringForLegalMessageLines(
Context context, LinkedList<LegalMessageLine> legalMessageLines) {
public static SpannableStringBuilder getSpannableStringForLegalMessageLines(Context context,
LinkedList<LegalMessageLine> legalMessageLines, Callback<String> onClickCallback) {
SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder();
for (LegalMessageLine line : legalMessageLines) {
SpannableString text = new SpannableString(line.text);
for (final LegalMessageLine.Link link : line.links) {
text.setSpan(new NoUnderlineClickableSpan(context.getResources(),
(view) -> CustomTabActivity.showInfoPage(context, link.url)),
view -> onClickCallback.onResult(link.url)),
link.start, link.end, Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
}
spannableStringBuilder.append(text);
Expand All @@ -408,19 +421,19 @@ public static SpannableStringBuilder getSpannableStringForLegalMessageLines(

/**
* Returns a {@link SpannableString} containing a {@link NoUnderlineClickableSpan} for the text
* contained within the tags <link1></link1> and defaults to opening a the provided url in a
* custom tab.
* contained within the tags <link1></link1>.
* @param context The context required to fetch the resources.
* @param stringResourceId The resource id of the string on which the clickable span should be
* applied.
* @param url The url that should be opened when the clickable span is clicked.
* @param onClickCallback The callback for the link clicks.
* @return {@link SpannableString} that can be directly set on the TextView.
*/
public static SpannableString getSpannableStringWithClickableSpansToOpenLinksInCustomTabs(
Context context, int stringResourceId, String url) {
Context context, int stringResourceId, String url, Callback<String> onClickCallback) {
return SpanApplier.applySpans(context.getString(stringResourceId),
new SpanApplier.SpanInfo("<link1>", "</link1>",
new NoUnderlineClickableSpan(context.getResources(),
(view) -> CustomTabActivity.showInfoPage(context, url))));
new NoUnderlineClickableSpan(
context.getResources(), view -> onClickCallback.onResult(url))));
}
}
Expand Up @@ -16,6 +16,7 @@
import androidx.annotation.Nullable;

import org.chromium.base.annotations.UsedByReflection;
import org.chromium.base.metrics.RecordHistogram;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeStringConstants;
import org.chromium.chrome.browser.autofill.PersonalDataManager;
Expand Down Expand Up @@ -63,10 +64,14 @@ public View onCreateView(
((TextView) v.findViewById(R.id.title)).setText(mCard.getObfuscatedNumber());
((TextView) v.findViewById(R.id.summary))
.setText(mCard.getFormattedExpirationDate(getActivity()));
v.findViewById(R.id.edit_server_card)
.setOnClickListener(view
-> CustomTabActivity.showInfoPage(getActivity(),
ChromeStringConstants.AUTOFILL_MANAGE_WALLET_CARD_URL));
v.findViewById(R.id.edit_server_card).setOnClickListener(view -> {
RecordHistogram.recordBooleanHistogram(showVirtualCardEnrollmentButton()
? "Autofill.SettingsPage.ButtonClicked.VirtualCard.EditCard"
: "Autofill.SettingsPage.ButtonClicked.ServerCard.EditCard",
true);
CustomTabActivity.showInfoPage(
getActivity(), ChromeStringConstants.AUTOFILL_MANAGE_WALLET_CARD_URL);
});

final LinearLayout virtualCardContainerLayout =
(LinearLayout) v.findViewById(R.id.virtual_card_ui);
Expand All @@ -81,6 +86,10 @@ public View onCreateView(
: "mDelegate must be initialized before making (un)enrolment calls.";
final ModalDialogManager modalDialogManager = new ModalDialogManager(
new AppModalPresenter(getActivity()), ModalDialogType.APP);
RecordHistogram.recordBooleanHistogram(mVirtualCardEnrollmentButtonShowsUnenroll
? "Autofill.SettingsPage.ButtonClicked.VirtualCard.VirtualCardUnenroll"
: "Autofill.SettingsPage.ButtonClicked.VirtualCard.VirtualCardEnroll",
true);
if (!mVirtualCardEnrollmentButtonShowsUnenroll) {
mDelegate.offerVirtualCardEnrollment(mCard.getInstrumentId(),
result -> showVirtualCardEnrollmentDialog(result, modalDialogManager));
Expand Down
Expand Up @@ -12,9 +12,12 @@
import android.widget.TextView;

import org.chromium.base.Callback;
import org.chromium.base.metrics.RecordHistogram;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeStringConstants;
import org.chromium.chrome.browser.autofill.AutofillUiUtils;
import org.chromium.chrome.browser.autofill.AutofillUiUtils.VirtualCardDialogLink;
import org.chromium.chrome.browser.customtabs.CustomTabActivity;
import org.chromium.ui.modaldialog.DialogDismissalCause;
import org.chromium.ui.modaldialog.ModalDialogManager;
import org.chromium.ui.modaldialog.ModalDialogProperties;
Expand All @@ -23,6 +26,9 @@

/** Dialog shown to the user to enroll a credit card into the virtual card feature. */
public class AutofillVirtualCardEnrollmentDialog {
private static final String LINK_CLICK_HISTOGRAM =
"Autofill.VirtualCard.SettingsPageEnrollment.LinkClicked";

private final Context mContext;
private final ModalDialogManager mModalDialogManager;
private final VirtualCardEnrollmentFields mVirtualCardEnrollmentFields;
Expand Down Expand Up @@ -52,6 +58,9 @@ public void show() {
mContext.getString(R.string.no_thanks));
dialogModel.with(ModalDialogProperties.CONTROLLER,
new SimpleModalDialogController(mModalDialogManager, (action) -> {
RecordHistogram.recordBooleanHistogram(
"Autofill.VirtualCard.SettingsPageEnrollment",
action == DialogDismissalCause.POSITIVE_BUTTON_CLICKED);
mResultHandler.onResult(action == DialogDismissalCause.POSITIVE_BUTTON_CLICKED);
}));
mModalDialogManager.showDialog(dialogModel.build(), ModalDialogManager.ModalDialogType.APP);
Expand All @@ -71,19 +80,34 @@ private View getCustomViewForModalDialog() {
virtualCardEducationTextView.setText(
AutofillUiUtils.getSpannableStringWithClickableSpansToOpenLinksInCustomTabs(
mContext, R.string.autofill_virtual_card_enrollment_dialog_education_text,
ChromeStringConstants.AUTOFILL_VIRTUAL_CARD_ENROLLMENT_SUPPORT_URL));
ChromeStringConstants.AUTOFILL_VIRTUAL_CARD_ENROLLMENT_SUPPORT_URL, url -> {
RecordHistogram.recordEnumeratedHistogram(LINK_CLICK_HISTOGRAM,
VirtualCardDialogLink.EDUCATION_TEXT,
VirtualCardDialogLink.NUM_ENTRIES);
CustomTabActivity.showInfoPage(mContext, url);
}));
virtualCardEducationTextView.setMovementMethod(LinkMovementMethod.getInstance());

TextView googleLegalMessageTextView =
(TextView) customView.findViewById(R.id.google_legal_message);
googleLegalMessageTextView.setText(AutofillUiUtils.getSpannableStringForLegalMessageLines(
mContext, mVirtualCardEnrollmentFields.getGoogleLegalMessages()));
mContext, mVirtualCardEnrollmentFields.getGoogleLegalMessages(), url -> {
RecordHistogram.recordEnumeratedHistogram(LINK_CLICK_HISTOGRAM,
VirtualCardDialogLink.GOOGLE_LEGAL_MESSAGE,
VirtualCardDialogLink.NUM_ENTRIES);
CustomTabActivity.showInfoPage(mContext, url);
}));
googleLegalMessageTextView.setMovementMethod(LinkMovementMethod.getInstance());

TextView issuerLegalMessageTextView =
(TextView) customView.findViewById(R.id.issuer_legal_message);
issuerLegalMessageTextView.setText(AutofillUiUtils.getSpannableStringForLegalMessageLines(
mContext, mVirtualCardEnrollmentFields.getIssuerLegalMessages()));
mContext, mVirtualCardEnrollmentFields.getIssuerLegalMessages(), url -> {
RecordHistogram.recordEnumeratedHistogram(LINK_CLICK_HISTOGRAM,
VirtualCardDialogLink.ISSUER_LEGAL_MESSAGE,
VirtualCardDialogLink.NUM_ENTRIES);
CustomTabActivity.showInfoPage(mContext, url);
}));
issuerLegalMessageTextView.setMovementMethod(LinkMovementMethod.getInstance());

((TextView) customView.findViewById(R.id.credit_card_identifier))
Expand Down
Expand Up @@ -7,9 +7,12 @@
import android.content.Context;

import org.chromium.base.Callback;
import org.chromium.base.metrics.RecordHistogram;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeStringConstants;
import org.chromium.chrome.browser.autofill.AutofillUiUtils;
import org.chromium.chrome.browser.autofill.AutofillUiUtils.VirtualCardDialogLink;
import org.chromium.chrome.browser.customtabs.CustomTabActivity;
import org.chromium.ui.modaldialog.DialogDismissalCause;
import org.chromium.ui.modaldialog.ModalDialogManager;
import org.chromium.ui.modaldialog.ModalDialogProperties;
Expand Down Expand Up @@ -37,6 +40,9 @@ public AutofillVirtualCardUnenrollmentDialog(Context context,
public void show() {
SimpleModalDialogController modalDialogController =
new SimpleModalDialogController(mModalDialogManager, result -> {
RecordHistogram.recordBooleanHistogram(
"Autofill.VirtualCard.SettingsPageUnenrollment",
result == DialogDismissalCause.POSITIVE_BUTTON_CLICKED);
mResultHandler.onResult(result == DialogDismissalCause.POSITIVE_BUTTON_CLICKED);
});
PropertyModel.Builder builder =
Expand All @@ -50,7 +56,14 @@ public void show() {
mContext,
R.string.autofill_credit_card_editor_virtual_card_unenroll_dialog_message,
ChromeStringConstants
.AUTOFILL_VIRTUAL_CARD_ENROLLMENT_SUPPORT_URL))
.AUTOFILL_VIRTUAL_CARD_ENROLLMENT_SUPPORT_URL,
url -> {
RecordHistogram.recordEnumeratedHistogram(
"Autofill.VirtualCard.SettingsPageUnenrollment.LinkClicked",
VirtualCardDialogLink.EDUCATION_TEXT,
VirtualCardDialogLink.NUM_ENTRIES);
CustomTabActivity.showInfoPage(mContext, url);
}))
.with(ModalDialogProperties.POSITIVE_BUTTON_TEXT,
mContext.getString(
R.string.autofill_credit_card_editor_virtual_card_unenroll_dialog_positive_button_label))
Expand Down

0 comments on commit 3911a4b

Please sign in to comment.