Commit 38330845 authored by cco3's avatar cco3 Committed by Commit bot

Add Opt-in notification UMA for the Physical Web

BUG=529962

Review URL: https://codereview.chromium.org/1544863003

Cr-Commit-Position: refs/heads/master@{#367125}
parent cd1d0628
......@@ -22,11 +22,13 @@ public class PhysicalWebOptInActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.physical_web_optin);
PhysicalWebUma.onOptInNotificationPressed(this);
Button declineButton = (Button) findViewById(R.id.physical_web_decline);
declineButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
PhysicalWebUma.onOptInDeclineButtonPressed(PhysicalWebOptInActivity.this);
PrivacyPreferencesManager privacyPrefManager =
PrivacyPreferencesManager.getInstance(PhysicalWebOptInActivity.this);
privacyPrefManager.setPhysicalWebEnabled(false);
......@@ -38,6 +40,7 @@ public class PhysicalWebOptInActivity extends AppCompatActivity {
enableButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
PhysicalWebUma.onOptInEnableButtonPressed(PhysicalWebOptInActivity.this);
PrivacyPreferencesManager privacyPrefManager =
PrivacyPreferencesManager.getInstance(PhysicalWebOptInActivity.this);
privacyPrefManager.setPhysicalWebEnabled(true);
......
......@@ -27,6 +27,16 @@ import javax.annotation.concurrent.ThreadSafe;
public class PhysicalWebUma {
private static final String TAG = "PhysicalWeb";
private static final String NOTIFICATION_PRESS_COUNT = "PhysicalWeb.NotificationPressed";
private static final String OPT_IN_DECLINE_BUTTON_PRESS_COUNT =
"PhysicalWeb.OptIn.DeclineButtonPressed";
private static final String OPT_IN_ENABLE_BUTTON_PRESS_COUNT =
"PhysicalWeb.OptIn.EnableButtonPressed";
private static final String OPT_IN_HIGH_PRIORITY_NOTIFICATION_COUNT =
"PhysicalWeb.OptIn.HighPriorityNotificationShown";
private static final String OPT_IN_MIN_PRIORITY_NOTIFICATION_COUNT =
"PhysicalWeb.OptIn.MinPriorityNotificationShown";
private static final String OPT_IN_NOTIFICATION_PRESS_COUNT =
"PhysicalWeb.OptIn.NotificationPressed";
private static final String PREFS_FEATURE_DISABLED_COUNT = "PhysicalWeb.Prefs.FeatureDisabled";
private static final String PREFS_FEATURE_ENABLED_COUNT = "PhysicalWeb.Prefs.FeatureEnabled";
private static final String PREFS_LOCATION_DENIED_COUNT = "PhysicalWeb.Prefs.LocationDenied";
......@@ -52,6 +62,41 @@ public class PhysicalWebUma {
}
/**
* Records a tap on the opt-in decline button.
*/
public static void onOptInDeclineButtonPressed(Context context) {
handleAction(context, OPT_IN_DECLINE_BUTTON_PRESS_COUNT);
}
/**
* Records a tap on the opt-in enable button.
*/
public static void onOptInEnableButtonPressed(Context context) {
handleAction(context, OPT_IN_ENABLE_BUTTON_PRESS_COUNT);
}
/**
* Records a display of a high priority opt-in notification.
*/
public static void onOptInHighPriorityNotificationShown(Context context) {
handleAction(context, OPT_IN_HIGH_PRIORITY_NOTIFICATION_COUNT);
}
/**
* Records a display of a min priority opt-in notification.
*/
public static void onOptInMinPriorityNotificationShown(Context context) {
handleAction(context, OPT_IN_MIN_PRIORITY_NOTIFICATION_COUNT);
}
/**
* Records a display of the opt-in activity.
*/
public static void onOptInNotificationPressed(Context context) {
handleAction(context, OPT_IN_NOTIFICATION_PRESS_COUNT);
}
/*
* Records when the user disables the Physical Web fetaure.
*/
public static void onPrefsFeatureDisabled(Context context) {
......@@ -123,6 +168,13 @@ public class PhysicalWebUma {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
uploader.notificationPressCount = prefs.getInt(NOTIFICATION_PRESS_COUNT, 0);
uploader.urlSelectedCount = prefs.getInt(URL_SELECTED_COUNT, 0);
uploader.optInDeclineButtonTapCount = prefs.getInt(OPT_IN_DECLINE_BUTTON_PRESS_COUNT, 0);
uploader.optInEnableButtonTapCount = prefs.getInt(OPT_IN_ENABLE_BUTTON_PRESS_COUNT, 0);
uploader.optInHighPriorityNotificationCount =
prefs.getInt(OPT_IN_HIGH_PRIORITY_NOTIFICATION_COUNT, 0);
uploader.optInMinPriorityNotificationCount =
prefs.getInt(OPT_IN_MIN_PRIORITY_NOTIFICATION_COUNT, 0);
uploader.optInNotificationPressCount = prefs.getInt(OPT_IN_NOTIFICATION_PRESS_COUNT, 0);
uploader.prefsFeatureDisabledCount = prefs.getInt(PREFS_FEATURE_DISABLED_COUNT, 0);
uploader.prefsFeatureEnabledCount = prefs.getInt(PREFS_FEATURE_ENABLED_COUNT, 0);
uploader.prefsLocationDeniedCount = prefs.getInt(PREFS_LOCATION_DENIED_COUNT, 0);
......@@ -140,6 +192,11 @@ public class PhysicalWebUma {
prefs.edit()
.remove(NOTIFICATION_PRESS_COUNT)
.remove(URL_SELECTED_COUNT)
.remove(OPT_IN_DECLINE_BUTTON_PRESS_COUNT)
.remove(OPT_IN_ENABLE_BUTTON_PRESS_COUNT)
.remove(OPT_IN_HIGH_PRIORITY_NOTIFICATION_COUNT)
.remove(OPT_IN_MIN_PRIORITY_NOTIFICATION_COUNT)
.remove(OPT_IN_NOTIFICATION_PRESS_COUNT)
.remove(PREFS_FEATURE_DISABLED_COUNT)
.remove(PREFS_FEATURE_ENABLED_COUNT)
.remove(PREFS_LOCATION_DENIED_COUNT)
......@@ -194,6 +251,11 @@ public class PhysicalWebUma {
private static class UmaUploader implements Runnable {
public int notificationPressCount;
public int urlSelectedCount;
public int optInDeclineButtonTapCount;
public int optInEnableButtonTapCount;
public int optInHighPriorityNotificationCount;
public int optInMinPriorityNotificationCount;
public int optInNotificationPressCount;
public int prefsFeatureDisabledCount;
public int prefsFeatureEnabledCount;
public int prefsLocationDeniedCount;
......@@ -205,6 +267,11 @@ public class PhysicalWebUma {
public boolean isEmpty() {
return notificationPressCount == 0
&& urlSelectedCount == 0
&& optInDeclineButtonTapCount == 0
&& optInEnableButtonTapCount == 0
&& optInHighPriorityNotificationCount == 0
&& optInMinPriorityNotificationCount == 0
&& optInNotificationPressCount == 0
&& prefsFeatureDisabledCount == 0
&& prefsFeatureEnabledCount == 0
&& prefsLocationDeniedCount == 0
......@@ -221,6 +288,13 @@ public class PhysicalWebUma {
public void run() {
uploadActions(notificationPressCount, NOTIFICATION_PRESS_COUNT);
uploadActions(urlSelectedCount, URL_SELECTED_COUNT);
uploadActions(optInDeclineButtonTapCount, OPT_IN_DECLINE_BUTTON_PRESS_COUNT);
uploadActions(optInEnableButtonTapCount, OPT_IN_ENABLE_BUTTON_PRESS_COUNT);
uploadActions(optInHighPriorityNotificationCount,
OPT_IN_HIGH_PRIORITY_NOTIFICATION_COUNT);
uploadActions(optInMinPriorityNotificationCount,
OPT_IN_MIN_PRIORITY_NOTIFICATION_COUNT);
uploadActions(optInNotificationPressCount, OPT_IN_NOTIFICATION_PRESS_COUNT);
uploadActions(prefsFeatureDisabledCount, PREFS_FEATURE_DISABLED_COUNT);
uploadActions(prefsFeatureEnabledCount, PREFS_FEATURE_ENABLED_COUNT);
uploadActions(prefsLocationDeniedCount, PREFS_LOCATION_DENIED_COUNT);
......
......@@ -277,9 +277,11 @@ class UrlManager {
// high priority notification
createOptInNotification(true);
PhysicalWeb.recordOptInNotification(mContext);
PhysicalWebUma.onOptInHighPriorityNotificationShown(mContext);
} else {
// min priority notification
createOptInNotification(false);
PhysicalWebUma.onOptInMinPriorityNotificationShown(mContext);
}
return;
}
......
......@@ -11173,6 +11173,51 @@ should be able to be added at any place in this file.
</description>
</action>
<action name="PhysicalWeb.OptIn.DeclineButtonPressed">
<owner>cco3@chromium.org</owner>
<owner>mattreynolds@chromium.org</owner>
<owner>mmocny@chromium.org</owner>
<description>
The user has disabled the Physical Web feature via the settings.
</description>
</action>
<action name="PhysicalWeb.OptIn.EnableButtonPressed">
<owner>cco3@chromium.org</owner>
<owner>mattreynolds@chromium.org</owner>
<owner>mmocny@chromium.org</owner>
<description>
The enable button was pressed in the Physical Web opt-in activity.
</description>
</action>
<action name="PhysicalWeb.OptIn.HighPriorityNotificationShown">
<owner>cco3@chromium.org</owner>
<owner>mattreynolds@chromium.org</owner>
<owner>mmocny@chromium.org</owner>
<description>
A high priority Physical Web opt-in notification was displayed.
</description>
</action>
<action name="PhysicalWeb.OptIn.MinPriorityNotificationShown">
<owner>cco3@chromium.org</owner>
<owner>mattreynolds@chromium.org</owner>
<owner>mmocny@chromium.org</owner>
<description>
A min priority Physical Web opt-in notification was displayed.
</description>
</action>
<action name="PhysicalWeb.OptIn.NotificationPressed">
<owner>cco3@chromium.org</owner>
<owner>mattreynolds@chromium.org</owner>
<owner>mmocny@chromium.org</owner>
<description>
The user pressed the Physical Web opt-in notification.
</description>
</action>
<action name="PhysicalWeb.Prefs.FeatureDisabled">
<owner>cco3@chromium.org</owner>
<owner>mattreynolds@chromium.org</owner>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment