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.os;
18 
19 import android.app.PendingIntent;
20 import android.os.IPullAtomCallback;
21 import android.os.IStatsQueryCallback;
22 
23 /**
24   * Binder interface to communicate with the Java-based statistics service helper.
25   * Contains parcelable objects available only in Java.
26   * {@hide}
27   */
28 interface IStatsManagerService {
29 
30     /**
31      * Registers the given pending intent for this config key. This intent is invoked when the
32      * memory consumed by the metrics for this configuration approach the pre-defined limits. There
33      * can be at most one listener per config key.
34      *
35      * Requires Manifest.permission.DUMP and Manifest.permission.PACKAGE_USAGE_STATS.
36      */
setDataFetchOperation(long configId, in PendingIntent pendingIntent, in String packageName)37     void setDataFetchOperation(long configId, in PendingIntent pendingIntent,
38         in String packageName);
39 
40     /**
41      * Removes the data fetch operation for the specified configuration.
42      *
43      * Requires Manifest.permission.DUMP and Manifest.permission.PACKAGE_USAGE_STATS.
44      */
removeDataFetchOperation(long configId, in String packageName)45     void removeDataFetchOperation(long configId, in String packageName);
46 
47     /**
48      * Registers the given pending intent for this packagename. This intent is invoked when the
49      * active status of any of the configs sent by this package changes and will contain a list of
50      * config ids that are currently active. It also returns the list of configs that are currently
51      * active. There can be at most one active configs changed listener per package.
52      *
53      * Requires Manifest.permission.DUMP and Manifest.permission.PACKAGE_USAGE_STATS.
54      */
setActiveConfigsChangedOperation(in PendingIntent pendingIntent, in String packageName)55     long[] setActiveConfigsChangedOperation(in PendingIntent pendingIntent, in String packageName);
56 
57     /**
58      * Removes the active configs changed operation for the specified package name.
59      *
60      * Requires Manifest.permission.DUMP and Manifest.permission.PACKAGE_USAGE_STATS.
61      */
removeActiveConfigsChangedOperation(in String packageName)62     void removeActiveConfigsChangedOperation(in String packageName);
63 
64     /**
65      * Set the PendingIntent to be used when broadcasting subscriber
66      * information to the given subscriberId within the given config.
67      *
68      * Suppose that the calling uid has added a config with key configKey, and that in this config
69      * it is specified that when a particular anomaly is detected, a broadcast should be sent to
70      * a BroadcastSubscriber with id subscriberId. This function links the given pendingIntent with
71      * that subscriberId (for that config), so that this pendingIntent is used to send the broadcast
72      * when the anomaly is detected.
73      *
74      * This function can only be called by the owner (uid) of the config. It must be called each
75      * time statsd starts. Later calls overwrite previous calls; only one PendingIntent is stored.
76      *
77      * Requires Manifest.permission.DUMP and Manifest.permission.PACKAGE_USAGE_STATS.
78      */
setBroadcastSubscriber(long configKey, long subscriberId, in PendingIntent pendingIntent, in String packageName)79     void setBroadcastSubscriber(long configKey, long subscriberId, in PendingIntent pendingIntent,
80                                 in String packageName);
81 
82     /**
83      * Undoes setBroadcastSubscriber() for the (configKey, subscriberId) pair.
84      * Any broadcasts associated with subscriberId will henceforth not be sent.
85      * No-op if this (configKey, subscriberId) pair was not associated with an PendingIntent.
86      *
87      * Requires Manifest.permission.DUMP and Manifest.permission.PACKAGE_USAGE_STATS.
88      */
unsetBroadcastSubscriber(long configKey, long subscriberId, in String packageName)89     void unsetBroadcastSubscriber(long configKey, long subscriberId, in String packageName);
90 
91     /**
92      * Returns the most recently registered experiment IDs.
93      *
94      * Requires Manifest.permission.DUMP and Manifest.permission.PACKAGE_USAGE_STATS.
95      */
getRegisteredExperimentIds()96     long[] getRegisteredExperimentIds();
97 
98     /**
99      * Fetches metadata across statsd. Returns byte array representing wire-encoded proto.
100      *
101      * Requires Manifest.permission.DUMP and Manifest.permission.PACKAGE_USAGE_STATS.
102      */
getMetadata(in String packageName)103     byte[] getMetadata(in String packageName);
104 
105     /**
106      * Fetches data for the specified configuration key. Returns a byte array representing proto
107      * wire-encoded of ConfigMetricsReportList.
108      *
109      * Requires Manifest.permission.DUMP and Manifest.permission.PACKAGE_USAGE_STATS.
110      * @deprecated use #getDataFd() instead
111      */
getData(in long key, in String packageName)112     byte[] getData(in long key, in String packageName);
113 
114     /**
115      * Sets a configuration with the specified config id and subscribes to updates for this
116      * configuration id. Broadcasts will be sent if this configuration needs to be collected.
117      * The configuration must be a wire-encoded StatsdConfig. The receiver for this data is
118      * registered in a separate function.
119      *
120      * Requires Manifest.permission.DUMP and Manifest.permission.PACKAGE_USAGE_STATS.
121      */
addConfiguration(in long configId, in byte[] config, in String packageName)122     void addConfiguration(in long configId, in byte[] config, in String packageName);
123 
124     /**
125      * Removes the configuration with the matching config id. No-op if this config id does not
126      * exist.
127      *
128      * Requires Manifest.permission.DUMP and Manifest.permission.PACKAGE_USAGE_STATS.
129      */
removeConfiguration(in long configId, in String packageName)130     void removeConfiguration(in long configId, in String packageName);
131 
132     /** Tell StatsManagerService to register a puller for the given atom tag with statsd. */
registerPullAtomCallback(int atomTag, long coolDownMillis, long timeoutMillis, in int[] additiveFields, IPullAtomCallback pullerCallback)133     oneway void registerPullAtomCallback(int atomTag, long coolDownMillis, long timeoutMillis,
134             in int[] additiveFields, IPullAtomCallback pullerCallback);
135 
136     /** Tell StatsManagerService to unregister the puller for the given atom tag from statsd. */
unregisterPullAtomCallback(int atomTag)137     oneway void unregisterPullAtomCallback(int atomTag);
138 
139     /** Section for restricted-logging methods. */
140 
141     /** Queries data from underlying statsd sql store. */
querySql(in String sqlQuery, in int minSqlClientVersion, in @nullable byte[] policyConfig, in IStatsQueryCallback queryCallback, in long configKey, in String configPackage)142     oneway void querySql(in String sqlQuery, in int minSqlClientVersion,
143         in @nullable byte[] policyConfig, in IStatsQueryCallback queryCallback,
144         in long configKey, in String configPackage);
145 
146     /**
147      * Registers the operation that is called whenever there is a change in the restricted metrics
148      * for a specified config that are present for this client. This operation allows statsd to
149      * inform the client about the current restricted metrics available to be queried for
150      * the specified config.
151      *
152      * Requires Manifest.permission.READ_RESTRICTED_STATS.
153      */
setRestrictedMetricsChangedOperation(in PendingIntent pendingIntent, in long configKey, in String configPackage)154     long[] setRestrictedMetricsChangedOperation(in PendingIntent pendingIntent, in long configKey,
155             in String configPackage);
156 
157     /**
158      * Removes the restricted metrics changed operation for the specified config key/package.
159      *
160      * Requires Manifest.permission.READ_RESTRICTED_STATS.
161      */
removeRestrictedMetricsChangedOperation(in long configKey, in String configPackage)162     void removeRestrictedMetricsChangedOperation(in long configKey, in String configPackage);
163 
164     /**
165      * Same as #getData(in long key, in String packageName), but the data is stored in a file
166      * descriptor.
167      *
168      * Requires Manifest.permission.DUMP and Manifest.permission.PACKAGE_USAGE_STATS.
169      */
getDataFd(long key, in String packageName, in ParcelFileDescriptor fd)170     oneway void getDataFd(long key, in String packageName, in ParcelFileDescriptor fd);
171 }
172