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