Consolidate user actions metrics into one histogram.
Bug: 27301081
Change-Id: Ib2ac46dd268e492c576bc082dc349c4a6826897f
diff --git a/src/com/android/documentsui/BaseActivity.java b/src/com/android/documentsui/BaseActivity.java
index 4ee37a5..3b0be57 100644
--- a/src/com/android/documentsui/BaseActivity.java
+++ b/src/com/android/documentsui/BaseActivity.java
@@ -257,7 +257,6 @@
@Override
public boolean onOptionsItemSelected(MenuItem item) {
- Metrics.logMenuAction(this, item.getItemId());
switch (item.getItemId()) {
case android.R.id.home:
@@ -279,6 +278,7 @@
case R.id.menu_sort_date:
setUserSortOrder(State.SORT_ORDER_LAST_MODIFIED);
return true;
+
case R.id.menu_sort_size:
setUserSortOrder(State.SORT_ORDER_SIZE);
return true;
@@ -307,6 +307,8 @@
return true;
case R.id.menu_settings:
+ Metrics.logUserAction(this, Metrics.USER_ACTION_SETTINGS);
+
final RootInfo root = getCurrentRoot();
final Intent intent = new Intent(DocumentsContract.ACTION_DOCUMENT_ROOT_SETTINGS);
intent.setDataAndType(root.getUri(), DocumentsContract.Root.MIME_TYPE_ITEM);
@@ -323,6 +325,8 @@
}
void showCreateDirectoryDialog() {
+ Metrics.logUserAction(this, Metrics.USER_ACTION_CREATE_DIR);
+
CreateDirectoryFragment.show(getFragmentManager());
}
@@ -469,13 +473,25 @@
"com.android.providers.downloads.documents", "downloads");
}
+ /**
+ * Set internal storage visible based on explicit user action.
+ */
void setDisplayAdvancedDevices(boolean display) {
+ Metrics.logUserAction(this,
+ display ? Metrics.USER_ACTION_SHOW_ADVANCED : Metrics.USER_ACTION_HIDE_ADVANCED);
+
mState.showAdvanced = display;
RootsFragment.get(getFragmentManager()).onDisplayStateChanged();
invalidateOptionsMenu();
}
+ /**
+ * Set file size visible based on explicit user action.
+ */
void setDisplayFileSize(boolean display) {
+ Metrics.logUserAction(this,
+ display ? Metrics.USER_ACTION_SHOW_SIZE : Metrics.USER_ACTION_HIDE_SIZE);
+
LocalPreferences.setDisplayFileSize(this, display);
mState.showSize = display;
DirectoryFragment dir = getDirectoryFragment();
@@ -489,6 +505,18 @@
* Set state sort order based on explicit user action.
*/
void setUserSortOrder(int sortOrder) {
+ switch(sortOrder) {
+ case State.SORT_ORDER_DISPLAY_NAME:
+ Metrics.logUserAction(this, Metrics.USER_ACTION_SORT_NAME);
+ break;
+ case State.SORT_ORDER_LAST_MODIFIED:
+ Metrics.logUserAction(this, Metrics.USER_ACTION_SORT_DATE);
+ break;
+ case State.SORT_ORDER_SIZE:
+ Metrics.logUserAction(this, Metrics.USER_ACTION_SORT_SIZE);
+ break;
+ }
+
mState.userSortOrder = sortOrder;
DirectoryFragment dir = getDirectoryFragment();
if (dir != null) {
@@ -500,6 +528,12 @@
* Set mode based on explicit user action.
*/
void setViewMode(@ViewMode int mode) {
+ if (mode == State.MODE_GRID) {
+ Metrics.logUserAction(this, Metrics.USER_ACTION_GRID);
+ } else if (mode == State.MODE_LIST) {
+ Metrics.logUserAction(this, Metrics.USER_ACTION_LIST);
+ }
+
LocalPreferences.setViewMode(this, getCurrentRoot(), mode);
mState.derivedMode = mode;
@@ -621,12 +655,10 @@
return true;
}
} else if (keyCode == KeyEvent.KEYCODE_TAB) {
- Metrics.logKeyboardAction(this, Metrics.ACTION_KEYBOARD_SWITCH_FOCUS);
// Tab toggles focus on the navigation drawer.
toggleNavDrawerFocus();
return true;
} else if (keyCode == KeyEvent.KEYCODE_DEL) {
- Metrics.logKeyboardAction(this, Metrics.ACTION_KEYBOARD_BACK);
popDir();
return true;
}
diff --git a/src/com/android/documentsui/FilesActivity.java b/src/com/android/documentsui/FilesActivity.java
index 527eb78..b34af0b 100644
--- a/src/com/android/documentsui/FilesActivity.java
+++ b/src/com/android/documentsui/FilesActivity.java
@@ -228,13 +228,12 @@
default:
return super.onOptionsItemSelected(item);
}
-
- Metrics.logMenuAction(this, item.getItemId());
return true;
}
private void createNewWindow() {
- Metrics.logMultiWindow(this);
+ Metrics.logUserAction(this, Metrics.USER_ACTION_NEW_WINDOW);
+
Intent intent = LauncherActivity.createLaunchIntent(this);
intent.putExtra(Shared.EXTRA_STACK, (Parcelable) mState.stack);
@@ -352,21 +351,18 @@
case KeyEvent.KEYCODE_A:
dir = getDirectoryFragment();
if (dir != null) {
- Metrics.logKeyboardAction(this, Metrics.ACTION_KEYBOARD_SELECT_ALL);
dir.selectAllFiles();
}
return true;
case KeyEvent.KEYCODE_C:
dir = getDirectoryFragment();
if (dir != null) {
- Metrics.logKeyboardAction(this, Metrics.ACTION_KEYBOARD_COPY);
dir.copySelectedToClipboard();
}
return true;
case KeyEvent.KEYCODE_V:
dir = getDirectoryFragment();
if (dir != null) {
- Metrics.logKeyboardAction(this, Metrics.ACTION_KEYBOARD_PASTE);
dir.pasteFromClipboard();
}
return true;
diff --git a/src/com/android/documentsui/Metrics.java b/src/com/android/documentsui/Metrics.java
index 05cc7e6..69a6e1f 100644
--- a/src/com/android/documentsui/Metrics.java
+++ b/src/com/android/documentsui/Metrics.java
@@ -62,16 +62,13 @@
private static final String COUNT_GET_CONTENT_MIME = "docsui_get_content_mime";
private static final String COUNT_BROWSE_ROOT = "docsui_browse_root";
@Deprecated private static final String COUNT_MANAGE_ROOT = "docsui_manage_root";
- private static final String COUNT_MULTI_WINDOW = "docsui_multi_window";
+ @Deprecated private static final String COUNT_MULTI_WINDOW = "docsui_multi_window";
private static final String COUNT_FILEOP_SYSTEM = "docsui_fileop_system";
private static final String COUNT_FILEOP_EXTERNAL = "docsui_fileop_external";
private static final String COUNT_FILEOP_CANCELED = "docsui_fileop_canceled";
private static final String COUNT_STARTUP_MS = "docsui_startup_ms";
private static final String COUNT_DRAWER_OPENED = "docsui_drawer_opened";
- private static final String COUNT_DRAG_N_DROP = "docsui_drag_n_drop";
- private static final String COUNT_SEARCH = "docsui_search";
- private static final String COUNT_MENU_ACTION = "docsui_menu_action";
- private static final String COUNT_KEYBOARD_ACTION = "docsui_keyboard_action";
+ private static final String COUNT_USER_ACTION = "docsui_menu_action";
// Indices for bucketing roots in the roots histogram. "Other" is the catch-all index for any
// root that is not explicitly recognized by the Metrics code (see {@link
@@ -215,54 +212,67 @@
public @interface Provider {}
- // Codes representing different menu actions. These are used for bucketing stats in the
- // COUNT_MENU_ACTION histogram.
- // Both regular toolbar menu and action mode menu operations are included.
+ // Codes representing different user actions. These are used for bucketing stats in the
+ // COUNT_USER_ACTION histogram.
+ // The historgram includes action triggered from menu or invoked by keyboard shortcut.
// Do not change or rearrange these values, that will break historical data. Only add to the
// list.
// Do not use negative numbers or zero; clearcut only handles positive integers.
- private static final int ACTION_MENU_OTHER = 1;
- private static final int ACTION_MENU_GRID = 2;
- private static final int ACTION_MENU_LIST = 3;
- private static final int ACTION_MENU_SORT = 4;
- private static final int ACTION_MENU_SORT_NAME = 5;
- private static final int ACTION_MENU_SORT_DATE = 6;
- private static final int ACTION_MENU_SORT_SIZE = 7;
- private static final int ACTION_MENU_SEARCH = 8;
- private static final int ACTION_MENU_SHOW_SIZE = 9;
- private static final int ACTION_MENU_SETTINGS = 10;
- private static final int ACTION_MENU_COPY_TO = 11;
- private static final int ACTION_MENU_MOVE_TO = 12;
- private static final int ACTION_MENU_DELETE = 13;
- private static final int ACTION_MENU_RENAME = 14;
- private static final int ACTION_MENU_CREATE_DIR = 15;
- private static final int ACTION_MENU_SELECT_ALL = 16;
- private static final int ACTION_MENU_SHARE = 17;
- private static final int ACTION_MENU_OPEN = 18;
- private static final int ACTION_MENU_ADVANCED = 19;
+ public static final int USER_ACTION_OTHER = 1;
+ public static final int USER_ACTION_GRID = 2;
+ public static final int USER_ACTION_LIST = 3;
+ public static final int USER_ACTION_SORT_NAME = 4;
+ public static final int USER_ACTION_SORT_DATE = 5;
+ public static final int USER_ACTION_SORT_SIZE = 6;
+ public static final int USER_ACTION_SEARCH = 7;
+ public static final int USER_ACTION_SHOW_SIZE = 8;
+ public static final int USER_ACTION_HIDE_SIZE = 9;
+ public static final int USER_ACTION_SETTINGS = 10;
+ public static final int USER_ACTION_COPY_TO = 11;
+ public static final int USER_ACTION_MOVE_TO = 12;
+ public static final int USER_ACTION_DELETE = 13;
+ public static final int USER_ACTION_RENAME = 14;
+ public static final int USER_ACTION_CREATE_DIR = 15;
+ public static final int USER_ACTION_SELECT_ALL = 16;
+ public static final int USER_ACTION_SHARE = 17;
+ public static final int USER_ACTION_OPEN = 18;
+ public static final int USER_ACTION_SHOW_ADVANCED = 19;
+ public static final int USER_ACTION_HIDE_ADVANCED = 20;
+ public static final int USER_ACTION_NEW_WINDOW = 21;
+ public static final int USER_ACTION_PASTE_CLIPBOARD = 22;
+ public static final int USER_ACTION_COPY_CLIPBOARD = 23;
+ public static final int USER_ACTION_DRAG_N_DROP = 24;
+ public static final int USER_ACTION_DRAG_N_DROP_MULTI_WINDOW = 25;
@IntDef(flag = false, value = {
- ACTION_MENU_OTHER,
- ACTION_MENU_GRID,
- ACTION_MENU_LIST,
- ACTION_MENU_SORT,
- ACTION_MENU_SORT_NAME,
- ACTION_MENU_SORT_DATE,
- ACTION_MENU_SORT_SIZE,
- ACTION_MENU_SHOW_SIZE,
- ACTION_MENU_SETTINGS,
- ACTION_MENU_COPY_TO,
- ACTION_MENU_MOVE_TO,
- ACTION_MENU_DELETE,
- ACTION_MENU_RENAME,
- ACTION_MENU_CREATE_DIR,
- ACTION_MENU_SELECT_ALL,
- ACTION_MENU_SHARE,
- ACTION_MENU_OPEN,
- ACTION_MENU_ADVANCED
+ USER_ACTION_OTHER,
+ USER_ACTION_GRID,
+ USER_ACTION_LIST,
+ USER_ACTION_SORT_NAME,
+ USER_ACTION_SORT_DATE,
+ USER_ACTION_SORT_SIZE,
+ USER_ACTION_SEARCH,
+ USER_ACTION_SHOW_SIZE,
+ USER_ACTION_HIDE_SIZE,
+ USER_ACTION_SETTINGS,
+ USER_ACTION_COPY_TO,
+ USER_ACTION_MOVE_TO,
+ USER_ACTION_DELETE,
+ USER_ACTION_RENAME,
+ USER_ACTION_CREATE_DIR,
+ USER_ACTION_SELECT_ALL,
+ USER_ACTION_SHARE,
+ USER_ACTION_OPEN,
+ USER_ACTION_SHOW_ADVANCED,
+ USER_ACTION_HIDE_ADVANCED,
+ USER_ACTION_NEW_WINDOW,
+ USER_ACTION_PASTE_CLIPBOARD,
+ USER_ACTION_COPY_CLIPBOARD,
+ USER_ACTION_DRAG_N_DROP,
+ USER_ACTION_DRAG_N_DROP_MULTI_WINDOW
})
@Retention(RetentionPolicy.SOURCE)
- public @interface MenuAction {}
+ public @interface UserAction {}
// Codes representing different menu actions. These are used for bucketing stats in the
// COUNT_MENU_ACTION histogram.
@@ -291,31 +301,6 @@
@Retention(RetentionPolicy.SOURCE)
public @interface MetricsAction {}
- // Codes representing different keyboard shortcut triggered actions. These are used for
- // bucketing stats in the COUNT_KEYBOARD_ACTION histogram.
- // Do not change or rearrange these values, that will break historical data. Only add to the
- // list.
- // Do not use negative numbers or zero; clearcut only handles positive integers.
- public static final int ACTION_KEYBOARD_OTHER = 1;
- public static final int ACTION_KEYBOARD_PASTE = 2;
- public static final int ACTION_KEYBOARD_COPY = 3;
- public static final int ACTION_KEYBOARD_DELETE = 4;
- public static final int ACTION_KEYBOARD_SELECT_ALL = 5;
- public static final int ACTION_KEYBOARD_BACK = 6;
- public static final int ACTION_KEYBOARD_SWITCH_FOCUS = 7;
-
- @IntDef(flag = false, value = {
- ACTION_KEYBOARD_OTHER,
- ACTION_KEYBOARD_PASTE,
- ACTION_KEYBOARD_COPY,
- ACTION_KEYBOARD_DELETE,
- ACTION_KEYBOARD_SELECT_ALL,
- ACTION_KEYBOARD_BACK,
- ACTION_KEYBOARD_SWITCH_FOCUS
- })
- @Retention(RetentionPolicy.SOURCE)
- public @interface KeyboardAction {}
-
// Codes representing different actions to open the drawer. They are used for bucketing stats in
// the COUNT_DRAWER_OPENED histogram.
// Do not change or rearrange these values, that will break historical data. Only add to the
@@ -382,15 +367,6 @@
}
/**
- * Logs a multi-window start. Call this when the user spawns a new DocumentsUI window.
- *
- * @param context
- */
- public static void logMultiWindow(Context context) {
- logCount(context, COUNT_MULTI_WINDOW);
- }
-
- /**
* Logs a drawer opened event. Call this when the user opens drawer by swipe or by clicking the
* hamburger icon.
* @param context
@@ -496,7 +472,7 @@
* @param context
*/
public static void logCreateDirError(Context context) {
- logHistogram(context, COUNT_FILEOP_SYSTEM, FILEOP_CREATE_DIR);
+ logHistogram(context, COUNT_FILEOP_SYSTEM, FILEOP_CREATE_DIR_ERROR);
}
/**
@@ -520,16 +496,6 @@
}
/**
- * Logs keyboard shortcut actions. Since keyboard shortcuts have their corresponding menu items,
- * they are identified by menu item resource id for convenience.
- * @param context
- * @param keyCode
- */
- public static void logKeyboardAction(Context context, @KeyboardAction int action) {
- logHistogram(context, COUNT_KEYBOARD_ACTION, action);
- }
-
- /**
* Logs startup time in milliseconds.
* @param context
* @param startupMs Startup time in milliseconds.
@@ -538,25 +504,6 @@
logHistogram(context, COUNT_STARTUP_MS, startupMs);
}
- /**
- * Logs a drag and drop action. Call this when the user drops the content triggering copy.
- * operation.
- *
- * @param context
- */
- public static void logDragNDrop(Context context) {
- logCount(context, COUNT_DRAG_N_DROP);
- }
-
- /**
- * Logs a search. Call this when the search operation is finished.
- *
- * @param context
- */
- public static void logSearch(Context context) {
- logCount(context, COUNT_SEARCH);
- }
-
private static void logInterProviderFileOps(
Context context,
String histogram,
@@ -677,71 +624,12 @@
}
/**
- * Logs menu action that was selected by user.
+ * Logs the action that was started by user.
* @param context
- * @param id Resource id of the menu item.
+ * @param userAction
*/
- public static void logMenuAction(Context context, int id) {
- @MenuAction int menuAction = ACTION_MENU_OTHER;
- switch (id) {
- case R.id.menu_grid:
- menuAction = ACTION_MENU_GRID;
- break;
- case R.id.menu_list:
- menuAction = ACTION_MENU_LIST;
- break;
- case R.id.menu_sort:
- menuAction = ACTION_MENU_SORT;
- break;
- case R.id.menu_sort_name:
- menuAction = ACTION_MENU_SORT_NAME;
- break;
- case R.id.menu_sort_date:
- menuAction = ACTION_MENU_SORT_DATE;
- break;
- case R.id.menu_sort_size:
- menuAction = ACTION_MENU_SORT_SIZE;
- break;
- case R.id.menu_search:
- menuAction = ACTION_MENU_SEARCH;
- break;
- case R.id.menu_file_size:
- menuAction = ACTION_MENU_SHOW_SIZE;
- break;
- case R.id.menu_settings:
- menuAction = ACTION_MENU_SETTINGS;
- break;
- case R.id.menu_copy_to:
- menuAction = ACTION_MENU_COPY_TO;
- break;
- case R.id.menu_move_to:
- menuAction = ACTION_MENU_MOVE_TO;
- break;
- case R.id.menu_delete:
- menuAction = ACTION_MENU_DELETE;
- break;
- case R.id.menu_rename:
- menuAction = ACTION_MENU_RENAME;
- break;
- case R.id.menu_create_dir:
- menuAction = ACTION_MENU_CREATE_DIR;
- break;
- case R.id.menu_select_all:
- menuAction = ACTION_MENU_SELECT_ALL;
- break;
- case R.id.menu_share:
- menuAction = ACTION_MENU_SHARE;
- break;
- case R.id.menu_open:
- menuAction = ACTION_MENU_OPEN;
- break;
- case R.id.menu_advanced:
- menuAction = ACTION_MENU_ADVANCED;
- break;
- default:
- break;
- }
- logHistogram(context, COUNT_MENU_ACTION, menuAction);
+ public static void logUserAction(Context context, @UserAction int userAction) {
+ logHistogram(context, COUNT_USER_ACTION, userAction);
}
/**
diff --git a/src/com/android/documentsui/SearchViewManager.java b/src/com/android/documentsui/SearchViewManager.java
index 945ed34..11b8891 100644
--- a/src/com/android/documentsui/SearchViewManager.java
+++ b/src/com/android/documentsui/SearchViewManager.java
@@ -185,9 +185,6 @@
if(mFullBar) {
Menu menu = mActionBar.getMenu();
menu.setGroupVisible(R.id.group_hide_when_searching, false);
- } else {
- // If search in full-bar mode it will be logged in FilesActivity#onOptionsItemSelected
- Metrics.logMenuAction(mActionBar.getContext(), R.id.menu_search);
}
}
diff --git a/src/com/android/documentsui/dirlist/DirectoryFragment.java b/src/com/android/documentsui/dirlist/DirectoryFragment.java
index 1c85a8a..bc2133e 100644
--- a/src/com/android/documentsui/dirlist/DirectoryFragment.java
+++ b/src/com/android/documentsui/dirlist/DirectoryFragment.java
@@ -605,8 +605,6 @@
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
- Metrics.logMenuAction(getContext(), item.getItemId());
-
Selection selection = mSelectionManager.getSelection(new Selection());
switch (item.getItemId()) {
@@ -674,6 +672,8 @@
}
private void openDocuments(final Selection selected) {
+ Metrics.logUserAction(getContext(), Metrics.USER_ACTION_OPEN);
+
new GetDocumentsTask() {
@Override
void onDocumentsReady(List<DocumentInfo> docs) {
@@ -684,6 +684,8 @@
}
private void shareDocuments(final Selection selected) {
+ Metrics.logUserAction(getContext(), Metrics.USER_ACTION_SHARE);
+
new GetDocumentsTask() {
@Override
void onDocumentsReady(List<DocumentInfo> docs) {
@@ -765,6 +767,8 @@
}
private void deleteDocuments(final Selection selected) {
+ Metrics.logUserAction(getContext(), Metrics.USER_ACTION_DELETE);
+
assert(!selected.isEmpty());
final DocumentInfo srcParent = getDisplayState().stack.peek();
@@ -815,6 +819,12 @@
}
private void transferDocuments(final Selection selected, final @OpType int mode) {
+ if(mode == FileOperationService.OPERATION_COPY) {
+ Metrics.logUserAction(getContext(), Metrics.USER_ACTION_COPY_TO);
+ } else if (mode == FileOperationService.OPERATION_MOVE) {
+ Metrics.logUserAction(getContext(), Metrics.USER_ACTION_MOVE_TO);
+ }
+
// Pop up a dialog to pick a destination. This is inadequate but works for now.
// TODO: Implement a picker that is to spec.
final Intent intent = new Intent(
@@ -861,6 +871,8 @@
}
private void renameDocuments(Selection selected) {
+ Metrics.logUserAction(getContext(), Metrics.USER_ACTION_RENAME);
+
// Batch renaming not supported
// Rename option is only available in menu when 1 document selected
assert(selected.size() == 1);
@@ -1020,6 +1032,8 @@
}
public void copySelectedToClipboard() {
+ Metrics.logUserAction(getContext(), Metrics.USER_ACTION_COPY_CLIPBOARD);
+
Selection selection = mSelectionManager.getSelection(new Selection());
if (!selection.isEmpty()) {
copySelectionToClipboard(selection);
@@ -1043,6 +1057,8 @@
}
public void pasteFromClipboard() {
+ Metrics.logUserAction(getContext(), Metrics.USER_ACTION_PASTE_CLIPBOARD);
+
copyFromClipboard();
getActivity().invalidateOptionsMenu();
}
@@ -1073,6 +1089,8 @@
}
public void selectAllFiles() {
+ Metrics.logUserAction(getContext(), Metrics.USER_ACTION_SELECT_ALL);
+
// Exclude disabled files
List<String> enabled = new ArrayList<String>();
for (String id : mAdapter.getModelIds()) {
@@ -1147,7 +1165,14 @@
if (Objects.equals(src, dst)) {
return false;
}
- Metrics.logDragNDrop(getContext());
+ // Recognize multi-window drag and drop based on the fact that localState is not
+ // carried between processes. It will stop working when the localsState behavior
+ // is changed. The info about window should be passed in the localState then.
+ // The localState could also be null for copying from Recents in single window
+ // mode, but Recents doesn't offer this functionality (no directories).
+ Metrics.logUserAction(getContext(),
+ src == null ? Metrics.USER_ACTION_DRAG_N_DROP_MULTI_WINDOW
+ : Metrics.USER_ACTION_DRAG_N_DROP);
copyFromClipData(event.getClipData(), dst);
return true;
}
@@ -1387,7 +1412,6 @@
// This has to be handled here instead of in a keyboard shortcut, because
// keyboard shortcuts all have to be modified with the 'Ctrl' key.
if (mSelectionManager.hasSelection()) {
- Metrics.logKeyboardAction(getContext(), Metrics.ACTION_KEYBOARD_DELETE);
deleteDocuments(mSelectionManager.getSelection());
}
// Always handle the key, even if there was nothing to delete. This is a
@@ -1674,8 +1698,9 @@
@Override
public void onLoadFinished(Loader<DirectoryResult> loader, DirectoryResult result) {
if (!isAdded()) return;
+
if (mSearchMode) {
- Metrics.logSearch(getContext());
+ Metrics.logUserAction(getContext(), Metrics.USER_ACTION_SEARCH);
}
State state = getDisplayState();