blob: 3efe9b18dcbaa74e86b6df7f992a5795015c5c79 [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
yro74fed972017-11-27 14:42:42 -080017#define DEBUG true // 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"
Yao Chen8d9989b2017-11-18 18:54:50 -080021#include "android-base/stringprintf.h"
David Chenadaf8b32017-11-03 15:42:08 -070022#include "config/ConfigKey.h"
23#include "config/ConfigManager.h"
Yao Chen8d9989b2017-11-18 18:54:50 -080024#include "guardrail/MemoryLeakTrackUtil.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>
Joe Onorato5dcbc6c2017-08-29 15:13:58 -070030#include <binder/IPCThreadState.h>
31#include <binder/IServiceManager.h>
yro87d983c2017-11-14 21:31:43 -080032#include <dirent.h>
David Chen0656b7a2017-09-13 15:53:39 -070033#include <frameworks/base/cmds/statsd/src/statsd_config.pb.h>
Joe Onorato5dcbc6c2017-08-29 15:13:58 -070034#include <private/android_filesystem_config.h>
35#include <utils/Looper.h>
Joe Onorato2cbc2cc2017-08-30 17:03:23 -070036#include <utils/String16.h>
Bookatzb223c4e2018-02-01 15:35:04 -080037#include <statslog.h>
Joe Onorato5dcbc6c2017-08-29 15:13:58 -070038#include <stdio.h>
Yao Chen482d2722017-09-12 13:25:43 -070039#include <stdlib.h>
Joe Onorato9fc9edf2017-10-15 20:08:52 -070040#include <sys/system_properties.h>
Yao Chenef99c4f2017-09-22 16:26:54 -070041#include <unistd.h>
Joe Onorato5dcbc6c2017-08-29 15:13:58 -070042
43using namespace android;
44
Bookatz906a35c2017-09-20 15:26:44 -070045namespace android {
46namespace os {
47namespace statsd {
48
David Chenadaf8b32017-11-03 15:42:08 -070049constexpr const char* kPermissionDump = "android.permission.DUMP";
yro03faf092017-12-12 00:17:50 -080050#define STATS_SERVICE_DIR "/data/misc/stats-service"
David Chenadaf8b32017-11-03 15:42:08 -070051
Joe Onorato9fc9edf2017-10-15 20:08:52 -070052// ======================================================================
53/**
54 * Watches for the death of the stats companion (system process).
55 */
56class CompanionDeathRecipient : public IBinder::DeathRecipient {
57public:
58 CompanionDeathRecipient(const sp<AnomalyMonitor>& anomalyMonitor);
59 virtual void binderDied(const wp<IBinder>& who);
60
61private:
62 const sp<AnomalyMonitor> mAnomalyMonitor;
63};
64
65CompanionDeathRecipient::CompanionDeathRecipient(const sp<AnomalyMonitor>& anomalyMonitor)
66 : mAnomalyMonitor(anomalyMonitor) {
67}
68
69void CompanionDeathRecipient::binderDied(const wp<IBinder>& who) {
70 ALOGW("statscompanion service died");
71 mAnomalyMonitor->setStatsCompanionService(nullptr);
Bookatzc6977972018-01-16 16:55:05 -080072 SubscriberReporter::getInstance().setStatsCompanionService(nullptr);
Joe Onorato9fc9edf2017-10-15 20:08:52 -070073}
74
75// ======================================================================
Joe Onorato5dcbc6c2017-08-29 15:13:58 -070076StatsService::StatsService(const sp<Looper>& handlerLooper)
Bookatz1d0136d2017-12-01 11:13:32 -080077 : mAnomalyMonitor(new AnomalyMonitor(MIN_DIFF_TO_UPDATE_REGISTERED_ALARM_SECS))
Joe Onorato5dcbc6c2017-08-29 15:13:58 -070078{
Joe Onorato9fc9edf2017-10-15 20:08:52 -070079 mUidMap = new UidMap();
80 mConfigManager = new ConfigManager();
Yangster-mac20877162017-12-22 17:19:39 -080081 mProcessor = new StatsLogProcessor(mUidMap, mAnomalyMonitor, time(nullptr), [this](const ConfigKey& key) {
yro947fbce2017-11-15 22:50:23 -080082 sp<IStatsCompanionService> sc = getStatsCompanionService();
David Chen1d7b0cd2017-11-15 14:20:04 -080083 auto receiver = mConfigManager->GetConfigReceiver(key);
84 if (sc == nullptr) {
yro74fed972017-11-27 14:42:42 -080085 VLOG("Could not find StatsCompanionService");
David Chen1d7b0cd2017-11-15 14:20:04 -080086 } else if (receiver.first.size() == 0) {
yro74fed972017-11-27 14:42:42 -080087 VLOG("Statscompanion could not find a broadcast receiver for %s",
88 key.ToString().c_str());
David Chen1d7b0cd2017-11-15 14:20:04 -080089 } else {
90 sc->sendBroadcast(String16(receiver.first.c_str()),
91 String16(receiver.second.c_str()));
92 }
yro31eb67b2017-10-24 13:33:21 -070093 });
Joe Onorato9fc9edf2017-10-15 20:08:52 -070094
95 mConfigManager->AddListener(mProcessor);
96
97 init_system_properties();
Joe Onorato5dcbc6c2017-08-29 15:13:58 -070098}
99
Yao Chenef99c4f2017-09-22 16:26:54 -0700100StatsService::~StatsService() {
Joe Onorato5dcbc6c2017-08-29 15:13:58 -0700101}
102
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700103void StatsService::init_system_properties() {
104 mEngBuild = false;
105 const prop_info* buildType = __system_property_find("ro.build.type");
106 if (buildType != NULL) {
107 __system_property_read_callback(buildType, init_build_type_callback, this);
108 }
David Chen0656b7a2017-09-13 15:53:39 -0700109}
110
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700111void StatsService::init_build_type_callback(void* cookie, const char* /*name*/, const char* value,
112 uint32_t serial) {
Yao Chen729093d2017-10-16 10:33:26 -0700113 if (0 == strcmp("eng", value) || 0 == strcmp("userdebug", value)) {
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700114 reinterpret_cast<StatsService*>(cookie)->mEngBuild = true;
115 }
116}
117
118/**
119 * Implement our own because the default binder implementation isn't
120 * properly handling SHELL_COMMAND_TRANSACTION.
121 */
Yao Chenef99c4f2017-09-22 16:26:54 -0700122status_t StatsService::onTransact(uint32_t code, const Parcel& data, Parcel* reply,
123 uint32_t flags) {
Joe Onorato2cbc2cc2017-08-30 17:03:23 -0700124 status_t err;
125
126 switch (code) {
127 case SHELL_COMMAND_TRANSACTION: {
128 int in = data.readFileDescriptor();
129 int out = data.readFileDescriptor();
130 int err = data.readFileDescriptor();
131 int argc = data.readInt32();
132 Vector<String8> args;
133 for (int i = 0; i < argc && data.dataAvail() > 0; i++) {
134 args.add(String8(data.readString16()));
135 }
Yao Chenef99c4f2017-09-22 16:26:54 -0700136 sp<IShellCallback> shellCallback = IShellCallback::asInterface(data.readStrongBinder());
137 sp<IResultReceiver> resultReceiver =
138 IResultReceiver::asInterface(data.readStrongBinder());
Joe Onorato2cbc2cc2017-08-30 17:03:23 -0700139
140 FILE* fin = fdopen(in, "r");
141 FILE* fout = fdopen(out, "w");
142 FILE* ferr = fdopen(err, "w");
143
144 if (fin == NULL || fout == NULL || ferr == NULL) {
145 resultReceiver->send(NO_MEMORY);
146 } else {
147 err = command(fin, fout, ferr, args);
148 resultReceiver->send(err);
149 }
150
151 if (fin != NULL) {
152 fflush(fin);
153 fclose(fin);
154 }
155 if (fout != NULL) {
156 fflush(fout);
157 fclose(fout);
158 }
159 if (fout != NULL) {
160 fflush(ferr);
161 fclose(ferr);
162 }
163
164 return NO_ERROR;
165 }
Yao Chenef99c4f2017-09-22 16:26:54 -0700166 default: { return BnStatsManager::onTransact(code, data, reply, flags); }
Joe Onorato2cbc2cc2017-08-30 17:03:23 -0700167 }
168}
169
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700170/**
171 * Write debugging data about statsd.
172 */
Yao Chenef99c4f2017-09-22 16:26:54 -0700173status_t StatsService::dump(int fd, const Vector<String16>& args) {
Joe Onorato5dcbc6c2017-08-29 15:13:58 -0700174 FILE* out = fdopen(fd, "w");
175 if (out == NULL) {
176 return NO_MEMORY; // the fd is already open
177 }
178
Yao Chen884c8c12018-01-26 10:36:25 -0800179 bool verbose = false;
180 if (args.size() > 0 && !args[0].compare(String16("-v"))) {
181 verbose = true;
182 }
183
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700184 // TODO: Proto format for incident reports
Yao Chen884c8c12018-01-26 10:36:25 -0800185 dump_impl(out, verbose);
Joe Onorato5dcbc6c2017-08-29 15:13:58 -0700186
187 fclose(out);
188 return NO_ERROR;
189}
190
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700191/**
192 * Write debugging data about statsd in text format.
193 */
Yao Chen884c8c12018-01-26 10:36:25 -0800194void StatsService::dump_impl(FILE* out, bool verbose) {
Yao Chenf5acabe2018-01-17 14:10:34 -0800195 StatsdStats::getInstance().dumpStats(out);
Yao Chen884c8c12018-01-26 10:36:25 -0800196 mProcessor->dumpStates(out, verbose);
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700197}
198
199/**
200 * Implementation of the adb shell cmd stats command.
201 */
Yao Chenef99c4f2017-09-22 16:26:54 -0700202status_t StatsService::command(FILE* in, FILE* out, FILE* err, Vector<String8>& args) {
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700203 // TODO: Permission check
204
205 const int argCount = args.size();
206 if (argCount >= 1) {
207 // adb shell cmd stats config ...
David Chen0656b7a2017-09-13 15:53:39 -0700208 if (!args[0].compare(String8("config"))) {
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700209 return cmd_config(in, out, err, args);
David Chen0656b7a2017-09-13 15:53:39 -0700210 }
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700211
David Chende701692017-10-05 13:16:02 -0700212 if (!args[0].compare(String8("print-uid-map"))) {
Yao Chend10f7b12017-12-18 12:53:50 -0800213 return cmd_print_uid_map(out, args);
David Chende701692017-10-05 13:16:02 -0700214 }
Yao Chen729093d2017-10-16 10:33:26 -0700215
216 if (!args[0].compare(String8("dump-report"))) {
217 return cmd_dump_report(out, err, args);
218 }
David Chen1481fe12017-10-16 13:16:34 -0700219
220 if (!args[0].compare(String8("pull-source")) && args.size() > 1) {
221 return cmd_print_pulled_metrics(out, args);
222 }
David Chenadaf8b32017-11-03 15:42:08 -0700223
224 if (!args[0].compare(String8("send-broadcast"))) {
David Chen1d7b0cd2017-11-15 14:20:04 -0800225 return cmd_trigger_broadcast(out, args);
226 }
227
228 if (!args[0].compare(String8("print-stats"))) {
Yao Chenb3561512017-11-21 18:07:17 -0800229 return cmd_print_stats(out, args);
David Chenadaf8b32017-11-03 15:42:08 -0700230 }
yro87d983c2017-11-14 21:31:43 -0800231
Yao Chen8d9989b2017-11-18 18:54:50 -0800232 if (!args[0].compare(String8("meminfo"))) {
233 return cmd_dump_memory_info(out);
234 }
yro947fbce2017-11-15 22:50:23 -0800235
236 if (!args[0].compare(String8("write-to-disk"))) {
237 return cmd_write_data_to_disk(out);
238 }
Bookatzb223c4e2018-02-01 15:35:04 -0800239
240 if (!args[0].compare(String8("log-app-hook"))) {
241 return cmd_log_app_hook(out, args);
242 }
Chenjie Yufa22d652018-02-05 14:37:48 -0800243
244 if (!args[0].compare(String8("clear-puller-cache"))) {
245 return cmd_clear_puller_cache(out);
246 }
Joe Onorato2cbc2cc2017-08-30 17:03:23 -0700247 }
Joe Onorato2cbc2cc2017-08-30 17:03:23 -0700248
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700249 print_cmd_help(out);
Joe Onorato2cbc2cc2017-08-30 17:03:23 -0700250 return NO_ERROR;
251}
252
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700253void StatsService::print_cmd_help(FILE* out) {
254 fprintf(out,
255 "usage: adb shell cmd stats print-stats-log [tag_required] "
256 "[timestamp_nsec_optional]\n");
257 fprintf(out, "\n");
258 fprintf(out, "\n");
Yao Chen8d9989b2017-11-18 18:54:50 -0800259 fprintf(out, "usage: adb shell cmd stats meminfo\n");
260 fprintf(out, "\n");
261 fprintf(out, " Prints the malloc debug information. You need to run the following first: \n");
262 fprintf(out, " # adb shell stop\n");
263 fprintf(out, " # adb shell setprop libc.debug.malloc.program statsd \n");
264 fprintf(out, " # adb shell setprop libc.debug.malloc.options backtrace \n");
265 fprintf(out, " # adb shell start\n");
266 fprintf(out, "\n");
267 fprintf(out, "\n");
Yao Chend10f7b12017-12-18 12:53:50 -0800268 fprintf(out, "usage: adb shell cmd stats print-uid-map [PKG]\n");
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700269 fprintf(out, "\n");
270 fprintf(out, " Prints the UID, app name, version mapping.\n");
Yao Chend10f7b12017-12-18 12:53:50 -0800271 fprintf(out, " PKG Optional package name to print the uids of the package\n");
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700272 fprintf(out, "\n");
273 fprintf(out, "\n");
yro3fca5ba2017-11-17 13:22:52 -0800274 fprintf(out, "usage: adb shell cmd stats pull-source [int] \n");
David Chen1481fe12017-10-16 13:16:34 -0700275 fprintf(out, "\n");
276 fprintf(out, " Prints the output of a pulled metrics source (int indicates source)\n");
277 fprintf(out, "\n");
278 fprintf(out, "\n");
yro947fbce2017-11-15 22:50:23 -0800279 fprintf(out, "usage: adb shell cmd stats write-to-disk \n");
280 fprintf(out, "\n");
281 fprintf(out, " Flushes all data on memory to disk.\n");
282 fprintf(out, "\n");
283 fprintf(out, "\n");
Bookatzb223c4e2018-02-01 15:35:04 -0800284 fprintf(out, "usage: adb shell cmd stats log-app-hook [UID] LABEL STATE\n");
285 fprintf(out, " Writes an AppHook event to the statslog buffer.\n");
286 fprintf(out, " UID The uid to use. It is only possible to pass a UID\n");
287 fprintf(out, " parameter on eng builds. If UID is omitted the calling\n");
288 fprintf(out, " uid is used.\n");
289 fprintf(out, " LABEL Integer in [0, 15], as per atoms.proto.\n");
290 fprintf(out, " STATE Integer in [0, 3], as per atoms.proto.\n");
291 fprintf(out, "\n");
292 fprintf(out, "\n");
yro74fed972017-11-27 14:42:42 -0800293 fprintf(out, "usage: adb shell cmd stats config remove [UID] [NAME]\n");
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700294 fprintf(out, "usage: adb shell cmd stats config update [UID] NAME\n");
295 fprintf(out, "\n");
296 fprintf(out, " Adds, updates or removes a configuration. The proto should be in\n");
yro74fed972017-11-27 14:42:42 -0800297 fprintf(out, " wire-encoded protobuf format and passed via stdin. If no UID and name is\n");
298 fprintf(out, " provided, then all configs will be removed from memory and disk.\n");
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700299 fprintf(out, "\n");
300 fprintf(out, " UID The uid to use. It is only possible to pass the UID\n");
yro74fed972017-11-27 14:42:42 -0800301 fprintf(out, " parameter on eng builds. If UID is omitted the calling\n");
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700302 fprintf(out, " uid is used.\n");
303 fprintf(out, " NAME The per-uid name to use\n");
Yao Chen5154a372017-10-30 22:57:06 -0700304 fprintf(out, "\n");
yro74fed972017-11-27 14:42:42 -0800305 fprintf(out, "\n *Note: If both UID and NAME are omitted then all configs will\n");
306 fprintf(out, "\n be removed from memory and disk!\n");
Yao Chen5154a372017-10-30 22:57:06 -0700307 fprintf(out, "\n");
Chenjie Yub236c862017-11-28 22:20:44 -0800308 fprintf(out, "usage: adb shell cmd stats dump-report [UID] NAME [--proto]\n");
Yao Chen5154a372017-10-30 22:57:06 -0700309 fprintf(out, " Dump all metric data for a configuration.\n");
310 fprintf(out, " UID The uid of the configuration. It is only possible to pass\n");
311 fprintf(out, " the UID parameter on eng builds. If UID is omitted the\n");
312 fprintf(out, " calling uid is used.\n");
313 fprintf(out, " NAME The name of the configuration\n");
Chenjie Yub236c862017-11-28 22:20:44 -0800314 fprintf(out, " --proto Print proto binary.\n");
David Chenadaf8b32017-11-03 15:42:08 -0700315 fprintf(out, "\n");
316 fprintf(out, "\n");
David Chen1d7b0cd2017-11-15 14:20:04 -0800317 fprintf(out, "usage: adb shell cmd stats send-broadcast [UID] NAME\n");
318 fprintf(out, " Send a broadcast that triggers the subscriber to fetch metrics.\n");
319 fprintf(out, " UID The uid of the configuration. It is only possible to pass\n");
320 fprintf(out, " the UID parameter on eng builds. If UID is omitted the\n");
321 fprintf(out, " calling uid is used.\n");
322 fprintf(out, " NAME The name of the configuration\n");
323 fprintf(out, "\n");
324 fprintf(out, "\n");
Yao Chenf5acabe2018-01-17 14:10:34 -0800325 fprintf(out, "usage: adb shell cmd stats print-stats\n");
David Chen1d7b0cd2017-11-15 14:20:04 -0800326 fprintf(out, " Prints some basic stats.\n");
Chenjie Yufa22d652018-02-05 14:37:48 -0800327 fprintf(out, "\n");
328 fprintf(out, "\n");
329 fprintf(out, "usage: adb shell cmd stats clear-puller-cache\n");
330 fprintf(out, " Clear cached puller data.\n");
David Chenadaf8b32017-11-03 15:42:08 -0700331}
332
David Chen1d7b0cd2017-11-15 14:20:04 -0800333status_t StatsService::cmd_trigger_broadcast(FILE* out, Vector<String8>& args) {
334 string name;
335 bool good = false;
336 int uid;
337 const int argCount = args.size();
338 if (argCount == 2) {
339 // Automatically pick the UID
340 uid = IPCThreadState::self()->getCallingUid();
341 // TODO: What if this isn't a binder call? Should we fail?
342 name.assign(args[1].c_str(), args[1].size());
343 good = true;
344 } else if (argCount == 3) {
345 // If it's a userdebug or eng build, then the shell user can
346 // impersonate other uids.
347 if (mEngBuild) {
348 const char* s = args[1].c_str();
349 if (*s != '\0') {
350 char* end = NULL;
351 uid = strtol(s, &end, 0);
352 if (*end == '\0') {
353 name.assign(args[2].c_str(), args[2].size());
354 good = true;
355 }
356 }
357 } else {
358 fprintf(out,
359 "The metrics can only be dumped for other UIDs on eng or userdebug "
360 "builds.\n");
361 }
362 }
363 if (!good) {
364 print_cmd_help(out);
365 return UNKNOWN_ERROR;
366 }
Yangster-mac94e197c2018-01-02 16:03:03 -0800367 auto receiver = mConfigManager->GetConfigReceiver(ConfigKey(uid, StrToInt64(name)));
yro4d889e62017-11-17 15:44:48 -0800368 sp<IStatsCompanionService> sc = getStatsCompanionService();
369 if (sc != nullptr) {
370 sc->sendBroadcast(String16(receiver.first.c_str()), String16(receiver.second.c_str()));
yro74fed972017-11-27 14:42:42 -0800371 VLOG("StatsService::trigger broadcast succeeded to %s, %s", args[1].c_str(),
372 args[2].c_str());
yro4d889e62017-11-17 15:44:48 -0800373 } else {
yro74fed972017-11-27 14:42:42 -0800374 VLOG("Could not access statsCompanion");
yro4d889e62017-11-17 15:44:48 -0800375 }
376
David Chenadaf8b32017-11-03 15:42:08 -0700377 return NO_ERROR;
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700378}
379
380status_t StatsService::cmd_config(FILE* in, FILE* out, FILE* err, Vector<String8>& args) {
381 const int argCount = args.size();
382 if (argCount >= 2) {
383 if (args[1] == "update" || args[1] == "remove") {
384 bool good = false;
385 int uid = -1;
386 string name;
387
388 if (argCount == 3) {
389 // Automatically pick the UID
390 uid = IPCThreadState::self()->getCallingUid();
391 // TODO: What if this isn't a binder call? Should we fail?
392 name.assign(args[2].c_str(), args[2].size());
393 good = true;
394 } else if (argCount == 4) {
395 // If it's a userdebug or eng build, then the shell user can
396 // impersonate other uids.
397 if (mEngBuild) {
398 const char* s = args[2].c_str();
399 if (*s != '\0') {
400 char* end = NULL;
401 uid = strtol(s, &end, 0);
402 if (*end == '\0') {
403 name.assign(args[3].c_str(), args[3].size());
404 good = true;
405 }
406 }
407 } else {
Yao Chen729093d2017-10-16 10:33:26 -0700408 fprintf(err,
409 "The config can only be set for other UIDs on eng or userdebug "
410 "builds.\n");
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700411 }
yroe5f82922018-01-22 18:37:27 -0800412 } else if (argCount == 2 && args[1] == "remove") {
413 good = true;
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700414 }
415
416 if (!good) {
417 // If arg parsing failed, print the help text and return an error.
418 print_cmd_help(out);
419 return UNKNOWN_ERROR;
420 }
421
422 if (args[1] == "update") {
423 // Read stream into buffer.
424 string buffer;
425 if (!android::base::ReadFdToString(fileno(in), &buffer)) {
426 fprintf(err, "Error reading stream for StatsConfig.\n");
427 return UNKNOWN_ERROR;
428 }
429
430 // Parse buffer.
431 StatsdConfig config;
432 if (!config.ParseFromString(buffer)) {
433 fprintf(err, "Error parsing proto stream for StatsConfig.\n");
434 return UNKNOWN_ERROR;
435 }
436
437 // Add / update the config.
Yangster-mac94e197c2018-01-02 16:03:03 -0800438 mConfigManager->UpdateConfig(ConfigKey(uid, StrToInt64(name)), config);
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700439 } else {
yro74fed972017-11-27 14:42:42 -0800440 if (argCount == 2) {
441 cmd_remove_all_configs(out);
442 } else {
443 // Remove the config.
Yangster-mac94e197c2018-01-02 16:03:03 -0800444 mConfigManager->RemoveConfig(ConfigKey(uid, StrToInt64(name)));
yro74fed972017-11-27 14:42:42 -0800445 }
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700446 }
447
448 return NO_ERROR;
449 }
David Chen0656b7a2017-09-13 15:53:39 -0700450 }
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700451 print_cmd_help(out);
452 return UNKNOWN_ERROR;
453}
454
Yao Chen729093d2017-10-16 10:33:26 -0700455status_t StatsService::cmd_dump_report(FILE* out, FILE* err, const Vector<String8>& args) {
456 if (mProcessor != nullptr) {
Chenjie Yub236c862017-11-28 22:20:44 -0800457 int argCount = args.size();
Yao Chen729093d2017-10-16 10:33:26 -0700458 bool good = false;
Chenjie Yub236c862017-11-28 22:20:44 -0800459 bool proto = false;
Yao Chen729093d2017-10-16 10:33:26 -0700460 int uid;
461 string name;
Chenjie Yub236c862017-11-28 22:20:44 -0800462 if (!std::strcmp("--proto", args[argCount-1].c_str())) {
463 proto = true;
464 argCount -= 1;
465 }
Yao Chen729093d2017-10-16 10:33:26 -0700466 if (argCount == 2) {
467 // Automatically pick the UID
468 uid = IPCThreadState::self()->getCallingUid();
469 // TODO: What if this isn't a binder call? Should we fail?
Yao Chen5154a372017-10-30 22:57:06 -0700470 name.assign(args[1].c_str(), args[1].size());
Yao Chen729093d2017-10-16 10:33:26 -0700471 good = true;
472 } else if (argCount == 3) {
473 // If it's a userdebug or eng build, then the shell user can
474 // impersonate other uids.
475 if (mEngBuild) {
476 const char* s = args[1].c_str();
477 if (*s != '\0') {
478 char* end = NULL;
479 uid = strtol(s, &end, 0);
480 if (*end == '\0') {
481 name.assign(args[2].c_str(), args[2].size());
482 good = true;
483 }
484 }
485 } else {
486 fprintf(out,
487 "The metrics can only be dumped for other UIDs on eng or userdebug "
488 "builds.\n");
489 }
490 }
491 if (good) {
David Chen1d7b0cd2017-11-15 14:20:04 -0800492 vector<uint8_t> data;
Yangster-mac94e197c2018-01-02 16:03:03 -0800493 mProcessor->onDumpReport(ConfigKey(uid, StrToInt64(name)), &data);
Yao Chen729093d2017-10-16 10:33:26 -0700494 // TODO: print the returned StatsLogReport to file instead of printing to logcat.
Chenjie Yub236c862017-11-28 22:20:44 -0800495 if (proto) {
496 for (size_t i = 0; i < data.size(); i ++) {
497 fprintf(out, "%c", data[i]);
498 }
499 } else {
500 fprintf(out, "Dump report for Config [%d,%s]\n", uid, name.c_str());
501 fprintf(out, "See the StatsLogReport in logcat...\n");
502 }
Yao Chen729093d2017-10-16 10:33:26 -0700503 return android::OK;
504 } else {
505 // If arg parsing failed, print the help text and return an error.
506 print_cmd_help(out);
507 return UNKNOWN_ERROR;
508 }
509 } else {
510 fprintf(out, "Log processor does not exist...\n");
511 return UNKNOWN_ERROR;
512 }
513}
514
Yao Chenb3561512017-11-21 18:07:17 -0800515status_t StatsService::cmd_print_stats(FILE* out, const Vector<String8>& args) {
David Chen1d7b0cd2017-11-15 14:20:04 -0800516 vector<ConfigKey> configs = mConfigManager->GetAllConfigKeys();
517 for (const ConfigKey& key : configs) {
518 fprintf(out, "Config %s uses %zu bytes\n", key.ToString().c_str(),
519 mProcessor->GetMetricsSize(key));
520 }
Yao Chenb3561512017-11-21 18:07:17 -0800521 StatsdStats& statsdStats = StatsdStats::getInstance();
Yao Chenf5acabe2018-01-17 14:10:34 -0800522 statsdStats.dumpStats(out);
David Chen1d7b0cd2017-11-15 14:20:04 -0800523 return NO_ERROR;
524}
525
Yao Chend10f7b12017-12-18 12:53:50 -0800526status_t StatsService::cmd_print_uid_map(FILE* out, const Vector<String8>& args) {
527 if (args.size() > 1) {
528 string pkg;
529 pkg.assign(args[1].c_str(), args[1].size());
530 auto uids = mUidMap->getAppUid(pkg);
531 fprintf(out, "%s -> [ ", pkg.c_str());
532 for (const auto& uid : uids) {
533 fprintf(out, "%d ", uid);
534 }
535 fprintf(out, "]\n");
536 } else {
537 mUidMap->printUidMap(out);
538 }
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700539 return NO_ERROR;
David Chen0656b7a2017-09-13 15:53:39 -0700540}
541
yro947fbce2017-11-15 22:50:23 -0800542status_t StatsService::cmd_write_data_to_disk(FILE* out) {
543 fprintf(out, "Writing data to disk\n");
544 mProcessor->WriteDataToDisk();
545 return NO_ERROR;
546}
547
Bookatzb223c4e2018-02-01 15:35:04 -0800548status_t StatsService::cmd_log_app_hook(FILE* out, const Vector<String8>& args) {
549 bool good = false;
550 int32_t uid;
551 int32_t label;
552 int32_t state;
553 const int argCount = args.size();
554 if (argCount == 3) {
555 // Automatically pick the UID
556 uid = IPCThreadState::self()->getCallingUid();
557 label = atoi(args[1].c_str());
558 state = atoi(args[2].c_str());
559 good = true;
560 } else if (argCount == 4) {
561 uid = atoi(args[1].c_str());
562 // If it's a userdebug or eng build, then the shell user can impersonate other uids.
563 // Otherwise, the uid must match the actual caller's uid.
564 if (mEngBuild || (uid >= 0 && (uid_t)uid == IPCThreadState::self()->getCallingUid())) {
565 label = atoi(args[2].c_str());
566 state = atoi(args[3].c_str());
567 good = true;
568 } else {
569 fprintf(out,
570 "Selecting a UID for writing AppHook can only be dumped for other UIDs on eng"
571 " or userdebug builds.\n");
572 }
573 }
574 if (good) {
575 fprintf(out, "Logging AppHook(%d, %d, %d) to statslog.\n", uid, label, state);
576 android::util::stats_write(android::util::APP_HOOK, uid, label, state);
577 } else {
578 print_cmd_help(out);
579 return UNKNOWN_ERROR;
580 }
581 return NO_ERROR;
582}
583
David Chen1481fe12017-10-16 13:16:34 -0700584status_t StatsService::cmd_print_pulled_metrics(FILE* out, const Vector<String8>& args) {
585 int s = atoi(args[1].c_str());
Chenjie Yu5305e1d2017-10-31 13:49:36 -0700586 vector<shared_ptr<LogEvent> > stats;
587 if (mStatsPullerManager.Pull(s, &stats)) {
588 for (const auto& it : stats) {
589 fprintf(out, "Pull from %d: %s\n", s, it->ToString().c_str());
590 }
591 fprintf(out, "Pull from %d: Received %zu elements\n", s, stats.size());
592 return NO_ERROR;
David Chen1481fe12017-10-16 13:16:34 -0700593 }
Chenjie Yu5305e1d2017-10-31 13:49:36 -0700594 return UNKNOWN_ERROR;
David Chen1481fe12017-10-16 13:16:34 -0700595}
596
yro74fed972017-11-27 14:42:42 -0800597status_t StatsService::cmd_remove_all_configs(FILE* out) {
598 fprintf(out, "Removing all configs...\n");
599 VLOG("StatsService::cmd_remove_all_configs was called");
600 mConfigManager->RemoveAllConfigs();
yro947fbce2017-11-15 22:50:23 -0800601 StorageManager::deleteAllFiles(STATS_SERVICE_DIR);
yro87d983c2017-11-14 21:31:43 -0800602 return NO_ERROR;
603}
604
Yao Chen8d9989b2017-11-18 18:54:50 -0800605status_t StatsService::cmd_dump_memory_info(FILE* out) {
606 std::string s = dumpMemInfo(100);
607 fprintf(out, "Memory Info\n");
608 fprintf(out, "%s", s.c_str());
609 return NO_ERROR;
610}
611
Chenjie Yue72252b2018-02-01 13:19:35 -0800612status_t StatsService::cmd_clear_puller_cache(FILE* out) {
Chenjie Yufa22d652018-02-05 14:37:48 -0800613 IPCThreadState* ipc = IPCThreadState::self();
614 VLOG("StatsService::cmd_clear_puller_cache with Pid %i, Uid %i", ipc->getCallingPid(), ipc->getCallingUid());
615 if (checkCallingPermission(String16(kPermissionDump))) {
616 int cleared = mStatsPullerManager.ForceClearPullerCache();
617 fprintf(out, "Puller removed %d cached data!\n", cleared);
618 return NO_ERROR;
619 } else {
620 return PERMISSION_DENIED;
621 }
Chenjie Yue72252b2018-02-01 13:19:35 -0800622}
623
Dianne Hackborn3accca02013-09-20 09:32:11 -0700624Status StatsService::informAllUidData(const vector<int32_t>& uid, const vector<int64_t>& version,
David Chende701692017-10-05 13:16:02 -0700625 const vector<String16>& app) {
yro74fed972017-11-27 14:42:42 -0800626 VLOG("StatsService::informAllUidData was called");
David Chende701692017-10-05 13:16:02 -0700627
628 if (IPCThreadState::self()->getCallingUid() != AID_SYSTEM) {
629 return Status::fromExceptionCode(Status::EX_SECURITY,
630 "Only system uid can call informAllUidData");
631 }
632
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700633 mUidMap->updateMap(uid, version, app);
yro74fed972017-11-27 14:42:42 -0800634 VLOG("StatsService::informAllUidData succeeded");
David Chende701692017-10-05 13:16:02 -0700635
636 return Status::ok();
637}
638
Dianne Hackborn3accca02013-09-20 09:32:11 -0700639Status StatsService::informOnePackage(const String16& app, int32_t uid, int64_t version) {
yro74fed972017-11-27 14:42:42 -0800640 VLOG("StatsService::informOnePackage was called");
David Chende701692017-10-05 13:16:02 -0700641
642 if (IPCThreadState::self()->getCallingUid() != AID_SYSTEM) {
643 return Status::fromExceptionCode(Status::EX_SECURITY,
644 "Only system uid can call informOnePackage");
645 }
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700646 mUidMap->updateApp(app, uid, version);
David Chende701692017-10-05 13:16:02 -0700647 return Status::ok();
648}
649
650Status StatsService::informOnePackageRemoved(const String16& app, int32_t uid) {
yro74fed972017-11-27 14:42:42 -0800651 VLOG("StatsService::informOnePackageRemoved was called");
David Chende701692017-10-05 13:16:02 -0700652
653 if (IPCThreadState::self()->getCallingUid() != AID_SYSTEM) {
654 return Status::fromExceptionCode(Status::EX_SECURITY,
655 "Only system uid can call informOnePackageRemoved");
656 }
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700657 mUidMap->removeApp(app, uid);
David Chende701692017-10-05 13:16:02 -0700658 return Status::ok();
659}
660
Yao Chenef99c4f2017-09-22 16:26:54 -0700661Status StatsService::informAnomalyAlarmFired() {
yro74fed972017-11-27 14:42:42 -0800662 VLOG("StatsService::informAnomalyAlarmFired was called");
Bookatz1b0b1142017-09-08 11:58:42 -0700663
664 if (IPCThreadState::self()->getCallingUid() != AID_SYSTEM) {
665 return Status::fromExceptionCode(Status::EX_SECURITY,
Yao Chenef99c4f2017-09-22 16:26:54 -0700666 "Only system uid can call informAnomalyAlarmFired");
Bookatz1b0b1142017-09-08 11:58:42 -0700667 }
668
yro74fed972017-11-27 14:42:42 -0800669 VLOG("StatsService::informAnomalyAlarmFired succeeded");
Bookatzcc5adef2017-11-21 14:36:23 -0800670 uint64_t currentTimeSec = time(nullptr);
Yangster-mace2cd6d52017-11-09 20:38:30 -0800671 std::unordered_set<sp<const AnomalyAlarm>, SpHash<AnomalyAlarm>> anomalySet =
Bookatzcc5adef2017-11-21 14:36:23 -0800672 mAnomalyMonitor->popSoonerThan(static_cast<uint32_t>(currentTimeSec));
673 mProcessor->onAnomalyAlarmFired(currentTimeSec * NS_PER_SEC, anomalySet);
Bookatz1b0b1142017-09-08 11:58:42 -0700674 return Status::ok();
675}
676
Yao Chenef99c4f2017-09-22 16:26:54 -0700677Status StatsService::informPollAlarmFired() {
yro74fed972017-11-27 14:42:42 -0800678 VLOG("StatsService::informPollAlarmFired was called");
Bookatz1b0b1142017-09-08 11:58:42 -0700679
680 if (IPCThreadState::self()->getCallingUid() != AID_SYSTEM) {
681 return Status::fromExceptionCode(Status::EX_SECURITY,
Yao Chenef99c4f2017-09-22 16:26:54 -0700682 "Only system uid can call informPollAlarmFired");
Bookatz1b0b1142017-09-08 11:58:42 -0700683 }
684
Chenjie Yu5305e1d2017-10-31 13:49:36 -0700685 mStatsPullerManager.OnAlarmFired();
Chenjie Yub3dda412017-10-24 13:41:59 -0700686
yro74fed972017-11-27 14:42:42 -0800687 VLOG("StatsService::informPollAlarmFired succeeded");
Bookatz1b0b1142017-09-08 11:58:42 -0700688
689 return Status::ok();
690}
691
Yao Chenef99c4f2017-09-22 16:26:54 -0700692Status StatsService::systemRunning() {
Joe Onorato5dcbc6c2017-08-29 15:13:58 -0700693 if (IPCThreadState::self()->getCallingUid() != AID_SYSTEM) {
694 return Status::fromExceptionCode(Status::EX_SECURITY,
Yao Chenef99c4f2017-09-22 16:26:54 -0700695 "Only system uid can call systemRunning");
Joe Onorato5dcbc6c2017-08-29 15:13:58 -0700696 }
697
698 // When system_server is up and running, schedule the dropbox task to run.
yro74fed972017-11-27 14:42:42 -0800699 VLOG("StatsService::systemRunning");
Joe Onorato5dcbc6c2017-08-29 15:13:58 -0700700
Bookatzb487b552017-09-18 11:26:01 -0700701 sayHiToStatsCompanion();
702
Joe Onorato5dcbc6c2017-08-29 15:13:58 -0700703 return Status::ok();
704}
705
yro947fbce2017-11-15 22:50:23 -0800706Status StatsService::writeDataToDisk() {
707 if (IPCThreadState::self()->getCallingUid() != AID_SYSTEM) {
708 return Status::fromExceptionCode(Status::EX_SECURITY,
709 "Only system uid can call systemRunning");
710 }
711
yro74fed972017-11-27 14:42:42 -0800712 VLOG("StatsService::writeDataToDisk");
yro947fbce2017-11-15 22:50:23 -0800713
714 mProcessor->WriteDataToDisk();
715
716 return Status::ok();
717}
718
Yao Chenef99c4f2017-09-22 16:26:54 -0700719void StatsService::sayHiToStatsCompanion() {
720 // TODO: This method needs to be private. It is temporarily public and unsecured for testing
721 // purposes.
Bookatzb487b552017-09-18 11:26:01 -0700722 sp<IStatsCompanionService> statsCompanion = getStatsCompanionService();
723 if (statsCompanion != nullptr) {
yro74fed972017-11-27 14:42:42 -0800724 VLOG("Telling statsCompanion that statsd is ready");
Bookatzb487b552017-09-18 11:26:01 -0700725 statsCompanion->statsdReady();
726 } else {
yro74fed972017-11-27 14:42:42 -0800727 VLOG("Could not access statsCompanion");
Bookatzb487b552017-09-18 11:26:01 -0700728 }
729}
730
Yao Chenef99c4f2017-09-22 16:26:54 -0700731sp<IStatsCompanionService> StatsService::getStatsCompanionService() {
Bookatz906a35c2017-09-20 15:26:44 -0700732 sp<IStatsCompanionService> statsCompanion = nullptr;
733 // Get statscompanion service from service manager
734 const sp<IServiceManager> sm(defaultServiceManager());
735 if (sm != nullptr) {
736 const String16 name("statscompanion");
737 statsCompanion = interface_cast<IStatsCompanionService>(sm->checkService(name));
738 if (statsCompanion == nullptr) {
739 ALOGW("statscompanion service unavailable!");
740 return nullptr;
741 }
742 }
743 return statsCompanion;
744}
745
Yao Chenef99c4f2017-09-22 16:26:54 -0700746Status StatsService::statsCompanionReady() {
yro74fed972017-11-27 14:42:42 -0800747 VLOG("StatsService::statsCompanionReady was called");
Bookatzb487b552017-09-18 11:26:01 -0700748
749 if (IPCThreadState::self()->getCallingUid() != AID_SYSTEM) {
750 return Status::fromExceptionCode(Status::EX_SECURITY,
751 "Only system uid can call statsCompanionReady");
752 }
753
754 sp<IStatsCompanionService> statsCompanion = getStatsCompanionService();
755 if (statsCompanion == nullptr) {
Yao Chenef99c4f2017-09-22 16:26:54 -0700756 return Status::fromExceptionCode(
757 Status::EX_NULL_POINTER,
758 "statscompanion unavailable despite it contacting statsd!");
Bookatzb487b552017-09-18 11:26:01 -0700759 }
yro74fed972017-11-27 14:42:42 -0800760 VLOG("StatsService::statsCompanionReady linking to statsCompanion.");
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700761 IInterface::asBinder(statsCompanion)->linkToDeath(new CompanionDeathRecipient(mAnomalyMonitor));
Bookatzb487b552017-09-18 11:26:01 -0700762 mAnomalyMonitor->setStatsCompanionService(statsCompanion);
Bookatzc6977972018-01-16 16:55:05 -0800763 SubscriberReporter::getInstance().setStatsCompanionService(statsCompanion);
Bookatzb487b552017-09-18 11:26:01 -0700764
765 return Status::ok();
766}
767
Joe Onorato9fc9edf2017-10-15 20:08:52 -0700768void StatsService::Startup() {
769 mConfigManager->Startup();
Bookatz906a35c2017-09-20 15:26:44 -0700770}
771
Yangster-macd40053e2018-01-09 16:29:22 -0800772void StatsService::OnLogEvent(LogEvent* event) {
Joe Onoratoc4dfae52017-10-17 23:38:21 -0700773 mProcessor->OnLogEvent(event);
Bookatz906a35c2017-09-20 15:26:44 -0700774}
775
Yangster-mac94e197c2018-01-02 16:03:03 -0800776Status StatsService::getData(int64_t key, vector<uint8_t>* output) {
David Chenadaf8b32017-11-03 15:42:08 -0700777 IPCThreadState* ipc = IPCThreadState::self();
yro74fed972017-11-27 14:42:42 -0800778 VLOG("StatsService::getData with Pid %i, Uid %i", ipc->getCallingPid(), ipc->getCallingUid());
Yao Chen7ee94152017-11-17 09:44:40 -0800779 if (checkCallingPermission(String16(kPermissionDump))) {
Yangster-mac94e197c2018-01-02 16:03:03 -0800780 ConfigKey configKey(ipc->getCallingUid(), key);
David Chen1d7b0cd2017-11-15 14:20:04 -0800781 mProcessor->onDumpReport(configKey, output);
David Chenadaf8b32017-11-03 15:42:08 -0700782 return Status::ok();
783 } else {
784 return Status::fromExceptionCode(binder::Status::EX_SECURITY);
785 }
yro31eb67b2017-10-24 13:33:21 -0700786}
787
David Chen2e8f3802017-11-22 10:56:48 -0800788Status StatsService::getMetadata(vector<uint8_t>* output) {
789 IPCThreadState* ipc = IPCThreadState::self();
790 VLOG("StatsService::getMetadata with Pid %i, Uid %i", ipc->getCallingPid(),
791 ipc->getCallingUid());
792 if (checkCallingPermission(String16(kPermissionDump))) {
793 StatsdStats::getInstance().dumpStats(output, false); // Don't reset the counters.
794 return Status::ok();
795 } else {
796 return Status::fromExceptionCode(binder::Status::EX_SECURITY);
797 }
798}
799
Yangster-mac94e197c2018-01-02 16:03:03 -0800800Status StatsService::addConfiguration(int64_t key,
David Chenadaf8b32017-11-03 15:42:08 -0700801 const vector <uint8_t>& config,
802 const String16& package, const String16& cls,
803 bool* success) {
804 IPCThreadState* ipc = IPCThreadState::self();
Yao Chen7ee94152017-11-17 09:44:40 -0800805 if (checkCallingPermission(String16(kPermissionDump))) {
Yangster-mac94e197c2018-01-02 16:03:03 -0800806 ConfigKey configKey(ipc->getCallingUid(), key);
David Chenadaf8b32017-11-03 15:42:08 -0700807 StatsdConfig cfg;
Yangster-macbbd056a2018-01-22 13:37:02 -0800808 if (config.empty() || !cfg.ParseFromArray(&config[0], config.size())) {
David Chen7d8aa4d2017-12-27 13:37:01 -0800809 *success = false;
810 return Status::ok();
811 }
David Chenadaf8b32017-11-03 15:42:08 -0700812 mConfigManager->UpdateConfig(configKey, cfg);
813 mConfigManager->SetConfigReceiver(configKey, string(String8(package).string()),
814 string(String8(cls).string()));
815 *success = true;
816 return Status::ok();
817 } else {
Yao Chenaa39bc72017-12-01 11:16:50 -0800818 *success = false;
David Chenadaf8b32017-11-03 15:42:08 -0700819 return Status::fromExceptionCode(binder::Status::EX_SECURITY);
yro31eb67b2017-10-24 13:33:21 -0700820 }
yro31eb67b2017-10-24 13:33:21 -0700821}
822
Yangster-mac94e197c2018-01-02 16:03:03 -0800823Status StatsService::removeConfiguration(int64_t key, bool* success) {
David Chenadaf8b32017-11-03 15:42:08 -0700824 IPCThreadState* ipc = IPCThreadState::self();
Yao Chen7ee94152017-11-17 09:44:40 -0800825 if (checkCallingPermission(String16(kPermissionDump))) {
Bookatzc6977972018-01-16 16:55:05 -0800826 ConfigKey configKey(ipc->getCallingUid(), key);
827 mConfigManager->RemoveConfig(configKey);
828 SubscriberReporter::getInstance().removeConfig(configKey);
Yao Chenaa39bc72017-12-01 11:16:50 -0800829 *success = true;
David Chenadaf8b32017-11-03 15:42:08 -0700830 return Status::ok();
831 } else {
832 *success = false;
833 return Status::fromExceptionCode(binder::Status::EX_SECURITY);
yro31eb67b2017-10-24 13:33:21 -0700834 }
yro31eb67b2017-10-24 13:33:21 -0700835}
836
Bookatzc6977972018-01-16 16:55:05 -0800837Status StatsService::setBroadcastSubscriber(int64_t configId,
838 int64_t subscriberId,
839 const sp<android::IBinder>& intentSender,
840 bool* success) {
841 VLOG("StatsService::setBroadcastSubscriber called.");
842 IPCThreadState* ipc = IPCThreadState::self();
843 if (checkCallingPermission(String16(kPermissionDump))) {
844 ConfigKey configKey(ipc->getCallingUid(), configId);
845 SubscriberReporter::getInstance()
846 .setBroadcastSubscriber(configKey, subscriberId, intentSender);
847 *success = true;
848 return Status::ok();
849 } else {
850 *success = false;
851 return Status::fromExceptionCode(binder::Status::EX_SECURITY);
852 }
853}
854
855Status StatsService::unsetBroadcastSubscriber(int64_t configId,
856 int64_t subscriberId,
857 bool* success) {
858 VLOG("StatsService::unsetBroadcastSubscriber called.");
859 IPCThreadState* ipc = IPCThreadState::self();
860 if (checkCallingPermission(String16(kPermissionDump))) {
861 ConfigKey configKey(ipc->getCallingUid(), configId);
862 SubscriberReporter::getInstance()
863 .unsetBroadcastSubscriber(configKey, subscriberId);
864 *success = true;
865 return Status::ok();
866 } else {
867 *success = false;
868 return Status::fromExceptionCode(binder::Status::EX_SECURITY);
869 }
870}
871
872
David Chen1d7b0cd2017-11-15 14:20:04 -0800873void StatsService::binderDied(const wp <IBinder>& who) {
yro31eb67b2017-10-24 13:33:21 -0700874}
875
Yao Chenef99c4f2017-09-22 16:26:54 -0700876} // namespace statsd
877} // namespace os
878} // namespace android