Joe Onorato | 5dcbc6c | 2017-08-29 15:13:58 -0700 | [diff] [blame] | 1 | /* |
yro | 0feae94 | 2017-11-15 14:38:48 -0800 | [diff] [blame] | 2 | * Copyright (C) 2017 The Android Open Source Project |
Joe Onorato | 5dcbc6c | 2017-08-29 15:13:58 -0700 | [diff] [blame] | 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 | |
Bookatz | b487b55 | 2017-09-18 11:26:01 -0700 | [diff] [blame] | 17 | #define DEBUG true |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 18 | #include "Log.h" |
Joe Onorato | 5dcbc6c | 2017-08-29 15:13:58 -0700 | [diff] [blame] | 19 | |
yro | 87d983c | 2017-11-14 21:31:43 -0800 | [diff] [blame] | 20 | #include "android-base/stringprintf.h" |
Joe Onorato | 5dcbc6c | 2017-08-29 15:13:58 -0700 | [diff] [blame] | 21 | #include "StatsService.h" |
David Chen | adaf8b3 | 2017-11-03 15:42:08 -0700 | [diff] [blame] | 22 | #include "config/ConfigKey.h" |
| 23 | #include "config/ConfigManager.h" |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 24 | #include "storage/DropboxReader.h" |
Joe Onorato | 5dcbc6c | 2017-08-29 15:13:58 -0700 | [diff] [blame] | 25 | |
David Chen | 0656b7a | 2017-09-13 15:53:39 -0700 | [diff] [blame] | 26 | #include <android-base/file.h> |
Joe Onorato | 5dcbc6c | 2017-08-29 15:13:58 -0700 | [diff] [blame] | 27 | #include <binder/IPCThreadState.h> |
| 28 | #include <binder/IServiceManager.h> |
yro | 87d983c | 2017-11-14 21:31:43 -0800 | [diff] [blame] | 29 | #include <dirent.h> |
David Chen | 0656b7a | 2017-09-13 15:53:39 -0700 | [diff] [blame] | 30 | #include <frameworks/base/cmds/statsd/src/statsd_config.pb.h> |
Joe Onorato | 5dcbc6c | 2017-08-29 15:13:58 -0700 | [diff] [blame] | 31 | #include <private/android_filesystem_config.h> |
| 32 | #include <utils/Looper.h> |
Joe Onorato | 2cbc2cc | 2017-08-30 17:03:23 -0700 | [diff] [blame] | 33 | #include <utils/String16.h> |
Joe Onorato | 5dcbc6c | 2017-08-29 15:13:58 -0700 | [diff] [blame] | 34 | #include <stdio.h> |
Yao Chen | 482d272 | 2017-09-12 13:25:43 -0700 | [diff] [blame] | 35 | #include <stdlib.h> |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 36 | #include <sys/system_properties.h> |
Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame] | 37 | #include <unistd.h> |
Joe Onorato | 5dcbc6c | 2017-08-29 15:13:58 -0700 | [diff] [blame] | 38 | |
| 39 | using namespace android; |
| 40 | |
Bookatz | 906a35c | 2017-09-20 15:26:44 -0700 | [diff] [blame] | 41 | namespace android { |
| 42 | namespace os { |
| 43 | namespace statsd { |
| 44 | |
David Chen | adaf8b3 | 2017-11-03 15:42:08 -0700 | [diff] [blame] | 45 | constexpr const char* kPermissionDump = "android.permission.DUMP"; |
yro | 87d983c | 2017-11-14 21:31:43 -0800 | [diff] [blame] | 46 | #define STATS_SERVICE_DIR "/data/system/stats-service" |
David Chen | adaf8b3 | 2017-11-03 15:42:08 -0700 | [diff] [blame] | 47 | |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 48 | // ====================================================================== |
| 49 | /** |
| 50 | * Watches for the death of the stats companion (system process). |
| 51 | */ |
| 52 | class CompanionDeathRecipient : public IBinder::DeathRecipient { |
| 53 | public: |
| 54 | CompanionDeathRecipient(const sp<AnomalyMonitor>& anomalyMonitor); |
| 55 | virtual void binderDied(const wp<IBinder>& who); |
| 56 | |
| 57 | private: |
| 58 | const sp<AnomalyMonitor> mAnomalyMonitor; |
| 59 | }; |
| 60 | |
| 61 | CompanionDeathRecipient::CompanionDeathRecipient(const sp<AnomalyMonitor>& anomalyMonitor) |
| 62 | : mAnomalyMonitor(anomalyMonitor) { |
| 63 | } |
| 64 | |
| 65 | void CompanionDeathRecipient::binderDied(const wp<IBinder>& who) { |
| 66 | ALOGW("statscompanion service died"); |
| 67 | mAnomalyMonitor->setStatsCompanionService(nullptr); |
| 68 | } |
| 69 | |
| 70 | // ====================================================================== |
Joe Onorato | 5dcbc6c | 2017-08-29 15:13:58 -0700 | [diff] [blame] | 71 | StatsService::StatsService(const sp<Looper>& handlerLooper) |
David Chen | 1481fe1 | 2017-10-16 13:16:34 -0700 | [diff] [blame] | 72 | : mAnomalyMonitor(new AnomalyMonitor(2)) // TODO: Put this comment somewhere better |
Joe Onorato | 5dcbc6c | 2017-08-29 15:13:58 -0700 | [diff] [blame] | 73 | { |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 74 | mUidMap = new UidMap(); |
| 75 | mConfigManager = new ConfigManager(); |
David Chen | 1d7b0cd | 2017-11-15 14:20:04 -0800 | [diff] [blame] | 76 | mProcessor = new StatsLogProcessor(mUidMap, [this](const ConfigKey& key) { |
| 77 | auto sc = getStatsCompanionService(); |
| 78 | auto receiver = mConfigManager->GetConfigReceiver(key); |
| 79 | if (sc == nullptr) { |
| 80 | ALOGD("Could not find StatsCompanionService"); |
| 81 | } else if (receiver.first.size() == 0) { |
| 82 | ALOGD("Statscompanion could not find a broadcast receiver for %s", |
| 83 | key.ToString().c_str()); |
| 84 | } else { |
| 85 | sc->sendBroadcast(String16(receiver.first.c_str()), |
| 86 | String16(receiver.second.c_str())); |
| 87 | } |
yro | 31eb67b | 2017-10-24 13:33:21 -0700 | [diff] [blame] | 88 | }); |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 89 | |
| 90 | mConfigManager->AddListener(mProcessor); |
| 91 | |
| 92 | init_system_properties(); |
Joe Onorato | 5dcbc6c | 2017-08-29 15:13:58 -0700 | [diff] [blame] | 93 | } |
| 94 | |
Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame] | 95 | StatsService::~StatsService() { |
Joe Onorato | 5dcbc6c | 2017-08-29 15:13:58 -0700 | [diff] [blame] | 96 | } |
| 97 | |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 98 | void StatsService::init_system_properties() { |
| 99 | mEngBuild = false; |
| 100 | const prop_info* buildType = __system_property_find("ro.build.type"); |
| 101 | if (buildType != NULL) { |
| 102 | __system_property_read_callback(buildType, init_build_type_callback, this); |
| 103 | } |
David Chen | 0656b7a | 2017-09-13 15:53:39 -0700 | [diff] [blame] | 104 | } |
| 105 | |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 106 | void StatsService::init_build_type_callback(void* cookie, const char* /*name*/, const char* value, |
| 107 | uint32_t serial) { |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 108 | if (0 == strcmp("eng", value) || 0 == strcmp("userdebug", value)) { |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 109 | reinterpret_cast<StatsService*>(cookie)->mEngBuild = true; |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | /** |
| 114 | * Implement our own because the default binder implementation isn't |
| 115 | * properly handling SHELL_COMMAND_TRANSACTION. |
| 116 | */ |
Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame] | 117 | status_t StatsService::onTransact(uint32_t code, const Parcel& data, Parcel* reply, |
| 118 | uint32_t flags) { |
Joe Onorato | 2cbc2cc | 2017-08-30 17:03:23 -0700 | [diff] [blame] | 119 | status_t err; |
| 120 | |
| 121 | switch (code) { |
| 122 | case SHELL_COMMAND_TRANSACTION: { |
| 123 | int in = data.readFileDescriptor(); |
| 124 | int out = data.readFileDescriptor(); |
| 125 | int err = data.readFileDescriptor(); |
| 126 | int argc = data.readInt32(); |
| 127 | Vector<String8> args; |
| 128 | for (int i = 0; i < argc && data.dataAvail() > 0; i++) { |
| 129 | args.add(String8(data.readString16())); |
| 130 | } |
Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame] | 131 | sp<IShellCallback> shellCallback = IShellCallback::asInterface(data.readStrongBinder()); |
| 132 | sp<IResultReceiver> resultReceiver = |
| 133 | IResultReceiver::asInterface(data.readStrongBinder()); |
Joe Onorato | 2cbc2cc | 2017-08-30 17:03:23 -0700 | [diff] [blame] | 134 | |
| 135 | FILE* fin = fdopen(in, "r"); |
| 136 | FILE* fout = fdopen(out, "w"); |
| 137 | FILE* ferr = fdopen(err, "w"); |
| 138 | |
| 139 | if (fin == NULL || fout == NULL || ferr == NULL) { |
| 140 | resultReceiver->send(NO_MEMORY); |
| 141 | } else { |
| 142 | err = command(fin, fout, ferr, args); |
| 143 | resultReceiver->send(err); |
| 144 | } |
| 145 | |
| 146 | if (fin != NULL) { |
| 147 | fflush(fin); |
| 148 | fclose(fin); |
| 149 | } |
| 150 | if (fout != NULL) { |
| 151 | fflush(fout); |
| 152 | fclose(fout); |
| 153 | } |
| 154 | if (fout != NULL) { |
| 155 | fflush(ferr); |
| 156 | fclose(ferr); |
| 157 | } |
| 158 | |
| 159 | return NO_ERROR; |
| 160 | } |
Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame] | 161 | default: { return BnStatsManager::onTransact(code, data, reply, flags); } |
Joe Onorato | 2cbc2cc | 2017-08-30 17:03:23 -0700 | [diff] [blame] | 162 | } |
| 163 | } |
| 164 | |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 165 | /** |
| 166 | * Write debugging data about statsd. |
| 167 | */ |
Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame] | 168 | status_t StatsService::dump(int fd, const Vector<String16>& args) { |
Joe Onorato | 5dcbc6c | 2017-08-29 15:13:58 -0700 | [diff] [blame] | 169 | FILE* out = fdopen(fd, "w"); |
| 170 | if (out == NULL) { |
| 171 | return NO_MEMORY; // the fd is already open |
| 172 | } |
| 173 | |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 174 | // TODO: Proto format for incident reports |
| 175 | dump_impl(out); |
Joe Onorato | 5dcbc6c | 2017-08-29 15:13:58 -0700 | [diff] [blame] | 176 | |
| 177 | fclose(out); |
| 178 | return NO_ERROR; |
| 179 | } |
| 180 | |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 181 | /** |
| 182 | * Write debugging data about statsd in text format. |
| 183 | */ |
| 184 | void StatsService::dump_impl(FILE* out) { |
| 185 | mConfigManager->Dump(out); |
| 186 | } |
| 187 | |
| 188 | /** |
| 189 | * Implementation of the adb shell cmd stats command. |
| 190 | */ |
Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame] | 191 | status_t StatsService::command(FILE* in, FILE* out, FILE* err, Vector<String8>& args) { |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 192 | // TODO: Permission check |
| 193 | |
| 194 | const int argCount = args.size(); |
| 195 | if (argCount >= 1) { |
| 196 | // adb shell cmd stats config ... |
David Chen | 0656b7a | 2017-09-13 15:53:39 -0700 | [diff] [blame] | 197 | if (!args[0].compare(String8("config"))) { |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 198 | return cmd_config(in, out, err, args); |
David Chen | 0656b7a | 2017-09-13 15:53:39 -0700 | [diff] [blame] | 199 | } |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 200 | |
| 201 | // adb shell cmd stats print-stats-log |
| 202 | if (!args[0].compare(String8("print-stats-log")) && args.size() > 1) { |
| 203 | return cmd_print_stats_log(out, args); |
| 204 | } |
| 205 | |
David Chen | de70169 | 2017-10-05 13:16:02 -0700 | [diff] [blame] | 206 | if (!args[0].compare(String8("print-uid-map"))) { |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 207 | return cmd_print_uid_map(out); |
David Chen | de70169 | 2017-10-05 13:16:02 -0700 | [diff] [blame] | 208 | } |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 209 | |
| 210 | if (!args[0].compare(String8("dump-report"))) { |
| 211 | return cmd_dump_report(out, err, args); |
| 212 | } |
David Chen | 1481fe1 | 2017-10-16 13:16:34 -0700 | [diff] [blame] | 213 | |
| 214 | if (!args[0].compare(String8("pull-source")) && args.size() > 1) { |
| 215 | return cmd_print_pulled_metrics(out, args); |
| 216 | } |
David Chen | adaf8b3 | 2017-11-03 15:42:08 -0700 | [diff] [blame] | 217 | |
| 218 | if (!args[0].compare(String8("send-broadcast"))) { |
David Chen | 1d7b0cd | 2017-11-15 14:20:04 -0800 | [diff] [blame] | 219 | return cmd_trigger_broadcast(out, args); |
| 220 | } |
| 221 | |
| 222 | if (!args[0].compare(String8("print-stats"))) { |
| 223 | return cmd_print_stats(out); |
David Chen | adaf8b3 | 2017-11-03 15:42:08 -0700 | [diff] [blame] | 224 | } |
yro | 87d983c | 2017-11-14 21:31:43 -0800 | [diff] [blame] | 225 | |
| 226 | if (!args[0].compare(String8("clear-config"))) { |
| 227 | return cmd_remove_config_files(out); |
| 228 | } |
Joe Onorato | 2cbc2cc | 2017-08-30 17:03:23 -0700 | [diff] [blame] | 229 | } |
Joe Onorato | 2cbc2cc | 2017-08-30 17:03:23 -0700 | [diff] [blame] | 230 | |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 231 | print_cmd_help(out); |
Joe Onorato | 2cbc2cc | 2017-08-30 17:03:23 -0700 | [diff] [blame] | 232 | return NO_ERROR; |
| 233 | } |
| 234 | |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 235 | void StatsService::print_cmd_help(FILE* out) { |
| 236 | fprintf(out, |
| 237 | "usage: adb shell cmd stats print-stats-log [tag_required] " |
| 238 | "[timestamp_nsec_optional]\n"); |
| 239 | fprintf(out, "\n"); |
| 240 | fprintf(out, "\n"); |
| 241 | fprintf(out, "usage: adb shell cmd stats print-uid-map \n"); |
| 242 | fprintf(out, "\n"); |
| 243 | fprintf(out, " Prints the UID, app name, version mapping.\n"); |
| 244 | fprintf(out, "\n"); |
| 245 | fprintf(out, "\n"); |
yro | 87d983c | 2017-11-14 21:31:43 -0800 | [diff] [blame] | 246 | fprintf(out, "usage: adb shell cmd stats clear-config \n"); |
| 247 | fprintf(out, "\n"); |
| 248 | fprintf(out, " Removes all configs from disk.\n"); |
| 249 | fprintf(out, "\n"); |
| 250 | fprintf(out, "\n"); |
yro | 3fca5ba | 2017-11-17 13:22:52 -0800 | [diff] [blame] | 251 | fprintf(out, "usage: adb shell cmd stats pull-source [int] \n"); |
David Chen | 1481fe1 | 2017-10-16 13:16:34 -0700 | [diff] [blame] | 252 | fprintf(out, "\n"); |
| 253 | fprintf(out, " Prints the output of a pulled metrics source (int indicates source)\n"); |
| 254 | fprintf(out, "\n"); |
| 255 | fprintf(out, "\n"); |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 256 | fprintf(out, "usage: adb shell cmd stats config remove [UID] NAME\n"); |
| 257 | fprintf(out, "usage: adb shell cmd stats config update [UID] NAME\n"); |
| 258 | fprintf(out, "\n"); |
| 259 | fprintf(out, " Adds, updates or removes a configuration. The proto should be in\n"); |
| 260 | fprintf(out, " wire-encoded protobuf format and passed via stdin.\n"); |
| 261 | fprintf(out, "\n"); |
| 262 | fprintf(out, " UID The uid to use. It is only possible to pass the UID\n"); |
| 263 | fprintf(out, " parameter on eng builds. If UID is omitted the calling\n"); |
| 264 | fprintf(out, " uid is used.\n"); |
| 265 | fprintf(out, " NAME The per-uid name to use\n"); |
Yao Chen | 5154a379 | 2017-10-30 22:57:06 -0700 | [diff] [blame] | 266 | fprintf(out, "\n"); |
| 267 | fprintf(out, "\n"); |
| 268 | fprintf(out, "usage: adb shell cmd stats dump-report [UID] NAME\n"); |
| 269 | fprintf(out, " Dump all metric data for a configuration.\n"); |
| 270 | fprintf(out, " UID The uid of the configuration. It is only possible to pass\n"); |
| 271 | fprintf(out, " the UID parameter on eng builds. If UID is omitted the\n"); |
| 272 | fprintf(out, " calling uid is used.\n"); |
| 273 | fprintf(out, " NAME The name of the configuration\n"); |
David Chen | adaf8b3 | 2017-11-03 15:42:08 -0700 | [diff] [blame] | 274 | fprintf(out, "\n"); |
| 275 | fprintf(out, "\n"); |
David Chen | 1d7b0cd | 2017-11-15 14:20:04 -0800 | [diff] [blame] | 276 | fprintf(out, "usage: adb shell cmd stats send-broadcast [UID] NAME\n"); |
| 277 | fprintf(out, " Send a broadcast that triggers the subscriber to fetch metrics.\n"); |
| 278 | fprintf(out, " UID The uid of the configuration. It is only possible to pass\n"); |
| 279 | fprintf(out, " the UID parameter on eng builds. If UID is omitted the\n"); |
| 280 | fprintf(out, " calling uid is used.\n"); |
| 281 | fprintf(out, " NAME The name of the configuration\n"); |
| 282 | fprintf(out, "\n"); |
| 283 | fprintf(out, "\n"); |
| 284 | fprintf(out, "usage: adb shell cmd stats print-stats\n"); |
| 285 | fprintf(out, " Prints some basic stats.\n"); |
David Chen | adaf8b3 | 2017-11-03 15:42:08 -0700 | [diff] [blame] | 286 | } |
| 287 | |
David Chen | 1d7b0cd | 2017-11-15 14:20:04 -0800 | [diff] [blame] | 288 | status_t StatsService::cmd_trigger_broadcast(FILE* out, Vector<String8>& args) { |
| 289 | string name; |
| 290 | bool good = false; |
| 291 | int uid; |
| 292 | const int argCount = args.size(); |
| 293 | if (argCount == 2) { |
| 294 | // Automatically pick the UID |
| 295 | uid = IPCThreadState::self()->getCallingUid(); |
| 296 | // TODO: What if this isn't a binder call? Should we fail? |
| 297 | name.assign(args[1].c_str(), args[1].size()); |
| 298 | good = true; |
| 299 | } else if (argCount == 3) { |
| 300 | // If it's a userdebug or eng build, then the shell user can |
| 301 | // impersonate other uids. |
| 302 | if (mEngBuild) { |
| 303 | const char* s = args[1].c_str(); |
| 304 | if (*s != '\0') { |
| 305 | char* end = NULL; |
| 306 | uid = strtol(s, &end, 0); |
| 307 | if (*end == '\0') { |
| 308 | name.assign(args[2].c_str(), args[2].size()); |
| 309 | good = true; |
| 310 | } |
| 311 | } |
| 312 | } else { |
| 313 | fprintf(out, |
| 314 | "The metrics can only be dumped for other UIDs on eng or userdebug " |
| 315 | "builds.\n"); |
| 316 | } |
| 317 | } |
| 318 | if (!good) { |
| 319 | print_cmd_help(out); |
| 320 | return UNKNOWN_ERROR; |
| 321 | } |
| 322 | auto receiver = mConfigManager->GetConfigReceiver(ConfigKey(uid, name)); |
David Chen | adaf8b3 | 2017-11-03 15:42:08 -0700 | [diff] [blame] | 323 | auto sc = getStatsCompanionService(); |
David Chen | 1d7b0cd | 2017-11-15 14:20:04 -0800 | [diff] [blame] | 324 | sc->sendBroadcast(String16(receiver.first.c_str()), String16(receiver.second.c_str())); |
| 325 | ALOGD("StatsService::trigger broadcast succeeded to %s, %s", args[1].c_str(), args[2].c_str()); |
David Chen | adaf8b3 | 2017-11-03 15:42:08 -0700 | [diff] [blame] | 326 | return NO_ERROR; |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | status_t StatsService::cmd_config(FILE* in, FILE* out, FILE* err, Vector<String8>& args) { |
| 330 | const int argCount = args.size(); |
| 331 | if (argCount >= 2) { |
| 332 | if (args[1] == "update" || args[1] == "remove") { |
| 333 | bool good = false; |
| 334 | int uid = -1; |
| 335 | string name; |
| 336 | |
| 337 | if (argCount == 3) { |
| 338 | // Automatically pick the UID |
| 339 | uid = IPCThreadState::self()->getCallingUid(); |
| 340 | // TODO: What if this isn't a binder call? Should we fail? |
| 341 | name.assign(args[2].c_str(), args[2].size()); |
| 342 | good = true; |
| 343 | } else if (argCount == 4) { |
| 344 | // If it's a userdebug or eng build, then the shell user can |
| 345 | // impersonate other uids. |
| 346 | if (mEngBuild) { |
| 347 | const char* s = args[2].c_str(); |
| 348 | if (*s != '\0') { |
| 349 | char* end = NULL; |
| 350 | uid = strtol(s, &end, 0); |
| 351 | if (*end == '\0') { |
| 352 | name.assign(args[3].c_str(), args[3].size()); |
| 353 | good = true; |
| 354 | } |
| 355 | } |
| 356 | } else { |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 357 | fprintf(err, |
| 358 | "The config can only be set for other UIDs on eng or userdebug " |
| 359 | "builds.\n"); |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 360 | } |
| 361 | } |
| 362 | |
| 363 | if (!good) { |
| 364 | // If arg parsing failed, print the help text and return an error. |
| 365 | print_cmd_help(out); |
| 366 | return UNKNOWN_ERROR; |
| 367 | } |
| 368 | |
| 369 | if (args[1] == "update") { |
| 370 | // Read stream into buffer. |
| 371 | string buffer; |
| 372 | if (!android::base::ReadFdToString(fileno(in), &buffer)) { |
| 373 | fprintf(err, "Error reading stream for StatsConfig.\n"); |
| 374 | return UNKNOWN_ERROR; |
| 375 | } |
| 376 | |
| 377 | // Parse buffer. |
| 378 | StatsdConfig config; |
| 379 | if (!config.ParseFromString(buffer)) { |
| 380 | fprintf(err, "Error parsing proto stream for StatsConfig.\n"); |
| 381 | return UNKNOWN_ERROR; |
| 382 | } |
| 383 | |
| 384 | // Add / update the config. |
| 385 | mConfigManager->UpdateConfig(ConfigKey(uid, name), config); |
| 386 | } else { |
| 387 | // Remove the config. |
| 388 | mConfigManager->RemoveConfig(ConfigKey(uid, name)); |
| 389 | } |
| 390 | |
| 391 | return NO_ERROR; |
| 392 | } |
David Chen | 0656b7a | 2017-09-13 15:53:39 -0700 | [diff] [blame] | 393 | } |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 394 | print_cmd_help(out); |
| 395 | return UNKNOWN_ERROR; |
| 396 | } |
| 397 | |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 398 | status_t StatsService::cmd_dump_report(FILE* out, FILE* err, const Vector<String8>& args) { |
| 399 | if (mProcessor != nullptr) { |
| 400 | const int argCount = args.size(); |
| 401 | bool good = false; |
| 402 | int uid; |
| 403 | string name; |
| 404 | if (argCount == 2) { |
| 405 | // Automatically pick the UID |
| 406 | uid = IPCThreadState::self()->getCallingUid(); |
| 407 | // TODO: What if this isn't a binder call? Should we fail? |
Yao Chen | 5154a379 | 2017-10-30 22:57:06 -0700 | [diff] [blame] | 408 | name.assign(args[1].c_str(), args[1].size()); |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 409 | good = true; |
| 410 | } else if (argCount == 3) { |
| 411 | // If it's a userdebug or eng build, then the shell user can |
| 412 | // impersonate other uids. |
| 413 | if (mEngBuild) { |
| 414 | const char* s = args[1].c_str(); |
| 415 | if (*s != '\0') { |
| 416 | char* end = NULL; |
| 417 | uid = strtol(s, &end, 0); |
| 418 | if (*end == '\0') { |
| 419 | name.assign(args[2].c_str(), args[2].size()); |
| 420 | good = true; |
| 421 | } |
| 422 | } |
| 423 | } else { |
| 424 | fprintf(out, |
| 425 | "The metrics can only be dumped for other UIDs on eng or userdebug " |
| 426 | "builds.\n"); |
| 427 | } |
| 428 | } |
| 429 | if (good) { |
David Chen | 1d7b0cd | 2017-11-15 14:20:04 -0800 | [diff] [blame] | 430 | vector<uint8_t> data; |
| 431 | mProcessor->onDumpReport(ConfigKey(uid, name), &data); |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 432 | // TODO: print the returned StatsLogReport to file instead of printing to logcat. |
| 433 | fprintf(out, "Dump report for Config [%d,%s]\n", uid, name.c_str()); |
| 434 | fprintf(out, "See the StatsLogReport in logcat...\n"); |
| 435 | return android::OK; |
| 436 | } else { |
| 437 | // If arg parsing failed, print the help text and return an error. |
| 438 | print_cmd_help(out); |
| 439 | return UNKNOWN_ERROR; |
| 440 | } |
| 441 | } else { |
| 442 | fprintf(out, "Log processor does not exist...\n"); |
| 443 | return UNKNOWN_ERROR; |
| 444 | } |
| 445 | } |
| 446 | |
David Chen | 1d7b0cd | 2017-11-15 14:20:04 -0800 | [diff] [blame] | 447 | status_t StatsService::cmd_print_stats(FILE* out) { |
| 448 | vector<ConfigKey> configs = mConfigManager->GetAllConfigKeys(); |
| 449 | for (const ConfigKey& key : configs) { |
| 450 | fprintf(out, "Config %s uses %zu bytes\n", key.ToString().c_str(), |
| 451 | mProcessor->GetMetricsSize(key)); |
| 452 | } |
| 453 | return NO_ERROR; |
| 454 | } |
| 455 | |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 456 | status_t StatsService::cmd_print_stats_log(FILE* out, const Vector<String8>& args) { |
| 457 | long msec = 0; |
| 458 | |
| 459 | if (args.size() > 2) { |
| 460 | msec = strtol(args[2].string(), NULL, 10); |
David Chen | 0656b7a | 2017-09-13 15:53:39 -0700 | [diff] [blame] | 461 | } |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 462 | return DropboxReader::readStatsLogs(out, args[1].string(), msec); |
| 463 | } |
| 464 | |
| 465 | status_t StatsService::cmd_print_uid_map(FILE* out) { |
| 466 | mUidMap->printUidMap(out); |
| 467 | return NO_ERROR; |
David Chen | 0656b7a | 2017-09-13 15:53:39 -0700 | [diff] [blame] | 468 | } |
| 469 | |
David Chen | 1481fe1 | 2017-10-16 13:16:34 -0700 | [diff] [blame] | 470 | status_t StatsService::cmd_print_pulled_metrics(FILE* out, const Vector<String8>& args) { |
| 471 | int s = atoi(args[1].c_str()); |
Chenjie Yu | 5305e1d | 2017-10-31 13:49:36 -0700 | [diff] [blame] | 472 | vector<shared_ptr<LogEvent> > stats; |
| 473 | if (mStatsPullerManager.Pull(s, &stats)) { |
| 474 | for (const auto& it : stats) { |
| 475 | fprintf(out, "Pull from %d: %s\n", s, it->ToString().c_str()); |
| 476 | } |
| 477 | fprintf(out, "Pull from %d: Received %zu elements\n", s, stats.size()); |
| 478 | return NO_ERROR; |
David Chen | 1481fe1 | 2017-10-16 13:16:34 -0700 | [diff] [blame] | 479 | } |
Chenjie Yu | 5305e1d | 2017-10-31 13:49:36 -0700 | [diff] [blame] | 480 | return UNKNOWN_ERROR; |
David Chen | 1481fe1 | 2017-10-16 13:16:34 -0700 | [diff] [blame] | 481 | } |
| 482 | |
yro | 87d983c | 2017-11-14 21:31:43 -0800 | [diff] [blame] | 483 | status_t StatsService::cmd_remove_config_files(FILE* out) { |
| 484 | fprintf(out, "Trying to remove config files...\n"); |
| 485 | unique_ptr<DIR, decltype(&closedir)> dir(opendir(STATS_SERVICE_DIR), closedir); |
| 486 | if (dir == NULL) { |
| 487 | fprintf(out, "No existing config files found exiting...\n"); |
| 488 | return NO_ERROR; |
| 489 | } |
| 490 | |
| 491 | dirent* de; |
| 492 | while ((de = readdir(dir.get()))) { |
| 493 | char* name = de->d_name; |
| 494 | if (name[0] == '.') continue; |
| 495 | string file_name = StringPrintf("%s/%s", STATS_SERVICE_DIR, name); |
| 496 | fprintf(out, "Deleting file %s\n", file_name.c_str()); |
| 497 | if (remove(file_name.c_str())) { |
| 498 | fprintf(out, "Error deleting file %s\n", file_name.c_str()); |
| 499 | } |
| 500 | } |
| 501 | return NO_ERROR; |
| 502 | } |
| 503 | |
David Chen | de70169 | 2017-10-05 13:16:02 -0700 | [diff] [blame] | 504 | Status StatsService::informAllUidData(const vector<int32_t>& uid, const vector<int32_t>& version, |
| 505 | const vector<String16>& app) { |
| 506 | if (DEBUG) ALOGD("StatsService::informAllUidData was called"); |
| 507 | |
| 508 | if (IPCThreadState::self()->getCallingUid() != AID_SYSTEM) { |
| 509 | return Status::fromExceptionCode(Status::EX_SECURITY, |
| 510 | "Only system uid can call informAllUidData"); |
| 511 | } |
| 512 | |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 513 | mUidMap->updateMap(uid, version, app); |
David Chen | de70169 | 2017-10-05 13:16:02 -0700 | [diff] [blame] | 514 | if (DEBUG) ALOGD("StatsService::informAllUidData succeeded"); |
| 515 | |
| 516 | return Status::ok(); |
| 517 | } |
| 518 | |
| 519 | Status StatsService::informOnePackage(const String16& app, int32_t uid, int32_t version) { |
| 520 | if (DEBUG) ALOGD("StatsService::informOnePackage was called"); |
| 521 | |
| 522 | if (IPCThreadState::self()->getCallingUid() != AID_SYSTEM) { |
| 523 | return Status::fromExceptionCode(Status::EX_SECURITY, |
| 524 | "Only system uid can call informOnePackage"); |
| 525 | } |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 526 | mUidMap->updateApp(app, uid, version); |
David Chen | de70169 | 2017-10-05 13:16:02 -0700 | [diff] [blame] | 527 | return Status::ok(); |
| 528 | } |
| 529 | |
| 530 | Status StatsService::informOnePackageRemoved(const String16& app, int32_t uid) { |
| 531 | if (DEBUG) ALOGD("StatsService::informOnePackageRemoved was called"); |
| 532 | |
| 533 | if (IPCThreadState::self()->getCallingUid() != AID_SYSTEM) { |
| 534 | return Status::fromExceptionCode(Status::EX_SECURITY, |
| 535 | "Only system uid can call informOnePackageRemoved"); |
| 536 | } |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 537 | mUidMap->removeApp(app, uid); |
David Chen | de70169 | 2017-10-05 13:16:02 -0700 | [diff] [blame] | 538 | return Status::ok(); |
| 539 | } |
| 540 | |
Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame] | 541 | Status StatsService::informAnomalyAlarmFired() { |
Bookatz | b487b55 | 2017-09-18 11:26:01 -0700 | [diff] [blame] | 542 | if (DEBUG) ALOGD("StatsService::informAnomalyAlarmFired was called"); |
Bookatz | 1b0b114 | 2017-09-08 11:58:42 -0700 | [diff] [blame] | 543 | |
| 544 | if (IPCThreadState::self()->getCallingUid() != AID_SYSTEM) { |
| 545 | return Status::fromExceptionCode(Status::EX_SECURITY, |
Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame] | 546 | "Only system uid can call informAnomalyAlarmFired"); |
Bookatz | 1b0b114 | 2017-09-08 11:58:42 -0700 | [diff] [blame] | 547 | } |
| 548 | |
Bookatz | b487b55 | 2017-09-18 11:26:01 -0700 | [diff] [blame] | 549 | if (DEBUG) ALOGD("StatsService::informAnomalyAlarmFired succeeded"); |
Bookatz | 1b0b114 | 2017-09-08 11:58:42 -0700 | [diff] [blame] | 550 | // TODO: check through all counters/timers and see if an anomaly has indeed occurred. |
| 551 | |
| 552 | return Status::ok(); |
| 553 | } |
| 554 | |
Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame] | 555 | Status StatsService::informPollAlarmFired() { |
Bookatz | b487b55 | 2017-09-18 11:26:01 -0700 | [diff] [blame] | 556 | if (DEBUG) ALOGD("StatsService::informPollAlarmFired was called"); |
Bookatz | 1b0b114 | 2017-09-08 11:58:42 -0700 | [diff] [blame] | 557 | |
| 558 | if (IPCThreadState::self()->getCallingUid() != AID_SYSTEM) { |
| 559 | return Status::fromExceptionCode(Status::EX_SECURITY, |
Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame] | 560 | "Only system uid can call informPollAlarmFired"); |
Bookatz | 1b0b114 | 2017-09-08 11:58:42 -0700 | [diff] [blame] | 561 | } |
| 562 | |
Chenjie Yu | 5305e1d | 2017-10-31 13:49:36 -0700 | [diff] [blame] | 563 | mStatsPullerManager.OnAlarmFired(); |
Chenjie Yu | b3dda41 | 2017-10-24 13:41:59 -0700 | [diff] [blame] | 564 | |
Bookatz | b487b55 | 2017-09-18 11:26:01 -0700 | [diff] [blame] | 565 | if (DEBUG) ALOGD("StatsService::informPollAlarmFired succeeded"); |
Bookatz | 1b0b114 | 2017-09-08 11:58:42 -0700 | [diff] [blame] | 566 | |
| 567 | return Status::ok(); |
| 568 | } |
| 569 | |
Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame] | 570 | Status StatsService::systemRunning() { |
Joe Onorato | 5dcbc6c | 2017-08-29 15:13:58 -0700 | [diff] [blame] | 571 | if (IPCThreadState::self()->getCallingUid() != AID_SYSTEM) { |
| 572 | return Status::fromExceptionCode(Status::EX_SECURITY, |
Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame] | 573 | "Only system uid can call systemRunning"); |
Joe Onorato | 5dcbc6c | 2017-08-29 15:13:58 -0700 | [diff] [blame] | 574 | } |
| 575 | |
| 576 | // When system_server is up and running, schedule the dropbox task to run. |
| 577 | ALOGD("StatsService::systemRunning"); |
| 578 | |
Bookatz | b487b55 | 2017-09-18 11:26:01 -0700 | [diff] [blame] | 579 | sayHiToStatsCompanion(); |
| 580 | |
Joe Onorato | 5dcbc6c | 2017-08-29 15:13:58 -0700 | [diff] [blame] | 581 | return Status::ok(); |
| 582 | } |
| 583 | |
Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame] | 584 | void StatsService::sayHiToStatsCompanion() { |
| 585 | // TODO: This method needs to be private. It is temporarily public and unsecured for testing |
| 586 | // purposes. |
Bookatz | b487b55 | 2017-09-18 11:26:01 -0700 | [diff] [blame] | 587 | sp<IStatsCompanionService> statsCompanion = getStatsCompanionService(); |
| 588 | if (statsCompanion != nullptr) { |
| 589 | if (DEBUG) ALOGD("Telling statsCompanion that statsd is ready"); |
| 590 | statsCompanion->statsdReady(); |
| 591 | } else { |
| 592 | if (DEBUG) ALOGD("Could not access statsCompanion"); |
| 593 | } |
| 594 | } |
| 595 | |
Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame] | 596 | sp<IStatsCompanionService> StatsService::getStatsCompanionService() { |
Bookatz | 906a35c | 2017-09-20 15:26:44 -0700 | [diff] [blame] | 597 | sp<IStatsCompanionService> statsCompanion = nullptr; |
| 598 | // Get statscompanion service from service manager |
| 599 | const sp<IServiceManager> sm(defaultServiceManager()); |
| 600 | if (sm != nullptr) { |
| 601 | const String16 name("statscompanion"); |
| 602 | statsCompanion = interface_cast<IStatsCompanionService>(sm->checkService(name)); |
| 603 | if (statsCompanion == nullptr) { |
| 604 | ALOGW("statscompanion service unavailable!"); |
| 605 | return nullptr; |
| 606 | } |
| 607 | } |
| 608 | return statsCompanion; |
| 609 | } |
| 610 | |
Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame] | 611 | Status StatsService::statsCompanionReady() { |
Bookatz | b487b55 | 2017-09-18 11:26:01 -0700 | [diff] [blame] | 612 | if (DEBUG) ALOGD("StatsService::statsCompanionReady was called"); |
| 613 | |
| 614 | if (IPCThreadState::self()->getCallingUid() != AID_SYSTEM) { |
| 615 | return Status::fromExceptionCode(Status::EX_SECURITY, |
| 616 | "Only system uid can call statsCompanionReady"); |
| 617 | } |
| 618 | |
| 619 | sp<IStatsCompanionService> statsCompanion = getStatsCompanionService(); |
| 620 | if (statsCompanion == nullptr) { |
Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame] | 621 | return Status::fromExceptionCode( |
| 622 | Status::EX_NULL_POINTER, |
| 623 | "statscompanion unavailable despite it contacting statsd!"); |
Bookatz | b487b55 | 2017-09-18 11:26:01 -0700 | [diff] [blame] | 624 | } |
| 625 | if (DEBUG) ALOGD("StatsService::statsCompanionReady linking to statsCompanion."); |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 626 | IInterface::asBinder(statsCompanion)->linkToDeath(new CompanionDeathRecipient(mAnomalyMonitor)); |
Bookatz | b487b55 | 2017-09-18 11:26:01 -0700 | [diff] [blame] | 627 | mAnomalyMonitor->setStatsCompanionService(statsCompanion); |
| 628 | |
| 629 | return Status::ok(); |
| 630 | } |
| 631 | |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 632 | void StatsService::Startup() { |
| 633 | mConfigManager->Startup(); |
Bookatz | 906a35c | 2017-09-20 15:26:44 -0700 | [diff] [blame] | 634 | } |
| 635 | |
Joe Onorato | c4dfae5 | 2017-10-17 23:38:21 -0700 | [diff] [blame] | 636 | void StatsService::OnLogEvent(const LogEvent& event) { |
| 637 | mProcessor->OnLogEvent(event); |
Bookatz | 906a35c | 2017-09-20 15:26:44 -0700 | [diff] [blame] | 638 | } |
| 639 | |
David Chen | 1d7b0cd | 2017-11-15 14:20:04 -0800 | [diff] [blame] | 640 | Status StatsService::getData(const String16& key, vector <uint8_t>* output) { |
David Chen | adaf8b3 | 2017-11-03 15:42:08 -0700 | [diff] [blame] | 641 | IPCThreadState* ipc = IPCThreadState::self(); |
David Chen | 1d7b0cd | 2017-11-15 14:20:04 -0800 | [diff] [blame] | 642 | ALOGD("StatsService::getData with Pid %i, Uid %i", ipc->getCallingPid(), |
| 643 | ipc->getCallingUid()); |
Yao Chen | 7ee9415 | 2017-11-17 09:44:40 -0800 | [diff] [blame] | 644 | if (checkCallingPermission(String16(kPermissionDump))) { |
David Chen | 1d7b0cd | 2017-11-15 14:20:04 -0800 | [diff] [blame] | 645 | string keyStr = string(String8(key).string()); |
| 646 | ConfigKey configKey(ipc->getCallingUid(), keyStr); |
| 647 | mProcessor->onDumpReport(configKey, output); |
David Chen | adaf8b3 | 2017-11-03 15:42:08 -0700 | [diff] [blame] | 648 | return Status::ok(); |
| 649 | } else { |
| 650 | return Status::fromExceptionCode(binder::Status::EX_SECURITY); |
| 651 | } |
yro | 31eb67b | 2017-10-24 13:33:21 -0700 | [diff] [blame] | 652 | } |
| 653 | |
David Chen | adaf8b3 | 2017-11-03 15:42:08 -0700 | [diff] [blame] | 654 | Status StatsService::addConfiguration(const String16& key, |
| 655 | const vector <uint8_t>& config, |
| 656 | const String16& package, const String16& cls, |
| 657 | bool* success) { |
| 658 | IPCThreadState* ipc = IPCThreadState::self(); |
Yao Chen | 7ee9415 | 2017-11-17 09:44:40 -0800 | [diff] [blame] | 659 | if (checkCallingPermission(String16(kPermissionDump))) { |
David Chen | adaf8b3 | 2017-11-03 15:42:08 -0700 | [diff] [blame] | 660 | string keyString = string(String8(key).string()); |
David Chen | 1d7b0cd | 2017-11-15 14:20:04 -0800 | [diff] [blame] | 661 | ConfigKey configKey(ipc->getCallingUid(), keyString); |
David Chen | adaf8b3 | 2017-11-03 15:42:08 -0700 | [diff] [blame] | 662 | StatsdConfig cfg; |
| 663 | cfg.ParseFromArray(&config[0], config.size()); |
| 664 | mConfigManager->UpdateConfig(configKey, cfg); |
| 665 | mConfigManager->SetConfigReceiver(configKey, string(String8(package).string()), |
| 666 | string(String8(cls).string())); |
| 667 | *success = true; |
| 668 | return Status::ok(); |
| 669 | } else { |
| 670 | return Status::fromExceptionCode(binder::Status::EX_SECURITY); |
yro | 31eb67b | 2017-10-24 13:33:21 -0700 | [diff] [blame] | 671 | } |
yro | 31eb67b | 2017-10-24 13:33:21 -0700 | [diff] [blame] | 672 | } |
| 673 | |
David Chen | adaf8b3 | 2017-11-03 15:42:08 -0700 | [diff] [blame] | 674 | Status StatsService::removeConfiguration(const String16& key, bool* success) { |
| 675 | IPCThreadState* ipc = IPCThreadState::self(); |
Yao Chen | 7ee9415 | 2017-11-17 09:44:40 -0800 | [diff] [blame] | 676 | if (checkCallingPermission(String16(kPermissionDump))) { |
David Chen | 1d7b0cd | 2017-11-15 14:20:04 -0800 | [diff] [blame] | 677 | string keyStr = string(String8(key).string()); |
| 678 | mConfigManager->RemoveConfig(ConfigKey(ipc->getCallingUid(), keyStr)); |
David Chen | adaf8b3 | 2017-11-03 15:42:08 -0700 | [diff] [blame] | 679 | return Status::ok(); |
| 680 | } else { |
| 681 | *success = false; |
| 682 | return Status::fromExceptionCode(binder::Status::EX_SECURITY); |
yro | 31eb67b | 2017-10-24 13:33:21 -0700 | [diff] [blame] | 683 | } |
yro | 31eb67b | 2017-10-24 13:33:21 -0700 | [diff] [blame] | 684 | } |
| 685 | |
David Chen | 1d7b0cd | 2017-11-15 14:20:04 -0800 | [diff] [blame] | 686 | void StatsService::binderDied(const wp <IBinder>& who) { |
yro | 31eb67b | 2017-10-24 13:33:21 -0700 | [diff] [blame] | 687 | for (size_t i = 0; i < mCallbacks.size(); i++) { |
| 688 | if (IInterface::asBinder(mCallbacks[i]) == who) { |
| 689 | mCallbacks.removeAt(i); |
| 690 | break; |
| 691 | } |
| 692 | } |
| 693 | } |
| 694 | |
Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame] | 695 | } // namespace statsd |
| 696 | } // namespace os |
| 697 | } // namespace android |