blob: cf0264700bbba2e922a3993cb31e5b2f4eeeb1e7 [file] [log] [blame]
Colin Crossf45fa6b2012-03-26 12:38:26 -07001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Arve Hjønnevåg2db0f5f2014-10-15 18:08:37 -070017#include <dirent.h>
Colin Crossf45fa6b2012-03-26 12:38:26 -070018#include <errno.h>
19#include <fcntl.h>
20#include <limits.h>
Felipe Leme6e01fa62015-11-11 19:35:14 -080021#include <memory>
Mark Salyzyn8f37aa52015-06-12 12:28:24 -070022#include <stdbool.h>
Colin Crossf45fa6b2012-03-26 12:38:26 -070023#include <stdio.h>
24#include <stdlib.h>
Felipe Leme6e01fa62015-11-11 19:35:14 -080025#include <string>
Colin Crossf45fa6b2012-03-26 12:38:26 -070026#include <string.h>
Christopher Ferris7dc7f322014-07-22 16:08:19 -070027#include <sys/capability.h>
28#include <sys/prctl.h>
Colin Crossf45fa6b2012-03-26 12:38:26 -070029#include <sys/resource.h>
30#include <sys/stat.h>
31#include <sys/time.h>
32#include <sys/wait.h>
33#include <unistd.h>
Colin Crossf45fa6b2012-03-26 12:38:26 -070034
Felipe Leme6e01fa62015-11-11 19:35:14 -080035#include <base/stringprintf.h>
Colin Crossf45fa6b2012-03-26 12:38:26 -070036#include <cutils/properties.h>
37
38#include "private/android_filesystem_config.h"
39
40#define LOG_TAG "dumpstate"
Alex Ray656a6b92013-07-23 13:44:34 -070041#include <cutils/log.h>
Colin Crossf45fa6b2012-03-26 12:38:26 -070042
43#include "dumpstate.h"
Felipe Leme6e01fa62015-11-11 19:35:14 -080044#include "ScopedFd.h"
45#include "ziparchive/zip_writer.h"
46
47using android::base::StringPrintf;
Colin Crossf45fa6b2012-03-26 12:38:26 -070048
49/* read before root is shed */
50static char cmdline_buf[16384] = "(unknown)";
51static const char *dump_traces_path = NULL;
52
Felipe Leme6e01fa62015-11-11 19:35:14 -080053static std::string screenshot_path;
Colin Crossf45fa6b2012-03-26 12:38:26 -070054
Todd Poynor2a83daa2013-11-22 15:44:22 -080055#define PSTORE_LAST_KMSG "/sys/fs/pstore/console-ramoops"
56
Sharvil Nanavati8d4cb7f2015-07-24 02:01:13 -070057#define RAFT_DIR "/data/misc/raft/"
Christopher Ferris7dc7f322014-07-22 16:08:19 -070058#define TOMBSTONE_DIR "/data/tombstones"
59#define TOMBSTONE_FILE_PREFIX TOMBSTONE_DIR "/tombstone_"
60/* Can accomodate a tombstone number up to 9999. */
61#define TOMBSTONE_MAX_LEN (sizeof(TOMBSTONE_FILE_PREFIX) + 4)
62#define NUM_TOMBSTONES 10
63
64typedef struct {
65 char name[TOMBSTONE_MAX_LEN];
66 int fd;
67} tombstone_data_t;
68
69static tombstone_data_t tombstone_data[NUM_TOMBSTONES];
70
71/* Get the fds of any tombstone that was modified in the last half an hour. */
72static void get_tombstone_fds(tombstone_data_t data[NUM_TOMBSTONES]) {
73 time_t thirty_minutes_ago = time(NULL) - 60*30;
74 for (size_t i = 0; i < NUM_TOMBSTONES; i++) {
75 snprintf(data[i].name, sizeof(data[i].name), "%s%02zu", TOMBSTONE_FILE_PREFIX, i);
Christopher Ferris54bcc5f2015-02-10 12:15:01 -080076 int fd = TEMP_FAILURE_RETRY(open(data[i].name,
77 O_RDONLY | O_CLOEXEC | O_NOFOLLOW | O_NONBLOCK));
Christopher Ferris7dc7f322014-07-22 16:08:19 -070078 struct stat st;
79 if (fstat(fd, &st) == 0 && S_ISREG(st.st_mode) &&
80 (time_t) st.st_mtime >= thirty_minutes_ago) {
81 data[i].fd = fd;
82 } else {
83 close(fd);
84 data[i].fd = -1;
85 }
86 }
87}
88
Arve Hjønnevåg2db0f5f2014-10-15 18:08:37 -070089static void dump_dev_files(const char *title, const char *driverpath, const char *filename)
90{
91 DIR *d;
92 struct dirent *de;
93 char path[PATH_MAX];
94
95 d = opendir(driverpath);
96 if (d == NULL) {
97 return;
98 }
99
100 while ((de = readdir(d))) {
101 if (de->d_type != DT_LNK) {
102 continue;
103 }
104 snprintf(path, sizeof(path), "%s/%s/%s", driverpath, de->d_name, filename);
105 dump_file(title, path);
106 }
107
108 closedir(d);
109}
110
Mark Salyzyn326842f2015-04-30 09:49:41 -0700111static bool skip_not_stat(const char *path) {
112 static const char stat[] = "/stat";
113 size_t len = strlen(path);
114 if (path[len - 1] == '/') { /* Directory? */
115 return false;
116 }
117 return strcmp(path + len - sizeof(stat) + 1, stat); /* .../stat? */
118}
119
120static const char mmcblk0[] = "/sys/block/mmcblk0/";
Mark Salyzyn8f37aa52015-06-12 12:28:24 -0700121unsigned long worst_write_perf = 20000; /* in KB/s */
Mark Salyzyn326842f2015-04-30 09:49:41 -0700122
123static int dump_stat_from_fd(const char *title __unused, const char *path, int fd) {
124 unsigned long fields[11], read_perf, write_perf;
125 bool z;
126 char *cp, *buffer = NULL;
127 size_t i = 0;
128 FILE *fp = fdopen(fd, "rb");
129 getline(&buffer, &i, fp);
130 fclose(fp);
131 if (!buffer) {
132 return -errno;
133 }
134 i = strlen(buffer);
135 while ((i > 0) && (buffer[i - 1] == '\n')) {
136 buffer[--i] = '\0';
137 }
138 if (!*buffer) {
139 free(buffer);
140 return 0;
141 }
142 z = true;
143 for (cp = buffer, i = 0; i < (sizeof(fields) / sizeof(fields[0])); ++i) {
144 fields[i] = strtol(cp, &cp, 0);
145 if (fields[i] != 0) {
146 z = false;
147 }
148 }
149 if (z) { /* never accessed */
150 free(buffer);
151 return 0;
152 }
153
154 if (!strncmp(path, mmcblk0, sizeof(mmcblk0) - 1)) {
155 path += sizeof(mmcblk0) - 1;
156 }
157
158 printf("%s: %s\n", path, buffer);
159 free(buffer);
160
161 read_perf = 0;
162 if (fields[3]) {
163 read_perf = 512 * fields[2] / fields[3];
164 }
165 write_perf = 0;
166 if (fields[7]) {
167 write_perf = 512 * fields[6] / fields[7];
168 }
169 printf("%s: read: %luKB/s write: %luKB/s\n", path, read_perf, write_perf);
Mark Salyzyn8f37aa52015-06-12 12:28:24 -0700170 if ((write_perf > 1) && (write_perf < worst_write_perf)) {
171 worst_write_perf = write_perf;
172 }
Mark Salyzyn326842f2015-04-30 09:49:41 -0700173 return 0;
174}
175
Mark Salyzyn8f37aa52015-06-12 12:28:24 -0700176/* Copied policy from system/core/logd/LogBuffer.cpp */
177
178#define LOG_BUFFER_SIZE (256 * 1024)
179#define LOG_BUFFER_MIN_SIZE (64 * 1024UL)
180#define LOG_BUFFER_MAX_SIZE (256 * 1024 * 1024UL)
181
182static bool valid_size(unsigned long value) {
183 if ((value < LOG_BUFFER_MIN_SIZE) || (LOG_BUFFER_MAX_SIZE < value)) {
184 return false;
185 }
186
187 long pages = sysconf(_SC_PHYS_PAGES);
188 if (pages < 1) {
189 return true;
190 }
191
192 long pagesize = sysconf(_SC_PAGESIZE);
193 if (pagesize <= 1) {
194 pagesize = PAGE_SIZE;
195 }
196
197 // maximum memory impact a somewhat arbitrary ~3%
198 pages = (pages + 31) / 32;
199 unsigned long maximum = pages * pagesize;
200
201 if ((maximum < LOG_BUFFER_MIN_SIZE) || (LOG_BUFFER_MAX_SIZE < maximum)) {
202 return true;
203 }
204
205 return value <= maximum;
206}
207
208static unsigned long property_get_size(const char *key) {
209 unsigned long value;
210 char *cp, property[PROPERTY_VALUE_MAX];
211
212 property_get(key, property, "");
213 value = strtoul(property, &cp, 10);
214
215 switch(*cp) {
216 case 'm':
217 case 'M':
218 value *= 1024;
219 /* FALLTHRU */
220 case 'k':
221 case 'K':
222 value *= 1024;
223 /* FALLTHRU */
224 case '\0':
225 break;
226
227 default:
228 value = 0;
229 }
230
231 if (!valid_size(value)) {
232 value = 0;
233 }
234
235 return value;
236}
237
238/* timeout in ms */
Felipe Leme8620bb42015-11-10 11:04:45 -0800239static unsigned long logcat_timeout(const char *name) {
Mark Salyzyn8f37aa52015-06-12 12:28:24 -0700240 static const char global_tuneable[] = "persist.logd.size"; // Settings App
241 static const char global_default[] = "ro.logd.size"; // BoardConfig.mk
242 char key[PROP_NAME_MAX];
243 unsigned long property_size, default_size;
244
245 default_size = property_get_size(global_tuneable);
246 if (!default_size) {
247 default_size = property_get_size(global_default);
248 }
249
250 snprintf(key, sizeof(key), "%s.%s", global_tuneable, name);
251 property_size = property_get_size(key);
252
253 if (!property_size) {
254 snprintf(key, sizeof(key), "%s.%s", global_default, name);
255 property_size = property_get_size(key);
256 }
257
258 if (!property_size) {
259 property_size = default_size;
260 }
261
262 if (!property_size) {
263 property_size = LOG_BUFFER_SIZE;
264 }
265
266 /* Engineering margin is ten-fold our guess */
267 return 10 * (property_size + worst_write_perf) / worst_write_perf;
268}
269
270/* End copy from system/core/logd/LogBuffer.cpp */
271
Colin Crossf45fa6b2012-03-26 12:38:26 -0700272/* dumps the current system state to stdout */
273static void dumpstate() {
Mark Salyzyn8f37aa52015-06-12 12:28:24 -0700274 unsigned long timeout;
Colin Crossf45fa6b2012-03-26 12:38:26 -0700275 time_t now = time(NULL);
276 char build[PROPERTY_VALUE_MAX], fingerprint[PROPERTY_VALUE_MAX];
277 char radio[PROPERTY_VALUE_MAX], bootloader[PROPERTY_VALUE_MAX];
278 char network[PROPERTY_VALUE_MAX], date[80];
279 char build_type[PROPERTY_VALUE_MAX];
280
281 property_get("ro.build.display.id", build, "(unknown)");
282 property_get("ro.build.fingerprint", fingerprint, "(unknown)");
283 property_get("ro.build.type", build_type, "(unknown)");
284 property_get("ro.baseband", radio, "(unknown)");
285 property_get("ro.bootloader", bootloader, "(unknown)");
286 property_get("gsm.operator.alpha", network, "(unknown)");
287 strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S", localtime(&now));
288
289 printf("========================================================\n");
290 printf("== dumpstate: %s\n", date);
291 printf("========================================================\n");
292
293 printf("\n");
294 printf("Build: %s\n", build);
295 printf("Build fingerprint: '%s'\n", fingerprint); /* format is important for other tools */
296 printf("Bootloader: %s\n", bootloader);
297 printf("Radio: %s\n", radio);
298 printf("Network: %s\n", network);
299
300 printf("Kernel: ");
301 dump_file(NULL, "/proc/version");
302 printf("Command line: %s\n", strtok(cmdline_buf, "\n"));
303 printf("\n");
304
Arve Hjønnevåg2db0f5f2014-10-15 18:08:37 -0700305 dump_dev_files("TRUSTY VERSION", "/sys/bus/platform/drivers/trusty", "trusty_version");
Colin Crossf45fa6b2012-03-26 12:38:26 -0700306 run_command("UPTIME", 10, "uptime", NULL);
Mark Salyzyn326842f2015-04-30 09:49:41 -0700307 dump_files("UPTIME MMC PERF", mmcblk0, skip_not_stat, dump_stat_from_fd);
Colin Crossf45fa6b2012-03-26 12:38:26 -0700308 dump_file("MEMORY INFO", "/proc/meminfo");
309 run_command("CPU INFO", 10, "top", "-n", "1", "-d", "1", "-m", "30", "-t", NULL);
Nick Kralevich2b1f88b2015-10-07 16:38:42 -0700310 run_command("PROCRANK", 20, SU_PATH, "root", "procrank", NULL);
Colin Crossf45fa6b2012-03-26 12:38:26 -0700311 dump_file("VIRTUAL MEMORY STATS", "/proc/vmstat");
312 dump_file("VMALLOC INFO", "/proc/vmallocinfo");
313 dump_file("SLAB INFO", "/proc/slabinfo");
314 dump_file("ZONEINFO", "/proc/zoneinfo");
315 dump_file("PAGETYPEINFO", "/proc/pagetypeinfo");
316 dump_file("BUDDYINFO", "/proc/buddyinfo");
Colin Cross2281af92012-10-28 22:41:06 -0700317 dump_file("FRAGMENTATION INFO", "/d/extfrag/unusable_index");
Colin Crossf45fa6b2012-03-26 12:38:26 -0700318
Colin Crossf45fa6b2012-03-26 12:38:26 -0700319 dump_file("KERNEL WAKELOCKS", "/proc/wakelocks");
Todd Poynor29e27a82012-05-22 17:54:59 -0700320 dump_file("KERNEL WAKE SOURCES", "/d/wakeup_sources");
Colin Crossf45fa6b2012-03-26 12:38:26 -0700321 dump_file("KERNEL CPUFREQ", "/sys/devices/system/cpu/cpu0/cpufreq/stats/time_in_state");
Mathias Agopian85aea742012-08-08 15:32:02 -0700322 dump_file("KERNEL SYNC", "/d/sync");
Colin Crossf45fa6b2012-03-26 12:38:26 -0700323
Elliott Hughesa3533a32015-10-30 16:17:49 -0700324 run_command("PROCESSES AND THREADS", 10, "ps", "-Z", "-t", "-p", "-P", NULL);
Colin Crossf45fa6b2012-03-26 12:38:26 -0700325 run_command("LIBRANK", 10, "librank", NULL);
326
327 do_dmesg();
328
329 run_command("LIST OF OPEN FILES", 10, SU_PATH, "root", "lsof", NULL);
Jeff Brown1dc94e32014-09-11 14:15:27 -0700330 for_each_pid(do_showmap, "SMAPS OF ALL PROCESSES");
331 for_each_tid(show_wchan, "BLOCKED PROCESS WAIT-CHANNELS");
Colin Crossf45fa6b2012-03-26 12:38:26 -0700332
Felipe Leme6e01fa62015-11-11 19:35:14 -0800333 if (!screenshot_path.empty()) {
Jeff Sharkey5a930032013-03-19 15:05:19 -0700334 ALOGI("taking screenshot\n");
Felipe Leme6e01fa62015-11-11 19:35:14 -0800335 const char *args[] = { "/system/bin/screencap", "-p", screenshot_path.c_str(), NULL };
336 run_command_always(NULL, 10, args);
337 ALOGI("wrote screenshot: %s\n", screenshot_path.c_str());
Jeff Sharkey5a930032013-03-19 15:05:19 -0700338 }
339
Colin Crossf45fa6b2012-03-26 12:38:26 -0700340 // dump_file("EVENT LOG TAGS", "/etc/event-log-tags");
Mark Salyzyn8f37aa52015-06-12 12:28:24 -0700341 // calculate timeout
342 timeout = logcat_timeout("main") + logcat_timeout("system") + logcat_timeout("crash");
343 if (timeout < 20000) {
344 timeout = 20000;
345 }
Mark Salyzyn78316382015-10-09 14:02:07 -0700346 run_command("SYSTEM LOG", timeout / 1000, "logcat", "-v", "threadtime",
347 "-v", "printable",
348 "-d",
349 "*:v", NULL);
Mark Salyzyn8f37aa52015-06-12 12:28:24 -0700350 timeout = logcat_timeout("events");
351 if (timeout < 20000) {
352 timeout = 20000;
353 }
Mark Salyzyn78316382015-10-09 14:02:07 -0700354 run_command("EVENT LOG", timeout / 1000, "logcat", "-b", "events",
355 "-v", "threadtime",
356 "-v", "printable",
357 "-d",
358 "*:v", NULL);
Mark Salyzyn8f37aa52015-06-12 12:28:24 -0700359 timeout = logcat_timeout("radio");
360 if (timeout < 20000) {
361 timeout = 20000;
362 }
Mark Salyzyn78316382015-10-09 14:02:07 -0700363 run_command("RADIO LOG", timeout / 1000, "logcat", "-b", "radio",
364 "-v", "threadtime",
365 "-v", "printable",
366 "-d",
367 "*:v", NULL);
Colin Crossf45fa6b2012-03-26 12:38:26 -0700368
Mark Salyzynecc07632015-07-30 14:57:09 -0700369 run_command("LOG STATISTICS", 10, "logcat", "-b", "all", "-S", NULL);
370
Jason Parks31baf8d2015-10-12 15:27:10 +0000371 run_command("RAFT LOGS", 300, SU_PATH, "root", "logcompressor", "-r", RAFT_DIR, NULL);
Sharvil Nanavati8d4cb7f2015-07-24 02:01:13 -0700372
Colin Crossf45fa6b2012-03-26 12:38:26 -0700373 /* show the traces we collected in main(), if that was done */
374 if (dump_traces_path != NULL) {
375 dump_file("VM TRACES JUST NOW", dump_traces_path);
376 }
377
378 /* only show ANR traces if they're less than 15 minutes old */
379 struct stat st;
380 char anr_traces_path[PATH_MAX];
381 property_get("dalvik.vm.stack-trace-file", anr_traces_path, "");
382 if (!anr_traces_path[0]) {
383 printf("*** NO VM TRACES FILE DEFINED (dalvik.vm.stack-trace-file)\n\n");
Colin Crossf45fa6b2012-03-26 12:38:26 -0700384 } else {
Christopher Ferris54bcc5f2015-02-10 12:15:01 -0800385 int fd = TEMP_FAILURE_RETRY(open(anr_traces_path,
386 O_RDONLY | O_CLOEXEC | O_NOFOLLOW | O_NONBLOCK));
Christopher Ferris7dc7f322014-07-22 16:08:19 -0700387 if (fd < 0) {
388 printf("*** NO ANR VM TRACES FILE (%s): %s\n\n", anr_traces_path, strerror(errno));
389 } else {
390 dump_file_from_fd("VM TRACES AT LAST ANR", anr_traces_path, fd);
391 }
Colin Crossf45fa6b2012-03-26 12:38:26 -0700392 }
393
394 /* slow traces for slow operations */
395 if (anr_traces_path[0] != 0) {
396 int tail = strlen(anr_traces_path)-1;
397 while (tail > 0 && anr_traces_path[tail] != '/') {
398 tail--;
399 }
400 int i = 0;
401 while (1) {
402 sprintf(anr_traces_path+tail+1, "slow%02d.txt", i);
403 if (stat(anr_traces_path, &st)) {
404 // No traces file at this index, done with the files.
405 break;
406 }
407 dump_file("VM TRACES WHEN SLOW", anr_traces_path);
408 i++;
409 }
410 }
411
Christopher Ferris7dc7f322014-07-22 16:08:19 -0700412 int dumped = 0;
413 for (size_t i = 0; i < NUM_TOMBSTONES; i++) {
414 if (tombstone_data[i].fd != -1) {
415 dumped = 1;
416 dump_file_from_fd("TOMBSTONE", tombstone_data[i].name, tombstone_data[i].fd);
417 tombstone_data[i].fd = -1;
418 }
419 }
420 if (!dumped) {
421 printf("*** NO TOMBSTONES to dump in %s\n\n", TOMBSTONE_DIR);
422 }
423
Colin Crossf45fa6b2012-03-26 12:38:26 -0700424 dump_file("NETWORK DEV INFO", "/proc/net/dev");
425 dump_file("QTAGUID NETWORK INTERFACES INFO", "/proc/net/xt_qtaguid/iface_stat_all");
JP Abgrall012c2ea2012-05-16 20:49:29 -0700426 dump_file("QTAGUID NETWORK INTERFACES INFO (xt)", "/proc/net/xt_qtaguid/iface_stat_fmt");
Colin Crossf45fa6b2012-03-26 12:38:26 -0700427 dump_file("QTAGUID CTRL INFO", "/proc/net/xt_qtaguid/ctrl");
428 dump_file("QTAGUID STATS INFO", "/proc/net/xt_qtaguid/stats");
429
Todd Poynor2a83daa2013-11-22 15:44:22 -0800430 if (!stat(PSTORE_LAST_KMSG, &st)) {
431 /* Also TODO: Make console-ramoops CAP_SYSLOG protected. */
432 dump_file("LAST KMSG", PSTORE_LAST_KMSG);
433 } else {
434 /* TODO: Make last_kmsg CAP_SYSLOG protected. b/5555691 */
435 dump_file("LAST KMSG", "/proc/last_kmsg");
436 }
437
Mark Salyzyn2262c162014-12-16 09:09:26 -0800438 /* kernels must set CONFIG_PSTORE_PMSG, slice up pstore with device tree */
Mark Salyzyn78316382015-10-09 14:02:07 -0700439 run_command("LAST LOGCAT", 10, "logcat", "-L",
440 "-b", "all",
441 "-v", "threadtime",
442 "-v", "printable",
443 "-d",
444 "*:v", NULL);
Mark Salyzyn2262c162014-12-16 09:09:26 -0800445
Colin Crossf45fa6b2012-03-26 12:38:26 -0700446 /* The following have a tendency to get wedged when wifi drivers/fw goes belly-up. */
Elliott Hughesa59828a2015-01-27 20:48:52 -0800447
448 run_command("NETWORK INTERFACES", 10, "ip", "link", NULL);
Lorenzo Colittid4c3d382014-07-30 14:38:20 +0900449
450 run_command("IPv4 ADDRESSES", 10, "ip", "-4", "addr", "show", NULL);
451 run_command("IPv6 ADDRESSES", 10, "ip", "-6", "addr", "show", NULL);
452
Colin Crossf45fa6b2012-03-26 12:38:26 -0700453 run_command("IP RULES", 10, "ip", "rule", "show", NULL);
454 run_command("IP RULES v6", 10, "ip", "-6", "rule", "show", NULL);
Sreeram Ramachandran2b3bba32014-07-08 15:40:55 -0700455
456 dump_route_tables();
457
Lorenzo Colittid4c3d382014-07-30 14:38:20 +0900458 run_command("ARP CACHE", 10, "ip", "-4", "neigh", "show", NULL);
459 run_command("IPv6 ND CACHE", 10, "ip", "-6", "neigh", "show", NULL);
460
Colin Crossf45fa6b2012-03-26 12:38:26 -0700461 run_command("IPTABLES", 10, SU_PATH, "root", "iptables", "-L", "-nvx", NULL);
462 run_command("IP6TABLES", 10, SU_PATH, "root", "ip6tables", "-L", "-nvx", NULL);
JP Abgrall012c2ea2012-05-16 20:49:29 -0700463 run_command("IPTABLE NAT", 10, SU_PATH, "root", "iptables", "-t", "nat", "-L", "-nvx", NULL);
464 /* no ip6 nat */
465 run_command("IPTABLE RAW", 10, SU_PATH, "root", "iptables", "-t", "raw", "-L", "-nvx", NULL);
466 run_command("IP6TABLE RAW", 10, SU_PATH, "root", "ip6tables", "-t", "raw", "-L", "-nvx", NULL);
Colin Crossf45fa6b2012-03-26 12:38:26 -0700467
468 run_command("WIFI NETWORKS", 20,
Dmitry Shmidt1d6b97c2013-08-21 10:58:29 -0700469 SU_PATH, "root", "wpa_cli", "IFNAME=wlan0", "list_networks", NULL);
Colin Crossf45fa6b2012-03-26 12:38:26 -0700470
Dmitry Shmidtc11f56e2012-11-07 10:42:05 -0800471#ifdef FWDUMP_bcmdhd
Lorenzo Colitti6afc38c2015-09-09 22:59:25 +0900472 run_command("ND OFFLOAD TABLE", 5,
473 SU_PATH, "root", "wlutil", "nd_hostip", NULL);
474
475 run_command("DUMP WIFI INTERNAL COUNTERS (1)", 20,
Dmitry Shmidtc11f56e2012-11-07 10:42:05 -0800476 SU_PATH, "root", "wlutil", "counters", NULL);
Lorenzo Colitti6afc38c2015-09-09 22:59:25 +0900477
478 run_command("ND OFFLOAD STATUS (1)", 5,
479 SU_PATH, "root", "wlutil", "nd_status", NULL);
480
Dmitry Shmidtc11f56e2012-11-07 10:42:05 -0800481#endif
Dmitry Shmidt0b2c9262012-11-07 11:09:46 -0800482 dump_file("INTERRUPTS (1)", "/proc/interrupts");
483
Lorenzo Colitti6afc38c2015-09-09 22:59:25 +0900484 run_command("NETWORK DIAGNOSTICS", 10, "dumpsys", "connectivity", "--diag", NULL);
485
Dmitry Shmidtc11f56e2012-11-07 10:42:05 -0800486#ifdef FWDUMP_bcmdhd
Colin Crossf45fa6b2012-03-26 12:38:26 -0700487 run_command("DUMP WIFI STATUS", 20,
488 SU_PATH, "root", "dhdutil", "-i", "wlan0", "dump", NULL);
Lorenzo Colitti6afc38c2015-09-09 22:59:25 +0900489
490 run_command("DUMP WIFI INTERNAL COUNTERS (2)", 20,
Colin Crossf45fa6b2012-03-26 12:38:26 -0700491 SU_PATH, "root", "wlutil", "counters", NULL);
Lorenzo Colitti6afc38c2015-09-09 22:59:25 +0900492
493 run_command("ND OFFLOAD STATUS (2)", 5,
494 SU_PATH, "root", "wlutil", "nd_status", NULL);
Colin Crossf45fa6b2012-03-26 12:38:26 -0700495#endif
Dmitry Shmidt0b2c9262012-11-07 11:09:46 -0800496 dump_file("INTERRUPTS (2)", "/proc/interrupts");
Colin Crossf45fa6b2012-03-26 12:38:26 -0700497
498 print_properties();
499
500 run_command("VOLD DUMP", 10, "vdc", "dump", NULL);
501 run_command("SECURE CONTAINERS", 10, "vdc", "asec", "list", NULL);
502
Ken Sumrall8f75fa72013-02-08 17:35:58 -0800503 run_command("FILESYSTEMS & FREE SPACE", 10, "df", NULL);
Colin Crossf45fa6b2012-03-26 12:38:26 -0700504
Colin Crossf45fa6b2012-03-26 12:38:26 -0700505 run_command("LAST RADIO LOG", 10, "parse_radio_log", "/proc/last_radio_log", NULL);
506
507 printf("------ BACKLIGHTS ------\n");
508 printf("LCD brightness=");
509 dump_file(NULL, "/sys/class/leds/lcd-backlight/brightness");
510 printf("Button brightness=");
511 dump_file(NULL, "/sys/class/leds/button-backlight/brightness");
512 printf("Keyboard brightness=");
513 dump_file(NULL, "/sys/class/leds/keyboard-backlight/brightness");
514 printf("ALS mode=");
515 dump_file(NULL, "/sys/class/leds/lcd-backlight/als");
516 printf("LCD driver registers:\n");
517 dump_file(NULL, "/sys/class/leds/lcd-backlight/registers");
518 printf("\n");
519
520 /* Binder state is expensive to look at as it uses a lot of memory. */
521 dump_file("BINDER FAILED TRANSACTION LOG", "/sys/kernel/debug/binder/failed_transaction_log");
522 dump_file("BINDER TRANSACTION LOG", "/sys/kernel/debug/binder/transaction_log");
523 dump_file("BINDER TRANSACTIONS", "/sys/kernel/debug/binder/transactions");
524 dump_file("BINDER STATS", "/sys/kernel/debug/binder/stats");
525 dump_file("BINDER STATE", "/sys/kernel/debug/binder/state");
526
Colin Crossf45fa6b2012-03-26 12:38:26 -0700527 printf("========================================================\n");
528 printf("== Board\n");
529 printf("========================================================\n");
530
531 dumpstate_board();
532 printf("\n");
Colin Crossf45fa6b2012-03-26 12:38:26 -0700533
534 /* Migrate the ril_dumpstate to a dumpstate_board()? */
535 char ril_dumpstate_timeout[PROPERTY_VALUE_MAX] = {0};
536 property_get("ril.dumpstate.timeout", ril_dumpstate_timeout, "30");
537 if (strnlen(ril_dumpstate_timeout, PROPERTY_VALUE_MAX - 1) > 0) {
538 if (0 == strncmp(build_type, "user", PROPERTY_VALUE_MAX - 1)) {
539 // su does not exist on user builds, so try running without it.
540 // This way any implementations of vril-dump that do not require
541 // root can run on user builds.
542 run_command("DUMP VENDOR RIL LOGS", atoi(ril_dumpstate_timeout),
543 "vril-dump", NULL);
544 } else {
545 run_command("DUMP VENDOR RIL LOGS", atoi(ril_dumpstate_timeout),
546 SU_PATH, "root", "vril-dump", NULL);
547 }
548 }
549
550 printf("========================================================\n");
551 printf("== Android Framework Services\n");
552 printf("========================================================\n");
553
554 /* the full dumpsys is starting to take a long time, so we need
555 to increase its timeout. we really need to do the timeouts in
556 dumpsys itself... */
557 run_command("DUMPSYS", 60, "dumpsys", NULL);
558
559 printf("========================================================\n");
Dianne Hackborn02bea972013-06-26 18:59:09 -0700560 printf("== Checkins\n");
561 printf("========================================================\n");
562
Dianne Hackborn59b15162013-09-04 18:04:14 -0700563 run_command("CHECKIN BATTERYSTATS", 30, "dumpsys", "batterystats", "-c", NULL);
Dianne Hackborn3e5fa732013-07-03 16:51:15 -0700564 run_command("CHECKIN MEMINFO", 30, "dumpsys", "meminfo", "--checkin", NULL);
Dianne Hackborn02bea972013-06-26 18:59:09 -0700565 run_command("CHECKIN NETSTATS", 30, "dumpsys", "netstats", "--checkin", NULL);
Dianne Hackborn5cd46aa2013-07-09 15:01:40 -0700566 run_command("CHECKIN PROCSTATS", 30, "dumpsys", "procstats", "-c", NULL);
Dianne Hackborn1bd50682013-07-11 11:45:18 -0700567 run_command("CHECKIN USAGESTATS", 30, "dumpsys", "usagestats", "-c", NULL);
Ashish Sharma8b3e1332015-04-28 13:32:54 -0700568 run_command("CHECKIN PACKAGE", 30, "dumpsys", "package", "--checkin", NULL);
Dianne Hackborn02bea972013-06-26 18:59:09 -0700569
570 printf("========================================================\n");
Colin Crossf45fa6b2012-03-26 12:38:26 -0700571 printf("== Running Application Activities\n");
572 printf("========================================================\n");
573
574 run_command("APP ACTIVITIES", 30, "dumpsys", "activity", "all", NULL);
575
576 printf("========================================================\n");
577 printf("== Running Application Services\n");
578 printf("========================================================\n");
579
580 run_command("APP SERVICES", 30, "dumpsys", "activity", "service", "all", NULL);
581
582 printf("========================================================\n");
583 printf("== Running Application Providers\n");
584 printf("========================================================\n");
585
586 run_command("APP SERVICES", 30, "dumpsys", "activity", "provider", "all", NULL);
587
588
589 printf("========================================================\n");
590 printf("== dumpstate: done\n");
591 printf("========================================================\n");
592}
593
594static void usage() {
John Michelau1f794c42012-09-17 11:20:19 -0500595 fprintf(stderr, "usage: dumpstate [-b soundfile] [-e soundfile] [-o file [-d] [-p] [-z]] [-s] [-q]\n"
Colin Crossf45fa6b2012-03-26 12:38:26 -0700596 " -o: write to file (instead of stdout)\n"
597 " -d: append date to filename (requires -o)\n"
Felipe Leme6e01fa62015-11-11 19:35:14 -0800598 " -z: generates zipped file (requires -o)\n"
Colin Crossf45fa6b2012-03-26 12:38:26 -0700599 " -p: capture screenshot to filename.png (requires -o)\n"
600 " -s: write output to control socket (for init)\n"
601 " -b: play sound file instead of vibrate, at beginning of job\n"
602 " -e: play sound file instead of vibrate, at end of job\n"
John Michelau1f794c42012-09-17 11:20:19 -0500603 " -q: disable vibrate\n"
Jeff Sharkey27f9e6d2013-03-13 15:45:50 -0700604 " -B: send broadcast when finished (requires -o and -p)\n"
Todd Poynor2a83daa2013-11-22 15:44:22 -0800605 );
Colin Crossf45fa6b2012-03-26 12:38:26 -0700606}
607
John Michelau885f8882013-05-06 16:42:02 -0500608static void sigpipe_handler(int n) {
Andres Morales2e671bb2014-08-21 12:38:22 -0700609 // don't complain to stderr or stdout
610 _exit(EXIT_FAILURE);
John Michelau885f8882013-05-06 16:42:02 -0500611}
612
Jeff Brown1dc94e32014-09-11 14:15:27 -0700613static void vibrate(FILE* vibrator, int ms) {
614 fprintf(vibrator, "%d\n", ms);
615 fflush(vibrator);
616}
617
Felipe Leme6e01fa62015-11-11 19:35:14 -0800618/* generates a zipfile on 'path' with an entry with the contents of 'tmp_path'
619 and removes the temporary file.
620 */
621static bool generate_zip_file(std::string tmp_path, std::string path,
622 std::string entry_name, time_t entry_time) {
623 std::unique_ptr<FILE, int(*)(FILE*)> file(fopen(path.c_str(), "wb"), fclose);
624 if (!file) {
625 ALOGE("fopen(%s, 'wb'): %s\n", path.c_str(), strerror(errno));
626 return false;
627 }
628
629 ZipWriter writer(file.get());
630 int32_t err = writer.StartEntryWithTime(entry_name.c_str(), ZipWriter::kCompress, entry_time);
631 if (err) {
632 ALOGE("writer.StartEntryWithTime(%s): %s\n", entry_name.c_str(), ZipWriter::ErrorCodeString(err));
633 return false;
634 }
635
636 ScopedFd fd(TEMP_FAILURE_RETRY(open(tmp_path.c_str(), O_RDONLY | O_NONBLOCK | O_CLOEXEC)));
637 if (fd.get() == -1) {
638 ALOGE("open(%s): %s\n", tmp_path.c_str(), strerror(errno));
639 return false;
640 }
641
642 while (1) {
643 std::vector<uint8_t> buffer(65536);
644 ssize_t bytes_read = TEMP_FAILURE_RETRY(read(fd.get(), buffer.data(), sizeof(buffer)));
645 if (bytes_read == 0) {
646 break;
647 } else if (bytes_read == -1) {
648 ALOGE("read(%s): %s\n", tmp_path.c_str(), strerror(errno));
649 return false;
650 }
651 err = writer.WriteBytes(buffer.data(), bytes_read);
652 if (err) {
653 ALOGE("writer.WriteBytes(): %s\n", ZipWriter::ErrorCodeString(err));
654 return false;
655 }
656 }
657
658 err = writer.FinishEntry();
659 if (err) {
660 ALOGE("writer.FinishEntry(): %s\n", ZipWriter::ErrorCodeString(err));
661 return false;
662 }
663
664 err = writer.Finish();
665 if (err) {
666 ALOGE("writer.Finish(): %s\n", ZipWriter::ErrorCodeString(err));
667 return false;
668 }
669
670 if (remove(tmp_path.c_str())) {
671 ALOGE("remove(%s): %s\n", tmp_path.c_str(), strerror(errno));
672 return false;
673 }
674
675 return true;
676}
677
678
Colin Crossf45fa6b2012-03-26 12:38:26 -0700679int main(int argc, char *argv[]) {
John Michelau885f8882013-05-06 16:42:02 -0500680 struct sigaction sigact;
Colin Crossf45fa6b2012-03-26 12:38:26 -0700681 int do_add_date = 0;
Felipe Leme6e01fa62015-11-11 19:35:14 -0800682 int do_zip_file = 0;
John Michelau1f794c42012-09-17 11:20:19 -0500683 int do_vibrate = 1;
Colin Crossf45fa6b2012-03-26 12:38:26 -0700684 char* use_outfile = 0;
Colin Crossf45fa6b2012-03-26 12:38:26 -0700685 int use_socket = 0;
686 int do_fb = 0;
Jeff Sharkey27f9e6d2013-03-13 15:45:50 -0700687 int do_broadcast = 0;
Colin Crossf45fa6b2012-03-26 12:38:26 -0700688
Nick Kralevich1e339872012-04-25 13:38:45 -0700689 if (getuid() != 0) {
690 // Old versions of the adb client would call the
691 // dumpstate command directly. Newer clients
692 // call /system/bin/bugreport instead. If we detect
693 // we're being called incorrectly, then exec the
694 // correct program.
695 return execl("/system/bin/bugreport", "/system/bin/bugreport", NULL);
696 }
Jeff Brown1dc94e32014-09-11 14:15:27 -0700697
Colin Crossf45fa6b2012-03-26 12:38:26 -0700698 ALOGI("begin\n");
699
Jeff Brown1dc94e32014-09-11 14:15:27 -0700700 /* clear SIGPIPE handler */
John Michelau885f8882013-05-06 16:42:02 -0500701 memset(&sigact, 0, sizeof(sigact));
702 sigact.sa_handler = sigpipe_handler;
703 sigaction(SIGPIPE, &sigact, NULL);
JP Abgrall3e03d3f2012-05-11 14:14:09 -0700704
Colin Crossf45fa6b2012-03-26 12:38:26 -0700705 /* set as high priority, and protect from OOM killer */
706 setpriority(PRIO_PROCESS, 0, -20);
Nick Kralevichcd67e9f2015-03-19 11:30:59 -0700707 FILE *oom_adj = fopen("/proc/self/oom_adj", "we");
Colin Crossf45fa6b2012-03-26 12:38:26 -0700708 if (oom_adj) {
709 fputs("-17", oom_adj);
710 fclose(oom_adj);
711 }
712
Jeff Brown1dc94e32014-09-11 14:15:27 -0700713 /* parse arguments */
Colin Crossf45fa6b2012-03-26 12:38:26 -0700714 int c;
Jeff Brown1dc94e32014-09-11 14:15:27 -0700715 while ((c = getopt(argc, argv, "dho:svqzpB")) != -1) {
Colin Crossf45fa6b2012-03-26 12:38:26 -0700716 switch (c) {
Colin Crossf45fa6b2012-03-26 12:38:26 -0700717 case 'd': do_add_date = 1; break;
Felipe Leme6e01fa62015-11-11 19:35:14 -0800718 case 'z': do_zip_file = 1; break;
Colin Crossf45fa6b2012-03-26 12:38:26 -0700719 case 'o': use_outfile = optarg; break;
720 case 's': use_socket = 1; break;
721 case 'v': break; // compatibility no-op
John Michelau1f794c42012-09-17 11:20:19 -0500722 case 'q': do_vibrate = 0; break;
Colin Crossf45fa6b2012-03-26 12:38:26 -0700723 case 'p': do_fb = 1; break;
Jeff Sharkey27f9e6d2013-03-13 15:45:50 -0700724 case 'B': do_broadcast = 1; break;
Colin Crossf45fa6b2012-03-26 12:38:26 -0700725 case '?': printf("\n");
726 case 'h':
727 usage();
728 exit(1);
729 }
730 }
731
Felipe Leme6e01fa62015-11-11 19:35:14 -0800732 if ((do_zip_file || do_add_date) && !use_outfile) {
733 usage();
734 exit(1);
735 }
736
737
Christopher Ferrised9354f2014-10-01 17:35:01 -0700738 // If we are going to use a socket, do it as early as possible
739 // to avoid timeouts from bugreport.
740 if (use_socket) {
741 redirect_to_socket(stdout, "dumpstate");
742 }
743
Jeff Brown1dc94e32014-09-11 14:15:27 -0700744 /* open the vibrator before dropping root */
Felipe Leme6e01fa62015-11-11 19:35:14 -0800745 std::unique_ptr<FILE, int(*)(FILE*)> vibrator(NULL, fclose);
John Michelau1f794c42012-09-17 11:20:19 -0500746 if (do_vibrate) {
Felipe Leme6e01fa62015-11-11 19:35:14 -0800747 vibrator.reset(fopen("/sys/class/timed_output/vibrator/enable", "we"));
Jeff Brown1dc94e32014-09-11 14:15:27 -0700748 if (vibrator) {
Felipe Leme6e01fa62015-11-11 19:35:14 -0800749 vibrate(vibrator.get(), 150);
Jeff Brown1dc94e32014-09-11 14:15:27 -0700750 }
John Michelau1f794c42012-09-17 11:20:19 -0500751 }
Colin Crossf45fa6b2012-03-26 12:38:26 -0700752
753 /* read /proc/cmdline before dropping root */
Nick Kralevichcd67e9f2015-03-19 11:30:59 -0700754 FILE *cmdline = fopen("/proc/cmdline", "re");
Felipe Leme6e01fa62015-11-11 19:35:14 -0800755 if (cmdline) {
Colin Crossf45fa6b2012-03-26 12:38:26 -0700756 fgets(cmdline_buf, sizeof(cmdline_buf), cmdline);
757 fclose(cmdline);
758 }
759
Jeff Brown1dc94e32014-09-11 14:15:27 -0700760 /* collect stack traces from Dalvik and native processes (needs root) */
761 dump_traces_path = dump_traces();
762
763 /* Get the tombstone fds here while we are running as root. */
764 get_tombstone_fds(tombstone_data);
765
766 /* ensure we will keep capabilities when we drop root */
Nick Kralevich1e339872012-04-25 13:38:45 -0700767 if (prctl(PR_SET_KEEPCAPS, 1) < 0) {
768 ALOGE("prctl(PR_SET_KEEPCAPS) failed: %s\n", strerror(errno));
769 return -1;
770 }
Colin Crossf45fa6b2012-03-26 12:38:26 -0700771
Nick Kralevich1e339872012-04-25 13:38:45 -0700772 /* switch to non-root user and group */
773 gid_t groups[] = { AID_LOG, AID_SDCARD_R, AID_SDCARD_RW,
Nick Kralevichab46a492015-11-07 17:05:41 -0800774 AID_MOUNT, AID_INET, AID_NET_BW_STATS, AID_READPROC };
Nick Kralevich1e339872012-04-25 13:38:45 -0700775 if (setgroups(sizeof(groups)/sizeof(groups[0]), groups) != 0) {
776 ALOGE("Unable to setgroups, aborting: %s\n", strerror(errno));
777 return -1;
778 }
779 if (setgid(AID_SHELL) != 0) {
780 ALOGE("Unable to setgid, aborting: %s\n", strerror(errno));
781 return -1;
782 }
783 if (setuid(AID_SHELL) != 0) {
784 ALOGE("Unable to setuid, aborting: %s\n", strerror(errno));
785 return -1;
786 }
Colin Crossf45fa6b2012-03-26 12:38:26 -0700787
Nick Kralevich1e339872012-04-25 13:38:45 -0700788 struct __user_cap_header_struct capheader;
789 struct __user_cap_data_struct capdata[2];
790 memset(&capheader, 0, sizeof(capheader));
791 memset(&capdata, 0, sizeof(capdata));
792 capheader.version = _LINUX_CAPABILITY_VERSION_3;
793 capheader.pid = 0;
Colin Crossf45fa6b2012-03-26 12:38:26 -0700794
Nick Kralevich1e339872012-04-25 13:38:45 -0700795 capdata[CAP_TO_INDEX(CAP_SYSLOG)].permitted = CAP_TO_MASK(CAP_SYSLOG);
796 capdata[CAP_TO_INDEX(CAP_SYSLOG)].effective = CAP_TO_MASK(CAP_SYSLOG);
797 capdata[0].inheritable = 0;
798 capdata[1].inheritable = 0;
Colin Crossf45fa6b2012-03-26 12:38:26 -0700799
Nick Kralevich1e339872012-04-25 13:38:45 -0700800 if (capset(&capheader, &capdata[0]) < 0) {
801 ALOGE("capset failed: %s\n", strerror(errno));
802 return -1;
Colin Crossf45fa6b2012-03-26 12:38:26 -0700803 }
804
Jeff Brown1dc94e32014-09-11 14:15:27 -0700805 /* redirect output if needed */
Felipe Leme6e01fa62015-11-11 19:35:14 -0800806 std::string text_path, zip_path, tmp_path, entry_name;
807
808 /* pointer to the actual path, be it zip or text */
809 std::string path;
810
811 time_t now = time(NULL);
Colin Crossf45fa6b2012-03-26 12:38:26 -0700812
Christopher Ferrised9354f2014-10-01 17:35:01 -0700813 if (!use_socket && use_outfile) {
Felipe Leme6e01fa62015-11-11 19:35:14 -0800814 text_path = use_outfile;
Colin Crossf45fa6b2012-03-26 12:38:26 -0700815 if (do_add_date) {
816 char date[80];
Colin Crossf45fa6b2012-03-26 12:38:26 -0700817 strftime(date, sizeof(date), "-%Y-%m-%d-%H-%M-%S", localtime(&now));
Felipe Leme6e01fa62015-11-11 19:35:14 -0800818 text_path += date;
Colin Crossf45fa6b2012-03-26 12:38:26 -0700819 }
820 if (do_fb) {
Felipe Leme6e01fa62015-11-11 19:35:14 -0800821 screenshot_path = text_path + ".png";
Colin Crossf45fa6b2012-03-26 12:38:26 -0700822 }
Felipe Leme6e01fa62015-11-11 19:35:14 -0800823 zip_path = text_path + ".zip";
824 text_path += ".txt";
825 tmp_path = text_path + ".tmp";
826 entry_name = basename(text_path.c_str());
827
828 ALOGD("Temporary path: %s\ntext path: %s\nzip path: %s\nzip entry: %s",
829 tmp_path.c_str(), text_path.c_str(), zip_path.c_str(), entry_name.c_str());
830 /* TODO: rather than generating a text file now and zipping it later,
831 it would be more efficient to redirect stdout to the zip entry
832 directly, but the libziparchive doesn't support that option yet. */
833 redirect_to_file(stdout, const_cast<char*>(tmp_path.c_str()));
Colin Crossf45fa6b2012-03-26 12:38:26 -0700834 }
835
Colin Crossf45fa6b2012-03-26 12:38:26 -0700836 dumpstate();
837
Jeff Brown1dc94e32014-09-11 14:15:27 -0700838 /* done */
839 if (vibrator) {
840 for (int i = 0; i < 3; i++) {
Felipe Leme6e01fa62015-11-11 19:35:14 -0800841 vibrate(vibrator.get(), 75);
Colin Crossf45fa6b2012-03-26 12:38:26 -0700842 usleep((75 + 50) * 1000);
843 }
Colin Crossf45fa6b2012-03-26 12:38:26 -0700844 }
845
Felipe Leme55b42a62015-11-10 17:39:08 -0800846 /* close output if needed */
847 if (!use_socket && use_outfile) {
Colin Crossf45fa6b2012-03-26 12:38:26 -0700848 fclose(stdout);
Colin Crossf45fa6b2012-03-26 12:38:26 -0700849 }
850
Felipe Leme6e01fa62015-11-11 19:35:14 -0800851 /* rename or zip the (now complete) .tmp file to its final location */
852 if (use_outfile) {
853 bool do_text_file = true;
854 if (do_zip_file) {
855 path = zip_path;
856 if (generate_zip_file(tmp_path, zip_path, entry_name, now)) {
857 ALOGE("Failed to generate zip file; sending text bugreport instead\n");
858 do_text_file = true;
859 } else {
860 do_text_file = false;
861 }
862 }
863 if (do_text_file) {
864 path = text_path;
865 if (rename(tmp_path.c_str(), text_path.c_str())) {
866 ALOGE("rename(%s, %s): %s\n", tmp_path.c_str(), text_path.c_str(), strerror(errno));
867 path.clear();
868 }
869 }
Colin Crossf45fa6b2012-03-26 12:38:26 -0700870 }
871
Jeff Brown1dc94e32014-09-11 14:15:27 -0700872 /* tell activity manager we're done */
Jeff Sharkey27f9e6d2013-03-13 15:45:50 -0700873 if (do_broadcast && use_outfile && do_fb) {
Felipe Leme6e01fa62015-11-11 19:35:14 -0800874 if (!path.empty()) {
875 ALOGI("Final bugreport path: %s\n", path.c_str());
876 const char *args[] = { "/system/bin/am", "broadcast", "--user", "0",
877 "-a", "android.intent.action.BUGREPORT_FINISHED",
878 "--es", "android.intent.extra.BUGREPORT", path.c_str(),
879 "--es", "android.intent.extra.SCREENSHOT", screenshot_path.c_str(),
880 "--receiver-permission", "android.permission.DUMP", NULL };
881 run_command_always(NULL, 5, args);
882 } else {
883 ALOGE("Skipping broadcast because bugreport could not be generated\n");
884 }
Jeff Sharkey27f9e6d2013-03-13 15:45:50 -0700885 }
886
Colin Crossf45fa6b2012-03-26 12:38:26 -0700887 ALOGI("done\n");
888
889 return 0;
890}