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 */ getData(in long key, int callingUid)99 byte[] getData(in long key, int callingUid); 100 101 /** 102 * Fetches metadata across statsd. Returns byte array representing wire-encoded proto. 103 * 104 * Requires Manifest.permission.DUMP. 105 */ getMetadata()106 byte[] getMetadata(); 107 108 /** 109 * Sets a configuration with the specified config id and subscribes to updates for this 110 * configuration key. Broadcasts will be sent if this configuration needs to be collected. 111 * The configuration must be a wire-encoded StatsdConfig. The receiver for this data is 112 * registered in a separate function. 113 * 114 * Requires Manifest.permission.DUMP. 115 */ addConfiguration(in long configId, in byte[] config, in int callingUid)116 void addConfiguration(in long configId, in byte[] config, in int callingUid); 117 118 /** 119 * Registers the given pending intent for this config key. This intent is invoked when the 120 * memory consumed by the metrics for this configuration approach the pre-defined limits. There 121 * can be at most one listener per config key. 122 * 123 * Requires Manifest.permission.DUMP. 124 */ setDataFetchOperation(long configId, in IPendingIntentRef pendingIntentRef, int callingUid)125 void setDataFetchOperation(long configId, in IPendingIntentRef pendingIntentRef, 126 int callingUid); 127 128 /** 129 * Removes the data fetch operation for the specified configuration. 130 * 131 * Requires Manifest.permission.DUMP. 132 */ removeDataFetchOperation(long configId, int callingUid)133 void removeDataFetchOperation(long configId, int callingUid); 134 135 /** 136 * Registers the given pending intent for this packagename. This intent is invoked when the 137 * active status of any of the configs sent by this package changes and will contain a list of 138 * config ids that are currently active. It also returns the list of configs that are currently 139 * active. There can be at most one active configs changed listener per package. 140 * 141 * Requires Manifest.permission.DUMP and Manifest.permission.PACKAGE_USAGE_STATS. 142 */ setActiveConfigsChangedOperation(in IPendingIntentRef pendingIntentRef, int callingUid)143 long[] setActiveConfigsChangedOperation(in IPendingIntentRef pendingIntentRef, int callingUid); 144 145 /** 146 * Removes the active configs changed operation for the specified package name. 147 * 148 * Requires Manifest.permission.DUMP and Manifest.permission.PACKAGE_USAGE_STATS. 149 */ removeActiveConfigsChangedOperation(int callingUid)150 void removeActiveConfigsChangedOperation(int callingUid); 151 152 /** 153 * Removes the configuration with the matching config id. No-op if this config id does not 154 * exist. 155 * 156 * Requires Manifest.permission.DUMP. 157 */ removeConfiguration(in long configId, in int callingUid)158 void removeConfiguration(in long configId, in int callingUid); 159 160 /** 161 * Set the PendingIntentRef to be used when broadcasting subscriber 162 * information to the given subscriberId within the given config. 163 * 164 * Suppose that the calling uid has added a config with key configId, and that in this config 165 * it is specified that when a particular anomaly is detected, a broadcast should be sent to 166 * a BroadcastSubscriber with id subscriberId. This function links the given pendingIntent with 167 * that subscriberId (for that config), so that this pendingIntent is used to send the broadcast 168 * when the anomaly is detected. 169 * 170 * This function can only be called by the owner (uid) of the config. It must be called each 171 * time statsd starts. Later calls overwrite previous calls; only one pendingIntent is stored. 172 * 173 * Requires Manifest.permission.DUMP. 174 */ setBroadcastSubscriber(long configId, long subscriberId, in IPendingIntentRef pir, int callingUid)175 void setBroadcastSubscriber(long configId, long subscriberId, in IPendingIntentRef pir, 176 int callingUid); 177 178 /** 179 * Undoes setBroadcastSubscriber() for the (configId, subscriberId) pair. 180 * Any broadcasts associated with subscriberId will henceforth not be sent. 181 * No-op if this (configKey, subscriberId) pair was not associated with an PendingIntentRef. 182 * 183 * Requires Manifest.permission.DUMP. 184 */ unsetBroadcastSubscriber(long configId, long subscriberId, int callingUid)185 void unsetBroadcastSubscriber(long configId, long subscriberId, int callingUid); 186 187 /** 188 * Tell the stats daemon that all the pullers registered during boot have been sent. 189 */ allPullersFromBootRegistered()190 oneway void allPullersFromBootRegistered(); 191 192 /** 193 * Registers a puller callback function that, when invoked, pulls the data 194 * for the specified atom tag. 195 */ registerPullAtomCallback(int uid, int atomTag, long coolDownMillis, long timeoutMillis,in int[] additiveFields, IPullAtomCallback pullerCallback)196 oneway void registerPullAtomCallback(int uid, int atomTag, long coolDownMillis, 197 long timeoutMillis,in int[] additiveFields, 198 IPullAtomCallback pullerCallback); 199 200 /** 201 * Registers a puller callback function that, when invoked, pulls the data 202 * for the specified atom tag. 203 * 204 * Enforces the REGISTER_STATS_PULL_ATOM permission. 205 */ registerNativePullAtomCallback(int atomTag, long coolDownMillis, long timeoutMillis, in int[] additiveFields, IPullAtomCallback pullerCallback)206 oneway void registerNativePullAtomCallback(int atomTag, long coolDownMillis, long timeoutMillis, 207 in int[] additiveFields, IPullAtomCallback pullerCallback); 208 209 /** 210 * Unregisters any pullAtomCallback for the given uid/atom. 211 */ unregisterPullAtomCallback(int uid, int atomTag)212 oneway void unregisterPullAtomCallback(int uid, int atomTag); 213 214 /** 215 * Unregisters any pullAtomCallback for the given atom + caller. 216 * 217 * Enforces the REGISTER_STATS_PULL_ATOM permission. 218 */ unregisterNativePullAtomCallback(int atomTag)219 oneway void unregisterNativePullAtomCallback(int atomTag); 220 221 /** 222 * The install requires staging. 223 */ 224 const int FLAG_REQUIRE_STAGING = 0x01; 225 226 /** 227 * Rollback is enabled with this install. 228 */ 229 const int FLAG_ROLLBACK_ENABLED = 0x02; 230 231 /** 232 * Requires low latency monitoring. 233 */ 234 const int FLAG_REQUIRE_LOW_LATENCY_MONITOR = 0x04; 235 236 /** 237 * Returns the most recently registered experiment IDs. 238 */ getRegisteredExperimentIds()239 long[] getRegisteredExperimentIds(); 240 241 /** 242 * Notifies of properties in statsd_java namespace. 243 */ updateProperties(in PropertyParcel[] properties)244 oneway void updateProperties(in PropertyParcel[] properties); 245 246 /** Section for restricted-logging methods. */ 247 /** 248 * Queries data from underlying statsd sql store. 249 */ querySql(in String sqlQuery, in int minSqlClientVersion, in @nullable byte[] policyConfig, in IStatsQueryCallback queryCallback, in long configKey, in String configPackage, in int callingUid)250 oneway void querySql(in String sqlQuery, in int minSqlClientVersion, 251 in @nullable byte[] policyConfig, in IStatsQueryCallback queryCallback, 252 in long configKey, in String configPackage, in int callingUid); 253 254 /** 255 * Registers the operation that is called whenever there is a change in the restricted metrics 256 * for a specified config that are present for this client. This operation allows statsd to 257 * inform the client about the current restricted metrics available to be queried for the 258 * specified config. 259 * 260 * Requires Manifest.permission.READ_RESTRICTED_STATS 261 */ setRestrictedMetricsChangedOperation(in long configKey, in String configPackage, in IPendingIntentRef pir, int callingUid)262 long[] setRestrictedMetricsChangedOperation(in long configKey, in String configPackage, 263 in IPendingIntentRef pir, int callingUid); 264 265 /** 266 * Removes the restricted metrics changed operation for the specified config package/id. 267 * 268 * Requires Manifest.permission.READ_RESTRICTED_STATS. 269 */ removeRestrictedMetricsChangedOperation(in long configKey, in String configPackage, in int callingUid)270 void removeRestrictedMetricsChangedOperation(in long configKey, in String configPackage, 271 in int callingUid); 272 273 /** Section for atoms subscription methods. */ 274 /** 275 * Adds a subscription for atom events. 276 * 277 * IStatsSubscriptionCallback Binder interface will be used to deliver subscription data back to 278 * the subscriber. IStatsSubscriptionCallback also uniquely identifies this subscription - it 279 * should not be reused for another subscription. 280 * 281 * Enforces caller is in the traced_probes selinux domain. 282 */ addSubscription(in byte[] subscriptionConfig, IStatsSubscriptionCallback callback)283 oneway void addSubscription(in byte[] subscriptionConfig, 284 IStatsSubscriptionCallback callback); 285 286 /** 287 * Unsubscribe from a given subscription identified by the IBinder token. 288 * 289 * This will subsequently trigger IStatsSubscriptionCallback with pending data 290 * for this subscription. 291 * 292 * Enforces caller is in the traced_probes selinux domain. 293 */ removeSubscription(IStatsSubscriptionCallback callback)294 oneway void removeSubscription(IStatsSubscriptionCallback callback); 295 296 /** 297 * Flush data for a subscription. 298 * 299 * This will subsequently trigger IStatsSubscriptionCallback with pending data 300 * for this subscription. 301 * 302 * Enforces caller is in the traced_probes selinux domain. 303 */ flushSubscription(IStatsSubscriptionCallback callback)304 oneway void flushSubscription(IStatsSubscriptionCallback callback); 305 } 306