blob: afb12556f4efc1f018b4d8ec4538eee5cd0cfda8 [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"
Mark Salyzyn7d0a7622016-06-24 14:06:15 -070049#define ALT_PSTORE_LAST_KMSG "/sys/fs/pstore/console-ramoops-0"
Todd Poynor2a83daa2013-11-22 15:44:22 -080050
Sharvil Nanavati8d4cb7f2015-07-24 02:01:13 -070051#define RAFT_DIR "/data/misc/raft/"
Christopher Ferris7dc7f322014-07-22 16:08:19 -070052#define TOMBSTONE_DIR "/data/tombstones"
53#define TOMBSTONE_FILE_PREFIX TOMBSTONE_DIR "/tombstone_"
54/* Can accomodate a tombstone number up to 9999. */
55#define TOMBSTONE_MAX_LEN (sizeof(TOMBSTONE_FILE_PREFIX) + 4)
56#define NUM_TOMBSTONES 10
57
58typedef struct {
59 char name[TOMBSTONE_MAX_LEN];
60 int fd;
61} tombstone_data_t;
62
63static tombstone_data_t tombstone_data[NUM_TOMBSTONES];
64
65/* Get the fds of any tombstone that was modified in the last half an hour. */
66static void get_tombstone_fds(tombstone_data_t data[NUM_TOMBSTONES]) {
67 time_t thirty_minutes_ago = time(NULL) - 60*30;
68 for (size_t i = 0; i < NUM_TOMBSTONES; i++) {
69 snprintf(data[i].name, sizeof(data[i].name), "%s%02zu", TOMBSTONE_FILE_PREFIX, i);
Christopher Ferris54bcc5f2015-02-10 12:15:01 -080070 int fd = TEMP_FAILURE_RETRY(open(data[i].name,
71 O_RDONLY | O_CLOEXEC | O_NOFOLLOW | O_NONBLOCK));
Christopher Ferris7dc7f322014-07-22 16:08:19 -070072 struct stat st;
73 if (fstat(fd, &st) == 0 && S_ISREG(st.st_mode) &&
74 (time_t) st.st_mtime >= thirty_minutes_ago) {
75 data[i].fd = fd;
76 } else {
77 close(fd);
78 data[i].fd = -1;
79 }
80 }
81}
82
Arve Hjønnevåg2db0f5f2014-10-15 18:08:37 -070083static void dump_dev_files(const char *title, const char *driverpath, const char *filename)
84{
85 DIR *d;
86 struct dirent *de;
87 char path[PATH_MAX];
88
89 d = opendir(driverpath);
90 if (d == NULL) {
91 return;
92 }
93
94 while ((de = readdir(d))) {
95 if (de->d_type != DT_LNK) {
96 continue;
97 }
98 snprintf(path, sizeof(path), "%s/%s/%s", driverpath, de->d_name, filename);
99 dump_file(title, path);
100 }
101
102 closedir(d);
103}
104
Mark Salyzyn326842f2015-04-30 09:49:41 -0700105static bool skip_not_stat(const char *path) {
106 static const char stat[] = "/stat";
107 size_t len = strlen(path);
108 if (path[len - 1] == '/') { /* Directory? */
109 return false;
110 }
111 return strcmp(path + len - sizeof(stat) + 1, stat); /* .../stat? */
112}
113
114static const char mmcblk0[] = "/sys/block/mmcblk0/";
Mark Salyzyn8f37aa52015-06-12 12:28:24 -0700115unsigned long worst_write_perf = 20000; /* in KB/s */
Mark Salyzyn326842f2015-04-30 09:49:41 -0700116
Mark Salyzyn01d6c392016-02-04 09:20:44 -0800117//
118// stat offsets
119// Name units description
120// ---- ----- -----------
121// read I/Os requests number of read I/Os processed
122#define __STAT_READ_IOS 0
123// read merges requests number of read I/Os merged with in-queue I/O
124#define __STAT_READ_MERGES 1
125// read sectors sectors number of sectors read
126#define __STAT_READ_SECTORS 2
127// read ticks milliseconds total wait time for read requests
128#define __STAT_READ_TICKS 3
129// write I/Os requests number of write I/Os processed
130#define __STAT_WRITE_IOS 4
131// write merges requests number of write I/Os merged with in-queue I/O
132#define __STAT_WRITE_MERGES 5
133// write sectors sectors number of sectors written
134#define __STAT_WRITE_SECTORS 6
135// write ticks milliseconds total wait time for write requests
136#define __STAT_WRITE_TICKS 7
137// in_flight requests number of I/Os currently in flight
138#define __STAT_IN_FLIGHT 8
139// io_ticks milliseconds total time this block device has been active
140#define __STAT_IO_TICKS 9
141// time_in_queue milliseconds total wait time for all requests
142#define __STAT_IN_QUEUE 10
143#define __STAT_NUMBER_FIELD 11
144//
145// read I/Os, write I/Os
146// =====================
147//
148// These values increment when an I/O request completes.
149//
150// read merges, write merges
151// =========================
152//
153// These values increment when an I/O request is merged with an
154// already-queued I/O request.
155//
156// read sectors, write sectors
157// ===========================
158//
159// These values count the number of sectors read from or written to this
160// block device. The "sectors" in question are the standard UNIX 512-byte
161// sectors, not any device- or filesystem-specific block size. The
162// counters are incremented when the I/O completes.
163#define SECTOR_SIZE 512
164//
165// read ticks, write ticks
166// =======================
167//
168// These values count the number of milliseconds that I/O requests have
169// waited on this block device. If there are multiple I/O requests waiting,
170// these values will increase at a rate greater than 1000/second; for
171// example, if 60 read requests wait for an average of 30 ms, the read_ticks
172// field will increase by 60*30 = 1800.
173//
174// in_flight
175// =========
176//
177// This value counts the number of I/O requests that have been issued to
178// the device driver but have not yet completed. It does not include I/O
179// requests that are in the queue but not yet issued to the device driver.
180//
181// io_ticks
182// ========
183//
184// This value counts the number of milliseconds during which the device has
185// had I/O requests queued.
186//
187// time_in_queue
188// =============
189//
190// This value counts the number of milliseconds that I/O requests have waited
191// on this block device. If there are multiple I/O requests waiting, this
192// value will increase as the product of the number of milliseconds times the
193// number of requests waiting (see "read ticks" above for an example).
194#define S_TO_MS 1000
195//
196
Mark Salyzyn326842f2015-04-30 09:49:41 -0700197static int dump_stat_from_fd(const char *title __unused, const char *path, int fd) {
Mark Salyzyn01d6c392016-02-04 09:20:44 -0800198 unsigned long long fields[__STAT_NUMBER_FIELD];
Mark Salyzyn326842f2015-04-30 09:49:41 -0700199 bool z;
200 char *cp, *buffer = NULL;
201 size_t i = 0;
202 FILE *fp = fdopen(fd, "rb");
203 getline(&buffer, &i, fp);
204 fclose(fp);
205 if (!buffer) {
206 return -errno;
207 }
208 i = strlen(buffer);
209 while ((i > 0) && (buffer[i - 1] == '\n')) {
210 buffer[--i] = '\0';
211 }
212 if (!*buffer) {
213 free(buffer);
214 return 0;
215 }
216 z = true;
217 for (cp = buffer, i = 0; i < (sizeof(fields) / sizeof(fields[0])); ++i) {
Mark Salyzyn01d6c392016-02-04 09:20:44 -0800218 fields[i] = strtoull(cp, &cp, 10);
Mark Salyzyn326842f2015-04-30 09:49:41 -0700219 if (fields[i] != 0) {
220 z = false;
221 }
222 }
223 if (z) { /* never accessed */
224 free(buffer);
225 return 0;
226 }
227
228 if (!strncmp(path, mmcblk0, sizeof(mmcblk0) - 1)) {
229 path += sizeof(mmcblk0) - 1;
230 }
231
232 printf("%s: %s\n", path, buffer);
233 free(buffer);
234
Mark Salyzyn01d6c392016-02-04 09:20:44 -0800235 if (fields[__STAT_IO_TICKS]) {
236 unsigned long read_perf = 0;
237 unsigned long read_ios = 0;
238 if (fields[__STAT_READ_TICKS]) {
239 unsigned long long divisor = fields[__STAT_READ_TICKS]
240 * fields[__STAT_IO_TICKS];
241 read_perf = ((unsigned long long)SECTOR_SIZE
242 * fields[__STAT_READ_SECTORS]
243 * fields[__STAT_IN_QUEUE] + (divisor >> 1))
244 / divisor;
245 read_ios = ((unsigned long long)S_TO_MS * fields[__STAT_READ_IOS]
246 * fields[__STAT_IN_QUEUE] + (divisor >> 1))
247 / divisor;
248 }
249
250 unsigned long write_perf = 0;
251 unsigned long write_ios = 0;
252 if (fields[__STAT_WRITE_TICKS]) {
253 unsigned long long divisor = fields[__STAT_WRITE_TICKS]
254 * fields[__STAT_IO_TICKS];
255 write_perf = ((unsigned long long)SECTOR_SIZE
256 * fields[__STAT_WRITE_SECTORS]
257 * fields[__STAT_IN_QUEUE] + (divisor >> 1))
258 / divisor;
259 write_ios = ((unsigned long long)S_TO_MS * fields[__STAT_WRITE_IOS]
260 * fields[__STAT_IN_QUEUE] + (divisor >> 1))
261 / divisor;
262 }
263
264 unsigned queue = (fields[__STAT_IN_QUEUE]
265 + (fields[__STAT_IO_TICKS] >> 1))
266 / fields[__STAT_IO_TICKS];
267
268 if (!write_perf && !write_ios) {
269 printf("%s: perf(ios) rd: %luKB/s(%lu/s) q: %u\n",
270 path, read_perf, read_ios, queue);
271 } else {
272 printf("%s: perf(ios) rd: %luKB/s(%lu/s) wr: %luKB/s(%lu/s) q: %u\n",
273 path, read_perf, read_ios, write_perf, write_ios, queue);
274 }
275
276 /* bugreport timeout factor adjustment */
277 if ((write_perf > 1) && (write_perf < worst_write_perf)) {
278 worst_write_perf = write_perf;
279 }
Mark Salyzyn8f37aa52015-06-12 12:28:24 -0700280 }
Mark Salyzyn326842f2015-04-30 09:49:41 -0700281 return 0;
282}
283
Mark Salyzyn8f37aa52015-06-12 12:28:24 -0700284/* Copied policy from system/core/logd/LogBuffer.cpp */
285
286#define LOG_BUFFER_SIZE (256 * 1024)
287#define LOG_BUFFER_MIN_SIZE (64 * 1024UL)
288#define LOG_BUFFER_MAX_SIZE (256 * 1024 * 1024UL)
289
290static bool valid_size(unsigned long value) {
291 if ((value < LOG_BUFFER_MIN_SIZE) || (LOG_BUFFER_MAX_SIZE < value)) {
292 return false;
293 }
294
295 long pages = sysconf(_SC_PHYS_PAGES);
296 if (pages < 1) {
297 return true;
298 }
299
300 long pagesize = sysconf(_SC_PAGESIZE);
301 if (pagesize <= 1) {
302 pagesize = PAGE_SIZE;
303 }
304
305 // maximum memory impact a somewhat arbitrary ~3%
306 pages = (pages + 31) / 32;
307 unsigned long maximum = pages * pagesize;
308
309 if ((maximum < LOG_BUFFER_MIN_SIZE) || (LOG_BUFFER_MAX_SIZE < maximum)) {
310 return true;
311 }
312
313 return value <= maximum;
314}
315
316static unsigned long property_get_size(const char *key) {
317 unsigned long value;
318 char *cp, property[PROPERTY_VALUE_MAX];
319
320 property_get(key, property, "");
321 value = strtoul(property, &cp, 10);
322
323 switch(*cp) {
324 case 'm':
325 case 'M':
326 value *= 1024;
327 /* FALLTHRU */
328 case 'k':
329 case 'K':
330 value *= 1024;
331 /* FALLTHRU */
332 case '\0':
333 break;
334
335 default:
336 value = 0;
337 }
338
339 if (!valid_size(value)) {
340 value = 0;
341 }
342
343 return value;
344}
345
346/* timeout in ms */
Felipe Leme515eb0d2015-12-14 15:09:56 -0800347static unsigned long logcat_timeout(const char *name) {
Mark Salyzyn8f37aa52015-06-12 12:28:24 -0700348 static const char global_tuneable[] = "persist.logd.size"; // Settings App
349 static const char global_default[] = "ro.logd.size"; // BoardConfig.mk
350 char key[PROP_NAME_MAX];
351 unsigned long property_size, default_size;
352
353 default_size = property_get_size(global_tuneable);
354 if (!default_size) {
355 default_size = property_get_size(global_default);
356 }
357
358 snprintf(key, sizeof(key), "%s.%s", global_tuneable, name);
359 property_size = property_get_size(key);
360
361 if (!property_size) {
362 snprintf(key, sizeof(key), "%s.%s", global_default, name);
363 property_size = property_get_size(key);
364 }
365
366 if (!property_size) {
367 property_size = default_size;
368 }
369
370 if (!property_size) {
371 property_size = LOG_BUFFER_SIZE;
372 }
373
374 /* Engineering margin is ten-fold our guess */
375 return 10 * (property_size + worst_write_perf) / worst_write_perf;
376}
377
378/* End copy from system/core/logd/LogBuffer.cpp */
379
Colin Crossf45fa6b2012-03-26 12:38:26 -0700380/* dumps the current system state to stdout */
381static void dumpstate() {
Mark Salyzyn8f37aa52015-06-12 12:28:24 -0700382 unsigned long timeout;
Colin Crossf45fa6b2012-03-26 12:38:26 -0700383 time_t now = time(NULL);
384 char build[PROPERTY_VALUE_MAX], fingerprint[PROPERTY_VALUE_MAX];
385 char radio[PROPERTY_VALUE_MAX], bootloader[PROPERTY_VALUE_MAX];
386 char network[PROPERTY_VALUE_MAX], date[80];
387 char build_type[PROPERTY_VALUE_MAX];
388
389 property_get("ro.build.display.id", build, "(unknown)");
390 property_get("ro.build.fingerprint", fingerprint, "(unknown)");
391 property_get("ro.build.type", build_type, "(unknown)");
392 property_get("ro.baseband", radio, "(unknown)");
393 property_get("ro.bootloader", bootloader, "(unknown)");
394 property_get("gsm.operator.alpha", network, "(unknown)");
395 strftime(date, sizeof(date), "%Y-%m-%d %H:%M:%S", localtime(&now));
396
397 printf("========================================================\n");
398 printf("== dumpstate: %s\n", date);
399 printf("========================================================\n");
400
401 printf("\n");
402 printf("Build: %s\n", build);
403 printf("Build fingerprint: '%s'\n", fingerprint); /* format is important for other tools */
404 printf("Bootloader: %s\n", bootloader);
405 printf("Radio: %s\n", radio);
406 printf("Network: %s\n", network);
407
408 printf("Kernel: ");
409 dump_file(NULL, "/proc/version");
410 printf("Command line: %s\n", strtok(cmdline_buf, "\n"));
411 printf("\n");
412
Arve Hjønnevåg2db0f5f2014-10-15 18:08:37 -0700413 dump_dev_files("TRUSTY VERSION", "/sys/bus/platform/drivers/trusty", "trusty_version");
Colin Crossf45fa6b2012-03-26 12:38:26 -0700414 run_command("UPTIME", 10, "uptime", NULL);
Mark Salyzyn326842f2015-04-30 09:49:41 -0700415 dump_files("UPTIME MMC PERF", mmcblk0, skip_not_stat, dump_stat_from_fd);
Mark Salyzyn8c8130e2015-12-09 11:21:28 -0800416 dump_emmc_ecsd("/d/mmc0/mmc0:0001/ext_csd");
Colin Crossf45fa6b2012-03-26 12:38:26 -0700417 dump_file("MEMORY INFO", "/proc/meminfo");
Elliott Hughes52860032016-06-14 13:56:00 -0700418 run_command("CPU INFO", 10, "top", "-b", "-n", "1", "-H", "-s", "6",
Elliott Hughes646e92f2016-06-13 17:35:07 -0700419 "-o", "pid,tid,user,pr,ni,%cpu,s,virt,res,pcy,cmd,name", NULL);
Nick Kralevich2b1f88b2015-10-07 16:38:42 -0700420 run_command("PROCRANK", 20, SU_PATH, "root", "procrank", NULL);
Colin Crossf45fa6b2012-03-26 12:38:26 -0700421 dump_file("VIRTUAL MEMORY STATS", "/proc/vmstat");
422 dump_file("VMALLOC INFO", "/proc/vmallocinfo");
423 dump_file("SLAB INFO", "/proc/slabinfo");
424 dump_file("ZONEINFO", "/proc/zoneinfo");
425 dump_file("PAGETYPEINFO", "/proc/pagetypeinfo");
426 dump_file("BUDDYINFO", "/proc/buddyinfo");
Colin Cross2281af92012-10-28 22:41:06 -0700427 dump_file("FRAGMENTATION INFO", "/d/extfrag/unusable_index");
Colin Crossf45fa6b2012-03-26 12:38:26 -0700428
Colin Crossf45fa6b2012-03-26 12:38:26 -0700429 dump_file("KERNEL WAKELOCKS", "/proc/wakelocks");
Todd Poynor29e27a82012-05-22 17:54:59 -0700430 dump_file("KERNEL WAKE SOURCES", "/d/wakeup_sources");
Colin Crossf45fa6b2012-03-26 12:38:26 -0700431 dump_file("KERNEL CPUFREQ", "/sys/devices/system/cpu/cpu0/cpufreq/stats/time_in_state");
Mathias Agopian85aea742012-08-08 15:32:02 -0700432 dump_file("KERNEL SYNC", "/d/sync");
Colin Crossf45fa6b2012-03-26 12:38:26 -0700433
Elliott Hughes52860032016-06-14 13:56:00 -0700434 run_command("PROCESSES AND THREADS", 10, "ps", "-A", "-T", "-Z",
Elliott Hughes32caf1d2016-05-04 14:03:54 -0700435 "-O", "pri,nice,rtprio,sched,pcy", NULL);
Colin Crossf45fa6b2012-03-26 12:38:26 -0700436 run_command("LIBRANK", 10, "librank", NULL);
437
438 do_dmesg();
439
440 run_command("LIST OF OPEN FILES", 10, SU_PATH, "root", "lsof", NULL);
Jeff Brown1dc94e32014-09-11 14:15:27 -0700441 for_each_pid(do_showmap, "SMAPS OF ALL PROCESSES");
442 for_each_tid(show_wchan, "BLOCKED PROCESS WAIT-CHANNELS");
Mark Salyzyn0751efa2016-02-05 15:33:17 -0800443 for_each_pid(show_showtime, "PROCESS TIMES (pid cmd user system iowait+percentage)");
Colin Crossf45fa6b2012-03-26 12:38:26 -0700444
Jeff Sharkey5a930032013-03-19 15:05:19 -0700445 if (screenshot_path[0]) {
446 ALOGI("taking screenshot\n");
447 run_command(NULL, 10, "/system/bin/screencap", "-p", screenshot_path, NULL);
448 ALOGI("wrote screenshot: %s\n", screenshot_path);
449 }
450
Colin Crossf45fa6b2012-03-26 12:38:26 -0700451 // dump_file("EVENT LOG TAGS", "/etc/event-log-tags");
Mark Salyzyn8f37aa52015-06-12 12:28:24 -0700452 // calculate timeout
453 timeout = logcat_timeout("main") + logcat_timeout("system") + logcat_timeout("crash");
454 if (timeout < 20000) {
455 timeout = 20000;
456 }
Mark Salyzyn78316382015-10-09 14:02:07 -0700457 run_command("SYSTEM LOG", timeout / 1000, "logcat", "-v", "threadtime",
458 "-v", "printable",
459 "-d",
460 "*:v", NULL);
Mark Salyzyn43afe5d2016-01-26 07:24:08 -0800461 timeout = logcat_timeout("events");
Mark Salyzyn8f37aa52015-06-12 12:28:24 -0700462 if (timeout < 20000) {
463 timeout = 20000;
464 }
Mark Salyzyn78316382015-10-09 14:02:07 -0700465 run_command("EVENT LOG", timeout / 1000, "logcat", "-b", "events",
466 "-v", "threadtime",
467 "-v", "printable",
468 "-d",
469 "*:v", NULL);
Mark Salyzyn8f37aa52015-06-12 12:28:24 -0700470 timeout = logcat_timeout("radio");
471 if (timeout < 20000) {
472 timeout = 20000;
473 }
Mark Salyzyn78316382015-10-09 14:02:07 -0700474 run_command("RADIO LOG", timeout / 1000, "logcat", "-b", "radio",
475 "-v", "threadtime",
476 "-v", "printable",
477 "-d",
478 "*:v", NULL);
Colin Crossf45fa6b2012-03-26 12:38:26 -0700479
Mark Salyzynecc07632015-07-30 14:57:09 -0700480 run_command("LOG STATISTICS", 10, "logcat", "-b", "all", "-S", NULL);
481
Sharvil Nanavati804339a2015-11-27 21:04:11 -0800482 run_command("RAFT LOGS", 600, SU_PATH, "root", "logcompressor", "-r", RAFT_DIR, NULL);
Sharvil Nanavati8d4cb7f2015-07-24 02:01:13 -0700483
Colin Crossf45fa6b2012-03-26 12:38:26 -0700484 /* show the traces we collected in main(), if that was done */
485 if (dump_traces_path != NULL) {
486 dump_file("VM TRACES JUST NOW", dump_traces_path);
487 }
488
489 /* only show ANR traces if they're less than 15 minutes old */
490 struct stat st;
491 char anr_traces_path[PATH_MAX];
492 property_get("dalvik.vm.stack-trace-file", anr_traces_path, "");
493 if (!anr_traces_path[0]) {
494 printf("*** NO VM TRACES FILE DEFINED (dalvik.vm.stack-trace-file)\n\n");
Colin Crossf45fa6b2012-03-26 12:38:26 -0700495 } else {
Christopher Ferris54bcc5f2015-02-10 12:15:01 -0800496 int fd = TEMP_FAILURE_RETRY(open(anr_traces_path,
497 O_RDONLY | O_CLOEXEC | O_NOFOLLOW | O_NONBLOCK));
Christopher Ferris7dc7f322014-07-22 16:08:19 -0700498 if (fd < 0) {
499 printf("*** NO ANR VM TRACES FILE (%s): %s\n\n", anr_traces_path, strerror(errno));
500 } else {
501 dump_file_from_fd("VM TRACES AT LAST ANR", anr_traces_path, fd);
502 }
Colin Crossf45fa6b2012-03-26 12:38:26 -0700503 }
504
505 /* slow traces for slow operations */
506 if (anr_traces_path[0] != 0) {
507 int tail = strlen(anr_traces_path)-1;
508 while (tail > 0 && anr_traces_path[tail] != '/') {
509 tail--;
510 }
511 int i = 0;
512 while (1) {
513 sprintf(anr_traces_path+tail+1, "slow%02d.txt", i);
514 if (stat(anr_traces_path, &st)) {
515 // No traces file at this index, done with the files.
516 break;
517 }
518 dump_file("VM TRACES WHEN SLOW", anr_traces_path);
519 i++;
520 }
521 }
522
Christopher Ferris7dc7f322014-07-22 16:08:19 -0700523 int dumped = 0;
524 for (size_t i = 0; i < NUM_TOMBSTONES; i++) {
525 if (tombstone_data[i].fd != -1) {
526 dumped = 1;
527 dump_file_from_fd("TOMBSTONE", tombstone_data[i].name, tombstone_data[i].fd);
528 tombstone_data[i].fd = -1;
529 }
530 }
531 if (!dumped) {
532 printf("*** NO TOMBSTONES to dump in %s\n\n", TOMBSTONE_DIR);
533 }
534
Colin Crossf45fa6b2012-03-26 12:38:26 -0700535 dump_file("NETWORK DEV INFO", "/proc/net/dev");
536 dump_file("QTAGUID NETWORK INTERFACES INFO", "/proc/net/xt_qtaguid/iface_stat_all");
JP Abgrall012c2ea2012-05-16 20:49:29 -0700537 dump_file("QTAGUID NETWORK INTERFACES INFO (xt)", "/proc/net/xt_qtaguid/iface_stat_fmt");
Colin Crossf45fa6b2012-03-26 12:38:26 -0700538 dump_file("QTAGUID CTRL INFO", "/proc/net/xt_qtaguid/ctrl");
539 dump_file("QTAGUID STATS INFO", "/proc/net/xt_qtaguid/stats");
540
Todd Poynor2a83daa2013-11-22 15:44:22 -0800541 if (!stat(PSTORE_LAST_KMSG, &st)) {
542 /* Also TODO: Make console-ramoops CAP_SYSLOG protected. */
543 dump_file("LAST KMSG", PSTORE_LAST_KMSG);
Mark Salyzyn7d0a7622016-06-24 14:06:15 -0700544 } else if (!stat(ALT_PSTORE_LAST_KMSG, &st)) {
545 dump_file("LAST KMSG", ALT_PSTORE_LAST_KMSG);
Todd Poynor2a83daa2013-11-22 15:44:22 -0800546 } else {
547 /* TODO: Make last_kmsg CAP_SYSLOG protected. b/5555691 */
548 dump_file("LAST KMSG", "/proc/last_kmsg");
549 }
550
Mark Salyzyn2262c162014-12-16 09:09:26 -0800551 /* kernels must set CONFIG_PSTORE_PMSG, slice up pstore with device tree */
Mark Salyzyn78316382015-10-09 14:02:07 -0700552 run_command("LAST LOGCAT", 10, "logcat", "-L",
553 "-b", "all",
554 "-v", "threadtime",
555 "-v", "printable",
556 "-d",
557 "*:v", NULL);
Mark Salyzyn2262c162014-12-16 09:09:26 -0800558
Colin Crossf45fa6b2012-03-26 12:38:26 -0700559 /* The following have a tendency to get wedged when wifi drivers/fw goes belly-up. */
Elliott Hughesa59828a2015-01-27 20:48:52 -0800560
561 run_command("NETWORK INTERFACES", 10, "ip", "link", NULL);
Lorenzo Colittid4c3d382014-07-30 14:38:20 +0900562
563 run_command("IPv4 ADDRESSES", 10, "ip", "-4", "addr", "show", NULL);
564 run_command("IPv6 ADDRESSES", 10, "ip", "-6", "addr", "show", NULL);
565
Colin Crossf45fa6b2012-03-26 12:38:26 -0700566 run_command("IP RULES", 10, "ip", "rule", "show", NULL);
567 run_command("IP RULES v6", 10, "ip", "-6", "rule", "show", NULL);
Sreeram Ramachandran2b3bba32014-07-08 15:40:55 -0700568
569 dump_route_tables();
570
Lorenzo Colittid4c3d382014-07-30 14:38:20 +0900571 run_command("ARP CACHE", 10, "ip", "-4", "neigh", "show", NULL);
572 run_command("IPv6 ND CACHE", 10, "ip", "-6", "neigh", "show", NULL);
573
Colin Crossf45fa6b2012-03-26 12:38:26 -0700574 run_command("IPTABLES", 10, SU_PATH, "root", "iptables", "-L", "-nvx", NULL);
575 run_command("IP6TABLES", 10, SU_PATH, "root", "ip6tables", "-L", "-nvx", NULL);
JP Abgrall012c2ea2012-05-16 20:49:29 -0700576 run_command("IPTABLE NAT", 10, SU_PATH, "root", "iptables", "-t", "nat", "-L", "-nvx", NULL);
577 /* no ip6 nat */
578 run_command("IPTABLE RAW", 10, SU_PATH, "root", "iptables", "-t", "raw", "-L", "-nvx", NULL);
579 run_command("IP6TABLE RAW", 10, SU_PATH, "root", "ip6tables", "-t", "raw", "-L", "-nvx", NULL);
Colin Crossf45fa6b2012-03-26 12:38:26 -0700580
581 run_command("WIFI NETWORKS", 20,
Dmitry Shmidt1d6b97c2013-08-21 10:58:29 -0700582 SU_PATH, "root", "wpa_cli", "IFNAME=wlan0", "list_networks", NULL);
Colin Crossf45fa6b2012-03-26 12:38:26 -0700583
Dmitry Shmidtc11f56e2012-11-07 10:42:05 -0800584#ifdef FWDUMP_bcmdhd
Lorenzo Colitti6afc38c2015-09-09 22:59:25 +0900585 run_command("ND OFFLOAD TABLE", 5,
586 SU_PATH, "root", "wlutil", "nd_hostip", NULL);
587
588 run_command("DUMP WIFI INTERNAL COUNTERS (1)", 20,
Dmitry Shmidtc11f56e2012-11-07 10:42:05 -0800589 SU_PATH, "root", "wlutil", "counters", NULL);
Lorenzo Colitti6afc38c2015-09-09 22:59:25 +0900590
591 run_command("ND OFFLOAD STATUS (1)", 5,
592 SU_PATH, "root", "wlutil", "nd_status", NULL);
593
Dmitry Shmidtc11f56e2012-11-07 10:42:05 -0800594#endif
Dmitry Shmidt0b2c9262012-11-07 11:09:46 -0800595 dump_file("INTERRUPTS (1)", "/proc/interrupts");
596
Lorenzo Colitti6afc38c2015-09-09 22:59:25 +0900597 run_command("NETWORK DIAGNOSTICS", 10, "dumpsys", "connectivity", "--diag", NULL);
598
Dmitry Shmidtc11f56e2012-11-07 10:42:05 -0800599#ifdef FWDUMP_bcmdhd
Colin Crossf45fa6b2012-03-26 12:38:26 -0700600 run_command("DUMP WIFI STATUS", 20,
601 SU_PATH, "root", "dhdutil", "-i", "wlan0", "dump", NULL);
Lorenzo Colitti6afc38c2015-09-09 22:59:25 +0900602
603 run_command("DUMP WIFI INTERNAL COUNTERS (2)", 20,
Colin Crossf45fa6b2012-03-26 12:38:26 -0700604 SU_PATH, "root", "wlutil", "counters", NULL);
Lorenzo Colitti6afc38c2015-09-09 22:59:25 +0900605
606 run_command("ND OFFLOAD STATUS (2)", 5,
607 SU_PATH, "root", "wlutil", "nd_status", NULL);
Colin Crossf45fa6b2012-03-26 12:38:26 -0700608#endif
Dmitry Shmidt0b2c9262012-11-07 11:09:46 -0800609 dump_file("INTERRUPTS (2)", "/proc/interrupts");
Colin Crossf45fa6b2012-03-26 12:38:26 -0700610
611 print_properties();
612
613 run_command("VOLD DUMP", 10, "vdc", "dump", NULL);
614 run_command("SECURE CONTAINERS", 10, "vdc", "asec", "list", NULL);
615
Ken Sumrall8f75fa72013-02-08 17:35:58 -0800616 run_command("FILESYSTEMS & FREE SPACE", 10, "df", NULL);
Colin Crossf45fa6b2012-03-26 12:38:26 -0700617
Colin Crossf45fa6b2012-03-26 12:38:26 -0700618 run_command("LAST RADIO LOG", 10, "parse_radio_log", "/proc/last_radio_log", NULL);
619
620 printf("------ BACKLIGHTS ------\n");
621 printf("LCD brightness=");
622 dump_file(NULL, "/sys/class/leds/lcd-backlight/brightness");
623 printf("Button brightness=");
624 dump_file(NULL, "/sys/class/leds/button-backlight/brightness");
625 printf("Keyboard brightness=");
626 dump_file(NULL, "/sys/class/leds/keyboard-backlight/brightness");
627 printf("ALS mode=");
628 dump_file(NULL, "/sys/class/leds/lcd-backlight/als");
629 printf("LCD driver registers:\n");
630 dump_file(NULL, "/sys/class/leds/lcd-backlight/registers");
631 printf("\n");
632
633 /* Binder state is expensive to look at as it uses a lot of memory. */
634 dump_file("BINDER FAILED TRANSACTION LOG", "/sys/kernel/debug/binder/failed_transaction_log");
635 dump_file("BINDER TRANSACTION LOG", "/sys/kernel/debug/binder/transaction_log");
636 dump_file("BINDER TRANSACTIONS", "/sys/kernel/debug/binder/transactions");
637 dump_file("BINDER STATS", "/sys/kernel/debug/binder/stats");
638 dump_file("BINDER STATE", "/sys/kernel/debug/binder/state");
639
Colin Crossf45fa6b2012-03-26 12:38:26 -0700640 printf("========================================================\n");
641 printf("== Board\n");
642 printf("========================================================\n");
643
644 dumpstate_board();
645 printf("\n");
Colin Crossf45fa6b2012-03-26 12:38:26 -0700646
647 /* Migrate the ril_dumpstate to a dumpstate_board()? */
648 char ril_dumpstate_timeout[PROPERTY_VALUE_MAX] = {0};
649 property_get("ril.dumpstate.timeout", ril_dumpstate_timeout, "30");
650 if (strnlen(ril_dumpstate_timeout, PROPERTY_VALUE_MAX - 1) > 0) {
651 if (0 == strncmp(build_type, "user", PROPERTY_VALUE_MAX - 1)) {
652 // su does not exist on user builds, so try running without it.
653 // This way any implementations of vril-dump that do not require
654 // root can run on user builds.
655 run_command("DUMP VENDOR RIL LOGS", atoi(ril_dumpstate_timeout),
656 "vril-dump", NULL);
657 } else {
658 run_command("DUMP VENDOR RIL LOGS", atoi(ril_dumpstate_timeout),
659 SU_PATH, "root", "vril-dump", NULL);
660 }
661 }
662
663 printf("========================================================\n");
664 printf("== Android Framework Services\n");
665 printf("========================================================\n");
666
667 /* the full dumpsys is starting to take a long time, so we need
668 to increase its timeout. we really need to do the timeouts in
669 dumpsys itself... */
670 run_command("DUMPSYS", 60, "dumpsys", NULL);
671
672 printf("========================================================\n");
Dianne Hackborn02bea972013-06-26 18:59:09 -0700673 printf("== Checkins\n");
674 printf("========================================================\n");
675
Dianne Hackborn59b15162013-09-04 18:04:14 -0700676 run_command("CHECKIN BATTERYSTATS", 30, "dumpsys", "batterystats", "-c", NULL);
Dianne Hackborn3e5fa732013-07-03 16:51:15 -0700677 run_command("CHECKIN MEMINFO", 30, "dumpsys", "meminfo", "--checkin", NULL);
Dianne Hackborn02bea972013-06-26 18:59:09 -0700678 run_command("CHECKIN NETSTATS", 30, "dumpsys", "netstats", "--checkin", NULL);
Dianne Hackborn5cd46aa2013-07-09 15:01:40 -0700679 run_command("CHECKIN PROCSTATS", 30, "dumpsys", "procstats", "-c", NULL);
Dianne Hackborn1bd50682013-07-11 11:45:18 -0700680 run_command("CHECKIN USAGESTATS", 30, "dumpsys", "usagestats", "-c", NULL);
Ashish Sharma8b3e1332015-04-28 13:32:54 -0700681 run_command("CHECKIN PACKAGE", 30, "dumpsys", "package", "--checkin", NULL);
Dianne Hackborn02bea972013-06-26 18:59:09 -0700682
683 printf("========================================================\n");
Colin Crossf45fa6b2012-03-26 12:38:26 -0700684 printf("== Running Application Activities\n");
685 printf("========================================================\n");
686
687 run_command("APP ACTIVITIES", 30, "dumpsys", "activity", "all", NULL);
688
689 printf("========================================================\n");
690 printf("== Running Application Services\n");
691 printf("========================================================\n");
692
693 run_command("APP SERVICES", 30, "dumpsys", "activity", "service", "all", NULL);
694
695 printf("========================================================\n");
696 printf("== Running Application Providers\n");
697 printf("========================================================\n");
698
699 run_command("APP SERVICES", 30, "dumpsys", "activity", "provider", "all", NULL);
700
701
702 printf("========================================================\n");
703 printf("== dumpstate: done\n");
704 printf("========================================================\n");
705}
706
707static void usage() {
John Michelau1f794c42012-09-17 11:20:19 -0500708 fprintf(stderr, "usage: dumpstate [-b soundfile] [-e soundfile] [-o file [-d] [-p] [-z]] [-s] [-q]\n"
Colin Crossf45fa6b2012-03-26 12:38:26 -0700709 " -o: write to file (instead of stdout)\n"
710 " -d: append date to filename (requires -o)\n"
Colin Crossf45fa6b2012-03-26 12:38:26 -0700711 " -p: capture screenshot to filename.png (requires -o)\n"
712 " -s: write output to control socket (for init)\n"
713 " -b: play sound file instead of vibrate, at beginning of job\n"
714 " -e: play sound file instead of vibrate, at end of job\n"
John Michelau1f794c42012-09-17 11:20:19 -0500715 " -q: disable vibrate\n"
Jeff Sharkey27f9e6d2013-03-13 15:45:50 -0700716 " -B: send broadcast when finished (requires -o and -p)\n"
Todd Poynor2a83daa2013-11-22 15:44:22 -0800717 );
Colin Crossf45fa6b2012-03-26 12:38:26 -0700718}
719
John Michelau885f8882013-05-06 16:42:02 -0500720static void sigpipe_handler(int n) {
Andres Morales2e671bb2014-08-21 12:38:22 -0700721 // don't complain to stderr or stdout
722 _exit(EXIT_FAILURE);
John Michelau885f8882013-05-06 16:42:02 -0500723}
724
Jeff Brown1dc94e32014-09-11 14:15:27 -0700725static void vibrate(FILE* vibrator, int ms) {
726 fprintf(vibrator, "%d\n", ms);
727 fflush(vibrator);
728}
729
Colin Crossf45fa6b2012-03-26 12:38:26 -0700730int main(int argc, char *argv[]) {
John Michelau885f8882013-05-06 16:42:02 -0500731 struct sigaction sigact;
Colin Crossf45fa6b2012-03-26 12:38:26 -0700732 int do_add_date = 0;
John Michelau1f794c42012-09-17 11:20:19 -0500733 int do_vibrate = 1;
Colin Crossf45fa6b2012-03-26 12:38:26 -0700734 char* use_outfile = 0;
Colin Crossf45fa6b2012-03-26 12:38:26 -0700735 int use_socket = 0;
736 int do_fb = 0;
Jeff Sharkey27f9e6d2013-03-13 15:45:50 -0700737 int do_broadcast = 0;
Colin Crossf45fa6b2012-03-26 12:38:26 -0700738
Nick Kralevich1e339872012-04-25 13:38:45 -0700739 if (getuid() != 0) {
740 // Old versions of the adb client would call the
741 // dumpstate command directly. Newer clients
742 // call /system/bin/bugreport instead. If we detect
743 // we're being called incorrectly, then exec the
744 // correct program.
745 return execl("/system/bin/bugreport", "/system/bin/bugreport", NULL);
746 }
Jeff Brown1dc94e32014-09-11 14:15:27 -0700747
Colin Crossf45fa6b2012-03-26 12:38:26 -0700748 ALOGI("begin\n");
749
Jeff Brown1dc94e32014-09-11 14:15:27 -0700750 /* clear SIGPIPE handler */
John Michelau885f8882013-05-06 16:42:02 -0500751 memset(&sigact, 0, sizeof(sigact));
752 sigact.sa_handler = sigpipe_handler;
753 sigaction(SIGPIPE, &sigact, NULL);
JP Abgrall3e03d3f2012-05-11 14:14:09 -0700754
Colin Crossf45fa6b2012-03-26 12:38:26 -0700755 /* set as high priority, and protect from OOM killer */
756 setpriority(PRIO_PROCESS, 0, -20);
Nick Kralevichcd67e9f2015-03-19 11:30:59 -0700757 FILE *oom_adj = fopen("/proc/self/oom_adj", "we");
Colin Crossf45fa6b2012-03-26 12:38:26 -0700758 if (oom_adj) {
759 fputs("-17", oom_adj);
760 fclose(oom_adj);
761 }
762
Jeff Brown1dc94e32014-09-11 14:15:27 -0700763 /* parse arguments */
Colin Crossf45fa6b2012-03-26 12:38:26 -0700764 int c;
Jeff Brown1dc94e32014-09-11 14:15:27 -0700765 while ((c = getopt(argc, argv, "dho:svqzpB")) != -1) {
Colin Crossf45fa6b2012-03-26 12:38:26 -0700766 switch (c) {
Colin Crossf45fa6b2012-03-26 12:38:26 -0700767 case 'd': do_add_date = 1; break;
Colin Crossf45fa6b2012-03-26 12:38:26 -0700768 case 'o': use_outfile = optarg; break;
769 case 's': use_socket = 1; break;
770 case 'v': break; // compatibility no-op
John Michelau1f794c42012-09-17 11:20:19 -0500771 case 'q': do_vibrate = 0; break;
Colin Crossf45fa6b2012-03-26 12:38:26 -0700772 case 'p': do_fb = 1; break;
Jeff Sharkey27f9e6d2013-03-13 15:45:50 -0700773 case 'B': do_broadcast = 1; break;
Colin Crossf45fa6b2012-03-26 12:38:26 -0700774 case '?': printf("\n");
775 case 'h':
776 usage();
777 exit(1);
778 }
779 }
780
Christopher Ferrised9354f2014-10-01 17:35:01 -0700781 // If we are going to use a socket, do it as early as possible
782 // to avoid timeouts from bugreport.
783 if (use_socket) {
784 redirect_to_socket(stdout, "dumpstate");
785 }
786
Jeff Brown1dc94e32014-09-11 14:15:27 -0700787 /* open the vibrator before dropping root */
John Michelau1f794c42012-09-17 11:20:19 -0500788 FILE *vibrator = 0;
789 if (do_vibrate) {
Nick Kralevichcd67e9f2015-03-19 11:30:59 -0700790 vibrator = fopen("/sys/class/timed_output/vibrator/enable", "we");
Jeff Brown1dc94e32014-09-11 14:15:27 -0700791 if (vibrator) {
Jeff Brown1dc94e32014-09-11 14:15:27 -0700792 vibrate(vibrator, 150);
793 }
John Michelau1f794c42012-09-17 11:20:19 -0500794 }
Colin Crossf45fa6b2012-03-26 12:38:26 -0700795
796 /* read /proc/cmdline before dropping root */
Nick Kralevichcd67e9f2015-03-19 11:30:59 -0700797 FILE *cmdline = fopen("/proc/cmdline", "re");
Colin Crossf45fa6b2012-03-26 12:38:26 -0700798 if (cmdline != NULL) {
799 fgets(cmdline_buf, sizeof(cmdline_buf), cmdline);
800 fclose(cmdline);
801 }
802
Jeff Brown1dc94e32014-09-11 14:15:27 -0700803 /* collect stack traces from Dalvik and native processes (needs root) */
804 dump_traces_path = dump_traces();
805
806 /* Get the tombstone fds here while we are running as root. */
807 get_tombstone_fds(tombstone_data);
808
809 /* ensure we will keep capabilities when we drop root */
Nick Kralevich1e339872012-04-25 13:38:45 -0700810 if (prctl(PR_SET_KEEPCAPS, 1) < 0) {
811 ALOGE("prctl(PR_SET_KEEPCAPS) failed: %s\n", strerror(errno));
812 return -1;
813 }
Colin Crossf45fa6b2012-03-26 12:38:26 -0700814
Nick Kralevich1e339872012-04-25 13:38:45 -0700815 /* switch to non-root user and group */
816 gid_t groups[] = { AID_LOG, AID_SDCARD_R, AID_SDCARD_RW,
Nick Kralevichab46a492015-11-07 17:05:41 -0800817 AID_MOUNT, AID_INET, AID_NET_BW_STATS, AID_READPROC };
Nick Kralevich1e339872012-04-25 13:38:45 -0700818 if (setgroups(sizeof(groups)/sizeof(groups[0]), groups) != 0) {
819 ALOGE("Unable to setgroups, aborting: %s\n", strerror(errno));
820 return -1;
821 }
822 if (setgid(AID_SHELL) != 0) {
823 ALOGE("Unable to setgid, aborting: %s\n", strerror(errno));
824 return -1;
825 }
826 if (setuid(AID_SHELL) != 0) {
827 ALOGE("Unable to setuid, aborting: %s\n", strerror(errno));
828 return -1;
829 }
Colin Crossf45fa6b2012-03-26 12:38:26 -0700830
Nick Kralevich1e339872012-04-25 13:38:45 -0700831 struct __user_cap_header_struct capheader;
832 struct __user_cap_data_struct capdata[2];
833 memset(&capheader, 0, sizeof(capheader));
834 memset(&capdata, 0, sizeof(capdata));
835 capheader.version = _LINUX_CAPABILITY_VERSION_3;
836 capheader.pid = 0;
Colin Crossf45fa6b2012-03-26 12:38:26 -0700837
Nick Kralevich1e339872012-04-25 13:38:45 -0700838 capdata[CAP_TO_INDEX(CAP_SYSLOG)].permitted = CAP_TO_MASK(CAP_SYSLOG);
839 capdata[CAP_TO_INDEX(CAP_SYSLOG)].effective = CAP_TO_MASK(CAP_SYSLOG);
840 capdata[0].inheritable = 0;
841 capdata[1].inheritable = 0;
Colin Crossf45fa6b2012-03-26 12:38:26 -0700842
Nick Kralevich1e339872012-04-25 13:38:45 -0700843 if (capset(&capheader, &capdata[0]) < 0) {
844 ALOGE("capset failed: %s\n", strerror(errno));
845 return -1;
Colin Crossf45fa6b2012-03-26 12:38:26 -0700846 }
847
Jeff Brown1dc94e32014-09-11 14:15:27 -0700848 /* redirect output if needed */
Colin Crossf45fa6b2012-03-26 12:38:26 -0700849 char path[PATH_MAX], tmp_path[PATH_MAX];
850 pid_t gzip_pid = -1;
851
Christopher Ferrised9354f2014-10-01 17:35:01 -0700852 if (!use_socket && use_outfile) {
Colin Crossf45fa6b2012-03-26 12:38:26 -0700853 strlcpy(path, use_outfile, sizeof(path));
854 if (do_add_date) {
855 char date[80];
856 time_t now = time(NULL);
857 strftime(date, sizeof(date), "-%Y-%m-%d-%H-%M-%S", localtime(&now));
858 strlcat(path, date, sizeof(path));
859 }
860 if (do_fb) {
861 strlcpy(screenshot_path, path, sizeof(screenshot_path));
862 strlcat(screenshot_path, ".png", sizeof(screenshot_path));
863 }
864 strlcat(path, ".txt", sizeof(path));
Colin Crossf45fa6b2012-03-26 12:38:26 -0700865 strlcpy(tmp_path, path, sizeof(tmp_path));
866 strlcat(tmp_path, ".tmp", sizeof(tmp_path));
Christopher Ferrisff4a4dc2015-02-09 16:24:47 -0800867 redirect_to_file(stdout, tmp_path);
Colin Crossf45fa6b2012-03-26 12:38:26 -0700868 }
869
Colin Crossf45fa6b2012-03-26 12:38:26 -0700870 dumpstate();
871
Jeff Brown1dc94e32014-09-11 14:15:27 -0700872 /* done */
873 if (vibrator) {
874 for (int i = 0; i < 3; i++) {
875 vibrate(vibrator, 75);
Colin Crossf45fa6b2012-03-26 12:38:26 -0700876 usleep((75 + 50) * 1000);
877 }
878 fclose(vibrator);
879 }
880
881 /* wait for gzip to finish, otherwise it might get killed when we exit */
882 if (gzip_pid > 0) {
883 fclose(stdout);
884 waitpid(gzip_pid, NULL, 0);
885 }
886
887 /* rename the (now complete) .tmp file to its final location */
888 if (use_outfile && rename(tmp_path, path)) {
889 fprintf(stderr, "rename(%s, %s): %s\n", tmp_path, path, strerror(errno));
890 }
891
Jeff Brown1dc94e32014-09-11 14:15:27 -0700892 /* tell activity manager we're done */
Jeff Sharkey27f9e6d2013-03-13 15:45:50 -0700893 if (do_broadcast && use_outfile && do_fb) {
Felipe Leme68116162015-11-10 20:10:25 -0800894 const char *args[] = { "/system/bin/am", "broadcast", "--user", "0",
Jeff Sharkey27f9e6d2013-03-13 15:45:50 -0700895 "-a", "android.intent.action.BUGREPORT_FINISHED",
896 "--es", "android.intent.extra.BUGREPORT", path,
897 "--es", "android.intent.extra.SCREENSHOT", screenshot_path,
Felipe Leme68116162015-11-10 20:10:25 -0800898 "--receiver-permission", "android.permission.DUMP", NULL };
899 run_command_always(NULL, 5, args);
Jeff Sharkey27f9e6d2013-03-13 15:45:50 -0700900 }
901
Colin Crossf45fa6b2012-03-26 12:38:26 -0700902 ALOGI("done\n");
903
904 return 0;
905}