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> |
Tej Singh | 53f9dee | 2019-04-30 17:45:54 -0700 | [diff] [blame] | 30 | #include <android-base/strings.h> |
Chenjie Yu | 6b1667c | 2019-01-18 10:09:33 -0800 | [diff] [blame] | 31 | #include <cutils/multiuser.h> |
David Chen | 0656b7a | 2017-09-13 15:53:39 -0700 | [diff] [blame] | 32 | #include <frameworks/base/cmds/statsd/src/statsd_config.pb.h> |
Max Dashouk | 11e0d40 | 2019-05-16 16:58:07 -0700 | [diff] [blame] | 33 | #include <frameworks/base/cmds/statsd/src/uid_data.pb.h> |
Joe Onorato | 5dcbc6c | 2017-08-29 15:13:58 -0700 | [diff] [blame] | 34 | #include <private/android_filesystem_config.h> |
Bookatz | b223c4e | 2018-02-01 15:35:04 -0800 | [diff] [blame] | 35 | #include <statslog.h> |
Joe Onorato | 5dcbc6c | 2017-08-29 15:13:58 -0700 | [diff] [blame] | 36 | #include <stdio.h> |
Yao Chen | 482d272 | 2017-09-12 13:25:43 -0700 | [diff] [blame] | 37 | #include <stdlib.h> |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 38 | #include <sys/system_properties.h> |
Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame] | 39 | #include <unistd.h> |
Yao Chen | a80e5c0 | 2018-09-04 13:55:29 -0700 | [diff] [blame] | 40 | #include <utils/String16.h> |
Joe Onorato | 5dcbc6c | 2017-08-29 15:13:58 -0700 | [diff] [blame] | 41 | |
| 42 | using namespace android; |
| 43 | |
Jeff Sharkey | 6b64925 | 2018-04-16 09:50:22 -0600 | [diff] [blame] | 44 | using android::base::StringPrintf; |
Bookatz | ff71cad | 2018-09-20 17:17:49 -0700 | [diff] [blame] | 45 | using android::util::FIELD_COUNT_REPEATED; |
| 46 | using android::util::FIELD_TYPE_MESSAGE; |
Jeff Sharkey | 6b64925 | 2018-04-16 09:50:22 -0600 | [diff] [blame] | 47 | |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 48 | using Status = ::ndk::ScopedAStatus; |
| 49 | |
Bookatz | 906a35c | 2017-09-20 15:26:44 -0700 | [diff] [blame] | 50 | namespace android { |
| 51 | namespace os { |
| 52 | namespace statsd { |
| 53 | |
David Chen | adaf8b3 | 2017-11-03 15:42:08 -0700 | [diff] [blame] | 54 | constexpr const char* kPermissionDump = "android.permission.DUMP"; |
Jeff Sharkey | 6b64925 | 2018-04-16 09:50:22 -0600 | [diff] [blame] | 55 | |
yro | 03faf09 | 2017-12-12 00:17:50 -0800 | [diff] [blame] | 56 | #define STATS_SERVICE_DIR "/data/misc/stats-service" |
David Chen | adaf8b3 | 2017-11-03 15:42:08 -0700 | [diff] [blame] | 57 | |
Bookatz | ff71cad | 2018-09-20 17:17:49 -0700 | [diff] [blame] | 58 | // for StatsDataDumpProto |
| 59 | const int FIELD_ID_REPORTS_LIST = 1; |
| 60 | |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 61 | static Status exception(int32_t code, const std::string& msg) { |
Jeff Sharkey | 6b64925 | 2018-04-16 09:50:22 -0600 | [diff] [blame] | 62 | ALOGE("%s (%d)", msg.c_str(), code); |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 63 | return ::ndk::ScopedAStatus(AStatus_fromExceptionCodeWithMessage(code, msg.c_str())); |
Jeff Sharkey | 6b64925 | 2018-04-16 09:50:22 -0600 | [diff] [blame] | 64 | } |
| 65 | |
Ruchir Rastogi | 0563e3b | 2020-01-28 17:43:13 -0800 | [diff] [blame] | 66 | static bool checkPermission(const char* permission) { |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 67 | pid_t pid = AIBinder_getCallingPid(); |
| 68 | uid_t uid = AIBinder_getCallingUid(); |
Jonathan Nguyen | a0e6de1 | 2020-01-28 18:33:55 -0800 | [diff] [blame] | 69 | return checkPermissionForIds(permission, pid, uid); |
Ruchir Rastogi | 0563e3b | 2020-01-28 17:43:13 -0800 | [diff] [blame] | 70 | } |
| 71 | |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 72 | Status checkUid(uid_t expectedUid) { |
| 73 | uid_t uid = AIBinder_getCallingUid(); |
Jeff Sharkey | 6b64925 | 2018-04-16 09:50:22 -0600 | [diff] [blame] | 74 | if (uid == expectedUid || uid == AID_ROOT) { |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 75 | return Status::ok(); |
Jeff Sharkey | 6b64925 | 2018-04-16 09:50:22 -0600 | [diff] [blame] | 76 | } else { |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 77 | return exception(EX_SECURITY, |
| 78 | StringPrintf("UID %d is not expected UID %d", uid, expectedUid)); |
Jeff Sharkey | 6b64925 | 2018-04-16 09:50:22 -0600 | [diff] [blame] | 79 | } |
| 80 | } |
| 81 | |
| 82 | #define ENFORCE_UID(uid) { \ |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 83 | Status status = checkUid((uid)); \ |
Jeff Sharkey | 6b64925 | 2018-04-16 09:50:22 -0600 | [diff] [blame] | 84 | if (!status.isOk()) { \ |
| 85 | return status; \ |
| 86 | } \ |
| 87 | } |
| 88 | |
Yao Chen | 0f86186 | 2019-03-27 11:51:15 -0700 | [diff] [blame] | 89 | StatsService::StatsService(const sp<Looper>& handlerLooper, shared_ptr<LogEventQueue> queue) |
| 90 | : mAnomalyAlarmMonitor(new AlarmMonitor( |
| 91 | MIN_DIFF_TO_UPDATE_REGISTERED_ALARM_SECS, |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 92 | [](const shared_ptr<IStatsCompanionService>& sc, int64_t timeMillis) { |
Yao Chen | 0f86186 | 2019-03-27 11:51:15 -0700 | [diff] [blame] | 93 | if (sc != nullptr) { |
| 94 | sc->setAnomalyAlarm(timeMillis); |
| 95 | StatsdStats::getInstance().noteRegisteredAnomalyAlarmChanged(); |
| 96 | } |
| 97 | }, |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 98 | [](const shared_ptr<IStatsCompanionService>& sc) { |
Yao Chen | 0f86186 | 2019-03-27 11:51:15 -0700 | [diff] [blame] | 99 | if (sc != nullptr) { |
| 100 | sc->cancelAnomalyAlarm(); |
| 101 | StatsdStats::getInstance().noteRegisteredAnomalyAlarmChanged(); |
| 102 | } |
| 103 | })), |
| 104 | mPeriodicAlarmMonitor(new AlarmMonitor( |
| 105 | MIN_DIFF_TO_UPDATE_REGISTERED_ALARM_SECS, |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 106 | [](const shared_ptr<IStatsCompanionService>& sc, int64_t timeMillis) { |
Yao Chen | 0f86186 | 2019-03-27 11:51:15 -0700 | [diff] [blame] | 107 | if (sc != nullptr) { |
| 108 | sc->setAlarmForSubscriberTriggering(timeMillis); |
| 109 | StatsdStats::getInstance().noteRegisteredPeriodicAlarmChanged(); |
| 110 | } |
| 111 | }, |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 112 | [](const shared_ptr<IStatsCompanionService>& sc) { |
Yao Chen | 0f86186 | 2019-03-27 11:51:15 -0700 | [diff] [blame] | 113 | if (sc != nullptr) { |
| 114 | sc->cancelAlarmForSubscriberTriggering(); |
| 115 | StatsdStats::getInstance().noteRegisteredPeriodicAlarmChanged(); |
| 116 | } |
| 117 | })), |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 118 | mEventQueue(queue), |
| 119 | mStatsCompanionServiceDeathRecipient(AIBinder_DeathRecipient_new( |
| 120 | StatsService::statsCompanionServiceDied)) { |
Yao Chen | 4ce0729 | 2019-02-13 13:06:36 -0800 | [diff] [blame] | 121 | mUidMap = UidMap::getInstance(); |
Chenjie Yu | e221920 | 2018-06-08 10:07:51 -0700 | [diff] [blame] | 122 | mPullerManager = new StatsPullerManager(); |
Chenjie Yu | 80f9112 | 2018-01-31 20:24:50 -0800 | [diff] [blame] | 123 | StatsPuller::SetUidMap(mUidMap); |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 124 | mConfigManager = new ConfigManager(); |
Chenjie Yu | e221920 | 2018-06-08 10:07:51 -0700 | [diff] [blame] | 125 | mProcessor = new StatsLogProcessor( |
| 126 | mUidMap, mPullerManager, mAnomalyAlarmMonitor, mPeriodicAlarmMonitor, |
Chenjie Yu | c7939cb | 2019-02-04 17:25:45 -0800 | [diff] [blame] | 127 | getElapsedRealtimeNs(), |
| 128 | [this](const ConfigKey& key) { |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 129 | shared_ptr<IPendingIntentRef> receiver = mConfigManager->GetConfigReceiver(key); |
Jeffrey Huang | ad21374 | 2019-12-16 13:50:06 -0800 | [diff] [blame] | 130 | if (receiver == nullptr) { |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 131 | VLOG("Could not find a broadcast receiver for %s", key.ToString().c_str()); |
Chenjie Yu | e221920 | 2018-06-08 10:07:51 -0700 | [diff] [blame] | 132 | return false; |
Jeffrey Huang | ad21374 | 2019-12-16 13:50:06 -0800 | [diff] [blame] | 133 | } else if (receiver->sendDataBroadcast( |
| 134 | mProcessor->getLastReportTimeNs(key)).isOk()) { |
Chenjie Yu | e221920 | 2018-06-08 10:07:51 -0700 | [diff] [blame] | 135 | return true; |
Jeffrey Huang | ad21374 | 2019-12-16 13:50:06 -0800 | [diff] [blame] | 136 | } else { |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 137 | VLOG("Failed to send a broadcast for receiver %s", key.ToString().c_str()); |
Jeffrey Huang | ad21374 | 2019-12-16 13:50:06 -0800 | [diff] [blame] | 138 | return false; |
Chenjie Yu | e221920 | 2018-06-08 10:07:51 -0700 | [diff] [blame] | 139 | } |
Tej Singh | 6ede28b | 2019-01-29 17:06:54 -0800 | [diff] [blame] | 140 | }, |
| 141 | [this](const int& uid, const vector<int64_t>& activeConfigs) { |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 142 | shared_ptr<IPendingIntentRef> receiver = |
Jeffrey Huang | 47537a1 | 2020-01-06 15:35:34 -0800 | [diff] [blame] | 143 | mConfigManager->GetActiveConfigsChangedReceiver(uid); |
| 144 | if (receiver == nullptr) { |
Tej Singh | 6ede28b | 2019-01-29 17:06:54 -0800 | [diff] [blame] | 145 | VLOG("Could not find receiver for uid %d", uid); |
| 146 | return false; |
Jeffrey Huang | 47537a1 | 2020-01-06 15:35:34 -0800 | [diff] [blame] | 147 | } else if (receiver->sendActiveConfigsChangedBroadcast(activeConfigs).isOk()) { |
Tej Singh | 6ede28b | 2019-01-29 17:06:54 -0800 | [diff] [blame] | 148 | VLOG("StatsService::active configs broadcast succeeded for uid %d" , uid); |
| 149 | return true; |
Jeffrey Huang | 47537a1 | 2020-01-06 15:35:34 -0800 | [diff] [blame] | 150 | } else { |
| 151 | VLOG("StatsService::active configs broadcast failed for uid %d" , uid); |
| 152 | return false; |
Tej Singh | 6ede28b | 2019-01-29 17:06:54 -0800 | [diff] [blame] | 153 | } |
Chenjie Yu | e221920 | 2018-06-08 10:07:51 -0700 | [diff] [blame] | 154 | }); |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 155 | |
Tej Singh | 9ec159a | 2019-11-14 11:59:48 -0800 | [diff] [blame] | 156 | mUidMap->setListener(mProcessor); |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 157 | mConfigManager->AddListener(mProcessor); |
| 158 | |
| 159 | init_system_properties(); |
Yao Chen | 0f86186 | 2019-03-27 11:51:15 -0700 | [diff] [blame] | 160 | |
| 161 | if (mEventQueue != nullptr) { |
| 162 | std::thread pushedEventThread([this] { readLogs(); }); |
| 163 | pushedEventThread.detach(); |
| 164 | } |
Joe Onorato | 5dcbc6c | 2017-08-29 15:13:58 -0700 | [diff] [blame] | 165 | } |
| 166 | |
Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame] | 167 | StatsService::~StatsService() { |
Joe Onorato | 5dcbc6c | 2017-08-29 15:13:58 -0700 | [diff] [blame] | 168 | } |
| 169 | |
Yao Chen | 0f86186 | 2019-03-27 11:51:15 -0700 | [diff] [blame] | 170 | /* Runs on a dedicated thread to process pushed events. */ |
| 171 | void StatsService::readLogs() { |
| 172 | // Read forever..... long live statsd |
| 173 | while (1) { |
| 174 | // Block until an event is available. |
| 175 | auto event = mEventQueue->waitPop(); |
| 176 | // Pass it to StatsLogProcess to all configs/metrics |
| 177 | // At this point, the LogEventQueue is not blocked, so that the socketListener |
| 178 | // can read events from the socket and write to buffer to avoid data drop. |
| 179 | mProcessor->OnLogEvent(event.get()); |
| 180 | // The ShellSubscriber is only used by shell for local debugging. |
| 181 | if (mShellSubscriber != nullptr) { |
| 182 | mShellSubscriber->onLogEvent(*event); |
| 183 | } |
| 184 | } |
| 185 | } |
| 186 | |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 187 | void StatsService::init_system_properties() { |
| 188 | mEngBuild = false; |
| 189 | const prop_info* buildType = __system_property_find("ro.build.type"); |
| 190 | if (buildType != NULL) { |
| 191 | __system_property_read_callback(buildType, init_build_type_callback, this); |
| 192 | } |
David Chen | 0656b7a | 2017-09-13 15:53:39 -0700 | [diff] [blame] | 193 | } |
| 194 | |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 195 | void StatsService::init_build_type_callback(void* cookie, const char* /*name*/, const char* value, |
| 196 | uint32_t serial) { |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 197 | if (0 == strcmp("eng", value) || 0 == strcmp("userdebug", value)) { |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 198 | reinterpret_cast<StatsService*>(cookie)->mEngBuild = true; |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | /** |
Bookatz | ff71cad | 2018-09-20 17:17:49 -0700 | [diff] [blame] | 203 | * Write data from statsd. |
| 204 | * Format for statsdStats: adb shell dumpsys stats --metadata [-v] [--proto] |
| 205 | * Format for data report: adb shell dumpsys stats [anything other than --metadata] [--proto] |
| 206 | * Anything ending in --proto will be in proto format. |
| 207 | * Anything without --metadata as the first argument will be report information. |
| 208 | * (bugreports call "adb shell dumpsys stats --dump-priority NORMAL -a --proto") |
| 209 | * 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] | 210 | */ |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 211 | status_t StatsService::dump(int fd, const char** args, uint32_t numArgs) { |
Ruchir Rastogi | 0563e3b | 2020-01-28 17:43:13 -0800 | [diff] [blame] | 212 | if (!checkPermission(kPermissionDump)) { |
Tej Singh | dd83d70 | 2018-04-10 17:24:50 -0700 | [diff] [blame] | 213 | return PERMISSION_DENIED; |
| 214 | } |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 215 | |
| 216 | int lastArg = numArgs - 1; |
Bookatz | ff71cad | 2018-09-20 17:17:49 -0700 | [diff] [blame] | 217 | bool asProto = false; |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 218 | if (lastArg >= 0 && string(args[lastArg]) == "--proto") { // last argument |
Bookatz | ff71cad | 2018-09-20 17:17:49 -0700 | [diff] [blame] | 219 | asProto = true; |
| 220 | lastArg--; |
Yao Chen | 884c8c1 | 2018-01-26 10:36:25 -0800 | [diff] [blame] | 221 | } |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 222 | if (numArgs > 0 && string(args[0]) == "--metadata") { // first argument |
Bookatz | ff71cad | 2018-09-20 17:17:49 -0700 | [diff] [blame] | 223 | // Request is to dump statsd stats. |
| 224 | bool verbose = false; |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 225 | if (lastArg >= 0 && string(args[lastArg]) == "-v") { |
Bookatz | ff71cad | 2018-09-20 17:17:49 -0700 | [diff] [blame] | 226 | verbose = true; |
| 227 | lastArg--; |
| 228 | } |
| 229 | dumpStatsdStats(fd, verbose, asProto); |
| 230 | } else { |
| 231 | // Request is to dump statsd report data. |
| 232 | if (asProto) { |
| 233 | dumpIncidentSection(fd); |
| 234 | } else { |
| 235 | dprintf(fd, "Non-proto format of stats data dump not available; see proto version.\n"); |
| 236 | } |
Tej Singh | 41b3f9a | 2018-04-03 17:06:35 -0700 | [diff] [blame] | 237 | } |
Yao Chen | 884c8c1 | 2018-01-26 10:36:25 -0800 | [diff] [blame] | 238 | |
Joe Onorato | 5dcbc6c | 2017-08-29 15:13:58 -0700 | [diff] [blame] | 239 | return NO_ERROR; |
| 240 | } |
| 241 | |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 242 | /** |
Tej Singh | 41b3f9a | 2018-04-03 17:06:35 -0700 | [diff] [blame] | 243 | * Write debugging data about statsd in text or proto format. |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 244 | */ |
Bookatz | ff71cad | 2018-09-20 17:17:49 -0700 | [diff] [blame] | 245 | void StatsService::dumpStatsdStats(int out, bool verbose, bool proto) { |
Tej Singh | 41b3f9a | 2018-04-03 17:06:35 -0700 | [diff] [blame] | 246 | if (proto) { |
| 247 | vector<uint8_t> data; |
| 248 | StatsdStats::getInstance().dumpStats(&data, false); // does not reset statsdStats. |
| 249 | for (size_t i = 0; i < data.size(); i ++) { |
Yao Chen | a80e5c0 | 2018-09-04 13:55:29 -0700 | [diff] [blame] | 250 | dprintf(out, "%c", data[i]); |
Tej Singh | 41b3f9a | 2018-04-03 17:06:35 -0700 | [diff] [blame] | 251 | } |
| 252 | } else { |
| 253 | StatsdStats::getInstance().dumpStats(out); |
| 254 | mProcessor->dumpStates(out, verbose); |
| 255 | } |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | /** |
Bookatz | ff71cad | 2018-09-20 17:17:49 -0700 | [diff] [blame] | 259 | * Write stats report data in StatsDataDumpProto incident section format. |
| 260 | */ |
| 261 | void StatsService::dumpIncidentSection(int out) { |
| 262 | ProtoOutputStream proto; |
| 263 | for (const ConfigKey& configKey : mConfigManager->GetAllConfigKeys()) { |
| 264 | uint64_t reportsListToken = |
| 265 | proto.start(FIELD_TYPE_MESSAGE | FIELD_COUNT_REPEATED | FIELD_ID_REPORTS_LIST); |
| 266 | mProcessor->onDumpReport(configKey, getElapsedRealtimeNs(), |
| 267 | true /* includeCurrentBucket */, false /* erase_data */, |
Olivier Gaillard | 6c75ecd | 2019-02-20 09:57:33 +0000 | [diff] [blame] | 268 | ADB_DUMP, |
| 269 | FAST, |
| 270 | &proto); |
Bookatz | ff71cad | 2018-09-20 17:17:49 -0700 | [diff] [blame] | 271 | proto.end(reportsListToken); |
| 272 | proto.flush(out); |
Bookatz | c71d901 | 2018-12-19 12:28:38 -0800 | [diff] [blame] | 273 | proto.clear(); |
Bookatz | ff71cad | 2018-09-20 17:17:49 -0700 | [diff] [blame] | 274 | } |
| 275 | } |
| 276 | |
| 277 | /** |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 278 | * Implementation of the adb shell cmd stats command. |
| 279 | */ |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 280 | status_t StatsService::handleShellCommand(int in, int out, int err, const char** argv, |
| 281 | uint32_t argc) { |
| 282 | uid_t uid = AIBinder_getCallingUid(); |
Stanislav Zholnin | d7674c2 | 2020-02-17 17:48:12 +0000 | [diff] [blame] | 283 | if (uid != AID_ROOT && uid != AID_SHELL) { |
Jeff Sharkey | 6b64925 | 2018-04-16 09:50:22 -0600 | [diff] [blame] | 284 | return PERMISSION_DENIED; |
| 285 | } |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 286 | |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 287 | Vector<String8> utf8Args; |
| 288 | utf8Args.setCapacity(argc); |
| 289 | for (uint32_t i = 0; i < argc; i++) { |
| 290 | utf8Args.push(String8(argv[i])); |
| 291 | } |
| 292 | |
| 293 | if (argc >= 1) { |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 294 | // adb shell cmd stats config ... |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 295 | if (!utf8Args[0].compare(String8("config"))) { |
| 296 | return cmd_config(in, out, err, utf8Args); |
David Chen | 0656b7a | 2017-09-13 15:53:39 -0700 | [diff] [blame] | 297 | } |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 298 | |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 299 | if (!utf8Args[0].compare(String8("print-uid-map"))) { |
| 300 | return cmd_print_uid_map(out, utf8Args); |
David Chen | de70169 | 2017-10-05 13:16:02 -0700 | [diff] [blame] | 301 | } |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 302 | |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 303 | if (!utf8Args[0].compare(String8("dump-report"))) { |
| 304 | return cmd_dump_report(out, utf8Args); |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 305 | } |
David Chen | 1481fe1 | 2017-10-16 13:16:34 -0700 | [diff] [blame] | 306 | |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 307 | if (!utf8Args[0].compare(String8("pull-source")) && argc > 1) { |
| 308 | return cmd_print_pulled_metrics(out, utf8Args); |
David Chen | 1481fe1 | 2017-10-16 13:16:34 -0700 | [diff] [blame] | 309 | } |
David Chen | adaf8b3 | 2017-11-03 15:42:08 -0700 | [diff] [blame] | 310 | |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 311 | if (!utf8Args[0].compare(String8("send-broadcast"))) { |
| 312 | return cmd_trigger_broadcast(out, utf8Args); |
David Chen | 1d7b0cd | 2017-11-15 14:20:04 -0800 | [diff] [blame] | 313 | } |
| 314 | |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 315 | if (!utf8Args[0].compare(String8("print-stats"))) { |
| 316 | return cmd_print_stats(out, utf8Args); |
David Chen | adaf8b3 | 2017-11-03 15:42:08 -0700 | [diff] [blame] | 317 | } |
yro | 87d983c | 2017-11-14 21:31:43 -0800 | [diff] [blame] | 318 | |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 319 | if (!utf8Args[0].compare(String8("meminfo"))) { |
Yao Chen | 8d9989b | 2017-11-18 18:54:50 -0800 | [diff] [blame] | 320 | return cmd_dump_memory_info(out); |
| 321 | } |
yro | 947fbce | 2017-11-15 22:50:23 -0800 | [diff] [blame] | 322 | |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 323 | if (!utf8Args[0].compare(String8("write-to-disk"))) { |
yro | 947fbce | 2017-11-15 22:50:23 -0800 | [diff] [blame] | 324 | return cmd_write_data_to_disk(out); |
| 325 | } |
Bookatz | b223c4e | 2018-02-01 15:35:04 -0800 | [diff] [blame] | 326 | |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 327 | if (!utf8Args[0].compare(String8("log-app-breadcrumb"))) { |
| 328 | return cmd_log_app_breadcrumb(out, utf8Args); |
Bookatz | b223c4e | 2018-02-01 15:35:04 -0800 | [diff] [blame] | 329 | } |
Chenjie Yu | fa22d65 | 2018-02-05 14:37:48 -0800 | [diff] [blame] | 330 | |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 331 | if (!utf8Args[0].compare(String8("log-binary-push"))) { |
| 332 | return cmd_log_binary_push(out, utf8Args); |
Tej Singh | 53f9dee | 2019-04-30 17:45:54 -0700 | [diff] [blame] | 333 | } |
| 334 | |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 335 | if (!utf8Args[0].compare(String8("clear-puller-cache"))) { |
Chenjie Yu | fa22d65 | 2018-02-05 14:37:48 -0800 | [diff] [blame] | 336 | return cmd_clear_puller_cache(out); |
| 337 | } |
Yao Chen | 876889c | 2018-05-02 11:16:16 -0700 | [diff] [blame] | 338 | |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 339 | if (!utf8Args[0].compare(String8("print-logs"))) { |
| 340 | return cmd_print_logs(out, utf8Args); |
Yao Chen | 876889c | 2018-05-02 11:16:16 -0700 | [diff] [blame] | 341 | } |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 342 | if (!utf8Args[0].compare(String8("send-active-configs"))) { |
| 343 | return cmd_trigger_active_config_broadcast(out, utf8Args); |
Tej Singh | 6ede28b | 2019-01-29 17:06:54 -0800 | [diff] [blame] | 344 | } |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 345 | if (!utf8Args[0].compare(String8("data-subscribe"))) { |
Tej Singh | c9250ce | 2019-09-20 19:28:53 -0700 | [diff] [blame] | 346 | { |
| 347 | std::lock_guard<std::mutex> lock(mShellSubscriberMutex); |
| 348 | if (mShellSubscriber == nullptr) { |
| 349 | mShellSubscriber = new ShellSubscriber(mUidMap, mPullerManager); |
| 350 | } |
Yao Chen | a80e5c0 | 2018-09-04 13:55:29 -0700 | [diff] [blame] | 351 | } |
Yao Chen | 35cb8d6 | 2019-01-03 16:49:14 -0800 | [diff] [blame] | 352 | int timeoutSec = -1; |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 353 | if (argc >= 2) { |
| 354 | timeoutSec = atoi(utf8Args[1].c_str()); |
Yao Chen | 35cb8d6 | 2019-01-03 16:49:14 -0800 | [diff] [blame] | 355 | } |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 356 | mShellSubscriber->startNewSubscription(in, out, timeoutSec); |
Yao Chen | a80e5c0 | 2018-09-04 13:55:29 -0700 | [diff] [blame] | 357 | return NO_ERROR; |
| 358 | } |
Joe Onorato | 2cbc2cc | 2017-08-30 17:03:23 -0700 | [diff] [blame] | 359 | } |
Joe Onorato | 2cbc2cc | 2017-08-30 17:03:23 -0700 | [diff] [blame] | 360 | |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 361 | print_cmd_help(out); |
Joe Onorato | 2cbc2cc | 2017-08-30 17:03:23 -0700 | [diff] [blame] | 362 | return NO_ERROR; |
| 363 | } |
| 364 | |
Yao Chen | a80e5c0 | 2018-09-04 13:55:29 -0700 | [diff] [blame] | 365 | void StatsService::print_cmd_help(int out) { |
| 366 | dprintf(out, |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 367 | "usage: adb shell cmd stats print-stats-log [tag_required] " |
| 368 | "[timestamp_nsec_optional]\n"); |
Yao Chen | a80e5c0 | 2018-09-04 13:55:29 -0700 | [diff] [blame] | 369 | dprintf(out, "\n"); |
| 370 | dprintf(out, "\n"); |
| 371 | dprintf(out, "usage: adb shell cmd stats meminfo\n"); |
| 372 | dprintf(out, "\n"); |
| 373 | dprintf(out, " Prints the malloc debug information. You need to run the following first: \n"); |
| 374 | dprintf(out, " # adb shell stop\n"); |
| 375 | dprintf(out, " # adb shell setprop libc.debug.malloc.program statsd \n"); |
| 376 | dprintf(out, " # adb shell setprop libc.debug.malloc.options backtrace \n"); |
| 377 | dprintf(out, " # adb shell start\n"); |
| 378 | dprintf(out, "\n"); |
| 379 | dprintf(out, "\n"); |
| 380 | dprintf(out, "usage: adb shell cmd stats print-uid-map [PKG]\n"); |
| 381 | dprintf(out, "\n"); |
| 382 | dprintf(out, " Prints the UID, app name, version mapping.\n"); |
| 383 | dprintf(out, " PKG Optional package name to print the uids of the package\n"); |
| 384 | dprintf(out, "\n"); |
| 385 | dprintf(out, "\n"); |
| 386 | dprintf(out, "usage: adb shell cmd stats pull-source [int] \n"); |
| 387 | dprintf(out, "\n"); |
| 388 | dprintf(out, " Prints the output of a pulled metrics source (int indicates source)\n"); |
| 389 | dprintf(out, "\n"); |
| 390 | dprintf(out, "\n"); |
| 391 | dprintf(out, "usage: adb shell cmd stats write-to-disk \n"); |
| 392 | dprintf(out, "\n"); |
| 393 | dprintf(out, " Flushes all data on memory to disk.\n"); |
| 394 | dprintf(out, "\n"); |
| 395 | dprintf(out, "\n"); |
| 396 | dprintf(out, "usage: adb shell cmd stats log-app-breadcrumb [UID] LABEL STATE\n"); |
| 397 | dprintf(out, " Writes an AppBreadcrumbReported event to the statslog buffer.\n"); |
| 398 | dprintf(out, " UID The uid to use. It is only possible to pass a UID\n"); |
| 399 | dprintf(out, " parameter on eng builds. If UID is omitted the calling\n"); |
| 400 | dprintf(out, " uid is used.\n"); |
| 401 | dprintf(out, " LABEL Integer in [0, 15], as per atoms.proto.\n"); |
| 402 | dprintf(out, " STATE Integer in [0, 3], as per atoms.proto.\n"); |
| 403 | dprintf(out, "\n"); |
| 404 | dprintf(out, "\n"); |
Tej Singh | 53f9dee | 2019-04-30 17:45:54 -0700 | [diff] [blame] | 405 | dprintf(out, |
| 406 | "usage: adb shell cmd stats log-binary-push NAME VERSION STAGING ROLLBACK_ENABLED " |
| 407 | "LOW_LATENCY STATE EXPERIMENT_IDS\n"); |
| 408 | dprintf(out, " Log a binary push state changed event.\n"); |
| 409 | dprintf(out, " NAME The train name.\n"); |
| 410 | dprintf(out, " VERSION The train version code.\n"); |
| 411 | dprintf(out, " STAGING If this train requires a restart.\n"); |
| 412 | dprintf(out, " ROLLBACK_ENABLED If rollback should be enabled for this install.\n"); |
| 413 | dprintf(out, " LOW_LATENCY If the train requires low latency monitoring.\n"); |
| 414 | dprintf(out, " STATE The status of the train push.\n"); |
| 415 | dprintf(out, " Integer value of the enum in atoms.proto.\n"); |
| 416 | dprintf(out, " EXPERIMENT_IDS Comma separated list of experiment ids.\n"); |
| 417 | dprintf(out, " Leave blank for none.\n"); |
| 418 | dprintf(out, "\n"); |
| 419 | dprintf(out, "\n"); |
Yao Chen | a80e5c0 | 2018-09-04 13:55:29 -0700 | [diff] [blame] | 420 | dprintf(out, "usage: adb shell cmd stats config remove [UID] [NAME]\n"); |
| 421 | dprintf(out, "usage: adb shell cmd stats config update [UID] NAME\n"); |
| 422 | dprintf(out, "\n"); |
| 423 | dprintf(out, " Adds, updates or removes a configuration. The proto should be in\n"); |
| 424 | dprintf(out, " wire-encoded protobuf format and passed via stdin. If no UID and name is\n"); |
| 425 | dprintf(out, " provided, then all configs will be removed from memory and disk.\n"); |
| 426 | dprintf(out, "\n"); |
| 427 | dprintf(out, " UID The uid to use. It is only possible to pass the UID\n"); |
| 428 | dprintf(out, " parameter on eng builds. If UID is omitted the calling\n"); |
| 429 | dprintf(out, " uid is used.\n"); |
| 430 | dprintf(out, " NAME The per-uid name to use\n"); |
| 431 | dprintf(out, "\n"); |
| 432 | dprintf(out, "\n *Note: If both UID and NAME are omitted then all configs will\n"); |
| 433 | dprintf(out, "\n be removed from memory and disk!\n"); |
| 434 | dprintf(out, "\n"); |
| 435 | dprintf(out, |
Bookatz | 3e90658 | 2018-12-10 17:26:58 -0800 | [diff] [blame] | 436 | "usage: adb shell cmd stats dump-report [UID] NAME [--keep_data] " |
| 437 | "[--include_current_bucket] [--proto]\n"); |
Yao Chen | a80e5c0 | 2018-09-04 13:55:29 -0700 | [diff] [blame] | 438 | dprintf(out, " Dump all metric data for a configuration.\n"); |
| 439 | dprintf(out, " UID The uid of the configuration. It is only possible to pass\n"); |
| 440 | dprintf(out, " the UID parameter on eng builds. If UID is omitted the\n"); |
| 441 | dprintf(out, " calling uid is used.\n"); |
| 442 | dprintf(out, " NAME The name of the configuration\n"); |
Bookatz | 3e90658 | 2018-12-10 17:26:58 -0800 | [diff] [blame] | 443 | 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] | 444 | dprintf(out, " --proto Print proto binary.\n"); |
| 445 | dprintf(out, "\n"); |
| 446 | dprintf(out, "\n"); |
| 447 | dprintf(out, "usage: adb shell cmd stats send-broadcast [UID] NAME\n"); |
| 448 | dprintf(out, " Send a broadcast that triggers the subscriber to fetch metrics.\n"); |
| 449 | dprintf(out, " UID The uid of the configuration. It is only possible to pass\n"); |
| 450 | dprintf(out, " the UID parameter on eng builds. If UID is omitted the\n"); |
| 451 | dprintf(out, " calling uid is used.\n"); |
| 452 | dprintf(out, " NAME The name of the configuration\n"); |
| 453 | dprintf(out, "\n"); |
| 454 | dprintf(out, "\n"); |
Tej Singh | 6ede28b | 2019-01-29 17:06:54 -0800 | [diff] [blame] | 455 | dprintf(out, |
| 456 | "usage: adb shell cmd stats send-active-configs [--uid=UID] [--configs] " |
| 457 | "[NAME1] [NAME2] [NAME3..]\n"); |
| 458 | dprintf(out, " Send a broadcast that informs the subscriber of the current active configs.\n"); |
| 459 | dprintf(out, " --uid=UID The uid of the configurations. It is only possible to pass\n"); |
| 460 | dprintf(out, " the UID parameter on eng builds. If UID is omitted the\n"); |
| 461 | dprintf(out, " calling uid is used.\n"); |
| 462 | dprintf(out, " --configs Send the list of configs in the name list instead of\n"); |
| 463 | dprintf(out, " the currently active configs\n"); |
| 464 | 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] | 465 | dprintf(out, "\n"); |
| 466 | dprintf(out, "\n"); |
Yao Chen | a80e5c0 | 2018-09-04 13:55:29 -0700 | [diff] [blame] | 467 | dprintf(out, "usage: adb shell cmd stats print-stats\n"); |
| 468 | dprintf(out, " Prints some basic stats.\n"); |
| 469 | dprintf(out, " --proto Print proto binary instead of string format.\n"); |
| 470 | dprintf(out, "\n"); |
| 471 | dprintf(out, "\n"); |
| 472 | dprintf(out, "usage: adb shell cmd stats clear-puller-cache\n"); |
| 473 | dprintf(out, " Clear cached puller data.\n"); |
| 474 | dprintf(out, "\n"); |
| 475 | dprintf(out, "usage: adb shell cmd stats print-logs\n"); |
| 476 | dprintf(out, " Only works on eng build\n"); |
David Chen | adaf8b3 | 2017-11-03 15:42:08 -0700 | [diff] [blame] | 477 | } |
| 478 | |
Yao Chen | a80e5c0 | 2018-09-04 13:55:29 -0700 | [diff] [blame] | 479 | status_t StatsService::cmd_trigger_broadcast(int out, Vector<String8>& args) { |
David Chen | 1d7b0cd | 2017-11-15 14:20:04 -0800 | [diff] [blame] | 480 | string name; |
| 481 | bool good = false; |
| 482 | int uid; |
| 483 | const int argCount = args.size(); |
| 484 | if (argCount == 2) { |
| 485 | // Automatically pick the UID |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 486 | uid = AIBinder_getCallingUid(); |
David Chen | 1d7b0cd | 2017-11-15 14:20:04 -0800 | [diff] [blame] | 487 | name.assign(args[1].c_str(), args[1].size()); |
| 488 | good = true; |
| 489 | } else if (argCount == 3) { |
Bookatz | d238657 | 2018-12-14 15:53:14 -0800 | [diff] [blame] | 490 | good = getUidFromArgs(args, 1, uid); |
| 491 | if (!good) { |
| 492 | dprintf(out, "Invalid UID. Note that the metrics can only be dumped for " |
| 493 | "other UIDs on eng or userdebug builds.\n"); |
David Chen | 1d7b0cd | 2017-11-15 14:20:04 -0800 | [diff] [blame] | 494 | } |
Bookatz | d238657 | 2018-12-14 15:53:14 -0800 | [diff] [blame] | 495 | name.assign(args[2].c_str(), args[2].size()); |
David Chen | 1d7b0cd | 2017-11-15 14:20:04 -0800 | [diff] [blame] | 496 | } |
| 497 | if (!good) { |
| 498 | print_cmd_help(out); |
| 499 | return UNKNOWN_ERROR; |
| 500 | } |
David Chen | d37bc23 | 2018-04-12 18:05:11 -0700 | [diff] [blame] | 501 | ConfigKey key(uid, StrToInt64(name)); |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 502 | shared_ptr<IPendingIntentRef> receiver = mConfigManager->GetConfigReceiver(key); |
Jeffrey Huang | ad21374 | 2019-12-16 13:50:06 -0800 | [diff] [blame] | 503 | if (receiver == nullptr) { |
| 504 | VLOG("Could not find receiver for %s, %s", args[1].c_str(), args[2].c_str()); |
| 505 | return UNKNOWN_ERROR; |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 506 | } else if (receiver->sendDataBroadcast(mProcessor->getLastReportTimeNs(key)).isOk()) { |
yro | 74fed97 | 2017-11-27 14:42:42 -0800 | [diff] [blame] | 507 | VLOG("StatsService::trigger broadcast succeeded to %s, %s", args[1].c_str(), |
| 508 | args[2].c_str()); |
Jeffrey Huang | ad21374 | 2019-12-16 13:50:06 -0800 | [diff] [blame] | 509 | } else { |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 510 | VLOG("StatsService::trigger broadcast failed to %s, %s", args[1].c_str(), args[2].c_str()); |
Jeffrey Huang | ad21374 | 2019-12-16 13:50:06 -0800 | [diff] [blame] | 511 | return UNKNOWN_ERROR; |
yro | 4d889e6 | 2017-11-17 15:44:48 -0800 | [diff] [blame] | 512 | } |
David Chen | adaf8b3 | 2017-11-03 15:42:08 -0700 | [diff] [blame] | 513 | return NO_ERROR; |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 514 | } |
| 515 | |
Tej Singh | 6ede28b | 2019-01-29 17:06:54 -0800 | [diff] [blame] | 516 | status_t StatsService::cmd_trigger_active_config_broadcast(int out, Vector<String8>& args) { |
| 517 | const int argCount = args.size(); |
| 518 | int uid; |
| 519 | vector<int64_t> configIds; |
| 520 | if (argCount == 1) { |
| 521 | // Automatically pick the uid and send a broadcast that has no active configs. |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 522 | uid = AIBinder_getCallingUid(); |
Tej Singh | 6ede28b | 2019-01-29 17:06:54 -0800 | [diff] [blame] | 523 | mProcessor->GetActiveConfigs(uid, configIds); |
| 524 | } else { |
| 525 | int curArg = 1; |
| 526 | if(args[curArg].find("--uid=") == 0) { |
| 527 | string uidArgStr(args[curArg].c_str()); |
| 528 | string uidStr = uidArgStr.substr(6); |
| 529 | if (!getUidFromString(uidStr.c_str(), uid)) { |
| 530 | dprintf(out, "Invalid UID. Note that the config can only be set for " |
| 531 | "other UIDs on eng or userdebug builds.\n"); |
| 532 | return UNKNOWN_ERROR; |
| 533 | } |
| 534 | curArg++; |
| 535 | } else { |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 536 | uid = AIBinder_getCallingUid(); |
Tej Singh | 6ede28b | 2019-01-29 17:06:54 -0800 | [diff] [blame] | 537 | } |
| 538 | if (curArg == argCount || args[curArg] != "--configs") { |
| 539 | VLOG("Reached end of args, or specify configs not set. Sending actual active configs,"); |
| 540 | mProcessor->GetActiveConfigs(uid, configIds); |
| 541 | } else { |
| 542 | // Flag specified, use the given list of configs. |
| 543 | curArg++; |
| 544 | for (int i = curArg; i < argCount; i++) { |
| 545 | char* endp; |
| 546 | int64_t configID = strtoll(args[i].c_str(), &endp, 10); |
| 547 | if (endp == args[i].c_str() || *endp != '\0') { |
| 548 | dprintf(out, "Error parsing config ID.\n"); |
| 549 | return UNKNOWN_ERROR; |
| 550 | } |
| 551 | VLOG("Adding config id %ld", static_cast<long>(configID)); |
| 552 | configIds.push_back(configID); |
| 553 | } |
| 554 | } |
| 555 | } |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 556 | shared_ptr<IPendingIntentRef> receiver = mConfigManager->GetActiveConfigsChangedReceiver(uid); |
Jeffrey Huang | 47537a1 | 2020-01-06 15:35:34 -0800 | [diff] [blame] | 557 | if (receiver == nullptr) { |
Tej Singh | 6ede28b | 2019-01-29 17:06:54 -0800 | [diff] [blame] | 558 | VLOG("Could not find receiver for uid %d", uid); |
Jeffrey Huang | 47537a1 | 2020-01-06 15:35:34 -0800 | [diff] [blame] | 559 | return UNKNOWN_ERROR; |
| 560 | } else if (receiver->sendActiveConfigsChangedBroadcast(configIds).isOk()) { |
Tej Singh | 6ede28b | 2019-01-29 17:06:54 -0800 | [diff] [blame] | 561 | VLOG("StatsService::trigger active configs changed broadcast succeeded for uid %d" , uid); |
Jeffrey Huang | 47537a1 | 2020-01-06 15:35:34 -0800 | [diff] [blame] | 562 | } else { |
| 563 | VLOG("StatsService::trigger active configs changed broadcast failed for uid %d", uid); |
| 564 | return UNKNOWN_ERROR; |
Tej Singh | 6ede28b | 2019-01-29 17:06:54 -0800 | [diff] [blame] | 565 | } |
| 566 | return NO_ERROR; |
| 567 | } |
| 568 | |
Yao Chen | a80e5c0 | 2018-09-04 13:55:29 -0700 | [diff] [blame] | 569 | 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] | 570 | const int argCount = args.size(); |
| 571 | if (argCount >= 2) { |
| 572 | if (args[1] == "update" || args[1] == "remove") { |
| 573 | bool good = false; |
| 574 | int uid = -1; |
| 575 | string name; |
| 576 | |
| 577 | if (argCount == 3) { |
| 578 | // Automatically pick the UID |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 579 | uid = AIBinder_getCallingUid(); |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 580 | name.assign(args[2].c_str(), args[2].size()); |
| 581 | good = true; |
| 582 | } else if (argCount == 4) { |
Bookatz | d238657 | 2018-12-14 15:53:14 -0800 | [diff] [blame] | 583 | good = getUidFromArgs(args, 2, uid); |
| 584 | if (!good) { |
| 585 | dprintf(err, "Invalid UID. Note that the config can only be set for " |
| 586 | "other UIDs on eng or userdebug builds.\n"); |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 587 | } |
Bookatz | d238657 | 2018-12-14 15:53:14 -0800 | [diff] [blame] | 588 | name.assign(args[3].c_str(), args[3].size()); |
yro | e5f8292 | 2018-01-22 18:37:27 -0800 | [diff] [blame] | 589 | } else if (argCount == 2 && args[1] == "remove") { |
| 590 | good = true; |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 591 | } |
| 592 | |
| 593 | if (!good) { |
| 594 | // If arg parsing failed, print the help text and return an error. |
| 595 | print_cmd_help(out); |
| 596 | return UNKNOWN_ERROR; |
| 597 | } |
| 598 | |
| 599 | if (args[1] == "update") { |
yro | 255f72e | 2018-02-26 15:15:17 -0800 | [diff] [blame] | 600 | char* endp; |
| 601 | int64_t configID = strtoll(name.c_str(), &endp, 10); |
| 602 | if (endp == name.c_str() || *endp != '\0') { |
Yao Chen | a80e5c0 | 2018-09-04 13:55:29 -0700 | [diff] [blame] | 603 | dprintf(err, "Error parsing config ID.\n"); |
yro | 255f72e | 2018-02-26 15:15:17 -0800 | [diff] [blame] | 604 | return UNKNOWN_ERROR; |
| 605 | } |
| 606 | |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 607 | // Read stream into buffer. |
| 608 | string buffer; |
Yao Chen | a80e5c0 | 2018-09-04 13:55:29 -0700 | [diff] [blame] | 609 | if (!android::base::ReadFdToString(in, &buffer)) { |
| 610 | dprintf(err, "Error reading stream for StatsConfig.\n"); |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 611 | return UNKNOWN_ERROR; |
| 612 | } |
| 613 | |
| 614 | // Parse buffer. |
| 615 | StatsdConfig config; |
| 616 | if (!config.ParseFromString(buffer)) { |
Yao Chen | a80e5c0 | 2018-09-04 13:55:29 -0700 | [diff] [blame] | 617 | dprintf(err, "Error parsing proto stream for StatsConfig.\n"); |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 618 | return UNKNOWN_ERROR; |
| 619 | } |
| 620 | |
| 621 | // Add / update the config. |
yro | 255f72e | 2018-02-26 15:15:17 -0800 | [diff] [blame] | 622 | mConfigManager->UpdateConfig(ConfigKey(uid, configID), config); |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 623 | } else { |
yro | 74fed97 | 2017-11-27 14:42:42 -0800 | [diff] [blame] | 624 | if (argCount == 2) { |
| 625 | cmd_remove_all_configs(out); |
| 626 | } else { |
| 627 | // Remove the config. |
Yangster-mac | 94e197c | 2018-01-02 16:03:03 -0800 | [diff] [blame] | 628 | mConfigManager->RemoveConfig(ConfigKey(uid, StrToInt64(name))); |
yro | 74fed97 | 2017-11-27 14:42:42 -0800 | [diff] [blame] | 629 | } |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 630 | } |
| 631 | |
| 632 | return NO_ERROR; |
| 633 | } |
David Chen | 0656b7a | 2017-09-13 15:53:39 -0700 | [diff] [blame] | 634 | } |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 635 | print_cmd_help(out); |
| 636 | return UNKNOWN_ERROR; |
| 637 | } |
| 638 | |
Bookatz | ff71cad | 2018-09-20 17:17:49 -0700 | [diff] [blame] | 639 | status_t StatsService::cmd_dump_report(int out, const Vector<String8>& args) { |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 640 | if (mProcessor != nullptr) { |
Chenjie Yu | b236c86 | 2017-11-28 22:20:44 -0800 | [diff] [blame] | 641 | int argCount = args.size(); |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 642 | bool good = false; |
Chenjie Yu | b236c86 | 2017-11-28 22:20:44 -0800 | [diff] [blame] | 643 | bool proto = false; |
Chenjie Yu | bd1a28f | 2018-07-17 14:55:19 -0700 | [diff] [blame] | 644 | bool includeCurrentBucket = false; |
Bookatz | 3e90658 | 2018-12-10 17:26:58 -0800 | [diff] [blame] | 645 | bool eraseData = true; |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 646 | int uid; |
| 647 | string name; |
Chenjie Yu | b236c86 | 2017-11-28 22:20:44 -0800 | [diff] [blame] | 648 | if (!std::strcmp("--proto", args[argCount-1].c_str())) { |
| 649 | proto = true; |
| 650 | argCount -= 1; |
| 651 | } |
Chenjie Yu | bd1a28f | 2018-07-17 14:55:19 -0700 | [diff] [blame] | 652 | if (!std::strcmp("--include_current_bucket", args[argCount-1].c_str())) { |
| 653 | includeCurrentBucket = true; |
| 654 | argCount -= 1; |
| 655 | } |
Bookatz | 3e90658 | 2018-12-10 17:26:58 -0800 | [diff] [blame] | 656 | if (!std::strcmp("--keep_data", args[argCount-1].c_str())) { |
| 657 | eraseData = false; |
| 658 | argCount -= 1; |
| 659 | } |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 660 | if (argCount == 2) { |
| 661 | // Automatically pick the UID |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 662 | uid = AIBinder_getCallingUid(); |
Yao Chen | 5154a37 | 2017-10-30 22:57:06 -0700 | [diff] [blame] | 663 | name.assign(args[1].c_str(), args[1].size()); |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 664 | good = true; |
| 665 | } else if (argCount == 3) { |
Bookatz | d238657 | 2018-12-14 15:53:14 -0800 | [diff] [blame] | 666 | good = getUidFromArgs(args, 1, uid); |
| 667 | if (!good) { |
| 668 | dprintf(out, "Invalid UID. Note that the metrics can only be dumped for " |
| 669 | "other UIDs on eng or userdebug builds.\n"); |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 670 | } |
Bookatz | d238657 | 2018-12-14 15:53:14 -0800 | [diff] [blame] | 671 | name.assign(args[2].c_str(), args[2].size()); |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 672 | } |
| 673 | if (good) { |
David Chen | 1d7b0cd | 2017-11-15 14:20:04 -0800 | [diff] [blame] | 674 | vector<uint8_t> data; |
David Chen | 926fc75 | 2018-02-23 13:31:43 -0800 | [diff] [blame] | 675 | mProcessor->onDumpReport(ConfigKey(uid, StrToInt64(name)), getElapsedRealtimeNs(), |
Olivier Gaillard | 6c75ecd | 2019-02-20 09:57:33 +0000 | [diff] [blame] | 676 | includeCurrentBucket, eraseData, ADB_DUMP, |
| 677 | NO_TIME_CONSTRAINTS, |
| 678 | &data); |
Chenjie Yu | b236c86 | 2017-11-28 22:20:44 -0800 | [diff] [blame] | 679 | if (proto) { |
| 680 | for (size_t i = 0; i < data.size(); i ++) { |
Yao Chen | a80e5c0 | 2018-09-04 13:55:29 -0700 | [diff] [blame] | 681 | dprintf(out, "%c", data[i]); |
Chenjie Yu | b236c86 | 2017-11-28 22:20:44 -0800 | [diff] [blame] | 682 | } |
| 683 | } else { |
Bookatz | ff71cad | 2018-09-20 17:17:49 -0700 | [diff] [blame] | 684 | dprintf(out, "Non-proto stats data dump not currently supported.\n"); |
Chenjie Yu | b236c86 | 2017-11-28 22:20:44 -0800 | [diff] [blame] | 685 | } |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 686 | return android::OK; |
| 687 | } else { |
| 688 | // If arg parsing failed, print the help text and return an error. |
| 689 | print_cmd_help(out); |
| 690 | return UNKNOWN_ERROR; |
| 691 | } |
| 692 | } else { |
Yao Chen | a80e5c0 | 2018-09-04 13:55:29 -0700 | [diff] [blame] | 693 | dprintf(out, "Log processor does not exist...\n"); |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 694 | return UNKNOWN_ERROR; |
| 695 | } |
| 696 | } |
| 697 | |
Yao Chen | a80e5c0 | 2018-09-04 13:55:29 -0700 | [diff] [blame] | 698 | status_t StatsService::cmd_print_stats(int out, const Vector<String8>& args) { |
Tej Singh | 41b3f9a | 2018-04-03 17:06:35 -0700 | [diff] [blame] | 699 | int argCount = args.size(); |
| 700 | bool proto = false; |
| 701 | if (!std::strcmp("--proto", args[argCount-1].c_str())) { |
| 702 | proto = true; |
| 703 | argCount -= 1; |
David Chen | 1d7b0cd | 2017-11-15 14:20:04 -0800 | [diff] [blame] | 704 | } |
Yao Chen | b356151 | 2017-11-21 18:07:17 -0800 | [diff] [blame] | 705 | StatsdStats& statsdStats = StatsdStats::getInstance(); |
Tej Singh | 41b3f9a | 2018-04-03 17:06:35 -0700 | [diff] [blame] | 706 | if (proto) { |
| 707 | vector<uint8_t> data; |
| 708 | statsdStats.dumpStats(&data, false); // does not reset statsdStats. |
| 709 | for (size_t i = 0; i < data.size(); i ++) { |
Yao Chen | a80e5c0 | 2018-09-04 13:55:29 -0700 | [diff] [blame] | 710 | dprintf(out, "%c", data[i]); |
Tej Singh | 41b3f9a | 2018-04-03 17:06:35 -0700 | [diff] [blame] | 711 | } |
| 712 | |
| 713 | } else { |
| 714 | vector<ConfigKey> configs = mConfigManager->GetAllConfigKeys(); |
| 715 | for (const ConfigKey& key : configs) { |
Yao Chen | a80e5c0 | 2018-09-04 13:55:29 -0700 | [diff] [blame] | 716 | dprintf(out, "Config %s uses %zu bytes\n", key.ToString().c_str(), |
Tej Singh | 41b3f9a | 2018-04-03 17:06:35 -0700 | [diff] [blame] | 717 | mProcessor->GetMetricsSize(key)); |
| 718 | } |
| 719 | statsdStats.dumpStats(out); |
| 720 | } |
David Chen | 1d7b0cd | 2017-11-15 14:20:04 -0800 | [diff] [blame] | 721 | return NO_ERROR; |
| 722 | } |
| 723 | |
Yao Chen | a80e5c0 | 2018-09-04 13:55:29 -0700 | [diff] [blame] | 724 | 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] | 725 | if (args.size() > 1) { |
| 726 | string pkg; |
| 727 | pkg.assign(args[1].c_str(), args[1].size()); |
| 728 | auto uids = mUidMap->getAppUid(pkg); |
Yao Chen | a80e5c0 | 2018-09-04 13:55:29 -0700 | [diff] [blame] | 729 | dprintf(out, "%s -> [ ", pkg.c_str()); |
Yao Chen | d10f7b1 | 2017-12-18 12:53:50 -0800 | [diff] [blame] | 730 | for (const auto& uid : uids) { |
Yao Chen | a80e5c0 | 2018-09-04 13:55:29 -0700 | [diff] [blame] | 731 | dprintf(out, "%d ", uid); |
Yao Chen | d10f7b1 | 2017-12-18 12:53:50 -0800 | [diff] [blame] | 732 | } |
Yao Chen | a80e5c0 | 2018-09-04 13:55:29 -0700 | [diff] [blame] | 733 | dprintf(out, "]\n"); |
Yao Chen | d10f7b1 | 2017-12-18 12:53:50 -0800 | [diff] [blame] | 734 | } else { |
| 735 | mUidMap->printUidMap(out); |
| 736 | } |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 737 | return NO_ERROR; |
David Chen | 0656b7a | 2017-09-13 15:53:39 -0700 | [diff] [blame] | 738 | } |
| 739 | |
Yao Chen | a80e5c0 | 2018-09-04 13:55:29 -0700 | [diff] [blame] | 740 | status_t StatsService::cmd_write_data_to_disk(int out) { |
| 741 | dprintf(out, "Writing data to disk\n"); |
Olivier Gaillard | 6c75ecd | 2019-02-20 09:57:33 +0000 | [diff] [blame] | 742 | mProcessor->WriteDataToDisk(ADB_DUMP, NO_TIME_CONSTRAINTS); |
yro | 947fbce | 2017-11-15 22:50:23 -0800 | [diff] [blame] | 743 | return NO_ERROR; |
| 744 | } |
| 745 | |
Yao Chen | a80e5c0 | 2018-09-04 13:55:29 -0700 | [diff] [blame] | 746 | status_t StatsService::cmd_log_app_breadcrumb(int out, const Vector<String8>& args) { |
Bookatz | b223c4e | 2018-02-01 15:35:04 -0800 | [diff] [blame] | 747 | bool good = false; |
| 748 | int32_t uid; |
| 749 | int32_t label; |
| 750 | int32_t state; |
| 751 | const int argCount = args.size(); |
| 752 | if (argCount == 3) { |
| 753 | // Automatically pick the UID |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 754 | uid = AIBinder_getCallingUid(); |
Bookatz | b223c4e | 2018-02-01 15:35:04 -0800 | [diff] [blame] | 755 | label = atoi(args[1].c_str()); |
| 756 | state = atoi(args[2].c_str()); |
| 757 | good = true; |
| 758 | } else if (argCount == 4) { |
Bookatz | d238657 | 2018-12-14 15:53:14 -0800 | [diff] [blame] | 759 | good = getUidFromArgs(args, 1, uid); |
| 760 | if (!good) { |
Yao Chen | a80e5c0 | 2018-09-04 13:55:29 -0700 | [diff] [blame] | 761 | dprintf(out, |
Bookatz | d238657 | 2018-12-14 15:53:14 -0800 | [diff] [blame] | 762 | "Invalid UID. Note that selecting a UID for writing AppBreadcrumb can only be " |
| 763 | "done for other UIDs on eng or userdebug builds.\n"); |
Bookatz | b223c4e | 2018-02-01 15:35:04 -0800 | [diff] [blame] | 764 | } |
Bookatz | d238657 | 2018-12-14 15:53:14 -0800 | [diff] [blame] | 765 | label = atoi(args[2].c_str()); |
| 766 | state = atoi(args[3].c_str()); |
Bookatz | b223c4e | 2018-02-01 15:35:04 -0800 | [diff] [blame] | 767 | } |
| 768 | if (good) { |
Yao Chen | a80e5c0 | 2018-09-04 13:55:29 -0700 | [diff] [blame] | 769 | 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] | 770 | android::util::stats_write(android::util::APP_BREADCRUMB_REPORTED, uid, label, state); |
Bookatz | b223c4e | 2018-02-01 15:35:04 -0800 | [diff] [blame] | 771 | } else { |
| 772 | print_cmd_help(out); |
| 773 | return UNKNOWN_ERROR; |
| 774 | } |
| 775 | return NO_ERROR; |
| 776 | } |
| 777 | |
Tej Singh | 53f9dee | 2019-04-30 17:45:54 -0700 | [diff] [blame] | 778 | status_t StatsService::cmd_log_binary_push(int out, const Vector<String8>& args) { |
| 779 | // Security checks are done in the sendBinaryPushStateChanged atom. |
| 780 | const int argCount = args.size(); |
| 781 | if (argCount != 7 && argCount != 8) { |
| 782 | dprintf(out, "Incorrect number of argument supplied\n"); |
| 783 | return UNKNOWN_ERROR; |
| 784 | } |
Jonathan Nguyen | a0e6de1 | 2020-01-28 18:33:55 -0800 | [diff] [blame] | 785 | string trainName = string(args[1].c_str()); |
Tej Singh | 53f9dee | 2019-04-30 17:45:54 -0700 | [diff] [blame] | 786 | int64_t trainVersion = strtoll(args[2].c_str(), nullptr, 10); |
Tej Singh | 53f9dee | 2019-04-30 17:45:54 -0700 | [diff] [blame] | 787 | int32_t state = atoi(args[6].c_str()); |
| 788 | vector<int64_t> experimentIds; |
| 789 | if (argCount == 8) { |
| 790 | vector<string> experimentIdsString = android::base::Split(string(args[7].c_str()), ","); |
| 791 | for (string experimentIdString : experimentIdsString) { |
| 792 | int64_t experimentId = strtoll(experimentIdString.c_str(), nullptr, 10); |
| 793 | experimentIds.push_back(experimentId); |
| 794 | } |
| 795 | } |
| 796 | dprintf(out, "Logging BinaryPushStateChanged\n"); |
Jonathan Nguyen | a0e6de1 | 2020-01-28 18:33:55 -0800 | [diff] [blame] | 797 | vector<uint8_t> experimentIdBytes; |
| 798 | writeExperimentIdsToProto(experimentIds, &experimentIdBytes); |
| 799 | LogEvent event(trainName, trainVersion, args[3], args[4], args[5], state, experimentIdBytes, 0); |
| 800 | mProcessor->OnLogEvent(&event); |
Tej Singh | 53f9dee | 2019-04-30 17:45:54 -0700 | [diff] [blame] | 801 | return NO_ERROR; |
| 802 | } |
| 803 | |
Yao Chen | a80e5c0 | 2018-09-04 13:55:29 -0700 | [diff] [blame] | 804 | 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] | 805 | int s = atoi(args[1].c_str()); |
Chenjie Yu | 5305e1d | 2017-10-31 13:49:36 -0700 | [diff] [blame] | 806 | vector<shared_ptr<LogEvent> > stats; |
Chenjie Yu | 0bd73db | 2018-12-16 07:37:04 -0800 | [diff] [blame] | 807 | if (mPullerManager->Pull(s, &stats)) { |
Chenjie Yu | 5305e1d | 2017-10-31 13:49:36 -0700 | [diff] [blame] | 808 | for (const auto& it : stats) { |
Yao Chen | a80e5c0 | 2018-09-04 13:55:29 -0700 | [diff] [blame] | 809 | dprintf(out, "Pull from %d: %s\n", s, it->ToString().c_str()); |
Chenjie Yu | 5305e1d | 2017-10-31 13:49:36 -0700 | [diff] [blame] | 810 | } |
Yao Chen | a80e5c0 | 2018-09-04 13:55:29 -0700 | [diff] [blame] | 811 | dprintf(out, "Pull from %d: Received %zu elements\n", s, stats.size()); |
Chenjie Yu | 5305e1d | 2017-10-31 13:49:36 -0700 | [diff] [blame] | 812 | return NO_ERROR; |
David Chen | 1481fe1 | 2017-10-16 13:16:34 -0700 | [diff] [blame] | 813 | } |
Chenjie Yu | 5305e1d | 2017-10-31 13:49:36 -0700 | [diff] [blame] | 814 | return UNKNOWN_ERROR; |
David Chen | 1481fe1 | 2017-10-16 13:16:34 -0700 | [diff] [blame] | 815 | } |
| 816 | |
Yao Chen | a80e5c0 | 2018-09-04 13:55:29 -0700 | [diff] [blame] | 817 | status_t StatsService::cmd_remove_all_configs(int out) { |
| 818 | dprintf(out, "Removing all configs...\n"); |
yro | 74fed97 | 2017-11-27 14:42:42 -0800 | [diff] [blame] | 819 | VLOG("StatsService::cmd_remove_all_configs was called"); |
| 820 | mConfigManager->RemoveAllConfigs(); |
yro | 947fbce | 2017-11-15 22:50:23 -0800 | [diff] [blame] | 821 | StorageManager::deleteAllFiles(STATS_SERVICE_DIR); |
yro | 87d983c | 2017-11-14 21:31:43 -0800 | [diff] [blame] | 822 | return NO_ERROR; |
| 823 | } |
| 824 | |
Yao Chen | a80e5c0 | 2018-09-04 13:55:29 -0700 | [diff] [blame] | 825 | status_t StatsService::cmd_dump_memory_info(int out) { |
| 826 | dprintf(out, "meminfo not available.\n"); |
Yao Chen | 8d9989b | 2017-11-18 18:54:50 -0800 | [diff] [blame] | 827 | return NO_ERROR; |
| 828 | } |
| 829 | |
Yao Chen | a80e5c0 | 2018-09-04 13:55:29 -0700 | [diff] [blame] | 830 | status_t StatsService::cmd_clear_puller_cache(int out) { |
Yangster-mac | 932ecec | 2018-02-01 10:23:52 -0800 | [diff] [blame] | 831 | VLOG("StatsService::cmd_clear_puller_cache with Pid %i, Uid %i", |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 832 | AIBinder_getCallingPid(), AIBinder_getCallingUid()); |
Ruchir Rastogi | 0563e3b | 2020-01-28 17:43:13 -0800 | [diff] [blame] | 833 | if (checkPermission(kPermissionDump)) { |
Chenjie Yu | e221920 | 2018-06-08 10:07:51 -0700 | [diff] [blame] | 834 | int cleared = mPullerManager->ForceClearPullerCache(); |
Yao Chen | a80e5c0 | 2018-09-04 13:55:29 -0700 | [diff] [blame] | 835 | dprintf(out, "Puller removed %d cached data!\n", cleared); |
Chenjie Yu | fa22d65 | 2018-02-05 14:37:48 -0800 | [diff] [blame] | 836 | return NO_ERROR; |
| 837 | } else { |
| 838 | return PERMISSION_DENIED; |
| 839 | } |
Chenjie Yu | e72252b | 2018-02-01 13:19:35 -0800 | [diff] [blame] | 840 | } |
| 841 | |
Yao Chen | a80e5c0 | 2018-09-04 13:55:29 -0700 | [diff] [blame] | 842 | status_t StatsService::cmd_print_logs(int out, const Vector<String8>& args) { |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 843 | VLOG("StatsService::cmd_print_logs with Pid %i, Uid %i", AIBinder_getCallingPid(), |
| 844 | AIBinder_getCallingUid()); |
Ruchir Rastogi | 0563e3b | 2020-01-28 17:43:13 -0800 | [diff] [blame] | 845 | if (checkPermission(kPermissionDump)) { |
Yao Chen | 876889c | 2018-05-02 11:16:16 -0700 | [diff] [blame] | 846 | bool enabled = true; |
| 847 | if (args.size() >= 2) { |
| 848 | enabled = atoi(args[1].c_str()) != 0; |
| 849 | } |
| 850 | mProcessor->setPrintLogs(enabled); |
| 851 | return NO_ERROR; |
| 852 | } else { |
| 853 | return PERMISSION_DENIED; |
| 854 | } |
| 855 | } |
| 856 | |
Bookatz | d238657 | 2018-12-14 15:53:14 -0800 | [diff] [blame] | 857 | 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] | 858 | return getUidFromString(args[uidArgIndex].c_str(), uid); |
| 859 | } |
| 860 | |
| 861 | bool StatsService::getUidFromString(const char* s, int32_t& uid) { |
Bookatz | d238657 | 2018-12-14 15:53:14 -0800 | [diff] [blame] | 862 | if (*s == '\0') { |
| 863 | return false; |
| 864 | } |
| 865 | char* endc = NULL; |
| 866 | int64_t longUid = strtol(s, &endc, 0); |
| 867 | if (*endc != '\0') { |
| 868 | return false; |
| 869 | } |
| 870 | int32_t goodUid = static_cast<int32_t>(longUid); |
| 871 | if (longUid < 0 || static_cast<uint64_t>(longUid) != static_cast<uid_t>(goodUid)) { |
| 872 | return false; // It was not of uid_t type. |
| 873 | } |
| 874 | uid = goodUid; |
| 875 | |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 876 | int32_t callingUid = AIBinder_getCallingUid(); |
Bookatz | d238657 | 2018-12-14 15:53:14 -0800 | [diff] [blame] | 877 | return mEngBuild // UserDebug/EngBuild are allowed to impersonate uids. |
| 878 | || (callingUid == goodUid) // Anyone can 'impersonate' themselves. |
| 879 | || (callingUid == AID_ROOT && goodUid == AID_SHELL); // ROOT can impersonate SHELL. |
| 880 | } |
| 881 | |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 882 | Status StatsService::informAllUidData(const ScopedFileDescriptor& fd) { |
Jeff Sharkey | 6b64925 | 2018-04-16 09:50:22 -0600 | [diff] [blame] | 883 | ENFORCE_UID(AID_SYSTEM); |
Max Dashouk | 11e0d40 | 2019-05-16 16:58:07 -0700 | [diff] [blame] | 884 | // Read stream into buffer. |
| 885 | string buffer; |
| 886 | if (!android::base::ReadFdToString(fd.get(), &buffer)) { |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 887 | return exception(EX_ILLEGAL_ARGUMENT, "Failed to read all data from the pipe."); |
Max Dashouk | 11e0d40 | 2019-05-16 16:58:07 -0700 | [diff] [blame] | 888 | } |
Jeff Sharkey | 6b64925 | 2018-04-16 09:50:22 -0600 | [diff] [blame] | 889 | |
Max Dashouk | 11e0d40 | 2019-05-16 16:58:07 -0700 | [diff] [blame] | 890 | // Parse buffer. |
| 891 | UidData uidData; |
| 892 | if (!uidData.ParseFromString(buffer)) { |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 893 | return exception(EX_ILLEGAL_ARGUMENT, "Error parsing proto stream for UidData."); |
Max Dashouk | 11e0d40 | 2019-05-16 16:58:07 -0700 | [diff] [blame] | 894 | } |
David Chen | de70169 | 2017-10-05 13:16:02 -0700 | [diff] [blame] | 895 | |
Max Dashouk | 11e0d40 | 2019-05-16 16:58:07 -0700 | [diff] [blame] | 896 | vector<String16> versionStrings; |
| 897 | vector<String16> installers; |
| 898 | vector<String16> packageNames; |
| 899 | vector<int32_t> uids; |
| 900 | vector<int64_t> versions; |
| 901 | |
| 902 | const auto numEntries = uidData.app_info_size(); |
| 903 | versionStrings.reserve(numEntries); |
| 904 | installers.reserve(numEntries); |
| 905 | packageNames.reserve(numEntries); |
| 906 | uids.reserve(numEntries); |
| 907 | versions.reserve(numEntries); |
| 908 | |
| 909 | for (const auto& appInfo: uidData.app_info()) { |
| 910 | packageNames.emplace_back(String16(appInfo.package_name().c_str())); |
| 911 | uids.push_back(appInfo.uid()); |
| 912 | versions.push_back(appInfo.version()); |
| 913 | versionStrings.emplace_back(String16(appInfo.version_string().c_str())); |
| 914 | installers.emplace_back(String16(appInfo.installer().c_str())); |
| 915 | } |
| 916 | |
| 917 | mUidMap->updateMap(getElapsedRealtimeNs(), |
| 918 | uids, |
| 919 | versions, |
| 920 | versionStrings, |
| 921 | packageNames, |
| 922 | installers); |
| 923 | |
| 924 | VLOG("StatsService::informAllUidData UidData proto parsed successfully."); |
David Chen | de70169 | 2017-10-05 13:16:02 -0700 | [diff] [blame] | 925 | return Status::ok(); |
| 926 | } |
| 927 | |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 928 | Status StatsService::informOnePackage(const string& app, int32_t uid, int64_t version, |
| 929 | const string& versionString, const string& installer) { |
Jeff Sharkey | 6b64925 | 2018-04-16 09:50:22 -0600 | [diff] [blame] | 930 | ENFORCE_UID(AID_SYSTEM); |
David Chen | de70169 | 2017-10-05 13:16:02 -0700 | [diff] [blame] | 931 | |
Jeff Sharkey | 6b64925 | 2018-04-16 09:50:22 -0600 | [diff] [blame] | 932 | VLOG("StatsService::informOnePackage was called"); |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 933 | // TODO(b/149254662): This is gross. We should consider changing statsd |
| 934 | // internals to use std::string. |
| 935 | String16 utf16App = String16(app.c_str()); |
| 936 | String16 utf16VersionString = String16(versionString.c_str()); |
| 937 | String16 utf16Installer = String16(installer.c_str()); |
| 938 | |
| 939 | mUidMap->updateApp(getElapsedRealtimeNs(), utf16App, uid, version, utf16VersionString, |
| 940 | utf16Installer); |
David Chen | de70169 | 2017-10-05 13:16:02 -0700 | [diff] [blame] | 941 | return Status::ok(); |
| 942 | } |
| 943 | |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 944 | Status StatsService::informOnePackageRemoved(const string& app, int32_t uid) { |
Jeff Sharkey | 6b64925 | 2018-04-16 09:50:22 -0600 | [diff] [blame] | 945 | ENFORCE_UID(AID_SYSTEM); |
David Chen | de70169 | 2017-10-05 13:16:02 -0700 | [diff] [blame] | 946 | |
Jeff Sharkey | 6b64925 | 2018-04-16 09:50:22 -0600 | [diff] [blame] | 947 | VLOG("StatsService::informOnePackageRemoved was called"); |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 948 | String16 utf16App = String16(app.c_str()); |
| 949 | mUidMap->removeApp(getElapsedRealtimeNs(), utf16App, uid); |
yro | 0192402 | 2018-02-20 18:20:49 -0800 | [diff] [blame] | 950 | mConfigManager->RemoveConfigs(uid); |
David Chen | de70169 | 2017-10-05 13:16:02 -0700 | [diff] [blame] | 951 | return Status::ok(); |
| 952 | } |
| 953 | |
Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame] | 954 | Status StatsService::informAnomalyAlarmFired() { |
Jeff Sharkey | 6b64925 | 2018-04-16 09:50:22 -0600 | [diff] [blame] | 955 | ENFORCE_UID(AID_SYSTEM); |
| 956 | |
yro | 74fed97 | 2017-11-27 14:42:42 -0800 | [diff] [blame] | 957 | VLOG("StatsService::informAnomalyAlarmFired was called"); |
Yangster-mac | b142cc8 | 2018-03-30 15:22:08 -0700 | [diff] [blame] | 958 | int64_t currentTimeSec = getElapsedRealtimeSec(); |
Yangster-mac | 932ecec | 2018-02-01 10:23:52 -0800 | [diff] [blame] | 959 | std::unordered_set<sp<const InternalAlarm>, SpHash<InternalAlarm>> alarmSet = |
| 960 | mAnomalyAlarmMonitor->popSoonerThan(static_cast<uint32_t>(currentTimeSec)); |
| 961 | if (alarmSet.size() > 0) { |
Bookatz | 66fe061 | 2018-02-07 18:51:48 -0800 | [diff] [blame] | 962 | VLOG("Found an anomaly alarm that fired."); |
Yangster-mac | 932ecec | 2018-02-01 10:23:52 -0800 | [diff] [blame] | 963 | mProcessor->onAnomalyAlarmFired(currentTimeSec * NS_PER_SEC, alarmSet); |
Bookatz | 66fe061 | 2018-02-07 18:51:48 -0800 | [diff] [blame] | 964 | } else { |
| 965 | VLOG("Cannot find an anomaly alarm that fired. Perhaps it was recently cancelled."); |
| 966 | } |
Bookatz | 1b0b114 | 2017-09-08 11:58:42 -0700 | [diff] [blame] | 967 | return Status::ok(); |
| 968 | } |
| 969 | |
Yangster-mac | 932ecec | 2018-02-01 10:23:52 -0800 | [diff] [blame] | 970 | Status StatsService::informAlarmForSubscriberTriggeringFired() { |
Jeff Sharkey | 6b64925 | 2018-04-16 09:50:22 -0600 | [diff] [blame] | 971 | ENFORCE_UID(AID_SYSTEM); |
| 972 | |
Yangster-mac | 932ecec | 2018-02-01 10:23:52 -0800 | [diff] [blame] | 973 | VLOG("StatsService::informAlarmForSubscriberTriggeringFired was called"); |
Yangster-mac | b142cc8 | 2018-03-30 15:22:08 -0700 | [diff] [blame] | 974 | int64_t currentTimeSec = getElapsedRealtimeSec(); |
Yangster-mac | 932ecec | 2018-02-01 10:23:52 -0800 | [diff] [blame] | 975 | std::unordered_set<sp<const InternalAlarm>, SpHash<InternalAlarm>> alarmSet = |
| 976 | mPeriodicAlarmMonitor->popSoonerThan(static_cast<uint32_t>(currentTimeSec)); |
| 977 | if (alarmSet.size() > 0) { |
| 978 | VLOG("Found periodic alarm fired."); |
| 979 | mProcessor->onPeriodicAlarmFired(currentTimeSec * NS_PER_SEC, alarmSet); |
| 980 | } else { |
| 981 | ALOGW("Cannot find an periodic alarm that fired. Perhaps it was recently cancelled."); |
| 982 | } |
| 983 | return Status::ok(); |
| 984 | } |
| 985 | |
Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame] | 986 | Status StatsService::informPollAlarmFired() { |
Jeff Sharkey | 6b64925 | 2018-04-16 09:50:22 -0600 | [diff] [blame] | 987 | ENFORCE_UID(AID_SYSTEM); |
| 988 | |
yro | 74fed97 | 2017-11-27 14:42:42 -0800 | [diff] [blame] | 989 | VLOG("StatsService::informPollAlarmFired was called"); |
Yangster-mac | 15f6bbc | 2018-04-08 11:52:26 -0700 | [diff] [blame] | 990 | mProcessor->informPullAlarmFired(getElapsedRealtimeNs()); |
yro | 74fed97 | 2017-11-27 14:42:42 -0800 | [diff] [blame] | 991 | VLOG("StatsService::informPollAlarmFired succeeded"); |
Bookatz | 1b0b114 | 2017-09-08 11:58:42 -0700 | [diff] [blame] | 992 | return Status::ok(); |
| 993 | } |
| 994 | |
Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame] | 995 | Status StatsService::systemRunning() { |
Jeff Sharkey | 6b64925 | 2018-04-16 09:50:22 -0600 | [diff] [blame] | 996 | ENFORCE_UID(AID_SYSTEM); |
Joe Onorato | 5dcbc6c | 2017-08-29 15:13:58 -0700 | [diff] [blame] | 997 | |
| 998 | // When system_server is up and running, schedule the dropbox task to run. |
yro | 74fed97 | 2017-11-27 14:42:42 -0800 | [diff] [blame] | 999 | VLOG("StatsService::systemRunning"); |
Bookatz | b487b55 | 2017-09-18 11:26:01 -0700 | [diff] [blame] | 1000 | sayHiToStatsCompanion(); |
Joe Onorato | 5dcbc6c | 2017-08-29 15:13:58 -0700 | [diff] [blame] | 1001 | return Status::ok(); |
| 1002 | } |
| 1003 | |
Yangster-mac | 892f3d3 | 2018-05-02 14:16:48 -0700 | [diff] [blame] | 1004 | Status StatsService::informDeviceShutdown() { |
Jeff Sharkey | 6b64925 | 2018-04-16 09:50:22 -0600 | [diff] [blame] | 1005 | ENFORCE_UID(AID_SYSTEM); |
Chenjie Yu | e36018b | 2018-04-16 15:18:30 -0700 | [diff] [blame] | 1006 | VLOG("StatsService::informDeviceShutdown"); |
Olivier Gaillard | 6c75ecd | 2019-02-20 09:57:33 +0000 | [diff] [blame] | 1007 | mProcessor->WriteDataToDisk(DEVICE_SHUTDOWN, FAST); |
Muhammad Qureshi | 844694b | 2019-04-05 10:10:40 -0700 | [diff] [blame] | 1008 | mProcessor->SaveActiveConfigsToDisk(getElapsedRealtimeNs()); |
yro | 947fbce | 2017-11-15 22:50:23 -0800 | [diff] [blame] | 1009 | return Status::ok(); |
| 1010 | } |
| 1011 | |
Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame] | 1012 | void StatsService::sayHiToStatsCompanion() { |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 1013 | shared_ptr<IStatsCompanionService> statsCompanion = getStatsCompanionService(); |
Bookatz | b487b55 | 2017-09-18 11:26:01 -0700 | [diff] [blame] | 1014 | if (statsCompanion != nullptr) { |
yro | 74fed97 | 2017-11-27 14:42:42 -0800 | [diff] [blame] | 1015 | VLOG("Telling statsCompanion that statsd is ready"); |
Bookatz | b487b55 | 2017-09-18 11:26:01 -0700 | [diff] [blame] | 1016 | statsCompanion->statsdReady(); |
| 1017 | } else { |
yro | 74fed97 | 2017-11-27 14:42:42 -0800 | [diff] [blame] | 1018 | VLOG("Could not access statsCompanion"); |
Bookatz | b487b55 | 2017-09-18 11:26:01 -0700 | [diff] [blame] | 1019 | } |
| 1020 | } |
| 1021 | |
Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame] | 1022 | Status StatsService::statsCompanionReady() { |
Jeff Sharkey | 6b64925 | 2018-04-16 09:50:22 -0600 | [diff] [blame] | 1023 | ENFORCE_UID(AID_SYSTEM); |
| 1024 | |
yro | 74fed97 | 2017-11-27 14:42:42 -0800 | [diff] [blame] | 1025 | VLOG("StatsService::statsCompanionReady was called"); |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 1026 | shared_ptr<IStatsCompanionService> statsCompanion = getStatsCompanionService(); |
Bookatz | b487b55 | 2017-09-18 11:26:01 -0700 | [diff] [blame] | 1027 | if (statsCompanion == nullptr) { |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 1028 | return exception(EX_NULL_POINTER, |
| 1029 | "StatsCompanion unavailable despite it contacting statsd."); |
Bookatz | b487b55 | 2017-09-18 11:26:01 -0700 | [diff] [blame] | 1030 | } |
yro | 74fed97 | 2017-11-27 14:42:42 -0800 | [diff] [blame] | 1031 | VLOG("StatsService::statsCompanionReady linking to statsCompanion."); |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 1032 | AIBinder_linkToDeath(statsCompanion->asBinder().get(), |
| 1033 | mStatsCompanionServiceDeathRecipient.get(), this); |
Chenjie Yu | e221920 | 2018-06-08 10:07:51 -0700 | [diff] [blame] | 1034 | mPullerManager->SetStatsCompanionService(statsCompanion); |
Yangster-mac | 932ecec | 2018-02-01 10:23:52 -0800 | [diff] [blame] | 1035 | mAnomalyAlarmMonitor->setStatsCompanionService(statsCompanion); |
| 1036 | mPeriodicAlarmMonitor->setStatsCompanionService(statsCompanion); |
Bookatz | b487b55 | 2017-09-18 11:26:01 -0700 | [diff] [blame] | 1037 | return Status::ok(); |
| 1038 | } |
| 1039 | |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 1040 | void StatsService::Startup() { |
| 1041 | mConfigManager->Startup(); |
Muhammad Qureshi | 844694b | 2019-04-05 10:10:40 -0700 | [diff] [blame] | 1042 | mProcessor->LoadActiveConfigsFromDisk(); |
Bookatz | 906a35c | 2017-09-20 15:26:44 -0700 | [diff] [blame] | 1043 | } |
| 1044 | |
Yangster-mac | 97e7d20 | 2018-10-09 11:05:39 -0700 | [diff] [blame] | 1045 | void StatsService::Terminate() { |
| 1046 | ALOGI("StatsService::Terminating"); |
| 1047 | if (mProcessor != nullptr) { |
Olivier Gaillard | 6c75ecd | 2019-02-20 09:57:33 +0000 | [diff] [blame] | 1048 | mProcessor->WriteDataToDisk(TERMINATION_SIGNAL_RECEIVED, FAST); |
Muhammad Qureshi | 844694b | 2019-04-05 10:10:40 -0700 | [diff] [blame] | 1049 | mProcessor->SaveActiveConfigsToDisk(getElapsedRealtimeNs()); |
Yangster-mac | 97e7d20 | 2018-10-09 11:05:39 -0700 | [diff] [blame] | 1050 | } |
| 1051 | } |
| 1052 | |
Yao Chen | 0f86186 | 2019-03-27 11:51:15 -0700 | [diff] [blame] | 1053 | // Test only interface!!! |
Yao Chen | 3ff3a49 | 2018-08-06 16:17:37 -0700 | [diff] [blame] | 1054 | void StatsService::OnLogEvent(LogEvent* event) { |
| 1055 | mProcessor->OnLogEvent(event); |
Yao Chen | a80e5c0 | 2018-09-04 13:55:29 -0700 | [diff] [blame] | 1056 | if (mShellSubscriber != nullptr) { |
| 1057 | mShellSubscriber->onLogEvent(*event); |
| 1058 | } |
Bookatz | 906a35c | 2017-09-20 15:26:44 -0700 | [diff] [blame] | 1059 | } |
| 1060 | |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 1061 | Status StatsService::getData(int64_t key, const int32_t callingUid, vector<int8_t>* output) { |
Jeffrey Huang | 04f948b | 2020-01-07 10:05:25 -0800 | [diff] [blame] | 1062 | ENFORCE_UID(AID_SYSTEM); |
Jeff Sharkey | 6b64925 | 2018-04-16 09:50:22 -0600 | [diff] [blame] | 1063 | |
Jeffrey Huang | 04f948b | 2020-01-07 10:05:25 -0800 | [diff] [blame] | 1064 | VLOG("StatsService::getData with Uid %i", callingUid); |
| 1065 | ConfigKey configKey(callingUid, key); |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 1066 | // TODO(b/149254662): Since libbinder_ndk uses int8_t instead of uint8_t, |
| 1067 | // there are inconsistencies with internal statsd logic. Instead of |
| 1068 | // modifying lots of files, we create a temporary output array of int8_t and |
| 1069 | // copy its data into output. This is a bad hack, but hopefully |
| 1070 | // libbinder_ndk will transition to using uint8_t soon: progress is tracked |
| 1071 | // in b/144957764. Same applies to StatsService::getMetadata. |
| 1072 | vector<uint8_t> unsignedOutput; |
Olivier Gaillard | 6c75ecd | 2019-02-20 09:57:33 +0000 | [diff] [blame] | 1073 | // The dump latency does not matter here since we do not include the current bucket, we do not |
| 1074 | // need to pull any new data anyhow. |
David Chen | 56ae0d9 | 2018-05-11 16:00:22 -0700 | [diff] [blame] | 1075 | mProcessor->onDumpReport(configKey, getElapsedRealtimeNs(), false /* include_current_bucket*/, |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 1076 | true /* erase_data */, GET_DATA_CALLED, FAST, &unsignedOutput); |
| 1077 | *output = vector<int8_t>(unsignedOutput.begin(), unsignedOutput.end()); |
Bookatz | 4f71629 | 2018-04-10 17:15:12 -0700 | [diff] [blame] | 1078 | return Status::ok(); |
yro | 31eb67b | 2017-10-24 13:33:21 -0700 | [diff] [blame] | 1079 | } |
| 1080 | |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 1081 | Status StatsService::getMetadata(vector<int8_t>* output) { |
Jeffrey Huang | 9613a97 | 2020-01-07 10:05:03 -0800 | [diff] [blame] | 1082 | ENFORCE_UID(AID_SYSTEM); |
Jeff Sharkey | 6b64925 | 2018-04-16 09:50:22 -0600 | [diff] [blame] | 1083 | |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 1084 | vector<uint8_t> unsignedOutput; |
| 1085 | StatsdStats::getInstance().dumpStats(&unsignedOutput, false); // Don't reset the counters. |
| 1086 | *output = vector<int8_t>(unsignedOutput.begin(), unsignedOutput.end()); |
Bookatz | 4f71629 | 2018-04-10 17:15:12 -0700 | [diff] [blame] | 1087 | return Status::ok(); |
David Chen | 2e8f380 | 2017-11-22 10:56:48 -0800 | [diff] [blame] | 1088 | } |
| 1089 | |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 1090 | Status StatsService::addConfiguration(int64_t key, const vector <int8_t>& config, |
Jeffrey Huang | 94eafe7 | 2020-01-07 15:18:43 -0800 | [diff] [blame] | 1091 | const int32_t callingUid) { |
| 1092 | ENFORCE_UID(AID_SYSTEM); |
Jeff Sharkey | 6b64925 | 2018-04-16 09:50:22 -0600 | [diff] [blame] | 1093 | |
Jeffrey Huang | 94eafe7 | 2020-01-07 15:18:43 -0800 | [diff] [blame] | 1094 | if (addConfigurationChecked(callingUid, key, config)) { |
David Chen | 661f791 | 2018-01-22 17:46:24 -0800 | [diff] [blame] | 1095 | return Status::ok(); |
| 1096 | } else { |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 1097 | return exception(EX_ILLEGAL_ARGUMENT, "Could not parse malformatted StatsdConfig."); |
David Chen | 661f791 | 2018-01-22 17:46:24 -0800 | [diff] [blame] | 1098 | } |
| 1099 | } |
| 1100 | |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 1101 | bool StatsService::addConfigurationChecked(int uid, int64_t key, const vector<int8_t>& config) { |
David Chen | 9fdd403 | 2018-03-20 14:38:56 -0700 | [diff] [blame] | 1102 | ConfigKey configKey(uid, key); |
| 1103 | StatsdConfig cfg; |
| 1104 | if (config.size() > 0) { // If the config is empty, skip parsing. |
| 1105 | if (!cfg.ParseFromArray(&config[0], config.size())) { |
| 1106 | return false; |
| 1107 | } |
| 1108 | } |
| 1109 | mConfigManager->UpdateConfig(configKey, cfg); |
| 1110 | return true; |
| 1111 | } |
| 1112 | |
Jeffrey Huang | ad21374 | 2019-12-16 13:50:06 -0800 | [diff] [blame] | 1113 | Status StatsService::removeDataFetchOperation(int64_t key, |
| 1114 | const int32_t callingUid) { |
| 1115 | ENFORCE_UID(AID_SYSTEM); |
| 1116 | ConfigKey configKey(callingUid, key); |
Bookatz | 4f71629 | 2018-04-10 17:15:12 -0700 | [diff] [blame] | 1117 | mConfigManager->RemoveConfigReceiver(configKey); |
| 1118 | return Status::ok(); |
David Chen | 661f791 | 2018-01-22 17:46:24 -0800 | [diff] [blame] | 1119 | } |
| 1120 | |
Jeff Sharkey | 6b64925 | 2018-04-16 09:50:22 -0600 | [diff] [blame] | 1121 | Status StatsService::setDataFetchOperation(int64_t key, |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 1122 | const shared_ptr<IPendingIntentRef>& pir, |
Jeffrey Huang | ad21374 | 2019-12-16 13:50:06 -0800 | [diff] [blame] | 1123 | const int32_t callingUid) { |
| 1124 | ENFORCE_UID(AID_SYSTEM); |
Jeff Sharkey | 6b64925 | 2018-04-16 09:50:22 -0600 | [diff] [blame] | 1125 | |
Jeffrey Huang | ad21374 | 2019-12-16 13:50:06 -0800 | [diff] [blame] | 1126 | ConfigKey configKey(callingUid, key); |
| 1127 | mConfigManager->SetConfigReceiver(configKey, pir); |
David Chen | 4894490 | 2018-05-03 10:29:11 -0700 | [diff] [blame] | 1128 | if (StorageManager::hasConfigMetricsReport(configKey)) { |
| 1129 | VLOG("StatsService::setDataFetchOperation marking configKey %s to dump reports on disk", |
| 1130 | configKey.ToString().c_str()); |
| 1131 | mProcessor->noteOnDiskData(configKey); |
| 1132 | } |
Bookatz | 4f71629 | 2018-04-10 17:15:12 -0700 | [diff] [blame] | 1133 | return Status::ok(); |
yro | 31eb67b | 2017-10-24 13:33:21 -0700 | [diff] [blame] | 1134 | } |
| 1135 | |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 1136 | Status StatsService::setActiveConfigsChangedOperation(const shared_ptr<IPendingIntentRef>& pir, |
Jeffrey Huang | 47537a1 | 2020-01-06 15:35:34 -0800 | [diff] [blame] | 1137 | const int32_t callingUid, |
Tej Singh | 2c9ef2a | 2019-01-22 11:33:51 -0800 | [diff] [blame] | 1138 | vector<int64_t>* output) { |
Jeffrey Huang | 47537a1 | 2020-01-06 15:35:34 -0800 | [diff] [blame] | 1139 | ENFORCE_UID(AID_SYSTEM); |
Tej Singh | 2c9ef2a | 2019-01-22 11:33:51 -0800 | [diff] [blame] | 1140 | |
Jeffrey Huang | 47537a1 | 2020-01-06 15:35:34 -0800 | [diff] [blame] | 1141 | mConfigManager->SetActiveConfigsChangedReceiver(callingUid, pir); |
Tej Singh | 6ede28b | 2019-01-29 17:06:54 -0800 | [diff] [blame] | 1142 | if (output != nullptr) { |
Jeffrey Huang | 47537a1 | 2020-01-06 15:35:34 -0800 | [diff] [blame] | 1143 | mProcessor->GetActiveConfigs(callingUid, *output); |
Tej Singh | 6ede28b | 2019-01-29 17:06:54 -0800 | [diff] [blame] | 1144 | } else { |
| 1145 | ALOGW("StatsService::setActiveConfigsChanged output was nullptr"); |
| 1146 | } |
Tej Singh | 2c9ef2a | 2019-01-22 11:33:51 -0800 | [diff] [blame] | 1147 | return Status::ok(); |
| 1148 | } |
| 1149 | |
Jeffrey Huang | 47537a1 | 2020-01-06 15:35:34 -0800 | [diff] [blame] | 1150 | Status StatsService::removeActiveConfigsChangedOperation(const int32_t callingUid) { |
| 1151 | ENFORCE_UID(AID_SYSTEM); |
Tej Singh | 2c9ef2a | 2019-01-22 11:33:51 -0800 | [diff] [blame] | 1152 | |
Jeffrey Huang | 47537a1 | 2020-01-06 15:35:34 -0800 | [diff] [blame] | 1153 | mConfigManager->RemoveActiveConfigsChangedReceiver(callingUid); |
Tej Singh | 2c9ef2a | 2019-01-22 11:33:51 -0800 | [diff] [blame] | 1154 | return Status::ok(); |
| 1155 | } |
| 1156 | |
Jeffrey Huang | 94eafe7 | 2020-01-07 15:18:43 -0800 | [diff] [blame] | 1157 | Status StatsService::removeConfiguration(int64_t key, const int32_t callingUid) { |
| 1158 | ENFORCE_UID(AID_SYSTEM); |
Jeff Sharkey | 6b64925 | 2018-04-16 09:50:22 -0600 | [diff] [blame] | 1159 | |
Jeffrey Huang | 94eafe7 | 2020-01-07 15:18:43 -0800 | [diff] [blame] | 1160 | ConfigKey configKey(callingUid, key); |
Bookatz | 4f71629 | 2018-04-10 17:15:12 -0700 | [diff] [blame] | 1161 | mConfigManager->RemoveConfig(configKey); |
Bookatz | 4f71629 | 2018-04-10 17:15:12 -0700 | [diff] [blame] | 1162 | return Status::ok(); |
yro | 31eb67b | 2017-10-24 13:33:21 -0700 | [diff] [blame] | 1163 | } |
| 1164 | |
Bookatz | c697797 | 2018-01-16 16:55:05 -0800 | [diff] [blame] | 1165 | Status StatsService::setBroadcastSubscriber(int64_t configId, |
| 1166 | int64_t subscriberId, |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 1167 | const shared_ptr<IPendingIntentRef>& pir, |
Jeffrey Huang | 4f2e6bd | 2020-01-06 16:24:45 -0800 | [diff] [blame] | 1168 | const int32_t callingUid) { |
| 1169 | ENFORCE_UID(AID_SYSTEM); |
Jeff Sharkey | 6b64925 | 2018-04-16 09:50:22 -0600 | [diff] [blame] | 1170 | |
Bookatz | c697797 | 2018-01-16 16:55:05 -0800 | [diff] [blame] | 1171 | VLOG("StatsService::setBroadcastSubscriber called."); |
Jeffrey Huang | 4f2e6bd | 2020-01-06 16:24:45 -0800 | [diff] [blame] | 1172 | ConfigKey configKey(callingUid, configId); |
Bookatz | 4f71629 | 2018-04-10 17:15:12 -0700 | [diff] [blame] | 1173 | SubscriberReporter::getInstance() |
Jeffrey Huang | 4f2e6bd | 2020-01-06 16:24:45 -0800 | [diff] [blame] | 1174 | .setBroadcastSubscriber(configKey, subscriberId, pir); |
Bookatz | 4f71629 | 2018-04-10 17:15:12 -0700 | [diff] [blame] | 1175 | return Status::ok(); |
Bookatz | c697797 | 2018-01-16 16:55:05 -0800 | [diff] [blame] | 1176 | } |
| 1177 | |
| 1178 | Status StatsService::unsetBroadcastSubscriber(int64_t configId, |
Jeff Sharkey | 6b64925 | 2018-04-16 09:50:22 -0600 | [diff] [blame] | 1179 | int64_t subscriberId, |
Jeffrey Huang | 4f2e6bd | 2020-01-06 16:24:45 -0800 | [diff] [blame] | 1180 | const int32_t callingUid) { |
| 1181 | ENFORCE_UID(AID_SYSTEM); |
Jeff Sharkey | 6b64925 | 2018-04-16 09:50:22 -0600 | [diff] [blame] | 1182 | |
Bookatz | c697797 | 2018-01-16 16:55:05 -0800 | [diff] [blame] | 1183 | VLOG("StatsService::unsetBroadcastSubscriber called."); |
Jeffrey Huang | 4f2e6bd | 2020-01-06 16:24:45 -0800 | [diff] [blame] | 1184 | ConfigKey configKey(callingUid, configId); |
Bookatz | 4f71629 | 2018-04-10 17:15:12 -0700 | [diff] [blame] | 1185 | SubscriberReporter::getInstance() |
| 1186 | .unsetBroadcastSubscriber(configKey, subscriberId); |
| 1187 | return Status::ok(); |
Bookatz | c697797 | 2018-01-16 16:55:05 -0800 | [diff] [blame] | 1188 | } |
| 1189 | |
yro | be6d7f9 | 2018-05-04 13:02:53 -0700 | [diff] [blame] | 1190 | Status StatsService::sendAppBreadcrumbAtom(int32_t label, int32_t state) { |
| 1191 | // Permission check not necessary as it's meant for applications to write to |
| 1192 | // statsd. |
| 1193 | android::util::stats_write(util::APP_BREADCRUMB_REPORTED, |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 1194 | (int32_t) AIBinder_getCallingUid(), label, |
yro | be6d7f9 | 2018-05-04 13:02:53 -0700 | [diff] [blame] | 1195 | state); |
| 1196 | return Status::ok(); |
| 1197 | } |
| 1198 | |
Tej Singh | 72a70a8 | 2020-02-26 23:46:29 -0800 | [diff] [blame^] | 1199 | Status StatsService::registerPullAtomCallback(int32_t uid, int32_t atomTag, int64_t coolDownMillis, |
| 1200 | int64_t timeoutMillis, |
| 1201 | const std::vector<int32_t>& additiveFields, |
| 1202 | const shared_ptr<IPullAtomCallback>& pullerCallback) { |
Tej Singh | 6a5c943 | 2019-10-11 11:07:06 -0700 | [diff] [blame] | 1203 | ENFORCE_UID(AID_SYSTEM); |
Tej Singh | b780251 | 2019-12-04 17:57:04 -0800 | [diff] [blame] | 1204 | VLOG("StatsService::registerPullAtomCallback called."); |
Tej Singh | 72a70a8 | 2020-02-26 23:46:29 -0800 | [diff] [blame^] | 1205 | mPullerManager->RegisterPullAtomCallback(uid, atomTag, MillisToNano(coolDownMillis), |
| 1206 | MillisToNano(timeoutMillis), additiveFields, |
Tej Singh | b780251 | 2019-12-04 17:57:04 -0800 | [diff] [blame] | 1207 | pullerCallback); |
| 1208 | return Status::ok(); |
| 1209 | } |
| 1210 | |
| 1211 | Status StatsService::registerNativePullAtomCallback(int32_t atomTag, int64_t coolDownNs, |
| 1212 | int64_t timeoutNs, const std::vector<int32_t>& additiveFields, |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 1213 | const shared_ptr<IPullAtomCallback>& pullerCallback) { |
Tej Singh | b780251 | 2019-12-04 17:57:04 -0800 | [diff] [blame] | 1214 | |
| 1215 | VLOG("StatsService::registerNativePullAtomCallback called."); |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 1216 | int32_t uid = AIBinder_getCallingUid(); |
Tej Singh | 6a5c943 | 2019-10-11 11:07:06 -0700 | [diff] [blame] | 1217 | mPullerManager->RegisterPullAtomCallback(uid, atomTag, coolDownNs, timeoutNs, additiveFields, |
| 1218 | pullerCallback); |
Tej Singh | 5918429 | 2019-10-11 11:07:06 -0700 | [diff] [blame] | 1219 | return Status::ok(); |
| 1220 | } |
| 1221 | |
Tej Singh | fa1c137 | 2019-12-05 20:36:54 -0800 | [diff] [blame] | 1222 | Status StatsService::unregisterPullAtomCallback(int32_t uid, int32_t atomTag) { |
| 1223 | ENFORCE_UID(AID_SYSTEM); |
| 1224 | VLOG("StatsService::unregisterPullAtomCallback called."); |
| 1225 | mPullerManager->UnregisterPullAtomCallback(uid, atomTag); |
| 1226 | return Status::ok(); |
| 1227 | } |
| 1228 | |
Tej Singh | 8f35860 | 2020-01-15 16:05:39 -0800 | [diff] [blame] | 1229 | Status StatsService::unregisterNativePullAtomCallback(int32_t atomTag) { |
| 1230 | VLOG("StatsService::unregisterNativePullAtomCallback called."); |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 1231 | int32_t uid = AIBinder_getCallingUid(); |
Tej Singh | 8f35860 | 2020-01-15 16:05:39 -0800 | [diff] [blame] | 1232 | mPullerManager->UnregisterPullAtomCallback(uid, atomTag); |
| 1233 | return Status::ok(); |
| 1234 | } |
| 1235 | |
Jeff Hamilton | fa2f91c | 2019-03-22 00:25:02 -0400 | [diff] [blame] | 1236 | Status StatsService::getRegisteredExperimentIds(std::vector<int64_t>* experimentIdsOut) { |
Jeffrey Huang | 80c9a97 | 2020-01-07 10:04:27 -0800 | [diff] [blame] | 1237 | ENFORCE_UID(AID_SYSTEM); |
Jeff Hamilton | fa2f91c | 2019-03-22 00:25:02 -0400 | [diff] [blame] | 1238 | // TODO: add verifier permission |
| 1239 | |
Jonathan Nguyen | 703c42f | 2020-02-04 15:54:26 -0800 | [diff] [blame] | 1240 | experimentIdsOut->clear(); |
Jeff Hamilton | fa2f91c | 2019-03-22 00:25:02 -0400 | [diff] [blame] | 1241 | // Read the latest train info |
Jonathan Nguyen | 703c42f | 2020-02-04 15:54:26 -0800 | [diff] [blame] | 1242 | vector<InstallTrainInfo> trainInfoList = StorageManager::readAllTrainInfo(); |
| 1243 | if (trainInfoList.empty()) { |
Jeff Hamilton | fa2f91c | 2019-03-22 00:25:02 -0400 | [diff] [blame] | 1244 | // No train info means no experiment IDs, return an empty list |
Jeff Hamilton | fa2f91c | 2019-03-22 00:25:02 -0400 | [diff] [blame] | 1245 | return Status::ok(); |
| 1246 | } |
| 1247 | |
| 1248 | // Copy the experiment IDs to the out vector |
Jonathan Nguyen | 703c42f | 2020-02-04 15:54:26 -0800 | [diff] [blame] | 1249 | for (InstallTrainInfo& trainInfo : trainInfoList) { |
| 1250 | experimentIdsOut->insert(experimentIdsOut->end(), |
| 1251 | trainInfo.experimentIds.begin(), |
| 1252 | trainInfo.experimentIds.end()); |
| 1253 | } |
Chenjie Yu | 6b1667c | 2019-01-18 10:09:33 -0800 | [diff] [blame] | 1254 | return Status::ok(); |
| 1255 | } |
| 1256 | |
Ruchir Rastogi | e449b0c | 2020-02-10 17:40:09 -0800 | [diff] [blame] | 1257 | |
| 1258 | void StatsService::statsCompanionServiceDied(void* cookie) { |
| 1259 | auto thiz = static_cast<StatsService*>(cookie); |
| 1260 | thiz->statsCompanionServiceDiedImpl(); |
| 1261 | } |
| 1262 | |
| 1263 | void StatsService::statsCompanionServiceDiedImpl() { |
Chenjie Yu | aa5b201 | 2018-03-21 13:53:15 -0700 | [diff] [blame] | 1264 | ALOGW("statscompanion service died"); |
Yangster-mac | 892f3d3 | 2018-05-02 14:16:48 -0700 | [diff] [blame] | 1265 | StatsdStats::getInstance().noteSystemServerRestart(getWallClockSec()); |
| 1266 | if (mProcessor != nullptr) { |
Howard Ro | e60992b | 2018-08-30 14:37:29 -0700 | [diff] [blame] | 1267 | ALOGW("Reset statsd upon system server restarts."); |
Tej Singh | f53d445 | 2019-05-09 18:17:59 -0700 | [diff] [blame] | 1268 | int64_t systemServerRestartNs = getElapsedRealtimeNs(); |
| 1269 | ProtoOutputStream proto; |
| 1270 | mProcessor->WriteActiveConfigsToProtoOutputStream(systemServerRestartNs, |
| 1271 | STATSCOMPANION_DIED, &proto); |
| 1272 | |
Olivier Gaillard | 6c75ecd | 2019-02-20 09:57:33 +0000 | [diff] [blame] | 1273 | mProcessor->WriteDataToDisk(STATSCOMPANION_DIED, FAST); |
Yangster-mac | 892f3d3 | 2018-05-02 14:16:48 -0700 | [diff] [blame] | 1274 | mProcessor->resetConfigs(); |
Tej Singh | f53d445 | 2019-05-09 18:17:59 -0700 | [diff] [blame] | 1275 | |
| 1276 | std::string serializedActiveConfigs; |
| 1277 | if (proto.serializeToString(&serializedActiveConfigs)) { |
| 1278 | ActiveConfigList activeConfigs; |
| 1279 | if (activeConfigs.ParseFromString(serializedActiveConfigs)) { |
| 1280 | mProcessor->SetConfigsActiveState(activeConfigs, systemServerRestartNs); |
| 1281 | } |
| 1282 | } |
Yangster-mac | 892f3d3 | 2018-05-02 14:16:48 -0700 | [diff] [blame] | 1283 | } |
Chenjie Yu | aa5b201 | 2018-03-21 13:53:15 -0700 | [diff] [blame] | 1284 | mAnomalyAlarmMonitor->setStatsCompanionService(nullptr); |
| 1285 | mPeriodicAlarmMonitor->setStatsCompanionService(nullptr); |
Chenjie Yu | e221920 | 2018-06-08 10:07:51 -0700 | [diff] [blame] | 1286 | mPullerManager->SetStatsCompanionService(nullptr); |
yro | 31eb67b | 2017-10-24 13:33:21 -0700 | [diff] [blame] | 1287 | } |
| 1288 | |
Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame] | 1289 | } // namespace statsd |
| 1290 | } // namespace os |
| 1291 | } // namespace android |