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 /**
20   * Binder interface to communicate with the statistics management service.
21   * {@hide}
22   */
23 interface IStatsManager {
24     /**
25      * Tell the stats daemon that the android system server is up and running.
26      */
systemRunning()27     oneway void systemRunning();
28 
29     /**
30      * Tell the stats daemon that the StatsCompanionService is up and running.
31      * Two-way binder call so that caller knows message received.
32      */
statsCompanionReady()33     void statsCompanionReady();
34 
35     /**
36      * Tells statsd that an anomaly may have occurred, so statsd can check whether this is so and
37      * act accordingly.
38      * Two-way binder call so that caller's method (and corresponding wakelocks) will linger.
39      */
informAnomalyAlarmFired()40     void informAnomalyAlarmFired();
41 
42     /**
43      * Tells statsd that it is time to poll some stats. Statsd will be responsible for determing
44      * what stats to poll and initiating the polling.
45      * Two-way binder call so that caller's method (and corresponding wakelocks) will linger.
46      */
informPollAlarmFired()47     void informPollAlarmFired();
48 
49     /**
50      * Tells statsd that it is time to handle periodic alarms. Statsd will be responsible for
51      * determing what alarm subscriber to trigger.
52      * Two-way binder call so that caller's method (and corresponding wakelocks) will linger.
53      */
informAlarmForSubscriberTriggeringFired()54     void informAlarmForSubscriberTriggeringFired();
55 
56     /**
57      * Tells statsd that the device is about to shutdown.
58      */
informDeviceShutdown()59     void informDeviceShutdown();
60 
61     /**
62      * Inform statsd what the version and package are for each uid. Note that each array should
63      * have the same number of elements, and version[i] and package[i] correspond to uid[i].
64      */
informAllUidData(in int[] uid, in long[] version, in String[] app)65     oneway void informAllUidData(in int[] uid, in long[] version, in String[] app);
66 
67     /**
68      * Inform statsd what the uid and version are for one app that was updated.
69      */
informOnePackage(in String app, in int uid, in long version)70     oneway void informOnePackage(in String app, in int uid, in long version);
71 
72     /**
73      * Inform stats that an app was removed.
74      */
informOnePackageRemoved(in String app, in int uid)75     oneway void informOnePackageRemoved(in String app, in int uid);
76 
77     /**
78      * Fetches data for the specified configuration key. Returns a byte array representing proto
79      * wire-encoded of ConfigMetricsReportList.
80      *
81      * Requires Manifest.permission.DUMP.
82      */
getData(in long key, in String packageName)83     byte[] getData(in long key, in String packageName);
84 
85     /**
86      * Fetches metadata across statsd. Returns byte array representing wire-encoded proto.
87      *
88      * Requires Manifest.permission.DUMP.
89      */
getMetadata(in String packageName)90     byte[] getMetadata(in String packageName);
91 
92     /**
93      * Sets a configuration with the specified config key and subscribes to updates for this
94      * configuration key. Broadcasts will be sent if this configuration needs to be collected.
95      * The configuration must be a wire-encoded StatsdConfig. The receiver for this data is
96      * registered in a separate function.
97      *
98      * Requires Manifest.permission.DUMP.
99      */
addConfiguration(in long configKey, in byte[] config, in String packageName)100     void addConfiguration(in long configKey, in byte[] config, in String packageName);
101 
102     /**
103      * Registers the given pending intent for this config key. This intent is invoked when the
104      * memory consumed by the metrics for this configuration approach the pre-defined limits. There
105      * can be at most one listener per config key.
106      *
107      * Requires Manifest.permission.DUMP.
108      */
setDataFetchOperation(long configKey, in IBinder intentSender, in String packageName)109     void setDataFetchOperation(long configKey, in IBinder intentSender, in String packageName);
110 
111     /**
112      * Removes the data fetch operation for the specified configuration.
113      *
114      * Requires Manifest.permission.DUMP.
115      */
removeDataFetchOperation(long configKey, in String packageName)116     void removeDataFetchOperation(long configKey, in String packageName);
117 
118     /**
119      * Removes the configuration with the matching config key. No-op if this config key does not
120      * exist.
121      *
122      * Requires Manifest.permission.DUMP.
123      */
removeConfiguration(in long configKey, in String packageName)124     void removeConfiguration(in long configKey, in String packageName);
125 
126     /**
127      * Set the IIntentSender (i.e. PendingIntent) to be used when broadcasting subscriber
128      * information to the given subscriberId within the given config.
129      *
130      * Suppose that the calling uid has added a config with key configKey, and that in this config
131      * it is specified that when a particular anomaly is detected, a broadcast should be sent to
132      * a BroadcastSubscriber with id subscriberId. This function links the given intentSender with
133      * that subscriberId (for that config), so that this intentSender is used to send the broadcast
134      * when the anomaly is detected.
135      *
136      * This function can only be called by the owner (uid) of the config. It must be called each
137      * time statsd starts. Later calls overwrite previous calls; only one intentSender is stored.
138      *
139      * intentSender must be convertible into an IntentSender using IntentSender(IBinder)
140      * and cannot be null.
141      *
142      * Requires Manifest.permission.DUMP.
143      */
setBroadcastSubscriber(long configKey, long subscriberId, in IBinder intentSender, in String packageName)144     void setBroadcastSubscriber(long configKey, long subscriberId, in IBinder intentSender,
145                                 in String packageName);
146 
147     /**
148      * Undoes setBroadcastSubscriber() for the (configKey, subscriberId) pair.
149      * Any broadcasts associated with subscriberId will henceforth not be sent.
150      * No-op if this (configKey, subsriberId) pair was not associated with an IntentSender.
151      *
152      * Requires Manifest.permission.DUMP.
153      */
unsetBroadcastSubscriber(long configKey, long subscriberId, in String packageName)154     void unsetBroadcastSubscriber(long configKey, long subscriberId, in String packageName);
155 
156     /**
157      * Apps can send an atom via this application breadcrumb with the specified label and state for
158      * this label. This allows building custom metrics and predicates.
159      */
sendAppBreadcrumbAtom(int label, int state)160     void sendAppBreadcrumbAtom(int label, int state);
161 }
162