shawnlin | 8a66b94 | 2018-12-27 10:30:10 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.util; |
| 18 | |
shawnlin | e40033e | 2019-03-04 17:01:34 +0800 | [diff] [blame] | 19 | import android.annotation.Nullable; |
shawnlin | 8a66b94 | 2018-12-27 10:30:10 +0800 | [diff] [blame] | 20 | import android.annotation.SystemApi; |
| 21 | import android.provider.DocumentsContract; |
| 22 | import android.provider.DocumentsProvider; |
| 23 | |
| 24 | /** |
| 25 | * DocumentsStatsLog provides APIs to send DocumentsUI related events to statsd. |
| 26 | * @hide |
| 27 | */ |
| 28 | @SystemApi |
| 29 | public class DocumentsStatsLog { |
| 30 | |
| 31 | private DocumentsStatsLog() {} |
| 32 | |
| 33 | /** |
| 34 | * Logs when DocumentsUI is started, and how. Call this when DocumentsUI first starts up. |
| 35 | * |
| 36 | * @param action action that launches DocumentsUI. |
| 37 | * @param hasInitialUri is DocumentsUI launched with |
| 38 | * {@link DocumentsContract#EXTRA_INITIAL_URI}. |
| 39 | * @param mimeType the requested mime type. |
| 40 | * @param rootUri the resolved rootUri, or {@code null} if the provider doesn't |
| 41 | * support {@link DocumentsProvider#findDocumentPath(String, String)} |
| 42 | */ |
| 43 | public static void logActivityLaunch( |
| 44 | int action, boolean hasInitialUri, int mimeType, int rootUri) { |
| 45 | StatsLog.write(StatsLog.DOCS_UI_LAUNCH_REPORTED, action, hasInitialUri, mimeType, rootUri); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Logs root visited event. |
| 50 | * |
| 51 | * @param scope whether it's in FILES or PICKER mode. |
| 52 | * @param root the root that user visited |
| 53 | */ |
| 54 | public static void logRootVisited(int scope, int root) { |
| 55 | StatsLog.write(StatsLog.DOCS_UI_ROOT_VISITED, scope, root); |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Logs file operation stats. Call this when a file operation has completed. |
| 60 | * |
| 61 | * @param provider whether it's system or external provider |
| 62 | * @param fileOp the file operation |
| 63 | */ |
| 64 | public static void logFileOperation(int provider, int fileOp) { |
| 65 | StatsLog.write(StatsLog.DOCS_UI_PROVIDER_FILE_OP, provider, fileOp); |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Logs file operation stats. Call this when a copy/move operation has completed with a specific |
| 70 | * mode. |
| 71 | * |
| 72 | * @param fileOp copy or move file operation |
| 73 | * @param mode the mode for copy and move operation |
| 74 | */ |
| 75 | public static void logFileOperationCopyMoveMode(int fileOp, int mode) { |
| 76 | StatsLog.write(StatsLog.DOCS_UI_FILE_OP_COPY_MOVE_MODE_REPORTED, fileOp, mode); |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Logs file sub operation stats. Call this when a file operation has failed. |
| 81 | * |
| 82 | * @param authority the authority of the source document |
| 83 | * @param subOp the sub-file operation |
| 84 | */ |
| 85 | public static void logFileOperationFailure(int authority, int subOp) { |
| 86 | StatsLog.write(StatsLog.DOCS_UI_FILE_OP_FAILURE, authority, subOp); |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * Logs the cancellation of a file operation. Call this when a job is canceled |
| 91 | * |
| 92 | * @param fileOp the file operation. |
| 93 | */ |
| 94 | public static void logFileOperationCanceled(int fileOp) { |
| 95 | StatsLog.write(StatsLog.DOCS_UI_FILE_OP_CANCELED, fileOp); |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * Logs startup time in milliseconds. |
| 100 | * |
| 101 | * @param startupMs |
| 102 | */ |
| 103 | public static void logStartupMs(int startupMs) { |
| 104 | StatsLog.write(StatsLog.DOCS_UI_STARTUP_MS, startupMs); |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * Logs the action that was started by user. |
| 109 | * |
| 110 | * @param userAction |
| 111 | */ |
| 112 | public static void logUserAction(int userAction) { |
| 113 | StatsLog.write(StatsLog.DOCS_UI_USER_ACTION_REPORTED, userAction); |
| 114 | } |
| 115 | |
| 116 | /** |
| 117 | * Logs the invalid type when invalid scoped access is requested. |
| 118 | * |
| 119 | * @param type the type of invalid scoped access request. |
| 120 | */ |
| 121 | public static void logInvalidScopedAccessRequest(int type) { |
| 122 | StatsLog.write(StatsLog.DOCS_UI_INVALID_SCOPED_ACCESS_REQUEST, type); |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | * Logs the package name that launches docsui picker mode. |
| 127 | * |
| 128 | * @param packageName |
| 129 | */ |
shawnlin | e40033e | 2019-03-04 17:01:34 +0800 | [diff] [blame] | 130 | public static void logPickerLaunchedFrom(@Nullable String packageName) { |
shawnlin | 8a66b94 | 2018-12-27 10:30:10 +0800 | [diff] [blame] | 131 | StatsLog.write(StatsLog.DOCS_UI_PICKER_LAUNCHED_FROM_REPORTED, packageName); |
| 132 | } |
| 133 | |
| 134 | /** |
| 135 | * Logs the search type. |
| 136 | * |
| 137 | * @param searchType |
| 138 | */ |
| 139 | public static void logSearchType(int searchType) { |
| 140 | StatsLog.write(StatsLog.DOCS_UI_SEARCH_TYPE_REPORTED, searchType); |
| 141 | } |
| 142 | |
| 143 | /** |
| 144 | * Logs the search mode. |
| 145 | * |
| 146 | * @param searchMode |
| 147 | */ |
| 148 | public static void logSearchMode(int searchMode) { |
| 149 | StatsLog.write(StatsLog.DOCS_UI_SEARCH_MODE_REPORTED, searchMode); |
| 150 | } |
| 151 | |
| 152 | /** |
| 153 | * Logs the pick result information. |
| 154 | * |
| 155 | * @param actionCount total user action count during pick process. |
| 156 | * @param duration total time spent on pick process. |
| 157 | * @param fileCount number of picked files. |
| 158 | * @param isSearching are the picked files found by search. |
| 159 | * @param root the root where the picked files located. |
| 160 | * @param mimeType the mime type of the picked file. Only for single-select case. |
| 161 | * @param repeatedlyPickTimes number of times that the file has been picked before. Only for |
| 162 | * single-select case. |
| 163 | */ |
| 164 | public static void logFilePick(int actionCount, long duration, int fileCount, |
| 165 | boolean isSearching, int root, int mimeType, int repeatedlyPickTimes) { |
| 166 | StatsLog.write(StatsLog.DOCS_UI_PICK_RESULT_REPORTED, actionCount, duration, fileCount, |
| 167 | isSearching, root, mimeType, repeatedlyPickTimes); |
| 168 | } |
| 169 | } |