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> |
Jeff Sharkey | 6b64925 | 2018-04-16 09:50:22 -0600 | [diff] [blame] | 30 | #include <android-base/stringprintf.h> |
Tej Singh | 53f9dee | 2019-04-30 17:45:54 -0700 | [diff] [blame] | 31 | #include <android-base/strings.h> |
Joe Onorato | 5dcbc6c | 2017-08-29 15:13:58 -0700 | [diff] [blame] | 32 | #include <binder/IPCThreadState.h> |
| 33 | #include <binder/IServiceManager.h> |
Jeff Sharkey | 6b64925 | 2018-04-16 09:50:22 -0600 | [diff] [blame] | 34 | #include <binder/PermissionController.h> |
Chenjie Yu | 6b1667c | 2019-01-18 10:09:33 -0800 | [diff] [blame] | 35 | #include <cutils/multiuser.h> |
yro | 87d983c | 2017-11-14 21:31:43 -0800 | [diff] [blame] | 36 | #include <dirent.h> |
David Chen | 0656b7a | 2017-09-13 15:53:39 -0700 | [diff] [blame] | 37 | #include <frameworks/base/cmds/statsd/src/statsd_config.pb.h> |
Joe Onorato | 5dcbc6c | 2017-08-29 15:13:58 -0700 | [diff] [blame] | 38 | #include <private/android_filesystem_config.h> |
Bookatz | b223c4e | 2018-02-01 15:35:04 -0800 | [diff] [blame] | 39 | #include <statslog.h> |
Joe Onorato | 5dcbc6c | 2017-08-29 15:13:58 -0700 | [diff] [blame] | 40 | #include <stdio.h> |
Yao Chen | 482d272 | 2017-09-12 13:25:43 -0700 | [diff] [blame] | 41 | #include <stdlib.h> |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 42 | #include <sys/system_properties.h> |
Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame] | 43 | #include <unistd.h> |
Yao Chen | a80e5c0 | 2018-09-04 13:55:29 -0700 | [diff] [blame] | 44 | #include <utils/Looper.h> |
| 45 | #include <utils/String16.h> |
| 46 | #include <chrono> |
Joe Onorato | 5dcbc6c | 2017-08-29 15:13:58 -0700 | [diff] [blame] | 47 | |
| 48 | using namespace android; |
| 49 | |
Jeff Sharkey | 6b64925 | 2018-04-16 09:50:22 -0600 | [diff] [blame] | 50 | using android::base::StringPrintf; |
Bookatz | ff71cad | 2018-09-20 17:17:49 -0700 | [diff] [blame] | 51 | using android::util::FIELD_COUNT_REPEATED; |
Chenjie Yu | 6b1667c | 2019-01-18 10:09:33 -0800 | [diff] [blame] | 52 | using android::util::FIELD_TYPE_INT64; |
Bookatz | ff71cad | 2018-09-20 17:17:49 -0700 | [diff] [blame] | 53 | using android::util::FIELD_TYPE_MESSAGE; |
Joe Onorato | 99598ee | 2019-02-11 15:55:13 +0000 | [diff] [blame] | 54 | using android::util::ProtoReader; |
Jeff Sharkey | 6b64925 | 2018-04-16 09:50:22 -0600 | [diff] [blame] | 55 | |
Bookatz | 906a35c | 2017-09-20 15:26:44 -0700 | [diff] [blame] | 56 | namespace android { |
| 57 | namespace os { |
| 58 | namespace statsd { |
| 59 | |
David Chen | adaf8b3 | 2017-11-03 15:42:08 -0700 | [diff] [blame] | 60 | constexpr const char* kPermissionDump = "android.permission.DUMP"; |
Jeff Sharkey | 6b64925 | 2018-04-16 09:50:22 -0600 | [diff] [blame] | 61 | constexpr const char* kPermissionUsage = "android.permission.PACKAGE_USAGE_STATS"; |
| 62 | |
| 63 | constexpr const char* kOpUsage = "android:get_usage_stats"; |
| 64 | |
yro | 03faf09 | 2017-12-12 00:17:50 -0800 | [diff] [blame] | 65 | #define STATS_SERVICE_DIR "/data/misc/stats-service" |
David Chen | adaf8b3 | 2017-11-03 15:42:08 -0700 | [diff] [blame] | 66 | |
Bookatz | ff71cad | 2018-09-20 17:17:49 -0700 | [diff] [blame] | 67 | // for StatsDataDumpProto |
| 68 | const int FIELD_ID_REPORTS_LIST = 1; |
| 69 | |
Jeff Sharkey | 6b64925 | 2018-04-16 09:50:22 -0600 | [diff] [blame] | 70 | static binder::Status ok() { |
| 71 | return binder::Status::ok(); |
| 72 | } |
| 73 | |
| 74 | static binder::Status exception(uint32_t code, const std::string& msg) { |
| 75 | ALOGE("%s (%d)", msg.c_str(), code); |
| 76 | return binder::Status::fromExceptionCode(code, String8(msg.c_str())); |
| 77 | } |
| 78 | |
| 79 | binder::Status checkUid(uid_t expectedUid) { |
| 80 | uid_t uid = IPCThreadState::self()->getCallingUid(); |
| 81 | if (uid == expectedUid || uid == AID_ROOT) { |
| 82 | return ok(); |
| 83 | } else { |
| 84 | return exception(binder::Status::EX_SECURITY, |
| 85 | StringPrintf("UID %d is not expected UID %d", uid, expectedUid)); |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | binder::Status checkDumpAndUsageStats(const String16& packageName) { |
| 90 | pid_t pid = IPCThreadState::self()->getCallingPid(); |
| 91 | uid_t uid = IPCThreadState::self()->getCallingUid(); |
| 92 | |
| 93 | // Root, system, and shell always have access |
| 94 | if (uid == AID_ROOT || uid == AID_SYSTEM || uid == AID_SHELL) { |
| 95 | return ok(); |
| 96 | } |
| 97 | |
| 98 | // Caller must be granted these permissions |
| 99 | if (!checkCallingPermission(String16(kPermissionDump))) { |
| 100 | return exception(binder::Status::EX_SECURITY, |
| 101 | StringPrintf("UID %d / PID %d lacks permission %s", uid, pid, kPermissionDump)); |
| 102 | } |
| 103 | if (!checkCallingPermission(String16(kPermissionUsage))) { |
| 104 | return exception(binder::Status::EX_SECURITY, |
| 105 | StringPrintf("UID %d / PID %d lacks permission %s", uid, pid, kPermissionUsage)); |
| 106 | } |
| 107 | |
| 108 | // Caller must also have usage stats op granted |
| 109 | PermissionController pc; |
| 110 | switch (pc.noteOp(String16(kOpUsage), uid, packageName)) { |
| 111 | case PermissionController::MODE_ALLOWED: |
| 112 | case PermissionController::MODE_DEFAULT: |
| 113 | return ok(); |
| 114 | default: |
| 115 | return exception(binder::Status::EX_SECURITY, |
| 116 | StringPrintf("UID %d / PID %d lacks app-op %s", uid, pid, kOpUsage)); |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | #define ENFORCE_UID(uid) { \ |
| 121 | binder::Status status = checkUid((uid)); \ |
| 122 | if (!status.isOk()) { \ |
| 123 | return status; \ |
| 124 | } \ |
| 125 | } |
| 126 | |
| 127 | #define ENFORCE_DUMP_AND_USAGE_STATS(packageName) { \ |
| 128 | binder::Status status = checkDumpAndUsageStats(packageName); \ |
| 129 | if (!status.isOk()) { \ |
| 130 | return status; \ |
| 131 | } \ |
| 132 | } |
| 133 | |
Yao Chen | 0f86186 | 2019-03-27 11:51:15 -0700 | [diff] [blame] | 134 | StatsService::StatsService(const sp<Looper>& handlerLooper, shared_ptr<LogEventQueue> queue) |
| 135 | : mAnomalyAlarmMonitor(new AlarmMonitor( |
| 136 | MIN_DIFF_TO_UPDATE_REGISTERED_ALARM_SECS, |
| 137 | [](const sp<IStatsCompanionService>& sc, int64_t timeMillis) { |
| 138 | if (sc != nullptr) { |
| 139 | sc->setAnomalyAlarm(timeMillis); |
| 140 | StatsdStats::getInstance().noteRegisteredAnomalyAlarmChanged(); |
| 141 | } |
| 142 | }, |
| 143 | [](const sp<IStatsCompanionService>& sc) { |
| 144 | if (sc != nullptr) { |
| 145 | sc->cancelAnomalyAlarm(); |
| 146 | StatsdStats::getInstance().noteRegisteredAnomalyAlarmChanged(); |
| 147 | } |
| 148 | })), |
| 149 | mPeriodicAlarmMonitor(new AlarmMonitor( |
| 150 | MIN_DIFF_TO_UPDATE_REGISTERED_ALARM_SECS, |
| 151 | [](const sp<IStatsCompanionService>& sc, int64_t timeMillis) { |
| 152 | if (sc != nullptr) { |
| 153 | sc->setAlarmForSubscriberTriggering(timeMillis); |
| 154 | StatsdStats::getInstance().noteRegisteredPeriodicAlarmChanged(); |
| 155 | } |
| 156 | }, |
| 157 | [](const sp<IStatsCompanionService>& sc) { |
| 158 | if (sc != nullptr) { |
| 159 | sc->cancelAlarmForSubscriberTriggering(); |
| 160 | StatsdStats::getInstance().noteRegisteredPeriodicAlarmChanged(); |
| 161 | } |
| 162 | })), |
| 163 | mEventQueue(queue) { |
Yao Chen | 4ce0729 | 2019-02-13 13:06:36 -0800 | [diff] [blame] | 164 | mUidMap = UidMap::getInstance(); |
Chenjie Yu | e221920 | 2018-06-08 10:07:51 -0700 | [diff] [blame] | 165 | mPullerManager = new StatsPullerManager(); |
Chenjie Yu | 80f9112 | 2018-01-31 20:24:50 -0800 | [diff] [blame] | 166 | StatsPuller::SetUidMap(mUidMap); |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 167 | mConfigManager = new ConfigManager(); |
Chenjie Yu | e221920 | 2018-06-08 10:07:51 -0700 | [diff] [blame] | 168 | mProcessor = new StatsLogProcessor( |
| 169 | mUidMap, mPullerManager, mAnomalyAlarmMonitor, mPeriodicAlarmMonitor, |
Chenjie Yu | c7939cb | 2019-02-04 17:25:45 -0800 | [diff] [blame] | 170 | getElapsedRealtimeNs(), |
| 171 | [this](const ConfigKey& key) { |
Chenjie Yu | e221920 | 2018-06-08 10:07:51 -0700 | [diff] [blame] | 172 | sp<IStatsCompanionService> sc = getStatsCompanionService(); |
| 173 | auto receiver = mConfigManager->GetConfigReceiver(key); |
| 174 | if (sc == nullptr) { |
| 175 | VLOG("Could not find StatsCompanionService"); |
| 176 | return false; |
| 177 | } else if (receiver == nullptr) { |
| 178 | VLOG("Statscompanion could not find a broadcast receiver for %s", |
| 179 | key.ToString().c_str()); |
| 180 | return false; |
| 181 | } else { |
| 182 | sc->sendDataBroadcast(receiver, mProcessor->getLastReportTimeNs(key)); |
| 183 | return true; |
| 184 | } |
Tej Singh | 6ede28b | 2019-01-29 17:06:54 -0800 | [diff] [blame] | 185 | }, |
| 186 | [this](const int& uid, const vector<int64_t>& activeConfigs) { |
| 187 | auto receiver = mConfigManager->GetActiveConfigsChangedReceiver(uid); |
| 188 | sp<IStatsCompanionService> sc = getStatsCompanionService(); |
| 189 | if (sc == nullptr) { |
| 190 | VLOG("Could not access statsCompanion"); |
| 191 | return false; |
| 192 | } else if (receiver == nullptr) { |
| 193 | VLOG("Could not find receiver for uid %d", uid); |
| 194 | return false; |
| 195 | } else { |
| 196 | sc->sendActiveConfigsChangedBroadcast(receiver, activeConfigs); |
| 197 | VLOG("StatsService::active configs broadcast succeeded for uid %d" , uid); |
| 198 | return true; |
| 199 | } |
Chenjie Yu | e221920 | 2018-06-08 10:07:51 -0700 | [diff] [blame] | 200 | }); |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 201 | |
| 202 | mConfigManager->AddListener(mProcessor); |
| 203 | |
| 204 | init_system_properties(); |
Yao Chen | 0f86186 | 2019-03-27 11:51:15 -0700 | [diff] [blame] | 205 | |
| 206 | if (mEventQueue != nullptr) { |
| 207 | std::thread pushedEventThread([this] { readLogs(); }); |
| 208 | pushedEventThread.detach(); |
| 209 | } |
Joe Onorato | 5dcbc6c | 2017-08-29 15:13:58 -0700 | [diff] [blame] | 210 | } |
| 211 | |
Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame] | 212 | StatsService::~StatsService() { |
Joe Onorato | 5dcbc6c | 2017-08-29 15:13:58 -0700 | [diff] [blame] | 213 | } |
| 214 | |
Yao Chen | 0f86186 | 2019-03-27 11:51:15 -0700 | [diff] [blame] | 215 | /* Runs on a dedicated thread to process pushed events. */ |
| 216 | void StatsService::readLogs() { |
| 217 | // Read forever..... long live statsd |
| 218 | while (1) { |
| 219 | // Block until an event is available. |
| 220 | auto event = mEventQueue->waitPop(); |
| 221 | // Pass it to StatsLogProcess to all configs/metrics |
| 222 | // At this point, the LogEventQueue is not blocked, so that the socketListener |
| 223 | // can read events from the socket and write to buffer to avoid data drop. |
| 224 | mProcessor->OnLogEvent(event.get()); |
| 225 | // The ShellSubscriber is only used by shell for local debugging. |
| 226 | if (mShellSubscriber != nullptr) { |
| 227 | mShellSubscriber->onLogEvent(*event); |
| 228 | } |
| 229 | } |
| 230 | } |
| 231 | |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 232 | void StatsService::init_system_properties() { |
| 233 | mEngBuild = false; |
| 234 | const prop_info* buildType = __system_property_find("ro.build.type"); |
| 235 | if (buildType != NULL) { |
| 236 | __system_property_read_callback(buildType, init_build_type_callback, this); |
| 237 | } |
David Chen | 0656b7a | 2017-09-13 15:53:39 -0700 | [diff] [blame] | 238 | } |
| 239 | |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 240 | void StatsService::init_build_type_callback(void* cookie, const char* /*name*/, const char* value, |
| 241 | uint32_t serial) { |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 242 | if (0 == strcmp("eng", value) || 0 == strcmp("userdebug", value)) { |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 243 | reinterpret_cast<StatsService*>(cookie)->mEngBuild = true; |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | /** |
| 248 | * Implement our own because the default binder implementation isn't |
| 249 | * properly handling SHELL_COMMAND_TRANSACTION. |
| 250 | */ |
Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame] | 251 | status_t StatsService::onTransact(uint32_t code, const Parcel& data, Parcel* reply, |
| 252 | uint32_t flags) { |
Joe Onorato | 2cbc2cc | 2017-08-30 17:03:23 -0700 | [diff] [blame] | 253 | switch (code) { |
| 254 | case SHELL_COMMAND_TRANSACTION: { |
| 255 | int in = data.readFileDescriptor(); |
| 256 | int out = data.readFileDescriptor(); |
| 257 | int err = data.readFileDescriptor(); |
| 258 | int argc = data.readInt32(); |
| 259 | Vector<String8> args; |
| 260 | for (int i = 0; i < argc && data.dataAvail() > 0; i++) { |
| 261 | args.add(String8(data.readString16())); |
| 262 | } |
Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame] | 263 | sp<IShellCallback> shellCallback = IShellCallback::asInterface(data.readStrongBinder()); |
| 264 | sp<IResultReceiver> resultReceiver = |
| 265 | IResultReceiver::asInterface(data.readStrongBinder()); |
Joe Onorato | 2cbc2cc | 2017-08-30 17:03:23 -0700 | [diff] [blame] | 266 | |
Yao Chen | a80e5c0 | 2018-09-04 13:55:29 -0700 | [diff] [blame] | 267 | err = command(in, out, err, args, resultReceiver); |
| 268 | resultReceiver->send(err); |
Joe Onorato | 2cbc2cc | 2017-08-30 17:03:23 -0700 | [diff] [blame] | 269 | return NO_ERROR; |
| 270 | } |
Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame] | 271 | default: { return BnStatsManager::onTransact(code, data, reply, flags); } |
Joe Onorato | 2cbc2cc | 2017-08-30 17:03:23 -0700 | [diff] [blame] | 272 | } |
| 273 | } |
| 274 | |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 275 | /** |
Bookatz | ff71cad | 2018-09-20 17:17:49 -0700 | [diff] [blame] | 276 | * Write data from statsd. |
| 277 | * Format for statsdStats: adb shell dumpsys stats --metadata [-v] [--proto] |
| 278 | * Format for data report: adb shell dumpsys stats [anything other than --metadata] [--proto] |
| 279 | * Anything ending in --proto will be in proto format. |
| 280 | * Anything without --metadata as the first argument will be report information. |
| 281 | * (bugreports call "adb shell dumpsys stats --dump-priority NORMAL -a --proto") |
| 282 | * TODO: Come up with a more robust method of enacting <serviceutils/PriorityDumper.h>. |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 283 | */ |
Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame] | 284 | status_t StatsService::dump(int fd, const Vector<String16>& args) { |
Tej Singh | dd83d70 | 2018-04-10 17:24:50 -0700 | [diff] [blame] | 285 | if (!checkCallingPermission(String16(kPermissionDump))) { |
| 286 | return PERMISSION_DENIED; |
| 287 | } |
Bookatz | ff71cad | 2018-09-20 17:17:49 -0700 | [diff] [blame] | 288 | int lastArg = args.size() - 1; |
| 289 | bool asProto = false; |
| 290 | if (lastArg >= 0 && !args[lastArg].compare(String16("--proto"))) { // last argument |
| 291 | asProto = true; |
| 292 | lastArg--; |
Yao Chen | 884c8c1 | 2018-01-26 10:36:25 -0800 | [diff] [blame] | 293 | } |
Bookatz | ff71cad | 2018-09-20 17:17:49 -0700 | [diff] [blame] | 294 | if (args.size() > 0 && !args[0].compare(String16("--metadata"))) { // first argument |
| 295 | // Request is to dump statsd stats. |
| 296 | bool verbose = false; |
| 297 | if (lastArg >= 0 && !args[lastArg].compare(String16("-v"))) { |
| 298 | verbose = true; |
| 299 | lastArg--; |
| 300 | } |
| 301 | dumpStatsdStats(fd, verbose, asProto); |
| 302 | } else { |
| 303 | // Request is to dump statsd report data. |
| 304 | if (asProto) { |
| 305 | dumpIncidentSection(fd); |
| 306 | } else { |
| 307 | dprintf(fd, "Non-proto format of stats data dump not available; see proto version.\n"); |
| 308 | } |
Tej Singh | 41b3f9a | 2018-04-03 17:06:35 -0700 | [diff] [blame] | 309 | } |
Yao Chen | 884c8c1 | 2018-01-26 10:36:25 -0800 | [diff] [blame] | 310 | |
Joe Onorato | 5dcbc6c | 2017-08-29 15:13:58 -0700 | [diff] [blame] | 311 | return NO_ERROR; |
| 312 | } |
| 313 | |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 314 | /** |
Tej Singh | 41b3f9a | 2018-04-03 17:06:35 -0700 | [diff] [blame] | 315 | * Write debugging data about statsd in text or proto format. |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 316 | */ |
Bookatz | ff71cad | 2018-09-20 17:17:49 -0700 | [diff] [blame] | 317 | void StatsService::dumpStatsdStats(int out, bool verbose, bool proto) { |
Tej Singh | 41b3f9a | 2018-04-03 17:06:35 -0700 | [diff] [blame] | 318 | if (proto) { |
| 319 | vector<uint8_t> data; |
| 320 | StatsdStats::getInstance().dumpStats(&data, false); // does not reset statsdStats. |
| 321 | for (size_t i = 0; i < data.size(); i ++) { |
Yao Chen | a80e5c0 | 2018-09-04 13:55:29 -0700 | [diff] [blame] | 322 | dprintf(out, "%c", data[i]); |
Tej Singh | 41b3f9a | 2018-04-03 17:06:35 -0700 | [diff] [blame] | 323 | } |
| 324 | } else { |
| 325 | StatsdStats::getInstance().dumpStats(out); |
| 326 | mProcessor->dumpStates(out, verbose); |
| 327 | } |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | /** |
Bookatz | ff71cad | 2018-09-20 17:17:49 -0700 | [diff] [blame] | 331 | * Write stats report data in StatsDataDumpProto incident section format. |
| 332 | */ |
| 333 | void StatsService::dumpIncidentSection(int out) { |
| 334 | ProtoOutputStream proto; |
| 335 | for (const ConfigKey& configKey : mConfigManager->GetAllConfigKeys()) { |
| 336 | uint64_t reportsListToken = |
| 337 | proto.start(FIELD_TYPE_MESSAGE | FIELD_COUNT_REPEATED | FIELD_ID_REPORTS_LIST); |
| 338 | mProcessor->onDumpReport(configKey, getElapsedRealtimeNs(), |
| 339 | true /* includeCurrentBucket */, false /* erase_data */, |
Olivier Gaillard | 6c75ecd | 2019-02-20 09:57:33 +0000 | [diff] [blame] | 340 | ADB_DUMP, |
| 341 | FAST, |
| 342 | &proto); |
Bookatz | ff71cad | 2018-09-20 17:17:49 -0700 | [diff] [blame] | 343 | proto.end(reportsListToken); |
| 344 | proto.flush(out); |
Bookatz | c71d901 | 2018-12-19 12:28:38 -0800 | [diff] [blame] | 345 | proto.clear(); |
Bookatz | ff71cad | 2018-09-20 17:17:49 -0700 | [diff] [blame] | 346 | } |
| 347 | } |
| 348 | |
| 349 | /** |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 350 | * Implementation of the adb shell cmd stats command. |
| 351 | */ |
Yao Chen | a80e5c0 | 2018-09-04 13:55:29 -0700 | [diff] [blame] | 352 | status_t StatsService::command(int in, int out, int err, Vector<String8>& args, |
| 353 | sp<IResultReceiver> resultReceiver) { |
Jeff Sharkey | 6b64925 | 2018-04-16 09:50:22 -0600 | [diff] [blame] | 354 | uid_t uid = IPCThreadState::self()->getCallingUid(); |
| 355 | if (uid != AID_ROOT && uid != AID_SHELL) { |
| 356 | return PERMISSION_DENIED; |
| 357 | } |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 358 | |
| 359 | const int argCount = args.size(); |
| 360 | if (argCount >= 1) { |
| 361 | // adb shell cmd stats config ... |
David Chen | 0656b7a | 2017-09-13 15:53:39 -0700 | [diff] [blame] | 362 | if (!args[0].compare(String8("config"))) { |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 363 | return cmd_config(in, out, err, args); |
David Chen | 0656b7a | 2017-09-13 15:53:39 -0700 | [diff] [blame] | 364 | } |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 365 | |
David Chen | de70169 | 2017-10-05 13:16:02 -0700 | [diff] [blame] | 366 | if (!args[0].compare(String8("print-uid-map"))) { |
Yao Chen | d10f7b1 | 2017-12-18 12:53:50 -0800 | [diff] [blame] | 367 | return cmd_print_uid_map(out, args); |
David Chen | de70169 | 2017-10-05 13:16:02 -0700 | [diff] [blame] | 368 | } |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 369 | |
| 370 | if (!args[0].compare(String8("dump-report"))) { |
Bookatz | ff71cad | 2018-09-20 17:17:49 -0700 | [diff] [blame] | 371 | return cmd_dump_report(out, args); |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 372 | } |
David Chen | 1481fe1 | 2017-10-16 13:16:34 -0700 | [diff] [blame] | 373 | |
| 374 | if (!args[0].compare(String8("pull-source")) && args.size() > 1) { |
| 375 | return cmd_print_pulled_metrics(out, args); |
| 376 | } |
David Chen | adaf8b3 | 2017-11-03 15:42:08 -0700 | [diff] [blame] | 377 | |
| 378 | if (!args[0].compare(String8("send-broadcast"))) { |
David Chen | 1d7b0cd | 2017-11-15 14:20:04 -0800 | [diff] [blame] | 379 | return cmd_trigger_broadcast(out, args); |
| 380 | } |
| 381 | |
| 382 | if (!args[0].compare(String8("print-stats"))) { |
Yao Chen | b356151 | 2017-11-21 18:07:17 -0800 | [diff] [blame] | 383 | return cmd_print_stats(out, args); |
David Chen | adaf8b3 | 2017-11-03 15:42:08 -0700 | [diff] [blame] | 384 | } |
yro | 87d983c | 2017-11-14 21:31:43 -0800 | [diff] [blame] | 385 | |
Yao Chen | 8d9989b | 2017-11-18 18:54:50 -0800 | [diff] [blame] | 386 | if (!args[0].compare(String8("meminfo"))) { |
| 387 | return cmd_dump_memory_info(out); |
| 388 | } |
yro | 947fbce | 2017-11-15 22:50:23 -0800 | [diff] [blame] | 389 | |
| 390 | if (!args[0].compare(String8("write-to-disk"))) { |
| 391 | return cmd_write_data_to_disk(out); |
| 392 | } |
Bookatz | b223c4e | 2018-02-01 15:35:04 -0800 | [diff] [blame] | 393 | |
David Chen | 0b5c90c | 2018-01-25 16:51:49 -0800 | [diff] [blame] | 394 | if (!args[0].compare(String8("log-app-breadcrumb"))) { |
| 395 | return cmd_log_app_breadcrumb(out, args); |
Bookatz | b223c4e | 2018-02-01 15:35:04 -0800 | [diff] [blame] | 396 | } |
Chenjie Yu | fa22d65 | 2018-02-05 14:37:48 -0800 | [diff] [blame] | 397 | |
Tej Singh | 53f9dee | 2019-04-30 17:45:54 -0700 | [diff] [blame] | 398 | if (!args[0].compare(String8("log-binary-push"))) { |
| 399 | return cmd_log_binary_push(out, args); |
| 400 | } |
| 401 | |
Chenjie Yu | fa22d65 | 2018-02-05 14:37:48 -0800 | [diff] [blame] | 402 | if (!args[0].compare(String8("clear-puller-cache"))) { |
| 403 | return cmd_clear_puller_cache(out); |
| 404 | } |
Yao Chen | 876889c | 2018-05-02 11:16:16 -0700 | [diff] [blame] | 405 | |
| 406 | if (!args[0].compare(String8("print-logs"))) { |
| 407 | return cmd_print_logs(out, args); |
| 408 | } |
Tej Singh | 6ede28b | 2019-01-29 17:06:54 -0800 | [diff] [blame] | 409 | if (!args[0].compare(String8("send-active-configs"))) { |
| 410 | return cmd_trigger_active_config_broadcast(out, args); |
| 411 | } |
Yao Chen | a80e5c0 | 2018-09-04 13:55:29 -0700 | [diff] [blame] | 412 | if (!args[0].compare(String8("data-subscribe"))) { |
| 413 | if (mShellSubscriber == nullptr) { |
Yao Chen | 41e606c | 2018-10-05 15:54:11 -0700 | [diff] [blame] | 414 | mShellSubscriber = new ShellSubscriber(mUidMap, mPullerManager); |
Yao Chen | a80e5c0 | 2018-09-04 13:55:29 -0700 | [diff] [blame] | 415 | } |
Yao Chen | 35cb8d6 | 2019-01-03 16:49:14 -0800 | [diff] [blame] | 416 | int timeoutSec = -1; |
| 417 | if (argCount >= 2) { |
| 418 | timeoutSec = atoi(args[1].c_str()); |
| 419 | } |
| 420 | mShellSubscriber->startNewSubscription(in, out, resultReceiver, timeoutSec); |
Yao Chen | a80e5c0 | 2018-09-04 13:55:29 -0700 | [diff] [blame] | 421 | return NO_ERROR; |
| 422 | } |
Joe Onorato | 2cbc2cc | 2017-08-30 17:03:23 -0700 | [diff] [blame] | 423 | } |
Joe Onorato | 2cbc2cc | 2017-08-30 17:03:23 -0700 | [diff] [blame] | 424 | |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 425 | print_cmd_help(out); |
Joe Onorato | 2cbc2cc | 2017-08-30 17:03:23 -0700 | [diff] [blame] | 426 | return NO_ERROR; |
| 427 | } |
| 428 | |
Yao Chen | a80e5c0 | 2018-09-04 13:55:29 -0700 | [diff] [blame] | 429 | void StatsService::print_cmd_help(int out) { |
| 430 | dprintf(out, |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 431 | "usage: adb shell cmd stats print-stats-log [tag_required] " |
| 432 | "[timestamp_nsec_optional]\n"); |
Yao Chen | a80e5c0 | 2018-09-04 13:55:29 -0700 | [diff] [blame] | 433 | dprintf(out, "\n"); |
| 434 | dprintf(out, "\n"); |
| 435 | dprintf(out, "usage: adb shell cmd stats meminfo\n"); |
| 436 | dprintf(out, "\n"); |
| 437 | dprintf(out, " Prints the malloc debug information. You need to run the following first: \n"); |
| 438 | dprintf(out, " # adb shell stop\n"); |
| 439 | dprintf(out, " # adb shell setprop libc.debug.malloc.program statsd \n"); |
| 440 | dprintf(out, " # adb shell setprop libc.debug.malloc.options backtrace \n"); |
| 441 | dprintf(out, " # adb shell start\n"); |
| 442 | dprintf(out, "\n"); |
| 443 | dprintf(out, "\n"); |
| 444 | dprintf(out, "usage: adb shell cmd stats print-uid-map [PKG]\n"); |
| 445 | dprintf(out, "\n"); |
| 446 | dprintf(out, " Prints the UID, app name, version mapping.\n"); |
| 447 | dprintf(out, " PKG Optional package name to print the uids of the package\n"); |
| 448 | dprintf(out, "\n"); |
| 449 | dprintf(out, "\n"); |
| 450 | dprintf(out, "usage: adb shell cmd stats pull-source [int] \n"); |
| 451 | dprintf(out, "\n"); |
| 452 | dprintf(out, " Prints the output of a pulled metrics source (int indicates source)\n"); |
| 453 | dprintf(out, "\n"); |
| 454 | dprintf(out, "\n"); |
| 455 | dprintf(out, "usage: adb shell cmd stats write-to-disk \n"); |
| 456 | dprintf(out, "\n"); |
| 457 | dprintf(out, " Flushes all data on memory to disk.\n"); |
| 458 | dprintf(out, "\n"); |
| 459 | dprintf(out, "\n"); |
| 460 | dprintf(out, "usage: adb shell cmd stats log-app-breadcrumb [UID] LABEL STATE\n"); |
| 461 | dprintf(out, " Writes an AppBreadcrumbReported event to the statslog buffer.\n"); |
| 462 | dprintf(out, " UID The uid to use. It is only possible to pass a UID\n"); |
| 463 | dprintf(out, " parameter on eng builds. If UID is omitted the calling\n"); |
| 464 | dprintf(out, " uid is used.\n"); |
| 465 | dprintf(out, " LABEL Integer in [0, 15], as per atoms.proto.\n"); |
| 466 | dprintf(out, " STATE Integer in [0, 3], as per atoms.proto.\n"); |
| 467 | dprintf(out, "\n"); |
| 468 | dprintf(out, "\n"); |
Tej Singh | 53f9dee | 2019-04-30 17:45:54 -0700 | [diff] [blame] | 469 | dprintf(out, |
| 470 | "usage: adb shell cmd stats log-binary-push NAME VERSION STAGING ROLLBACK_ENABLED " |
| 471 | "LOW_LATENCY STATE EXPERIMENT_IDS\n"); |
| 472 | dprintf(out, " Log a binary push state changed event.\n"); |
| 473 | dprintf(out, " NAME The train name.\n"); |
| 474 | dprintf(out, " VERSION The train version code.\n"); |
| 475 | dprintf(out, " STAGING If this train requires a restart.\n"); |
| 476 | dprintf(out, " ROLLBACK_ENABLED If rollback should be enabled for this install.\n"); |
| 477 | dprintf(out, " LOW_LATENCY If the train requires low latency monitoring.\n"); |
| 478 | dprintf(out, " STATE The status of the train push.\n"); |
| 479 | dprintf(out, " Integer value of the enum in atoms.proto.\n"); |
| 480 | dprintf(out, " EXPERIMENT_IDS Comma separated list of experiment ids.\n"); |
| 481 | dprintf(out, " Leave blank for none.\n"); |
| 482 | dprintf(out, "\n"); |
| 483 | dprintf(out, "\n"); |
Yao Chen | a80e5c0 | 2018-09-04 13:55:29 -0700 | [diff] [blame] | 484 | dprintf(out, "usage: adb shell cmd stats config remove [UID] [NAME]\n"); |
| 485 | dprintf(out, "usage: adb shell cmd stats config update [UID] NAME\n"); |
| 486 | dprintf(out, "\n"); |
| 487 | dprintf(out, " Adds, updates or removes a configuration. The proto should be in\n"); |
| 488 | dprintf(out, " wire-encoded protobuf format and passed via stdin. If no UID and name is\n"); |
| 489 | dprintf(out, " provided, then all configs will be removed from memory and disk.\n"); |
| 490 | dprintf(out, "\n"); |
| 491 | dprintf(out, " UID The uid to use. It is only possible to pass the UID\n"); |
| 492 | dprintf(out, " parameter on eng builds. If UID is omitted the calling\n"); |
| 493 | dprintf(out, " uid is used.\n"); |
| 494 | dprintf(out, " NAME The per-uid name to use\n"); |
| 495 | dprintf(out, "\n"); |
| 496 | dprintf(out, "\n *Note: If both UID and NAME are omitted then all configs will\n"); |
| 497 | dprintf(out, "\n be removed from memory and disk!\n"); |
| 498 | dprintf(out, "\n"); |
| 499 | dprintf(out, |
Bookatz | 3e90658 | 2018-12-10 17:26:58 -0800 | [diff] [blame] | 500 | "usage: adb shell cmd stats dump-report [UID] NAME [--keep_data] " |
| 501 | "[--include_current_bucket] [--proto]\n"); |
Yao Chen | a80e5c0 | 2018-09-04 13:55:29 -0700 | [diff] [blame] | 502 | dprintf(out, " Dump all metric data for a configuration.\n"); |
| 503 | dprintf(out, " UID The uid of the configuration. It is only possible to pass\n"); |
| 504 | dprintf(out, " the UID parameter on eng builds. If UID is omitted the\n"); |
| 505 | dprintf(out, " calling uid is used.\n"); |
| 506 | dprintf(out, " NAME The name of the configuration\n"); |
Bookatz | 3e90658 | 2018-12-10 17:26:58 -0800 | [diff] [blame] | 507 | dprintf(out, " --keep_data Do NOT erase the data upon dumping it.\n"); |
Yao Chen | a80e5c0 | 2018-09-04 13:55:29 -0700 | [diff] [blame] | 508 | dprintf(out, " --proto Print proto binary.\n"); |
| 509 | dprintf(out, "\n"); |
| 510 | dprintf(out, "\n"); |
| 511 | dprintf(out, "usage: adb shell cmd stats send-broadcast [UID] NAME\n"); |
| 512 | dprintf(out, " Send a broadcast that triggers the subscriber to fetch metrics.\n"); |
| 513 | dprintf(out, " UID The uid of the configuration. It is only possible to pass\n"); |
| 514 | dprintf(out, " the UID parameter on eng builds. If UID is omitted the\n"); |
| 515 | dprintf(out, " calling uid is used.\n"); |
| 516 | dprintf(out, " NAME The name of the configuration\n"); |
| 517 | dprintf(out, "\n"); |
| 518 | dprintf(out, "\n"); |
Tej Singh | 6ede28b | 2019-01-29 17:06:54 -0800 | [diff] [blame] | 519 | dprintf(out, |
| 520 | "usage: adb shell cmd stats send-active-configs [--uid=UID] [--configs] " |
| 521 | "[NAME1] [NAME2] [NAME3..]\n"); |
| 522 | dprintf(out, " Send a broadcast that informs the subscriber of the current active configs.\n"); |
| 523 | dprintf(out, " --uid=UID The uid of the configurations. It is only possible to pass\n"); |
| 524 | dprintf(out, " the UID parameter on eng builds. If UID is omitted the\n"); |
| 525 | dprintf(out, " calling uid is used.\n"); |
| 526 | dprintf(out, " --configs Send the list of configs in the name list instead of\n"); |
| 527 | dprintf(out, " the currently active configs\n"); |
| 528 | dprintf(out, " NAME LIST List of configuration names to be included in the broadcast.\n"); |
Tej Singh | 6ede28b | 2019-01-29 17:06:54 -0800 | [diff] [blame] | 529 | dprintf(out, "\n"); |
| 530 | dprintf(out, "\n"); |
Yao Chen | a80e5c0 | 2018-09-04 13:55:29 -0700 | [diff] [blame] | 531 | dprintf(out, "usage: adb shell cmd stats print-stats\n"); |
| 532 | dprintf(out, " Prints some basic stats.\n"); |
| 533 | dprintf(out, " --proto Print proto binary instead of string format.\n"); |
| 534 | dprintf(out, "\n"); |
| 535 | dprintf(out, "\n"); |
| 536 | dprintf(out, "usage: adb shell cmd stats clear-puller-cache\n"); |
| 537 | dprintf(out, " Clear cached puller data.\n"); |
| 538 | dprintf(out, "\n"); |
| 539 | dprintf(out, "usage: adb shell cmd stats print-logs\n"); |
| 540 | dprintf(out, " Only works on eng build\n"); |
David Chen | adaf8b3 | 2017-11-03 15:42:08 -0700 | [diff] [blame] | 541 | } |
| 542 | |
Yao Chen | a80e5c0 | 2018-09-04 13:55:29 -0700 | [diff] [blame] | 543 | status_t StatsService::cmd_trigger_broadcast(int out, Vector<String8>& args) { |
David Chen | 1d7b0cd | 2017-11-15 14:20:04 -0800 | [diff] [blame] | 544 | string name; |
| 545 | bool good = false; |
| 546 | int uid; |
| 547 | const int argCount = args.size(); |
| 548 | if (argCount == 2) { |
| 549 | // Automatically pick the UID |
| 550 | uid = IPCThreadState::self()->getCallingUid(); |
David Chen | 1d7b0cd | 2017-11-15 14:20:04 -0800 | [diff] [blame] | 551 | name.assign(args[1].c_str(), args[1].size()); |
| 552 | good = true; |
| 553 | } else if (argCount == 3) { |
Bookatz | d238657 | 2018-12-14 15:53:14 -0800 | [diff] [blame] | 554 | good = getUidFromArgs(args, 1, uid); |
| 555 | if (!good) { |
| 556 | dprintf(out, "Invalid UID. Note that the metrics can only be dumped for " |
| 557 | "other UIDs on eng or userdebug builds.\n"); |
David Chen | 1d7b0cd | 2017-11-15 14:20:04 -0800 | [diff] [blame] | 558 | } |
Bookatz | d238657 | 2018-12-14 15:53:14 -0800 | [diff] [blame] | 559 | name.assign(args[2].c_str(), args[2].size()); |
David Chen | 1d7b0cd | 2017-11-15 14:20:04 -0800 | [diff] [blame] | 560 | } |
| 561 | if (!good) { |
| 562 | print_cmd_help(out); |
| 563 | return UNKNOWN_ERROR; |
| 564 | } |
David Chen | d37bc23 | 2018-04-12 18:05:11 -0700 | [diff] [blame] | 565 | ConfigKey key(uid, StrToInt64(name)); |
| 566 | auto receiver = mConfigManager->GetConfigReceiver(key); |
yro | 4d889e6 | 2017-11-17 15:44:48 -0800 | [diff] [blame] | 567 | sp<IStatsCompanionService> sc = getStatsCompanionService(); |
David Chen | 661f791 | 2018-01-22 17:46:24 -0800 | [diff] [blame] | 568 | if (sc == nullptr) { |
| 569 | VLOG("Could not access statsCompanion"); |
| 570 | } else if (receiver == nullptr) { |
| 571 | VLOG("Could not find receiver for %s, %s", args[1].c_str(), args[2].c_str()) |
| 572 | } else { |
David Chen | d37bc23 | 2018-04-12 18:05:11 -0700 | [diff] [blame] | 573 | sc->sendDataBroadcast(receiver, mProcessor->getLastReportTimeNs(key)); |
yro | 74fed97 | 2017-11-27 14:42:42 -0800 | [diff] [blame] | 574 | VLOG("StatsService::trigger broadcast succeeded to %s, %s", args[1].c_str(), |
| 575 | args[2].c_str()); |
yro | 4d889e6 | 2017-11-17 15:44:48 -0800 | [diff] [blame] | 576 | } |
| 577 | |
David Chen | adaf8b3 | 2017-11-03 15:42:08 -0700 | [diff] [blame] | 578 | return NO_ERROR; |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 579 | } |
| 580 | |
Tej Singh | 6ede28b | 2019-01-29 17:06:54 -0800 | [diff] [blame] | 581 | status_t StatsService::cmd_trigger_active_config_broadcast(int out, Vector<String8>& args) { |
| 582 | const int argCount = args.size(); |
| 583 | int uid; |
| 584 | vector<int64_t> configIds; |
| 585 | if (argCount == 1) { |
| 586 | // Automatically pick the uid and send a broadcast that has no active configs. |
| 587 | uid = IPCThreadState::self()->getCallingUid(); |
| 588 | mProcessor->GetActiveConfigs(uid, configIds); |
| 589 | } else { |
| 590 | int curArg = 1; |
| 591 | if(args[curArg].find("--uid=") == 0) { |
| 592 | string uidArgStr(args[curArg].c_str()); |
| 593 | string uidStr = uidArgStr.substr(6); |
| 594 | if (!getUidFromString(uidStr.c_str(), uid)) { |
| 595 | dprintf(out, "Invalid UID. Note that the config can only be set for " |
| 596 | "other UIDs on eng or userdebug builds.\n"); |
| 597 | return UNKNOWN_ERROR; |
| 598 | } |
| 599 | curArg++; |
| 600 | } else { |
| 601 | uid = IPCThreadState::self()->getCallingUid(); |
| 602 | } |
| 603 | if (curArg == argCount || args[curArg] != "--configs") { |
| 604 | VLOG("Reached end of args, or specify configs not set. Sending actual active configs,"); |
| 605 | mProcessor->GetActiveConfigs(uid, configIds); |
| 606 | } else { |
| 607 | // Flag specified, use the given list of configs. |
| 608 | curArg++; |
| 609 | for (int i = curArg; i < argCount; i++) { |
| 610 | char* endp; |
| 611 | int64_t configID = strtoll(args[i].c_str(), &endp, 10); |
| 612 | if (endp == args[i].c_str() || *endp != '\0') { |
| 613 | dprintf(out, "Error parsing config ID.\n"); |
| 614 | return UNKNOWN_ERROR; |
| 615 | } |
| 616 | VLOG("Adding config id %ld", static_cast<long>(configID)); |
| 617 | configIds.push_back(configID); |
| 618 | } |
| 619 | } |
| 620 | } |
| 621 | auto receiver = mConfigManager->GetActiveConfigsChangedReceiver(uid); |
| 622 | sp<IStatsCompanionService> sc = getStatsCompanionService(); |
| 623 | if (sc == nullptr) { |
| 624 | VLOG("Could not access statsCompanion"); |
| 625 | } else if (receiver == nullptr) { |
| 626 | VLOG("Could not find receiver for uid %d", uid); |
| 627 | } else { |
| 628 | sc->sendActiveConfigsChangedBroadcast(receiver, configIds); |
| 629 | VLOG("StatsService::trigger active configs changed broadcast succeeded for uid %d" , uid); |
| 630 | } |
| 631 | return NO_ERROR; |
| 632 | } |
| 633 | |
Yao Chen | a80e5c0 | 2018-09-04 13:55:29 -0700 | [diff] [blame] | 634 | status_t StatsService::cmd_config(int in, int out, int err, Vector<String8>& args) { |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 635 | const int argCount = args.size(); |
| 636 | if (argCount >= 2) { |
| 637 | if (args[1] == "update" || args[1] == "remove") { |
| 638 | bool good = false; |
| 639 | int uid = -1; |
| 640 | string name; |
| 641 | |
| 642 | if (argCount == 3) { |
| 643 | // Automatically pick the UID |
| 644 | uid = IPCThreadState::self()->getCallingUid(); |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 645 | name.assign(args[2].c_str(), args[2].size()); |
| 646 | good = true; |
| 647 | } else if (argCount == 4) { |
Bookatz | d238657 | 2018-12-14 15:53:14 -0800 | [diff] [blame] | 648 | good = getUidFromArgs(args, 2, uid); |
| 649 | if (!good) { |
| 650 | dprintf(err, "Invalid UID. Note that the config can only be set for " |
| 651 | "other UIDs on eng or userdebug builds.\n"); |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 652 | } |
Bookatz | d238657 | 2018-12-14 15:53:14 -0800 | [diff] [blame] | 653 | name.assign(args[3].c_str(), args[3].size()); |
yro | e5f8292 | 2018-01-22 18:37:27 -0800 | [diff] [blame] | 654 | } else if (argCount == 2 && args[1] == "remove") { |
| 655 | good = true; |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 656 | } |
| 657 | |
| 658 | if (!good) { |
| 659 | // If arg parsing failed, print the help text and return an error. |
| 660 | print_cmd_help(out); |
| 661 | return UNKNOWN_ERROR; |
| 662 | } |
| 663 | |
| 664 | if (args[1] == "update") { |
yro | 255f72e | 2018-02-26 15:15:17 -0800 | [diff] [blame] | 665 | char* endp; |
| 666 | int64_t configID = strtoll(name.c_str(), &endp, 10); |
| 667 | if (endp == name.c_str() || *endp != '\0') { |
Yao Chen | a80e5c0 | 2018-09-04 13:55:29 -0700 | [diff] [blame] | 668 | dprintf(err, "Error parsing config ID.\n"); |
yro | 255f72e | 2018-02-26 15:15:17 -0800 | [diff] [blame] | 669 | return UNKNOWN_ERROR; |
| 670 | } |
| 671 | |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 672 | // Read stream into buffer. |
| 673 | string buffer; |
Yao Chen | a80e5c0 | 2018-09-04 13:55:29 -0700 | [diff] [blame] | 674 | if (!android::base::ReadFdToString(in, &buffer)) { |
| 675 | dprintf(err, "Error reading stream for StatsConfig.\n"); |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 676 | return UNKNOWN_ERROR; |
| 677 | } |
| 678 | |
| 679 | // Parse buffer. |
| 680 | StatsdConfig config; |
| 681 | if (!config.ParseFromString(buffer)) { |
Yao Chen | a80e5c0 | 2018-09-04 13:55:29 -0700 | [diff] [blame] | 682 | dprintf(err, "Error parsing proto stream for StatsConfig.\n"); |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 683 | return UNKNOWN_ERROR; |
| 684 | } |
| 685 | |
| 686 | // Add / update the config. |
yro | 255f72e | 2018-02-26 15:15:17 -0800 | [diff] [blame] | 687 | mConfigManager->UpdateConfig(ConfigKey(uid, configID), config); |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 688 | } else { |
yro | 74fed97 | 2017-11-27 14:42:42 -0800 | [diff] [blame] | 689 | if (argCount == 2) { |
| 690 | cmd_remove_all_configs(out); |
| 691 | } else { |
| 692 | // Remove the config. |
Yangster-mac | 94e197c | 2018-01-02 16:03:03 -0800 | [diff] [blame] | 693 | mConfigManager->RemoveConfig(ConfigKey(uid, StrToInt64(name))); |
yro | 74fed97 | 2017-11-27 14:42:42 -0800 | [diff] [blame] | 694 | } |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 695 | } |
| 696 | |
| 697 | return NO_ERROR; |
| 698 | } |
David Chen | 0656b7a | 2017-09-13 15:53:39 -0700 | [diff] [blame] | 699 | } |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 700 | print_cmd_help(out); |
| 701 | return UNKNOWN_ERROR; |
| 702 | } |
| 703 | |
Bookatz | ff71cad | 2018-09-20 17:17:49 -0700 | [diff] [blame] | 704 | status_t StatsService::cmd_dump_report(int out, const Vector<String8>& args) { |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 705 | if (mProcessor != nullptr) { |
Chenjie Yu | b236c86 | 2017-11-28 22:20:44 -0800 | [diff] [blame] | 706 | int argCount = args.size(); |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 707 | bool good = false; |
Chenjie Yu | b236c86 | 2017-11-28 22:20:44 -0800 | [diff] [blame] | 708 | bool proto = false; |
Chenjie Yu | bd1a28f | 2018-07-17 14:55:19 -0700 | [diff] [blame] | 709 | bool includeCurrentBucket = false; |
Bookatz | 3e90658 | 2018-12-10 17:26:58 -0800 | [diff] [blame] | 710 | bool eraseData = true; |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 711 | int uid; |
| 712 | string name; |
Chenjie Yu | b236c86 | 2017-11-28 22:20:44 -0800 | [diff] [blame] | 713 | if (!std::strcmp("--proto", args[argCount-1].c_str())) { |
| 714 | proto = true; |
| 715 | argCount -= 1; |
| 716 | } |
Chenjie Yu | bd1a28f | 2018-07-17 14:55:19 -0700 | [diff] [blame] | 717 | if (!std::strcmp("--include_current_bucket", args[argCount-1].c_str())) { |
| 718 | includeCurrentBucket = true; |
| 719 | argCount -= 1; |
| 720 | } |
Bookatz | 3e90658 | 2018-12-10 17:26:58 -0800 | [diff] [blame] | 721 | if (!std::strcmp("--keep_data", args[argCount-1].c_str())) { |
| 722 | eraseData = false; |
| 723 | argCount -= 1; |
| 724 | } |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 725 | if (argCount == 2) { |
| 726 | // Automatically pick the UID |
| 727 | uid = IPCThreadState::self()->getCallingUid(); |
Yao Chen | 5154a379 | 2017-10-30 22:57:06 -0700 | [diff] [blame] | 728 | name.assign(args[1].c_str(), args[1].size()); |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 729 | good = true; |
| 730 | } else if (argCount == 3) { |
Bookatz | d238657 | 2018-12-14 15:53:14 -0800 | [diff] [blame] | 731 | good = getUidFromArgs(args, 1, uid); |
| 732 | if (!good) { |
| 733 | dprintf(out, "Invalid UID. Note that the metrics can only be dumped for " |
| 734 | "other UIDs on eng or userdebug builds.\n"); |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 735 | } |
Bookatz | d238657 | 2018-12-14 15:53:14 -0800 | [diff] [blame] | 736 | name.assign(args[2].c_str(), args[2].size()); |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 737 | } |
| 738 | if (good) { |
David Chen | 1d7b0cd | 2017-11-15 14:20:04 -0800 | [diff] [blame] | 739 | vector<uint8_t> data; |
David Chen | 926fc75 | 2018-02-23 13:31:43 -0800 | [diff] [blame] | 740 | mProcessor->onDumpReport(ConfigKey(uid, StrToInt64(name)), getElapsedRealtimeNs(), |
Olivier Gaillard | 6c75ecd | 2019-02-20 09:57:33 +0000 | [diff] [blame] | 741 | includeCurrentBucket, eraseData, ADB_DUMP, |
| 742 | NO_TIME_CONSTRAINTS, |
| 743 | &data); |
Chenjie Yu | b236c86 | 2017-11-28 22:20:44 -0800 | [diff] [blame] | 744 | if (proto) { |
| 745 | for (size_t i = 0; i < data.size(); i ++) { |
Yao Chen | a80e5c0 | 2018-09-04 13:55:29 -0700 | [diff] [blame] | 746 | dprintf(out, "%c", data[i]); |
Chenjie Yu | b236c86 | 2017-11-28 22:20:44 -0800 | [diff] [blame] | 747 | } |
| 748 | } else { |
Bookatz | ff71cad | 2018-09-20 17:17:49 -0700 | [diff] [blame] | 749 | dprintf(out, "Non-proto stats data dump not currently supported.\n"); |
Chenjie Yu | b236c86 | 2017-11-28 22:20:44 -0800 | [diff] [blame] | 750 | } |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 751 | return android::OK; |
| 752 | } else { |
| 753 | // If arg parsing failed, print the help text and return an error. |
| 754 | print_cmd_help(out); |
| 755 | return UNKNOWN_ERROR; |
| 756 | } |
| 757 | } else { |
Yao Chen | a80e5c0 | 2018-09-04 13:55:29 -0700 | [diff] [blame] | 758 | dprintf(out, "Log processor does not exist...\n"); |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 759 | return UNKNOWN_ERROR; |
| 760 | } |
| 761 | } |
| 762 | |
Yao Chen | a80e5c0 | 2018-09-04 13:55:29 -0700 | [diff] [blame] | 763 | status_t StatsService::cmd_print_stats(int out, const Vector<String8>& args) { |
Tej Singh | 41b3f9a | 2018-04-03 17:06:35 -0700 | [diff] [blame] | 764 | int argCount = args.size(); |
| 765 | bool proto = false; |
| 766 | if (!std::strcmp("--proto", args[argCount-1].c_str())) { |
| 767 | proto = true; |
| 768 | argCount -= 1; |
David Chen | 1d7b0cd | 2017-11-15 14:20:04 -0800 | [diff] [blame] | 769 | } |
Yao Chen | b356151 | 2017-11-21 18:07:17 -0800 | [diff] [blame] | 770 | StatsdStats& statsdStats = StatsdStats::getInstance(); |
Tej Singh | 41b3f9a | 2018-04-03 17:06:35 -0700 | [diff] [blame] | 771 | if (proto) { |
| 772 | vector<uint8_t> data; |
| 773 | statsdStats.dumpStats(&data, false); // does not reset statsdStats. |
| 774 | for (size_t i = 0; i < data.size(); i ++) { |
Yao Chen | a80e5c0 | 2018-09-04 13:55:29 -0700 | [diff] [blame] | 775 | dprintf(out, "%c", data[i]); |
Tej Singh | 41b3f9a | 2018-04-03 17:06:35 -0700 | [diff] [blame] | 776 | } |
| 777 | |
| 778 | } else { |
| 779 | vector<ConfigKey> configs = mConfigManager->GetAllConfigKeys(); |
| 780 | for (const ConfigKey& key : configs) { |
Yao Chen | a80e5c0 | 2018-09-04 13:55:29 -0700 | [diff] [blame] | 781 | dprintf(out, "Config %s uses %zu bytes\n", key.ToString().c_str(), |
Tej Singh | 41b3f9a | 2018-04-03 17:06:35 -0700 | [diff] [blame] | 782 | mProcessor->GetMetricsSize(key)); |
| 783 | } |
| 784 | statsdStats.dumpStats(out); |
| 785 | } |
David Chen | 1d7b0cd | 2017-11-15 14:20:04 -0800 | [diff] [blame] | 786 | return NO_ERROR; |
| 787 | } |
| 788 | |
Yao Chen | a80e5c0 | 2018-09-04 13:55:29 -0700 | [diff] [blame] | 789 | status_t StatsService::cmd_print_uid_map(int out, const Vector<String8>& args) { |
Yao Chen | d10f7b1 | 2017-12-18 12:53:50 -0800 | [diff] [blame] | 790 | if (args.size() > 1) { |
| 791 | string pkg; |
| 792 | pkg.assign(args[1].c_str(), args[1].size()); |
| 793 | auto uids = mUidMap->getAppUid(pkg); |
Yao Chen | a80e5c0 | 2018-09-04 13:55:29 -0700 | [diff] [blame] | 794 | dprintf(out, "%s -> [ ", pkg.c_str()); |
Yao Chen | d10f7b1 | 2017-12-18 12:53:50 -0800 | [diff] [blame] | 795 | for (const auto& uid : uids) { |
Yao Chen | a80e5c0 | 2018-09-04 13:55:29 -0700 | [diff] [blame] | 796 | dprintf(out, "%d ", uid); |
Yao Chen | d10f7b1 | 2017-12-18 12:53:50 -0800 | [diff] [blame] | 797 | } |
Yao Chen | a80e5c0 | 2018-09-04 13:55:29 -0700 | [diff] [blame] | 798 | dprintf(out, "]\n"); |
Yao Chen | d10f7b1 | 2017-12-18 12:53:50 -0800 | [diff] [blame] | 799 | } else { |
| 800 | mUidMap->printUidMap(out); |
| 801 | } |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 802 | return NO_ERROR; |
David Chen | 0656b7a | 2017-09-13 15:53:39 -0700 | [diff] [blame] | 803 | } |
| 804 | |
Yao Chen | a80e5c0 | 2018-09-04 13:55:29 -0700 | [diff] [blame] | 805 | status_t StatsService::cmd_write_data_to_disk(int out) { |
| 806 | dprintf(out, "Writing data to disk\n"); |
Olivier Gaillard | 6c75ecd | 2019-02-20 09:57:33 +0000 | [diff] [blame] | 807 | mProcessor->WriteDataToDisk(ADB_DUMP, NO_TIME_CONSTRAINTS); |
yro | 947fbce | 2017-11-15 22:50:23 -0800 | [diff] [blame] | 808 | return NO_ERROR; |
| 809 | } |
| 810 | |
Yao Chen | a80e5c0 | 2018-09-04 13:55:29 -0700 | [diff] [blame] | 811 | status_t StatsService::cmd_log_app_breadcrumb(int out, const Vector<String8>& args) { |
Bookatz | b223c4e | 2018-02-01 15:35:04 -0800 | [diff] [blame] | 812 | bool good = false; |
| 813 | int32_t uid; |
| 814 | int32_t label; |
| 815 | int32_t state; |
| 816 | const int argCount = args.size(); |
| 817 | if (argCount == 3) { |
| 818 | // Automatically pick the UID |
| 819 | uid = IPCThreadState::self()->getCallingUid(); |
| 820 | label = atoi(args[1].c_str()); |
| 821 | state = atoi(args[2].c_str()); |
| 822 | good = true; |
| 823 | } else if (argCount == 4) { |
Bookatz | d238657 | 2018-12-14 15:53:14 -0800 | [diff] [blame] | 824 | good = getUidFromArgs(args, 1, uid); |
| 825 | if (!good) { |
Yao Chen | a80e5c0 | 2018-09-04 13:55:29 -0700 | [diff] [blame] | 826 | dprintf(out, |
Bookatz | d238657 | 2018-12-14 15:53:14 -0800 | [diff] [blame] | 827 | "Invalid UID. Note that selecting a UID for writing AppBreadcrumb can only be " |
| 828 | "done for other UIDs on eng or userdebug builds.\n"); |
Bookatz | b223c4e | 2018-02-01 15:35:04 -0800 | [diff] [blame] | 829 | } |
Bookatz | d238657 | 2018-12-14 15:53:14 -0800 | [diff] [blame] | 830 | label = atoi(args[2].c_str()); |
| 831 | state = atoi(args[3].c_str()); |
Bookatz | b223c4e | 2018-02-01 15:35:04 -0800 | [diff] [blame] | 832 | } |
| 833 | if (good) { |
Yao Chen | a80e5c0 | 2018-09-04 13:55:29 -0700 | [diff] [blame] | 834 | dprintf(out, "Logging AppBreadcrumbReported(%d, %d, %d) to statslog.\n", uid, label, state); |
David Chen | 0b5c90c | 2018-01-25 16:51:49 -0800 | [diff] [blame] | 835 | android::util::stats_write(android::util::APP_BREADCRUMB_REPORTED, uid, label, state); |
Bookatz | b223c4e | 2018-02-01 15:35:04 -0800 | [diff] [blame] | 836 | } else { |
| 837 | print_cmd_help(out); |
| 838 | return UNKNOWN_ERROR; |
| 839 | } |
| 840 | return NO_ERROR; |
| 841 | } |
| 842 | |
Tej Singh | 53f9dee | 2019-04-30 17:45:54 -0700 | [diff] [blame] | 843 | status_t StatsService::cmd_log_binary_push(int out, const Vector<String8>& args) { |
| 844 | // Security checks are done in the sendBinaryPushStateChanged atom. |
| 845 | const int argCount = args.size(); |
| 846 | if (argCount != 7 && argCount != 8) { |
| 847 | dprintf(out, "Incorrect number of argument supplied\n"); |
| 848 | return UNKNOWN_ERROR; |
| 849 | } |
| 850 | android::String16 trainName = android::String16(args[1].c_str()); |
| 851 | int64_t trainVersion = strtoll(args[2].c_str(), nullptr, 10); |
| 852 | int options = 0; |
| 853 | if (args[3] == "1") { |
| 854 | options = options | IStatsManager::FLAG_REQUIRE_STAGING; |
| 855 | } |
| 856 | if (args[4] == "1") { |
| 857 | options = options | IStatsManager::FLAG_ROLLBACK_ENABLED; |
| 858 | } |
| 859 | if (args[5] == "1") { |
| 860 | options = options | IStatsManager::FLAG_REQUIRE_LOW_LATENCY_MONITOR; |
| 861 | } |
| 862 | int32_t state = atoi(args[6].c_str()); |
| 863 | vector<int64_t> experimentIds; |
| 864 | if (argCount == 8) { |
| 865 | vector<string> experimentIdsString = android::base::Split(string(args[7].c_str()), ","); |
| 866 | for (string experimentIdString : experimentIdsString) { |
| 867 | int64_t experimentId = strtoll(experimentIdString.c_str(), nullptr, 10); |
| 868 | experimentIds.push_back(experimentId); |
| 869 | } |
| 870 | } |
| 871 | dprintf(out, "Logging BinaryPushStateChanged\n"); |
| 872 | sendBinaryPushStateChangedAtom(trainName, trainVersion, options, state, experimentIds); |
| 873 | return NO_ERROR; |
| 874 | } |
| 875 | |
Yao Chen | a80e5c0 | 2018-09-04 13:55:29 -0700 | [diff] [blame] | 876 | status_t StatsService::cmd_print_pulled_metrics(int out, const Vector<String8>& args) { |
David Chen | 1481fe1 | 2017-10-16 13:16:34 -0700 | [diff] [blame] | 877 | int s = atoi(args[1].c_str()); |
Chenjie Yu | 5305e1d | 2017-10-31 13:49:36 -0700 | [diff] [blame] | 878 | vector<shared_ptr<LogEvent> > stats; |
Chenjie Yu | 0bd73db | 2018-12-16 07:37:04 -0800 | [diff] [blame] | 879 | if (mPullerManager->Pull(s, &stats)) { |
Chenjie Yu | 5305e1d | 2017-10-31 13:49:36 -0700 | [diff] [blame] | 880 | for (const auto& it : stats) { |
Yao Chen | a80e5c0 | 2018-09-04 13:55:29 -0700 | [diff] [blame] | 881 | dprintf(out, "Pull from %d: %s\n", s, it->ToString().c_str()); |
Chenjie Yu | 5305e1d | 2017-10-31 13:49:36 -0700 | [diff] [blame] | 882 | } |
Yao Chen | a80e5c0 | 2018-09-04 13:55:29 -0700 | [diff] [blame] | 883 | dprintf(out, "Pull from %d: Received %zu elements\n", s, stats.size()); |
Chenjie Yu | 5305e1d | 2017-10-31 13:49:36 -0700 | [diff] [blame] | 884 | return NO_ERROR; |
David Chen | 1481fe1 | 2017-10-16 13:16:34 -0700 | [diff] [blame] | 885 | } |
Chenjie Yu | 5305e1d | 2017-10-31 13:49:36 -0700 | [diff] [blame] | 886 | return UNKNOWN_ERROR; |
David Chen | 1481fe1 | 2017-10-16 13:16:34 -0700 | [diff] [blame] | 887 | } |
| 888 | |
Yao Chen | a80e5c0 | 2018-09-04 13:55:29 -0700 | [diff] [blame] | 889 | status_t StatsService::cmd_remove_all_configs(int out) { |
| 890 | dprintf(out, "Removing all configs...\n"); |
yro | 74fed97 | 2017-11-27 14:42:42 -0800 | [diff] [blame] | 891 | VLOG("StatsService::cmd_remove_all_configs was called"); |
| 892 | mConfigManager->RemoveAllConfigs(); |
yro | 947fbce | 2017-11-15 22:50:23 -0800 | [diff] [blame] | 893 | StorageManager::deleteAllFiles(STATS_SERVICE_DIR); |
yro | 87d983c | 2017-11-14 21:31:43 -0800 | [diff] [blame] | 894 | return NO_ERROR; |
| 895 | } |
| 896 | |
Yao Chen | a80e5c0 | 2018-09-04 13:55:29 -0700 | [diff] [blame] | 897 | status_t StatsService::cmd_dump_memory_info(int out) { |
| 898 | dprintf(out, "meminfo not available.\n"); |
Yao Chen | 8d9989b | 2017-11-18 18:54:50 -0800 | [diff] [blame] | 899 | return NO_ERROR; |
| 900 | } |
| 901 | |
Yao Chen | a80e5c0 | 2018-09-04 13:55:29 -0700 | [diff] [blame] | 902 | status_t StatsService::cmd_clear_puller_cache(int out) { |
Chenjie Yu | fa22d65 | 2018-02-05 14:37:48 -0800 | [diff] [blame] | 903 | IPCThreadState* ipc = IPCThreadState::self(); |
Yangster-mac | 932ecec | 2018-02-01 10:23:52 -0800 | [diff] [blame] | 904 | VLOG("StatsService::cmd_clear_puller_cache with Pid %i, Uid %i", |
| 905 | ipc->getCallingPid(), ipc->getCallingUid()); |
Chenjie Yu | fa22d65 | 2018-02-05 14:37:48 -0800 | [diff] [blame] | 906 | if (checkCallingPermission(String16(kPermissionDump))) { |
Chenjie Yu | e221920 | 2018-06-08 10:07:51 -0700 | [diff] [blame] | 907 | int cleared = mPullerManager->ForceClearPullerCache(); |
Yao Chen | a80e5c0 | 2018-09-04 13:55:29 -0700 | [diff] [blame] | 908 | dprintf(out, "Puller removed %d cached data!\n", cleared); |
Chenjie Yu | fa22d65 | 2018-02-05 14:37:48 -0800 | [diff] [blame] | 909 | return NO_ERROR; |
| 910 | } else { |
| 911 | return PERMISSION_DENIED; |
| 912 | } |
Chenjie Yu | e72252b | 2018-02-01 13:19:35 -0800 | [diff] [blame] | 913 | } |
| 914 | |
Yao Chen | a80e5c0 | 2018-09-04 13:55:29 -0700 | [diff] [blame] | 915 | status_t StatsService::cmd_print_logs(int out, const Vector<String8>& args) { |
Yao Chen | 876889c | 2018-05-02 11:16:16 -0700 | [diff] [blame] | 916 | IPCThreadState* ipc = IPCThreadState::self(); |
| 917 | VLOG("StatsService::cmd_print_logs with Pid %i, Uid %i", ipc->getCallingPid(), |
| 918 | ipc->getCallingUid()); |
| 919 | if (checkCallingPermission(String16(kPermissionDump))) { |
| 920 | bool enabled = true; |
| 921 | if (args.size() >= 2) { |
| 922 | enabled = atoi(args[1].c_str()) != 0; |
| 923 | } |
| 924 | mProcessor->setPrintLogs(enabled); |
| 925 | return NO_ERROR; |
| 926 | } else { |
| 927 | return PERMISSION_DENIED; |
| 928 | } |
| 929 | } |
| 930 | |
Bookatz | d238657 | 2018-12-14 15:53:14 -0800 | [diff] [blame] | 931 | bool StatsService::getUidFromArgs(const Vector<String8>& args, size_t uidArgIndex, int32_t& uid) { |
Tej Singh | 6ede28b | 2019-01-29 17:06:54 -0800 | [diff] [blame] | 932 | return getUidFromString(args[uidArgIndex].c_str(), uid); |
| 933 | } |
| 934 | |
| 935 | bool StatsService::getUidFromString(const char* s, int32_t& uid) { |
Bookatz | d238657 | 2018-12-14 15:53:14 -0800 | [diff] [blame] | 936 | if (*s == '\0') { |
| 937 | return false; |
| 938 | } |
| 939 | char* endc = NULL; |
| 940 | int64_t longUid = strtol(s, &endc, 0); |
| 941 | if (*endc != '\0') { |
| 942 | return false; |
| 943 | } |
| 944 | int32_t goodUid = static_cast<int32_t>(longUid); |
| 945 | if (longUid < 0 || static_cast<uint64_t>(longUid) != static_cast<uid_t>(goodUid)) { |
| 946 | return false; // It was not of uid_t type. |
| 947 | } |
| 948 | uid = goodUid; |
| 949 | |
| 950 | int32_t callingUid = IPCThreadState::self()->getCallingUid(); |
| 951 | return mEngBuild // UserDebug/EngBuild are allowed to impersonate uids. |
| 952 | || (callingUid == goodUid) // Anyone can 'impersonate' themselves. |
| 953 | || (callingUid == AID_ROOT && goodUid == AID_SHELL); // ROOT can impersonate SHELL. |
| 954 | } |
| 955 | |
Dianne Hackborn | 3accca0 | 2013-09-20 09:32:11 -0700 | [diff] [blame] | 956 | Status StatsService::informAllUidData(const vector<int32_t>& uid, const vector<int64_t>& version, |
dwchen | 730403e | 2018-10-29 11:41:56 -0700 | [diff] [blame] | 957 | const vector<String16>& version_string, |
| 958 | const vector<String16>& app, |
| 959 | const vector<String16>& installer) { |
Jeff Sharkey | 6b64925 | 2018-04-16 09:50:22 -0600 | [diff] [blame] | 960 | ENFORCE_UID(AID_SYSTEM); |
| 961 | |
yro | 74fed97 | 2017-11-27 14:42:42 -0800 | [diff] [blame] | 962 | VLOG("StatsService::informAllUidData was called"); |
dwchen | 730403e | 2018-10-29 11:41:56 -0700 | [diff] [blame] | 963 | mUidMap->updateMap(getElapsedRealtimeNs(), uid, version, version_string, app, installer); |
yro | 74fed97 | 2017-11-27 14:42:42 -0800 | [diff] [blame] | 964 | VLOG("StatsService::informAllUidData succeeded"); |
David Chen | de70169 | 2017-10-05 13:16:02 -0700 | [diff] [blame] | 965 | |
| 966 | return Status::ok(); |
| 967 | } |
| 968 | |
dwchen | 730403e | 2018-10-29 11:41:56 -0700 | [diff] [blame] | 969 | Status StatsService::informOnePackage(const String16& app, int32_t uid, int64_t version, |
| 970 | const String16& version_string, const String16& installer) { |
Jeff Sharkey | 6b64925 | 2018-04-16 09:50:22 -0600 | [diff] [blame] | 971 | ENFORCE_UID(AID_SYSTEM); |
David Chen | de70169 | 2017-10-05 13:16:02 -0700 | [diff] [blame] | 972 | |
Jeff Sharkey | 6b64925 | 2018-04-16 09:50:22 -0600 | [diff] [blame] | 973 | VLOG("StatsService::informOnePackage was called"); |
dwchen | 730403e | 2018-10-29 11:41:56 -0700 | [diff] [blame] | 974 | mUidMap->updateApp(getElapsedRealtimeNs(), app, uid, version, version_string, installer); |
David Chen | de70169 | 2017-10-05 13:16:02 -0700 | [diff] [blame] | 975 | return Status::ok(); |
| 976 | } |
| 977 | |
| 978 | Status StatsService::informOnePackageRemoved(const String16& app, int32_t uid) { |
Jeff Sharkey | 6b64925 | 2018-04-16 09:50:22 -0600 | [diff] [blame] | 979 | ENFORCE_UID(AID_SYSTEM); |
David Chen | de70169 | 2017-10-05 13:16:02 -0700 | [diff] [blame] | 980 | |
Jeff Sharkey | 6b64925 | 2018-04-16 09:50:22 -0600 | [diff] [blame] | 981 | VLOG("StatsService::informOnePackageRemoved was called"); |
David Chen | bd12527 | 2018-04-04 19:02:50 -0700 | [diff] [blame] | 982 | mUidMap->removeApp(getElapsedRealtimeNs(), app, uid); |
yro | 0192402 | 2018-02-20 18:20:49 -0800 | [diff] [blame] | 983 | mConfigManager->RemoveConfigs(uid); |
David Chen | de70169 | 2017-10-05 13:16:02 -0700 | [diff] [blame] | 984 | return Status::ok(); |
| 985 | } |
| 986 | |
Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame] | 987 | Status StatsService::informAnomalyAlarmFired() { |
Jeff Sharkey | 6b64925 | 2018-04-16 09:50:22 -0600 | [diff] [blame] | 988 | ENFORCE_UID(AID_SYSTEM); |
| 989 | |
yro | 74fed97 | 2017-11-27 14:42:42 -0800 | [diff] [blame] | 990 | VLOG("StatsService::informAnomalyAlarmFired was called"); |
Yangster-mac | b142cc8 | 2018-03-30 15:22:08 -0700 | [diff] [blame] | 991 | int64_t currentTimeSec = getElapsedRealtimeSec(); |
Yangster-mac | 932ecec | 2018-02-01 10:23:52 -0800 | [diff] [blame] | 992 | std::unordered_set<sp<const InternalAlarm>, SpHash<InternalAlarm>> alarmSet = |
| 993 | mAnomalyAlarmMonitor->popSoonerThan(static_cast<uint32_t>(currentTimeSec)); |
| 994 | if (alarmSet.size() > 0) { |
Bookatz | 66fe061 | 2018-02-07 18:51:48 -0800 | [diff] [blame] | 995 | VLOG("Found an anomaly alarm that fired."); |
Yangster-mac | 932ecec | 2018-02-01 10:23:52 -0800 | [diff] [blame] | 996 | mProcessor->onAnomalyAlarmFired(currentTimeSec * NS_PER_SEC, alarmSet); |
Bookatz | 66fe061 | 2018-02-07 18:51:48 -0800 | [diff] [blame] | 997 | } else { |
| 998 | VLOG("Cannot find an anomaly alarm that fired. Perhaps it was recently cancelled."); |
| 999 | } |
Bookatz | 1b0b114 | 2017-09-08 11:58:42 -0700 | [diff] [blame] | 1000 | return Status::ok(); |
| 1001 | } |
| 1002 | |
Yangster-mac | 932ecec | 2018-02-01 10:23:52 -0800 | [diff] [blame] | 1003 | Status StatsService::informAlarmForSubscriberTriggeringFired() { |
Jeff Sharkey | 6b64925 | 2018-04-16 09:50:22 -0600 | [diff] [blame] | 1004 | ENFORCE_UID(AID_SYSTEM); |
| 1005 | |
Yangster-mac | 932ecec | 2018-02-01 10:23:52 -0800 | [diff] [blame] | 1006 | VLOG("StatsService::informAlarmForSubscriberTriggeringFired was called"); |
Yangster-mac | b142cc8 | 2018-03-30 15:22:08 -0700 | [diff] [blame] | 1007 | int64_t currentTimeSec = getElapsedRealtimeSec(); |
Yangster-mac | 932ecec | 2018-02-01 10:23:52 -0800 | [diff] [blame] | 1008 | std::unordered_set<sp<const InternalAlarm>, SpHash<InternalAlarm>> alarmSet = |
| 1009 | mPeriodicAlarmMonitor->popSoonerThan(static_cast<uint32_t>(currentTimeSec)); |
| 1010 | if (alarmSet.size() > 0) { |
| 1011 | VLOG("Found periodic alarm fired."); |
| 1012 | mProcessor->onPeriodicAlarmFired(currentTimeSec * NS_PER_SEC, alarmSet); |
| 1013 | } else { |
| 1014 | ALOGW("Cannot find an periodic alarm that fired. Perhaps it was recently cancelled."); |
| 1015 | } |
| 1016 | return Status::ok(); |
| 1017 | } |
| 1018 | |
Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame] | 1019 | Status StatsService::informPollAlarmFired() { |
Jeff Sharkey | 6b64925 | 2018-04-16 09:50:22 -0600 | [diff] [blame] | 1020 | ENFORCE_UID(AID_SYSTEM); |
| 1021 | |
yro | 74fed97 | 2017-11-27 14:42:42 -0800 | [diff] [blame] | 1022 | VLOG("StatsService::informPollAlarmFired was called"); |
Yangster-mac | 15f6bbc | 2018-04-08 11:52:26 -0700 | [diff] [blame] | 1023 | mProcessor->informPullAlarmFired(getElapsedRealtimeNs()); |
yro | 74fed97 | 2017-11-27 14:42:42 -0800 | [diff] [blame] | 1024 | VLOG("StatsService::informPollAlarmFired succeeded"); |
Bookatz | 1b0b114 | 2017-09-08 11:58:42 -0700 | [diff] [blame] | 1025 | return Status::ok(); |
| 1026 | } |
| 1027 | |
Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame] | 1028 | Status StatsService::systemRunning() { |
Jeff Sharkey | 6b64925 | 2018-04-16 09:50:22 -0600 | [diff] [blame] | 1029 | ENFORCE_UID(AID_SYSTEM); |
Joe Onorato | 5dcbc6c | 2017-08-29 15:13:58 -0700 | [diff] [blame] | 1030 | |
| 1031 | // When system_server is up and running, schedule the dropbox task to run. |
yro | 74fed97 | 2017-11-27 14:42:42 -0800 | [diff] [blame] | 1032 | VLOG("StatsService::systemRunning"); |
Bookatz | b487b55 | 2017-09-18 11:26:01 -0700 | [diff] [blame] | 1033 | sayHiToStatsCompanion(); |
Joe Onorato | 5dcbc6c | 2017-08-29 15:13:58 -0700 | [diff] [blame] | 1034 | return Status::ok(); |
| 1035 | } |
| 1036 | |
Yangster-mac | 892f3d3 | 2018-05-02 14:16:48 -0700 | [diff] [blame] | 1037 | Status StatsService::informDeviceShutdown() { |
Jeff Sharkey | 6b64925 | 2018-04-16 09:50:22 -0600 | [diff] [blame] | 1038 | ENFORCE_UID(AID_SYSTEM); |
Chenjie Yu | e36018b | 2018-04-16 15:18:30 -0700 | [diff] [blame] | 1039 | VLOG("StatsService::informDeviceShutdown"); |
Olivier Gaillard | 6c75ecd | 2019-02-20 09:57:33 +0000 | [diff] [blame] | 1040 | mProcessor->WriteDataToDisk(DEVICE_SHUTDOWN, FAST); |
Muhammad Qureshi | 844694b | 2019-04-05 10:10:40 -0700 | [diff] [blame] | 1041 | mProcessor->SaveActiveConfigsToDisk(getElapsedRealtimeNs()); |
yro | 947fbce | 2017-11-15 22:50:23 -0800 | [diff] [blame] | 1042 | return Status::ok(); |
| 1043 | } |
| 1044 | |
Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame] | 1045 | void StatsService::sayHiToStatsCompanion() { |
Bookatz | b487b55 | 2017-09-18 11:26:01 -0700 | [diff] [blame] | 1046 | sp<IStatsCompanionService> statsCompanion = getStatsCompanionService(); |
| 1047 | if (statsCompanion != nullptr) { |
yro | 74fed97 | 2017-11-27 14:42:42 -0800 | [diff] [blame] | 1048 | VLOG("Telling statsCompanion that statsd is ready"); |
Bookatz | b487b55 | 2017-09-18 11:26:01 -0700 | [diff] [blame] | 1049 | statsCompanion->statsdReady(); |
| 1050 | } else { |
yro | 74fed97 | 2017-11-27 14:42:42 -0800 | [diff] [blame] | 1051 | VLOG("Could not access statsCompanion"); |
Bookatz | b487b55 | 2017-09-18 11:26:01 -0700 | [diff] [blame] | 1052 | } |
| 1053 | } |
| 1054 | |
Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame] | 1055 | Status StatsService::statsCompanionReady() { |
Jeff Sharkey | 6b64925 | 2018-04-16 09:50:22 -0600 | [diff] [blame] | 1056 | ENFORCE_UID(AID_SYSTEM); |
| 1057 | |
yro | 74fed97 | 2017-11-27 14:42:42 -0800 | [diff] [blame] | 1058 | VLOG("StatsService::statsCompanionReady was called"); |
Bookatz | b487b55 | 2017-09-18 11:26:01 -0700 | [diff] [blame] | 1059 | sp<IStatsCompanionService> statsCompanion = getStatsCompanionService(); |
| 1060 | if (statsCompanion == nullptr) { |
Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame] | 1061 | return Status::fromExceptionCode( |
| 1062 | Status::EX_NULL_POINTER, |
| 1063 | "statscompanion unavailable despite it contacting statsd!"); |
Bookatz | b487b55 | 2017-09-18 11:26:01 -0700 | [diff] [blame] | 1064 | } |
yro | 74fed97 | 2017-11-27 14:42:42 -0800 | [diff] [blame] | 1065 | VLOG("StatsService::statsCompanionReady linking to statsCompanion."); |
Chenjie Yu | aa5b201 | 2018-03-21 13:53:15 -0700 | [diff] [blame] | 1066 | IInterface::asBinder(statsCompanion)->linkToDeath(this); |
Chenjie Yu | e221920 | 2018-06-08 10:07:51 -0700 | [diff] [blame] | 1067 | mPullerManager->SetStatsCompanionService(statsCompanion); |
Yangster-mac | 932ecec | 2018-02-01 10:23:52 -0800 | [diff] [blame] | 1068 | mAnomalyAlarmMonitor->setStatsCompanionService(statsCompanion); |
| 1069 | mPeriodicAlarmMonitor->setStatsCompanionService(statsCompanion); |
Bookatz | c697797 | 2018-01-16 16:55:05 -0800 | [diff] [blame] | 1070 | SubscriberReporter::getInstance().setStatsCompanionService(statsCompanion); |
Bookatz | b487b55 | 2017-09-18 11:26:01 -0700 | [diff] [blame] | 1071 | return Status::ok(); |
| 1072 | } |
| 1073 | |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 1074 | void StatsService::Startup() { |
| 1075 | mConfigManager->Startup(); |
Muhammad Qureshi | 844694b | 2019-04-05 10:10:40 -0700 | [diff] [blame] | 1076 | mProcessor->LoadActiveConfigsFromDisk(); |
Bookatz | 906a35c | 2017-09-20 15:26:44 -0700 | [diff] [blame] | 1077 | } |
| 1078 | |
Yangster-mac | 97e7d20 | 2018-10-09 11:05:39 -0700 | [diff] [blame] | 1079 | void StatsService::Terminate() { |
| 1080 | ALOGI("StatsService::Terminating"); |
| 1081 | if (mProcessor != nullptr) { |
Olivier Gaillard | 6c75ecd | 2019-02-20 09:57:33 +0000 | [diff] [blame] | 1082 | mProcessor->WriteDataToDisk(TERMINATION_SIGNAL_RECEIVED, FAST); |
Muhammad Qureshi | 844694b | 2019-04-05 10:10:40 -0700 | [diff] [blame] | 1083 | mProcessor->SaveActiveConfigsToDisk(getElapsedRealtimeNs()); |
Yangster-mac | 97e7d20 | 2018-10-09 11:05:39 -0700 | [diff] [blame] | 1084 | } |
| 1085 | } |
| 1086 | |
Yao Chen | 0f86186 | 2019-03-27 11:51:15 -0700 | [diff] [blame] | 1087 | // Test only interface!!! |
Yao Chen | 3ff3a49 | 2018-08-06 16:17:37 -0700 | [diff] [blame] | 1088 | void StatsService::OnLogEvent(LogEvent* event) { |
| 1089 | mProcessor->OnLogEvent(event); |
Yao Chen | a80e5c0 | 2018-09-04 13:55:29 -0700 | [diff] [blame] | 1090 | if (mShellSubscriber != nullptr) { |
| 1091 | mShellSubscriber->onLogEvent(*event); |
| 1092 | } |
Bookatz | 906a35c | 2017-09-20 15:26:44 -0700 | [diff] [blame] | 1093 | } |
| 1094 | |
Jeff Sharkey | 6b64925 | 2018-04-16 09:50:22 -0600 | [diff] [blame] | 1095 | Status StatsService::getData(int64_t key, const String16& packageName, vector<uint8_t>* output) { |
| 1096 | ENFORCE_DUMP_AND_USAGE_STATS(packageName); |
| 1097 | |
David Chen | adaf8b3 | 2017-11-03 15:42:08 -0700 | [diff] [blame] | 1098 | IPCThreadState* ipc = IPCThreadState::self(); |
yro | 74fed97 | 2017-11-27 14:42:42 -0800 | [diff] [blame] | 1099 | VLOG("StatsService::getData with Pid %i, Uid %i", ipc->getCallingPid(), ipc->getCallingUid()); |
Bookatz | 4f71629 | 2018-04-10 17:15:12 -0700 | [diff] [blame] | 1100 | ConfigKey configKey(ipc->getCallingUid(), key); |
Olivier Gaillard | 6c75ecd | 2019-02-20 09:57:33 +0000 | [diff] [blame] | 1101 | // The dump latency does not matter here since we do not include the current bucket, we do not |
| 1102 | // need to pull any new data anyhow. |
David Chen | 56ae0d9 | 2018-05-11 16:00:22 -0700 | [diff] [blame] | 1103 | mProcessor->onDumpReport(configKey, getElapsedRealtimeNs(), false /* include_current_bucket*/, |
Olivier Gaillard | 6c75ecd | 2019-02-20 09:57:33 +0000 | [diff] [blame] | 1104 | true /* erase_data */, GET_DATA_CALLED, FAST, output); |
Bookatz | 4f71629 | 2018-04-10 17:15:12 -0700 | [diff] [blame] | 1105 | return Status::ok(); |
yro | 31eb67b | 2017-10-24 13:33:21 -0700 | [diff] [blame] | 1106 | } |
| 1107 | |
Jeff Sharkey | 6b64925 | 2018-04-16 09:50:22 -0600 | [diff] [blame] | 1108 | Status StatsService::getMetadata(const String16& packageName, vector<uint8_t>* output) { |
| 1109 | ENFORCE_DUMP_AND_USAGE_STATS(packageName); |
| 1110 | |
David Chen | 2e8f380 | 2017-11-22 10:56:48 -0800 | [diff] [blame] | 1111 | IPCThreadState* ipc = IPCThreadState::self(); |
| 1112 | VLOG("StatsService::getMetadata with Pid %i, Uid %i", ipc->getCallingPid(), |
| 1113 | ipc->getCallingUid()); |
Bookatz | 4f71629 | 2018-04-10 17:15:12 -0700 | [diff] [blame] | 1114 | StatsdStats::getInstance().dumpStats(output, false); // Don't reset the counters. |
| 1115 | return Status::ok(); |
David Chen | 2e8f380 | 2017-11-22 10:56:48 -0800 | [diff] [blame] | 1116 | } |
| 1117 | |
Jeff Sharkey | 6b64925 | 2018-04-16 09:50:22 -0600 | [diff] [blame] | 1118 | Status StatsService::addConfiguration(int64_t key, const vector <uint8_t>& config, |
| 1119 | const String16& packageName) { |
| 1120 | ENFORCE_DUMP_AND_USAGE_STATS(packageName); |
| 1121 | |
David Chen | adaf8b3 | 2017-11-03 15:42:08 -0700 | [diff] [blame] | 1122 | IPCThreadState* ipc = IPCThreadState::self(); |
Bookatz | 4f71629 | 2018-04-10 17:15:12 -0700 | [diff] [blame] | 1123 | if (addConfigurationChecked(ipc->getCallingUid(), key, config)) { |
David Chen | 661f791 | 2018-01-22 17:46:24 -0800 | [diff] [blame] | 1124 | return Status::ok(); |
| 1125 | } else { |
Bookatz | 4f71629 | 2018-04-10 17:15:12 -0700 | [diff] [blame] | 1126 | ALOGE("Could not parse malformatted StatsdConfig"); |
| 1127 | return Status::fromExceptionCode(binder::Status::EX_ILLEGAL_ARGUMENT, |
| 1128 | "config does not correspond to a StatsdConfig proto"); |
David Chen | 661f791 | 2018-01-22 17:46:24 -0800 | [diff] [blame] | 1129 | } |
| 1130 | } |
| 1131 | |
David Chen | 9fdd403 | 2018-03-20 14:38:56 -0700 | [diff] [blame] | 1132 | bool StatsService::addConfigurationChecked(int uid, int64_t key, const vector<uint8_t>& config) { |
| 1133 | ConfigKey configKey(uid, key); |
| 1134 | StatsdConfig cfg; |
| 1135 | if (config.size() > 0) { // If the config is empty, skip parsing. |
| 1136 | if (!cfg.ParseFromArray(&config[0], config.size())) { |
| 1137 | return false; |
| 1138 | } |
| 1139 | } |
| 1140 | mConfigManager->UpdateConfig(configKey, cfg); |
| 1141 | return true; |
| 1142 | } |
| 1143 | |
Jeff Sharkey | 6b64925 | 2018-04-16 09:50:22 -0600 | [diff] [blame] | 1144 | Status StatsService::removeDataFetchOperation(int64_t key, const String16& packageName) { |
| 1145 | ENFORCE_DUMP_AND_USAGE_STATS(packageName); |
| 1146 | |
Bookatz | 4f71629 | 2018-04-10 17:15:12 -0700 | [diff] [blame] | 1147 | IPCThreadState* ipc = IPCThreadState::self(); |
| 1148 | ConfigKey configKey(ipc->getCallingUid(), key); |
| 1149 | mConfigManager->RemoveConfigReceiver(configKey); |
| 1150 | return Status::ok(); |
David Chen | 661f791 | 2018-01-22 17:46:24 -0800 | [diff] [blame] | 1151 | } |
| 1152 | |
Jeff Sharkey | 6b64925 | 2018-04-16 09:50:22 -0600 | [diff] [blame] | 1153 | Status StatsService::setDataFetchOperation(int64_t key, |
| 1154 | const sp<android::IBinder>& intentSender, |
| 1155 | const String16& packageName) { |
| 1156 | ENFORCE_DUMP_AND_USAGE_STATS(packageName); |
| 1157 | |
Bookatz | 4f71629 | 2018-04-10 17:15:12 -0700 | [diff] [blame] | 1158 | IPCThreadState* ipc = IPCThreadState::self(); |
| 1159 | ConfigKey configKey(ipc->getCallingUid(), key); |
| 1160 | mConfigManager->SetConfigReceiver(configKey, intentSender); |
David Chen | 4894490 | 2018-05-03 10:29:11 -0700 | [diff] [blame] | 1161 | if (StorageManager::hasConfigMetricsReport(configKey)) { |
| 1162 | VLOG("StatsService::setDataFetchOperation marking configKey %s to dump reports on disk", |
| 1163 | configKey.ToString().c_str()); |
| 1164 | mProcessor->noteOnDiskData(configKey); |
| 1165 | } |
Bookatz | 4f71629 | 2018-04-10 17:15:12 -0700 | [diff] [blame] | 1166 | return Status::ok(); |
yro | 31eb67b | 2017-10-24 13:33:21 -0700 | [diff] [blame] | 1167 | } |
| 1168 | |
Tej Singh | 2c9ef2a | 2019-01-22 11:33:51 -0800 | [diff] [blame] | 1169 | Status StatsService::setActiveConfigsChangedOperation(const sp<android::IBinder>& intentSender, |
| 1170 | const String16& packageName, |
| 1171 | vector<int64_t>* output) { |
| 1172 | ENFORCE_DUMP_AND_USAGE_STATS(packageName); |
| 1173 | |
| 1174 | IPCThreadState* ipc = IPCThreadState::self(); |
Tej Singh | 6ede28b | 2019-01-29 17:06:54 -0800 | [diff] [blame] | 1175 | int uid = ipc->getCallingUid(); |
| 1176 | mConfigManager->SetActiveConfigsChangedReceiver(uid, intentSender); |
| 1177 | if (output != nullptr) { |
| 1178 | mProcessor->GetActiveConfigs(uid, *output); |
| 1179 | } else { |
| 1180 | ALOGW("StatsService::setActiveConfigsChanged output was nullptr"); |
| 1181 | } |
Tej Singh | 2c9ef2a | 2019-01-22 11:33:51 -0800 | [diff] [blame] | 1182 | return Status::ok(); |
| 1183 | } |
| 1184 | |
| 1185 | Status StatsService::removeActiveConfigsChangedOperation(const String16& packageName) { |
| 1186 | ENFORCE_DUMP_AND_USAGE_STATS(packageName); |
| 1187 | |
| 1188 | IPCThreadState* ipc = IPCThreadState::self(); |
| 1189 | mConfigManager->RemoveActiveConfigsChangedReceiver(ipc->getCallingUid()); |
| 1190 | return Status::ok(); |
| 1191 | } |
| 1192 | |
Jeff Sharkey | 6b64925 | 2018-04-16 09:50:22 -0600 | [diff] [blame] | 1193 | Status StatsService::removeConfiguration(int64_t key, const String16& packageName) { |
| 1194 | ENFORCE_DUMP_AND_USAGE_STATS(packageName); |
| 1195 | |
Bookatz | 4f71629 | 2018-04-10 17:15:12 -0700 | [diff] [blame] | 1196 | IPCThreadState* ipc = IPCThreadState::self(); |
| 1197 | ConfigKey configKey(ipc->getCallingUid(), key); |
| 1198 | mConfigManager->RemoveConfig(configKey); |
| 1199 | SubscriberReporter::getInstance().removeConfig(configKey); |
| 1200 | return Status::ok(); |
yro | 31eb67b | 2017-10-24 13:33:21 -0700 | [diff] [blame] | 1201 | } |
| 1202 | |
Bookatz | c697797 | 2018-01-16 16:55:05 -0800 | [diff] [blame] | 1203 | Status StatsService::setBroadcastSubscriber(int64_t configId, |
| 1204 | int64_t subscriberId, |
Jeff Sharkey | 6b64925 | 2018-04-16 09:50:22 -0600 | [diff] [blame] | 1205 | const sp<android::IBinder>& intentSender, |
| 1206 | const String16& packageName) { |
| 1207 | ENFORCE_DUMP_AND_USAGE_STATS(packageName); |
| 1208 | |
Bookatz | c697797 | 2018-01-16 16:55:05 -0800 | [diff] [blame] | 1209 | VLOG("StatsService::setBroadcastSubscriber called."); |
Bookatz | 4f71629 | 2018-04-10 17:15:12 -0700 | [diff] [blame] | 1210 | IPCThreadState* ipc = IPCThreadState::self(); |
| 1211 | ConfigKey configKey(ipc->getCallingUid(), configId); |
| 1212 | SubscriberReporter::getInstance() |
| 1213 | .setBroadcastSubscriber(configKey, subscriberId, intentSender); |
| 1214 | return Status::ok(); |
Bookatz | c697797 | 2018-01-16 16:55:05 -0800 | [diff] [blame] | 1215 | } |
| 1216 | |
| 1217 | Status StatsService::unsetBroadcastSubscriber(int64_t configId, |
Jeff Sharkey | 6b64925 | 2018-04-16 09:50:22 -0600 | [diff] [blame] | 1218 | int64_t subscriberId, |
| 1219 | const String16& packageName) { |
| 1220 | ENFORCE_DUMP_AND_USAGE_STATS(packageName); |
| 1221 | |
Bookatz | c697797 | 2018-01-16 16:55:05 -0800 | [diff] [blame] | 1222 | VLOG("StatsService::unsetBroadcastSubscriber called."); |
Bookatz | 4f71629 | 2018-04-10 17:15:12 -0700 | [diff] [blame] | 1223 | IPCThreadState* ipc = IPCThreadState::self(); |
| 1224 | ConfigKey configKey(ipc->getCallingUid(), configId); |
| 1225 | SubscriberReporter::getInstance() |
| 1226 | .unsetBroadcastSubscriber(configKey, subscriberId); |
| 1227 | return Status::ok(); |
Bookatz | c697797 | 2018-01-16 16:55:05 -0800 | [diff] [blame] | 1228 | } |
| 1229 | |
yro | be6d7f9 | 2018-05-04 13:02:53 -0700 | [diff] [blame] | 1230 | Status StatsService::sendAppBreadcrumbAtom(int32_t label, int32_t state) { |
| 1231 | // Permission check not necessary as it's meant for applications to write to |
| 1232 | // statsd. |
| 1233 | android::util::stats_write(util::APP_BREADCRUMB_REPORTED, |
| 1234 | IPCThreadState::self()->getCallingUid(), label, |
| 1235 | state); |
| 1236 | return Status::ok(); |
| 1237 | } |
| 1238 | |
Tej Singh | a0c89dd | 2019-01-25 16:39:18 -0800 | [diff] [blame] | 1239 | Status StatsService::registerPullerCallback(int32_t atomTag, |
| 1240 | const sp<android::os::IStatsPullerCallback>& pullerCallback, |
| 1241 | const String16& packageName) { |
| 1242 | ENFORCE_DUMP_AND_USAGE_STATS(packageName); |
| 1243 | |
| 1244 | VLOG("StatsService::registerPullerCallback called."); |
| 1245 | mPullerManager->RegisterPullerCallback(atomTag, pullerCallback); |
| 1246 | return Status::ok(); |
| 1247 | } |
| 1248 | |
| 1249 | Status StatsService::unregisterPullerCallback(int32_t atomTag, const String16& packageName) { |
| 1250 | ENFORCE_DUMP_AND_USAGE_STATS(packageName); |
| 1251 | |
| 1252 | VLOG("StatsService::unregisterPullerCallback called."); |
| 1253 | mPullerManager->UnregisterPullerCallback(atomTag); |
| 1254 | return Status::ok(); |
| 1255 | } |
| 1256 | |
Tej Singh | 9b4a5ec | 2019-04-25 12:43:35 -0700 | [diff] [blame] | 1257 | Status StatsService::sendBinaryPushStateChangedAtom(const android::String16& trainNameIn, |
| 1258 | const int64_t trainVersionCodeIn, |
| 1259 | const int options, |
| 1260 | const int32_t state, |
Jeff Hamilton | fa2f91c | 2019-03-22 00:25:02 -0400 | [diff] [blame] | 1261 | const std::vector<int64_t>& experimentIdsIn) { |
Tej Singh | 53f9dee | 2019-04-30 17:45:54 -0700 | [diff] [blame] | 1262 | // Note: We skip the usage stats op check here since we do not have a package name. |
| 1263 | // This is ok since we are overloading the usage_stats permission. |
| 1264 | // This method only sends data, it does not receive it. |
| 1265 | pid_t pid = IPCThreadState::self()->getCallingPid(); |
Chenjie Yu | 6b1667c | 2019-01-18 10:09:33 -0800 | [diff] [blame] | 1266 | uid_t uid = IPCThreadState::self()->getCallingUid(); |
Tej Singh | 53f9dee | 2019-04-30 17:45:54 -0700 | [diff] [blame] | 1267 | // Root, system, and shell always have access |
| 1268 | if (uid != AID_ROOT && uid != AID_SYSTEM && uid != AID_SHELL) { |
| 1269 | // Caller must be granted these permissions |
| 1270 | if (!checkCallingPermission(String16(kPermissionDump))) { |
| 1271 | return exception(binder::Status::EX_SECURITY, |
| 1272 | StringPrintf("UID %d / PID %d lacks permission %s", uid, pid, |
| 1273 | kPermissionDump)); |
| 1274 | } |
| 1275 | if (!checkCallingPermission(String16(kPermissionUsage))) { |
| 1276 | return exception(binder::Status::EX_SECURITY, |
| 1277 | StringPrintf("UID %d / PID %d lacks permission %s", uid, pid, |
| 1278 | kPermissionUsage)); |
| 1279 | } |
Chenjie Yu | 6b1667c | 2019-01-18 10:09:33 -0800 | [diff] [blame] | 1280 | } |
| 1281 | |
Jonathan Nguyen | bbe311c | 2019-03-14 20:44:52 -0700 | [diff] [blame] | 1282 | bool readTrainInfoSuccess = false; |
Tej Singh | 9b4a5ec | 2019-04-25 12:43:35 -0700 | [diff] [blame] | 1283 | InstallTrainInfo trainInfoOnDisk; |
| 1284 | readTrainInfoSuccess = StorageManager::readTrainInfo(trainInfoOnDisk); |
Chenjie Yu | 6b1667c | 2019-01-18 10:09:33 -0800 | [diff] [blame] | 1285 | |
Tej Singh | 9b4a5ec | 2019-04-25 12:43:35 -0700 | [diff] [blame] | 1286 | bool resetExperimentIds = false; |
| 1287 | int64_t trainVersionCode = trainVersionCodeIn; |
| 1288 | std::string trainNameUtf8 = std::string(String8(trainNameIn).string()); |
| 1289 | if (readTrainInfoSuccess) { |
| 1290 | // Keep the old train version if we received an empty version. |
| 1291 | if (trainVersionCodeIn == -1) { |
| 1292 | trainVersionCode = trainInfoOnDisk.trainVersionCode; |
| 1293 | } else if (trainVersionCodeIn != trainInfoOnDisk.trainVersionCode) { |
| 1294 | // Reset experiment ids if we receive a new non-empty train version. |
| 1295 | resetExperimentIds = true; |
| 1296 | } |
| 1297 | |
| 1298 | // Keep the old train name if we received an empty train name. |
| 1299 | if (trainNameUtf8.size() == 0) { |
| 1300 | trainNameUtf8 = trainInfoOnDisk.trainName; |
| 1301 | } else if (trainNameUtf8 != trainInfoOnDisk.trainName) { |
| 1302 | // Reset experiment ids if we received a new valid train name. |
| 1303 | resetExperimentIds = true; |
| 1304 | } |
| 1305 | |
| 1306 | // Reset if we received a different experiment id. |
| 1307 | if (!experimentIdsIn.empty() && |
| 1308 | (trainInfoOnDisk.experimentIds.empty() || |
| 1309 | experimentIdsIn[0] != trainInfoOnDisk.experimentIds[0])) { |
| 1310 | resetExperimentIds = true; |
| 1311 | } |
Chenjie Yu | 6b1667c | 2019-01-18 10:09:33 -0800 | [diff] [blame] | 1312 | } |
Chenjie Yu | 6b1667c | 2019-01-18 10:09:33 -0800 | [diff] [blame] | 1313 | |
Jeff Hamilton | fa2f91c | 2019-03-22 00:25:02 -0400 | [diff] [blame] | 1314 | // Find the right experiment IDs |
| 1315 | std::vector<int64_t> experimentIds; |
Tej Singh | 9b4a5ec | 2019-04-25 12:43:35 -0700 | [diff] [blame] | 1316 | if (resetExperimentIds || !readTrainInfoSuccess) { |
Jeff Hamilton | fa2f91c | 2019-03-22 00:25:02 -0400 | [diff] [blame] | 1317 | experimentIds = experimentIdsIn; |
Tej Singh | 9b4a5ec | 2019-04-25 12:43:35 -0700 | [diff] [blame] | 1318 | } else { |
| 1319 | experimentIds = trainInfoOnDisk.experimentIds; |
| 1320 | } |
| 1321 | |
| 1322 | if (!experimentIds.empty()) { |
| 1323 | int64_t firstId = experimentIds[0]; |
| 1324 | switch (state) { |
| 1325 | case android::util::BINARY_PUSH_STATE_CHANGED__STATE__INSTALL_SUCCESS: |
| 1326 | experimentIds.push_back(firstId + 1); |
| 1327 | break; |
| 1328 | case android::util::BINARY_PUSH_STATE_CHANGED__STATE__INSTALLER_ROLLBACK_INITIATED: |
| 1329 | experimentIds.push_back(firstId + 2); |
| 1330 | break; |
| 1331 | case android::util::BINARY_PUSH_STATE_CHANGED__STATE__INSTALLER_ROLLBACK_SUCCESS: |
| 1332 | experimentIds.push_back(firstId + 3); |
| 1333 | break; |
| 1334 | } |
Chenjie Yu | 6b1667c | 2019-01-18 10:09:33 -0800 | [diff] [blame] | 1335 | } |
Muhammad Qureshi | f4ca824 | 2019-03-01 09:20:15 -0800 | [diff] [blame] | 1336 | |
Jeff Hamilton | fa2f91c | 2019-03-22 00:25:02 -0400 | [diff] [blame] | 1337 | // Flatten the experiment IDs to proto |
| 1338 | vector<uint8_t> experimentIdsProtoBuffer; |
| 1339 | writeExperimentIdsToProto(experimentIds, &experimentIdsProtoBuffer); |
Tej Singh | 9b4a5ec | 2019-04-25 12:43:35 -0700 | [diff] [blame] | 1340 | StorageManager::writeTrainInfo(trainVersionCode, trainNameUtf8, state, experimentIds); |
Jonathan Nguyen | bbe311c | 2019-03-14 20:44:52 -0700 | [diff] [blame] | 1341 | |
| 1342 | userid_t userId = multiuser_get_user_id(uid); |
| 1343 | bool requiresStaging = options & IStatsManager::FLAG_REQUIRE_STAGING; |
| 1344 | bool rollbackEnabled = options & IStatsManager::FLAG_ROLLBACK_ENABLED; |
| 1345 | bool requiresLowLatencyMonitor = options & IStatsManager::FLAG_REQUIRE_LOW_LATENCY_MONITOR; |
Muhammad Qureshi | f4ca824 | 2019-03-01 09:20:15 -0800 | [diff] [blame] | 1346 | LogEvent event(trainNameUtf8, trainVersionCode, requiresStaging, rollbackEnabled, |
| 1347 | requiresLowLatencyMonitor, state, experimentIdsProtoBuffer, userId); |
Chenjie Yu | 6b1667c | 2019-01-18 10:09:33 -0800 | [diff] [blame] | 1348 | mProcessor->OnLogEvent(&event); |
Jeff Hamilton | fa2f91c | 2019-03-22 00:25:02 -0400 | [diff] [blame] | 1349 | return Status::ok(); |
| 1350 | } |
| 1351 | |
| 1352 | Status StatsService::getRegisteredExperimentIds(std::vector<int64_t>* experimentIdsOut) { |
| 1353 | uid_t uid = IPCThreadState::self()->getCallingUid(); |
| 1354 | |
| 1355 | // Caller must be granted these permissions |
| 1356 | if (!checkCallingPermission(String16(kPermissionDump))) { |
| 1357 | return exception(binder::Status::EX_SECURITY, |
| 1358 | StringPrintf("UID %d lacks permission %s", uid, kPermissionDump)); |
| 1359 | } |
| 1360 | if (!checkCallingPermission(String16(kPermissionUsage))) { |
| 1361 | return exception(binder::Status::EX_SECURITY, |
| 1362 | StringPrintf("UID %d lacks permission %s", uid, kPermissionUsage)); |
| 1363 | } |
| 1364 | // TODO: add verifier permission |
| 1365 | |
| 1366 | // Read the latest train info |
| 1367 | InstallTrainInfo trainInfo; |
| 1368 | if (!StorageManager::readTrainInfo(trainInfo)) { |
| 1369 | // No train info means no experiment IDs, return an empty list |
| 1370 | experimentIdsOut->clear(); |
| 1371 | return Status::ok(); |
| 1372 | } |
| 1373 | |
| 1374 | // Copy the experiment IDs to the out vector |
| 1375 | experimentIdsOut->assign(trainInfo.experimentIds.begin(), trainInfo.experimentIds.end()); |
Chenjie Yu | 6b1667c | 2019-01-18 10:09:33 -0800 | [diff] [blame] | 1376 | return Status::ok(); |
| 1377 | } |
| 1378 | |
Howard Ro | a46b658 | 2018-09-18 16:45:02 -0700 | [diff] [blame] | 1379 | hardware::Return<void> StatsService::reportSpeakerImpedance( |
| 1380 | const SpeakerImpedance& speakerImpedance) { |
Tej Singh | 8928ed7 | 2019-02-22 19:06:22 -0800 | [diff] [blame] | 1381 | android::util::stats_write(android::util::SPEAKER_IMPEDANCE_REPORTED, |
| 1382 | speakerImpedance.speakerLocation, speakerImpedance.milliOhms); |
Howard Ro | a46b658 | 2018-09-18 16:45:02 -0700 | [diff] [blame] | 1383 | |
| 1384 | return hardware::Void(); |
| 1385 | } |
| 1386 | |
| 1387 | hardware::Return<void> StatsService::reportHardwareFailed(const HardwareFailed& hardwareFailed) { |
Tej Singh | 8928ed7 | 2019-02-22 19:06:22 -0800 | [diff] [blame] | 1388 | android::util::stats_write(android::util::HARDWARE_FAILED, int32_t(hardwareFailed.hardwareType), |
| 1389 | hardwareFailed.hardwareLocation, int32_t(hardwareFailed.errorCode)); |
Howard Ro | a46b658 | 2018-09-18 16:45:02 -0700 | [diff] [blame] | 1390 | |
| 1391 | return hardware::Void(); |
| 1392 | } |
| 1393 | |
| 1394 | hardware::Return<void> StatsService::reportPhysicalDropDetected( |
| 1395 | const PhysicalDropDetected& physicalDropDetected) { |
Tej Singh | 8928ed7 | 2019-02-22 19:06:22 -0800 | [diff] [blame] | 1396 | android::util::stats_write(android::util::PHYSICAL_DROP_DETECTED, |
| 1397 | int32_t(physicalDropDetected.confidencePctg), physicalDropDetected.accelPeak, |
| 1398 | physicalDropDetected.freefallDuration); |
Howard Ro | a46b658 | 2018-09-18 16:45:02 -0700 | [diff] [blame] | 1399 | |
| 1400 | return hardware::Void(); |
| 1401 | } |
| 1402 | |
| 1403 | hardware::Return<void> StatsService::reportChargeCycles(const ChargeCycles& chargeCycles) { |
Tej Singh | 8928ed7 | 2019-02-22 19:06:22 -0800 | [diff] [blame] | 1404 | std::vector<int32_t> buckets = chargeCycles.cycleBucket; |
| 1405 | int initialSize = buckets.size(); |
| 1406 | for (int i = 0; i < 10 - initialSize; i++) { |
| 1407 | buckets.push_back(-1); // Push -1 for buckets that do not exist. |
| 1408 | } |
| 1409 | android::util::stats_write(android::util::CHARGE_CYCLES_REPORTED, buckets[0], buckets[1], |
| 1410 | buckets[2], buckets[3], buckets[4], buckets[5], buckets[6], buckets[7], buckets[8], |
| 1411 | buckets[9]); |
Howard Ro | a46b658 | 2018-09-18 16:45:02 -0700 | [diff] [blame] | 1412 | |
| 1413 | return hardware::Void(); |
| 1414 | } |
| 1415 | |
| 1416 | hardware::Return<void> StatsService::reportBatteryHealthSnapshot( |
| 1417 | const BatteryHealthSnapshotArgs& batteryHealthSnapshotArgs) { |
Tej Singh | 8928ed7 | 2019-02-22 19:06:22 -0800 | [diff] [blame] | 1418 | android::util::stats_write(android::util::BATTERY_HEALTH_SNAPSHOT, |
| 1419 | int32_t(batteryHealthSnapshotArgs.type), batteryHealthSnapshotArgs.temperatureDeciC, |
| 1420 | batteryHealthSnapshotArgs.voltageMicroV, batteryHealthSnapshotArgs.currentMicroA, |
| 1421 | batteryHealthSnapshotArgs.openCircuitVoltageMicroV, |
| 1422 | batteryHealthSnapshotArgs.resistanceMicroOhm, batteryHealthSnapshotArgs.levelPercent); |
Howard Ro | a46b658 | 2018-09-18 16:45:02 -0700 | [diff] [blame] | 1423 | |
| 1424 | return hardware::Void(); |
| 1425 | } |
| 1426 | |
| 1427 | hardware::Return<void> StatsService::reportSlowIo(const SlowIo& slowIo) { |
Tej Singh | 8928ed7 | 2019-02-22 19:06:22 -0800 | [diff] [blame] | 1428 | android::util::stats_write(android::util::SLOW_IO, int32_t(slowIo.operation), slowIo.count); |
Howard Ro | a46b658 | 2018-09-18 16:45:02 -0700 | [diff] [blame] | 1429 | |
| 1430 | return hardware::Void(); |
| 1431 | } |
| 1432 | |
| 1433 | hardware::Return<void> StatsService::reportBatteryCausedShutdown( |
| 1434 | const BatteryCausedShutdown& batteryCausedShutdown) { |
Tej Singh | 8928ed7 | 2019-02-22 19:06:22 -0800 | [diff] [blame] | 1435 | android::util::stats_write(android::util::BATTERY_CAUSED_SHUTDOWN, |
| 1436 | batteryCausedShutdown.voltageMicroV); |
Howard Ro | a46b658 | 2018-09-18 16:45:02 -0700 | [diff] [blame] | 1437 | |
| 1438 | return hardware::Void(); |
| 1439 | } |
| 1440 | |
Maggie White | fc1aa59 | 2018-11-28 21:55:23 -0800 | [diff] [blame] | 1441 | hardware::Return<void> StatsService::reportUsbPortOverheatEvent( |
| 1442 | const UsbPortOverheatEvent& usbPortOverheatEvent) { |
Tej Singh | 8928ed7 | 2019-02-22 19:06:22 -0800 | [diff] [blame] | 1443 | android::util::stats_write(android::util::USB_PORT_OVERHEAT_EVENT_REPORTED, |
| 1444 | usbPortOverheatEvent.plugTemperatureDeciC, usbPortOverheatEvent.maxTemperatureDeciC, |
| 1445 | usbPortOverheatEvent.timeToOverheat, usbPortOverheatEvent.timeToHysteresis, |
| 1446 | usbPortOverheatEvent.timeToInactive); |
Maggie White | fc1aa59 | 2018-11-28 21:55:23 -0800 | [diff] [blame] | 1447 | |
| 1448 | return hardware::Void(); |
| 1449 | } |
| 1450 | |
Carter Hsu | b8fd1e9 | 2019-01-11 15:24:45 +0800 | [diff] [blame] | 1451 | hardware::Return<void> StatsService::reportSpeechDspStat( |
| 1452 | const SpeechDspStat& speechDspStat) { |
Tej Singh | 8928ed7 | 2019-02-22 19:06:22 -0800 | [diff] [blame] | 1453 | android::util::stats_write(android::util::SPEECH_DSP_STAT_REPORTED, |
| 1454 | speechDspStat.totalUptimeMillis, speechDspStat.totalDowntimeMillis, |
| 1455 | speechDspStat.totalCrashCount, speechDspStat.totalRecoverCount); |
Carter Hsu | b8fd1e9 | 2019-01-11 15:24:45 +0800 | [diff] [blame] | 1456 | |
| 1457 | return hardware::Void(); |
| 1458 | } |
| 1459 | |
Maggie White | 58174da | 2019-01-18 15:23:35 -0800 | [diff] [blame] | 1460 | hardware::Return<void> StatsService::reportVendorAtom(const VendorAtom& vendorAtom) { |
| 1461 | std::string reverseDomainName = (std::string) vendorAtom.reverseDomainName; |
| 1462 | if (vendorAtom.atomId < 100000 || vendorAtom.atomId >= 200000) { |
| 1463 | ALOGE("Atom ID %ld is not a valid vendor atom ID", (long) vendorAtom.atomId); |
| 1464 | return hardware::Void(); |
| 1465 | } |
| 1466 | if (reverseDomainName.length() > 50) { |
| 1467 | ALOGE("Vendor atom reverse domain name %s is too long.", reverseDomainName.c_str()); |
| 1468 | return hardware::Void(); |
| 1469 | } |
| 1470 | LogEvent event(getWallClockSec() * NS_PER_SEC, getElapsedRealtimeNs(), vendorAtom); |
| 1471 | mProcessor->OnLogEvent(&event); |
| 1472 | |
| 1473 | return hardware::Void(); |
| 1474 | } |
| 1475 | |
David Chen | 1d7b0cd | 2017-11-15 14:20:04 -0800 | [diff] [blame] | 1476 | void StatsService::binderDied(const wp <IBinder>& who) { |
Chenjie Yu | aa5b201 | 2018-03-21 13:53:15 -0700 | [diff] [blame] | 1477 | ALOGW("statscompanion service died"); |
Yangster-mac | 892f3d3 | 2018-05-02 14:16:48 -0700 | [diff] [blame] | 1478 | StatsdStats::getInstance().noteSystemServerRestart(getWallClockSec()); |
| 1479 | if (mProcessor != nullptr) { |
Howard Ro | e60992b | 2018-08-30 14:37:29 -0700 | [diff] [blame] | 1480 | ALOGW("Reset statsd upon system server restarts."); |
Tej Singh | f53d445 | 2019-05-09 18:17:59 -0700 | [diff] [blame^] | 1481 | int64_t systemServerRestartNs = getElapsedRealtimeNs(); |
| 1482 | ProtoOutputStream proto; |
| 1483 | mProcessor->WriteActiveConfigsToProtoOutputStream(systemServerRestartNs, |
| 1484 | STATSCOMPANION_DIED, &proto); |
| 1485 | |
Olivier Gaillard | 6c75ecd | 2019-02-20 09:57:33 +0000 | [diff] [blame] | 1486 | mProcessor->WriteDataToDisk(STATSCOMPANION_DIED, FAST); |
Yangster-mac | 892f3d3 | 2018-05-02 14:16:48 -0700 | [diff] [blame] | 1487 | mProcessor->resetConfigs(); |
Tej Singh | f53d445 | 2019-05-09 18:17:59 -0700 | [diff] [blame^] | 1488 | |
| 1489 | std::string serializedActiveConfigs; |
| 1490 | if (proto.serializeToString(&serializedActiveConfigs)) { |
| 1491 | ActiveConfigList activeConfigs; |
| 1492 | if (activeConfigs.ParseFromString(serializedActiveConfigs)) { |
| 1493 | mProcessor->SetConfigsActiveState(activeConfigs, systemServerRestartNs); |
| 1494 | } |
| 1495 | } |
Yangster-mac | 892f3d3 | 2018-05-02 14:16:48 -0700 | [diff] [blame] | 1496 | } |
Chenjie Yu | aa5b201 | 2018-03-21 13:53:15 -0700 | [diff] [blame] | 1497 | mAnomalyAlarmMonitor->setStatsCompanionService(nullptr); |
| 1498 | mPeriodicAlarmMonitor->setStatsCompanionService(nullptr); |
| 1499 | SubscriberReporter::getInstance().setStatsCompanionService(nullptr); |
Chenjie Yu | e221920 | 2018-06-08 10:07:51 -0700 | [diff] [blame] | 1500 | mPullerManager->SetStatsCompanionService(nullptr); |
yro | 31eb67b | 2017-10-24 13:33:21 -0700 | [diff] [blame] | 1501 | } |
| 1502 | |
Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame] | 1503 | } // namespace statsd |
| 1504 | } // namespace os |
| 1505 | } // namespace android |