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 | |
Tej Singh | 484524a | 2018-02-01 15:10:05 -0800 | [diff] [blame] | 17 | #define DEBUG false // STOPSHIP if 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 | |
| 20 | #include "StatsService.h" |
Yangster-mac | 330af58 | 2018-02-08 15:24:38 -0800 | [diff] [blame] | 21 | #include "stats_log_util.h" |
Yao Chen | 8d9989b | 2017-11-18 18:54:50 -0800 | [diff] [blame] | 22 | #include "android-base/stringprintf.h" |
David Chen | adaf8b3 | 2017-11-03 15:42:08 -0700 | [diff] [blame] | 23 | #include "config/ConfigKey.h" |
| 24 | #include "config/ConfigManager.h" |
Yao Chen | b356151 | 2017-11-21 18:07:17 -0800 | [diff] [blame] | 25 | #include "guardrail/StatsdStats.h" |
yro | 947fbce | 2017-11-15 22:50:23 -0800 | [diff] [blame] | 26 | #include "storage/StorageManager.h" |
Bookatz | c697797 | 2018-01-16 16:55:05 -0800 | [diff] [blame] | 27 | #include "subscriber/SubscriberReporter.h" |
Joe Onorato | 5dcbc6c | 2017-08-29 15:13:58 -0700 | [diff] [blame] | 28 | |
David Chen | 0656b7a | 2017-09-13 15:53:39 -0700 | [diff] [blame] | 29 | #include <android-base/file.h> |
Joe Onorato | 5dcbc6c | 2017-08-29 15:13:58 -0700 | [diff] [blame] | 30 | #include <binder/IPCThreadState.h> |
| 31 | #include <binder/IServiceManager.h> |
yro | 87d983c | 2017-11-14 21:31:43 -0800 | [diff] [blame] | 32 | #include <dirent.h> |
David Chen | 0656b7a | 2017-09-13 15:53:39 -0700 | [diff] [blame] | 33 | #include <frameworks/base/cmds/statsd/src/statsd_config.pb.h> |
Joe Onorato | 5dcbc6c | 2017-08-29 15:13:58 -0700 | [diff] [blame] | 34 | #include <private/android_filesystem_config.h> |
| 35 | #include <utils/Looper.h> |
Joe Onorato | 2cbc2cc | 2017-08-30 17:03:23 -0700 | [diff] [blame] | 36 | #include <utils/String16.h> |
Bookatz | b223c4e | 2018-02-01 15:35:04 -0800 | [diff] [blame] | 37 | #include <statslog.h> |
Joe Onorato | 5dcbc6c | 2017-08-29 15:13:58 -0700 | [diff] [blame] | 38 | #include <stdio.h> |
Yao Chen | 482d272 | 2017-09-12 13:25:43 -0700 | [diff] [blame] | 39 | #include <stdlib.h> |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 40 | #include <sys/system_properties.h> |
Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame] | 41 | #include <unistd.h> |
Joe Onorato | 5dcbc6c | 2017-08-29 15:13:58 -0700 | [diff] [blame] | 42 | |
| 43 | using namespace android; |
| 44 | |
Bookatz | 906a35c | 2017-09-20 15:26:44 -0700 | [diff] [blame] | 45 | namespace android { |
| 46 | namespace os { |
| 47 | namespace statsd { |
| 48 | |
David Chen | adaf8b3 | 2017-11-03 15:42:08 -0700 | [diff] [blame] | 49 | constexpr const char* kPermissionDump = "android.permission.DUMP"; |
yro | 03faf09 | 2017-12-12 00:17:50 -0800 | [diff] [blame] | 50 | #define STATS_SERVICE_DIR "/data/misc/stats-service" |
David Chen | adaf8b3 | 2017-11-03 15:42:08 -0700 | [diff] [blame] | 51 | |
Joe Onorato | 5dcbc6c | 2017-08-29 15:13:58 -0700 | [diff] [blame] | 52 | StatsService::StatsService(const sp<Looper>& handlerLooper) |
Yangster-mac | 932ecec | 2018-02-01 10:23:52 -0800 | [diff] [blame] | 53 | : mAnomalyAlarmMonitor(new AlarmMonitor(MIN_DIFF_TO_UPDATE_REGISTERED_ALARM_SECS, |
| 54 | [](const sp<IStatsCompanionService>& sc, int64_t timeMillis) { |
| 55 | if (sc != nullptr) { |
| 56 | sc->setAnomalyAlarm(timeMillis); |
| 57 | StatsdStats::getInstance().noteRegisteredAnomalyAlarmChanged(); |
| 58 | } |
| 59 | }, |
| 60 | [](const sp<IStatsCompanionService>& sc) { |
| 61 | if (sc != nullptr) { |
| 62 | sc->cancelAnomalyAlarm(); |
| 63 | StatsdStats::getInstance().noteRegisteredAnomalyAlarmChanged(); |
| 64 | } |
| 65 | })), |
| 66 | mPeriodicAlarmMonitor(new AlarmMonitor(MIN_DIFF_TO_UPDATE_REGISTERED_ALARM_SECS, |
| 67 | [](const sp<IStatsCompanionService>& sc, int64_t timeMillis) { |
| 68 | if (sc != nullptr) { |
| 69 | sc->setAlarmForSubscriberTriggering(timeMillis); |
| 70 | StatsdStats::getInstance().noteRegisteredPeriodicAlarmChanged(); |
| 71 | } |
| 72 | }, |
| 73 | [](const sp<IStatsCompanionService>& sc) { |
| 74 | if (sc != nullptr) { |
| 75 | sc->cancelAlarmForSubscriberTriggering(); |
| 76 | StatsdStats::getInstance().noteRegisteredPeriodicAlarmChanged(); |
| 77 | } |
| 78 | |
| 79 | })) { |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 80 | mUidMap = new UidMap(); |
Chenjie Yu | 80f9112 | 2018-01-31 20:24:50 -0800 | [diff] [blame] | 81 | StatsPuller::SetUidMap(mUidMap); |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 82 | mConfigManager = new ConfigManager(); |
Yangster-mac | 932ecec | 2018-02-01 10:23:52 -0800 | [diff] [blame] | 83 | mProcessor = new StatsLogProcessor(mUidMap, mAnomalyAlarmMonitor, mPeriodicAlarmMonitor, |
| 84 | getElapsedRealtimeSec(), [this](const ConfigKey& key) { |
| 85 | sp<IStatsCompanionService> sc = getStatsCompanionService(); |
| 86 | auto receiver = mConfigManager->GetConfigReceiver(key); |
| 87 | if (sc == nullptr) { |
| 88 | VLOG("Could not find StatsCompanionService"); |
| 89 | } else if (receiver == nullptr) { |
| 90 | VLOG("Statscompanion could not find a broadcast receiver for %s", |
| 91 | key.ToString().c_str()); |
| 92 | } else { |
| 93 | sc->sendDataBroadcast(receiver); |
David Chen | 1d7b0cd | 2017-11-15 14:20:04 -0800 | [diff] [blame] | 94 | } |
Yangster-mac | 932ecec | 2018-02-01 10:23:52 -0800 | [diff] [blame] | 95 | } |
Yangster-mac | 330af58 | 2018-02-08 15:24:38 -0800 | [diff] [blame] | 96 | ); |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 97 | |
| 98 | mConfigManager->AddListener(mProcessor); |
| 99 | |
| 100 | init_system_properties(); |
Joe Onorato | 5dcbc6c | 2017-08-29 15:13:58 -0700 | [diff] [blame] | 101 | } |
| 102 | |
Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame] | 103 | StatsService::~StatsService() { |
Joe Onorato | 5dcbc6c | 2017-08-29 15:13:58 -0700 | [diff] [blame] | 104 | } |
| 105 | |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 106 | void StatsService::init_system_properties() { |
| 107 | mEngBuild = false; |
| 108 | const prop_info* buildType = __system_property_find("ro.build.type"); |
| 109 | if (buildType != NULL) { |
| 110 | __system_property_read_callback(buildType, init_build_type_callback, this); |
| 111 | } |
David Chen | 0656b7a | 2017-09-13 15:53:39 -0700 | [diff] [blame] | 112 | } |
| 113 | |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 114 | void StatsService::init_build_type_callback(void* cookie, const char* /*name*/, const char* value, |
| 115 | uint32_t serial) { |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 116 | if (0 == strcmp("eng", value) || 0 == strcmp("userdebug", value)) { |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 117 | reinterpret_cast<StatsService*>(cookie)->mEngBuild = true; |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | /** |
| 122 | * Implement our own because the default binder implementation isn't |
| 123 | * properly handling SHELL_COMMAND_TRANSACTION. |
| 124 | */ |
Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame] | 125 | status_t StatsService::onTransact(uint32_t code, const Parcel& data, Parcel* reply, |
| 126 | uint32_t flags) { |
Joe Onorato | 2cbc2cc | 2017-08-30 17:03:23 -0700 | [diff] [blame] | 127 | switch (code) { |
| 128 | case SHELL_COMMAND_TRANSACTION: { |
| 129 | int in = data.readFileDescriptor(); |
| 130 | int out = data.readFileDescriptor(); |
| 131 | int err = data.readFileDescriptor(); |
| 132 | int argc = data.readInt32(); |
| 133 | Vector<String8> args; |
| 134 | for (int i = 0; i < argc && data.dataAvail() > 0; i++) { |
| 135 | args.add(String8(data.readString16())); |
| 136 | } |
Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame] | 137 | sp<IShellCallback> shellCallback = IShellCallback::asInterface(data.readStrongBinder()); |
| 138 | sp<IResultReceiver> resultReceiver = |
| 139 | IResultReceiver::asInterface(data.readStrongBinder()); |
Joe Onorato | 2cbc2cc | 2017-08-30 17:03:23 -0700 | [diff] [blame] | 140 | |
| 141 | FILE* fin = fdopen(in, "r"); |
| 142 | FILE* fout = fdopen(out, "w"); |
| 143 | FILE* ferr = fdopen(err, "w"); |
| 144 | |
| 145 | if (fin == NULL || fout == NULL || ferr == NULL) { |
| 146 | resultReceiver->send(NO_MEMORY); |
| 147 | } else { |
| 148 | err = command(fin, fout, ferr, args); |
| 149 | resultReceiver->send(err); |
| 150 | } |
| 151 | |
| 152 | if (fin != NULL) { |
| 153 | fflush(fin); |
| 154 | fclose(fin); |
| 155 | } |
| 156 | if (fout != NULL) { |
| 157 | fflush(fout); |
| 158 | fclose(fout); |
| 159 | } |
| 160 | if (fout != NULL) { |
| 161 | fflush(ferr); |
| 162 | fclose(ferr); |
| 163 | } |
| 164 | |
| 165 | return NO_ERROR; |
| 166 | } |
Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame] | 167 | default: { return BnStatsManager::onTransact(code, data, reply, flags); } |
Joe Onorato | 2cbc2cc | 2017-08-30 17:03:23 -0700 | [diff] [blame] | 168 | } |
| 169 | } |
| 170 | |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 171 | /** |
| 172 | * Write debugging data about statsd. |
| 173 | */ |
Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame] | 174 | status_t StatsService::dump(int fd, const Vector<String16>& args) { |
Joe Onorato | 5dcbc6c | 2017-08-29 15:13:58 -0700 | [diff] [blame] | 175 | FILE* out = fdopen(fd, "w"); |
| 176 | if (out == NULL) { |
| 177 | return NO_MEMORY; // the fd is already open |
| 178 | } |
| 179 | |
Yao Chen | 884c8c1 | 2018-01-26 10:36:25 -0800 | [diff] [blame] | 180 | bool verbose = false; |
| 181 | if (args.size() > 0 && !args[0].compare(String16("-v"))) { |
| 182 | verbose = true; |
| 183 | } |
| 184 | |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 185 | // TODO: Proto format for incident reports |
Yao Chen | 884c8c1 | 2018-01-26 10:36:25 -0800 | [diff] [blame] | 186 | dump_impl(out, verbose); |
Joe Onorato | 5dcbc6c | 2017-08-29 15:13:58 -0700 | [diff] [blame] | 187 | |
| 188 | fclose(out); |
| 189 | return NO_ERROR; |
| 190 | } |
| 191 | |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 192 | /** |
| 193 | * Write debugging data about statsd in text format. |
| 194 | */ |
Yao Chen | 884c8c1 | 2018-01-26 10:36:25 -0800 | [diff] [blame] | 195 | void StatsService::dump_impl(FILE* out, bool verbose) { |
Yao Chen | f5acabe | 2018-01-17 14:10:34 -0800 | [diff] [blame] | 196 | StatsdStats::getInstance().dumpStats(out); |
Yao Chen | 884c8c1 | 2018-01-26 10:36:25 -0800 | [diff] [blame] | 197 | mProcessor->dumpStates(out, verbose); |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | /** |
| 201 | * Implementation of the adb shell cmd stats command. |
| 202 | */ |
Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame] | 203 | 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] | 204 | // TODO: Permission check |
| 205 | |
| 206 | const int argCount = args.size(); |
| 207 | if (argCount >= 1) { |
| 208 | // adb shell cmd stats config ... |
David Chen | 0656b7a | 2017-09-13 15:53:39 -0700 | [diff] [blame] | 209 | if (!args[0].compare(String8("config"))) { |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 210 | return cmd_config(in, out, err, args); |
David Chen | 0656b7a | 2017-09-13 15:53:39 -0700 | [diff] [blame] | 211 | } |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 212 | |
David Chen | de70169 | 2017-10-05 13:16:02 -0700 | [diff] [blame] | 213 | if (!args[0].compare(String8("print-uid-map"))) { |
Yao Chen | d10f7b1 | 2017-12-18 12:53:50 -0800 | [diff] [blame] | 214 | return cmd_print_uid_map(out, args); |
David Chen | de70169 | 2017-10-05 13:16:02 -0700 | [diff] [blame] | 215 | } |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 216 | |
| 217 | if (!args[0].compare(String8("dump-report"))) { |
| 218 | return cmd_dump_report(out, err, args); |
| 219 | } |
David Chen | 1481fe1 | 2017-10-16 13:16:34 -0700 | [diff] [blame] | 220 | |
| 221 | if (!args[0].compare(String8("pull-source")) && args.size() > 1) { |
| 222 | return cmd_print_pulled_metrics(out, args); |
| 223 | } |
David Chen | adaf8b3 | 2017-11-03 15:42:08 -0700 | [diff] [blame] | 224 | |
| 225 | if (!args[0].compare(String8("send-broadcast"))) { |
David Chen | 1d7b0cd | 2017-11-15 14:20:04 -0800 | [diff] [blame] | 226 | return cmd_trigger_broadcast(out, args); |
| 227 | } |
| 228 | |
| 229 | if (!args[0].compare(String8("print-stats"))) { |
Yao Chen | b356151 | 2017-11-21 18:07:17 -0800 | [diff] [blame] | 230 | return cmd_print_stats(out, args); |
David Chen | adaf8b3 | 2017-11-03 15:42:08 -0700 | [diff] [blame] | 231 | } |
yro | 87d983c | 2017-11-14 21:31:43 -0800 | [diff] [blame] | 232 | |
Yao Chen | 8d9989b | 2017-11-18 18:54:50 -0800 | [diff] [blame] | 233 | if (!args[0].compare(String8("meminfo"))) { |
| 234 | return cmd_dump_memory_info(out); |
| 235 | } |
yro | 947fbce | 2017-11-15 22:50:23 -0800 | [diff] [blame] | 236 | |
| 237 | if (!args[0].compare(String8("write-to-disk"))) { |
| 238 | return cmd_write_data_to_disk(out); |
| 239 | } |
Bookatz | b223c4e | 2018-02-01 15:35:04 -0800 | [diff] [blame] | 240 | |
David Chen | 0b5c90c | 2018-01-25 16:51:49 -0800 | [diff] [blame] | 241 | if (!args[0].compare(String8("log-app-breadcrumb"))) { |
| 242 | return cmd_log_app_breadcrumb(out, args); |
Bookatz | b223c4e | 2018-02-01 15:35:04 -0800 | [diff] [blame] | 243 | } |
Chenjie Yu | fa22d65 | 2018-02-05 14:37:48 -0800 | [diff] [blame] | 244 | |
| 245 | if (!args[0].compare(String8("clear-puller-cache"))) { |
| 246 | return cmd_clear_puller_cache(out); |
| 247 | } |
Joe Onorato | 2cbc2cc | 2017-08-30 17:03:23 -0700 | [diff] [blame] | 248 | } |
Joe Onorato | 2cbc2cc | 2017-08-30 17:03:23 -0700 | [diff] [blame] | 249 | |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 250 | print_cmd_help(out); |
Joe Onorato | 2cbc2cc | 2017-08-30 17:03:23 -0700 | [diff] [blame] | 251 | return NO_ERROR; |
| 252 | } |
| 253 | |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 254 | void StatsService::print_cmd_help(FILE* out) { |
| 255 | fprintf(out, |
| 256 | "usage: adb shell cmd stats print-stats-log [tag_required] " |
| 257 | "[timestamp_nsec_optional]\n"); |
| 258 | fprintf(out, "\n"); |
| 259 | fprintf(out, "\n"); |
Yao Chen | 8d9989b | 2017-11-18 18:54:50 -0800 | [diff] [blame] | 260 | fprintf(out, "usage: adb shell cmd stats meminfo\n"); |
| 261 | fprintf(out, "\n"); |
| 262 | fprintf(out, " Prints the malloc debug information. You need to run the following first: \n"); |
| 263 | fprintf(out, " # adb shell stop\n"); |
| 264 | fprintf(out, " # adb shell setprop libc.debug.malloc.program statsd \n"); |
| 265 | fprintf(out, " # adb shell setprop libc.debug.malloc.options backtrace \n"); |
| 266 | fprintf(out, " # adb shell start\n"); |
| 267 | fprintf(out, "\n"); |
| 268 | fprintf(out, "\n"); |
Yao Chen | d10f7b1 | 2017-12-18 12:53:50 -0800 | [diff] [blame] | 269 | fprintf(out, "usage: adb shell cmd stats print-uid-map [PKG]\n"); |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 270 | fprintf(out, "\n"); |
| 271 | fprintf(out, " Prints the UID, app name, version mapping.\n"); |
Yao Chen | d10f7b1 | 2017-12-18 12:53:50 -0800 | [diff] [blame] | 272 | fprintf(out, " PKG Optional package name to print the uids of the package\n"); |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 273 | fprintf(out, "\n"); |
| 274 | fprintf(out, "\n"); |
yro | 3fca5ba | 2017-11-17 13:22:52 -0800 | [diff] [blame] | 275 | fprintf(out, "usage: adb shell cmd stats pull-source [int] \n"); |
David Chen | 1481fe1 | 2017-10-16 13:16:34 -0700 | [diff] [blame] | 276 | fprintf(out, "\n"); |
| 277 | fprintf(out, " Prints the output of a pulled metrics source (int indicates source)\n"); |
| 278 | fprintf(out, "\n"); |
| 279 | fprintf(out, "\n"); |
yro | 947fbce | 2017-11-15 22:50:23 -0800 | [diff] [blame] | 280 | fprintf(out, "usage: adb shell cmd stats write-to-disk \n"); |
| 281 | fprintf(out, "\n"); |
| 282 | fprintf(out, " Flushes all data on memory to disk.\n"); |
| 283 | fprintf(out, "\n"); |
| 284 | fprintf(out, "\n"); |
David Chen | 0b5c90c | 2018-01-25 16:51:49 -0800 | [diff] [blame] | 285 | fprintf(out, "usage: adb shell cmd stats log-app-breadcrumb [UID] LABEL STATE\n"); |
| 286 | fprintf(out, " Writes an AppBreadcrumbReported event to the statslog buffer.\n"); |
Bookatz | b223c4e | 2018-02-01 15:35:04 -0800 | [diff] [blame] | 287 | fprintf(out, " UID The uid to use. It is only possible to pass a UID\n"); |
| 288 | fprintf(out, " parameter on eng builds. If UID is omitted the calling\n"); |
| 289 | fprintf(out, " uid is used.\n"); |
| 290 | fprintf(out, " LABEL Integer in [0, 15], as per atoms.proto.\n"); |
| 291 | fprintf(out, " STATE Integer in [0, 3], as per atoms.proto.\n"); |
| 292 | fprintf(out, "\n"); |
| 293 | fprintf(out, "\n"); |
yro | 74fed97 | 2017-11-27 14:42:42 -0800 | [diff] [blame] | 294 | fprintf(out, "usage: adb shell cmd stats config remove [UID] [NAME]\n"); |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 295 | fprintf(out, "usage: adb shell cmd stats config update [UID] NAME\n"); |
| 296 | fprintf(out, "\n"); |
| 297 | fprintf(out, " Adds, updates or removes a configuration. The proto should be in\n"); |
yro | 74fed97 | 2017-11-27 14:42:42 -0800 | [diff] [blame] | 298 | fprintf(out, " wire-encoded protobuf format and passed via stdin. If no UID and name is\n"); |
| 299 | fprintf(out, " provided, then all configs will be removed from memory and disk.\n"); |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 300 | fprintf(out, "\n"); |
| 301 | fprintf(out, " UID The uid to use. It is only possible to pass the UID\n"); |
yro | 74fed97 | 2017-11-27 14:42:42 -0800 | [diff] [blame] | 302 | fprintf(out, " parameter on eng builds. If UID is omitted the calling\n"); |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 303 | fprintf(out, " uid is used.\n"); |
| 304 | fprintf(out, " NAME The per-uid name to use\n"); |
Yao Chen | 5154a37 | 2017-10-30 22:57:06 -0700 | [diff] [blame] | 305 | fprintf(out, "\n"); |
yro | 74fed97 | 2017-11-27 14:42:42 -0800 | [diff] [blame] | 306 | fprintf(out, "\n *Note: If both UID and NAME are omitted then all configs will\n"); |
| 307 | fprintf(out, "\n be removed from memory and disk!\n"); |
Yao Chen | 5154a37 | 2017-10-30 22:57:06 -0700 | [diff] [blame] | 308 | fprintf(out, "\n"); |
Chenjie Yu | b236c86 | 2017-11-28 22:20:44 -0800 | [diff] [blame] | 309 | fprintf(out, "usage: adb shell cmd stats dump-report [UID] NAME [--proto]\n"); |
Yao Chen | 5154a37 | 2017-10-30 22:57:06 -0700 | [diff] [blame] | 310 | fprintf(out, " Dump all metric data for a configuration.\n"); |
| 311 | fprintf(out, " UID The uid of the configuration. It is only possible to pass\n"); |
| 312 | fprintf(out, " the UID parameter on eng builds. If UID is omitted the\n"); |
| 313 | fprintf(out, " calling uid is used.\n"); |
| 314 | fprintf(out, " NAME The name of the configuration\n"); |
Chenjie Yu | b236c86 | 2017-11-28 22:20:44 -0800 | [diff] [blame] | 315 | fprintf(out, " --proto Print proto binary.\n"); |
David Chen | adaf8b3 | 2017-11-03 15:42:08 -0700 | [diff] [blame] | 316 | fprintf(out, "\n"); |
| 317 | fprintf(out, "\n"); |
David Chen | 1d7b0cd | 2017-11-15 14:20:04 -0800 | [diff] [blame] | 318 | fprintf(out, "usage: adb shell cmd stats send-broadcast [UID] NAME\n"); |
| 319 | fprintf(out, " Send a broadcast that triggers the subscriber to fetch metrics.\n"); |
| 320 | fprintf(out, " UID The uid of the configuration. It is only possible to pass\n"); |
| 321 | fprintf(out, " the UID parameter on eng builds. If UID is omitted the\n"); |
| 322 | fprintf(out, " calling uid is used.\n"); |
| 323 | fprintf(out, " NAME The name of the configuration\n"); |
| 324 | fprintf(out, "\n"); |
| 325 | fprintf(out, "\n"); |
Yao Chen | f5acabe | 2018-01-17 14:10:34 -0800 | [diff] [blame] | 326 | fprintf(out, "usage: adb shell cmd stats print-stats\n"); |
David Chen | 1d7b0cd | 2017-11-15 14:20:04 -0800 | [diff] [blame] | 327 | fprintf(out, " Prints some basic stats.\n"); |
Chenjie Yu | fa22d65 | 2018-02-05 14:37:48 -0800 | [diff] [blame] | 328 | fprintf(out, "\n"); |
| 329 | fprintf(out, "\n"); |
| 330 | fprintf(out, "usage: adb shell cmd stats clear-puller-cache\n"); |
| 331 | fprintf(out, " Clear cached puller data.\n"); |
David Chen | adaf8b3 | 2017-11-03 15:42:08 -0700 | [diff] [blame] | 332 | } |
| 333 | |
David Chen | 1d7b0cd | 2017-11-15 14:20:04 -0800 | [diff] [blame] | 334 | status_t StatsService::cmd_trigger_broadcast(FILE* out, Vector<String8>& args) { |
| 335 | string name; |
| 336 | bool good = false; |
| 337 | int uid; |
| 338 | const int argCount = args.size(); |
| 339 | if (argCount == 2) { |
| 340 | // Automatically pick the UID |
| 341 | uid = IPCThreadState::self()->getCallingUid(); |
| 342 | // TODO: What if this isn't a binder call? Should we fail? |
| 343 | name.assign(args[1].c_str(), args[1].size()); |
| 344 | good = true; |
| 345 | } else if (argCount == 3) { |
| 346 | // If it's a userdebug or eng build, then the shell user can |
| 347 | // impersonate other uids. |
| 348 | if (mEngBuild) { |
| 349 | const char* s = args[1].c_str(); |
| 350 | if (*s != '\0') { |
| 351 | char* end = NULL; |
| 352 | uid = strtol(s, &end, 0); |
| 353 | if (*end == '\0') { |
| 354 | name.assign(args[2].c_str(), args[2].size()); |
| 355 | good = true; |
| 356 | } |
| 357 | } |
| 358 | } else { |
| 359 | fprintf(out, |
| 360 | "The metrics can only be dumped for other UIDs on eng or userdebug " |
| 361 | "builds.\n"); |
| 362 | } |
| 363 | } |
| 364 | if (!good) { |
| 365 | print_cmd_help(out); |
| 366 | return UNKNOWN_ERROR; |
| 367 | } |
Yangster-mac | 94e197c | 2018-01-02 16:03:03 -0800 | [diff] [blame] | 368 | auto receiver = mConfigManager->GetConfigReceiver(ConfigKey(uid, StrToInt64(name))); |
yro | 4d889e6 | 2017-11-17 15:44:48 -0800 | [diff] [blame] | 369 | sp<IStatsCompanionService> sc = getStatsCompanionService(); |
David Chen | 661f791 | 2018-01-22 17:46:24 -0800 | [diff] [blame] | 370 | if (sc == nullptr) { |
| 371 | VLOG("Could not access statsCompanion"); |
| 372 | } else if (receiver == nullptr) { |
| 373 | VLOG("Could not find receiver for %s, %s", args[1].c_str(), args[2].c_str()) |
| 374 | } else { |
| 375 | sc->sendDataBroadcast(receiver); |
yro | 74fed97 | 2017-11-27 14:42:42 -0800 | [diff] [blame] | 376 | VLOG("StatsService::trigger broadcast succeeded to %s, %s", args[1].c_str(), |
| 377 | args[2].c_str()); |
yro | 4d889e6 | 2017-11-17 15:44:48 -0800 | [diff] [blame] | 378 | } |
| 379 | |
David Chen | adaf8b3 | 2017-11-03 15:42:08 -0700 | [diff] [blame] | 380 | return NO_ERROR; |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | status_t StatsService::cmd_config(FILE* in, FILE* out, FILE* err, Vector<String8>& args) { |
| 384 | const int argCount = args.size(); |
| 385 | if (argCount >= 2) { |
| 386 | if (args[1] == "update" || args[1] == "remove") { |
| 387 | bool good = false; |
| 388 | int uid = -1; |
| 389 | string name; |
| 390 | |
| 391 | if (argCount == 3) { |
| 392 | // Automatically pick the UID |
| 393 | uid = IPCThreadState::self()->getCallingUid(); |
| 394 | // TODO: What if this isn't a binder call? Should we fail? |
| 395 | name.assign(args[2].c_str(), args[2].size()); |
| 396 | good = true; |
| 397 | } else if (argCount == 4) { |
| 398 | // If it's a userdebug or eng build, then the shell user can |
| 399 | // impersonate other uids. |
| 400 | if (mEngBuild) { |
| 401 | const char* s = args[2].c_str(); |
| 402 | if (*s != '\0') { |
| 403 | char* end = NULL; |
| 404 | uid = strtol(s, &end, 0); |
| 405 | if (*end == '\0') { |
| 406 | name.assign(args[3].c_str(), args[3].size()); |
| 407 | good = true; |
| 408 | } |
| 409 | } |
| 410 | } else { |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 411 | fprintf(err, |
| 412 | "The config can only be set for other UIDs on eng or userdebug " |
| 413 | "builds.\n"); |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 414 | } |
yro | e5f8292 | 2018-01-22 18:37:27 -0800 | [diff] [blame] | 415 | } else if (argCount == 2 && args[1] == "remove") { |
| 416 | good = true; |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | if (!good) { |
| 420 | // If arg parsing failed, print the help text and return an error. |
| 421 | print_cmd_help(out); |
| 422 | return UNKNOWN_ERROR; |
| 423 | } |
| 424 | |
| 425 | if (args[1] == "update") { |
yro | 255f72e | 2018-02-26 15:15:17 -0800 | [diff] [blame] | 426 | char* endp; |
| 427 | int64_t configID = strtoll(name.c_str(), &endp, 10); |
| 428 | if (endp == name.c_str() || *endp != '\0') { |
| 429 | fprintf(err, "Error parsing config ID.\n"); |
| 430 | return UNKNOWN_ERROR; |
| 431 | } |
| 432 | |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 433 | // Read stream into buffer. |
| 434 | string buffer; |
| 435 | if (!android::base::ReadFdToString(fileno(in), &buffer)) { |
| 436 | fprintf(err, "Error reading stream for StatsConfig.\n"); |
| 437 | return UNKNOWN_ERROR; |
| 438 | } |
| 439 | |
| 440 | // Parse buffer. |
| 441 | StatsdConfig config; |
| 442 | if (!config.ParseFromString(buffer)) { |
| 443 | fprintf(err, "Error parsing proto stream for StatsConfig.\n"); |
| 444 | return UNKNOWN_ERROR; |
| 445 | } |
| 446 | |
| 447 | // Add / update the config. |
yro | 255f72e | 2018-02-26 15:15:17 -0800 | [diff] [blame] | 448 | mConfigManager->UpdateConfig(ConfigKey(uid, configID), config); |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 449 | } else { |
yro | 74fed97 | 2017-11-27 14:42:42 -0800 | [diff] [blame] | 450 | if (argCount == 2) { |
| 451 | cmd_remove_all_configs(out); |
| 452 | } else { |
| 453 | // Remove the config. |
Yangster-mac | 94e197c | 2018-01-02 16:03:03 -0800 | [diff] [blame] | 454 | mConfigManager->RemoveConfig(ConfigKey(uid, StrToInt64(name))); |
yro | 74fed97 | 2017-11-27 14:42:42 -0800 | [diff] [blame] | 455 | } |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 456 | } |
| 457 | |
| 458 | return NO_ERROR; |
| 459 | } |
David Chen | 0656b7a | 2017-09-13 15:53:39 -0700 | [diff] [blame] | 460 | } |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 461 | print_cmd_help(out); |
| 462 | return UNKNOWN_ERROR; |
| 463 | } |
| 464 | |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 465 | status_t StatsService::cmd_dump_report(FILE* out, FILE* err, const Vector<String8>& args) { |
| 466 | if (mProcessor != nullptr) { |
Chenjie Yu | b236c86 | 2017-11-28 22:20:44 -0800 | [diff] [blame] | 467 | int argCount = args.size(); |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 468 | bool good = false; |
Chenjie Yu | b236c86 | 2017-11-28 22:20:44 -0800 | [diff] [blame] | 469 | bool proto = false; |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 470 | int uid; |
| 471 | string name; |
Chenjie Yu | b236c86 | 2017-11-28 22:20:44 -0800 | [diff] [blame] | 472 | if (!std::strcmp("--proto", args[argCount-1].c_str())) { |
| 473 | proto = true; |
| 474 | argCount -= 1; |
| 475 | } |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 476 | if (argCount == 2) { |
| 477 | // Automatically pick the UID |
| 478 | uid = IPCThreadState::self()->getCallingUid(); |
| 479 | // TODO: What if this isn't a binder call? Should we fail? |
Yao Chen | 5154a37 | 2017-10-30 22:57:06 -0700 | [diff] [blame] | 480 | name.assign(args[1].c_str(), args[1].size()); |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 481 | good = true; |
| 482 | } else if (argCount == 3) { |
| 483 | // If it's a userdebug or eng build, then the shell user can |
| 484 | // impersonate other uids. |
| 485 | if (mEngBuild) { |
| 486 | const char* s = args[1].c_str(); |
| 487 | if (*s != '\0') { |
| 488 | char* end = NULL; |
| 489 | uid = strtol(s, &end, 0); |
| 490 | if (*end == '\0') { |
| 491 | name.assign(args[2].c_str(), args[2].size()); |
| 492 | good = true; |
| 493 | } |
| 494 | } |
| 495 | } else { |
| 496 | fprintf(out, |
| 497 | "The metrics can only be dumped for other UIDs on eng or userdebug " |
| 498 | "builds.\n"); |
| 499 | } |
| 500 | } |
| 501 | if (good) { |
David Chen | 1d7b0cd | 2017-11-15 14:20:04 -0800 | [diff] [blame] | 502 | vector<uint8_t> data; |
David Chen | 926fc75 | 2018-02-23 13:31:43 -0800 | [diff] [blame] | 503 | mProcessor->onDumpReport(ConfigKey(uid, StrToInt64(name)), getElapsedRealtimeNs(), |
Yao Chen | 8a8d16c | 2018-02-08 14:50:40 -0800 | [diff] [blame] | 504 | &data); |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 505 | // TODO: print the returned StatsLogReport to file instead of printing to logcat. |
Chenjie Yu | b236c86 | 2017-11-28 22:20:44 -0800 | [diff] [blame] | 506 | if (proto) { |
| 507 | for (size_t i = 0; i < data.size(); i ++) { |
| 508 | fprintf(out, "%c", data[i]); |
| 509 | } |
| 510 | } else { |
| 511 | fprintf(out, "Dump report for Config [%d,%s]\n", uid, name.c_str()); |
| 512 | fprintf(out, "See the StatsLogReport in logcat...\n"); |
| 513 | } |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 514 | return android::OK; |
| 515 | } else { |
| 516 | // If arg parsing failed, print the help text and return an error. |
| 517 | print_cmd_help(out); |
| 518 | return UNKNOWN_ERROR; |
| 519 | } |
| 520 | } else { |
| 521 | fprintf(out, "Log processor does not exist...\n"); |
| 522 | return UNKNOWN_ERROR; |
| 523 | } |
| 524 | } |
| 525 | |
Yao Chen | b356151 | 2017-11-21 18:07:17 -0800 | [diff] [blame] | 526 | status_t StatsService::cmd_print_stats(FILE* out, const Vector<String8>& args) { |
David Chen | 1d7b0cd | 2017-11-15 14:20:04 -0800 | [diff] [blame] | 527 | vector<ConfigKey> configs = mConfigManager->GetAllConfigKeys(); |
| 528 | for (const ConfigKey& key : configs) { |
| 529 | fprintf(out, "Config %s uses %zu bytes\n", key.ToString().c_str(), |
| 530 | mProcessor->GetMetricsSize(key)); |
| 531 | } |
Yao Chen | b356151 | 2017-11-21 18:07:17 -0800 | [diff] [blame] | 532 | StatsdStats& statsdStats = StatsdStats::getInstance(); |
Yao Chen | f5acabe | 2018-01-17 14:10:34 -0800 | [diff] [blame] | 533 | statsdStats.dumpStats(out); |
David Chen | 1d7b0cd | 2017-11-15 14:20:04 -0800 | [diff] [blame] | 534 | return NO_ERROR; |
| 535 | } |
| 536 | |
Yao Chen | d10f7b1 | 2017-12-18 12:53:50 -0800 | [diff] [blame] | 537 | status_t StatsService::cmd_print_uid_map(FILE* out, const Vector<String8>& args) { |
| 538 | if (args.size() > 1) { |
| 539 | string pkg; |
| 540 | pkg.assign(args[1].c_str(), args[1].size()); |
| 541 | auto uids = mUidMap->getAppUid(pkg); |
| 542 | fprintf(out, "%s -> [ ", pkg.c_str()); |
| 543 | for (const auto& uid : uids) { |
| 544 | fprintf(out, "%d ", uid); |
| 545 | } |
| 546 | fprintf(out, "]\n"); |
| 547 | } else { |
| 548 | mUidMap->printUidMap(out); |
| 549 | } |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 550 | return NO_ERROR; |
David Chen | 0656b7a | 2017-09-13 15:53:39 -0700 | [diff] [blame] | 551 | } |
| 552 | |
yro | 947fbce | 2017-11-15 22:50:23 -0800 | [diff] [blame] | 553 | status_t StatsService::cmd_write_data_to_disk(FILE* out) { |
| 554 | fprintf(out, "Writing data to disk\n"); |
| 555 | mProcessor->WriteDataToDisk(); |
| 556 | return NO_ERROR; |
| 557 | } |
| 558 | |
David Chen | 0b5c90c | 2018-01-25 16:51:49 -0800 | [diff] [blame] | 559 | status_t StatsService::cmd_log_app_breadcrumb(FILE* out, const Vector<String8>& args) { |
Bookatz | b223c4e | 2018-02-01 15:35:04 -0800 | [diff] [blame] | 560 | bool good = false; |
| 561 | int32_t uid; |
| 562 | int32_t label; |
| 563 | int32_t state; |
| 564 | const int argCount = args.size(); |
| 565 | if (argCount == 3) { |
| 566 | // Automatically pick the UID |
| 567 | uid = IPCThreadState::self()->getCallingUid(); |
| 568 | label = atoi(args[1].c_str()); |
| 569 | state = atoi(args[2].c_str()); |
| 570 | good = true; |
| 571 | } else if (argCount == 4) { |
| 572 | uid = atoi(args[1].c_str()); |
| 573 | // If it's a userdebug or eng build, then the shell user can impersonate other uids. |
| 574 | // Otherwise, the uid must match the actual caller's uid. |
| 575 | if (mEngBuild || (uid >= 0 && (uid_t)uid == IPCThreadState::self()->getCallingUid())) { |
| 576 | label = atoi(args[2].c_str()); |
| 577 | state = atoi(args[3].c_str()); |
| 578 | good = true; |
| 579 | } else { |
| 580 | fprintf(out, |
David Chen | b639d14 | 2018-02-14 17:29:54 -0800 | [diff] [blame] | 581 | "Selecting a UID for writing AppBreadcrumb can only be done for other UIDs " |
| 582 | "on eng or userdebug builds.\n"); |
Bookatz | b223c4e | 2018-02-01 15:35:04 -0800 | [diff] [blame] | 583 | } |
| 584 | } |
| 585 | if (good) { |
David Chen | 0b5c90c | 2018-01-25 16:51:49 -0800 | [diff] [blame] | 586 | fprintf(out, "Logging AppBreadcrumbReported(%d, %d, %d) to statslog.\n", uid, label, state); |
| 587 | android::util::stats_write(android::util::APP_BREADCRUMB_REPORTED, uid, label, state); |
Bookatz | b223c4e | 2018-02-01 15:35:04 -0800 | [diff] [blame] | 588 | } else { |
| 589 | print_cmd_help(out); |
| 590 | return UNKNOWN_ERROR; |
| 591 | } |
| 592 | return NO_ERROR; |
| 593 | } |
| 594 | |
David Chen | 1481fe1 | 2017-10-16 13:16:34 -0700 | [diff] [blame] | 595 | status_t StatsService::cmd_print_pulled_metrics(FILE* out, const Vector<String8>& args) { |
| 596 | int s = atoi(args[1].c_str()); |
Chenjie Yu | 5305e1d | 2017-10-31 13:49:36 -0700 | [diff] [blame] | 597 | vector<shared_ptr<LogEvent> > stats; |
Chenjie Yu | 1a0a941 | 2018-03-28 10:07:22 -0700 | [diff] [blame] | 598 | if (mStatsPullerManager.Pull(s, getElapsedRealtimeNs(), &stats)) { |
Chenjie Yu | 5305e1d | 2017-10-31 13:49:36 -0700 | [diff] [blame] | 599 | for (const auto& it : stats) { |
| 600 | fprintf(out, "Pull from %d: %s\n", s, it->ToString().c_str()); |
| 601 | } |
| 602 | fprintf(out, "Pull from %d: Received %zu elements\n", s, stats.size()); |
| 603 | return NO_ERROR; |
David Chen | 1481fe1 | 2017-10-16 13:16:34 -0700 | [diff] [blame] | 604 | } |
Chenjie Yu | 5305e1d | 2017-10-31 13:49:36 -0700 | [diff] [blame] | 605 | return UNKNOWN_ERROR; |
David Chen | 1481fe1 | 2017-10-16 13:16:34 -0700 | [diff] [blame] | 606 | } |
| 607 | |
yro | 74fed97 | 2017-11-27 14:42:42 -0800 | [diff] [blame] | 608 | status_t StatsService::cmd_remove_all_configs(FILE* out) { |
| 609 | fprintf(out, "Removing all configs...\n"); |
| 610 | VLOG("StatsService::cmd_remove_all_configs was called"); |
| 611 | mConfigManager->RemoveAllConfigs(); |
yro | 947fbce | 2017-11-15 22:50:23 -0800 | [diff] [blame] | 612 | StorageManager::deleteAllFiles(STATS_SERVICE_DIR); |
yro | 87d983c | 2017-11-14 21:31:43 -0800 | [diff] [blame] | 613 | return NO_ERROR; |
| 614 | } |
| 615 | |
Yao Chen | 8d9989b | 2017-11-18 18:54:50 -0800 | [diff] [blame] | 616 | status_t StatsService::cmd_dump_memory_info(FILE* out) { |
Yao Chen | 20e9e62 | 2018-02-28 11:18:51 -0800 | [diff] [blame] | 617 | fprintf(out, "meminfo not available.\n"); |
Yao Chen | 8d9989b | 2017-11-18 18:54:50 -0800 | [diff] [blame] | 618 | return NO_ERROR; |
| 619 | } |
| 620 | |
Chenjie Yu | e72252b | 2018-02-01 13:19:35 -0800 | [diff] [blame] | 621 | status_t StatsService::cmd_clear_puller_cache(FILE* out) { |
Chenjie Yu | fa22d65 | 2018-02-05 14:37:48 -0800 | [diff] [blame] | 622 | IPCThreadState* ipc = IPCThreadState::self(); |
Yangster-mac | 932ecec | 2018-02-01 10:23:52 -0800 | [diff] [blame] | 623 | VLOG("StatsService::cmd_clear_puller_cache with Pid %i, Uid %i", |
| 624 | ipc->getCallingPid(), ipc->getCallingUid()); |
Chenjie Yu | fa22d65 | 2018-02-05 14:37:48 -0800 | [diff] [blame] | 625 | if (checkCallingPermission(String16(kPermissionDump))) { |
| 626 | int cleared = mStatsPullerManager.ForceClearPullerCache(); |
| 627 | fprintf(out, "Puller removed %d cached data!\n", cleared); |
| 628 | return NO_ERROR; |
| 629 | } else { |
| 630 | return PERMISSION_DENIED; |
| 631 | } |
Chenjie Yu | e72252b | 2018-02-01 13:19:35 -0800 | [diff] [blame] | 632 | } |
| 633 | |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 634 | Status StatsService::informAllUidData(const vector<int32_t>& uid, const vector<int64_t>& version, |
David Chen | de70169 | 2017-10-05 13:16:02 -0700 | [diff] [blame] | 635 | const vector<String16>& app) { |
yro | 74fed97 | 2017-11-27 14:42:42 -0800 | [diff] [blame] | 636 | VLOG("StatsService::informAllUidData was called"); |
David Chen | de70169 | 2017-10-05 13:16:02 -0700 | [diff] [blame] | 637 | |
| 638 | if (IPCThreadState::self()->getCallingUid() != AID_SYSTEM) { |
| 639 | return Status::fromExceptionCode(Status::EX_SECURITY, |
| 640 | "Only system uid can call informAllUidData"); |
| 641 | } |
| 642 | |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 643 | mUidMap->updateMap(uid, version, app); |
yro | 74fed97 | 2017-11-27 14:42:42 -0800 | [diff] [blame] | 644 | VLOG("StatsService::informAllUidData succeeded"); |
David Chen | de70169 | 2017-10-05 13:16:02 -0700 | [diff] [blame] | 645 | |
| 646 | return Status::ok(); |
| 647 | } |
| 648 | |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 649 | Status StatsService::informOnePackage(const String16& app, int32_t uid, int64_t version) { |
yro | 74fed97 | 2017-11-27 14:42:42 -0800 | [diff] [blame] | 650 | VLOG("StatsService::informOnePackage was called"); |
David Chen | de70169 | 2017-10-05 13:16:02 -0700 | [diff] [blame] | 651 | |
| 652 | if (IPCThreadState::self()->getCallingUid() != AID_SYSTEM) { |
| 653 | return Status::fromExceptionCode(Status::EX_SECURITY, |
| 654 | "Only system uid can call informOnePackage"); |
| 655 | } |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 656 | mUidMap->updateApp(app, uid, version); |
David Chen | de70169 | 2017-10-05 13:16:02 -0700 | [diff] [blame] | 657 | return Status::ok(); |
| 658 | } |
| 659 | |
| 660 | Status StatsService::informOnePackageRemoved(const String16& app, int32_t uid) { |
yro | 74fed97 | 2017-11-27 14:42:42 -0800 | [diff] [blame] | 661 | VLOG("StatsService::informOnePackageRemoved was called"); |
David Chen | de70169 | 2017-10-05 13:16:02 -0700 | [diff] [blame] | 662 | |
| 663 | if (IPCThreadState::self()->getCallingUid() != AID_SYSTEM) { |
| 664 | return Status::fromExceptionCode(Status::EX_SECURITY, |
| 665 | "Only system uid can call informOnePackageRemoved"); |
| 666 | } |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 667 | mUidMap->removeApp(app, uid); |
yro | 0192402 | 2018-02-20 18:20:49 -0800 | [diff] [blame] | 668 | mConfigManager->RemoveConfigs(uid); |
David Chen | de70169 | 2017-10-05 13:16:02 -0700 | [diff] [blame] | 669 | return Status::ok(); |
| 670 | } |
| 671 | |
Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame] | 672 | Status StatsService::informAnomalyAlarmFired() { |
yro | 74fed97 | 2017-11-27 14:42:42 -0800 | [diff] [blame] | 673 | VLOG("StatsService::informAnomalyAlarmFired was called"); |
Bookatz | 1b0b114 | 2017-09-08 11:58:42 -0700 | [diff] [blame] | 674 | |
| 675 | if (IPCThreadState::self()->getCallingUid() != AID_SYSTEM) { |
| 676 | return Status::fromExceptionCode(Status::EX_SECURITY, |
Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame] | 677 | "Only system uid can call informAnomalyAlarmFired"); |
Bookatz | 1b0b114 | 2017-09-08 11:58:42 -0700 | [diff] [blame] | 678 | } |
Yangster-mac | 932ecec | 2018-02-01 10:23:52 -0800 | [diff] [blame] | 679 | |
Yangster-mac | 330af58 | 2018-02-08 15:24:38 -0800 | [diff] [blame] | 680 | uint64_t currentTimeSec = getElapsedRealtimeSec(); |
Yangster-mac | 932ecec | 2018-02-01 10:23:52 -0800 | [diff] [blame] | 681 | std::unordered_set<sp<const InternalAlarm>, SpHash<InternalAlarm>> alarmSet = |
| 682 | mAnomalyAlarmMonitor->popSoonerThan(static_cast<uint32_t>(currentTimeSec)); |
| 683 | if (alarmSet.size() > 0) { |
Bookatz | 66fe061 | 2018-02-07 18:51:48 -0800 | [diff] [blame] | 684 | VLOG("Found an anomaly alarm that fired."); |
Yangster-mac | 932ecec | 2018-02-01 10:23:52 -0800 | [diff] [blame] | 685 | mProcessor->onAnomalyAlarmFired(currentTimeSec * NS_PER_SEC, alarmSet); |
Bookatz | 66fe061 | 2018-02-07 18:51:48 -0800 | [diff] [blame] | 686 | } else { |
| 687 | VLOG("Cannot find an anomaly alarm that fired. Perhaps it was recently cancelled."); |
| 688 | } |
Bookatz | 1b0b114 | 2017-09-08 11:58:42 -0700 | [diff] [blame] | 689 | return Status::ok(); |
| 690 | } |
| 691 | |
Yangster-mac | 932ecec | 2018-02-01 10:23:52 -0800 | [diff] [blame] | 692 | Status StatsService::informAlarmForSubscriberTriggeringFired() { |
| 693 | VLOG("StatsService::informAlarmForSubscriberTriggeringFired was called"); |
| 694 | |
| 695 | if (IPCThreadState::self()->getCallingUid() != AID_SYSTEM) { |
| 696 | return Status::fromExceptionCode( |
| 697 | Status::EX_SECURITY, |
| 698 | "Only system uid can call informAlarmForSubscriberTriggeringFired"); |
| 699 | } |
| 700 | |
| 701 | uint64_t currentTimeSec = time(nullptr); |
| 702 | std::unordered_set<sp<const InternalAlarm>, SpHash<InternalAlarm>> alarmSet = |
| 703 | mPeriodicAlarmMonitor->popSoonerThan(static_cast<uint32_t>(currentTimeSec)); |
| 704 | if (alarmSet.size() > 0) { |
| 705 | VLOG("Found periodic alarm fired."); |
| 706 | mProcessor->onPeriodicAlarmFired(currentTimeSec * NS_PER_SEC, alarmSet); |
| 707 | } else { |
| 708 | ALOGW("Cannot find an periodic alarm that fired. Perhaps it was recently cancelled."); |
| 709 | } |
| 710 | return Status::ok(); |
| 711 | } |
| 712 | |
Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame] | 713 | Status StatsService::informPollAlarmFired() { |
yro | 74fed97 | 2017-11-27 14:42:42 -0800 | [diff] [blame] | 714 | VLOG("StatsService::informPollAlarmFired was called"); |
Bookatz | 1b0b114 | 2017-09-08 11:58:42 -0700 | [diff] [blame] | 715 | |
| 716 | if (IPCThreadState::self()->getCallingUid() != AID_SYSTEM) { |
| 717 | return Status::fromExceptionCode(Status::EX_SECURITY, |
Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame] | 718 | "Only system uid can call informPollAlarmFired"); |
Bookatz | 1b0b114 | 2017-09-08 11:58:42 -0700 | [diff] [blame] | 719 | } |
| 720 | |
Chenjie Yu | 5305e1d | 2017-10-31 13:49:36 -0700 | [diff] [blame] | 721 | mStatsPullerManager.OnAlarmFired(); |
Chenjie Yu | b3dda41 | 2017-10-24 13:41:59 -0700 | [diff] [blame] | 722 | |
yro | 74fed97 | 2017-11-27 14:42:42 -0800 | [diff] [blame] | 723 | VLOG("StatsService::informPollAlarmFired succeeded"); |
Bookatz | 1b0b114 | 2017-09-08 11:58:42 -0700 | [diff] [blame] | 724 | |
| 725 | return Status::ok(); |
| 726 | } |
| 727 | |
Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame] | 728 | Status StatsService::systemRunning() { |
Joe Onorato | 5dcbc6c | 2017-08-29 15:13:58 -0700 | [diff] [blame] | 729 | if (IPCThreadState::self()->getCallingUid() != AID_SYSTEM) { |
| 730 | return Status::fromExceptionCode(Status::EX_SECURITY, |
Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame] | 731 | "Only system uid can call systemRunning"); |
Joe Onorato | 5dcbc6c | 2017-08-29 15:13:58 -0700 | [diff] [blame] | 732 | } |
| 733 | |
| 734 | // When system_server is up and running, schedule the dropbox task to run. |
yro | 74fed97 | 2017-11-27 14:42:42 -0800 | [diff] [blame] | 735 | VLOG("StatsService::systemRunning"); |
Joe Onorato | 5dcbc6c | 2017-08-29 15:13:58 -0700 | [diff] [blame] | 736 | |
Bookatz | b487b55 | 2017-09-18 11:26:01 -0700 | [diff] [blame] | 737 | sayHiToStatsCompanion(); |
| 738 | |
Joe Onorato | 5dcbc6c | 2017-08-29 15:13:58 -0700 | [diff] [blame] | 739 | return Status::ok(); |
| 740 | } |
| 741 | |
yro | 947fbce | 2017-11-15 22:50:23 -0800 | [diff] [blame] | 742 | Status StatsService::writeDataToDisk() { |
| 743 | if (IPCThreadState::self()->getCallingUid() != AID_SYSTEM) { |
| 744 | return Status::fromExceptionCode(Status::EX_SECURITY, |
| 745 | "Only system uid can call systemRunning"); |
| 746 | } |
| 747 | |
yro | 74fed97 | 2017-11-27 14:42:42 -0800 | [diff] [blame] | 748 | VLOG("StatsService::writeDataToDisk"); |
yro | 947fbce | 2017-11-15 22:50:23 -0800 | [diff] [blame] | 749 | |
| 750 | mProcessor->WriteDataToDisk(); |
| 751 | |
| 752 | return Status::ok(); |
| 753 | } |
| 754 | |
Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame] | 755 | void StatsService::sayHiToStatsCompanion() { |
| 756 | // TODO: This method needs to be private. It is temporarily public and unsecured for testing |
| 757 | // purposes. |
Bookatz | b487b55 | 2017-09-18 11:26:01 -0700 | [diff] [blame] | 758 | sp<IStatsCompanionService> statsCompanion = getStatsCompanionService(); |
| 759 | if (statsCompanion != nullptr) { |
yro | 74fed97 | 2017-11-27 14:42:42 -0800 | [diff] [blame] | 760 | VLOG("Telling statsCompanion that statsd is ready"); |
Bookatz | b487b55 | 2017-09-18 11:26:01 -0700 | [diff] [blame] | 761 | statsCompanion->statsdReady(); |
| 762 | } else { |
yro | 74fed97 | 2017-11-27 14:42:42 -0800 | [diff] [blame] | 763 | VLOG("Could not access statsCompanion"); |
Bookatz | b487b55 | 2017-09-18 11:26:01 -0700 | [diff] [blame] | 764 | } |
| 765 | } |
| 766 | |
Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame] | 767 | Status StatsService::statsCompanionReady() { |
yro | 74fed97 | 2017-11-27 14:42:42 -0800 | [diff] [blame] | 768 | VLOG("StatsService::statsCompanionReady was called"); |
Bookatz | b487b55 | 2017-09-18 11:26:01 -0700 | [diff] [blame] | 769 | |
| 770 | if (IPCThreadState::self()->getCallingUid() != AID_SYSTEM) { |
| 771 | return Status::fromExceptionCode(Status::EX_SECURITY, |
| 772 | "Only system uid can call statsCompanionReady"); |
| 773 | } |
| 774 | |
| 775 | sp<IStatsCompanionService> statsCompanion = getStatsCompanionService(); |
| 776 | if (statsCompanion == nullptr) { |
Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame] | 777 | return Status::fromExceptionCode( |
| 778 | Status::EX_NULL_POINTER, |
| 779 | "statscompanion unavailable despite it contacting statsd!"); |
Bookatz | b487b55 | 2017-09-18 11:26:01 -0700 | [diff] [blame] | 780 | } |
yro | 74fed97 | 2017-11-27 14:42:42 -0800 | [diff] [blame] | 781 | VLOG("StatsService::statsCompanionReady linking to statsCompanion."); |
Chenjie Yu | aa5b201 | 2018-03-21 13:53:15 -0700 | [diff] [blame] | 782 | IInterface::asBinder(statsCompanion)->linkToDeath(this); |
| 783 | mStatsPullerManager.SetStatsCompanionService(statsCompanion); |
Yangster-mac | 932ecec | 2018-02-01 10:23:52 -0800 | [diff] [blame] | 784 | mAnomalyAlarmMonitor->setStatsCompanionService(statsCompanion); |
| 785 | mPeriodicAlarmMonitor->setStatsCompanionService(statsCompanion); |
Bookatz | c697797 | 2018-01-16 16:55:05 -0800 | [diff] [blame] | 786 | SubscriberReporter::getInstance().setStatsCompanionService(statsCompanion); |
Bookatz | b487b55 | 2017-09-18 11:26:01 -0700 | [diff] [blame] | 787 | return Status::ok(); |
| 788 | } |
| 789 | |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 790 | void StatsService::Startup() { |
| 791 | mConfigManager->Startup(); |
Bookatz | 906a35c | 2017-09-20 15:26:44 -0700 | [diff] [blame] | 792 | } |
| 793 | |
Yangster-mac | d40053e | 2018-01-09 16:29:22 -0800 | [diff] [blame] | 794 | void StatsService::OnLogEvent(LogEvent* event) { |
Joe Onorato | c4dfae5 | 2017-10-17 23:38:21 -0700 | [diff] [blame] | 795 | mProcessor->OnLogEvent(event); |
Bookatz | 906a35c | 2017-09-20 15:26:44 -0700 | [diff] [blame] | 796 | } |
| 797 | |
Yangster-mac | 94e197c | 2018-01-02 16:03:03 -0800 | [diff] [blame] | 798 | Status StatsService::getData(int64_t key, vector<uint8_t>* output) { |
David Chen | adaf8b3 | 2017-11-03 15:42:08 -0700 | [diff] [blame] | 799 | IPCThreadState* ipc = IPCThreadState::self(); |
yro | 74fed97 | 2017-11-27 14:42:42 -0800 | [diff] [blame] | 800 | VLOG("StatsService::getData with Pid %i, Uid %i", ipc->getCallingPid(), ipc->getCallingUid()); |
Yao Chen | 7ee9415 | 2017-11-17 09:44:40 -0800 | [diff] [blame] | 801 | if (checkCallingPermission(String16(kPermissionDump))) { |
Yangster-mac | 94e197c | 2018-01-02 16:03:03 -0800 | [diff] [blame] | 802 | ConfigKey configKey(ipc->getCallingUid(), key); |
David Chen | 926fc75 | 2018-02-23 13:31:43 -0800 | [diff] [blame] | 803 | mProcessor->onDumpReport(configKey, getElapsedRealtimeNs(), output); |
David Chen | adaf8b3 | 2017-11-03 15:42:08 -0700 | [diff] [blame] | 804 | return Status::ok(); |
| 805 | } else { |
| 806 | return Status::fromExceptionCode(binder::Status::EX_SECURITY); |
| 807 | } |
yro | 31eb67b | 2017-10-24 13:33:21 -0700 | [diff] [blame] | 808 | } |
| 809 | |
David Chen | 2e8f380 | 2017-11-22 10:56:48 -0800 | [diff] [blame] | 810 | Status StatsService::getMetadata(vector<uint8_t>* output) { |
| 811 | IPCThreadState* ipc = IPCThreadState::self(); |
| 812 | VLOG("StatsService::getMetadata with Pid %i, Uid %i", ipc->getCallingPid(), |
| 813 | ipc->getCallingUid()); |
| 814 | if (checkCallingPermission(String16(kPermissionDump))) { |
| 815 | StatsdStats::getInstance().dumpStats(output, false); // Don't reset the counters. |
| 816 | return Status::ok(); |
| 817 | } else { |
| 818 | return Status::fromExceptionCode(binder::Status::EX_SECURITY); |
| 819 | } |
| 820 | } |
| 821 | |
Yangster-mac | 94e197c | 2018-01-02 16:03:03 -0800 | [diff] [blame] | 822 | Status StatsService::addConfiguration(int64_t key, |
David Chen | adaf8b3 | 2017-11-03 15:42:08 -0700 | [diff] [blame] | 823 | const vector <uint8_t>& config, |
David Chen | adaf8b3 | 2017-11-03 15:42:08 -0700 | [diff] [blame] | 824 | bool* success) { |
| 825 | IPCThreadState* ipc = IPCThreadState::self(); |
Yao Chen | 7ee9415 | 2017-11-17 09:44:40 -0800 | [diff] [blame] | 826 | if (checkCallingPermission(String16(kPermissionDump))) { |
David Chen | 9fdd403 | 2018-03-20 14:38:56 -0700 | [diff] [blame] | 827 | if (addConfigurationChecked(ipc->getCallingUid(), key, config)) { |
| 828 | *success = true; |
| 829 | } else { |
David Chen | 7d8aa4d | 2017-12-27 13:37:01 -0800 | [diff] [blame] | 830 | *success = false; |
David Chen | 7d8aa4d | 2017-12-27 13:37:01 -0800 | [diff] [blame] | 831 | } |
David Chen | 661f791 | 2018-01-22 17:46:24 -0800 | [diff] [blame] | 832 | return Status::ok(); |
| 833 | } else { |
| 834 | *success = false; |
| 835 | return Status::fromExceptionCode(binder::Status::EX_SECURITY); |
| 836 | } |
| 837 | } |
| 838 | |
David Chen | 9fdd403 | 2018-03-20 14:38:56 -0700 | [diff] [blame] | 839 | bool StatsService::addConfigurationChecked(int uid, int64_t key, const vector<uint8_t>& config) { |
| 840 | ConfigKey configKey(uid, key); |
| 841 | StatsdConfig cfg; |
| 842 | if (config.size() > 0) { // If the config is empty, skip parsing. |
| 843 | if (!cfg.ParseFromArray(&config[0], config.size())) { |
| 844 | return false; |
| 845 | } |
| 846 | } |
| 847 | mConfigManager->UpdateConfig(configKey, cfg); |
| 848 | return true; |
| 849 | } |
| 850 | |
David Chen | 661f791 | 2018-01-22 17:46:24 -0800 | [diff] [blame] | 851 | Status StatsService::removeDataFetchOperation(int64_t key, bool* success) { |
| 852 | IPCThreadState* ipc = IPCThreadState::self(); |
| 853 | if (checkCallingPermission(String16(kPermissionDump))) { |
| 854 | ConfigKey configKey(ipc->getCallingUid(), key); |
| 855 | mConfigManager->RemoveConfigReceiver(configKey); |
| 856 | *success = true; |
| 857 | return Status::ok(); |
| 858 | } else { |
| 859 | *success = false; |
| 860 | return Status::fromExceptionCode(binder::Status::EX_SECURITY); |
| 861 | } |
| 862 | } |
| 863 | |
| 864 | Status StatsService::setDataFetchOperation(int64_t key, const sp<android::IBinder>& intentSender, |
| 865 | bool* success) { |
| 866 | IPCThreadState* ipc = IPCThreadState::self(); |
| 867 | if (checkCallingPermission(String16(kPermissionDump))) { |
| 868 | ConfigKey configKey(ipc->getCallingUid(), key); |
| 869 | mConfigManager->SetConfigReceiver(configKey, intentSender); |
David Chen | adaf8b3 | 2017-11-03 15:42:08 -0700 | [diff] [blame] | 870 | *success = true; |
| 871 | return Status::ok(); |
| 872 | } else { |
Yao Chen | aa39bc7 | 2017-12-01 11:16:50 -0800 | [diff] [blame] | 873 | *success = false; |
David Chen | adaf8b3 | 2017-11-03 15:42:08 -0700 | [diff] [blame] | 874 | return Status::fromExceptionCode(binder::Status::EX_SECURITY); |
yro | 31eb67b | 2017-10-24 13:33:21 -0700 | [diff] [blame] | 875 | } |
yro | 31eb67b | 2017-10-24 13:33:21 -0700 | [diff] [blame] | 876 | } |
| 877 | |
Yangster-mac | 94e197c | 2018-01-02 16:03:03 -0800 | [diff] [blame] | 878 | Status StatsService::removeConfiguration(int64_t key, bool* success) { |
David Chen | adaf8b3 | 2017-11-03 15:42:08 -0700 | [diff] [blame] | 879 | IPCThreadState* ipc = IPCThreadState::self(); |
Yao Chen | 7ee9415 | 2017-11-17 09:44:40 -0800 | [diff] [blame] | 880 | if (checkCallingPermission(String16(kPermissionDump))) { |
Bookatz | c697797 | 2018-01-16 16:55:05 -0800 | [diff] [blame] | 881 | ConfigKey configKey(ipc->getCallingUid(), key); |
| 882 | mConfigManager->RemoveConfig(configKey); |
| 883 | SubscriberReporter::getInstance().removeConfig(configKey); |
Yao Chen | aa39bc7 | 2017-12-01 11:16:50 -0800 | [diff] [blame] | 884 | *success = true; |
David Chen | adaf8b3 | 2017-11-03 15:42:08 -0700 | [diff] [blame] | 885 | return Status::ok(); |
| 886 | } else { |
| 887 | *success = false; |
| 888 | return Status::fromExceptionCode(binder::Status::EX_SECURITY); |
yro | 31eb67b | 2017-10-24 13:33:21 -0700 | [diff] [blame] | 889 | } |
yro | 31eb67b | 2017-10-24 13:33:21 -0700 | [diff] [blame] | 890 | } |
| 891 | |
Bookatz | c697797 | 2018-01-16 16:55:05 -0800 | [diff] [blame] | 892 | Status StatsService::setBroadcastSubscriber(int64_t configId, |
| 893 | int64_t subscriberId, |
| 894 | const sp<android::IBinder>& intentSender, |
| 895 | bool* success) { |
| 896 | VLOG("StatsService::setBroadcastSubscriber called."); |
| 897 | IPCThreadState* ipc = IPCThreadState::self(); |
| 898 | if (checkCallingPermission(String16(kPermissionDump))) { |
| 899 | ConfigKey configKey(ipc->getCallingUid(), configId); |
| 900 | SubscriberReporter::getInstance() |
| 901 | .setBroadcastSubscriber(configKey, subscriberId, intentSender); |
| 902 | *success = true; |
| 903 | return Status::ok(); |
| 904 | } else { |
| 905 | *success = false; |
| 906 | return Status::fromExceptionCode(binder::Status::EX_SECURITY); |
| 907 | } |
| 908 | } |
| 909 | |
| 910 | Status StatsService::unsetBroadcastSubscriber(int64_t configId, |
| 911 | int64_t subscriberId, |
| 912 | bool* success) { |
| 913 | VLOG("StatsService::unsetBroadcastSubscriber called."); |
| 914 | IPCThreadState* ipc = IPCThreadState::self(); |
| 915 | if (checkCallingPermission(String16(kPermissionDump))) { |
| 916 | ConfigKey configKey(ipc->getCallingUid(), configId); |
| 917 | SubscriberReporter::getInstance() |
| 918 | .unsetBroadcastSubscriber(configKey, subscriberId); |
| 919 | *success = true; |
| 920 | return Status::ok(); |
| 921 | } else { |
| 922 | *success = false; |
| 923 | return Status::fromExceptionCode(binder::Status::EX_SECURITY); |
| 924 | } |
| 925 | } |
| 926 | |
| 927 | |
David Chen | 1d7b0cd | 2017-11-15 14:20:04 -0800 | [diff] [blame] | 928 | void StatsService::binderDied(const wp <IBinder>& who) { |
Chenjie Yu | aa5b201 | 2018-03-21 13:53:15 -0700 | [diff] [blame] | 929 | ALOGW("statscompanion service died"); |
| 930 | mProcessor->WriteDataToDisk(); |
| 931 | mAnomalyAlarmMonitor->setStatsCompanionService(nullptr); |
| 932 | mPeriodicAlarmMonitor->setStatsCompanionService(nullptr); |
| 933 | SubscriberReporter::getInstance().setStatsCompanionService(nullptr); |
| 934 | mStatsPullerManager.SetStatsCompanionService(nullptr); |
yro | 31eb67b | 2017-10-24 13:33:21 -0700 | [diff] [blame] | 935 | } |
| 936 | |
Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame] | 937 | } // namespace statsd |
| 938 | } // namespace os |
| 939 | } // namespace android |