Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(849)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/physicalweb/PhysicalWebUma.java

Issue 1814213004: Record UMA for Physical Web state (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Included utils.java in gn build Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/physicalweb/PhysicalWebUma.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/physicalweb/PhysicalWebUma.java b/chrome/android/java/src/org/chromium/chrome/browser/physicalweb/PhysicalWebUma.java
index 867f56f1888fb831258f4726a1a69a8c97382ca3..8f6d964cfc74e036908fb0dafccf12aa3490a2cf 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/physicalweb/PhysicalWebUma.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/physicalweb/PhysicalWebUma.java
@@ -53,6 +53,17 @@ public class PhysicalWebUma {
private static final String TOTAL_URLS_REFRESH_COUNTS =
"PhysicalWeb.TotalUrls.OnRefresh";
private static final String ACTIVITY_REFERRALS = "PhysicalWeb.ActivityReferral";
+ private static final String PHYSICAL_WEB_STATE = "PhysicalWeb.State";
+ private static final String CHROME_START = "ChromeStart";
+ private static final String LAUNCH_FROM_PREFERENCES = "LaunchFromPreferences";
+ private static final String LAUNCH_FROM_DIAGNOSTICS = "LaunchFromDiagnostics";
+ private static final String BLUETOOTH = "Bluetooth";
+ private static final String DATA_CONNECTION = "DataConnection";
+ private static final String LOCATION_PERMISSION = "LocationPermission";
+ private static final String LOCATION_SERVICES = "LocationServices";
+ private static final String PREFERENCE = "Preference";
+ private static final int BOOLEAN_BOUNDARY = 2;
+ private static final int TRISTATE_BOUNDARY = 3;
private static boolean sUploadAllowed = false;
/**
@@ -173,30 +184,63 @@ public class PhysicalWebUma {
* histograms.xml.
*/
public static void onActivityReferral(Context context, int referer) {
- if (sUploadAllowed) {
- RecordHistogram.recordEnumeratedHistogram(
- ACTIVITY_REFERRALS, referer, ListUrlsActivity.REFERER_BOUNDARY);
- } else {
- storeValue(context, ACTIVITY_REFERRALS, referer);
- }
- long delay;
+ handleEnum(context, ACTIVITY_REFERRALS, referer, ListUrlsActivity.REFERER_BOUNDARY);
switch (referer) {
case ListUrlsActivity.NOTIFICATION_REFERER:
- delay = UrlManager.getInstance(context).getTimeSinceNotificationUpdate();
- handleTime(context, STANDARD_NOTIFICATION_PRESS_DELAYS, delay,
+ handleTime(context, STANDARD_NOTIFICATION_PRESS_DELAYS,
+ UrlManager.getInstance(context).getTimeSinceNotificationUpdate(),
TimeUnit.MILLISECONDS);
break;
case ListUrlsActivity.OPTIN_REFERER:
- delay = UrlManager.getInstance(context).getTimeSinceNotificationUpdate();
- handleTime(context, OPT_IN_NOTIFICATION_PRESS_DELAYS, delay,
+ handleTime(context, OPT_IN_NOTIFICATION_PRESS_DELAYS,
+ UrlManager.getInstance(context).getTimeSinceNotificationUpdate(),
TimeUnit.MILLISECONDS);
break;
+ case ListUrlsActivity.PREFERENCE_REFERER:
+ recordPhysicalWebState(context, LAUNCH_FROM_PREFERENCES);
+ break;
+ case ListUrlsActivity.DIAGNOSTICS_REFERER:
+ recordPhysicalWebState(context, LAUNCH_FROM_DIAGNOSTICS);
+ break;
default:
break;
}
}
/**
+ * Records the Physical Web state on Chrome startup.
+ */
+ public static void onChromeStart(Context context) {
+ recordPhysicalWebState(context, CHROME_START);
+ }
+
+ /**
+ * Calculate a Physical Web state.
+ * The Physical Web state includes:
+ * - The location provider
+ * - The location permission
+ * - The bluetooth status
+ * - The data connection status
+ * - The Physical Web preference status
+ */
+ public static void recordPhysicalWebState(Context context, String actionName) {
+ handleEnum(context, createStateString(LOCATION_SERVICES, actionName),
+ Utils.isLocationServicesEnabled(context) ? 1 : 0, BOOLEAN_BOUNDARY);
+ handleEnum(context, createStateString(LOCATION_PERMISSION, actionName),
+ Utils.isLocationPermissionGranted(context) ? 1 : 0, BOOLEAN_BOUNDARY);
+ handleEnum(context, createStateString(BLUETOOTH, actionName),
+ Utils.getBluetoothEnabledStatus(context), TRISTATE_BOUNDARY);
+ handleEnum(context, createStateString(DATA_CONNECTION, actionName),
+ Utils.isDataConnectionActive(context) ? 1 : 0, BOOLEAN_BOUNDARY);
+ int preferenceState = 2;
+ if (!PhysicalWeb.isOnboarding(context)) {
+ preferenceState = PhysicalWeb.isPhysicalWebPreferenceEnabled(context) ? 1 : 0;
+ }
+ handleEnum(context, createStateString(PREFERENCE, actionName),
+ preferenceState, TRISTATE_BOUNDARY);
+ }
+
+ /**
* Uploads metrics that we have deferred for uploading.
* Additionally, this method will cause future stat records not to be deferred and instead
* uploaded immediately.
@@ -212,6 +256,10 @@ public class PhysicalWebUma {
}
}
+ private static String createStateString(String stateName, String actionName) {
+ return PHYSICAL_WEB_STATE + "." + stateName + "." + actionName;
+ }
+
private static void storeAction(Context context, String key) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
int count = prefs.getInt(key, 0);
@@ -256,6 +304,14 @@ public class PhysicalWebUma {
}
}
+ private static void handleEnum(Context context, String key, int value, int boundary) {
+ if (sUploadAllowed) {
+ RecordHistogram.recordEnumeratedHistogram(key, value, boundary);
+ } else {
+ storeValue(context, key, value);
+ }
+ }
+
private static class UmaUploader implements Runnable {
SharedPreferences mPrefs;
@@ -282,6 +338,27 @@ public class PhysicalWebUma {
uploadCounts(TOTAL_URLS_INITIAL_COUNTS);
uploadCounts(TOTAL_URLS_REFRESH_COUNTS);
uploadEnums(ACTIVITY_REFERRALS, ListUrlsActivity.REFERER_BOUNDARY);
+ uploadEnums(createStateString(LOCATION_SERVICES, CHROME_START), BOOLEAN_BOUNDARY);
+ uploadEnums(createStateString(LOCATION_PERMISSION, CHROME_START), BOOLEAN_BOUNDARY);
+ uploadEnums(createStateString(BLUETOOTH, CHROME_START), TRISTATE_BOUNDARY);
+ uploadEnums(createStateString(DATA_CONNECTION, CHROME_START), BOOLEAN_BOUNDARY);
+ uploadEnums(createStateString(PREFERENCE, CHROME_START), TRISTATE_BOUNDARY);
+ uploadEnums(createStateString(LOCATION_SERVICES, LAUNCH_FROM_DIAGNOSTICS),
+ BOOLEAN_BOUNDARY);
+ uploadEnums(createStateString(LOCATION_PERMISSION, LAUNCH_FROM_DIAGNOSTICS),
+ BOOLEAN_BOUNDARY);
+ uploadEnums(createStateString(BLUETOOTH, LAUNCH_FROM_DIAGNOSTICS), TRISTATE_BOUNDARY);
+ uploadEnums(createStateString(DATA_CONNECTION, LAUNCH_FROM_DIAGNOSTICS),
+ BOOLEAN_BOUNDARY);
+ uploadEnums(createStateString(PREFERENCE, LAUNCH_FROM_DIAGNOSTICS), TRISTATE_BOUNDARY);
+ uploadEnums(createStateString(LOCATION_SERVICES, LAUNCH_FROM_PREFERENCES),
+ BOOLEAN_BOUNDARY);
+ uploadEnums(createStateString(LOCATION_PERMISSION, LAUNCH_FROM_PREFERENCES),
+ BOOLEAN_BOUNDARY);
+ uploadEnums(createStateString(BLUETOOTH, LAUNCH_FROM_PREFERENCES), TRISTATE_BOUNDARY);
+ uploadEnums(createStateString(DATA_CONNECTION, LAUNCH_FROM_PREFERENCES),
+ BOOLEAN_BOUNDARY);
+ uploadEnums(createStateString(PREFERENCE, LAUNCH_FROM_PREFERENCES), TRISTATE_BOUNDARY);
removePref(HAS_DEFERRED_METRICS_KEY);
}

Powered by Google App Engine
This is Rietveld 408576698