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 | 5154a37 | 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)); |
yro | 4d889e6 | 2017-11-17 15:44:48 -0800 | [diff] [blame^] | 323 | sp<IStatsCompanionService> sc = getStatsCompanionService(); |
| 324 | if (sc != nullptr) { |
| 325 | sc->sendBroadcast(String16(receiver.first.c_str()), String16(receiver.second.c_str())); |
| 326 | ALOGD("StatsService::trigger broadcast succeeded to %s, %s", args[1].c_str(), |
| 327 | args[2].c_str()); |
| 328 | } else { |
| 329 | ALOGD("Could not access statsCompanion"); |
| 330 | } |
| 331 | |
David Chen | adaf8b3 | 2017-11-03 15:42:08 -0700 | [diff] [blame] | 332 | return NO_ERROR; |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | status_t StatsService::cmd_config(FILE* in, FILE* out, FILE* err, Vector<String8>& args) { |
| 336 | const int argCount = args.size(); |
| 337 | if (argCount >= 2) { |
| 338 | if (args[1] == "update" || args[1] == "remove") { |
| 339 | bool good = false; |
| 340 | int uid = -1; |
| 341 | string name; |
| 342 | |
| 343 | if (argCount == 3) { |
| 344 | // Automatically pick the UID |
| 345 | uid = IPCThreadState::self()->getCallingUid(); |
| 346 | // TODO: What if this isn't a binder call? Should we fail? |
| 347 | name.assign(args[2].c_str(), args[2].size()); |
| 348 | good = true; |
| 349 | } else if (argCount == 4) { |
| 350 | // If it's a userdebug or eng build, then the shell user can |
| 351 | // impersonate other uids. |
| 352 | if (mEngBuild) { |
| 353 | const char* s = args[2].c_str(); |
| 354 | if (*s != '\0') { |
| 355 | char* end = NULL; |
| 356 | uid = strtol(s, &end, 0); |
| 357 | if (*end == '\0') { |
| 358 | name.assign(args[3].c_str(), args[3].size()); |
| 359 | good = true; |
| 360 | } |
| 361 | } |
| 362 | } else { |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 363 | fprintf(err, |
| 364 | "The config can only be set for other UIDs on eng or userdebug " |
| 365 | "builds.\n"); |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 366 | } |
| 367 | } |
| 368 | |
| 369 | if (!good) { |
| 370 | // If arg parsing failed, print the help text and return an error. |
| 371 | print_cmd_help(out); |
| 372 | return UNKNOWN_ERROR; |
| 373 | } |
| 374 | |
| 375 | if (args[1] == "update") { |
| 376 | // Read stream into buffer. |
| 377 | string buffer; |
| 378 | if (!android::base::ReadFdToString(fileno(in), &buffer)) { |
| 379 | fprintf(err, "Error reading stream for StatsConfig.\n"); |
| 380 | return UNKNOWN_ERROR; |
| 381 | } |
| 382 | |
| 383 | // Parse buffer. |
| 384 | StatsdConfig config; |
| 385 | if (!config.ParseFromString(buffer)) { |
| 386 | fprintf(err, "Error parsing proto stream for StatsConfig.\n"); |
| 387 | return UNKNOWN_ERROR; |
| 388 | } |
| 389 | |
| 390 | // Add / update the config. |
| 391 | mConfigManager->UpdateConfig(ConfigKey(uid, name), config); |
| 392 | } else { |
| 393 | // Remove the config. |
| 394 | mConfigManager->RemoveConfig(ConfigKey(uid, name)); |
| 395 | } |
| 396 | |
| 397 | return NO_ERROR; |
| 398 | } |
David Chen | 0656b7a | 2017-09-13 15:53:39 -0700 | [diff] [blame] | 399 | } |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 400 | print_cmd_help(out); |
| 401 | return UNKNOWN_ERROR; |
| 402 | } |
| 403 | |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 404 | status_t StatsService::cmd_dump_report(FILE* out, FILE* err, const Vector<String8>& args) { |
| 405 | if (mProcessor != nullptr) { |
| 406 | const int argCount = args.size(); |
| 407 | bool good = false; |
| 408 | int uid; |
| 409 | string name; |
| 410 | if (argCount == 2) { |
| 411 | // Automatically pick the UID |
| 412 | uid = IPCThreadState::self()->getCallingUid(); |
| 413 | // TODO: What if this isn't a binder call? Should we fail? |
Yao Chen | 5154a37 | 2017-10-30 22:57:06 -0700 | [diff] [blame] | 414 | name.assign(args[1].c_str(), args[1].size()); |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 415 | good = true; |
| 416 | } else if (argCount == 3) { |
| 417 | // If it's a userdebug or eng build, then the shell user can |
| 418 | // impersonate other uids. |
| 419 | if (mEngBuild) { |
| 420 | const char* s = args[1].c_str(); |
| 421 | if (*s != '\0') { |
| 422 | char* end = NULL; |
| 423 | uid = strtol(s, &end, 0); |
| 424 | if (*end == '\0') { |
| 425 | name.assign(args[2].c_str(), args[2].size()); |
| 426 | good = true; |
| 427 | } |
| 428 | } |
| 429 | } else { |
| 430 | fprintf(out, |
| 431 | "The metrics can only be dumped for other UIDs on eng or userdebug " |
| 432 | "builds.\n"); |
| 433 | } |
| 434 | } |
| 435 | if (good) { |
David Chen | 1d7b0cd | 2017-11-15 14:20:04 -0800 | [diff] [blame] | 436 | vector<uint8_t> data; |
| 437 | mProcessor->onDumpReport(ConfigKey(uid, name), &data); |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 438 | // TODO: print the returned StatsLogReport to file instead of printing to logcat. |
| 439 | fprintf(out, "Dump report for Config [%d,%s]\n", uid, name.c_str()); |
| 440 | fprintf(out, "See the StatsLogReport in logcat...\n"); |
| 441 | return android::OK; |
| 442 | } else { |
| 443 | // If arg parsing failed, print the help text and return an error. |
| 444 | print_cmd_help(out); |
| 445 | return UNKNOWN_ERROR; |
| 446 | } |
| 447 | } else { |
| 448 | fprintf(out, "Log processor does not exist...\n"); |
| 449 | return UNKNOWN_ERROR; |
| 450 | } |
| 451 | } |
| 452 | |
David Chen | 1d7b0cd | 2017-11-15 14:20:04 -0800 | [diff] [blame] | 453 | status_t StatsService::cmd_print_stats(FILE* out) { |
| 454 | vector<ConfigKey> configs = mConfigManager->GetAllConfigKeys(); |
| 455 | for (const ConfigKey& key : configs) { |
| 456 | fprintf(out, "Config %s uses %zu bytes\n", key.ToString().c_str(), |
| 457 | mProcessor->GetMetricsSize(key)); |
| 458 | } |
| 459 | return NO_ERROR; |
| 460 | } |
| 461 | |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 462 | status_t StatsService::cmd_print_stats_log(FILE* out, const Vector<String8>& args) { |
| 463 | long msec = 0; |
| 464 | |
| 465 | if (args.size() > 2) { |
| 466 | msec = strtol(args[2].string(), NULL, 10); |
David Chen | 0656b7a | 2017-09-13 15:53:39 -0700 | [diff] [blame] | 467 | } |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 468 | return DropboxReader::readStatsLogs(out, args[1].string(), msec); |
| 469 | } |
| 470 | |
| 471 | status_t StatsService::cmd_print_uid_map(FILE* out) { |
| 472 | mUidMap->printUidMap(out); |
| 473 | return NO_ERROR; |
David Chen | 0656b7a | 2017-09-13 15:53:39 -0700 | [diff] [blame] | 474 | } |
| 475 | |
David Chen | 1481fe1 | 2017-10-16 13:16:34 -0700 | [diff] [blame] | 476 | status_t StatsService::cmd_print_pulled_metrics(FILE* out, const Vector<String8>& args) { |
| 477 | int s = atoi(args[1].c_str()); |
Chenjie Yu | 5305e1d | 2017-10-31 13:49:36 -0700 | [diff] [blame] | 478 | vector<shared_ptr<LogEvent> > stats; |
| 479 | if (mStatsPullerManager.Pull(s, &stats)) { |
| 480 | for (const auto& it : stats) { |
| 481 | fprintf(out, "Pull from %d: %s\n", s, it->ToString().c_str()); |
| 482 | } |
| 483 | fprintf(out, "Pull from %d: Received %zu elements\n", s, stats.size()); |
| 484 | return NO_ERROR; |
David Chen | 1481fe1 | 2017-10-16 13:16:34 -0700 | [diff] [blame] | 485 | } |
Chenjie Yu | 5305e1d | 2017-10-31 13:49:36 -0700 | [diff] [blame] | 486 | return UNKNOWN_ERROR; |
David Chen | 1481fe1 | 2017-10-16 13:16:34 -0700 | [diff] [blame] | 487 | } |
| 488 | |
yro | 87d983c | 2017-11-14 21:31:43 -0800 | [diff] [blame] | 489 | status_t StatsService::cmd_remove_config_files(FILE* out) { |
| 490 | fprintf(out, "Trying to remove config files...\n"); |
| 491 | unique_ptr<DIR, decltype(&closedir)> dir(opendir(STATS_SERVICE_DIR), closedir); |
| 492 | if (dir == NULL) { |
| 493 | fprintf(out, "No existing config files found exiting...\n"); |
| 494 | return NO_ERROR; |
| 495 | } |
| 496 | |
| 497 | dirent* de; |
| 498 | while ((de = readdir(dir.get()))) { |
| 499 | char* name = de->d_name; |
| 500 | if (name[0] == '.') continue; |
| 501 | string file_name = StringPrintf("%s/%s", STATS_SERVICE_DIR, name); |
| 502 | fprintf(out, "Deleting file %s\n", file_name.c_str()); |
| 503 | if (remove(file_name.c_str())) { |
| 504 | fprintf(out, "Error deleting file %s\n", file_name.c_str()); |
| 505 | } |
| 506 | } |
| 507 | return NO_ERROR; |
| 508 | } |
| 509 | |
David Chen | de70169 | 2017-10-05 13:16:02 -0700 | [diff] [blame] | 510 | Status StatsService::informAllUidData(const vector<int32_t>& uid, const vector<int32_t>& version, |
| 511 | const vector<String16>& app) { |
| 512 | if (DEBUG) ALOGD("StatsService::informAllUidData was called"); |
| 513 | |
| 514 | if (IPCThreadState::self()->getCallingUid() != AID_SYSTEM) { |
| 515 | return Status::fromExceptionCode(Status::EX_SECURITY, |
| 516 | "Only system uid can call informAllUidData"); |
| 517 | } |
| 518 | |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 519 | mUidMap->updateMap(uid, version, app); |
David Chen | de70169 | 2017-10-05 13:16:02 -0700 | [diff] [blame] | 520 | if (DEBUG) ALOGD("StatsService::informAllUidData succeeded"); |
| 521 | |
| 522 | return Status::ok(); |
| 523 | } |
| 524 | |
| 525 | Status StatsService::informOnePackage(const String16& app, int32_t uid, int32_t version) { |
| 526 | if (DEBUG) ALOGD("StatsService::informOnePackage was called"); |
| 527 | |
| 528 | if (IPCThreadState::self()->getCallingUid() != AID_SYSTEM) { |
| 529 | return Status::fromExceptionCode(Status::EX_SECURITY, |
| 530 | "Only system uid can call informOnePackage"); |
| 531 | } |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 532 | mUidMap->updateApp(app, uid, version); |
David Chen | de70169 | 2017-10-05 13:16:02 -0700 | [diff] [blame] | 533 | return Status::ok(); |
| 534 | } |
| 535 | |
| 536 | Status StatsService::informOnePackageRemoved(const String16& app, int32_t uid) { |
| 537 | if (DEBUG) ALOGD("StatsService::informOnePackageRemoved was called"); |
| 538 | |
| 539 | if (IPCThreadState::self()->getCallingUid() != AID_SYSTEM) { |
| 540 | return Status::fromExceptionCode(Status::EX_SECURITY, |
| 541 | "Only system uid can call informOnePackageRemoved"); |
| 542 | } |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 543 | mUidMap->removeApp(app, uid); |
David Chen | de70169 | 2017-10-05 13:16:02 -0700 | [diff] [blame] | 544 | return Status::ok(); |
| 545 | } |
| 546 | |
Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame] | 547 | Status StatsService::informAnomalyAlarmFired() { |
Bookatz | b487b55 | 2017-09-18 11:26:01 -0700 | [diff] [blame] | 548 | if (DEBUG) ALOGD("StatsService::informAnomalyAlarmFired was called"); |
Bookatz | 1b0b114 | 2017-09-08 11:58:42 -0700 | [diff] [blame] | 549 | |
| 550 | if (IPCThreadState::self()->getCallingUid() != AID_SYSTEM) { |
| 551 | return Status::fromExceptionCode(Status::EX_SECURITY, |
Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame] | 552 | "Only system uid can call informAnomalyAlarmFired"); |
Bookatz | 1b0b114 | 2017-09-08 11:58:42 -0700 | [diff] [blame] | 553 | } |
| 554 | |
Bookatz | b487b55 | 2017-09-18 11:26:01 -0700 | [diff] [blame] | 555 | if (DEBUG) ALOGD("StatsService::informAnomalyAlarmFired succeeded"); |
Bookatz | 1b0b114 | 2017-09-08 11:58:42 -0700 | [diff] [blame] | 556 | // TODO: check through all counters/timers and see if an anomaly has indeed occurred. |
| 557 | |
| 558 | return Status::ok(); |
| 559 | } |
| 560 | |
Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame] | 561 | Status StatsService::informPollAlarmFired() { |
Bookatz | b487b55 | 2017-09-18 11:26:01 -0700 | [diff] [blame] | 562 | if (DEBUG) ALOGD("StatsService::informPollAlarmFired was called"); |
Bookatz | 1b0b114 | 2017-09-08 11:58:42 -0700 | [diff] [blame] | 563 | |
| 564 | if (IPCThreadState::self()->getCallingUid() != AID_SYSTEM) { |
| 565 | return Status::fromExceptionCode(Status::EX_SECURITY, |
Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame] | 566 | "Only system uid can call informPollAlarmFired"); |
Bookatz | 1b0b114 | 2017-09-08 11:58:42 -0700 | [diff] [blame] | 567 | } |
| 568 | |
Chenjie Yu | 5305e1d | 2017-10-31 13:49:36 -0700 | [diff] [blame] | 569 | mStatsPullerManager.OnAlarmFired(); |
Chenjie Yu | b3dda41 | 2017-10-24 13:41:59 -0700 | [diff] [blame] | 570 | |
Bookatz | b487b55 | 2017-09-18 11:26:01 -0700 | [diff] [blame] | 571 | if (DEBUG) ALOGD("StatsService::informPollAlarmFired succeeded"); |
Bookatz | 1b0b114 | 2017-09-08 11:58:42 -0700 | [diff] [blame] | 572 | |
| 573 | return Status::ok(); |
| 574 | } |
| 575 | |
Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame] | 576 | Status StatsService::systemRunning() { |
Joe Onorato | 5dcbc6c | 2017-08-29 15:13:58 -0700 | [diff] [blame] | 577 | if (IPCThreadState::self()->getCallingUid() != AID_SYSTEM) { |
| 578 | return Status::fromExceptionCode(Status::EX_SECURITY, |
Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame] | 579 | "Only system uid can call systemRunning"); |
Joe Onorato | 5dcbc6c | 2017-08-29 15:13:58 -0700 | [diff] [blame] | 580 | } |
| 581 | |
| 582 | // When system_server is up and running, schedule the dropbox task to run. |
| 583 | ALOGD("StatsService::systemRunning"); |
| 584 | |
Bookatz | b487b55 | 2017-09-18 11:26:01 -0700 | [diff] [blame] | 585 | sayHiToStatsCompanion(); |
| 586 | |
Joe Onorato | 5dcbc6c | 2017-08-29 15:13:58 -0700 | [diff] [blame] | 587 | return Status::ok(); |
| 588 | } |
| 589 | |
Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame] | 590 | void StatsService::sayHiToStatsCompanion() { |
| 591 | // TODO: This method needs to be private. It is temporarily public and unsecured for testing |
| 592 | // purposes. |
Bookatz | b487b55 | 2017-09-18 11:26:01 -0700 | [diff] [blame] | 593 | sp<IStatsCompanionService> statsCompanion = getStatsCompanionService(); |
| 594 | if (statsCompanion != nullptr) { |
| 595 | if (DEBUG) ALOGD("Telling statsCompanion that statsd is ready"); |
| 596 | statsCompanion->statsdReady(); |
| 597 | } else { |
| 598 | if (DEBUG) ALOGD("Could not access statsCompanion"); |
| 599 | } |
| 600 | } |
| 601 | |
Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame] | 602 | sp<IStatsCompanionService> StatsService::getStatsCompanionService() { |
Bookatz | 906a35c | 2017-09-20 15:26:44 -0700 | [diff] [blame] | 603 | sp<IStatsCompanionService> statsCompanion = nullptr; |
| 604 | // Get statscompanion service from service manager |
| 605 | const sp<IServiceManager> sm(defaultServiceManager()); |
| 606 | if (sm != nullptr) { |
| 607 | const String16 name("statscompanion"); |
| 608 | statsCompanion = interface_cast<IStatsCompanionService>(sm->checkService(name)); |
| 609 | if (statsCompanion == nullptr) { |
| 610 | ALOGW("statscompanion service unavailable!"); |
| 611 | return nullptr; |
| 612 | } |
| 613 | } |
| 614 | return statsCompanion; |
| 615 | } |
| 616 | |
Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame] | 617 | Status StatsService::statsCompanionReady() { |
Bookatz | b487b55 | 2017-09-18 11:26:01 -0700 | [diff] [blame] | 618 | if (DEBUG) ALOGD("StatsService::statsCompanionReady was called"); |
| 619 | |
| 620 | if (IPCThreadState::self()->getCallingUid() != AID_SYSTEM) { |
| 621 | return Status::fromExceptionCode(Status::EX_SECURITY, |
| 622 | "Only system uid can call statsCompanionReady"); |
| 623 | } |
| 624 | |
| 625 | sp<IStatsCompanionService> statsCompanion = getStatsCompanionService(); |
| 626 | if (statsCompanion == nullptr) { |
Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame] | 627 | return Status::fromExceptionCode( |
| 628 | Status::EX_NULL_POINTER, |
| 629 | "statscompanion unavailable despite it contacting statsd!"); |
Bookatz | b487b55 | 2017-09-18 11:26:01 -0700 | [diff] [blame] | 630 | } |
| 631 | if (DEBUG) ALOGD("StatsService::statsCompanionReady linking to statsCompanion."); |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 632 | IInterface::asBinder(statsCompanion)->linkToDeath(new CompanionDeathRecipient(mAnomalyMonitor)); |
Bookatz | b487b55 | 2017-09-18 11:26:01 -0700 | [diff] [blame] | 633 | mAnomalyMonitor->setStatsCompanionService(statsCompanion); |
| 634 | |
| 635 | return Status::ok(); |
| 636 | } |
| 637 | |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 638 | void StatsService::Startup() { |
| 639 | mConfigManager->Startup(); |
Bookatz | 906a35c | 2017-09-20 15:26:44 -0700 | [diff] [blame] | 640 | } |
| 641 | |
Joe Onorato | c4dfae5 | 2017-10-17 23:38:21 -0700 | [diff] [blame] | 642 | void StatsService::OnLogEvent(const LogEvent& event) { |
| 643 | mProcessor->OnLogEvent(event); |
Bookatz | 906a35c | 2017-09-20 15:26:44 -0700 | [diff] [blame] | 644 | } |
| 645 | |
David Chen | 1d7b0cd | 2017-11-15 14:20:04 -0800 | [diff] [blame] | 646 | Status StatsService::getData(const String16& key, vector <uint8_t>* output) { |
David Chen | adaf8b3 | 2017-11-03 15:42:08 -0700 | [diff] [blame] | 647 | IPCThreadState* ipc = IPCThreadState::self(); |
David Chen | 1d7b0cd | 2017-11-15 14:20:04 -0800 | [diff] [blame] | 648 | ALOGD("StatsService::getData with Pid %i, Uid %i", ipc->getCallingPid(), |
| 649 | ipc->getCallingUid()); |
Yao Chen | 7ee9415 | 2017-11-17 09:44:40 -0800 | [diff] [blame] | 650 | if (checkCallingPermission(String16(kPermissionDump))) { |
David Chen | 1d7b0cd | 2017-11-15 14:20:04 -0800 | [diff] [blame] | 651 | string keyStr = string(String8(key).string()); |
| 652 | ConfigKey configKey(ipc->getCallingUid(), keyStr); |
| 653 | mProcessor->onDumpReport(configKey, output); |
David Chen | adaf8b3 | 2017-11-03 15:42:08 -0700 | [diff] [blame] | 654 | return Status::ok(); |
| 655 | } else { |
| 656 | return Status::fromExceptionCode(binder::Status::EX_SECURITY); |
| 657 | } |
yro | 31eb67b | 2017-10-24 13:33:21 -0700 | [diff] [blame] | 658 | } |
| 659 | |
David Chen | adaf8b3 | 2017-11-03 15:42:08 -0700 | [diff] [blame] | 660 | Status StatsService::addConfiguration(const String16& key, |
| 661 | const vector <uint8_t>& config, |
| 662 | const String16& package, const String16& cls, |
| 663 | bool* success) { |
| 664 | IPCThreadState* ipc = IPCThreadState::self(); |
Yao Chen | 7ee9415 | 2017-11-17 09:44:40 -0800 | [diff] [blame] | 665 | if (checkCallingPermission(String16(kPermissionDump))) { |
David Chen | adaf8b3 | 2017-11-03 15:42:08 -0700 | [diff] [blame] | 666 | string keyString = string(String8(key).string()); |
David Chen | 1d7b0cd | 2017-11-15 14:20:04 -0800 | [diff] [blame] | 667 | ConfigKey configKey(ipc->getCallingUid(), keyString); |
David Chen | adaf8b3 | 2017-11-03 15:42:08 -0700 | [diff] [blame] | 668 | StatsdConfig cfg; |
| 669 | cfg.ParseFromArray(&config[0], config.size()); |
| 670 | mConfigManager->UpdateConfig(configKey, cfg); |
| 671 | mConfigManager->SetConfigReceiver(configKey, string(String8(package).string()), |
| 672 | string(String8(cls).string())); |
| 673 | *success = true; |
| 674 | return Status::ok(); |
| 675 | } else { |
| 676 | return Status::fromExceptionCode(binder::Status::EX_SECURITY); |
yro | 31eb67b | 2017-10-24 13:33:21 -0700 | [diff] [blame] | 677 | } |
yro | 31eb67b | 2017-10-24 13:33:21 -0700 | [diff] [blame] | 678 | } |
| 679 | |
David Chen | adaf8b3 | 2017-11-03 15:42:08 -0700 | [diff] [blame] | 680 | Status StatsService::removeConfiguration(const String16& key, bool* success) { |
| 681 | IPCThreadState* ipc = IPCThreadState::self(); |
Yao Chen | 7ee9415 | 2017-11-17 09:44:40 -0800 | [diff] [blame] | 682 | if (checkCallingPermission(String16(kPermissionDump))) { |
David Chen | 1d7b0cd | 2017-11-15 14:20:04 -0800 | [diff] [blame] | 683 | string keyStr = string(String8(key).string()); |
| 684 | mConfigManager->RemoveConfig(ConfigKey(ipc->getCallingUid(), keyStr)); |
David Chen | adaf8b3 | 2017-11-03 15:42:08 -0700 | [diff] [blame] | 685 | return Status::ok(); |
| 686 | } else { |
| 687 | *success = false; |
| 688 | return Status::fromExceptionCode(binder::Status::EX_SECURITY); |
yro | 31eb67b | 2017-10-24 13:33:21 -0700 | [diff] [blame] | 689 | } |
yro | 31eb67b | 2017-10-24 13:33:21 -0700 | [diff] [blame] | 690 | } |
| 691 | |
David Chen | 1d7b0cd | 2017-11-15 14:20:04 -0800 | [diff] [blame] | 692 | void StatsService::binderDied(const wp <IBinder>& who) { |
yro | 31eb67b | 2017-10-24 13:33:21 -0700 | [diff] [blame] | 693 | for (size_t i = 0; i < mCallbacks.size(); i++) { |
| 694 | if (IInterface::asBinder(mCallbacks[i]) == who) { |
| 695 | mCallbacks.removeAt(i); |
| 696 | break; |
| 697 | } |
| 698 | } |
| 699 | } |
| 700 | |
Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame] | 701 | } // namespace statsd |
| 702 | } // namespace os |
| 703 | } // namespace android |