blob: 6b8ca570b030728c851216eda7d1ae470a2994cb [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>
Mark Salyzyn8f37aa52015-06-12 12:28:24 -070021#include <stdbool.h>
Colin Crossf45fa6b2012-03-26 12:38:26 -070022#include <stdio.h>
23#include <stdlib.h>
24#include <string.h>
Christopher Ferris7dc7f322014-07-22 16:08:19 -070025#include <sys/capability.h>
26#include <sys/prctl.h>
Colin Crossf45fa6b2012-03-26 12:38:26 -070027#include <sys/resource.h>
28#include <sys/stat.h>
29#include <sys/time.h>
30#include <sys/wait.h>
31#include <unistd.h>
Colin Crossf45fa6b2012-03-26 12:38:26 -070032
33#include <cutils/properties.h>
34
35#include "private/android_filesystem_config.h"
36
37#define LOG_TAG "dumpstate"
Alex Ray656a6b92013-07-23 13:44:34 -070038#include <cutils/log.h>
Colin Crossf45fa6b2012-03-26 12:38:26 -070039
40#include "dumpstate.h"
41
42/* read before root is shed */
43static char cmdline_buf[16384] = "(unknown)";
44static const char *dump_traces_path = NULL;
45
46static char screenshot_path[PATH_MAX] = "";
47
Todd Poynor2a83daa2013-11-22 15:44:22 -080048#define PSTORE_LAST_KMSG "/sys/fs/pstore/console-ramoops"
49
Sharvil Nanavati8d4cb7f2015-07-24 02:01:13 -070050#define RAFT_DIR "/data/misc/raft/"
Christopher Ferris7dc7f322014-07-22 16:08:19 -070051#define TOMBSTONE_DIR "/data/tombstones"
52#define TOMBSTONE_FILE_PREFIX TOMBSTONE_DIR "/tombstone_"
53/* Can accomodate a tombstone number up to 9999. */
54#define TOMBSTONE_MAX_LEN (sizeof(TOMBSTONE_FILE_PREFIX) + 4)
55#define NUM_TOMBSTONES 10
56
57typedef struct {
58 char name[TOMBSTONE_MAX_LEN];
59 int fd;
60} tombstone_data_t;
61
62static tombstone_data_t tombstone_data[NUM_TOMBSTONES];
63
64/* Get the fds of any tombstone that was modified in the last half an hour. */
65static void get_tombstone_fds(tombstone_data_t data[NUM_TOMBSTONES]) {
66 time_t thirty_minutes_ago = time(NULL) - 60*30;
67 for (size_t i = 0; i < NUM_TOMBSTONES; i++) {
68 snprintf(data[i].name, sizeof(data[i].name), "%s%02zu", TOMBSTONE_FILE_PREFIX, i);
Christopher Ferris54bcc5f2015-02-10 12:15:01 -080069 int fd = TEMP_FAILURE_RETRY(open(data[i].name,
70 O_RDONLY | O_CLOEXEC | O_NOFOLLOW | O_NONBLOCK));
Christopher Ferris7dc7f322014-07-22 16:08:19 -070071 struct stat st;
72 if (fstat(fd, &st) == 0 && S_ISREG(st.st_mode) &&
73 (time_t) st.st_mtime >= thirty_minutes_ago) {
74 data[i].fd = fd;
75 } else {
76 close(fd);
77 data[i].fd = -1;
78 }
79 }
80}
81
Arve Hjønnevåg2db0f5f2014-10-15 18:08:37 -070082static void dump_dev_files(const char *title, const char *driverpath, const char *filename)
83{
84 DIR *d;
85 struct dirent *de;
86 char path[PATH_MAX];
87
88 d = opendir(driverpath);
89 if (d == NULL) {
90 return;
91 }
92
93 while ((de = readdir(d))) {
94 if (de->d_type != DT_LNK) {
95 continue;
96 }
97 snprintf(path, sizeof(path), "%s/%s/%s", driverpath, de->d_name, filename);
98 dump_file(title, path);
99 }
100
101 closedir(d);
102}
103
Mark Salyzyn326842f2015-04-30 09:49:41 -0700104static bool skip_not_stat(const char *path) {
105 static const char stat[] = "/stat";
106 size_t len = strlen(path);
107 if (path[len - 1] == '/') { /* Directory? */
108 return false;
109 }
110 return strcmp(path + len - sizeof(stat) + 1, stat); /* .../stat? */
111}
112
113static const char mmcblk0[] = "/sys/block/mmcblk0/";
Mark Salyzyn8f37aa52015-06-12 12:28:24 -0700114unsigned long worst_write_perf = 20000; /* in KB/s */
Mark Salyzyn326842f2015-04-30 09:49:41 -0700115
Mark Salyzyn01d6c392016-02-04 09:20:44 -0800116//
117// stat offsets
118// Name units description
119// ---- ----- -----------
120// read I/Os requests number of read I/Os processed
121#define __STAT_READ_IOS 0
122// read merges requests number of read I/Os merged with in-queue I/O
123#define __STAT_READ_MERGES 1
124// read sectors sectors number of sectors read
125#define __STAT_READ_SECTORS 2
126// read ticks milliseconds total wait time for read requests
127#define __STAT_READ_TICKS 3
128// write I/Os requests number of write I/Os processed
129#define __STAT_WRITE_IOS 4
130// write merges requests number of write I/Os merged with in-queue I/O
131#define __STAT_WRITE_MERGES 5
132// write sectors sectors number of sectors written
133#define __STAT_WRITE_SECTORS 6
134// write ticks milliseconds total wait time for write requests
135#define __STAT_WRITE_TICKS 7
136// in_flight requests number of I/Os currently in flight
137#define __STAT_IN_FLIGHT 8
138// io_ticks milliseconds total time this block device has been active
139#define __STAT_IO_TICKS 9
140// time_in_queue milliseconds total wait time for all requests
141#define __STAT_IN_QUEUE 10
142#define __STAT_NUMBER_FIELD 11
143//
144// read I/Os, write I/Os
145// =====================
146//
147// These values increment when an I/O request completes.
148//
149// read merges, write merges
150// =========================
151//
152// These values increment when an I/O request is merged with an
153// already-queued I/O request.
154//
155// read sectors, write sectors
156// ===========================
157//
158// These values count the number of sectors read from or written to this
159// block device. The "sectors" in question are the standard UNIX 512-byte
160// sectors, not any device- or filesystem-specific block size. The
161// counters are incremented when the I/O completes.
162#define SECTOR_SIZE 512
163//
164// read ticks, write ticks
165// =======================
166//
167// These values count the number of milliseconds that I/O requests have
168// waited on this block device. If there are multiple I/O requests waiting,
169// these values will increase at a rate greater than 1000/second; for
170// example, if 60 read requests wait for an average of 30 ms, the read_ticks
171// field will increase by 60*30 = 1800.
172//
173// in_flight
174// =========
175//
176// This value counts the number of I/O requests that have been issued to
177// the device driver but have not yet completed. It does not include I/O
178// requests that are in the queue but not yet issued to the device driver.
179//
180// io_ticks
181// ========
182//
183// This value counts the number of milliseconds during which the device has
184// had I/O requests queued.
185//
186// time_in_queue
187// =============
188//
189// This value counts the number of milliseconds that I/O requests have waited
190// on this block device. If there are multiple I/O requests waiting, this
191// value will increase as the product of the number of milliseconds times the
192// number of requests waiting (see "read ticks" above for an example).
193#define S_TO_MS 1000
194//
195
Mark Salyzyn326842f2015-04-30 09:49:41 -0700196static int dump_stat_from_fd(const char *title __unused, const char *path, int fd) {
Mark Salyzyn01d6c392016-02-04 09:20:44 -0800197 unsigned long long fields[__STAT_NUMBER_FIELD];
Mark Salyzyn326842f2015-04-30 09:49:41 -0700198 bool z;
199 char *cp, *buffer = NULL;
200 size_t i = 0;
201 FILE *fp = fdopen(fd, "rb");
202 getline(&buffer, &i, fp);
203 fclose(fp);
204 if (!buffer) {
205 return -errno;
206 }
207 i = strlen(buffer);
208 while ((i > 0) && (buffer[i - 1] == '\n')) {
209 buffer[--i] = '\0';
210 }
211 if (!*buffer) {
212 free(buffer);
213 return 0;
214 }
215 z = true;
216 for (cp = buffer, i = 0; i < (sizeof(fields) / sizeof(fields[0])); ++i) {
Mark Salyzyn01d6c392016-02-04 09:20:44 -0800217 fields[i] = strtoull(cp, &cp, 10);
Mark Salyzyn326842f2015-04-30 09:49:41 -0700218 if (fields[i] != 0) {
219 z = false;
220 }
221 }
222 if (z) { /* never accessed */
223 free(buffer);
224 return 0;
225 }
226
227 if (!strncmp(path, mmcblk0, sizeof(mmcblk0) - 1)) {
228 path += sizeof(mmcblk0) - 1;
229 }
230
231 printf("%s: %s\n", path, buffer);
232 free(buffer);
233
Mark Salyzyn01d6c392016-02-04 09:20:44 -0800234 if (fields[__STAT_IO_TICKS]) {
235 unsigned long read_perf = 0;
236 unsigned long read_ios = 0;
237 if (fields[__STAT_READ_TICKS]) {
238 unsigned long long divisor = fields[__STAT_READ_TICKS]
239 * fields[__STAT_IO_TICKS];
240 read_perf = ((unsigned long long)SECTOR_SIZE
241 * fields[__STAT_READ_SECTORS]
242 * fields[__STAT_IN_QUEUE] + (divisor >> 1))
243 / divisor;
244 read_ios = ((unsigned long long)S_TO_MS * fields[__STAT_READ_IOS]
245 * fields[__STAT_IN_QUEUE] + (divisor >> 1))
246 / divisor;
247 }
248
249 unsigned long write_perf = 0;
250 unsigned long write_ios = 0;
251 if (fields[__STAT_WRITE_TICKS]) {
252 unsigned long long divisor = fields[__STAT_WRITE_TICKS]
253 * fields[__STAT_IO_TICKS];
254 write_perf = ((unsigned long long)SECTOR_SIZE
255 * fields[__STAT_WRITE_SECTORS]
256 * fields[__STAT_IN_QUEUE] + (divisor >> 1))
257 / divisor;
258 write_ios = ((unsigned long long)S_TO_MS * fields[__STAT_WRITE_IOS]
259 * fields[__STAT_IN_QUEUE] + (divisor >> 1))
260 / divisor;
261 }
262
263 unsigned queue = (fields[__STAT_IN_QUEUE]
264 + (fields[__STAT_IO_TICKS] >> 1))
265 / fields[__STAT_IO_TICKS];
266
267 if (!write_perf && !write_ios) {
268 printf("%s: perf(ios) rd: %luKB/s(%lu/s) q: %u\n",
269 path, read_perf, read_ios, queue);
270 } else {
271 printf("%s: perf(ios) rd: %luKB/s(%lu/s) wr: %luKB/s(%lu/s) q: %u\n",
272 path, read_perf, read_ios, write_perf, write_ios, queue);
273 }
274
275 /* bugreport timeout factor adjustment */
276 if ((write_perf > 1) && (write_perf < worst_write_perf)) {
277 worst_write_perf = write_perf;
278 }
Mark Salyzyn8f37aa52015-06-12 12:28:24 -0700279 }
Mark Salyzyn326842f2015-04-30 09:49:41 -0700280 return 0;
281}
282
Mark Salyzyn8f37aa52015-06-12 12:28:24 -0700283/* Copied policy from system/core/logd/LogBuffer.cpp */
284
285#define LOG_BUFFER_SIZE (256 * 1024)
286#define LOG_BUFFER_MIN_SIZE (64 * 1024UL)
287#define LOG_BUFFER_MAX_SIZE (256 * 1024 * 1024UL)
288
289static bool valid_size(unsigned long value) {
290 if ((value < LOG_BUFFER_MIN_SIZE) || (LOG_BUFFER_MAX_SIZE < value)) {
291 return false;
292 }
293
294 long pages = sysconf(_SC_PHYS_PAGES);
295 if (pages < 1) {
296 return true;
297 }
298
299 long pagesize = sysconf(_SC_PAGESIZE);
300 if (pagesize <= 1) {
301 pagesize = PAGE_SIZE;
302 }
303
304 // maximum memory impact a somewhat arbitrary ~3%
305 pages = (pages + 31) / 32;
306 unsigned long maximum = pages * pagesize;
307
308 if ((maximum < LOG_BUFFER_MIN_SIZE) || (LOG_BUFFER_MAX_SIZE < maximum)) {
309 return true;
310 }
311
312 return value <= maximum;
313}
314
315static unsigned long property_get_size(const char *key) {
316 unsigned long value;
317 char *cp, property[PROPERTY_VALUE_MAX];
318
319 property_get(key, property, "");
320 value = strtoul(property, &cp, 10);
321
322 switch(*cp) {
323 case 'm':
324 case 'M':
325 value *= 1024;
326 /* FALLTHRU */
327 case 'k':
328 case 'K':
329 value *= 1024;
330 /* FALLTHRU */
331 case '\0':
332 break;
333
334 default:
335 value = 0;
336 }
337
338 if (!valid_size(value)) {
339 value = 0;
340 }
341
342 return value;
343}
344
345/* timeout in ms */
Felipe Leme515eb0d2015-12-14 15:09:56 -0800346static unsigned long logcat_timeout(const char *name) {
Mark Salyzyn8f37aa52015-06-12 12:28:24 -0700347 static const char global_tuneable[] = "persist.logd.size"; // Settings App
348 static const char global_default[] = "ro.logd.size"; // BoardConfig.mk
349 char key[PROP_NAME_MAX];
350 unsigned long property_size, default_size;
351
352 default_size = property_get_size(global_tuneable);
353 if (!default_size) {
354 default_size = property_get_size(global_default);
355 }
356
357 snprintf(key, sizeof(key), "%s.%s", global_tuneable, name);
358 property_size = property_get_size(key);
359
360 if (!property_size) {
361 snprintf(key, sizeof(key), "%s.%s", global_default, name);
362 property_size = property_get_size(key);
363 }
364
365 if (!property_size) {
366 property_size = default_size;
367 }
368
369 if (!property_size) {
370 property_size = LOG_BUFFER_SIZE;
371 }
372
373 /* Engineering margin is ten-fold our guess */
374 return 10 * (property_size + worst_write_perf) / worst_write_perf;
375}
376
377/* End copy from system/core/logd/LogBuffer.cpp */
378
Colin Crossf45fa6b2012-03-26 12:38:26 -0700379/* dumps the current system state to stdout */
380static void dumpstate() {
Mark Salyzyn8f37aa52015-06-12 12:28:24 -0700381 unsigned long timeout;
Colin Crossf45fa6b2012-03-26 12:38:26 -0700382 time_t now = time(NULL);
383 char build[PROPERTY_VALUE_MAX], fingerprint[PROPERTY_VALUE_MAX];
384 char radio[PROPERTY_VALUE_MAX], bootloader[PROPERTY_VALUE_MAX];
385 char network[PROPERTY_VALUE_MAX], date[80];
386 char build_type[PROPERTY_VALUE_MAX];
387
388 property_get("ro.build.display.id", build, "(unknown)");
389 property_get("ro.build.fingerprint", fingerprint, "(unknown)");
390 property_get("ro.build.type", build_type, "(unknown)");
391 property_get("ro.baseband", radio, "(unknown)");
392 property_get("ro.bootloader", bootloader, "(unknown)");
393 property_get("gsm.operator.alpha", network, "(unknown)");
394 strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S", localtime(&now));
395
396 printf("========================================================\n");
397 printf("== dumpstate: %s\n", date);
398 printf("========================================================\n");
399
400 printf("\n");
401 printf("Build: %s\n", build);
402 printf("Build fingerprint: '%s'\n", fingerprint); /* format is important for other tools */
403 printf("Bootloader: %s\n", bootloader);
404 printf("Radio: %s\n", radio);
405 printf("Network: %s\n", network);
406
407 printf("Kernel: ");
408 dump_file(NULL, "/proc/version");
409 printf("Command line: %s\n", strtok(cmdline_buf, "\n"));
410 printf("\n");
411
Arve Hjønnevåg2db0f5f2014-10-15 18:08:37 -0700412 dump_dev_files("TRUSTY VERSION", "/sys/bus/platform/drivers/trusty", "trusty_version");
Colin Crossf45fa6b2012-03-26 12:38:26 -0700413 run_command("UPTIME", 10, "uptime", NULL);
Mark Salyzyn326842f2015-04-30 09:49:41 -0700414 dump_files("UPTIME MMC PERF", mmcblk0, skip_not_stat, dump_stat_from_fd);
Mark Salyzyn8c8130e2015-12-09 11:21:28 -0800415 dump_emmc_ecsd("/d/mmc0/mmc0:0001/ext_csd");
Colin Crossf45fa6b2012-03-26 12:38:26 -0700416 dump_file("MEMORY INFO", "/proc/meminfo");
Elliott Hughesb32c7e12015-11-13 11:32:48 -0800417 run_command("CPU INFO", 10, "top", "-n", "1", "-d", "1", "-m", "30", "-H", NULL);
Nick Kralevich2b1f88b2015-10-07 16:38:42 -0700418 run_command("PROCRANK", 20, SU_PATH, "root", "procrank", NULL);
Colin Crossf45fa6b2012-03-26 12:38:26 -0700419 dump_file("VIRTUAL MEMORY STATS", "/proc/vmstat");
420 dump_file("VMALLOC INFO", "/proc/vmallocinfo");
421 dump_file("SLAB INFO", "/proc/slabinfo");
422 dump_file("ZONEINFO", "/proc/zoneinfo");
423 dump_file("PAGETYPEINFO", "/proc/pagetypeinfo");
424 dump_file("BUDDYINFO", "/proc/buddyinfo");
Colin Cross2281af92012-10-28 22:41:06 -0700425 dump_file("FRAGMENTATION INFO", "/d/extfrag/unusable_index");
Colin Crossf45fa6b2012-03-26 12:38:26 -0700426
Colin Crossf45fa6b2012-03-26 12:38:26 -0700427 dump_file("KERNEL WAKELOCKS", "/proc/wakelocks");
Todd Poynor29e27a82012-05-22 17:54:59 -0700428 dump_file("KERNEL WAKE SOURCES", "/d/wakeup_sources");
Colin Crossf45fa6b2012-03-26 12:38:26 -0700429 dump_file("KERNEL CPUFREQ", "/sys/devices/system/cpu/cpu0/cpufreq/stats/time_in_state");
Mathias Agopian85aea742012-08-08 15:32:02 -0700430 dump_file("KERNEL SYNC", "/d/sync");
Colin Crossf45fa6b2012-03-26 12:38:26 -0700431
Elliott Hughes32caf1d2016-05-04 14:03:54 -0700432 run_command("PROCESSES AND THREADS", 10, "toybox", "ps", "-A", "-T", "-Z",
433 "-O", "pri,nice,rtprio,sched,pcy", NULL);
Colin Crossf45fa6b2012-03-26 12:38:26 -0700434 run_command("LIBRANK", 10, "librank", NULL);
435
436 do_dmesg();
437
438 run_command("LIST OF OPEN FILES", 10, SU_PATH, "root", "lsof", NULL);
Jeff Brown1dc94e32014-09-11 14:15:27 -0700439 for_each_pid(do_showmap, "SMAPS OF ALL PROCESSES");
440 for_each_tid(show_wchan, "BLOCKED PROCESS WAIT-CHANNELS");
Mark Salyzyn0751efa2016-02-05 15:33:17 -0800441 for_each_pid(show_showtime, "PROCESS TIMES (pid cmd user system iowait+percentage)");
Colin Crossf45fa6b2012-03-26 12:38:26 -0700442
Jeff Sharkey5a930032013-03-19 15:05:19 -0700443 if (screenshot_path[0]) {
444 ALOGI("taking screenshot\n");
445 run_command(NULL, 10, "/system/bin/screencap", "-p", screenshot_path, NULL);
446 ALOGI("wrote screenshot: %s\n", screenshot_path);
447 }
448
Colin Crossf45fa6b2012-03-26 12:38:26 -0700449 // dump_file("EVENT LOG TAGS", "/etc/event-log-tags");
Mark Salyzyn8f37aa52015-06-12 12:28:24 -0700450 // calculate timeout
451 timeout = logcat_timeout("main") + logcat_timeout("system") + logcat_timeout("crash");
452 if (timeout < 20000) {
453 timeout = 20000;
454 }
Mark Salyzyn78316382015-10-09 14:02:07 -0700455 run_command("SYSTEM LOG", timeout / 1000, "logcat", "-v", "threadtime",
456 "-v", "printable",
457 "-d",
458 "*:v", NULL);
Mark Salyzyn43afe5d2016-01-26 07:24:08 -0800459 timeout = logcat_timeout("events");
Mark Salyzyn8f37aa52015-06-12 12:28:24 -0700460 if (timeout < 20000) {
461 timeout = 20000;
462 }
Mark Salyzyn78316382015-10-09 14:02:07 -0700463 run_command("EVENT LOG", timeout / 1000, "logcat", "-b", "events",
464 "-v", "threadtime",
465 "-v", "printable",
466 "-d",
467 "*:v", NULL);
Mark Salyzyn8f37aa52015-06-12 12:28:24 -0700468 timeout = logcat_timeout("radio");
469 if (timeout < 20000) {
470 timeout = 20000;
471 }
Mark Salyzyn78316382015-10-09 14:02:07 -0700472 run_command("RADIO LOG", timeout / 1000, "logcat", "-b", "radio",
473 "-v", "threadtime",
474 "-v", "printable",
475 "-d",
476 "*:v", NULL);
Colin Crossf45fa6b2012-03-26 12:38:26 -0700477
Mark Salyzynecc07632015-07-30 14:57:09 -0700478 run_command("LOG STATISTICS", 10, "logcat", "-b", "all", "-S", NULL);
479
Sharvil Nanavati804339a2015-11-27 21:04:11 -0800480 run_command("RAFT LOGS", 600, SU_PATH, "root", "logcompressor", "-r", RAFT_DIR, NULL);
Sharvil Nanavati8d4cb7f2015-07-24 02:01:13 -0700481
Colin Crossf45fa6b2012-03-26 12:38:26 -0700482 /* show the traces we collected in main(), if that was done */
483 if (dump_traces_path != NULL) {
484 dump_file("VM TRACES JUST NOW", dump_traces_path);
485 }
486
487 /* only show ANR traces if they're less than 15 minutes old */
488 struct stat st;
489 char anr_traces_path[PATH_MAX];
490 property_get("dalvik.vm.stack-trace-file", anr_traces_path, "");
491 if (!anr_traces_path[0]) {
492 printf("*** NO VM TRACES FILE DEFINED (dalvik.vm.stack-trace-file)\n\n");
Colin Crossf45fa6b2012-03-26 12:38:26 -0700493 } else {
Christopher Ferris54bcc5f2015-02-10 12:15:01 -0800494 int fd = TEMP_FAILURE_RETRY(open(anr_traces_path,
495 O_RDONLY | O_CLOEXEC | O_NOFOLLOW | O_NONBLOCK));
Christopher Ferris7dc7f322014-07-22 16:08:19 -0700496 if (fd < 0) {
497 printf("*** NO ANR VM TRACES FILE (%s): %s\n\n", anr_traces_path, strerror(errno));
498 } else {
499 dump_file_from_fd("VM TRACES AT LAST ANR", anr_traces_path, fd);
500 }
Colin Crossf45fa6b2012-03-26 12:38:26 -0700501 }
502
503 /* slow traces for slow operations */
504 if (anr_traces_path[0] != 0) {
505 int tail = strlen(anr_traces_path)-1;
506 while (tail > 0 && anr_traces_path[tail] != '/') {
507 tail--;
508 }
509 int i = 0;
510 while (1) {
511 sprintf(anr_traces_path+tail+1, "slow%02d.txt", i);
512 if (stat(anr_traces_path, &st)) {
513 // No traces file at this index, done with the files.
514 break;
515 }
516 dump_file("VM TRACES WHEN SLOW", anr_traces_path);
517 i++;
518 }
519 }
520
Christopher Ferris7dc7f322014-07-22 16:08:19 -0700521 int dumped = 0;
522 for (size_t i = 0; i < NUM_TOMBSTONES; i++) {
523 if (tombstone_data[i].fd != -1) {
524 dumped = 1;
525 dump_file_from_fd("TOMBSTONE", tombstone_data[i].name, tombstone_data[i].fd);
526 tombstone_data[i].fd = -1;
527 }
528 }
529 if (!dumped) {
530 printf("*** NO TOMBSTONES to dump in %s\n\n", TOMBSTONE_DIR);
531 }
532
Colin Crossf45fa6b2012-03-26 12:38:26 -0700533 dump_file("NETWORK DEV INFO", "/proc/net/dev");
534 dump_file("QTAGUID NETWORK INTERFACES INFO", "/proc/net/xt_qtaguid/iface_stat_all");
JP Abgrall012c2ea2012-05-16 20:49:29 -0700535 dump_file("QTAGUID NETWORK INTERFACES INFO (xt)", "/proc/net/xt_qtaguid/iface_stat_fmt");
Colin Crossf45fa6b2012-03-26 12:38:26 -0700536 dump_file("QTAGUID CTRL INFO", "/proc/net/xt_qtaguid/ctrl");
537 dump_file("QTAGUID STATS INFO", "/proc/net/xt_qtaguid/stats");
538
Todd Poynor2a83daa2013-11-22 15:44:22 -0800539 if (!stat(PSTORE_LAST_KMSG, &st)) {
540 /* Also TODO: Make console-ramoops CAP_SYSLOG protected. */
541 dump_file("LAST KMSG", PSTORE_LAST_KMSG);
542 } else {
543 /* TODO: Make last_kmsg CAP_SYSLOG protected. b/5555691 */
544 dump_file("LAST KMSG", "/proc/last_kmsg");
545 }
546
Mark Salyzyn2262c162014-12-16 09:09:26 -0800547 /* kernels must set CONFIG_PSTORE_PMSG, slice up pstore with device tree */
Mark Salyzyn78316382015-10-09 14:02:07 -0700548 run_command("LAST LOGCAT", 10, "logcat", "-L",
549 "-b", "all",
550 "-v", "threadtime",
551 "-v", "printable",
552 "-d",
553 "*:v", NULL);
Mark Salyzyn2262c162014-12-16 09:09:26 -0800554
Colin Crossf45fa6b2012-03-26 12:38:26 -0700555 /* The following have a tendency to get wedged when wifi drivers/fw goes belly-up. */
Elliott Hughesa59828a2015-01-27 20:48:52 -0800556
557 run_command("NETWORK INTERFACES", 10, "ip", "link", NULL);
Lorenzo Colittid4c3d382014-07-30 14:38:20 +0900558
559 run_command("IPv4 ADDRESSES", 10, "ip", "-4", "addr", "show", NULL);
560 run_command("IPv6 ADDRESSES", 10, "ip", "-6", "addr", "show", NULL);
561
Colin Crossf45fa6b2012-03-26 12:38:26 -0700562 run_command("IP RULES", 10, "ip", "rule", "show", NULL);
563 run_command("IP RULES v6", 10, "ip", "-6", "rule", "show", NULL);
Sreeram Ramachandran2b3bba32014-07-08 15:40:55 -0700564
565 dump_route_tables();
566
Lorenzo Colittid4c3d382014-07-30 14:38:20 +0900567 run_command("ARP CACHE", 10, "ip", "-4", "neigh", "show", NULL);
568 run_command("IPv6 ND CACHE", 10, "ip", "-6", "neigh", "show", NULL);
569
Colin Crossf45fa6b2012-03-26 12:38:26 -0700570 run_command("IPTABLES", 10, SU_PATH, "root", "iptables", "-L", "-nvx", NULL);
571 run_command("IP6TABLES", 10, SU_PATH, "root", "ip6tables", "-L", "-nvx", NULL);
JP Abgrall012c2ea2012-05-16 20:49:29 -0700572 run_command("IPTABLE NAT", 10, SU_PATH, "root", "iptables", "-t", "nat", "-L", "-nvx", NULL);
573 /* no ip6 nat */
574 run_command("IPTABLE RAW", 10, SU_PATH, "root", "iptables", "-t", "raw", "-L", "-nvx", NULL);
575 run_command("IP6TABLE RAW", 10, SU_PATH, "root", "ip6tables", "-t", "raw", "-L", "-nvx", NULL);
Colin Crossf45fa6b2012-03-26 12:38:26 -0700576
577 run_command("WIFI NETWORKS", 20,
Dmitry Shmidt1d6b97c2013-08-21 10:58:29 -0700578 SU_PATH, "root", "wpa_cli", "IFNAME=wlan0", "list_networks", NULL);
Colin Crossf45fa6b2012-03-26 12:38:26 -0700579
Dmitry Shmidtc11f56e2012-11-07 10:42:05 -0800580#ifdef FWDUMP_bcmdhd
Lorenzo Colitti6afc38c2015-09-09 22:59:25 +0900581 run_command("ND OFFLOAD TABLE", 5,
582 SU_PATH, "root", "wlutil", "nd_hostip", NULL);
583
584 run_command("DUMP WIFI INTERNAL COUNTERS (1)", 20,
Dmitry Shmidtc11f56e2012-11-07 10:42:05 -0800585 SU_PATH, "root", "wlutil", "counters", NULL);
Lorenzo Colitti6afc38c2015-09-09 22:59:25 +0900586
587 run_command("ND OFFLOAD STATUS (1)", 5,
588 SU_PATH, "root", "wlutil", "nd_status", NULL);
589
Dmitry Shmidtc11f56e2012-11-07 10:42:05 -0800590#endif
Dmitry Shmidt0b2c9262012-11-07 11:09:46 -0800591 dump_file("INTERRUPTS (1)", "/proc/interrupts");
592
Lorenzo Colitti6afc38c2015-09-09 22:59:25 +0900593 run_command("NETWORK DIAGNOSTICS", 10, "dumpsys", "connectivity", "--diag", NULL);
594
Dmitry Shmidtc11f56e2012-11-07 10:42:05 -0800595#ifdef FWDUMP_bcmdhd
Colin Crossf45fa6b2012-03-26 12:38:26 -0700596 run_command("DUMP WIFI STATUS", 20,
597 SU_PATH, "root", "dhdutil", "-i", "wlan0", "dump", NULL);
Lorenzo Colitti6afc38c2015-09-09 22:59:25 +0900598
599 run_command("DUMP WIFI INTERNAL COUNTERS (2)", 20,
Colin Crossf45fa6b2012-03-26 12:38:26 -0700600 SU_PATH, "root", "wlutil", "counters", NULL);
Lorenzo Colitti6afc38c2015-09-09 22:59:25 +0900601
602 run_command("ND OFFLOAD STATUS (2)", 5,
603 SU_PATH, "root", "wlutil", "nd_status", NULL);
Colin Crossf45fa6b2012-03-26 12:38:26 -0700604#endif
Dmitry Shmidt0b2c9262012-11-07 11:09:46 -0800605 dump_file("INTERRUPTS (2)", "/proc/interrupts");
Colin Crossf45fa6b2012-03-26 12:38:26 -0700606
607 print_properties();
608
609 run_command("VOLD DUMP", 10, "vdc", "dump", NULL);
610 run_command("SECURE CONTAINERS", 10, "vdc", "asec", "list", NULL);
611
Ken Sumrall8f75fa72013-02-08 17:35:58 -0800612 run_command("FILESYSTEMS & FREE SPACE", 10, "df", NULL);
Colin Crossf45fa6b2012-03-26 12:38:26 -0700613
Colin Crossf45fa6b2012-03-26 12:38:26 -0700614 run_command("LAST RADIO LOG", 10, "parse_radio_log", "/proc/last_radio_log", NULL);
615
616 printf("------ BACKLIGHTS ------\n");
617 printf("LCD brightness=");
618 dump_file(NULL, "/sys/class/leds/lcd-backlight/brightness");
619 printf("Button brightness=");
620 dump_file(NULL, "/sys/class/leds/button-backlight/brightness");
621 printf("Keyboard brightness=");
622 dump_file(NULL, "/sys/class/leds/keyboard-backlight/brightness");
623 printf("ALS mode=");
624 dump_file(NULL, "/sys/class/leds/lcd-backlight/als");
625 printf("LCD driver registers:\n");
626 dump_file(NULL, "/sys/class/leds/lcd-backlight/registers");
627 printf("\n");
628
629 /* Binder state is expensive to look at as it uses a lot of memory. */
630 dump_file("BINDER FAILED TRANSACTION LOG", "/sys/kernel/debug/binder/failed_transaction_log");
631 dump_file("BINDER TRANSACTION LOG", "/sys/kernel/debug/binder/transaction_log");
632 dump_file("BINDER TRANSACTIONS", "/sys/kernel/debug/binder/transactions");
633 dump_file("BINDER STATS", "/sys/kernel/debug/binder/stats");
634 dump_file("BINDER STATE", "/sys/kernel/debug/binder/state");
635
Colin Crossf45fa6b2012-03-26 12:38:26 -0700636 printf("========================================================\n");
637 printf("== Board\n");
638 printf("========================================================\n");
639
640 dumpstate_board();
641 printf("\n");
Colin Crossf45fa6b2012-03-26 12:38:26 -0700642
643 /* Migrate the ril_dumpstate to a dumpstate_board()? */
644 char ril_dumpstate_timeout[PROPERTY_VALUE_MAX] = {0};
645 property_get("ril.dumpstate.timeout", ril_dumpstate_timeout, "30");
646 if (strnlen(ril_dumpstate_timeout, PROPERTY_VALUE_MAX - 1) > 0) {
647 if (0 == strncmp(build_type, "user", PROPERTY_VALUE_MAX - 1)) {
648 // su does not exist on user builds, so try running without it.
649 // This way any implementations of vril-dump that do not require
650 // root can run on user builds.
651 run_command("DUMP VENDOR RIL LOGS", atoi(ril_dumpstate_timeout),
652 "vril-dump", NULL);
653 } else {
654 run_command("DUMP VENDOR RIL LOGS", atoi(ril_dumpstate_timeout),
655 SU_PATH, "root", "vril-dump", NULL);
656 }
657 }
658
659 printf("========================================================\n");
660 printf("== Android Framework Services\n");
661 printf("========================================================\n");
662
663 /* the full dumpsys is starting to take a long time, so we need
664 to increase its timeout. we really need to do the timeouts in
665 dumpsys itself... */
666 run_command("DUMPSYS", 60, "dumpsys", NULL);
667
668 printf("========================================================\n");
Dianne Hackborn02bea972013-06-26 18:59:09 -0700669 printf("== Checkins\n");
670 printf("========================================================\n");
671
Dianne Hackborn59b15162013-09-04 18:04:14 -0700672 run_command("CHECKIN BATTERYSTATS", 30, "dumpsys", "batterystats", "-c", NULL);
Dianne Hackborn3e5fa732013-07-03 16:51:15 -0700673 run_command("CHECKIN MEMINFO", 30, "dumpsys", "meminfo", "--checkin", NULL);
Dianne Hackborn02bea972013-06-26 18:59:09 -0700674 run_command("CHECKIN NETSTATS", 30, "dumpsys", "netstats", "--checkin", NULL);
Dianne Hackborn5cd46aa2013-07-09 15:01:40 -0700675 run_command("CHECKIN PROCSTATS", 30, "dumpsys", "procstats", "-c", NULL);
Dianne Hackborn1bd50682013-07-11 11:45:18 -0700676 run_command("CHECKIN USAGESTATS", 30, "dumpsys", "usagestats", "-c", NULL);
Ashish Sharma8b3e1332015-04-28 13:32:54 -0700677 run_command("CHECKIN PACKAGE", 30, "dumpsys", "package", "--checkin", NULL);
Dianne Hackborn02bea972013-06-26 18:59:09 -0700678
679 printf("========================================================\n");
Colin Crossf45fa6b2012-03-26 12:38:26 -0700680 printf("== Running Application Activities\n");
681 printf("========================================================\n");
682
683 run_command("APP ACTIVITIES", 30, "dumpsys", "activity", "all", NULL);
684
685 printf("========================================================\n");
686 printf("== Running Application Services\n");
687 printf("========================================================\n");
688
689 run_command("APP SERVICES", 30, "dumpsys", "activity", "service", "all", NULL);
690
691 printf("========================================================\n");
692 printf("== Running Application Providers\n");
693 printf("========================================================\n");
694
695 run_command("APP SERVICES", 30, "dumpsys", "activity", "provider", "all", NULL);
696
697
698 printf("========================================================\n");
699 printf("== dumpstate: done\n");
700 printf("========================================================\n");
701}
702
703static void usage() {
John Michelau1f794c42012-09-17 11:20:19 -0500704 fprintf(stderr, "usage: dumpstate [-b soundfile] [-e soundfile] [-o file [-d] [-p] [-z]] [-s] [-q]\n"
Colin Crossf45fa6b2012-03-26 12:38:26 -0700705 " -o: write to file (instead of stdout)\n"
706 " -d: append date to filename (requires -o)\n"
Colin Crossf45fa6b2012-03-26 12:38:26 -0700707 " -p: capture screenshot to filename.png (requires -o)\n"
708 " -s: write output to control socket (for init)\n"
709 " -b: play sound file instead of vibrate, at beginning of job\n"
710 " -e: play sound file instead of vibrate, at end of job\n"
John Michelau1f794c42012-09-17 11:20:19 -0500711 " -q: disable vibrate\n"
Jeff Sharkey27f9e6d2013-03-13 15:45:50 -0700712 " -B: send broadcast when finished (requires -o and -p)\n"
Todd Poynor2a83daa2013-11-22 15:44:22 -0800713 );
Colin Crossf45fa6b2012-03-26 12:38:26 -0700714}
715
John Michelau885f8882013-05-06 16:42:02 -0500716static void sigpipe_handler(int n) {
Andres Morales2e671bb2014-08-21 12:38:22 -0700717 // don't complain to stderr or stdout
718 _exit(EXIT_FAILURE);
John Michelau885f8882013-05-06 16:42:02 -0500719}
720
Jeff Brown1dc94e32014-09-11 14:15:27 -0700721static void vibrate(FILE* vibrator, int ms) {
722 fprintf(vibrator, "%d\n", ms);
723 fflush(vibrator);
724}
725
Colin Crossf45fa6b2012-03-26 12:38:26 -0700726int main(int argc, char *argv[]) {
John Michelau885f8882013-05-06 16:42:02 -0500727 struct sigaction sigact;
Colin Crossf45fa6b2012-03-26 12:38:26 -0700728 int do_add_date = 0;
John Michelau1f794c42012-09-17 11:20:19 -0500729 int do_vibrate = 1;
Colin Crossf45fa6b2012-03-26 12:38:26 -0700730 char* use_outfile = 0;
Colin Crossf45fa6b2012-03-26 12:38:26 -0700731 int use_socket = 0;
732 int do_fb = 0;
Jeff Sharkey27f9e6d2013-03-13 15:45:50 -0700733 int do_broadcast = 0;
Colin Crossf45fa6b2012-03-26 12:38:26 -0700734
Nick Kralevich1e339872012-04-25 13:38:45 -0700735 if (getuid() != 0) {
736 // Old versions of the adb client would call the
737 // dumpstate command directly. Newer clients
738 // call /system/bin/bugreport instead. If we detect
739 // we're being called incorrectly, then exec the
740 // correct program.
741 return execl("/system/bin/bugreport", "/system/bin/bugreport", NULL);
742 }
Jeff Brown1dc94e32014-09-11 14:15:27 -0700743
Colin Crossf45fa6b2012-03-26 12:38:26 -0700744 ALOGI("begin\n");
745
Jeff Brown1dc94e32014-09-11 14:15:27 -0700746 /* clear SIGPIPE handler */
John Michelau885f8882013-05-06 16:42:02 -0500747 memset(&sigact, 0, sizeof(sigact));
748 sigact.sa_handler = sigpipe_handler;
749 sigaction(SIGPIPE, &sigact, NULL);
JP Abgrall3e03d3f2012-05-11 14:14:09 -0700750
Colin Crossf45fa6b2012-03-26 12:38:26 -0700751 /* set as high priority, and protect from OOM killer */
752 setpriority(PRIO_PROCESS, 0, -20);
Nick Kralevichcd67e9f2015-03-19 11:30:59 -0700753 FILE *oom_adj = fopen("/proc/self/oom_adj", "we");
Colin Crossf45fa6b2012-03-26 12:38:26 -0700754 if (oom_adj) {
755 fputs("-17", oom_adj);
756 fclose(oom_adj);
757 }
758
Jeff Brown1dc94e32014-09-11 14:15:27 -0700759 /* parse arguments */
Colin Crossf45fa6b2012-03-26 12:38:26 -0700760 int c;
Jeff Brown1dc94e32014-09-11 14:15:27 -0700761 while ((c = getopt(argc, argv, "dho:svqzpB")) != -1) {
Colin Crossf45fa6b2012-03-26 12:38:26 -0700762 switch (c) {
Colin Crossf45fa6b2012-03-26 12:38:26 -0700763 case 'd': do_add_date = 1; break;
Colin Crossf45fa6b2012-03-26 12:38:26 -0700764 case 'o': use_outfile = optarg; break;
765 case 's': use_socket = 1; break;
766 case 'v': break; // compatibility no-op
John Michelau1f794c42012-09-17 11:20:19 -0500767 case 'q': do_vibrate = 0; break;
Colin Crossf45fa6b2012-03-26 12:38:26 -0700768 case 'p': do_fb = 1; break;
Jeff Sharkey27f9e6d2013-03-13 15:45:50 -0700769 case 'B': do_broadcast = 1; break;
Colin Crossf45fa6b2012-03-26 12:38:26 -0700770 case '?': printf("\n");
771 case 'h':
772 usage();
773 exit(1);
774 }
775 }
776
Christopher Ferrised9354f2014-10-01 17:35:01 -0700777 // If we are going to use a socket, do it as early as possible
778 // to avoid timeouts from bugreport.
779 if (use_socket) {
780 redirect_to_socket(stdout, "dumpstate");
781 }
782
Jeff Brown1dc94e32014-09-11 14:15:27 -0700783 /* open the vibrator before dropping root */
John Michelau1f794c42012-09-17 11:20:19 -0500784 FILE *vibrator = 0;
785 if (do_vibrate) {
Nick Kralevichcd67e9f2015-03-19 11:30:59 -0700786 vibrator = fopen("/sys/class/timed_output/vibrator/enable", "we");
Jeff Brown1dc94e32014-09-11 14:15:27 -0700787 if (vibrator) {
Jeff Brown1dc94e32014-09-11 14:15:27 -0700788 vibrate(vibrator, 150);
789 }
John Michelau1f794c42012-09-17 11:20:19 -0500790 }
Colin Crossf45fa6b2012-03-26 12:38:26 -0700791
792 /* read /proc/cmdline before dropping root */
Nick Kralevichcd67e9f2015-03-19 11:30:59 -0700793 FILE *cmdline = fopen("/proc/cmdline", "re");
Colin Crossf45fa6b2012-03-26 12:38:26 -0700794 if (cmdline != NULL) {
795 fgets(cmdline_buf, sizeof(cmdline_buf), cmdline);
796 fclose(cmdline);
797 }
798
Jeff Brown1dc94e32014-09-11 14:15:27 -0700799 /* collect stack traces from Dalvik and native processes (needs root) */
800 dump_traces_path = dump_traces();
801
802 /* Get the tombstone fds here while we are running as root. */
803 get_tombstone_fds(tombstone_data);
804
805 /* ensure we will keep capabilities when we drop root */
Nick Kralevich1e339872012-04-25 13:38:45 -0700806 if (prctl(PR_SET_KEEPCAPS, 1) < 0) {
807 ALOGE("prctl(PR_SET_KEEPCAPS) failed: %s\n", strerror(errno));
808 return -1;
809 }
Colin Crossf45fa6b2012-03-26 12:38:26 -0700810
Nick Kralevich1e339872012-04-25 13:38:45 -0700811 /* switch to non-root user and group */
812 gid_t groups[] = { AID_LOG, AID_SDCARD_R, AID_SDCARD_RW,
Nick Kralevichab46a492015-11-07 17:05:41 -0800813 AID_MOUNT, AID_INET, AID_NET_BW_STATS, AID_READPROC };
Nick Kralevich1e339872012-04-25 13:38:45 -0700814 if (setgroups(sizeof(groups)/sizeof(groups[0]), groups) != 0) {
815 ALOGE("Unable to setgroups, aborting: %s\n", strerror(errno));
816 return -1;
817 }
818 if (setgid(AID_SHELL) != 0) {
819 ALOGE("Unable to setgid, aborting: %s\n", strerror(errno));
820 return -1;
821 }
822 if (setuid(AID_SHELL) != 0) {
823 ALOGE("Unable to setuid, aborting: %s\n", strerror(errno));
824 return -1;
825 }
Colin Crossf45fa6b2012-03-26 12:38:26 -0700826
Nick Kralevich1e339872012-04-25 13:38:45 -0700827 struct __user_cap_header_struct capheader;
828 struct __user_cap_data_struct capdata[2];
829 memset(&capheader, 0, sizeof(capheader));
830 memset(&capdata, 0, sizeof(capdata));
831 capheader.version = _LINUX_CAPABILITY_VERSION_3;
832 capheader.pid = 0;
Colin Crossf45fa6b2012-03-26 12:38:26 -0700833
Nick Kralevich1e339872012-04-25 13:38:45 -0700834 capdata[CAP_TO_INDEX(CAP_SYSLOG)].permitted = CAP_TO_MASK(CAP_SYSLOG);
835 capdata[CAP_TO_INDEX(CAP_SYSLOG)].effective = CAP_TO_MASK(CAP_SYSLOG);
836 capdata[0].inheritable = 0;
837 capdata[1].inheritable = 0;
Colin Crossf45fa6b2012-03-26 12:38:26 -0700838
Nick Kralevich1e339872012-04-25 13:38:45 -0700839 if (capset(&capheader, &capdata[0]) < 0) {
840 ALOGE("capset failed: %s\n", strerror(errno));
841 return -1;
Colin Crossf45fa6b2012-03-26 12:38:26 -0700842 }
843
Jeff Brown1dc94e32014-09-11 14:15:27 -0700844 /* redirect output if needed */
Colin Crossf45fa6b2012-03-26 12:38:26 -0700845 char path[PATH_MAX], tmp_path[PATH_MAX];
846 pid_t gzip_pid = -1;
847
Christopher Ferrised9354f2014-10-01 17:35:01 -0700848 if (!use_socket && use_outfile) {
Colin Crossf45fa6b2012-03-26 12:38:26 -0700849 strlcpy(path, use_outfile, sizeof(path));
850 if (do_add_date) {
851 char date[80];
852 time_t now = time(NULL);
853 strftime(date, sizeof(date), "-%Y-%m-%d-%H-%M-%S", localtime(&now));
854 strlcat(path, date, sizeof(path));
855 }
856 if (do_fb) {
857 strlcpy(screenshot_path, path, sizeof(screenshot_path));
858 strlcat(screenshot_path, ".png", sizeof(screenshot_path));
859 }
860 strlcat(path, ".txt", sizeof(path));
Colin Crossf45fa6b2012-03-26 12:38:26 -0700861 strlcpy(tmp_path, path, sizeof(tmp_path));
862 strlcat(tmp_path, ".tmp", sizeof(tmp_path));
Christopher Ferrisff4a4dc2015-02-09 16:24:47 -0800863 redirect_to_file(stdout, tmp_path);
Colin Crossf45fa6b2012-03-26 12:38:26 -0700864 }
865
Colin Crossf45fa6b2012-03-26 12:38:26 -0700866 dumpstate();
867
Jeff Brown1dc94e32014-09-11 14:15:27 -0700868 /* done */
869 if (vibrator) {
870 for (int i = 0; i < 3; i++) {
871 vibrate(vibrator, 75);
Colin Crossf45fa6b2012-03-26 12:38:26 -0700872 usleep((75 + 50) * 1000);
873 }
874 fclose(vibrator);
875 }
876
877 /* wait for gzip to finish, otherwise it might get killed when we exit */
878 if (gzip_pid > 0) {
879 fclose(stdout);
880 waitpid(gzip_pid, NULL, 0);
881 }
882
883 /* rename the (now complete) .tmp file to its final location */
884 if (use_outfile && rename(tmp_path, path)) {
885 fprintf(stderr, "rename(%s, %s): %s\n", tmp_path, path, strerror(errno));
886 }
887
Jeff Brown1dc94e32014-09-11 14:15:27 -0700888 /* tell activity manager we're done */
Jeff Sharkey27f9e6d2013-03-13 15:45:50 -0700889 if (do_broadcast && use_outfile && do_fb) {
Felipe Leme68116162015-11-10 20:10:25 -0800890 const char *args[] = { "/system/bin/am", "broadcast", "--user", "0",
Jeff Sharkey27f9e6d2013-03-13 15:45:50 -0700891 "-a", "android.intent.action.BUGREPORT_FINISHED",
892 "--es", "android.intent.extra.BUGREPORT", path,
893 "--es", "android.intent.extra.SCREENSHOT", screenshot_path,
Felipe Leme68116162015-11-10 20:10:25 -0800894 "--receiver-permission", "android.permission.DUMP", NULL };
895 run_command_always(NULL, 5, args);
Jeff Sharkey27f9e6d2013-03-13 15:45:50 -0700896 }
897
Colin Crossf45fa6b2012-03-26 12:38:26 -0700898 ALOGI("done\n");
899
900 return 0;
901}