15dcbc6c015fd56db9381cb7aff58506e8ebcc150Joe Onorato/**
2947fbce521d9e8377df03e3c1c31884ed5577f32yro * Copyright (c) 2017, The Android Open Source Project
35dcbc6c015fd56db9381cb7aff58506e8ebcc150Joe Onorato *
45dcbc6c015fd56db9381cb7aff58506e8ebcc150Joe Onorato * Licensed under the Apache License, Version 2.0 (the "License");
55dcbc6c015fd56db9381cb7aff58506e8ebcc150Joe Onorato * you may not use this file except in compliance with the License.
65dcbc6c015fd56db9381cb7aff58506e8ebcc150Joe Onorato * You may obtain a copy of the License at
75dcbc6c015fd56db9381cb7aff58506e8ebcc150Joe Onorato *
85dcbc6c015fd56db9381cb7aff58506e8ebcc150Joe Onorato *     http://www.apache.org/licenses/LICENSE-2.0
95dcbc6c015fd56db9381cb7aff58506e8ebcc150Joe Onorato *
105dcbc6c015fd56db9381cb7aff58506e8ebcc150Joe Onorato * Unless required by applicable law or agreed to in writing, software
115dcbc6c015fd56db9381cb7aff58506e8ebcc150Joe Onorato * distributed under the License is distributed on an "AS IS" BASIS,
125dcbc6c015fd56db9381cb7aff58506e8ebcc150Joe Onorato * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
135dcbc6c015fd56db9381cb7aff58506e8ebcc150Joe Onorato * See the License for the specific language governing permissions and
145dcbc6c015fd56db9381cb7aff58506e8ebcc150Joe Onorato * limitations under the License.
155dcbc6c015fd56db9381cb7aff58506e8ebcc150Joe Onorato */
165dcbc6c015fd56db9381cb7aff58506e8ebcc150Joe Onorato
175dcbc6c015fd56db9381cb7aff58506e8ebcc150Joe Onoratopackage android.os;
185dcbc6c015fd56db9381cb7aff58506e8ebcc150Joe Onorato
195dcbc6c015fd56db9381cb7aff58506e8ebcc150Joe Onorato/**
201b0b114abca0a7c7642b0b7de343e1e2f982ebf0Bookatz  * Binder interface to communicate with the statistics management service.
215dcbc6c015fd56db9381cb7aff58506e8ebcc150Joe Onorato  * {@hide}
225dcbc6c015fd56db9381cb7aff58506e8ebcc150Joe Onorato  */
23b487b5533eba8635232009c7f32a54a0380a532dBookatzinterface IStatsManager {
245dcbc6c015fd56db9381cb7aff58506e8ebcc150Joe Onorato    /**
251b0b114abca0a7c7642b0b7de343e1e2f982ebf0Bookatz     * Tell the stats daemon that the android system server is up and running.
265dcbc6c015fd56db9381cb7aff58506e8ebcc150Joe Onorato     */
27b487b5533eba8635232009c7f32a54a0380a532dBookatz    oneway void systemRunning();
28b487b5533eba8635232009c7f32a54a0380a532dBookatz
29b487b5533eba8635232009c7f32a54a0380a532dBookatz    /**
30b487b5533eba8635232009c7f32a54a0380a532dBookatz     * Tell the stats daemon that the StatsCompanionService is up and running.
31b487b5533eba8635232009c7f32a54a0380a532dBookatz     * Two-way binder call so that caller knows message received.
32b487b5533eba8635232009c7f32a54a0380a532dBookatz     */
33b487b5533eba8635232009c7f32a54a0380a532dBookatz    void statsCompanionReady();
341b0b114abca0a7c7642b0b7de343e1e2f982ebf0Bookatz
351b0b114abca0a7c7642b0b7de343e1e2f982ebf0Bookatz    /**
361b0b114abca0a7c7642b0b7de343e1e2f982ebf0Bookatz     * Tells statsd that an anomaly may have occurred, so statsd can check whether this is so and
371b0b114abca0a7c7642b0b7de343e1e2f982ebf0Bookatz     * act accordingly.
38b487b5533eba8635232009c7f32a54a0380a532dBookatz     * Two-way binder call so that caller's method (and corresponding wakelocks) will linger.
391b0b114abca0a7c7642b0b7de343e1e2f982ebf0Bookatz     */
401b0b114abca0a7c7642b0b7de343e1e2f982ebf0Bookatz    void informAnomalyAlarmFired();
411b0b114abca0a7c7642b0b7de343e1e2f982ebf0Bookatz
42b487b5533eba8635232009c7f32a54a0380a532dBookatz    /**
43b487b5533eba8635232009c7f32a54a0380a532dBookatz     * Tells statsd that it is time to poll some stats. Statsd will be responsible for determing
441b0b114abca0a7c7642b0b7de343e1e2f982ebf0Bookatz     * what stats to poll and initiating the polling.
45b487b5533eba8635232009c7f32a54a0380a532dBookatz     * Two-way binder call so that caller's method (and corresponding wakelocks) will linger.
461b0b114abca0a7c7642b0b7de343e1e2f982ebf0Bookatz     */
471b0b114abca0a7c7642b0b7de343e1e2f982ebf0Bookatz    void informPollAlarmFired();
48de70169109c57787a23c732ec4b361ade2e9850eDavid Chen
49de70169109c57787a23c732ec4b361ade2e9850eDavid Chen    /**
50932ececa1674c59a8da9f3e32d2651e781b86fc4Yangster-mac     * Tells statsd that it is time to handle periodic alarms. Statsd will be responsible for
51932ececa1674c59a8da9f3e32d2651e781b86fc4Yangster-mac     * determing what alarm subscriber to trigger.
52932ececa1674c59a8da9f3e32d2651e781b86fc4Yangster-mac     * Two-way binder call so that caller's method (and corresponding wakelocks) will linger.
53932ececa1674c59a8da9f3e32d2651e781b86fc4Yangster-mac     */
54932ececa1674c59a8da9f3e32d2651e781b86fc4Yangster-mac    void informAlarmForSubscriberTriggeringFired();
55932ececa1674c59a8da9f3e32d2651e781b86fc4Yangster-mac
56932ececa1674c59a8da9f3e32d2651e781b86fc4Yangster-mac    /**
57e36018b2724b5ae40180f956b16c3e276855b99bChenjie Yu     * Tells statsd that the device is about to shutdown.
58947fbce521d9e8377df03e3c1c31884ed5577f32yro     */
59892f3d32293b8358c72da4a94633827abbda640bYangster-mac    void informDeviceShutdown();
60947fbce521d9e8377df03e3c1c31884ed5577f32yro
61947fbce521d9e8377df03e3c1c31884ed5577f32yro    /**
62de70169109c57787a23c732ec4b361ade2e9850eDavid Chen     * Inform statsd what the version and package are for each uid. Note that each array should
63de70169109c57787a23c732ec4b361ade2e9850eDavid Chen     * have the same number of elements, and version[i] and package[i] correspond to uid[i].
64de70169109c57787a23c732ec4b361ade2e9850eDavid Chen     */
653accca05ddcad9d0b1b313eae49f273e39121d3cDianne Hackborn    oneway void informAllUidData(in int[] uid, in long[] version, in String[] app);
66de70169109c57787a23c732ec4b361ade2e9850eDavid Chen
67de70169109c57787a23c732ec4b361ade2e9850eDavid Chen    /**
68de70169109c57787a23c732ec4b361ade2e9850eDavid Chen     * Inform statsd what the uid and version are for one app that was updated.
69de70169109c57787a23c732ec4b361ade2e9850eDavid Chen     */
703accca05ddcad9d0b1b313eae49f273e39121d3cDianne Hackborn    oneway void informOnePackage(in String app, in int uid, in long version);
71de70169109c57787a23c732ec4b361ade2e9850eDavid Chen
72de70169109c57787a23c732ec4b361ade2e9850eDavid Chen    /**
73de70169109c57787a23c732ec4b361ade2e9850eDavid Chen     * Inform stats that an app was removed.
74de70169109c57787a23c732ec4b361ade2e9850eDavid Chen     */
75de70169109c57787a23c732ec4b361ade2e9850eDavid Chen    oneway void informOnePackageRemoved(in String app, in int uid);
7631eb67b3498d326659b2b164ff367a01a793d641yro
7731eb67b3498d326659b2b164ff367a01a793d641yro    /**
78adaf8b344e312853530e276ceff05783133ecf17David Chen     * Fetches data for the specified configuration key. Returns a byte array representing proto
792e8f3807379f5d5d151ad2cb434d8a7aca910238David Chen     * wire-encoded of ConfigMetricsReportList.
804f71629002ae1da22ca1c07ce11b9cca9b272d97Bookatz     *
814f71629002ae1da22ca1c07ce11b9cca9b272d97Bookatz     * Requires Manifest.permission.DUMP.
8231eb67b3498d326659b2b164ff367a01a793d641yro     */
836b649257377b4ba2dd8a2a02b8dd692a72a2cc1eJeff Sharkey    byte[] getData(in long key, in String packageName);
8431eb67b3498d326659b2b164ff367a01a793d641yro
8531eb67b3498d326659b2b164ff367a01a793d641yro    /**
862e8f3807379f5d5d151ad2cb434d8a7aca910238David Chen     * Fetches metadata across statsd. Returns byte array representing wire-encoded proto.
874f71629002ae1da22ca1c07ce11b9cca9b272d97Bookatz     *
884f71629002ae1da22ca1c07ce11b9cca9b272d97Bookatz     * Requires Manifest.permission.DUMP.
892e8f3807379f5d5d151ad2cb434d8a7aca910238David Chen     */
906b649257377b4ba2dd8a2a02b8dd692a72a2cc1eJeff Sharkey    byte[] getMetadata(in String packageName);
912e8f3807379f5d5d151ad2cb434d8a7aca910238David Chen
922e8f3807379f5d5d151ad2cb434d8a7aca910238David Chen    /**
93adaf8b344e312853530e276ceff05783133ecf17David Chen     * Sets a configuration with the specified config key and subscribes to updates for this
94adaf8b344e312853530e276ceff05783133ecf17David Chen     * configuration key. Broadcasts will be sent if this configuration needs to be collected.
954f71629002ae1da22ca1c07ce11b9cca9b272d97Bookatz     * The configuration must be a wire-encoded StatsdConfig. The receiver for this data is
96661f791a2580515eee5882ab9498aef94a0d33a5David Chen     * registered in a separate function.
97adaf8b344e312853530e276ceff05783133ecf17David Chen     *
984f71629002ae1da22ca1c07ce11b9cca9b272d97Bookatz     * Requires Manifest.permission.DUMP.
9931eb67b3498d326659b2b164ff367a01a793d641yro     */
1006b649257377b4ba2dd8a2a02b8dd692a72a2cc1eJeff Sharkey    void addConfiguration(in long configKey, in byte[] config, in String packageName);
101661f791a2580515eee5882ab9498aef94a0d33a5David Chen
102661f791a2580515eee5882ab9498aef94a0d33a5David Chen    /**
103661f791a2580515eee5882ab9498aef94a0d33a5David Chen     * Registers the given pending intent for this config key. This intent is invoked when the
104661f791a2580515eee5882ab9498aef94a0d33a5David Chen     * memory consumed by the metrics for this configuration approach the pre-defined limits. There
105661f791a2580515eee5882ab9498aef94a0d33a5David Chen     * can be at most one listener per config key.
106661f791a2580515eee5882ab9498aef94a0d33a5David Chen     *
1074f71629002ae1da22ca1c07ce11b9cca9b272d97Bookatz     * Requires Manifest.permission.DUMP.
108661f791a2580515eee5882ab9498aef94a0d33a5David Chen     */
1096b649257377b4ba2dd8a2a02b8dd692a72a2cc1eJeff Sharkey    void setDataFetchOperation(long configKey, in IBinder intentSender, in String packageName);
110661f791a2580515eee5882ab9498aef94a0d33a5David Chen
111661f791a2580515eee5882ab9498aef94a0d33a5David Chen    /**
112661f791a2580515eee5882ab9498aef94a0d33a5David Chen     * Removes the data fetch operation for the specified configuration.
1134f71629002ae1da22ca1c07ce11b9cca9b272d97Bookatz     *
1144f71629002ae1da22ca1c07ce11b9cca9b272d97Bookatz     * Requires Manifest.permission.DUMP.
115661f791a2580515eee5882ab9498aef94a0d33a5David Chen     */
1166b649257377b4ba2dd8a2a02b8dd692a72a2cc1eJeff Sharkey    void removeDataFetchOperation(long configKey, in String packageName);
117adaf8b344e312853530e276ceff05783133ecf17David Chen
118adaf8b344e312853530e276ceff05783133ecf17David Chen    /**
119adaf8b344e312853530e276ceff05783133ecf17David Chen     * Removes the configuration with the matching config key. No-op if this config key does not
120adaf8b344e312853530e276ceff05783133ecf17David Chen     * exist.
121adaf8b344e312853530e276ceff05783133ecf17David Chen     *
1224f71629002ae1da22ca1c07ce11b9cca9b272d97Bookatz     * Requires Manifest.permission.DUMP.
123adaf8b344e312853530e276ceff05783133ecf17David Chen     */
1246b649257377b4ba2dd8a2a02b8dd692a72a2cc1eJeff Sharkey    void removeConfiguration(in long configKey, in String packageName);
125c697797d43b6932fc7cca1c8d7d850c3fb4d1452Bookatz
126c697797d43b6932fc7cca1c8d7d850c3fb4d1452Bookatz    /**
127c697797d43b6932fc7cca1c8d7d850c3fb4d1452Bookatz     * Set the IIntentSender (i.e. PendingIntent) to be used when broadcasting subscriber
128c697797d43b6932fc7cca1c8d7d850c3fb4d1452Bookatz     * information to the given subscriberId within the given config.
129c697797d43b6932fc7cca1c8d7d850c3fb4d1452Bookatz     *
130c697797d43b6932fc7cca1c8d7d850c3fb4d1452Bookatz     * Suppose that the calling uid has added a config with key configKey, and that in this config
131c697797d43b6932fc7cca1c8d7d850c3fb4d1452Bookatz     * it is specified that when a particular anomaly is detected, a broadcast should be sent to
132c697797d43b6932fc7cca1c8d7d850c3fb4d1452Bookatz     * a BroadcastSubscriber with id subscriberId. This function links the given intentSender with
133c697797d43b6932fc7cca1c8d7d850c3fb4d1452Bookatz     * that subscriberId (for that config), so that this intentSender is used to send the broadcast
134c697797d43b6932fc7cca1c8d7d850c3fb4d1452Bookatz     * when the anomaly is detected.
135c697797d43b6932fc7cca1c8d7d850c3fb4d1452Bookatz     *
136c697797d43b6932fc7cca1c8d7d850c3fb4d1452Bookatz     * This function can only be called by the owner (uid) of the config. It must be called each
137c697797d43b6932fc7cca1c8d7d850c3fb4d1452Bookatz     * time statsd starts. Later calls overwrite previous calls; only one intentSender is stored.
138c697797d43b6932fc7cca1c8d7d850c3fb4d1452Bookatz     *
139c697797d43b6932fc7cca1c8d7d850c3fb4d1452Bookatz     * intentSender must be convertible into an IntentSender using IntentSender(IBinder)
140c697797d43b6932fc7cca1c8d7d850c3fb4d1452Bookatz     * and cannot be null.
141c697797d43b6932fc7cca1c8d7d850c3fb4d1452Bookatz     *
1424f71629002ae1da22ca1c07ce11b9cca9b272d97Bookatz     * Requires Manifest.permission.DUMP.
143c697797d43b6932fc7cca1c8d7d850c3fb4d1452Bookatz     */
1446b649257377b4ba2dd8a2a02b8dd692a72a2cc1eJeff Sharkey    void setBroadcastSubscriber(long configKey, long subscriberId, in IBinder intentSender,
1456b649257377b4ba2dd8a2a02b8dd692a72a2cc1eJeff Sharkey                                in String packageName);
146c697797d43b6932fc7cca1c8d7d850c3fb4d1452Bookatz
147c697797d43b6932fc7cca1c8d7d850c3fb4d1452Bookatz    /**
148c697797d43b6932fc7cca1c8d7d850c3fb4d1452Bookatz     * Undoes setBroadcastSubscriber() for the (configKey, subscriberId) pair.
149c697797d43b6932fc7cca1c8d7d850c3fb4d1452Bookatz     * Any broadcasts associated with subscriberId will henceforth not be sent.
150c697797d43b6932fc7cca1c8d7d850c3fb4d1452Bookatz     * No-op if this (configKey, subsriberId) pair was not associated with an IntentSender.
151c697797d43b6932fc7cca1c8d7d850c3fb4d1452Bookatz     *
1524f71629002ae1da22ca1c07ce11b9cca9b272d97Bookatz     * Requires Manifest.permission.DUMP.
153c697797d43b6932fc7cca1c8d7d850c3fb4d1452Bookatz     */
1546b649257377b4ba2dd8a2a02b8dd692a72a2cc1eJeff Sharkey    void unsetBroadcastSubscriber(long configKey, long subscriberId, in String packageName);
155be6d7f90e8487f16e9459011f3b85ca354429f14yro
156be6d7f90e8487f16e9459011f3b85ca354429f14yro    /**
157be6d7f90e8487f16e9459011f3b85ca354429f14yro     * Apps can send an atom via this application breadcrumb with the specified label and state for
158be6d7f90e8487f16e9459011f3b85ca354429f14yro     * this label. This allows building custom metrics and predicates.
159be6d7f90e8487f16e9459011f3b85ca354429f14yro     */
160be6d7f90e8487f16e9459011f3b85ca354429f14yro    void sendAppBreadcrumbAtom(int label, int state);
1615dcbc6c015fd56db9381cb7aff58506e8ebcc150Joe Onorato}
162