1 /**
2  * Copyright (c) 2017, 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.os.IStatsSubscriptionCallback;
20 import android.os.IPendingIntentRef;
21 import android.os.IPullAtomCallback;
22 import android.os.ParcelFileDescriptor;
23 import android.util.PropertyParcel;
24 import android.os.IStatsQueryCallback;
25 
26 /**
27   * Binder interface to communicate with the statistics management service.
28   * {@hide}
29   */
30 interface IStatsd {
31     /**
32      * Tell the stats daemon that the android system server is up and running.
33      */
systemRunning()34     oneway void systemRunning();
35 
36     /**
37      * Tell the stats daemon that the android system has finished booting.
38      */
bootCompleted()39     oneway void bootCompleted();
40 
41     /**
42      * Tell the stats daemon that the StatsCompanionService is up and running.
43      * Two-way binder call so that caller knows message received.
44      */
statsCompanionReady()45     void statsCompanionReady();
46 
47     /**
48      * Tells statsd that an anomaly may have occurred, so statsd can check whether this is so and
49      * act accordingly.
50      * Two-way binder call so that caller's method (and corresponding wakelocks) will linger.
51      */
informAnomalyAlarmFired()52     void informAnomalyAlarmFired();
53 
54     /**
55      * Tells statsd that it is time to poll some stats. Statsd will be responsible for determing
56      * what stats to poll and initiating the polling.
57      * Two-way binder call so that caller's method (and corresponding wakelocks) will linger.
58      */
informPollAlarmFired()59     void informPollAlarmFired();
60 
61     /**
62      * Tells statsd that it is time to handle periodic alarms. Statsd will be responsible for
63      * determing what alarm subscriber to trigger.
64      * Two-way binder call so that caller's method (and corresponding wakelocks) will linger.
65      */
informAlarmForSubscriberTriggeringFired()66     void informAlarmForSubscriberTriggeringFired();
67 
68     /**
69      * Tells statsd that the device is about to shutdown.
70      */
informDeviceShutdown()71     void informDeviceShutdown();
72 
73     /**
74      * Inform statsd about a file descriptor for a pipe through which we will pipe version
75      * and package information for each uid.
76      * Versions and package information are supplied via UidData proto where info for each app
77      * is captured in its own element of a repeated ApplicationInfo message.
78      */
informAllUidData(in ParcelFileDescriptor fd)79     oneway void informAllUidData(in ParcelFileDescriptor fd);
80 
81     /**
82      * Inform statsd what the uid, version, version_string, and installer are for one app that was
83      * updated.
84      */
informOnePackage(in String app, in int uid, in long version, in String version_string, in String installer, in byte[] certificate_hash)85     oneway void informOnePackage(in String app, in int uid, in long version,
86         in String version_string, in String installer, in byte[] certificate_hash);
87 
88     /**
89      * Inform stats that an app was removed.
90      */
informOnePackageRemoved(in String app, in int uid)91     oneway void informOnePackageRemoved(in String app, in int uid);
92 
93     /**
94      * Fetches data for the specified configuration key. Returns a byte array representing proto
95      * wire-encoded of ConfigMetricsReportList.
96      *
97      * Requires Manifest.permission.DUMP.
98      * @deprecated use #getDataFd() instead for Android T+
99      */
getData(in long key, int callingUid)100     byte[] getData(in long key, int callingUid);
101 
102     /**
103      * Fetches metadata across statsd. Returns byte array representing wire-encoded proto.
104      *
105      * Requires Manifest.permission.DUMP.
106      */
getMetadata()107     byte[] getMetadata();
108 
109     /**
110      * Sets a configuration with the specified config id and subscribes to updates for this
111      * configuration key. Broadcasts will be sent if this configuration needs to be collected.
112      * The configuration must be a wire-encoded StatsdConfig. The receiver for this data is
113      * registered in a separate function.
114      *
115      * Requires Manifest.permission.DUMP.
116      */
addConfiguration(in long configId, in byte[] config, in int callingUid)117     void addConfiguration(in long configId, in byte[] config, in int callingUid);
118 
119     /**
120      * Registers the given pending intent for this config key. This intent is invoked when the
121      * memory consumed by the metrics for this configuration approach the pre-defined limits. There
122      * can be at most one listener per config key.
123      *
124      * Requires Manifest.permission.DUMP.
125      */
setDataFetchOperation(long configId, in IPendingIntentRef pendingIntentRef, int callingUid)126     void setDataFetchOperation(long configId, in IPendingIntentRef pendingIntentRef,
127                                int callingUid);
128 
129     /**
130      * Removes the data fetch operation for the specified configuration.
131      *
132      * Requires Manifest.permission.DUMP.
133      */
removeDataFetchOperation(long configId, int callingUid)134     void removeDataFetchOperation(long configId, int callingUid);
135 
136     /**
137      * Registers the given pending intent for this packagename. This intent is invoked when the
138      * active status of any of the configs sent by this package changes and will contain a list of
139      * config ids that are currently active. It also returns the list of configs that are currently
140      * active. There can be at most one active configs changed listener per package.
141      *
142      * Requires Manifest.permission.DUMP and Manifest.permission.PACKAGE_USAGE_STATS.
143      */
setActiveConfigsChangedOperation(in IPendingIntentRef pendingIntentRef, int callingUid)144     long[] setActiveConfigsChangedOperation(in IPendingIntentRef pendingIntentRef, int callingUid);
145 
146     /**
147      * Removes the active configs changed operation for the specified package name.
148      *
149      * Requires Manifest.permission.DUMP and Manifest.permission.PACKAGE_USAGE_STATS.
150      */
removeActiveConfigsChangedOperation(int callingUid)151     void removeActiveConfigsChangedOperation(int callingUid);
152 
153     /**
154      * Removes the configuration with the matching config id. No-op if this config id does not
155      * exist.
156      *
157      * Requires Manifest.permission.DUMP.
158      */
removeConfiguration(in long configId, in int callingUid)159     void removeConfiguration(in long configId, in int callingUid);
160 
161     /**
162      * Set the PendingIntentRef to be used when broadcasting subscriber
163      * information to the given subscriberId within the given config.
164      *
165      * Suppose that the calling uid has added a config with key configId, and that in this config
166      * it is specified that when a particular anomaly is detected, a broadcast should be sent to
167      * a BroadcastSubscriber with id subscriberId. This function links the given pendingIntent with
168      * that subscriberId (for that config), so that this pendingIntent is used to send the broadcast
169      * when the anomaly is detected.
170      *
171      * This function can only be called by the owner (uid) of the config. It must be called each
172      * time statsd starts. Later calls overwrite previous calls; only one pendingIntent is stored.
173      *
174      * Requires Manifest.permission.DUMP.
175      */
setBroadcastSubscriber(long configId, long subscriberId, in IPendingIntentRef pir, int callingUid)176     void setBroadcastSubscriber(long configId, long subscriberId, in IPendingIntentRef pir,
177                                 int callingUid);
178 
179     /**
180      * Undoes setBroadcastSubscriber() for the (configId, subscriberId) pair.
181      * Any broadcasts associated with subscriberId will henceforth not be sent.
182      * No-op if this (configKey, subscriberId) pair was not associated with an PendingIntentRef.
183      *
184      * Requires Manifest.permission.DUMP.
185      */
unsetBroadcastSubscriber(long configId, long subscriberId, int callingUid)186     void unsetBroadcastSubscriber(long configId, long subscriberId, int callingUid);
187 
188     /**
189      * Tell the stats daemon that all the pullers registered during boot have been sent.
190      */
allPullersFromBootRegistered()191     oneway void allPullersFromBootRegistered();
192 
193     /**
194      * Registers a puller callback function that, when invoked, pulls the data
195      * for the specified atom tag.
196      */
registerPullAtomCallback(int uid, int atomTag, long coolDownMillis, long timeoutMillis,in int[] additiveFields, IPullAtomCallback pullerCallback)197     oneway void registerPullAtomCallback(int uid, int atomTag, long coolDownMillis,
198                                          long timeoutMillis,in int[] additiveFields,
199                                          IPullAtomCallback pullerCallback);
200 
201     /**
202      * Registers a puller callback function that, when invoked, pulls the data
203      * for the specified atom tag.
204      *
205      * Enforces the REGISTER_STATS_PULL_ATOM permission.
206      */
registerNativePullAtomCallback(int atomTag, long coolDownMillis, long timeoutMillis, in int[] additiveFields, IPullAtomCallback pullerCallback)207     oneway void registerNativePullAtomCallback(int atomTag, long coolDownMillis, long timeoutMillis,
208                            in int[] additiveFields, IPullAtomCallback pullerCallback);
209 
210     /**
211      * Unregisters any pullAtomCallback for the given uid/atom.
212      */
unregisterPullAtomCallback(int uid, int atomTag)213     oneway void unregisterPullAtomCallback(int uid, int atomTag);
214 
215     /**
216      * Unregisters any pullAtomCallback for the given atom + caller.
217      *
218      * Enforces the REGISTER_STATS_PULL_ATOM permission.
219      */
unregisterNativePullAtomCallback(int atomTag)220     oneway void unregisterNativePullAtomCallback(int atomTag);
221 
222     /**
223      * The install requires staging.
224      */
225     const int FLAG_REQUIRE_STAGING = 0x01;
226 
227     /**
228      * Rollback is enabled with this install.
229      */
230     const int FLAG_ROLLBACK_ENABLED = 0x02;
231 
232     /**
233      * Requires low latency monitoring.
234      */
235     const int FLAG_REQUIRE_LOW_LATENCY_MONITOR = 0x04;
236 
237     /**
238      * Returns the most recently registered experiment IDs.
239      */
getRegisteredExperimentIds()240     long[] getRegisteredExperimentIds();
241 
242     /**
243      * Notifies of properties in statsd_java namespace.
244      */
updateProperties(in PropertyParcel[] properties)245     oneway void updateProperties(in PropertyParcel[] properties);
246 
247     /** Section for restricted-logging methods. */
248     /**
249      * Queries data from underlying statsd sql store.
250      */
querySql(in String sqlQuery, in int minSqlClientVersion, in @nullable byte[] policyConfig, in IStatsQueryCallback queryCallback, in long configKey, in String configPackage, in int callingUid)251     oneway void querySql(in String sqlQuery, in int minSqlClientVersion,
252         in @nullable byte[] policyConfig, in IStatsQueryCallback queryCallback,
253         in long configKey, in String configPackage, in int callingUid);
254 
255     /**
256      * Registers the operation that is called whenever there is a change in the restricted metrics
257      * for a specified config that are present for this client. This operation allows statsd to
258      * inform the client about the current restricted metrics available to be queried for the
259      * specified config.
260      *
261      * Requires Manifest.permission.READ_RESTRICTED_STATS
262      */
setRestrictedMetricsChangedOperation(in long configKey, in String configPackage, in IPendingIntentRef pir, int callingUid)263     long[] setRestrictedMetricsChangedOperation(in long configKey, in String configPackage,
264             in IPendingIntentRef pir, int callingUid);
265 
266     /**
267      * Removes the restricted metrics changed operation for the specified config package/id.
268      *
269      * Requires Manifest.permission.READ_RESTRICTED_STATS.
270      */
removeRestrictedMetricsChangedOperation(in long configKey, in String configPackage, in int callingUid)271     void removeRestrictedMetricsChangedOperation(in long configKey, in String configPackage,
272             in int callingUid);
273 
274     /** Section for atoms subscription methods. */
275     /**
276      * Adds a subscription for atom events.
277      *
278      * IStatsSubscriptionCallback Binder interface will be used to deliver subscription data back to
279      * the subscriber. IStatsSubscriptionCallback also uniquely identifies this subscription - it
280      * should not be reused for another subscription.
281      *
282      * Enforces caller is in the traced_probes selinux domain.
283      */
addSubscription(in byte[] subscriptionConfig, IStatsSubscriptionCallback callback)284     oneway void addSubscription(in byte[] subscriptionConfig,
285             IStatsSubscriptionCallback callback);
286 
287     /**
288      * Unsubscribe from a given subscription identified by the IBinder token.
289      *
290      * This will subsequently trigger IStatsSubscriptionCallback with pending data
291      * for this subscription.
292      *
293      * Enforces caller is in the traced_probes selinux domain.
294      */
removeSubscription(IStatsSubscriptionCallback callback)295     oneway void removeSubscription(IStatsSubscriptionCallback callback);
296 
297     /**
298      * Flush data for a subscription.
299      *
300      * This will subsequently trigger IStatsSubscriptionCallback with pending data
301      * for this subscription.
302      *
303      * Enforces caller is in the traced_probes selinux domain.
304      */
flushSubscription(IStatsSubscriptionCallback callback)305     oneway void flushSubscription(IStatsSubscriptionCallback callback);
306 
307     /**
308      * Same as #getData(in long key, int callingUid), but the data is stored in a file descriptor.
309      *
310      * The call is async, purpose is to initiate data transfer process.
311      * Report is expected to be written into fd.
312      * The content schema is |4 bytes - expected report size in bytes|report body of len bytes|EOF|.
313      * fd will be closed automatically at the end of the transaction.
314      * To confirm report correctness expected report size should be equal to size of report body
315      * read from file descriptor. Any IOException during the read signals about failure and API
316      * call should be considered as failed.
317      *
318      * Requires Manifest.permission.DUMP.
319      */
getDataFd(long key, int callingUid, in ParcelFileDescriptor fd)320     oneway void getDataFd(long key, int callingUid, in ParcelFileDescriptor fd);
321 }
322