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 { ...@@ -22,11 +22,13 @@ public class PhysicalWebOptInActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.physical_web_optin); setContentView(R.layout.physical_web_optin);
PhysicalWebUma.onOptInNotificationPressed(this);
Button declineButton = (Button) findViewById(R.id.physical_web_decline); Button declineButton = (Button) findViewById(R.id.physical_web_decline);
declineButton.setOnClickListener(new View.OnClickListener() { declineButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
PhysicalWebUma.onOptInDeclineButtonPressed(PhysicalWebOptInActivity.this);
PrivacyPreferencesManager privacyPrefManager = PrivacyPreferencesManager privacyPrefManager =
PrivacyPreferencesManager.getInstance(PhysicalWebOptInActivity.this); PrivacyPreferencesManager.getInstance(PhysicalWebOptInActivity.this);
privacyPrefManager.setPhysicalWebEnabled(false); privacyPrefManager.setPhysicalWebEnabled(false);
...@@ -38,6 +40,7 @@ public class PhysicalWebOptInActivity extends AppCompatActivity { ...@@ -38,6 +40,7 @@ public class PhysicalWebOptInActivity extends AppCompatActivity {
enableButton.setOnClickListener(new View.OnClickListener() { enableButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
PhysicalWebUma.onOptInEnableButtonPressed(PhysicalWebOptInActivity.this);
PrivacyPreferencesManager privacyPrefManager = PrivacyPreferencesManager privacyPrefManager =
PrivacyPreferencesManager.getInstance(PhysicalWebOptInActivity.this); PrivacyPreferencesManager.getInstance(PhysicalWebOptInActivity.this);
privacyPrefManager.setPhysicalWebEnabled(true); privacyPrefManager.setPhysicalWebEnabled(true);
...@@ -53,4 +56,4 @@ public class PhysicalWebOptInActivity extends AppCompatActivity { ...@@ -53,4 +56,4 @@ public class PhysicalWebOptInActivity extends AppCompatActivity {
ListUrlsActivity.OPTIN_REFERER); ListUrlsActivity.OPTIN_REFERER);
return intent; return intent;
} }
} }
\ No newline at end of file
...@@ -27,6 +27,16 @@ import javax.annotation.concurrent.ThreadSafe; ...@@ -27,6 +27,16 @@ import javax.annotation.concurrent.ThreadSafe;
public class PhysicalWebUma { public class PhysicalWebUma {
private static final String TAG = "PhysicalWeb"; private static final String TAG = "PhysicalWeb";
private static final String NOTIFICATION_PRESS_COUNT = "PhysicalWeb.NotificationPressed"; 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_DISABLED_COUNT = "PhysicalWeb.Prefs.FeatureDisabled";
private static final String PREFS_FEATURE_ENABLED_COUNT = "PhysicalWeb.Prefs.FeatureEnabled"; private static final String PREFS_FEATURE_ENABLED_COUNT = "PhysicalWeb.Prefs.FeatureEnabled";
private static final String PREFS_LOCATION_DENIED_COUNT = "PhysicalWeb.Prefs.LocationDenied"; private static final String PREFS_LOCATION_DENIED_COUNT = "PhysicalWeb.Prefs.LocationDenied";
...@@ -52,6 +62,41 @@ public class PhysicalWebUma { ...@@ -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. * Records when the user disables the Physical Web fetaure.
*/ */
public static void onPrefsFeatureDisabled(Context context) { public static void onPrefsFeatureDisabled(Context context) {
...@@ -123,6 +168,13 @@ public class PhysicalWebUma { ...@@ -123,6 +168,13 @@ public class PhysicalWebUma {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
uploader.notificationPressCount = prefs.getInt(NOTIFICATION_PRESS_COUNT, 0); uploader.notificationPressCount = prefs.getInt(NOTIFICATION_PRESS_COUNT, 0);
uploader.urlSelectedCount = prefs.getInt(URL_SELECTED_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.prefsFeatureDisabledCount = prefs.getInt(PREFS_FEATURE_DISABLED_COUNT, 0);
uploader.prefsFeatureEnabledCount = prefs.getInt(PREFS_FEATURE_ENABLED_COUNT, 0); uploader.prefsFeatureEnabledCount = prefs.getInt(PREFS_FEATURE_ENABLED_COUNT, 0);
uploader.prefsLocationDeniedCount = prefs.getInt(PREFS_LOCATION_DENIED_COUNT, 0); uploader.prefsLocationDeniedCount = prefs.getInt(PREFS_LOCATION_DENIED_COUNT, 0);
...@@ -140,6 +192,11 @@ public class PhysicalWebUma { ...@@ -140,6 +192,11 @@ public class PhysicalWebUma {
prefs.edit() prefs.edit()
.remove(NOTIFICATION_PRESS_COUNT) .remove(NOTIFICATION_PRESS_COUNT)
.remove(URL_SELECTED_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_DISABLED_COUNT)
.remove(PREFS_FEATURE_ENABLED_COUNT) .remove(PREFS_FEATURE_ENABLED_COUNT)
.remove(PREFS_LOCATION_DENIED_COUNT) .remove(PREFS_LOCATION_DENIED_COUNT)
...@@ -194,6 +251,11 @@ public class PhysicalWebUma { ...@@ -194,6 +251,11 @@ public class PhysicalWebUma {
private static class UmaUploader implements Runnable { private static class UmaUploader implements Runnable {
public int notificationPressCount; public int notificationPressCount;
public int urlSelectedCount; public int urlSelectedCount;
public int optInDeclineButtonTapCount;
public int optInEnableButtonTapCount;
public int optInHighPriorityNotificationCount;
public int optInMinPriorityNotificationCount;
public int optInNotificationPressCount;
public int prefsFeatureDisabledCount; public int prefsFeatureDisabledCount;
public int prefsFeatureEnabledCount; public int prefsFeatureEnabledCount;
public int prefsLocationDeniedCount; public int prefsLocationDeniedCount;
...@@ -205,6 +267,11 @@ public class PhysicalWebUma { ...@@ -205,6 +267,11 @@ public class PhysicalWebUma {
public boolean isEmpty() { public boolean isEmpty() {
return notificationPressCount == 0 return notificationPressCount == 0
&& urlSelectedCount == 0 && urlSelectedCount == 0
&& optInDeclineButtonTapCount == 0
&& optInEnableButtonTapCount == 0
&& optInHighPriorityNotificationCount == 0
&& optInMinPriorityNotificationCount == 0
&& optInNotificationPressCount == 0
&& prefsFeatureDisabledCount == 0 && prefsFeatureDisabledCount == 0
&& prefsFeatureEnabledCount == 0 && prefsFeatureEnabledCount == 0
&& prefsLocationDeniedCount == 0 && prefsLocationDeniedCount == 0
...@@ -221,6 +288,13 @@ public class PhysicalWebUma { ...@@ -221,6 +288,13 @@ public class PhysicalWebUma {
public void run() { public void run() {
uploadActions(notificationPressCount, NOTIFICATION_PRESS_COUNT); uploadActions(notificationPressCount, NOTIFICATION_PRESS_COUNT);
uploadActions(urlSelectedCount, URL_SELECTED_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(prefsFeatureDisabledCount, PREFS_FEATURE_DISABLED_COUNT);
uploadActions(prefsFeatureEnabledCount, PREFS_FEATURE_ENABLED_COUNT); uploadActions(prefsFeatureEnabledCount, PREFS_FEATURE_ENABLED_COUNT);
uploadActions(prefsLocationDeniedCount, PREFS_LOCATION_DENIED_COUNT); uploadActions(prefsLocationDeniedCount, PREFS_LOCATION_DENIED_COUNT);
......
...@@ -277,9 +277,11 @@ class UrlManager { ...@@ -277,9 +277,11 @@ class UrlManager {
// high priority notification // high priority notification
createOptInNotification(true); createOptInNotification(true);
PhysicalWeb.recordOptInNotification(mContext); PhysicalWeb.recordOptInNotification(mContext);
PhysicalWebUma.onOptInHighPriorityNotificationShown(mContext);
} else { } else {
// min priority notification // min priority notification
createOptInNotification(false); createOptInNotification(false);
PhysicalWebUma.onOptInMinPriorityNotificationShown(mContext);
} }
return; return;
} }
......
...@@ -11173,6 +11173,51 @@ should be able to be added at any place in this file. ...@@ -11173,6 +11173,51 @@ should be able to be added at any place in this file.
</description> </description>
</action> </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"> <action name="PhysicalWeb.Prefs.FeatureDisabled">
<owner>cco3@chromium.org</owner> <owner>cco3@chromium.org</owner>
<owner>mattreynolds@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