summaryrefslogtreecommitdiff
path: root/core/java/android/util/DocumentsStatsLog.java
blob: f483944c97c734d807c2e51cce527ae15f7857c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*
 * Copyright (C) 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.util;

import android.annotation.SystemApi;
import android.provider.DocumentsContract;
import android.provider.DocumentsProvider;

/**
 * DocumentsStatsLog provides APIs to send DocumentsUI related events to statsd.
 * @hide
 */
@SystemApi
public class DocumentsStatsLog {

    private DocumentsStatsLog() {}

    /**
     * Logs when DocumentsUI is started, and how. Call this when DocumentsUI first starts up.
     *
     * @param action action that launches DocumentsUI.
     * @param hasInitialUri is DocumentsUI launched with
     *                      {@link DocumentsContract#EXTRA_INITIAL_URI}.
     * @param mimeType the requested mime type.
     * @param rootUri the resolved rootUri, or {@code null} if the provider doesn't
     *                support {@link DocumentsProvider#findDocumentPath(String, String)}
     */
    public static void logActivityLaunch(
            int action, boolean hasInitialUri, int mimeType, int rootUri) {
        StatsLog.write(StatsLog.DOCS_UI_LAUNCH_REPORTED, action, hasInitialUri, mimeType, rootUri);
    }

    /**
     * Logs root visited event.
     *
     * @param scope whether it's in FILES or PICKER mode.
     * @param root the root that user visited
     */
    public static void logRootVisited(int scope, int root) {
        StatsLog.write(StatsLog.DOCS_UI_ROOT_VISITED, scope, root);
    }

    /**
     * Logs file operation stats. Call this when a file operation has completed.
     *
     * @param provider whether it's system or external provider
     * @param fileOp the file operation
     */
    public static void logFileOperation(int provider, int fileOp) {
        StatsLog.write(StatsLog.DOCS_UI_PROVIDER_FILE_OP, provider, fileOp);
    }

    /**
     * Logs file operation stats. Call this when a copy/move operation has completed with a specific
     * mode.
     *
     * @param fileOp copy or move file operation
     * @param mode the mode for copy and move operation
     */
    public static void logFileOperationCopyMoveMode(int fileOp, int mode) {
        StatsLog.write(StatsLog.DOCS_UI_FILE_OP_COPY_MOVE_MODE_REPORTED, fileOp, mode);
    }

    /**
     * Logs file sub operation stats. Call this when a file operation has failed.
     *
     * @param authority the authority of the source document
     * @param subOp the sub-file operation
     */
    public static void logFileOperationFailure(int authority, int subOp) {
        StatsLog.write(StatsLog.DOCS_UI_FILE_OP_FAILURE, authority, subOp);
    }

    /**
     * Logs the cancellation of a file operation. Call this when a job is canceled
     *
     * @param fileOp the file operation.
     */
    public static void logFileOperationCanceled(int fileOp) {
        StatsLog.write(StatsLog.DOCS_UI_FILE_OP_CANCELED, fileOp);
    }

    /**
     * Logs startup time in milliseconds.
     *
     * @param startupMs
     */
    public static void logStartupMs(int startupMs) {
        StatsLog.write(StatsLog.DOCS_UI_STARTUP_MS, startupMs);
    }

    /**
     * Logs the action that was started by user.
     *
     * @param userAction
     */
    public static void logUserAction(int userAction) {
        StatsLog.write(StatsLog.DOCS_UI_USER_ACTION_REPORTED, userAction);
    }

    /**
     * Logs the invalid type when invalid scoped access is requested.
     *
     * @param type the type of invalid scoped access request.
     */
    public static void logInvalidScopedAccessRequest(int type) {
        StatsLog.write(StatsLog.DOCS_UI_INVALID_SCOPED_ACCESS_REQUEST, type);
    }

    /**
     * Logs the package name that launches docsui picker mode.
     *
     * @param packageName
     */
    public static void logPickerLaunchedFrom(String packageName) {
        StatsLog.write(StatsLog.DOCS_UI_PICKER_LAUNCHED_FROM_REPORTED, packageName);
    }

    /**
     * Logs the search type.
     *
     * @param searchType
     */
    public static void logSearchType(int searchType) {
        StatsLog.write(StatsLog.DOCS_UI_SEARCH_TYPE_REPORTED, searchType);
    }

    /**
     * Logs the search mode.
     *
     * @param searchMode
     */
    public static void logSearchMode(int searchMode) {
        StatsLog.write(StatsLog.DOCS_UI_SEARCH_MODE_REPORTED, searchMode);
    }

    /**
     * Logs the pick result information.
     *
     * @param actionCount total user action count during pick process.
     * @param duration total time spent on pick process.
     * @param fileCount number of picked files.
     * @param isSearching are the picked files found by search.
     * @param root the root where the picked files located.
     * @param mimeType the mime type of the picked file. Only for single-select case.
     * @param repeatedlyPickTimes number of times that the file has been picked before. Only for
     *                            single-select case.
     */
    public static void logFilePick(int actionCount, long duration, int fileCount,
            boolean isSearching, int root, int mimeType, int repeatedlyPickTimes) {
        StatsLog.write(StatsLog.DOCS_UI_PICK_RESULT_REPORTED, actionCount, duration, fileCount,
                isSearching, root, mimeType, repeatedlyPickTimes);
    }
}