blob: f072c9c7b121588d718396579851a03d0b65ad42 [file] [log] [blame]
Joe Onorato5dcbc6c2017-08-29 15:13:58 -07001/*
yro0feae942017-11-15 14:38:48 -08002 * Copyright (C) 2017 The Android Open Source Project
Joe Onorato5dcbc6c2017-08-29 15:13:58 -07003 *
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 Singh484524a2018-02-01 15:10:05 -080017#define DEBUG false // STOPSHIP if true
Joe Onorato9fc9edf2017-10-15 20:08:52 -070018#include "Log.h"
Joe Onorato5dcbc6c2017-08-29 15:13:58 -070019
20#include "StatsService.h"
Yangster-mac330af582018-02-08 15:24:38 -080021#include "stats_log_util.h"
Yao Chen8d9989b2017-11-18 18:54:50 -080022#include "android-base/stringprintf.h"
David Chenadaf8b32017-11-03 15:42:08 -070023#include "config/ConfigKey.h"
24#include "config/ConfigManager.h"
Yao Chenb3561512017-11-21 18:07:17 -080025#include "guardrail/StatsdStats.h"
yro947fbce2017-11-15 22:50:23 -080026#include "storage/StorageManager.h"
Bookatzc6977972018-01-16 16:55:05 -080027#include "subscriber/SubscriberReporter.h"
Joe Onorato5dcbc6c2017-08-29 15:13:58 -070028
David Chen0656b7a2017-09-13 15:53:39 -070029#include <android-base/file.h>
Jeff Sharkey6b649252018-04-16 09:50:22 -060030#include <android-base/stringprintf.h>
Tej Singh53f9dee2019-04-30 17:45:54 -070031#include <android-base/strings.h>
Joe Onorato5dcbc6c2017-08-29 15:13:58 -070032#include <binder/IPCThreadState.h>
33#include <binder/IServiceManager.h>
Jeff Sharkey6b649252018-04-16 09:50:22 -060034#include <binder/PermissionController.h>
Chenjie Yu6b1667c2019-01-18 10:09:33 -080035#include <cutils/multiuser.h>
yro87d983c2017-11-14 21:31:43 -080036#include <dirent.h>
David Chen0656b7a2017-09-13 15:53:39 -070037#include <frameworks/base/cmds/statsd/src/statsd_config.pb.h>
Max Dashouk11e0d402019-05-16 16:58:07 -070038#include <frameworks/base/cmds/statsd/src/uid_data.pb.h>
Joe Onorato5dcbc6c2017-08-29 15:13:58 -070039#include <private/android_filesystem_config.h>
Bookatzb223c4e2018-02-01 15:35:04 -080040#include <statslog.h>
Joe Onorato5dcbc6c2017-08-29 15:13:58 -070041#include <stdio.h>
Yao Chen482d2722017-09-12 13:25:43 -070042#include <stdlib.h>
Joe Onorato9fc9edf2017-10-15 20:08:52 -070043#include <sys/system_properties.h>
Yao Chenef99c4f2017-09-22 16:26:54 -070044#include <unistd.h>
Yao Chena80e5c02018-09-04 13:55:29 -070045#include <utils/Looper.h>
46#include <utils/String16.h>
47#include <chrono>
Joe Onorato5dcbc6c2017-08-29 15:13:58 -070048
49using namespace android;
50
Jeff Sharkey6b649252018-04-16 09:50:22 -060051using android::base::StringPrintf;
Bookatzff71cad2018-09-20 17:17:49 -070052using android::util::FIELD_COUNT_REPEATED;
Chenjie Yu6b1667c2019-01-18 10:09:33 -080053using android::util::FIELD_TYPE_INT64;
Bookatzff71cad2018-09-20 17:17:49 -070054using android::util::FIELD_TYPE_MESSAGE;
Joe Onorato99598ee2019-02-11 15:55:13 +000055using android::util::ProtoReader;
Jeff Sharkey6b649252018-04-16 09:50:22 -060056
Bookatz906a35c2017-09-20 15:26:44 -070057namespace android {
58namespace os {
59namespace statsd {
60
David Chenadaf8b32017-11-03 15:42:08 -070061constexpr const char* kPermissionDump = "android.permission.DUMP";
Jeff Sharkey6b649252018-04-16 09:50:22 -060062constexpr const char* kPermissionUsage = "android.permission.PACKAGE_USAGE_STATS";
63
64constexpr const char* kOpUsage = "android:get_usage_stats";
65
yro03faf092017-12-12 00:17:50 -080066#define STATS_SERVICE_DIR "/data/misc/stats-service"
David Chenadaf8b32017-11-03 15:42:08 -070067
Bookatzff71cad2018-09-20 17:17:49 -070068// for StatsDataDumpProto
69const int FIELD_ID_REPORTS_LIST = 1;
70
Jeff Sharkey6b649252018-04-16 09:50:22 -060071static binder::Status ok() {
72 return binder::Status::ok();
73}
74
75static binder::Status exception(uint32_t code, const std::string& msg) {
76 ALOGE("%s (%d)", msg.c_str(), code);
77 return binder::Status::fromExceptionCode(code, String8(msg.c_str()));
78}
79
80binder::Status checkUid(uid_t expectedUid) {
81 uid_t uid = IPCThreadState::self()->getCallingUid();
82 if (uid == expectedUid || uid == AID_ROOT) {
83 return ok();
84 } else {
85 return exception(binder::Status::EX_SECURITY,
86 StringPrintf("UID %d is not expected UID %d", uid, expectedUid));
87 }
88}
89
90binder::Status checkDumpAndUsageStats(const String16& packageName) {
91 pid_t pid = IPCThreadState::self()->getCallingPid();
92 uid_t uid = IPCThreadState::self()->getCallingUid();
93
94 // Root, system, and shell always have access
95 if (uid == AID_ROOT || uid == AID_SYSTEM || uid == AID_SHELL) {
96 return ok();
97 }
98
99 // Caller must be granted these permissions
100 if (!checkCallingPermission(String16(kPermissionDump))) {
101 return exception(binder::Status::EX_SECURITY,
102 StringPrintf("UID %d / PID %d lacks permission %s", uid, pid, kPermissionDump));
103 }
104 if (!checkCallingPermission(String16(kPermissionUsage))) {
105 return exception(binder::Status::EX_SECURITY,
106 StringPrintf("UID %d / PID %d lacks permission %s", uid, pid, kPermissionUsage));
107 }
108
109 // Caller must also have usage stats op granted
110 PermissionController pc;
111 switch (pc.noteOp(String16(kOpUsage), uid, packageName)) {
112 case PermissionController::MODE_ALLOWED:
113 case PermissionController::MODE_DEFAULT:
114 return ok();
115 default:
116 return exception(binder::Status::EX_SECURITY,
117 StringPrintf("UID %d / PID %d lacks app-op %s", uid, pid, kOpUsage));
118 }
119}
120
121#define ENFORCE_UID(uid) { \
122 binder::Status status = checkUid((uid)); \
123 if (!status.isOk()) { \
124 return status; \
125 } \
126}
127
128#define ENFORCE_DUMP_AND_USAGE_STATS(packageName) { \
129 binder::Status status = checkDumpAndUsageStats(packageName); \
130 if (!status.isOk()) { \
131 return status; \
132 } \
133}
134
Yao Chen0f861862019-03-27 11:51:15 -0700135StatsService::StatsService(const sp<Looper>& handlerLooper, shared_ptr<LogEventQueue> queue)
136 : mAnomalyAlarmMonitor(new AlarmMonitor(
137 MIN_DIFF_TO_UPDATE_REGISTERED_ALARM_SECS,
138 [](const sp<IStatsCompanionService>& sc, int64_t timeMillis) {
139 if (sc != nullptr) {
140 sc->setAnomalyAlarm(timeMillis);
141 StatsdStats::getInstance().noteRegisteredAnomalyAlarmChanged();
142 }
143 },
144 [](const sp<IStatsCompanionService>& sc) {
145 if (sc != nullptr) {
146 sc->cancelAnomalyAlarm();
147 StatsdStats::getInstance().noteRegisteredAnomalyAlarmChanged();
148 }
149 })),
150 mPeriodicAlarmMonitor(new AlarmMonitor(
151 MIN_DIFF_TO_UPDATE_REGISTERED_ALARM_SECS,
152 [](const sp<IStatsCompanionService>& sc, int64_t timeMillis) {
153 if (sc != nullptr) {
154 sc->setAlarmForSubscriberTriggering(timeMillis);
155 StatsdStats::getInstance().noteRegisteredPeriodicAlarmChanged();
156 }
157 },
158 [](const sp<IStatsCompanionService>& sc) {
159 if (sc != nullptr) {
160 sc->cancelAlarmForSubscriberTriggering();
161 StatsdStats::getInstance().noteRegisteredPeriodicAlarmChanged();
162 }
163 })),
164 mEventQueue(queue) {
Yao Chen4ce07292019-02-13 13:06:36 -0800165 mUidMap = UidMap::getInstance();
Chenjie Yue2219202018-06-08 10:07:51 -0700166 mPullerManager = new StatsPullerManager();
Chenjie Yu80f91122018-01-31 20:24:50 -0800167 StatsPuller::SetUidMap(mUidMap);
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700168 mConfigManager = new ConfigManager();
Chenjie Yue2219202018-06-08 10:07:51 -0700169 mProcessor = new StatsLogProcessor(
170 mUidMap, mPullerManager, mAnomalyAlarmMonitor, mPeriodicAlarmMonitor,
Chenjie Yuc7939cb2019-02-04 17:25:45 -0800171 getElapsedRealtimeNs(),
172 [this](const ConfigKey& key) {
Chenjie Yue2219202018-06-08 10:07:51 -0700173 sp<IStatsCompanionService> sc = getStatsCompanionService();
174 auto receiver = mConfigManager->GetConfigReceiver(key);
175 if (sc == nullptr) {
176 VLOG("Could not find StatsCompanionService");
177 return false;
178 } else if (receiver == nullptr) {
179 VLOG("Statscompanion could not find a broadcast receiver for %s",
180 key.ToString().c_str());
181 return false;
182 } else {
183 sc->sendDataBroadcast(receiver, mProcessor->getLastReportTimeNs(key));
184 return true;
185 }
Tej Singh6ede28b2019-01-29 17:06:54 -0800186 },
187 [this](const int& uid, const vector<int64_t>& activeConfigs) {
188 auto receiver = mConfigManager->GetActiveConfigsChangedReceiver(uid);
189 sp<IStatsCompanionService> sc = getStatsCompanionService();
190 if (sc == nullptr) {
191 VLOG("Could not access statsCompanion");
192 return false;
193 } else if (receiver == nullptr) {
194 VLOG("Could not find receiver for uid %d", uid);
195 return false;
196 } else {
197 sc->sendActiveConfigsChangedBroadcast(receiver, activeConfigs);
198 VLOG("StatsService::active configs broadcast succeeded for uid %d" , uid);
199 return true;
200 }
Chenjie Yue2219202018-06-08 10:07:51 -0700201 });
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700202
203 mConfigManager->AddListener(mProcessor);
204
205 init_system_properties();
Yao Chen0f861862019-03-27 11:51:15 -0700206
207 if (mEventQueue != nullptr) {
208 std::thread pushedEventThread([this] { readLogs(); });
209 pushedEventThread.detach();
210 }
Joe Onorato5dcbc6c2017-08-29 15:13:58 -0700211}
212
Yao Chenef99c4f2017-09-22 16:26:54 -0700213StatsService::~StatsService() {
Joe Onorato5dcbc6c2017-08-29 15:13:58 -0700214}
215
Yao Chen0f861862019-03-27 11:51:15 -0700216/* Runs on a dedicated thread to process pushed events. */
217void StatsService::readLogs() {
218 // Read forever..... long live statsd
219 while (1) {
220 // Block until an event is available.
221 auto event = mEventQueue->waitPop();
222 // Pass it to StatsLogProcess to all configs/metrics
223 // At this point, the LogEventQueue is not blocked, so that the socketListener
224 // can read events from the socket and write to buffer to avoid data drop.
225 mProcessor->OnLogEvent(event.get());
226 // The ShellSubscriber is only used by shell for local debugging.
227 if (mShellSubscriber != nullptr) {
228 mShellSubscriber->onLogEvent(*event);
229 }
230 }
231}
232
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700233void StatsService::init_system_properties() {
234 mEngBuild = false;
235 const prop_info* buildType = __system_property_find("ro.build.type");
236 if (buildType != NULL) {
237 __system_property_read_callback(buildType, init_build_type_callback, this);
238 }
David Chen0656b7a2017-09-13 15:53:39 -0700239}
240
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700241void StatsService::init_build_type_callback(void* cookie, const char* /*name*/, const char* value,
242 uint32_t serial) {
Yao Chen729093d2017-10-16 10:33:26 -0700243 if (0 == strcmp("eng", value) || 0 == strcmp("userdebug", value)) {
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700244 reinterpret_cast<StatsService*>(cookie)->mEngBuild = true;
245 }
246}
247
248/**
249 * Implement our own because the default binder implementation isn't
250 * properly handling SHELL_COMMAND_TRANSACTION.
251 */
Yao Chenef99c4f2017-09-22 16:26:54 -0700252status_t StatsService::onTransact(uint32_t code, const Parcel& data, Parcel* reply,
253 uint32_t flags) {
Joe Onorato2cbc2cc2017-08-30 17:03:23 -0700254 switch (code) {
255 case SHELL_COMMAND_TRANSACTION: {
256 int in = data.readFileDescriptor();
257 int out = data.readFileDescriptor();
258 int err = data.readFileDescriptor();
259 int argc = data.readInt32();
260 Vector<String8> args;
261 for (int i = 0; i < argc && data.dataAvail() > 0; i++) {
262 args.add(String8(data.readString16()));
263 }
Yao Chenef99c4f2017-09-22 16:26:54 -0700264 sp<IShellCallback> shellCallback = IShellCallback::asInterface(data.readStrongBinder());
265 sp<IResultReceiver> resultReceiver =
266 IResultReceiver::asInterface(data.readStrongBinder());
Joe Onorato2cbc2cc2017-08-30 17:03:23 -0700267
Yao Chena80e5c02018-09-04 13:55:29 -0700268 err = command(in, out, err, args, resultReceiver);
Tej Singhc9250ce2019-09-20 19:28:53 -0700269 if (resultReceiver != nullptr) {
270 resultReceiver->send(err);
271 }
Joe Onorato2cbc2cc2017-08-30 17:03:23 -0700272 return NO_ERROR;
273 }
Yao Chenef99c4f2017-09-22 16:26:54 -0700274 default: { return BnStatsManager::onTransact(code, data, reply, flags); }
Joe Onorato2cbc2cc2017-08-30 17:03:23 -0700275 }
276}
277
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700278/**
Bookatzff71cad2018-09-20 17:17:49 -0700279 * Write data from statsd.
280 * Format for statsdStats: adb shell dumpsys stats --metadata [-v] [--proto]
281 * Format for data report: adb shell dumpsys stats [anything other than --metadata] [--proto]
282 * Anything ending in --proto will be in proto format.
283 * Anything without --metadata as the first argument will be report information.
284 * (bugreports call "adb shell dumpsys stats --dump-priority NORMAL -a --proto")
285 * TODO: Come up with a more robust method of enacting <serviceutils/PriorityDumper.h>.
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700286 */
Yao Chenef99c4f2017-09-22 16:26:54 -0700287status_t StatsService::dump(int fd, const Vector<String16>& args) {
Tej Singhdd83d702018-04-10 17:24:50 -0700288 if (!checkCallingPermission(String16(kPermissionDump))) {
289 return PERMISSION_DENIED;
290 }
Bookatzff71cad2018-09-20 17:17:49 -0700291 int lastArg = args.size() - 1;
292 bool asProto = false;
293 if (lastArg >= 0 && !args[lastArg].compare(String16("--proto"))) { // last argument
294 asProto = true;
295 lastArg--;
Yao Chen884c8c12018-01-26 10:36:25 -0800296 }
Bookatzff71cad2018-09-20 17:17:49 -0700297 if (args.size() > 0 && !args[0].compare(String16("--metadata"))) { // first argument
298 // Request is to dump statsd stats.
299 bool verbose = false;
300 if (lastArg >= 0 && !args[lastArg].compare(String16("-v"))) {
301 verbose = true;
302 lastArg--;
303 }
304 dumpStatsdStats(fd, verbose, asProto);
305 } else {
306 // Request is to dump statsd report data.
307 if (asProto) {
308 dumpIncidentSection(fd);
309 } else {
310 dprintf(fd, "Non-proto format of stats data dump not available; see proto version.\n");
311 }
Tej Singh41b3f9a2018-04-03 17:06:35 -0700312 }
Yao Chen884c8c12018-01-26 10:36:25 -0800313
Joe Onorato5dcbc6c2017-08-29 15:13:58 -0700314 return NO_ERROR;
315}
316
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700317/**
Tej Singh41b3f9a2018-04-03 17:06:35 -0700318 * Write debugging data about statsd in text or proto format.
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700319 */
Bookatzff71cad2018-09-20 17:17:49 -0700320void StatsService::dumpStatsdStats(int out, bool verbose, bool proto) {
Tej Singh41b3f9a2018-04-03 17:06:35 -0700321 if (proto) {
322 vector<uint8_t> data;
323 StatsdStats::getInstance().dumpStats(&data, false); // does not reset statsdStats.
324 for (size_t i = 0; i < data.size(); i ++) {
Yao Chena80e5c02018-09-04 13:55:29 -0700325 dprintf(out, "%c", data[i]);
Tej Singh41b3f9a2018-04-03 17:06:35 -0700326 }
327 } else {
328 StatsdStats::getInstance().dumpStats(out);
329 mProcessor->dumpStates(out, verbose);
330 }
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700331}
332
333/**
Bookatzff71cad2018-09-20 17:17:49 -0700334 * Write stats report data in StatsDataDumpProto incident section format.
335 */
336void StatsService::dumpIncidentSection(int out) {
337 ProtoOutputStream proto;
338 for (const ConfigKey& configKey : mConfigManager->GetAllConfigKeys()) {
339 uint64_t reportsListToken =
340 proto.start(FIELD_TYPE_MESSAGE | FIELD_COUNT_REPEATED | FIELD_ID_REPORTS_LIST);
341 mProcessor->onDumpReport(configKey, getElapsedRealtimeNs(),
342 true /* includeCurrentBucket */, false /* erase_data */,
Olivier Gaillard6c75ecd2019-02-20 09:57:33 +0000343 ADB_DUMP,
344 FAST,
345 &proto);
Bookatzff71cad2018-09-20 17:17:49 -0700346 proto.end(reportsListToken);
347 proto.flush(out);
Bookatzc71d9012018-12-19 12:28:38 -0800348 proto.clear();
Bookatzff71cad2018-09-20 17:17:49 -0700349 }
350}
351
352/**
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700353 * Implementation of the adb shell cmd stats command.
354 */
Yao Chena80e5c02018-09-04 13:55:29 -0700355status_t StatsService::command(int in, int out, int err, Vector<String8>& args,
356 sp<IResultReceiver> resultReceiver) {
Jeff Sharkey6b649252018-04-16 09:50:22 -0600357 uid_t uid = IPCThreadState::self()->getCallingUid();
358 if (uid != AID_ROOT && uid != AID_SHELL) {
359 return PERMISSION_DENIED;
360 }
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700361
362 const int argCount = args.size();
363 if (argCount >= 1) {
364 // adb shell cmd stats config ...
David Chen0656b7a2017-09-13 15:53:39 -0700365 if (!args[0].compare(String8("config"))) {
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700366 return cmd_config(in, out, err, args);
David Chen0656b7a2017-09-13 15:53:39 -0700367 }
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700368
David Chende701692017-10-05 13:16:02 -0700369 if (!args[0].compare(String8("print-uid-map"))) {
Yao Chend10f7b12017-12-18 12:53:50 -0800370 return cmd_print_uid_map(out, args);
David Chende701692017-10-05 13:16:02 -0700371 }
Yao Chen729093d2017-10-16 10:33:26 -0700372
373 if (!args[0].compare(String8("dump-report"))) {
Bookatzff71cad2018-09-20 17:17:49 -0700374 return cmd_dump_report(out, args);
Yao Chen729093d2017-10-16 10:33:26 -0700375 }
David Chen1481fe12017-10-16 13:16:34 -0700376
377 if (!args[0].compare(String8("pull-source")) && args.size() > 1) {
378 return cmd_print_pulled_metrics(out, args);
379 }
David Chenadaf8b32017-11-03 15:42:08 -0700380
381 if (!args[0].compare(String8("send-broadcast"))) {
David Chen1d7b0cd2017-11-15 14:20:04 -0800382 return cmd_trigger_broadcast(out, args);
383 }
384
385 if (!args[0].compare(String8("print-stats"))) {
Yao Chenb3561512017-11-21 18:07:17 -0800386 return cmd_print_stats(out, args);
David Chenadaf8b32017-11-03 15:42:08 -0700387 }
yro87d983c2017-11-14 21:31:43 -0800388
Yao Chen8d9989b2017-11-18 18:54:50 -0800389 if (!args[0].compare(String8("meminfo"))) {
390 return cmd_dump_memory_info(out);
391 }
yro947fbce2017-11-15 22:50:23 -0800392
393 if (!args[0].compare(String8("write-to-disk"))) {
394 return cmd_write_data_to_disk(out);
395 }
Bookatzb223c4e2018-02-01 15:35:04 -0800396
David Chen0b5c90c2018-01-25 16:51:49 -0800397 if (!args[0].compare(String8("log-app-breadcrumb"))) {
398 return cmd_log_app_breadcrumb(out, args);
Bookatzb223c4e2018-02-01 15:35:04 -0800399 }
Chenjie Yufa22d652018-02-05 14:37:48 -0800400
Tej Singh53f9dee2019-04-30 17:45:54 -0700401 if (!args[0].compare(String8("log-binary-push"))) {
402 return cmd_log_binary_push(out, args);
403 }
404
Chenjie Yufa22d652018-02-05 14:37:48 -0800405 if (!args[0].compare(String8("clear-puller-cache"))) {
406 return cmd_clear_puller_cache(out);
407 }
Yao Chen876889c2018-05-02 11:16:16 -0700408
409 if (!args[0].compare(String8("print-logs"))) {
410 return cmd_print_logs(out, args);
411 }
Tej Singh6ede28b2019-01-29 17:06:54 -0800412 if (!args[0].compare(String8("send-active-configs"))) {
413 return cmd_trigger_active_config_broadcast(out, args);
414 }
Yao Chena80e5c02018-09-04 13:55:29 -0700415 if (!args[0].compare(String8("data-subscribe"))) {
Tej Singhc9250ce2019-09-20 19:28:53 -0700416 {
417 std::lock_guard<std::mutex> lock(mShellSubscriberMutex);
418 if (mShellSubscriber == nullptr) {
419 mShellSubscriber = new ShellSubscriber(mUidMap, mPullerManager);
420 }
Yao Chena80e5c02018-09-04 13:55:29 -0700421 }
Yao Chen35cb8d62019-01-03 16:49:14 -0800422 int timeoutSec = -1;
423 if (argCount >= 2) {
424 timeoutSec = atoi(args[1].c_str());
425 }
Tej Singhc9250ce2019-09-20 19:28:53 -0700426 if (resultReceiver == nullptr) {
427 ALOGI("Null resultReceiver given, no subscription will be started");
428 return UNEXPECTED_NULL;
429 }
Yao Chen35cb8d62019-01-03 16:49:14 -0800430 mShellSubscriber->startNewSubscription(in, out, resultReceiver, timeoutSec);
Yao Chena80e5c02018-09-04 13:55:29 -0700431 return NO_ERROR;
432 }
Joe Onorato2cbc2cc2017-08-30 17:03:23 -0700433 }
Joe Onorato2cbc2cc2017-08-30 17:03:23 -0700434
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700435 print_cmd_help(out);
Joe Onorato2cbc2cc2017-08-30 17:03:23 -0700436 return NO_ERROR;
437}
438
Yao Chena80e5c02018-09-04 13:55:29 -0700439void StatsService::print_cmd_help(int out) {
440 dprintf(out,
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700441 "usage: adb shell cmd stats print-stats-log [tag_required] "
442 "[timestamp_nsec_optional]\n");
Yao Chena80e5c02018-09-04 13:55:29 -0700443 dprintf(out, "\n");
444 dprintf(out, "\n");
445 dprintf(out, "usage: adb shell cmd stats meminfo\n");
446 dprintf(out, "\n");
447 dprintf(out, " Prints the malloc debug information. You need to run the following first: \n");
448 dprintf(out, " # adb shell stop\n");
449 dprintf(out, " # adb shell setprop libc.debug.malloc.program statsd \n");
450 dprintf(out, " # adb shell setprop libc.debug.malloc.options backtrace \n");
451 dprintf(out, " # adb shell start\n");
452 dprintf(out, "\n");
453 dprintf(out, "\n");
454 dprintf(out, "usage: adb shell cmd stats print-uid-map [PKG]\n");
455 dprintf(out, "\n");
456 dprintf(out, " Prints the UID, app name, version mapping.\n");
457 dprintf(out, " PKG Optional package name to print the uids of the package\n");
458 dprintf(out, "\n");
459 dprintf(out, "\n");
460 dprintf(out, "usage: adb shell cmd stats pull-source [int] \n");
461 dprintf(out, "\n");
462 dprintf(out, " Prints the output of a pulled metrics source (int indicates source)\n");
463 dprintf(out, "\n");
464 dprintf(out, "\n");
465 dprintf(out, "usage: adb shell cmd stats write-to-disk \n");
466 dprintf(out, "\n");
467 dprintf(out, " Flushes all data on memory to disk.\n");
468 dprintf(out, "\n");
469 dprintf(out, "\n");
470 dprintf(out, "usage: adb shell cmd stats log-app-breadcrumb [UID] LABEL STATE\n");
471 dprintf(out, " Writes an AppBreadcrumbReported event to the statslog buffer.\n");
472 dprintf(out, " UID The uid to use. It is only possible to pass a UID\n");
473 dprintf(out, " parameter on eng builds. If UID is omitted the calling\n");
474 dprintf(out, " uid is used.\n");
475 dprintf(out, " LABEL Integer in [0, 15], as per atoms.proto.\n");
476 dprintf(out, " STATE Integer in [0, 3], as per atoms.proto.\n");
477 dprintf(out, "\n");
478 dprintf(out, "\n");
Tej Singh53f9dee2019-04-30 17:45:54 -0700479 dprintf(out,
480 "usage: adb shell cmd stats log-binary-push NAME VERSION STAGING ROLLBACK_ENABLED "
481 "LOW_LATENCY STATE EXPERIMENT_IDS\n");
482 dprintf(out, " Log a binary push state changed event.\n");
483 dprintf(out, " NAME The train name.\n");
484 dprintf(out, " VERSION The train version code.\n");
485 dprintf(out, " STAGING If this train requires a restart.\n");
486 dprintf(out, " ROLLBACK_ENABLED If rollback should be enabled for this install.\n");
487 dprintf(out, " LOW_LATENCY If the train requires low latency monitoring.\n");
488 dprintf(out, " STATE The status of the train push.\n");
489 dprintf(out, " Integer value of the enum in atoms.proto.\n");
490 dprintf(out, " EXPERIMENT_IDS Comma separated list of experiment ids.\n");
491 dprintf(out, " Leave blank for none.\n");
492 dprintf(out, "\n");
493 dprintf(out, "\n");
Yao Chena80e5c02018-09-04 13:55:29 -0700494 dprintf(out, "usage: adb shell cmd stats config remove [UID] [NAME]\n");
495 dprintf(out, "usage: adb shell cmd stats config update [UID] NAME\n");
496 dprintf(out, "\n");
497 dprintf(out, " Adds, updates or removes a configuration. The proto should be in\n");
498 dprintf(out, " wire-encoded protobuf format and passed via stdin. If no UID and name is\n");
499 dprintf(out, " provided, then all configs will be removed from memory and disk.\n");
500 dprintf(out, "\n");
501 dprintf(out, " UID The uid to use. It is only possible to pass the UID\n");
502 dprintf(out, " parameter on eng builds. If UID is omitted the calling\n");
503 dprintf(out, " uid is used.\n");
504 dprintf(out, " NAME The per-uid name to use\n");
505 dprintf(out, "\n");
506 dprintf(out, "\n *Note: If both UID and NAME are omitted then all configs will\n");
507 dprintf(out, "\n be removed from memory and disk!\n");
508 dprintf(out, "\n");
509 dprintf(out,
Bookatz3e906582018-12-10 17:26:58 -0800510 "usage: adb shell cmd stats dump-report [UID] NAME [--keep_data] "
511 "[--include_current_bucket] [--proto]\n");
Yao Chena80e5c02018-09-04 13:55:29 -0700512 dprintf(out, " Dump all metric data for a configuration.\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");
Bookatz3e906582018-12-10 17:26:58 -0800517 dprintf(out, " --keep_data Do NOT erase the data upon dumping it.\n");
Yao Chena80e5c02018-09-04 13:55:29 -0700518 dprintf(out, " --proto Print proto binary.\n");
519 dprintf(out, "\n");
520 dprintf(out, "\n");
521 dprintf(out, "usage: adb shell cmd stats send-broadcast [UID] NAME\n");
522 dprintf(out, " Send a broadcast that triggers the subscriber to fetch metrics.\n");
523 dprintf(out, " UID The uid of the configuration. 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, " NAME The name of the configuration\n");
527 dprintf(out, "\n");
528 dprintf(out, "\n");
Tej Singh6ede28b2019-01-29 17:06:54 -0800529 dprintf(out,
530 "usage: adb shell cmd stats send-active-configs [--uid=UID] [--configs] "
531 "[NAME1] [NAME2] [NAME3..]\n");
532 dprintf(out, " Send a broadcast that informs the subscriber of the current active configs.\n");
533 dprintf(out, " --uid=UID The uid of the configurations. It is only possible to pass\n");
534 dprintf(out, " the UID parameter on eng builds. If UID is omitted the\n");
535 dprintf(out, " calling uid is used.\n");
536 dprintf(out, " --configs Send the list of configs in the name list instead of\n");
537 dprintf(out, " the currently active configs\n");
538 dprintf(out, " NAME LIST List of configuration names to be included in the broadcast.\n");
Tej Singh6ede28b2019-01-29 17:06:54 -0800539 dprintf(out, "\n");
540 dprintf(out, "\n");
Yao Chena80e5c02018-09-04 13:55:29 -0700541 dprintf(out, "usage: adb shell cmd stats print-stats\n");
542 dprintf(out, " Prints some basic stats.\n");
543 dprintf(out, " --proto Print proto binary instead of string format.\n");
544 dprintf(out, "\n");
545 dprintf(out, "\n");
546 dprintf(out, "usage: adb shell cmd stats clear-puller-cache\n");
547 dprintf(out, " Clear cached puller data.\n");
548 dprintf(out, "\n");
549 dprintf(out, "usage: adb shell cmd stats print-logs\n");
550 dprintf(out, " Only works on eng build\n");
David Chenadaf8b32017-11-03 15:42:08 -0700551}
552
Yao Chena80e5c02018-09-04 13:55:29 -0700553status_t StatsService::cmd_trigger_broadcast(int out, Vector<String8>& args) {
David Chen1d7b0cd2017-11-15 14:20:04 -0800554 string name;
555 bool good = false;
556 int uid;
557 const int argCount = args.size();
558 if (argCount == 2) {
559 // Automatically pick the UID
560 uid = IPCThreadState::self()->getCallingUid();
David Chen1d7b0cd2017-11-15 14:20:04 -0800561 name.assign(args[1].c_str(), args[1].size());
562 good = true;
563 } else if (argCount == 3) {
Bookatzd2386572018-12-14 15:53:14 -0800564 good = getUidFromArgs(args, 1, uid);
565 if (!good) {
566 dprintf(out, "Invalid UID. Note that the metrics can only be dumped for "
567 "other UIDs on eng or userdebug builds.\n");
David Chen1d7b0cd2017-11-15 14:20:04 -0800568 }
Bookatzd2386572018-12-14 15:53:14 -0800569 name.assign(args[2].c_str(), args[2].size());
David Chen1d7b0cd2017-11-15 14:20:04 -0800570 }
571 if (!good) {
572 print_cmd_help(out);
573 return UNKNOWN_ERROR;
574 }
David Chend37bc232018-04-12 18:05:11 -0700575 ConfigKey key(uid, StrToInt64(name));
576 auto receiver = mConfigManager->GetConfigReceiver(key);
yro4d889e62017-11-17 15:44:48 -0800577 sp<IStatsCompanionService> sc = getStatsCompanionService();
David Chen661f7912018-01-22 17:46:24 -0800578 if (sc == nullptr) {
579 VLOG("Could not access statsCompanion");
580 } else if (receiver == nullptr) {
581 VLOG("Could not find receiver for %s, %s", args[1].c_str(), args[2].c_str())
582 } else {
David Chend37bc232018-04-12 18:05:11 -0700583 sc->sendDataBroadcast(receiver, mProcessor->getLastReportTimeNs(key));
yro74fed972017-11-27 14:42:42 -0800584 VLOG("StatsService::trigger broadcast succeeded to %s, %s", args[1].c_str(),
585 args[2].c_str());
yro4d889e62017-11-17 15:44:48 -0800586 }
587
David Chenadaf8b32017-11-03 15:42:08 -0700588 return NO_ERROR;
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700589}
590
Tej Singh6ede28b2019-01-29 17:06:54 -0800591status_t StatsService::cmd_trigger_active_config_broadcast(int out, Vector<String8>& args) {
592 const int argCount = args.size();
593 int uid;
594 vector<int64_t> configIds;
595 if (argCount == 1) {
596 // Automatically pick the uid and send a broadcast that has no active configs.
597 uid = IPCThreadState::self()->getCallingUid();
598 mProcessor->GetActiveConfigs(uid, configIds);
599 } else {
600 int curArg = 1;
601 if(args[curArg].find("--uid=") == 0) {
602 string uidArgStr(args[curArg].c_str());
603 string uidStr = uidArgStr.substr(6);
604 if (!getUidFromString(uidStr.c_str(), uid)) {
605 dprintf(out, "Invalid UID. Note that the config can only be set for "
606 "other UIDs on eng or userdebug builds.\n");
607 return UNKNOWN_ERROR;
608 }
609 curArg++;
610 } else {
611 uid = IPCThreadState::self()->getCallingUid();
612 }
613 if (curArg == argCount || args[curArg] != "--configs") {
614 VLOG("Reached end of args, or specify configs not set. Sending actual active configs,");
615 mProcessor->GetActiveConfigs(uid, configIds);
616 } else {
617 // Flag specified, use the given list of configs.
618 curArg++;
619 for (int i = curArg; i < argCount; i++) {
620 char* endp;
621 int64_t configID = strtoll(args[i].c_str(), &endp, 10);
622 if (endp == args[i].c_str() || *endp != '\0') {
623 dprintf(out, "Error parsing config ID.\n");
624 return UNKNOWN_ERROR;
625 }
626 VLOG("Adding config id %ld", static_cast<long>(configID));
627 configIds.push_back(configID);
628 }
629 }
630 }
631 auto receiver = mConfigManager->GetActiveConfigsChangedReceiver(uid);
632 sp<IStatsCompanionService> sc = getStatsCompanionService();
633 if (sc == nullptr) {
634 VLOG("Could not access statsCompanion");
635 } else if (receiver == nullptr) {
636 VLOG("Could not find receiver for uid %d", uid);
637 } else {
638 sc->sendActiveConfigsChangedBroadcast(receiver, configIds);
639 VLOG("StatsService::trigger active configs changed broadcast succeeded for uid %d" , uid);
640 }
641 return NO_ERROR;
642}
643
Yao Chena80e5c02018-09-04 13:55:29 -0700644status_t StatsService::cmd_config(int in, int out, int err, Vector<String8>& args) {
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700645 const int argCount = args.size();
646 if (argCount >= 2) {
647 if (args[1] == "update" || args[1] == "remove") {
648 bool good = false;
649 int uid = -1;
650 string name;
651
652 if (argCount == 3) {
653 // Automatically pick the UID
654 uid = IPCThreadState::self()->getCallingUid();
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700655 name.assign(args[2].c_str(), args[2].size());
656 good = true;
657 } else if (argCount == 4) {
Bookatzd2386572018-12-14 15:53:14 -0800658 good = getUidFromArgs(args, 2, uid);
659 if (!good) {
660 dprintf(err, "Invalid UID. Note that the config can only be set for "
661 "other UIDs on eng or userdebug builds.\n");
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700662 }
Bookatzd2386572018-12-14 15:53:14 -0800663 name.assign(args[3].c_str(), args[3].size());
yroe5f82922018-01-22 18:37:27 -0800664 } else if (argCount == 2 && args[1] == "remove") {
665 good = true;
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700666 }
667
668 if (!good) {
669 // If arg parsing failed, print the help text and return an error.
670 print_cmd_help(out);
671 return UNKNOWN_ERROR;
672 }
673
674 if (args[1] == "update") {
yro255f72e2018-02-26 15:15:17 -0800675 char* endp;
676 int64_t configID = strtoll(name.c_str(), &endp, 10);
677 if (endp == name.c_str() || *endp != '\0') {
Yao Chena80e5c02018-09-04 13:55:29 -0700678 dprintf(err, "Error parsing config ID.\n");
yro255f72e2018-02-26 15:15:17 -0800679 return UNKNOWN_ERROR;
680 }
681
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700682 // Read stream into buffer.
683 string buffer;
Yao Chena80e5c02018-09-04 13:55:29 -0700684 if (!android::base::ReadFdToString(in, &buffer)) {
685 dprintf(err, "Error reading stream for StatsConfig.\n");
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700686 return UNKNOWN_ERROR;
687 }
688
689 // Parse buffer.
690 StatsdConfig config;
691 if (!config.ParseFromString(buffer)) {
Yao Chena80e5c02018-09-04 13:55:29 -0700692 dprintf(err, "Error parsing proto stream for StatsConfig.\n");
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700693 return UNKNOWN_ERROR;
694 }
695
696 // Add / update the config.
yro255f72e2018-02-26 15:15:17 -0800697 mConfigManager->UpdateConfig(ConfigKey(uid, configID), config);
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700698 } else {
yro74fed972017-11-27 14:42:42 -0800699 if (argCount == 2) {
700 cmd_remove_all_configs(out);
701 } else {
702 // Remove the config.
Yangster-mac94e197c2018-01-02 16:03:03 -0800703 mConfigManager->RemoveConfig(ConfigKey(uid, StrToInt64(name)));
yro74fed972017-11-27 14:42:42 -0800704 }
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700705 }
706
707 return NO_ERROR;
708 }
David Chen0656b7a2017-09-13 15:53:39 -0700709 }
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700710 print_cmd_help(out);
711 return UNKNOWN_ERROR;
712}
713
Bookatzff71cad2018-09-20 17:17:49 -0700714status_t StatsService::cmd_dump_report(int out, const Vector<String8>& args) {
Yao Chen729093d2017-10-16 10:33:26 -0700715 if (mProcessor != nullptr) {
Chenjie Yub236c862017-11-28 22:20:44 -0800716 int argCount = args.size();
Yao Chen729093d2017-10-16 10:33:26 -0700717 bool good = false;
Chenjie Yub236c862017-11-28 22:20:44 -0800718 bool proto = false;
Chenjie Yubd1a28f2018-07-17 14:55:19 -0700719 bool includeCurrentBucket = false;
Bookatz3e906582018-12-10 17:26:58 -0800720 bool eraseData = true;
Yao Chen729093d2017-10-16 10:33:26 -0700721 int uid;
722 string name;
Chenjie Yub236c862017-11-28 22:20:44 -0800723 if (!std::strcmp("--proto", args[argCount-1].c_str())) {
724 proto = true;
725 argCount -= 1;
726 }
Chenjie Yubd1a28f2018-07-17 14:55:19 -0700727 if (!std::strcmp("--include_current_bucket", args[argCount-1].c_str())) {
728 includeCurrentBucket = true;
729 argCount -= 1;
730 }
Bookatz3e906582018-12-10 17:26:58 -0800731 if (!std::strcmp("--keep_data", args[argCount-1].c_str())) {
732 eraseData = false;
733 argCount -= 1;
734 }
Yao Chen729093d2017-10-16 10:33:26 -0700735 if (argCount == 2) {
736 // Automatically pick the UID
737 uid = IPCThreadState::self()->getCallingUid();
Yao Chen5154a3792017-10-30 22:57:06 -0700738 name.assign(args[1].c_str(), args[1].size());
Yao Chen729093d2017-10-16 10:33:26 -0700739 good = true;
740 } else if (argCount == 3) {
Bookatzd2386572018-12-14 15:53:14 -0800741 good = getUidFromArgs(args, 1, uid);
742 if (!good) {
743 dprintf(out, "Invalid UID. Note that the metrics can only be dumped for "
744 "other UIDs on eng or userdebug builds.\n");
Yao Chen729093d2017-10-16 10:33:26 -0700745 }
Bookatzd2386572018-12-14 15:53:14 -0800746 name.assign(args[2].c_str(), args[2].size());
Yao Chen729093d2017-10-16 10:33:26 -0700747 }
748 if (good) {
David Chen1d7b0cd2017-11-15 14:20:04 -0800749 vector<uint8_t> data;
David Chen926fc752018-02-23 13:31:43 -0800750 mProcessor->onDumpReport(ConfigKey(uid, StrToInt64(name)), getElapsedRealtimeNs(),
Olivier Gaillard6c75ecd2019-02-20 09:57:33 +0000751 includeCurrentBucket, eraseData, ADB_DUMP,
752 NO_TIME_CONSTRAINTS,
753 &data);
Chenjie Yub236c862017-11-28 22:20:44 -0800754 if (proto) {
755 for (size_t i = 0; i < data.size(); i ++) {
Yao Chena80e5c02018-09-04 13:55:29 -0700756 dprintf(out, "%c", data[i]);
Chenjie Yub236c862017-11-28 22:20:44 -0800757 }
758 } else {
Bookatzff71cad2018-09-20 17:17:49 -0700759 dprintf(out, "Non-proto stats data dump not currently supported.\n");
Chenjie Yub236c862017-11-28 22:20:44 -0800760 }
Yao Chen729093d2017-10-16 10:33:26 -0700761 return android::OK;
762 } else {
763 // If arg parsing failed, print the help text and return an error.
764 print_cmd_help(out);
765 return UNKNOWN_ERROR;
766 }
767 } else {
Yao Chena80e5c02018-09-04 13:55:29 -0700768 dprintf(out, "Log processor does not exist...\n");
Yao Chen729093d2017-10-16 10:33:26 -0700769 return UNKNOWN_ERROR;
770 }
771}
772
Yao Chena80e5c02018-09-04 13:55:29 -0700773status_t StatsService::cmd_print_stats(int out, const Vector<String8>& args) {
Tej Singh41b3f9a2018-04-03 17:06:35 -0700774 int argCount = args.size();
775 bool proto = false;
776 if (!std::strcmp("--proto", args[argCount-1].c_str())) {
777 proto = true;
778 argCount -= 1;
David Chen1d7b0cd2017-11-15 14:20:04 -0800779 }
Yao Chenb3561512017-11-21 18:07:17 -0800780 StatsdStats& statsdStats = StatsdStats::getInstance();
Tej Singh41b3f9a2018-04-03 17:06:35 -0700781 if (proto) {
782 vector<uint8_t> data;
783 statsdStats.dumpStats(&data, false); // does not reset statsdStats.
784 for (size_t i = 0; i < data.size(); i ++) {
Yao Chena80e5c02018-09-04 13:55:29 -0700785 dprintf(out, "%c", data[i]);
Tej Singh41b3f9a2018-04-03 17:06:35 -0700786 }
787
788 } else {
789 vector<ConfigKey> configs = mConfigManager->GetAllConfigKeys();
790 for (const ConfigKey& key : configs) {
Yao Chena80e5c02018-09-04 13:55:29 -0700791 dprintf(out, "Config %s uses %zu bytes\n", key.ToString().c_str(),
Tej Singh41b3f9a2018-04-03 17:06:35 -0700792 mProcessor->GetMetricsSize(key));
793 }
794 statsdStats.dumpStats(out);
795 }
David Chen1d7b0cd2017-11-15 14:20:04 -0800796 return NO_ERROR;
797}
798
Yao Chena80e5c02018-09-04 13:55:29 -0700799status_t StatsService::cmd_print_uid_map(int out, const Vector<String8>& args) {
Yao Chend10f7b12017-12-18 12:53:50 -0800800 if (args.size() > 1) {
801 string pkg;
802 pkg.assign(args[1].c_str(), args[1].size());
803 auto uids = mUidMap->getAppUid(pkg);
Yao Chena80e5c02018-09-04 13:55:29 -0700804 dprintf(out, "%s -> [ ", pkg.c_str());
Yao Chend10f7b12017-12-18 12:53:50 -0800805 for (const auto& uid : uids) {
Yao Chena80e5c02018-09-04 13:55:29 -0700806 dprintf(out, "%d ", uid);
Yao Chend10f7b12017-12-18 12:53:50 -0800807 }
Yao Chena80e5c02018-09-04 13:55:29 -0700808 dprintf(out, "]\n");
Yao Chend10f7b12017-12-18 12:53:50 -0800809 } else {
810 mUidMap->printUidMap(out);
811 }
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700812 return NO_ERROR;
David Chen0656b7a2017-09-13 15:53:39 -0700813}
814
Yao Chena80e5c02018-09-04 13:55:29 -0700815status_t StatsService::cmd_write_data_to_disk(int out) {
816 dprintf(out, "Writing data to disk\n");
Olivier Gaillard6c75ecd2019-02-20 09:57:33 +0000817 mProcessor->WriteDataToDisk(ADB_DUMP, NO_TIME_CONSTRAINTS);
yro947fbce2017-11-15 22:50:23 -0800818 return NO_ERROR;
819}
820
Yao Chena80e5c02018-09-04 13:55:29 -0700821status_t StatsService::cmd_log_app_breadcrumb(int out, const Vector<String8>& args) {
Bookatzb223c4e2018-02-01 15:35:04 -0800822 bool good = false;
823 int32_t uid;
824 int32_t label;
825 int32_t state;
826 const int argCount = args.size();
827 if (argCount == 3) {
828 // Automatically pick the UID
829 uid = IPCThreadState::self()->getCallingUid();
830 label = atoi(args[1].c_str());
831 state = atoi(args[2].c_str());
832 good = true;
833 } else if (argCount == 4) {
Bookatzd2386572018-12-14 15:53:14 -0800834 good = getUidFromArgs(args, 1, uid);
835 if (!good) {
Yao Chena80e5c02018-09-04 13:55:29 -0700836 dprintf(out,
Bookatzd2386572018-12-14 15:53:14 -0800837 "Invalid UID. Note that selecting a UID for writing AppBreadcrumb can only be "
838 "done for other UIDs on eng or userdebug builds.\n");
Bookatzb223c4e2018-02-01 15:35:04 -0800839 }
Bookatzd2386572018-12-14 15:53:14 -0800840 label = atoi(args[2].c_str());
841 state = atoi(args[3].c_str());
Bookatzb223c4e2018-02-01 15:35:04 -0800842 }
843 if (good) {
Yao Chena80e5c02018-09-04 13:55:29 -0700844 dprintf(out, "Logging AppBreadcrumbReported(%d, %d, %d) to statslog.\n", uid, label, state);
David Chen0b5c90c2018-01-25 16:51:49 -0800845 android::util::stats_write(android::util::APP_BREADCRUMB_REPORTED, uid, label, state);
Bookatzb223c4e2018-02-01 15:35:04 -0800846 } else {
847 print_cmd_help(out);
848 return UNKNOWN_ERROR;
849 }
850 return NO_ERROR;
851}
852
Tej Singh53f9dee2019-04-30 17:45:54 -0700853status_t StatsService::cmd_log_binary_push(int out, const Vector<String8>& args) {
854 // Security checks are done in the sendBinaryPushStateChanged atom.
855 const int argCount = args.size();
856 if (argCount != 7 && argCount != 8) {
857 dprintf(out, "Incorrect number of argument supplied\n");
858 return UNKNOWN_ERROR;
859 }
860 android::String16 trainName = android::String16(args[1].c_str());
861 int64_t trainVersion = strtoll(args[2].c_str(), nullptr, 10);
862 int options = 0;
863 if (args[3] == "1") {
864 options = options | IStatsManager::FLAG_REQUIRE_STAGING;
865 }
866 if (args[4] == "1") {
867 options = options | IStatsManager::FLAG_ROLLBACK_ENABLED;
868 }
869 if (args[5] == "1") {
870 options = options | IStatsManager::FLAG_REQUIRE_LOW_LATENCY_MONITOR;
871 }
872 int32_t state = atoi(args[6].c_str());
873 vector<int64_t> experimentIds;
874 if (argCount == 8) {
875 vector<string> experimentIdsString = android::base::Split(string(args[7].c_str()), ",");
876 for (string experimentIdString : experimentIdsString) {
877 int64_t experimentId = strtoll(experimentIdString.c_str(), nullptr, 10);
878 experimentIds.push_back(experimentId);
879 }
880 }
881 dprintf(out, "Logging BinaryPushStateChanged\n");
882 sendBinaryPushStateChangedAtom(trainName, trainVersion, options, state, experimentIds);
883 return NO_ERROR;
884}
885
Yao Chena80e5c02018-09-04 13:55:29 -0700886status_t StatsService::cmd_print_pulled_metrics(int out, const Vector<String8>& args) {
David Chen1481fe12017-10-16 13:16:34 -0700887 int s = atoi(args[1].c_str());
Chenjie Yu5305e1d2017-10-31 13:49:36 -0700888 vector<shared_ptr<LogEvent> > stats;
Chenjie Yu0bd73db2018-12-16 07:37:04 -0800889 if (mPullerManager->Pull(s, &stats)) {
Chenjie Yu5305e1d2017-10-31 13:49:36 -0700890 for (const auto& it : stats) {
Yao Chena80e5c02018-09-04 13:55:29 -0700891 dprintf(out, "Pull from %d: %s\n", s, it->ToString().c_str());
Chenjie Yu5305e1d2017-10-31 13:49:36 -0700892 }
Yao Chena80e5c02018-09-04 13:55:29 -0700893 dprintf(out, "Pull from %d: Received %zu elements\n", s, stats.size());
Chenjie Yu5305e1d2017-10-31 13:49:36 -0700894 return NO_ERROR;
David Chen1481fe12017-10-16 13:16:34 -0700895 }
Chenjie Yu5305e1d2017-10-31 13:49:36 -0700896 return UNKNOWN_ERROR;
David Chen1481fe12017-10-16 13:16:34 -0700897}
898
Yao Chena80e5c02018-09-04 13:55:29 -0700899status_t StatsService::cmd_remove_all_configs(int out) {
900 dprintf(out, "Removing all configs...\n");
yro74fed972017-11-27 14:42:42 -0800901 VLOG("StatsService::cmd_remove_all_configs was called");
902 mConfigManager->RemoveAllConfigs();
yro947fbce2017-11-15 22:50:23 -0800903 StorageManager::deleteAllFiles(STATS_SERVICE_DIR);
yro87d983c2017-11-14 21:31:43 -0800904 return NO_ERROR;
905}
906
Yao Chena80e5c02018-09-04 13:55:29 -0700907status_t StatsService::cmd_dump_memory_info(int out) {
908 dprintf(out, "meminfo not available.\n");
Yao Chen8d9989b2017-11-18 18:54:50 -0800909 return NO_ERROR;
910}
911
Yao Chena80e5c02018-09-04 13:55:29 -0700912status_t StatsService::cmd_clear_puller_cache(int out) {
Chenjie Yufa22d652018-02-05 14:37:48 -0800913 IPCThreadState* ipc = IPCThreadState::self();
Yangster-mac932ecec2018-02-01 10:23:52 -0800914 VLOG("StatsService::cmd_clear_puller_cache with Pid %i, Uid %i",
915 ipc->getCallingPid(), ipc->getCallingUid());
Chenjie Yufa22d652018-02-05 14:37:48 -0800916 if (checkCallingPermission(String16(kPermissionDump))) {
Chenjie Yue2219202018-06-08 10:07:51 -0700917 int cleared = mPullerManager->ForceClearPullerCache();
Yao Chena80e5c02018-09-04 13:55:29 -0700918 dprintf(out, "Puller removed %d cached data!\n", cleared);
Chenjie Yufa22d652018-02-05 14:37:48 -0800919 return NO_ERROR;
920 } else {
921 return PERMISSION_DENIED;
922 }
Chenjie Yue72252b2018-02-01 13:19:35 -0800923}
924
Yao Chena80e5c02018-09-04 13:55:29 -0700925status_t StatsService::cmd_print_logs(int out, const Vector<String8>& args) {
Yao Chen876889c2018-05-02 11:16:16 -0700926 IPCThreadState* ipc = IPCThreadState::self();
927 VLOG("StatsService::cmd_print_logs with Pid %i, Uid %i", ipc->getCallingPid(),
928 ipc->getCallingUid());
929 if (checkCallingPermission(String16(kPermissionDump))) {
930 bool enabled = true;
931 if (args.size() >= 2) {
932 enabled = atoi(args[1].c_str()) != 0;
933 }
934 mProcessor->setPrintLogs(enabled);
935 return NO_ERROR;
936 } else {
937 return PERMISSION_DENIED;
938 }
939}
940
Bookatzd2386572018-12-14 15:53:14 -0800941bool StatsService::getUidFromArgs(const Vector<String8>& args, size_t uidArgIndex, int32_t& uid) {
Tej Singh6ede28b2019-01-29 17:06:54 -0800942 return getUidFromString(args[uidArgIndex].c_str(), uid);
943}
944
945bool StatsService::getUidFromString(const char* s, int32_t& uid) {
Bookatzd2386572018-12-14 15:53:14 -0800946 if (*s == '\0') {
947 return false;
948 }
949 char* endc = NULL;
950 int64_t longUid = strtol(s, &endc, 0);
951 if (*endc != '\0') {
952 return false;
953 }
954 int32_t goodUid = static_cast<int32_t>(longUid);
955 if (longUid < 0 || static_cast<uint64_t>(longUid) != static_cast<uid_t>(goodUid)) {
956 return false; // It was not of uid_t type.
957 }
958 uid = goodUid;
959
960 int32_t callingUid = IPCThreadState::self()->getCallingUid();
961 return mEngBuild // UserDebug/EngBuild are allowed to impersonate uids.
962 || (callingUid == goodUid) // Anyone can 'impersonate' themselves.
963 || (callingUid == AID_ROOT && goodUid == AID_SHELL); // ROOT can impersonate SHELL.
964}
965
Max Dashouk11e0d402019-05-16 16:58:07 -0700966Status StatsService::informAllUidData(const ParcelFileDescriptor& fd) {
Jeff Sharkey6b649252018-04-16 09:50:22 -0600967 ENFORCE_UID(AID_SYSTEM);
Max Dashouk11e0d402019-05-16 16:58:07 -0700968 // Read stream into buffer.
969 string buffer;
970 if (!android::base::ReadFdToString(fd.get(), &buffer)) {
971 return exception(Status::EX_ILLEGAL_ARGUMENT, "Failed to read all data from the pipe.");
972 }
Jeff Sharkey6b649252018-04-16 09:50:22 -0600973
Max Dashouk11e0d402019-05-16 16:58:07 -0700974 // Parse buffer.
975 UidData uidData;
976 if (!uidData.ParseFromString(buffer)) {
977 return exception(Status::EX_ILLEGAL_ARGUMENT, "Error parsing proto stream for UidData.");
978 }
David Chende701692017-10-05 13:16:02 -0700979
Max Dashouk11e0d402019-05-16 16:58:07 -0700980 vector<String16> versionStrings;
981 vector<String16> installers;
982 vector<String16> packageNames;
983 vector<int32_t> uids;
984 vector<int64_t> versions;
985
986 const auto numEntries = uidData.app_info_size();
987 versionStrings.reserve(numEntries);
988 installers.reserve(numEntries);
989 packageNames.reserve(numEntries);
990 uids.reserve(numEntries);
991 versions.reserve(numEntries);
992
993 for (const auto& appInfo: uidData.app_info()) {
994 packageNames.emplace_back(String16(appInfo.package_name().c_str()));
995 uids.push_back(appInfo.uid());
996 versions.push_back(appInfo.version());
997 versionStrings.emplace_back(String16(appInfo.version_string().c_str()));
998 installers.emplace_back(String16(appInfo.installer().c_str()));
999 }
1000
1001 mUidMap->updateMap(getElapsedRealtimeNs(),
1002 uids,
1003 versions,
1004 versionStrings,
1005 packageNames,
1006 installers);
1007
1008 VLOG("StatsService::informAllUidData UidData proto parsed successfully.");
David Chende701692017-10-05 13:16:02 -07001009 return Status::ok();
1010}
1011
dwchen730403e2018-10-29 11:41:56 -07001012Status StatsService::informOnePackage(const String16& app, int32_t uid, int64_t version,
1013 const String16& version_string, const String16& installer) {
Jeff Sharkey6b649252018-04-16 09:50:22 -06001014 ENFORCE_UID(AID_SYSTEM);
David Chende701692017-10-05 13:16:02 -07001015
Jeff Sharkey6b649252018-04-16 09:50:22 -06001016 VLOG("StatsService::informOnePackage was called");
dwchen730403e2018-10-29 11:41:56 -07001017 mUidMap->updateApp(getElapsedRealtimeNs(), app, uid, version, version_string, installer);
David Chende701692017-10-05 13:16:02 -07001018 return Status::ok();
1019}
1020
1021Status StatsService::informOnePackageRemoved(const String16& app, int32_t uid) {
Jeff Sharkey6b649252018-04-16 09:50:22 -06001022 ENFORCE_UID(AID_SYSTEM);
David Chende701692017-10-05 13:16:02 -07001023
Jeff Sharkey6b649252018-04-16 09:50:22 -06001024 VLOG("StatsService::informOnePackageRemoved was called");
David Chenbd125272018-04-04 19:02:50 -07001025 mUidMap->removeApp(getElapsedRealtimeNs(), app, uid);
yro01924022018-02-20 18:20:49 -08001026 mConfigManager->RemoveConfigs(uid);
David Chende701692017-10-05 13:16:02 -07001027 return Status::ok();
1028}
1029
Yao Chenef99c4f2017-09-22 16:26:54 -07001030Status StatsService::informAnomalyAlarmFired() {
Jeff Sharkey6b649252018-04-16 09:50:22 -06001031 ENFORCE_UID(AID_SYSTEM);
1032
yro74fed972017-11-27 14:42:42 -08001033 VLOG("StatsService::informAnomalyAlarmFired was called");
Yangster-macb142cc82018-03-30 15:22:08 -07001034 int64_t currentTimeSec = getElapsedRealtimeSec();
Yangster-mac932ecec2018-02-01 10:23:52 -08001035 std::unordered_set<sp<const InternalAlarm>, SpHash<InternalAlarm>> alarmSet =
1036 mAnomalyAlarmMonitor->popSoonerThan(static_cast<uint32_t>(currentTimeSec));
1037 if (alarmSet.size() > 0) {
Bookatz66fe0612018-02-07 18:51:48 -08001038 VLOG("Found an anomaly alarm that fired.");
Yangster-mac932ecec2018-02-01 10:23:52 -08001039 mProcessor->onAnomalyAlarmFired(currentTimeSec * NS_PER_SEC, alarmSet);
Bookatz66fe0612018-02-07 18:51:48 -08001040 } else {
1041 VLOG("Cannot find an anomaly alarm that fired. Perhaps it was recently cancelled.");
1042 }
Bookatz1b0b1142017-09-08 11:58:42 -07001043 return Status::ok();
1044}
1045
Yangster-mac932ecec2018-02-01 10:23:52 -08001046Status StatsService::informAlarmForSubscriberTriggeringFired() {
Jeff Sharkey6b649252018-04-16 09:50:22 -06001047 ENFORCE_UID(AID_SYSTEM);
1048
Yangster-mac932ecec2018-02-01 10:23:52 -08001049 VLOG("StatsService::informAlarmForSubscriberTriggeringFired was called");
Yangster-macb142cc82018-03-30 15:22:08 -07001050 int64_t currentTimeSec = getElapsedRealtimeSec();
Yangster-mac932ecec2018-02-01 10:23:52 -08001051 std::unordered_set<sp<const InternalAlarm>, SpHash<InternalAlarm>> alarmSet =
1052 mPeriodicAlarmMonitor->popSoonerThan(static_cast<uint32_t>(currentTimeSec));
1053 if (alarmSet.size() > 0) {
1054 VLOG("Found periodic alarm fired.");
1055 mProcessor->onPeriodicAlarmFired(currentTimeSec * NS_PER_SEC, alarmSet);
1056 } else {
1057 ALOGW("Cannot find an periodic alarm that fired. Perhaps it was recently cancelled.");
1058 }
1059 return Status::ok();
1060}
1061
Yao Chenef99c4f2017-09-22 16:26:54 -07001062Status StatsService::informPollAlarmFired() {
Jeff Sharkey6b649252018-04-16 09:50:22 -06001063 ENFORCE_UID(AID_SYSTEM);
1064
yro74fed972017-11-27 14:42:42 -08001065 VLOG("StatsService::informPollAlarmFired was called");
Yangster-mac15f6bbc2018-04-08 11:52:26 -07001066 mProcessor->informPullAlarmFired(getElapsedRealtimeNs());
yro74fed972017-11-27 14:42:42 -08001067 VLOG("StatsService::informPollAlarmFired succeeded");
Bookatz1b0b1142017-09-08 11:58:42 -07001068 return Status::ok();
1069}
1070
Yao Chenef99c4f2017-09-22 16:26:54 -07001071Status StatsService::systemRunning() {
Jeff Sharkey6b649252018-04-16 09:50:22 -06001072 ENFORCE_UID(AID_SYSTEM);
Joe Onorato5dcbc6c2017-08-29 15:13:58 -07001073
1074 // When system_server is up and running, schedule the dropbox task to run.
yro74fed972017-11-27 14:42:42 -08001075 VLOG("StatsService::systemRunning");
Bookatzb487b552017-09-18 11:26:01 -07001076 sayHiToStatsCompanion();
Joe Onorato5dcbc6c2017-08-29 15:13:58 -07001077 return Status::ok();
1078}
1079
Yangster-mac892f3d32018-05-02 14:16:48 -07001080Status StatsService::informDeviceShutdown() {
Jeff Sharkey6b649252018-04-16 09:50:22 -06001081 ENFORCE_UID(AID_SYSTEM);
Chenjie Yue36018b2018-04-16 15:18:30 -07001082 VLOG("StatsService::informDeviceShutdown");
Olivier Gaillard6c75ecd2019-02-20 09:57:33 +00001083 mProcessor->WriteDataToDisk(DEVICE_SHUTDOWN, FAST);
Muhammad Qureshi844694b2019-04-05 10:10:40 -07001084 mProcessor->SaveActiveConfigsToDisk(getElapsedRealtimeNs());
yro947fbce2017-11-15 22:50:23 -08001085 return Status::ok();
1086}
1087
Yao Chenef99c4f2017-09-22 16:26:54 -07001088void StatsService::sayHiToStatsCompanion() {
Bookatzb487b552017-09-18 11:26:01 -07001089 sp<IStatsCompanionService> statsCompanion = getStatsCompanionService();
1090 if (statsCompanion != nullptr) {
yro74fed972017-11-27 14:42:42 -08001091 VLOG("Telling statsCompanion that statsd is ready");
Bookatzb487b552017-09-18 11:26:01 -07001092 statsCompanion->statsdReady();
1093 } else {
yro74fed972017-11-27 14:42:42 -08001094 VLOG("Could not access statsCompanion");
Bookatzb487b552017-09-18 11:26:01 -07001095 }
1096}
1097
Yao Chenef99c4f2017-09-22 16:26:54 -07001098Status StatsService::statsCompanionReady() {
Jeff Sharkey6b649252018-04-16 09:50:22 -06001099 ENFORCE_UID(AID_SYSTEM);
1100
yro74fed972017-11-27 14:42:42 -08001101 VLOG("StatsService::statsCompanionReady was called");
Bookatzb487b552017-09-18 11:26:01 -07001102 sp<IStatsCompanionService> statsCompanion = getStatsCompanionService();
1103 if (statsCompanion == nullptr) {
Yao Chenef99c4f2017-09-22 16:26:54 -07001104 return Status::fromExceptionCode(
1105 Status::EX_NULL_POINTER,
1106 "statscompanion unavailable despite it contacting statsd!");
Bookatzb487b552017-09-18 11:26:01 -07001107 }
yro74fed972017-11-27 14:42:42 -08001108 VLOG("StatsService::statsCompanionReady linking to statsCompanion.");
Chenjie Yuaa5b2012018-03-21 13:53:15 -07001109 IInterface::asBinder(statsCompanion)->linkToDeath(this);
Chenjie Yue2219202018-06-08 10:07:51 -07001110 mPullerManager->SetStatsCompanionService(statsCompanion);
Yangster-mac932ecec2018-02-01 10:23:52 -08001111 mAnomalyAlarmMonitor->setStatsCompanionService(statsCompanion);
1112 mPeriodicAlarmMonitor->setStatsCompanionService(statsCompanion);
Bookatzc6977972018-01-16 16:55:05 -08001113 SubscriberReporter::getInstance().setStatsCompanionService(statsCompanion);
Bookatzb487b552017-09-18 11:26:01 -07001114 return Status::ok();
1115}
1116
Joe Onorato9fc9edf2017-10-15 20:08:52 -07001117void StatsService::Startup() {
1118 mConfigManager->Startup();
Muhammad Qureshi844694b2019-04-05 10:10:40 -07001119 mProcessor->LoadActiveConfigsFromDisk();
Bookatz906a35c2017-09-20 15:26:44 -07001120}
1121
Yangster-mac97e7d202018-10-09 11:05:39 -07001122void StatsService::Terminate() {
1123 ALOGI("StatsService::Terminating");
1124 if (mProcessor != nullptr) {
Olivier Gaillard6c75ecd2019-02-20 09:57:33 +00001125 mProcessor->WriteDataToDisk(TERMINATION_SIGNAL_RECEIVED, FAST);
Muhammad Qureshi844694b2019-04-05 10:10:40 -07001126 mProcessor->SaveActiveConfigsToDisk(getElapsedRealtimeNs());
Yangster-mac97e7d202018-10-09 11:05:39 -07001127 }
1128}
1129
Yao Chen0f861862019-03-27 11:51:15 -07001130// Test only interface!!!
Yao Chen3ff3a492018-08-06 16:17:37 -07001131void StatsService::OnLogEvent(LogEvent* event) {
1132 mProcessor->OnLogEvent(event);
Yao Chena80e5c02018-09-04 13:55:29 -07001133 if (mShellSubscriber != nullptr) {
1134 mShellSubscriber->onLogEvent(*event);
1135 }
Bookatz906a35c2017-09-20 15:26:44 -07001136}
1137
Jeff Sharkey6b649252018-04-16 09:50:22 -06001138Status StatsService::getData(int64_t key, const String16& packageName, vector<uint8_t>* output) {
1139 ENFORCE_DUMP_AND_USAGE_STATS(packageName);
1140
David Chenadaf8b32017-11-03 15:42:08 -07001141 IPCThreadState* ipc = IPCThreadState::self();
yro74fed972017-11-27 14:42:42 -08001142 VLOG("StatsService::getData with Pid %i, Uid %i", ipc->getCallingPid(), ipc->getCallingUid());
Bookatz4f716292018-04-10 17:15:12 -07001143 ConfigKey configKey(ipc->getCallingUid(), key);
Olivier Gaillard6c75ecd2019-02-20 09:57:33 +00001144 // The dump latency does not matter here since we do not include the current bucket, we do not
1145 // need to pull any new data anyhow.
David Chen56ae0d92018-05-11 16:00:22 -07001146 mProcessor->onDumpReport(configKey, getElapsedRealtimeNs(), false /* include_current_bucket*/,
Olivier Gaillard6c75ecd2019-02-20 09:57:33 +00001147 true /* erase_data */, GET_DATA_CALLED, FAST, output);
Bookatz4f716292018-04-10 17:15:12 -07001148 return Status::ok();
yro31eb67b2017-10-24 13:33:21 -07001149}
1150
Jeff Sharkey6b649252018-04-16 09:50:22 -06001151Status StatsService::getMetadata(const String16& packageName, vector<uint8_t>* output) {
1152 ENFORCE_DUMP_AND_USAGE_STATS(packageName);
1153
David Chen2e8f3802017-11-22 10:56:48 -08001154 IPCThreadState* ipc = IPCThreadState::self();
1155 VLOG("StatsService::getMetadata with Pid %i, Uid %i", ipc->getCallingPid(),
1156 ipc->getCallingUid());
Bookatz4f716292018-04-10 17:15:12 -07001157 StatsdStats::getInstance().dumpStats(output, false); // Don't reset the counters.
1158 return Status::ok();
David Chen2e8f3802017-11-22 10:56:48 -08001159}
1160
Jeff Sharkey6b649252018-04-16 09:50:22 -06001161Status StatsService::addConfiguration(int64_t key, const vector <uint8_t>& config,
1162 const String16& packageName) {
1163 ENFORCE_DUMP_AND_USAGE_STATS(packageName);
1164
David Chenadaf8b32017-11-03 15:42:08 -07001165 IPCThreadState* ipc = IPCThreadState::self();
Bookatz4f716292018-04-10 17:15:12 -07001166 if (addConfigurationChecked(ipc->getCallingUid(), key, config)) {
David Chen661f7912018-01-22 17:46:24 -08001167 return Status::ok();
1168 } else {
Bookatz4f716292018-04-10 17:15:12 -07001169 ALOGE("Could not parse malformatted StatsdConfig");
1170 return Status::fromExceptionCode(binder::Status::EX_ILLEGAL_ARGUMENT,
1171 "config does not correspond to a StatsdConfig proto");
David Chen661f7912018-01-22 17:46:24 -08001172 }
1173}
1174
David Chen9fdd4032018-03-20 14:38:56 -07001175bool StatsService::addConfigurationChecked(int uid, int64_t key, const vector<uint8_t>& config) {
1176 ConfigKey configKey(uid, key);
1177 StatsdConfig cfg;
1178 if (config.size() > 0) { // If the config is empty, skip parsing.
1179 if (!cfg.ParseFromArray(&config[0], config.size())) {
1180 return false;
1181 }
1182 }
1183 mConfigManager->UpdateConfig(configKey, cfg);
1184 return true;
1185}
1186
Jeff Sharkey6b649252018-04-16 09:50:22 -06001187Status StatsService::removeDataFetchOperation(int64_t key, const String16& packageName) {
1188 ENFORCE_DUMP_AND_USAGE_STATS(packageName);
1189
Bookatz4f716292018-04-10 17:15:12 -07001190 IPCThreadState* ipc = IPCThreadState::self();
1191 ConfigKey configKey(ipc->getCallingUid(), key);
1192 mConfigManager->RemoveConfigReceiver(configKey);
1193 return Status::ok();
David Chen661f7912018-01-22 17:46:24 -08001194}
1195
Jeff Sharkey6b649252018-04-16 09:50:22 -06001196Status StatsService::setDataFetchOperation(int64_t key,
1197 const sp<android::IBinder>& intentSender,
1198 const String16& packageName) {
1199 ENFORCE_DUMP_AND_USAGE_STATS(packageName);
1200
Bookatz4f716292018-04-10 17:15:12 -07001201 IPCThreadState* ipc = IPCThreadState::self();
1202 ConfigKey configKey(ipc->getCallingUid(), key);
1203 mConfigManager->SetConfigReceiver(configKey, intentSender);
David Chen48944902018-05-03 10:29:11 -07001204 if (StorageManager::hasConfigMetricsReport(configKey)) {
1205 VLOG("StatsService::setDataFetchOperation marking configKey %s to dump reports on disk",
1206 configKey.ToString().c_str());
1207 mProcessor->noteOnDiskData(configKey);
1208 }
Bookatz4f716292018-04-10 17:15:12 -07001209 return Status::ok();
yro31eb67b2017-10-24 13:33:21 -07001210}
1211
Tej Singh2c9ef2a2019-01-22 11:33:51 -08001212Status StatsService::setActiveConfigsChangedOperation(const sp<android::IBinder>& intentSender,
1213 const String16& packageName,
1214 vector<int64_t>* output) {
1215 ENFORCE_DUMP_AND_USAGE_STATS(packageName);
1216
1217 IPCThreadState* ipc = IPCThreadState::self();
Tej Singh6ede28b2019-01-29 17:06:54 -08001218 int uid = ipc->getCallingUid();
1219 mConfigManager->SetActiveConfigsChangedReceiver(uid, intentSender);
1220 if (output != nullptr) {
1221 mProcessor->GetActiveConfigs(uid, *output);
1222 } else {
1223 ALOGW("StatsService::setActiveConfigsChanged output was nullptr");
1224 }
Tej Singh2c9ef2a2019-01-22 11:33:51 -08001225 return Status::ok();
1226}
1227
1228Status StatsService::removeActiveConfigsChangedOperation(const String16& packageName) {
1229 ENFORCE_DUMP_AND_USAGE_STATS(packageName);
1230
1231 IPCThreadState* ipc = IPCThreadState::self();
1232 mConfigManager->RemoveActiveConfigsChangedReceiver(ipc->getCallingUid());
1233 return Status::ok();
1234}
1235
Jeff Sharkey6b649252018-04-16 09:50:22 -06001236Status StatsService::removeConfiguration(int64_t key, const String16& packageName) {
1237 ENFORCE_DUMP_AND_USAGE_STATS(packageName);
1238
Bookatz4f716292018-04-10 17:15:12 -07001239 IPCThreadState* ipc = IPCThreadState::self();
1240 ConfigKey configKey(ipc->getCallingUid(), key);
1241 mConfigManager->RemoveConfig(configKey);
1242 SubscriberReporter::getInstance().removeConfig(configKey);
1243 return Status::ok();
yro31eb67b2017-10-24 13:33:21 -07001244}
1245
Bookatzc6977972018-01-16 16:55:05 -08001246Status StatsService::setBroadcastSubscriber(int64_t configId,
1247 int64_t subscriberId,
Jeff Sharkey6b649252018-04-16 09:50:22 -06001248 const sp<android::IBinder>& intentSender,
1249 const String16& packageName) {
1250 ENFORCE_DUMP_AND_USAGE_STATS(packageName);
1251
Bookatzc6977972018-01-16 16:55:05 -08001252 VLOG("StatsService::setBroadcastSubscriber called.");
Bookatz4f716292018-04-10 17:15:12 -07001253 IPCThreadState* ipc = IPCThreadState::self();
1254 ConfigKey configKey(ipc->getCallingUid(), configId);
1255 SubscriberReporter::getInstance()
1256 .setBroadcastSubscriber(configKey, subscriberId, intentSender);
1257 return Status::ok();
Bookatzc6977972018-01-16 16:55:05 -08001258}
1259
1260Status StatsService::unsetBroadcastSubscriber(int64_t configId,
Jeff Sharkey6b649252018-04-16 09:50:22 -06001261 int64_t subscriberId,
1262 const String16& packageName) {
1263 ENFORCE_DUMP_AND_USAGE_STATS(packageName);
1264
Bookatzc6977972018-01-16 16:55:05 -08001265 VLOG("StatsService::unsetBroadcastSubscriber called.");
Bookatz4f716292018-04-10 17:15:12 -07001266 IPCThreadState* ipc = IPCThreadState::self();
1267 ConfigKey configKey(ipc->getCallingUid(), configId);
1268 SubscriberReporter::getInstance()
1269 .unsetBroadcastSubscriber(configKey, subscriberId);
1270 return Status::ok();
Bookatzc6977972018-01-16 16:55:05 -08001271}
1272
yrobe6d7f92018-05-04 13:02:53 -07001273Status StatsService::sendAppBreadcrumbAtom(int32_t label, int32_t state) {
1274 // Permission check not necessary as it's meant for applications to write to
1275 // statsd.
1276 android::util::stats_write(util::APP_BREADCRUMB_REPORTED,
1277 IPCThreadState::self()->getCallingUid(), label,
1278 state);
1279 return Status::ok();
1280}
1281
Tej Singha0c89dd2019-01-25 16:39:18 -08001282Status StatsService::registerPullerCallback(int32_t atomTag,
1283 const sp<android::os::IStatsPullerCallback>& pullerCallback,
1284 const String16& packageName) {
1285 ENFORCE_DUMP_AND_USAGE_STATS(packageName);
1286
1287 VLOG("StatsService::registerPullerCallback called.");
1288 mPullerManager->RegisterPullerCallback(atomTag, pullerCallback);
1289 return Status::ok();
1290}
1291
Tej Singh59184292019-10-11 11:07:06 -07001292Status StatsService::registerPullAtomCallback(int32_t uid, int32_t atomTag, int64_t coolDownNs,
1293 int64_t timeoutNs, const std::vector<int32_t>& additiveFields,
1294 const sp<android::os::IPullAtomCallback>& pullerCallback) {
1295 VLOG("StatsService::registerPuller called.");
1296 return Status::ok();
1297}
1298
Tej Singha0c89dd2019-01-25 16:39:18 -08001299Status StatsService::unregisterPullerCallback(int32_t atomTag, const String16& packageName) {
1300 ENFORCE_DUMP_AND_USAGE_STATS(packageName);
1301
1302 VLOG("StatsService::unregisterPullerCallback called.");
1303 mPullerManager->UnregisterPullerCallback(atomTag);
1304 return Status::ok();
1305}
1306
Tej Singh9b4a5ec2019-04-25 12:43:35 -07001307Status StatsService::sendBinaryPushStateChangedAtom(const android::String16& trainNameIn,
1308 const int64_t trainVersionCodeIn,
1309 const int options,
1310 const int32_t state,
Jeff Hamiltonfa2f91c2019-03-22 00:25:02 -04001311 const std::vector<int64_t>& experimentIdsIn) {
Tej Singh53f9dee2019-04-30 17:45:54 -07001312 // Note: We skip the usage stats op check here since we do not have a package name.
1313 // This is ok since we are overloading the usage_stats permission.
1314 // This method only sends data, it does not receive it.
1315 pid_t pid = IPCThreadState::self()->getCallingPid();
Chenjie Yu6b1667c2019-01-18 10:09:33 -08001316 uid_t uid = IPCThreadState::self()->getCallingUid();
Tej Singh73f8e9b2019-05-19 16:52:38 -07001317 // Root, system, and shell always have access
Tej Singh53f9dee2019-04-30 17:45:54 -07001318 if (uid != AID_ROOT && uid != AID_SYSTEM && uid != AID_SHELL) {
1319 // Caller must be granted these permissions
1320 if (!checkCallingPermission(String16(kPermissionDump))) {
1321 return exception(binder::Status::EX_SECURITY,
1322 StringPrintf("UID %d / PID %d lacks permission %s", uid, pid,
1323 kPermissionDump));
1324 }
1325 if (!checkCallingPermission(String16(kPermissionUsage))) {
1326 return exception(binder::Status::EX_SECURITY,
1327 StringPrintf("UID %d / PID %d lacks permission %s", uid, pid,
1328 kPermissionUsage));
1329 }
Chenjie Yu6b1667c2019-01-18 10:09:33 -08001330 }
1331
Jonathan Nguyenbbe311c2019-03-14 20:44:52 -07001332 bool readTrainInfoSuccess = false;
Tej Singh9b4a5ec2019-04-25 12:43:35 -07001333 InstallTrainInfo trainInfoOnDisk;
1334 readTrainInfoSuccess = StorageManager::readTrainInfo(trainInfoOnDisk);
Chenjie Yu6b1667c2019-01-18 10:09:33 -08001335
Tej Singh9b4a5ec2019-04-25 12:43:35 -07001336 bool resetExperimentIds = false;
1337 int64_t trainVersionCode = trainVersionCodeIn;
1338 std::string trainNameUtf8 = std::string(String8(trainNameIn).string());
1339 if (readTrainInfoSuccess) {
1340 // Keep the old train version if we received an empty version.
1341 if (trainVersionCodeIn == -1) {
1342 trainVersionCode = trainInfoOnDisk.trainVersionCode;
1343 } else if (trainVersionCodeIn != trainInfoOnDisk.trainVersionCode) {
1344 // Reset experiment ids if we receive a new non-empty train version.
1345 resetExperimentIds = true;
1346 }
1347
1348 // Keep the old train name if we received an empty train name.
1349 if (trainNameUtf8.size() == 0) {
1350 trainNameUtf8 = trainInfoOnDisk.trainName;
1351 } else if (trainNameUtf8 != trainInfoOnDisk.trainName) {
1352 // Reset experiment ids if we received a new valid train name.
1353 resetExperimentIds = true;
1354 }
1355
1356 // Reset if we received a different experiment id.
1357 if (!experimentIdsIn.empty() &&
1358 (trainInfoOnDisk.experimentIds.empty() ||
1359 experimentIdsIn[0] != trainInfoOnDisk.experimentIds[0])) {
1360 resetExperimentIds = true;
1361 }
Chenjie Yu6b1667c2019-01-18 10:09:33 -08001362 }
Chenjie Yu6b1667c2019-01-18 10:09:33 -08001363
Jeff Hamiltonfa2f91c2019-03-22 00:25:02 -04001364 // Find the right experiment IDs
1365 std::vector<int64_t> experimentIds;
Tej Singh9b4a5ec2019-04-25 12:43:35 -07001366 if (resetExperimentIds || !readTrainInfoSuccess) {
Jeff Hamiltonfa2f91c2019-03-22 00:25:02 -04001367 experimentIds = experimentIdsIn;
Tej Singh9b4a5ec2019-04-25 12:43:35 -07001368 } else {
1369 experimentIds = trainInfoOnDisk.experimentIds;
1370 }
1371
1372 if (!experimentIds.empty()) {
1373 int64_t firstId = experimentIds[0];
1374 switch (state) {
1375 case android::util::BINARY_PUSH_STATE_CHANGED__STATE__INSTALL_SUCCESS:
1376 experimentIds.push_back(firstId + 1);
1377 break;
1378 case android::util::BINARY_PUSH_STATE_CHANGED__STATE__INSTALLER_ROLLBACK_INITIATED:
1379 experimentIds.push_back(firstId + 2);
1380 break;
1381 case android::util::BINARY_PUSH_STATE_CHANGED__STATE__INSTALLER_ROLLBACK_SUCCESS:
1382 experimentIds.push_back(firstId + 3);
1383 break;
1384 }
Chenjie Yu6b1667c2019-01-18 10:09:33 -08001385 }
Muhammad Qureshif4ca8242019-03-01 09:20:15 -08001386
Jeff Hamiltonfa2f91c2019-03-22 00:25:02 -04001387 // Flatten the experiment IDs to proto
1388 vector<uint8_t> experimentIdsProtoBuffer;
1389 writeExperimentIdsToProto(experimentIds, &experimentIdsProtoBuffer);
Tej Singh9b4a5ec2019-04-25 12:43:35 -07001390 StorageManager::writeTrainInfo(trainVersionCode, trainNameUtf8, state, experimentIds);
Jonathan Nguyenbbe311c2019-03-14 20:44:52 -07001391
1392 userid_t userId = multiuser_get_user_id(uid);
1393 bool requiresStaging = options & IStatsManager::FLAG_REQUIRE_STAGING;
1394 bool rollbackEnabled = options & IStatsManager::FLAG_ROLLBACK_ENABLED;
1395 bool requiresLowLatencyMonitor = options & IStatsManager::FLAG_REQUIRE_LOW_LATENCY_MONITOR;
Muhammad Qureshif4ca8242019-03-01 09:20:15 -08001396 LogEvent event(trainNameUtf8, trainVersionCode, requiresStaging, rollbackEnabled,
1397 requiresLowLatencyMonitor, state, experimentIdsProtoBuffer, userId);
Chenjie Yu6b1667c2019-01-18 10:09:33 -08001398 mProcessor->OnLogEvent(&event);
Jeff Hamiltonfa2f91c2019-03-22 00:25:02 -04001399 return Status::ok();
1400}
1401
Tej Singh73f8e9b2019-05-19 16:52:38 -07001402Status StatsService::sendWatchdogRollbackOccurredAtom(const int32_t rollbackTypeIn,
1403 const android::String16& packageNameIn,
1404 const int64_t packageVersionCodeIn) {
1405 // Note: We skip the usage stats op check here since we do not have a package name.
1406 // This is ok since we are overloading the usage_stats permission.
1407 // This method only sends data, it does not receive it.
1408 pid_t pid = IPCThreadState::self()->getCallingPid();
1409 uid_t uid = IPCThreadState::self()->getCallingUid();
1410 // Root, system, and shell always have access
1411 if (uid != AID_ROOT && uid != AID_SYSTEM && uid != AID_SHELL) {
1412 // Caller must be granted these permissions
1413 if (!checkCallingPermission(String16(kPermissionDump))) {
1414 return exception(binder::Status::EX_SECURITY,
1415 StringPrintf("UID %d / PID %d lacks permission %s", uid, pid,
1416 kPermissionDump));
1417 }
1418 if (!checkCallingPermission(String16(kPermissionUsage))) {
1419 return exception(binder::Status::EX_SECURITY,
1420 StringPrintf("UID %d / PID %d lacks permission %s", uid, pid,
1421 kPermissionUsage));
1422 }
1423 }
1424
1425 android::util::stats_write(android::util::WATCHDOG_ROLLBACK_OCCURRED,
1426 rollbackTypeIn, String8(packageNameIn).string(), packageVersionCodeIn);
1427
1428 // Fast return to save disk read.
1429 if (rollbackTypeIn != android::util::WATCHDOG_ROLLBACK_OCCURRED__ROLLBACK_TYPE__ROLLBACK_SUCCESS
1430 && rollbackTypeIn !=
1431 android::util::WATCHDOG_ROLLBACK_OCCURRED__ROLLBACK_TYPE__ROLLBACK_INITIATE) {
1432 return Status::ok();
1433 }
1434
1435 bool readTrainInfoSuccess = false;
1436 InstallTrainInfo trainInfoOnDisk;
1437 readTrainInfoSuccess = StorageManager::readTrainInfo(trainInfoOnDisk);
1438
1439 if (!readTrainInfoSuccess) {
1440 return Status::ok();
1441 }
1442 std::vector<int64_t> experimentIds = trainInfoOnDisk.experimentIds;
1443 if (experimentIds.empty()) {
1444 return Status::ok();
1445 }
1446 switch (rollbackTypeIn) {
1447 case android::util::WATCHDOG_ROLLBACK_OCCURRED__ROLLBACK_TYPE__ROLLBACK_INITIATE:
1448 experimentIds.push_back(experimentIds[0] + 4);
1449 break;
1450 case android::util::WATCHDOG_ROLLBACK_OCCURRED__ROLLBACK_TYPE__ROLLBACK_SUCCESS:
1451 experimentIds.push_back(experimentIds[0] + 5);
1452 break;
1453 }
1454 StorageManager::writeTrainInfo(trainInfoOnDisk.trainVersionCode, trainInfoOnDisk.trainName,
1455 trainInfoOnDisk.status, experimentIds);
1456 return Status::ok();
1457}
1458
1459
Jeff Hamiltonfa2f91c2019-03-22 00:25:02 -04001460Status StatsService::getRegisteredExperimentIds(std::vector<int64_t>* experimentIdsOut) {
1461 uid_t uid = IPCThreadState::self()->getCallingUid();
1462
1463 // Caller must be granted these permissions
1464 if (!checkCallingPermission(String16(kPermissionDump))) {
1465 return exception(binder::Status::EX_SECURITY,
1466 StringPrintf("UID %d lacks permission %s", uid, kPermissionDump));
1467 }
1468 if (!checkCallingPermission(String16(kPermissionUsage))) {
1469 return exception(binder::Status::EX_SECURITY,
1470 StringPrintf("UID %d lacks permission %s", uid, kPermissionUsage));
1471 }
1472 // TODO: add verifier permission
1473
1474 // Read the latest train info
1475 InstallTrainInfo trainInfo;
1476 if (!StorageManager::readTrainInfo(trainInfo)) {
1477 // No train info means no experiment IDs, return an empty list
1478 experimentIdsOut->clear();
1479 return Status::ok();
1480 }
1481
1482 // Copy the experiment IDs to the out vector
1483 experimentIdsOut->assign(trainInfo.experimentIds.begin(), trainInfo.experimentIds.end());
Chenjie Yu6b1667c2019-01-18 10:09:33 -08001484 return Status::ok();
1485}
1486
Howard Roa46b6582018-09-18 16:45:02 -07001487hardware::Return<void> StatsService::reportSpeakerImpedance(
1488 const SpeakerImpedance& speakerImpedance) {
Tej Singh8928ed72019-02-22 19:06:22 -08001489 android::util::stats_write(android::util::SPEAKER_IMPEDANCE_REPORTED,
1490 speakerImpedance.speakerLocation, speakerImpedance.milliOhms);
Howard Roa46b6582018-09-18 16:45:02 -07001491
1492 return hardware::Void();
1493}
1494
1495hardware::Return<void> StatsService::reportHardwareFailed(const HardwareFailed& hardwareFailed) {
Tej Singh8928ed72019-02-22 19:06:22 -08001496 android::util::stats_write(android::util::HARDWARE_FAILED, int32_t(hardwareFailed.hardwareType),
1497 hardwareFailed.hardwareLocation, int32_t(hardwareFailed.errorCode));
Howard Roa46b6582018-09-18 16:45:02 -07001498
1499 return hardware::Void();
1500}
1501
1502hardware::Return<void> StatsService::reportPhysicalDropDetected(
1503 const PhysicalDropDetected& physicalDropDetected) {
Tej Singh8928ed72019-02-22 19:06:22 -08001504 android::util::stats_write(android::util::PHYSICAL_DROP_DETECTED,
1505 int32_t(physicalDropDetected.confidencePctg), physicalDropDetected.accelPeak,
1506 physicalDropDetected.freefallDuration);
Howard Roa46b6582018-09-18 16:45:02 -07001507
1508 return hardware::Void();
1509}
1510
1511hardware::Return<void> StatsService::reportChargeCycles(const ChargeCycles& chargeCycles) {
Tej Singh8928ed72019-02-22 19:06:22 -08001512 std::vector<int32_t> buckets = chargeCycles.cycleBucket;
1513 int initialSize = buckets.size();
1514 for (int i = 0; i < 10 - initialSize; i++) {
1515 buckets.push_back(-1); // Push -1 for buckets that do not exist.
1516 }
1517 android::util::stats_write(android::util::CHARGE_CYCLES_REPORTED, buckets[0], buckets[1],
1518 buckets[2], buckets[3], buckets[4], buckets[5], buckets[6], buckets[7], buckets[8],
1519 buckets[9]);
Howard Roa46b6582018-09-18 16:45:02 -07001520
1521 return hardware::Void();
1522}
1523
1524hardware::Return<void> StatsService::reportBatteryHealthSnapshot(
1525 const BatteryHealthSnapshotArgs& batteryHealthSnapshotArgs) {
Tej Singh8928ed72019-02-22 19:06:22 -08001526 android::util::stats_write(android::util::BATTERY_HEALTH_SNAPSHOT,
1527 int32_t(batteryHealthSnapshotArgs.type), batteryHealthSnapshotArgs.temperatureDeciC,
1528 batteryHealthSnapshotArgs.voltageMicroV, batteryHealthSnapshotArgs.currentMicroA,
1529 batteryHealthSnapshotArgs.openCircuitVoltageMicroV,
1530 batteryHealthSnapshotArgs.resistanceMicroOhm, batteryHealthSnapshotArgs.levelPercent);
Howard Roa46b6582018-09-18 16:45:02 -07001531
1532 return hardware::Void();
1533}
1534
1535hardware::Return<void> StatsService::reportSlowIo(const SlowIo& slowIo) {
Tej Singh8928ed72019-02-22 19:06:22 -08001536 android::util::stats_write(android::util::SLOW_IO, int32_t(slowIo.operation), slowIo.count);
Howard Roa46b6582018-09-18 16:45:02 -07001537
1538 return hardware::Void();
1539}
1540
1541hardware::Return<void> StatsService::reportBatteryCausedShutdown(
1542 const BatteryCausedShutdown& batteryCausedShutdown) {
Tej Singh8928ed72019-02-22 19:06:22 -08001543 android::util::stats_write(android::util::BATTERY_CAUSED_SHUTDOWN,
1544 batteryCausedShutdown.voltageMicroV);
Howard Roa46b6582018-09-18 16:45:02 -07001545
1546 return hardware::Void();
1547}
1548
Maggie Whitefc1aa592018-11-28 21:55:23 -08001549hardware::Return<void> StatsService::reportUsbPortOverheatEvent(
1550 const UsbPortOverheatEvent& usbPortOverheatEvent) {
Tej Singh8928ed72019-02-22 19:06:22 -08001551 android::util::stats_write(android::util::USB_PORT_OVERHEAT_EVENT_REPORTED,
1552 usbPortOverheatEvent.plugTemperatureDeciC, usbPortOverheatEvent.maxTemperatureDeciC,
1553 usbPortOverheatEvent.timeToOverheat, usbPortOverheatEvent.timeToHysteresis,
1554 usbPortOverheatEvent.timeToInactive);
Maggie Whitefc1aa592018-11-28 21:55:23 -08001555
1556 return hardware::Void();
1557}
1558
Carter Hsub8fd1e92019-01-11 15:24:45 +08001559hardware::Return<void> StatsService::reportSpeechDspStat(
1560 const SpeechDspStat& speechDspStat) {
Tej Singh8928ed72019-02-22 19:06:22 -08001561 android::util::stats_write(android::util::SPEECH_DSP_STAT_REPORTED,
1562 speechDspStat.totalUptimeMillis, speechDspStat.totalDowntimeMillis,
1563 speechDspStat.totalCrashCount, speechDspStat.totalRecoverCount);
Carter Hsub8fd1e92019-01-11 15:24:45 +08001564
1565 return hardware::Void();
1566}
1567
Maggie White58174da2019-01-18 15:23:35 -08001568hardware::Return<void> StatsService::reportVendorAtom(const VendorAtom& vendorAtom) {
1569 std::string reverseDomainName = (std::string) vendorAtom.reverseDomainName;
1570 if (vendorAtom.atomId < 100000 || vendorAtom.atomId >= 200000) {
1571 ALOGE("Atom ID %ld is not a valid vendor atom ID", (long) vendorAtom.atomId);
1572 return hardware::Void();
1573 }
1574 if (reverseDomainName.length() > 50) {
1575 ALOGE("Vendor atom reverse domain name %s is too long.", reverseDomainName.c_str());
1576 return hardware::Void();
1577 }
1578 LogEvent event(getWallClockSec() * NS_PER_SEC, getElapsedRealtimeNs(), vendorAtom);
1579 mProcessor->OnLogEvent(&event);
1580
1581 return hardware::Void();
1582}
1583
David Chen1d7b0cd2017-11-15 14:20:04 -08001584void StatsService::binderDied(const wp <IBinder>& who) {
Chenjie Yuaa5b2012018-03-21 13:53:15 -07001585 ALOGW("statscompanion service died");
Yangster-mac892f3d32018-05-02 14:16:48 -07001586 StatsdStats::getInstance().noteSystemServerRestart(getWallClockSec());
1587 if (mProcessor != nullptr) {
Howard Roe60992b2018-08-30 14:37:29 -07001588 ALOGW("Reset statsd upon system server restarts.");
Tej Singhf53d4452019-05-09 18:17:59 -07001589 int64_t systemServerRestartNs = getElapsedRealtimeNs();
1590 ProtoOutputStream proto;
1591 mProcessor->WriteActiveConfigsToProtoOutputStream(systemServerRestartNs,
1592 STATSCOMPANION_DIED, &proto);
1593
Olivier Gaillard6c75ecd2019-02-20 09:57:33 +00001594 mProcessor->WriteDataToDisk(STATSCOMPANION_DIED, FAST);
Yangster-mac892f3d32018-05-02 14:16:48 -07001595 mProcessor->resetConfigs();
Tej Singhf53d4452019-05-09 18:17:59 -07001596
1597 std::string serializedActiveConfigs;
1598 if (proto.serializeToString(&serializedActiveConfigs)) {
1599 ActiveConfigList activeConfigs;
1600 if (activeConfigs.ParseFromString(serializedActiveConfigs)) {
1601 mProcessor->SetConfigsActiveState(activeConfigs, systemServerRestartNs);
1602 }
1603 }
Yangster-mac892f3d32018-05-02 14:16:48 -07001604 }
Chenjie Yuaa5b2012018-03-21 13:53:15 -07001605 mAnomalyAlarmMonitor->setStatsCompanionService(nullptr);
1606 mPeriodicAlarmMonitor->setStatsCompanionService(nullptr);
1607 SubscriberReporter::getInstance().setStatsCompanionService(nullptr);
Chenjie Yue2219202018-06-08 10:07:51 -07001608 mPullerManager->SetStatsCompanionService(nullptr);
yro31eb67b2017-10-24 13:33:21 -07001609}
1610
Yao Chenef99c4f2017-09-22 16:26:54 -07001611} // namespace statsd
1612} // namespace os
1613} // namespace android