Bug 1329156 - Add telemetry for customtab customization usage. r?walkingice
MozReview-Commit-ID: EJrFzvHOqOU
--- a/mobile/android/base/java/org/mozilla/gecko/customtabs/CustomTabsActivity.java
+++ b/mobile/android/base/java/org/mozilla/gecko/customtabs/CustomTabsActivity.java
@@ -70,17 +70,17 @@ public class CustomTabsActivity extends
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState != null) {
startIntent = savedInstanceState.getParcelable(SAVED_START_INTENT);
} else {
- Telemetry.sendUIEvent(TelemetryContract.Event.LOAD_URL, TelemetryContract.Method.INTENT, "customtab");
+ sendTelemetry();
startIntent = getIntent();
final String host = getReferrerHost();
recordCustomTabUsage(host);
}
setThemeFromToolbarColor();
doorhangerOverlay = findViewById(R.id.custom_tabs_doorhanger_overlay);
@@ -94,16 +94,34 @@ public class CustomTabsActivity extends
actionBarPresenter = new ActionBarPresenter(actionBar);
actionBarPresenter.displayUrlOnly(startIntent.getDataString());
actionBarPresenter.setBackgroundColor(IntentUtil.getToolbarColor(startIntent), getWindow());
actionBarPresenter.setTextLongClickListener(new UrlCopyListener());
Tabs.registerOnTabsChangedListener(this);
}
+ private void sendTelemetry() {
+ Telemetry.sendUIEvent(TelemetryContract.Event.LOAD_URL, TelemetryContract.Method.INTENT, "customtab");
+ if (IntentUtil.hasToolbarColor(startIntent)) {
+ Telemetry.sendUIEvent(TelemetryContract.Event.LOAD_URL, TelemetryContract.Method.INTENT, "customtab-hasToolbarColor");
+ }
+ if (IntentUtil.hasActionButton(startIntent)) {
+ Telemetry.sendUIEvent(TelemetryContract.Event.LOAD_URL, TelemetryContract.Method.INTENT, "customtab-hasActionButton");
+ }
+ if (IntentUtil.isActionButtonTinted(startIntent)) {
+ Telemetry.sendUIEvent(TelemetryContract.Event.LOAD_URL, TelemetryContract.Method.INTENT, "customtab-isActionButtonTinted");
+ }
+ if (IntentUtil.hasShareItem(startIntent)) {
+ Telemetry.sendUIEvent(TelemetryContract.Event.LOAD_URL, TelemetryContract.Method.INTENT, "customtab-hasShareItem");
+ }
+
+
+ }
+
private void recordCustomTabUsage(final String host) {
final GeckoBundle data = new GeckoBundle(1);
if (host != null) {
data.putString("client", host);
} else {
data.putString("client", "unknown");
}
// Pass a message to Gecko to send Telemetry data
@@ -256,41 +274,54 @@ public class CustomTabsActivity extends
updateMenuItemForward();
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
+ Telemetry.sendUIEvent(TelemetryContract.Event.ACTION, TelemetryContract.Method.MENU, "customtab-home");
finish();
return true;
case R.id.share:
+ Telemetry.sendUIEvent(TelemetryContract.Event.ACTION, TelemetryContract.Method.MENU, "customtab-share");
onShareClicked();
return true;
case R.id.custom_tabs_menu_forward:
+ Telemetry.sendUIEvent(TelemetryContract.Event.ACTION, TelemetryContract.Method.MENU, "customtab-forward");
onForwardClicked();
return true;
case R.id.custom_tabs_menu_control:
+ Telemetry.sendUIEvent(TelemetryContract.Event.ACTION, TelemetryContract.Method.MENU, "customtab-control");
onLoadingControlClicked();
return true;
case R.id.custom_tabs_menu_open_in:
+ Telemetry.sendUIEvent(TelemetryContract.Event.ACTION, TelemetryContract.Method.MENU, "customtab-open-in");
onOpenInClicked();
return true;
}
final PendingIntent intent = menuItemsIntent.get(item.getItemId());
if (intent != null) {
- performPendingIntent(intent);
+ onCustomMenuItemClicked(intent);
return true;
}
return super.onOptionsItemSelected(item);
}
+ /**
+ * Called when the menu that's been clicked is added by the client
+ */
+ private void onCustomMenuItemClicked(PendingIntent intent) {
+ Telemetry.sendUIEvent(TelemetryContract.Event.ACTION, TelemetryContract.Method.MENU, "customtab-customized-menu");
+ performPendingIntent(intent);
+ }
+
@Override
protected ActionModePresenter getTextSelectPresenter() {
return new ActionModePresenter() {
private ActionMode mMode;
@Override
public void startActionMode(ActionMode.Callback callback) {
mMode = startSupportActionMode(callback);
@@ -453,16 +484,17 @@ public class CustomTabsActivity extends
intent.setData(Uri.parse(tab.getURL()));
intent.setAction(Intent.ACTION_VIEW);
startActivity(intent);
finish();
}
}
private void onActionButtonClicked() {
+ Telemetry.sendUIEvent(TelemetryContract.Event.ACTION, TelemetryContract.Method.MENU, "customtab-action-button");
PendingIntent pendingIntent = IntentUtil.getActionButtonPendingIntent(startIntent);
performPendingIntent(pendingIntent);
}
/**
* Callback for Share menu item.
*/
--- a/mobile/android/base/java/org/mozilla/gecko/customtabs/IntentUtil.java
+++ b/mobile/android/base/java/org/mozilla/gecko/customtabs/IntentUtil.java
@@ -68,16 +68,27 @@ class IntentUtil {
* @return bitmap icon, if any. Otherwise, null.
*/
static Bitmap getActionButtonIcon(@NonNull Intent intent) {
final Bundle bundle = getActionButtonBundle(intent);
return (bundle == null) ? null : (Bitmap) bundle.getParcelable(CustomTabsIntent.KEY_ICON);
}
/**
+ * Only for telemetry to understand caller app's customization
+ * This method should only be called once during one usage.
+ *
+ * @param intent which to launch a Custom-Tabs-Activity
+ * @return true, if the caller customized the color.
+ */
+ static boolean hasToolbarColor(@NonNull Intent intent) {
+ return intent.hasExtra(CustomTabsIntent.EXTRA_TOOLBAR_COLOR);
+ }
+
+ /**
* To extract color code from intent for top toolbar.
* It also ensure the color is not translucent.
*
* @param intent which to launch a Custom-Tabs-Activity
* @return color code in integer type.
*/
@ColorInt
static int getToolbarColor(@NonNull Intent intent) {