Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 1 | /* |
| 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åg | 2db0f5f | 2014-10-15 18:08:37 -0700 | [diff] [blame] | 17 | #include <dirent.h> |
Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 18 | #include <errno.h> |
| 19 | #include <fcntl.h> |
Felipe Leme | ad5f6c4 | 2015-11-30 14:26:46 -0800 | [diff] [blame] | 20 | #include <libgen.h> |
Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 21 | #include <limits.h> |
Felipe Leme | 6e01fa6 | 2015-11-11 19:35:14 -0800 | [diff] [blame] | 22 | #include <memory> |
Felipe Leme | ad5f6c4 | 2015-11-30 14:26:46 -0800 | [diff] [blame] | 23 | #include <regex> |
Mark Salyzyn | 8f37aa5 | 2015-06-12 12:28:24 -0700 | [diff] [blame] | 24 | #include <stdbool.h> |
Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 25 | #include <stdio.h> |
| 26 | #include <stdlib.h> |
Felipe Leme | 6e01fa6 | 2015-11-11 19:35:14 -0800 | [diff] [blame] | 27 | #include <string> |
Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 28 | #include <string.h> |
Christopher Ferris | 7dc7f32 | 2014-07-22 16:08:19 -0700 | [diff] [blame] | 29 | #include <sys/capability.h> |
| 30 | #include <sys/prctl.h> |
Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 31 | #include <sys/resource.h> |
| 32 | #include <sys/stat.h> |
| 33 | #include <sys/time.h> |
| 34 | #include <sys/wait.h> |
| 35 | #include <unistd.h> |
Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 36 | |
Elliott Hughes | 9dc117c | 2015-12-07 14:21:50 -0800 | [diff] [blame] | 37 | #include <android-base/stringprintf.h> |
Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 38 | #include <cutils/properties.h> |
| 39 | |
| 40 | #include "private/android_filesystem_config.h" |
| 41 | |
| 42 | #define LOG_TAG "dumpstate" |
Alex Ray | 656a6b9 | 2013-07-23 13:44:34 -0700 | [diff] [blame] | 43 | #include <cutils/log.h> |
Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 44 | |
| 45 | #include "dumpstate.h" |
Felipe Leme | 6e01fa6 | 2015-11-11 19:35:14 -0800 | [diff] [blame] | 46 | #include "ScopedFd.h" |
| 47 | #include "ziparchive/zip_writer.h" |
| 48 | |
| 49 | using android::base::StringPrintf; |
Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 50 | |
| 51 | /* read before root is shed */ |
| 52 | static char cmdline_buf[16384] = "(unknown)"; |
| 53 | static const char *dump_traces_path = NULL; |
| 54 | |
Todd Poynor | 2a83daa | 2013-11-22 15:44:22 -0800 | [diff] [blame] | 55 | #define PSTORE_LAST_KMSG "/sys/fs/pstore/console-ramoops" |
| 56 | |
Sharvil Nanavati | 8d4cb7f | 2015-07-24 02:01:13 -0700 | [diff] [blame] | 57 | #define RAFT_DIR "/data/misc/raft/" |
Christopher Ferris | 7dc7f32 | 2014-07-22 16:08:19 -0700 | [diff] [blame] | 58 | #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 | |
| 64 | typedef struct { |
| 65 | char name[TOMBSTONE_MAX_LEN]; |
| 66 | int fd; |
| 67 | } tombstone_data_t; |
| 68 | |
| 69 | static tombstone_data_t tombstone_data[NUM_TOMBSTONES]; |
| 70 | |
| 71 | /* Get the fds of any tombstone that was modified in the last half an hour. */ |
| 72 | static 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 Ferris | 54bcc5f | 2015-02-10 12:15:01 -0800 | [diff] [blame] | 76 | int fd = TEMP_FAILURE_RETRY(open(data[i].name, |
| 77 | O_RDONLY | O_CLOEXEC | O_NOFOLLOW | O_NONBLOCK)); |
Christopher Ferris | 7dc7f32 | 2014-07-22 16:08:19 -0700 | [diff] [blame] | 78 | 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åg | 2db0f5f | 2014-10-15 18:08:37 -0700 | [diff] [blame] | 89 | static 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 Salyzyn | 326842f | 2015-04-30 09:49:41 -0700 | [diff] [blame] | 111 | static 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 | |
| 120 | static const char mmcblk0[] = "/sys/block/mmcblk0/"; |
Mark Salyzyn | 8f37aa5 | 2015-06-12 12:28:24 -0700 | [diff] [blame] | 121 | unsigned long worst_write_perf = 20000; /* in KB/s */ |
Mark Salyzyn | 326842f | 2015-04-30 09:49:41 -0700 | [diff] [blame] | 122 | |
| 123 | static 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 Salyzyn | 8f37aa5 | 2015-06-12 12:28:24 -0700 | [diff] [blame] | 170 | if ((write_perf > 1) && (write_perf < worst_write_perf)) { |
| 171 | worst_write_perf = write_perf; |
| 172 | } |
Mark Salyzyn | 326842f | 2015-04-30 09:49:41 -0700 | [diff] [blame] | 173 | return 0; |
| 174 | } |
| 175 | |
Mark Salyzyn | 8f37aa5 | 2015-06-12 12:28:24 -0700 | [diff] [blame] | 176 | /* 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 | |
| 182 | static 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 | |
| 208 | static 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 Leme | 8620bb4 | 2015-11-10 11:04:45 -0800 | [diff] [blame] | 239 | static unsigned long logcat_timeout(const char *name) { |
Mark Salyzyn | 8f37aa5 | 2015-06-12 12:28:24 -0700 | [diff] [blame] | 240 | 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 Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 272 | /* dumps the current system state to stdout */ |
Felipe Leme | 3634a1e | 2015-12-09 10:11:47 -0800 | [diff] [blame] | 273 | static void dumpstate(const std::string& screenshot_path) { |
Mark Salyzyn | 8f37aa5 | 2015-06-12 12:28:24 -0700 | [diff] [blame] | 274 | unsigned long timeout; |
Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 275 | 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åg | 2db0f5f | 2014-10-15 18:08:37 -0700 | [diff] [blame] | 305 | dump_dev_files("TRUSTY VERSION", "/sys/bus/platform/drivers/trusty", "trusty_version"); |
Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 306 | run_command("UPTIME", 10, "uptime", NULL); |
Mark Salyzyn | 326842f | 2015-04-30 09:49:41 -0700 | [diff] [blame] | 307 | dump_files("UPTIME MMC PERF", mmcblk0, skip_not_stat, dump_stat_from_fd); |
Mark Salyzyn | 8c8130e | 2015-12-09 11:21:28 -0800 | [diff] [blame] | 308 | dump_emmc_ecsd("/d/mmc0/mmc0:0001/ext_csd"); |
Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 309 | dump_file("MEMORY INFO", "/proc/meminfo"); |
Elliott Hughes | b32c7e1 | 2015-11-13 11:32:48 -0800 | [diff] [blame] | 310 | run_command("CPU INFO", 10, "top", "-n", "1", "-d", "1", "-m", "30", "-H", NULL); |
Nick Kralevich | 2b1f88b | 2015-10-07 16:38:42 -0700 | [diff] [blame] | 311 | run_command("PROCRANK", 20, SU_PATH, "root", "procrank", NULL); |
Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 312 | dump_file("VIRTUAL MEMORY STATS", "/proc/vmstat"); |
| 313 | dump_file("VMALLOC INFO", "/proc/vmallocinfo"); |
| 314 | dump_file("SLAB INFO", "/proc/slabinfo"); |
| 315 | dump_file("ZONEINFO", "/proc/zoneinfo"); |
| 316 | dump_file("PAGETYPEINFO", "/proc/pagetypeinfo"); |
| 317 | dump_file("BUDDYINFO", "/proc/buddyinfo"); |
Colin Cross | 2281af9 | 2012-10-28 22:41:06 -0700 | [diff] [blame] | 318 | dump_file("FRAGMENTATION INFO", "/d/extfrag/unusable_index"); |
Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 319 | |
Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 320 | dump_file("KERNEL WAKELOCKS", "/proc/wakelocks"); |
Todd Poynor | 29e27a8 | 2012-05-22 17:54:59 -0700 | [diff] [blame] | 321 | dump_file("KERNEL WAKE SOURCES", "/d/wakeup_sources"); |
Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 322 | dump_file("KERNEL CPUFREQ", "/sys/devices/system/cpu/cpu0/cpufreq/stats/time_in_state"); |
Mathias Agopian | 85aea74 | 2012-08-08 15:32:02 -0700 | [diff] [blame] | 323 | dump_file("KERNEL SYNC", "/d/sync"); |
Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 324 | |
Elliott Hughes | a3533a3 | 2015-10-30 16:17:49 -0700 | [diff] [blame] | 325 | run_command("PROCESSES AND THREADS", 10, "ps", "-Z", "-t", "-p", "-P", NULL); |
Nick Kralevich | b82c925 | 2015-11-27 17:56:13 -0800 | [diff] [blame] | 326 | run_command("LIBRANK", 10, SU_PATH, "root", "librank", NULL); |
Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 327 | |
| 328 | do_dmesg(); |
| 329 | |
| 330 | run_command("LIST OF OPEN FILES", 10, SU_PATH, "root", "lsof", NULL); |
Jeff Brown | 1dc94e3 | 2014-09-11 14:15:27 -0700 | [diff] [blame] | 331 | for_each_pid(do_showmap, "SMAPS OF ALL PROCESSES"); |
| 332 | for_each_tid(show_wchan, "BLOCKED PROCESS WAIT-CHANNELS"); |
Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 333 | |
Felipe Leme | 6e01fa6 | 2015-11-11 19:35:14 -0800 | [diff] [blame] | 334 | if (!screenshot_path.empty()) { |
Felipe Leme | e338bf6 | 2015-12-07 14:03:50 -0800 | [diff] [blame] | 335 | ALOGI("taking late screenshot\n"); |
| 336 | take_screenshot(screenshot_path); |
Felipe Leme | 6e01fa6 | 2015-11-11 19:35:14 -0800 | [diff] [blame] | 337 | ALOGI("wrote screenshot: %s\n", screenshot_path.c_str()); |
Jeff Sharkey | 5a93003 | 2013-03-19 15:05:19 -0700 | [diff] [blame] | 338 | } |
| 339 | |
Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 340 | // dump_file("EVENT LOG TAGS", "/etc/event-log-tags"); |
Mark Salyzyn | 8f37aa5 | 2015-06-12 12:28:24 -0700 | [diff] [blame] | 341 | // calculate timeout |
| 342 | timeout = logcat_timeout("main") + logcat_timeout("system") + logcat_timeout("crash"); |
| 343 | if (timeout < 20000) { |
| 344 | timeout = 20000; |
| 345 | } |
Mark Salyzyn | 7831638 | 2015-10-09 14:02:07 -0700 | [diff] [blame] | 346 | run_command("SYSTEM LOG", timeout / 1000, "logcat", "-v", "threadtime", |
| 347 | "-v", "printable", |
| 348 | "-d", |
| 349 | "*:v", NULL); |
Mark Salyzyn | c7ad8cb | 2015-12-11 13:04:02 -0800 | [diff] [blame] | 350 | timeout = logcat_timeout("events") + logcat_timeout("security"); |
Mark Salyzyn | 8f37aa5 | 2015-06-12 12:28:24 -0700 | [diff] [blame] | 351 | if (timeout < 20000) { |
| 352 | timeout = 20000; |
| 353 | } |
Mark Salyzyn | 7831638 | 2015-10-09 14:02:07 -0700 | [diff] [blame] | 354 | run_command("EVENT LOG", timeout / 1000, "logcat", "-b", "events", |
Mark Salyzyn | c7ad8cb | 2015-12-11 13:04:02 -0800 | [diff] [blame] | 355 | "-b", "security", |
Mark Salyzyn | 7831638 | 2015-10-09 14:02:07 -0700 | [diff] [blame] | 356 | "-v", "threadtime", |
| 357 | "-v", "printable", |
| 358 | "-d", |
| 359 | "*:v", NULL); |
Mark Salyzyn | 8f37aa5 | 2015-06-12 12:28:24 -0700 | [diff] [blame] | 360 | timeout = logcat_timeout("radio"); |
| 361 | if (timeout < 20000) { |
| 362 | timeout = 20000; |
| 363 | } |
Mark Salyzyn | 7831638 | 2015-10-09 14:02:07 -0700 | [diff] [blame] | 364 | run_command("RADIO LOG", timeout / 1000, "logcat", "-b", "radio", |
| 365 | "-v", "threadtime", |
| 366 | "-v", "printable", |
| 367 | "-d", |
| 368 | "*:v", NULL); |
Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 369 | |
Mark Salyzyn | ecc0763 | 2015-07-30 14:57:09 -0700 | [diff] [blame] | 370 | run_command("LOG STATISTICS", 10, "logcat", "-b", "all", "-S", NULL); |
| 371 | |
Sharvil Nanavati | 804339a | 2015-11-27 21:04:11 -0800 | [diff] [blame] | 372 | run_command("RAFT LOGS", 600, SU_PATH, "root", "logcompressor", "-r", RAFT_DIR, NULL); |
Sharvil Nanavati | 8d4cb7f | 2015-07-24 02:01:13 -0700 | [diff] [blame] | 373 | |
Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 374 | /* show the traces we collected in main(), if that was done */ |
| 375 | if (dump_traces_path != NULL) { |
| 376 | dump_file("VM TRACES JUST NOW", dump_traces_path); |
| 377 | } |
| 378 | |
| 379 | /* only show ANR traces if they're less than 15 minutes old */ |
| 380 | struct stat st; |
| 381 | char anr_traces_path[PATH_MAX]; |
| 382 | property_get("dalvik.vm.stack-trace-file", anr_traces_path, ""); |
| 383 | if (!anr_traces_path[0]) { |
| 384 | printf("*** NO VM TRACES FILE DEFINED (dalvik.vm.stack-trace-file)\n\n"); |
Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 385 | } else { |
Christopher Ferris | 54bcc5f | 2015-02-10 12:15:01 -0800 | [diff] [blame] | 386 | int fd = TEMP_FAILURE_RETRY(open(anr_traces_path, |
| 387 | O_RDONLY | O_CLOEXEC | O_NOFOLLOW | O_NONBLOCK)); |
Christopher Ferris | 7dc7f32 | 2014-07-22 16:08:19 -0700 | [diff] [blame] | 388 | if (fd < 0) { |
| 389 | printf("*** NO ANR VM TRACES FILE (%s): %s\n\n", anr_traces_path, strerror(errno)); |
| 390 | } else { |
| 391 | dump_file_from_fd("VM TRACES AT LAST ANR", anr_traces_path, fd); |
| 392 | } |
Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | /* slow traces for slow operations */ |
| 396 | if (anr_traces_path[0] != 0) { |
| 397 | int tail = strlen(anr_traces_path)-1; |
| 398 | while (tail > 0 && anr_traces_path[tail] != '/') { |
| 399 | tail--; |
| 400 | } |
| 401 | int i = 0; |
| 402 | while (1) { |
| 403 | sprintf(anr_traces_path+tail+1, "slow%02d.txt", i); |
| 404 | if (stat(anr_traces_path, &st)) { |
| 405 | // No traces file at this index, done with the files. |
| 406 | break; |
| 407 | } |
| 408 | dump_file("VM TRACES WHEN SLOW", anr_traces_path); |
| 409 | i++; |
| 410 | } |
| 411 | } |
| 412 | |
Christopher Ferris | 7dc7f32 | 2014-07-22 16:08:19 -0700 | [diff] [blame] | 413 | int dumped = 0; |
| 414 | for (size_t i = 0; i < NUM_TOMBSTONES; i++) { |
| 415 | if (tombstone_data[i].fd != -1) { |
| 416 | dumped = 1; |
| 417 | dump_file_from_fd("TOMBSTONE", tombstone_data[i].name, tombstone_data[i].fd); |
| 418 | tombstone_data[i].fd = -1; |
| 419 | } |
| 420 | } |
| 421 | if (!dumped) { |
| 422 | printf("*** NO TOMBSTONES to dump in %s\n\n", TOMBSTONE_DIR); |
| 423 | } |
| 424 | |
Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 425 | dump_file("NETWORK DEV INFO", "/proc/net/dev"); |
| 426 | dump_file("QTAGUID NETWORK INTERFACES INFO", "/proc/net/xt_qtaguid/iface_stat_all"); |
JP Abgrall | 012c2ea | 2012-05-16 20:49:29 -0700 | [diff] [blame] | 427 | dump_file("QTAGUID NETWORK INTERFACES INFO (xt)", "/proc/net/xt_qtaguid/iface_stat_fmt"); |
Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 428 | dump_file("QTAGUID CTRL INFO", "/proc/net/xt_qtaguid/ctrl"); |
| 429 | dump_file("QTAGUID STATS INFO", "/proc/net/xt_qtaguid/stats"); |
| 430 | |
Todd Poynor | 2a83daa | 2013-11-22 15:44:22 -0800 | [diff] [blame] | 431 | if (!stat(PSTORE_LAST_KMSG, &st)) { |
| 432 | /* Also TODO: Make console-ramoops CAP_SYSLOG protected. */ |
| 433 | dump_file("LAST KMSG", PSTORE_LAST_KMSG); |
| 434 | } else { |
| 435 | /* TODO: Make last_kmsg CAP_SYSLOG protected. b/5555691 */ |
| 436 | dump_file("LAST KMSG", "/proc/last_kmsg"); |
| 437 | } |
| 438 | |
Mark Salyzyn | 2262c16 | 2014-12-16 09:09:26 -0800 | [diff] [blame] | 439 | /* kernels must set CONFIG_PSTORE_PMSG, slice up pstore with device tree */ |
Mark Salyzyn | 7831638 | 2015-10-09 14:02:07 -0700 | [diff] [blame] | 440 | run_command("LAST LOGCAT", 10, "logcat", "-L", |
| 441 | "-b", "all", |
| 442 | "-v", "threadtime", |
| 443 | "-v", "printable", |
| 444 | "-d", |
| 445 | "*:v", NULL); |
Mark Salyzyn | 2262c16 | 2014-12-16 09:09:26 -0800 | [diff] [blame] | 446 | |
Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 447 | /* The following have a tendency to get wedged when wifi drivers/fw goes belly-up. */ |
Elliott Hughes | a59828a | 2015-01-27 20:48:52 -0800 | [diff] [blame] | 448 | |
| 449 | run_command("NETWORK INTERFACES", 10, "ip", "link", NULL); |
Lorenzo Colitti | d4c3d38 | 2014-07-30 14:38:20 +0900 | [diff] [blame] | 450 | |
| 451 | run_command("IPv4 ADDRESSES", 10, "ip", "-4", "addr", "show", NULL); |
| 452 | run_command("IPv6 ADDRESSES", 10, "ip", "-6", "addr", "show", NULL); |
| 453 | |
Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 454 | run_command("IP RULES", 10, "ip", "rule", "show", NULL); |
| 455 | run_command("IP RULES v6", 10, "ip", "-6", "rule", "show", NULL); |
Sreeram Ramachandran | 2b3bba3 | 2014-07-08 15:40:55 -0700 | [diff] [blame] | 456 | |
| 457 | dump_route_tables(); |
| 458 | |
Lorenzo Colitti | d4c3d38 | 2014-07-30 14:38:20 +0900 | [diff] [blame] | 459 | run_command("ARP CACHE", 10, "ip", "-4", "neigh", "show", NULL); |
| 460 | run_command("IPv6 ND CACHE", 10, "ip", "-6", "neigh", "show", NULL); |
| 461 | |
Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 462 | run_command("IPTABLES", 10, SU_PATH, "root", "iptables", "-L", "-nvx", NULL); |
| 463 | run_command("IP6TABLES", 10, SU_PATH, "root", "ip6tables", "-L", "-nvx", NULL); |
JP Abgrall | 012c2ea | 2012-05-16 20:49:29 -0700 | [diff] [blame] | 464 | run_command("IPTABLE NAT", 10, SU_PATH, "root", "iptables", "-t", "nat", "-L", "-nvx", NULL); |
| 465 | /* no ip6 nat */ |
| 466 | run_command("IPTABLE RAW", 10, SU_PATH, "root", "iptables", "-t", "raw", "-L", "-nvx", NULL); |
| 467 | run_command("IP6TABLE RAW", 10, SU_PATH, "root", "ip6tables", "-t", "raw", "-L", "-nvx", NULL); |
Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 468 | |
| 469 | run_command("WIFI NETWORKS", 20, |
Dmitry Shmidt | 1d6b97c | 2013-08-21 10:58:29 -0700 | [diff] [blame] | 470 | SU_PATH, "root", "wpa_cli", "IFNAME=wlan0", "list_networks", NULL); |
Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 471 | |
Dmitry Shmidt | c11f56e | 2012-11-07 10:42:05 -0800 | [diff] [blame] | 472 | #ifdef FWDUMP_bcmdhd |
Lorenzo Colitti | 6afc38c | 2015-09-09 22:59:25 +0900 | [diff] [blame] | 473 | run_command("ND OFFLOAD TABLE", 5, |
| 474 | SU_PATH, "root", "wlutil", "nd_hostip", NULL); |
| 475 | |
| 476 | run_command("DUMP WIFI INTERNAL COUNTERS (1)", 20, |
Dmitry Shmidt | c11f56e | 2012-11-07 10:42:05 -0800 | [diff] [blame] | 477 | SU_PATH, "root", "wlutil", "counters", NULL); |
Lorenzo Colitti | 6afc38c | 2015-09-09 22:59:25 +0900 | [diff] [blame] | 478 | |
| 479 | run_command("ND OFFLOAD STATUS (1)", 5, |
| 480 | SU_PATH, "root", "wlutil", "nd_status", NULL); |
| 481 | |
Dmitry Shmidt | c11f56e | 2012-11-07 10:42:05 -0800 | [diff] [blame] | 482 | #endif |
Dmitry Shmidt | 0b2c926 | 2012-11-07 11:09:46 -0800 | [diff] [blame] | 483 | dump_file("INTERRUPTS (1)", "/proc/interrupts"); |
| 484 | |
Lorenzo Colitti | 6afc38c | 2015-09-09 22:59:25 +0900 | [diff] [blame] | 485 | run_command("NETWORK DIAGNOSTICS", 10, "dumpsys", "connectivity", "--diag", NULL); |
| 486 | |
Dmitry Shmidt | c11f56e | 2012-11-07 10:42:05 -0800 | [diff] [blame] | 487 | #ifdef FWDUMP_bcmdhd |
Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 488 | run_command("DUMP WIFI STATUS", 20, |
| 489 | SU_PATH, "root", "dhdutil", "-i", "wlan0", "dump", NULL); |
Lorenzo Colitti | 6afc38c | 2015-09-09 22:59:25 +0900 | [diff] [blame] | 490 | |
| 491 | run_command("DUMP WIFI INTERNAL COUNTERS (2)", 20, |
Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 492 | SU_PATH, "root", "wlutil", "counters", NULL); |
Lorenzo Colitti | 6afc38c | 2015-09-09 22:59:25 +0900 | [diff] [blame] | 493 | |
| 494 | run_command("ND OFFLOAD STATUS (2)", 5, |
| 495 | SU_PATH, "root", "wlutil", "nd_status", NULL); |
Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 496 | #endif |
Dmitry Shmidt | 0b2c926 | 2012-11-07 11:09:46 -0800 | [diff] [blame] | 497 | dump_file("INTERRUPTS (2)", "/proc/interrupts"); |
Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 498 | |
| 499 | print_properties(); |
| 500 | |
| 501 | run_command("VOLD DUMP", 10, "vdc", "dump", NULL); |
| 502 | run_command("SECURE CONTAINERS", 10, "vdc", "asec", "list", NULL); |
| 503 | |
Ken Sumrall | 8f75fa7 | 2013-02-08 17:35:58 -0800 | [diff] [blame] | 504 | run_command("FILESYSTEMS & FREE SPACE", 10, "df", NULL); |
Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 505 | |
Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 506 | run_command("LAST RADIO LOG", 10, "parse_radio_log", "/proc/last_radio_log", NULL); |
| 507 | |
| 508 | printf("------ BACKLIGHTS ------\n"); |
| 509 | printf("LCD brightness="); |
| 510 | dump_file(NULL, "/sys/class/leds/lcd-backlight/brightness"); |
| 511 | printf("Button brightness="); |
| 512 | dump_file(NULL, "/sys/class/leds/button-backlight/brightness"); |
| 513 | printf("Keyboard brightness="); |
| 514 | dump_file(NULL, "/sys/class/leds/keyboard-backlight/brightness"); |
| 515 | printf("ALS mode="); |
| 516 | dump_file(NULL, "/sys/class/leds/lcd-backlight/als"); |
| 517 | printf("LCD driver registers:\n"); |
| 518 | dump_file(NULL, "/sys/class/leds/lcd-backlight/registers"); |
| 519 | printf("\n"); |
| 520 | |
| 521 | /* Binder state is expensive to look at as it uses a lot of memory. */ |
| 522 | dump_file("BINDER FAILED TRANSACTION LOG", "/sys/kernel/debug/binder/failed_transaction_log"); |
| 523 | dump_file("BINDER TRANSACTION LOG", "/sys/kernel/debug/binder/transaction_log"); |
| 524 | dump_file("BINDER TRANSACTIONS", "/sys/kernel/debug/binder/transactions"); |
| 525 | dump_file("BINDER STATS", "/sys/kernel/debug/binder/stats"); |
| 526 | dump_file("BINDER STATE", "/sys/kernel/debug/binder/state"); |
| 527 | |
Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 528 | printf("========================================================\n"); |
| 529 | printf("== Board\n"); |
| 530 | printf("========================================================\n"); |
| 531 | |
| 532 | dumpstate_board(); |
| 533 | printf("\n"); |
Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 534 | |
| 535 | /* Migrate the ril_dumpstate to a dumpstate_board()? */ |
| 536 | char ril_dumpstate_timeout[PROPERTY_VALUE_MAX] = {0}; |
| 537 | property_get("ril.dumpstate.timeout", ril_dumpstate_timeout, "30"); |
| 538 | if (strnlen(ril_dumpstate_timeout, PROPERTY_VALUE_MAX - 1) > 0) { |
| 539 | if (0 == strncmp(build_type, "user", PROPERTY_VALUE_MAX - 1)) { |
| 540 | // su does not exist on user builds, so try running without it. |
| 541 | // This way any implementations of vril-dump that do not require |
| 542 | // root can run on user builds. |
| 543 | run_command("DUMP VENDOR RIL LOGS", atoi(ril_dumpstate_timeout), |
| 544 | "vril-dump", NULL); |
| 545 | } else { |
| 546 | run_command("DUMP VENDOR RIL LOGS", atoi(ril_dumpstate_timeout), |
| 547 | SU_PATH, "root", "vril-dump", NULL); |
| 548 | } |
| 549 | } |
| 550 | |
| 551 | printf("========================================================\n"); |
| 552 | printf("== Android Framework Services\n"); |
| 553 | printf("========================================================\n"); |
| 554 | |
| 555 | /* the full dumpsys is starting to take a long time, so we need |
| 556 | to increase its timeout. we really need to do the timeouts in |
| 557 | dumpsys itself... */ |
| 558 | run_command("DUMPSYS", 60, "dumpsys", NULL); |
| 559 | |
| 560 | printf("========================================================\n"); |
Dianne Hackborn | 02bea97 | 2013-06-26 18:59:09 -0700 | [diff] [blame] | 561 | printf("== Checkins\n"); |
| 562 | printf("========================================================\n"); |
| 563 | |
Dianne Hackborn | 59b1516 | 2013-09-04 18:04:14 -0700 | [diff] [blame] | 564 | run_command("CHECKIN BATTERYSTATS", 30, "dumpsys", "batterystats", "-c", NULL); |
Dianne Hackborn | 3e5fa73 | 2013-07-03 16:51:15 -0700 | [diff] [blame] | 565 | run_command("CHECKIN MEMINFO", 30, "dumpsys", "meminfo", "--checkin", NULL); |
Dianne Hackborn | 02bea97 | 2013-06-26 18:59:09 -0700 | [diff] [blame] | 566 | run_command("CHECKIN NETSTATS", 30, "dumpsys", "netstats", "--checkin", NULL); |
Dianne Hackborn | 5cd46aa | 2013-07-09 15:01:40 -0700 | [diff] [blame] | 567 | run_command("CHECKIN PROCSTATS", 30, "dumpsys", "procstats", "-c", NULL); |
Dianne Hackborn | 1bd5068 | 2013-07-11 11:45:18 -0700 | [diff] [blame] | 568 | run_command("CHECKIN USAGESTATS", 30, "dumpsys", "usagestats", "-c", NULL); |
Ashish Sharma | 8b3e133 | 2015-04-28 13:32:54 -0700 | [diff] [blame] | 569 | run_command("CHECKIN PACKAGE", 30, "dumpsys", "package", "--checkin", NULL); |
Dianne Hackborn | 02bea97 | 2013-06-26 18:59:09 -0700 | [diff] [blame] | 570 | |
| 571 | printf("========================================================\n"); |
Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 572 | printf("== Running Application Activities\n"); |
| 573 | printf("========================================================\n"); |
| 574 | |
| 575 | run_command("APP ACTIVITIES", 30, "dumpsys", "activity", "all", NULL); |
| 576 | |
| 577 | printf("========================================================\n"); |
| 578 | printf("== Running Application Services\n"); |
| 579 | printf("========================================================\n"); |
| 580 | |
| 581 | run_command("APP SERVICES", 30, "dumpsys", "activity", "service", "all", NULL); |
| 582 | |
| 583 | printf("========================================================\n"); |
| 584 | printf("== Running Application Providers\n"); |
| 585 | printf("========================================================\n"); |
| 586 | |
| 587 | run_command("APP SERVICES", 30, "dumpsys", "activity", "provider", "all", NULL); |
| 588 | |
| 589 | |
| 590 | printf("========================================================\n"); |
| 591 | printf("== dumpstate: done\n"); |
| 592 | printf("========================================================\n"); |
| 593 | } |
| 594 | |
| 595 | static void usage() { |
John Michelau | 1f794c4 | 2012-09-17 11:20:19 -0500 | [diff] [blame] | 596 | fprintf(stderr, "usage: dumpstate [-b soundfile] [-e soundfile] [-o file [-d] [-p] [-z]] [-s] [-q]\n" |
Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 597 | " -o: write to file (instead of stdout)\n" |
| 598 | " -d: append date to filename (requires -o)\n" |
Felipe Leme | 6e01fa6 | 2015-11-11 19:35:14 -0800 | [diff] [blame] | 599 | " -z: generates zipped file (requires -o)\n" |
Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 600 | " -p: capture screenshot to filename.png (requires -o)\n" |
| 601 | " -s: write output to control socket (for init)\n" |
| 602 | " -b: play sound file instead of vibrate, at beginning of job\n" |
| 603 | " -e: play sound file instead of vibrate, at end of job\n" |
John Michelau | 1f794c4 | 2012-09-17 11:20:19 -0500 | [diff] [blame] | 604 | " -q: disable vibrate\n" |
Felipe Leme | 36b3f6f | 2015-11-19 15:41:04 -0800 | [diff] [blame] | 605 | " -B: send broadcast when finished (requires -o)\n" |
Felipe Leme | 71bbfc5 | 2015-11-23 14:14:51 -0800 | [diff] [blame] | 606 | " -P: send broadacast when started and update system properties on progress (requires -o and -B)\n" |
Todd Poynor | 2a83daa | 2013-11-22 15:44:22 -0800 | [diff] [blame] | 607 | ); |
Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 608 | } |
| 609 | |
John Michelau | 885f888 | 2013-05-06 16:42:02 -0500 | [diff] [blame] | 610 | static void sigpipe_handler(int n) { |
Andres Morales | 2e671bb | 2014-08-21 12:38:22 -0700 | [diff] [blame] | 611 | // don't complain to stderr or stdout |
| 612 | _exit(EXIT_FAILURE); |
John Michelau | 885f888 | 2013-05-06 16:42:02 -0500 | [diff] [blame] | 613 | } |
| 614 | |
Jeff Brown | 1dc94e3 | 2014-09-11 14:15:27 -0700 | [diff] [blame] | 615 | static void vibrate(FILE* vibrator, int ms) { |
| 616 | fprintf(vibrator, "%d\n", ms); |
| 617 | fflush(vibrator); |
| 618 | } |
| 619 | |
Felipe Leme | 6e01fa6 | 2015-11-11 19:35:14 -0800 | [diff] [blame] | 620 | /* generates a zipfile on 'path' with an entry with the contents of 'tmp_path' |
| 621 | and removes the temporary file. |
| 622 | */ |
| 623 | static bool generate_zip_file(std::string tmp_path, std::string path, |
| 624 | std::string entry_name, time_t entry_time) { |
| 625 | std::unique_ptr<FILE, int(*)(FILE*)> file(fopen(path.c_str(), "wb"), fclose); |
| 626 | if (!file) { |
| 627 | ALOGE("fopen(%s, 'wb'): %s\n", path.c_str(), strerror(errno)); |
| 628 | return false; |
| 629 | } |
| 630 | |
| 631 | ZipWriter writer(file.get()); |
| 632 | int32_t err = writer.StartEntryWithTime(entry_name.c_str(), ZipWriter::kCompress, entry_time); |
| 633 | if (err) { |
| 634 | ALOGE("writer.StartEntryWithTime(%s): %s\n", entry_name.c_str(), ZipWriter::ErrorCodeString(err)); |
| 635 | return false; |
| 636 | } |
| 637 | |
| 638 | ScopedFd fd(TEMP_FAILURE_RETRY(open(tmp_path.c_str(), O_RDONLY | O_NONBLOCK | O_CLOEXEC))); |
| 639 | if (fd.get() == -1) { |
| 640 | ALOGE("open(%s): %s\n", tmp_path.c_str(), strerror(errno)); |
| 641 | return false; |
| 642 | } |
| 643 | |
| 644 | while (1) { |
| 645 | std::vector<uint8_t> buffer(65536); |
| 646 | ssize_t bytes_read = TEMP_FAILURE_RETRY(read(fd.get(), buffer.data(), sizeof(buffer))); |
| 647 | if (bytes_read == 0) { |
| 648 | break; |
| 649 | } else if (bytes_read == -1) { |
| 650 | ALOGE("read(%s): %s\n", tmp_path.c_str(), strerror(errno)); |
| 651 | return false; |
| 652 | } |
| 653 | err = writer.WriteBytes(buffer.data(), bytes_read); |
| 654 | if (err) { |
| 655 | ALOGE("writer.WriteBytes(): %s\n", ZipWriter::ErrorCodeString(err)); |
| 656 | return false; |
| 657 | } |
| 658 | } |
| 659 | |
| 660 | err = writer.FinishEntry(); |
| 661 | if (err) { |
| 662 | ALOGE("writer.FinishEntry(): %s\n", ZipWriter::ErrorCodeString(err)); |
| 663 | return false; |
| 664 | } |
| 665 | |
| 666 | err = writer.Finish(); |
| 667 | if (err) { |
| 668 | ALOGE("writer.Finish(): %s\n", ZipWriter::ErrorCodeString(err)); |
| 669 | return false; |
| 670 | } |
| 671 | |
| 672 | if (remove(tmp_path.c_str())) { |
| 673 | ALOGE("remove(%s): %s\n", tmp_path.c_str(), strerror(errno)); |
| 674 | return false; |
| 675 | } |
| 676 | |
| 677 | return true; |
| 678 | } |
| 679 | |
| 680 | |
Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 681 | int main(int argc, char *argv[]) { |
John Michelau | 885f888 | 2013-05-06 16:42:02 -0500 | [diff] [blame] | 682 | struct sigaction sigact; |
Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 683 | int do_add_date = 0; |
Felipe Leme | 6e01fa6 | 2015-11-11 19:35:14 -0800 | [diff] [blame] | 684 | int do_zip_file = 0; |
John Michelau | 1f794c4 | 2012-09-17 11:20:19 -0500 | [diff] [blame] | 685 | int do_vibrate = 1; |
Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 686 | char* use_outfile = 0; |
Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 687 | int use_socket = 0; |
| 688 | int do_fb = 0; |
Jeff Sharkey | 27f9e6d | 2013-03-13 15:45:50 -0700 | [diff] [blame] | 689 | int do_broadcast = 0; |
Felipe Leme | e338bf6 | 2015-12-07 14:03:50 -0800 | [diff] [blame] | 690 | int do_early_screenshot = 0; |
Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 691 | |
Nick Kralevich | 1e33987 | 2012-04-25 13:38:45 -0700 | [diff] [blame] | 692 | if (getuid() != 0) { |
| 693 | // Old versions of the adb client would call the |
| 694 | // dumpstate command directly. Newer clients |
| 695 | // call /system/bin/bugreport instead. If we detect |
| 696 | // we're being called incorrectly, then exec the |
| 697 | // correct program. |
| 698 | return execl("/system/bin/bugreport", "/system/bin/bugreport", NULL); |
| 699 | } |
Jeff Brown | 1dc94e3 | 2014-09-11 14:15:27 -0700 | [diff] [blame] | 700 | |
Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 701 | ALOGI("begin\n"); |
| 702 | |
Jeff Brown | 1dc94e3 | 2014-09-11 14:15:27 -0700 | [diff] [blame] | 703 | /* clear SIGPIPE handler */ |
John Michelau | 885f888 | 2013-05-06 16:42:02 -0500 | [diff] [blame] | 704 | memset(&sigact, 0, sizeof(sigact)); |
| 705 | sigact.sa_handler = sigpipe_handler; |
| 706 | sigaction(SIGPIPE, &sigact, NULL); |
JP Abgrall | 3e03d3f | 2012-05-11 14:14:09 -0700 | [diff] [blame] | 707 | |
Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 708 | /* set as high priority, and protect from OOM killer */ |
| 709 | setpriority(PRIO_PROCESS, 0, -20); |
Nick Kralevich | cd67e9f | 2015-03-19 11:30:59 -0700 | [diff] [blame] | 710 | FILE *oom_adj = fopen("/proc/self/oom_adj", "we"); |
Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 711 | if (oom_adj) { |
| 712 | fputs("-17", oom_adj); |
| 713 | fclose(oom_adj); |
| 714 | } |
| 715 | |
Jeff Brown | 1dc94e3 | 2014-09-11 14:15:27 -0700 | [diff] [blame] | 716 | /* parse arguments */ |
Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 717 | int c; |
Felipe Leme | 71bbfc5 | 2015-11-23 14:14:51 -0800 | [diff] [blame] | 718 | while ((c = getopt(argc, argv, "dho:svqzpPB")) != -1) { |
Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 719 | switch (c) { |
Felipe Leme | 71bbfc5 | 2015-11-23 14:14:51 -0800 | [diff] [blame] | 720 | case 'd': do_add_date = 1; break; |
| 721 | case 'z': do_zip_file = 1; break; |
| 722 | case 'o': use_outfile = optarg; break; |
| 723 | case 's': use_socket = 1; break; |
Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 724 | case 'v': break; // compatibility no-op |
Felipe Leme | 71bbfc5 | 2015-11-23 14:14:51 -0800 | [diff] [blame] | 725 | case 'q': do_vibrate = 0; break; |
| 726 | case 'p': do_fb = 1; break; |
| 727 | case 'P': do_update_progress = 1; break; |
| 728 | case 'B': do_broadcast = 1; break; |
Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 729 | case '?': printf("\n"); |
| 730 | case 'h': |
| 731 | usage(); |
| 732 | exit(1); |
| 733 | } |
| 734 | } |
| 735 | |
Felipe Leme | 71bbfc5 | 2015-11-23 14:14:51 -0800 | [diff] [blame] | 736 | if ((do_zip_file || do_add_date || do_update_progress || do_broadcast) && !use_outfile) { |
Felipe Leme | 6e01fa6 | 2015-11-11 19:35:14 -0800 | [diff] [blame] | 737 | usage(); |
| 738 | exit(1); |
| 739 | } |
| 740 | |
Felipe Leme | 71bbfc5 | 2015-11-23 14:14:51 -0800 | [diff] [blame] | 741 | if (do_update_progress && !do_broadcast) { |
| 742 | usage(); |
| 743 | exit(1); |
| 744 | } |
Felipe Leme | 6e01fa6 | 2015-11-11 19:35:14 -0800 | [diff] [blame] | 745 | |
Felipe Leme | e338bf6 | 2015-12-07 14:03:50 -0800 | [diff] [blame] | 746 | do_early_screenshot = do_update_progress; |
| 747 | |
Christopher Ferris | ed9354f | 2014-10-01 17:35:01 -0700 | [diff] [blame] | 748 | // If we are going to use a socket, do it as early as possible |
| 749 | // to avoid timeouts from bugreport. |
| 750 | if (use_socket) { |
| 751 | redirect_to_socket(stdout, "dumpstate"); |
| 752 | } |
| 753 | |
Felipe Leme | ad5f6c4 | 2015-11-30 14:26:46 -0800 | [diff] [blame] | 754 | /* full path of the directory where the bug report files will be written */ |
| 755 | std::string bugreport_dir; |
| 756 | |
| 757 | /* full path of the temporary file containing the bug report */ |
| 758 | std::string tmp_path; |
| 759 | |
Felipe Leme | e338bf6 | 2015-12-07 14:03:50 -0800 | [diff] [blame] | 760 | /* full path of the temporary file containing the screenshot (when requested) */ |
| 761 | std::string screenshot_path; |
| 762 | |
Felipe Leme | ad5f6c4 | 2015-11-30 14:26:46 -0800 | [diff] [blame] | 763 | /* base name (without suffix or extensions) of the bug report files */ |
| 764 | std::string base_name; |
| 765 | |
| 766 | /* suffix of the bug report files - it's typically the date (when invoked with -d), |
| 767 | * although it could be changed by the user using a system property */ |
| 768 | std::string suffix; |
Felipe Leme | 71bbfc5 | 2015-11-23 14:14:51 -0800 | [diff] [blame] | 769 | |
| 770 | /* pointer to the actual path, be it zip or text */ |
| 771 | std::string path; |
| 772 | |
| 773 | time_t now = time(NULL); |
| 774 | |
Felipe Leme | ad5f6c4 | 2015-11-30 14:26:46 -0800 | [diff] [blame] | 775 | /* redirect output if needed */ |
Felipe Leme | 71bbfc5 | 2015-11-23 14:14:51 -0800 | [diff] [blame] | 776 | bool is_redirecting = !use_socket && use_outfile; |
| 777 | |
| 778 | if (is_redirecting) { |
Felipe Leme | ad5f6c4 | 2015-11-30 14:26:46 -0800 | [diff] [blame] | 779 | bugreport_dir = dirname(use_outfile); |
| 780 | base_name = basename(use_outfile); |
Felipe Leme | 71bbfc5 | 2015-11-23 14:14:51 -0800 | [diff] [blame] | 781 | if (do_add_date) { |
| 782 | char date[80]; |
Felipe Leme | ad5f6c4 | 2015-11-30 14:26:46 -0800 | [diff] [blame] | 783 | strftime(date, sizeof(date), "%Y-%m-%d-%H-%M-%S", localtime(&now)); |
| 784 | suffix = date; |
| 785 | } else { |
| 786 | suffix = "undated"; |
Felipe Leme | 71bbfc5 | 2015-11-23 14:14:51 -0800 | [diff] [blame] | 787 | } |
| 788 | if (do_fb) { |
Felipe Leme | ad5f6c4 | 2015-11-30 14:26:46 -0800 | [diff] [blame] | 789 | // TODO: if dumpstate was an object, the paths could be internal variables and then |
| 790 | // we could have a function to calculate the derived values, such as: |
| 791 | // screenshot_path = GetPath(".png"); |
| 792 | screenshot_path = bugreport_dir + "/" + base_name + "-" + suffix + ".png"; |
Felipe Leme | 71bbfc5 | 2015-11-23 14:14:51 -0800 | [diff] [blame] | 793 | } |
Felipe Leme | ad5f6c4 | 2015-11-30 14:26:46 -0800 | [diff] [blame] | 794 | tmp_path = bugreport_dir + "/" + base_name + "-" + suffix + ".tmp"; |
Felipe Leme | 71bbfc5 | 2015-11-23 14:14:51 -0800 | [diff] [blame] | 795 | |
Felipe Leme | ad5f6c4 | 2015-11-30 14:26:46 -0800 | [diff] [blame] | 796 | ALOGD("Bugreport dir: %s\nBase name: %s\nSuffix: %s\nTemporary path: %s\n" |
| 797 | "Screenshot path: %s\n", bugreport_dir.c_str(), base_name.c_str(), suffix.c_str(), |
| 798 | tmp_path.c_str(), screenshot_path.c_str()); |
Felipe Leme | 71bbfc5 | 2015-11-23 14:14:51 -0800 | [diff] [blame] | 799 | |
| 800 | if (do_update_progress) { |
Felipe Leme | ad5f6c4 | 2015-11-30 14:26:46 -0800 | [diff] [blame] | 801 | std::vector<std::string> am_args = { |
| 802 | "--receiver-permission", "android.permission.DUMP", |
| 803 | "--es", "android.intent.extra.NAME", suffix, |
| 804 | "--ei", "android.intent.extra.PID", std::to_string(getpid()), |
| 805 | "--ei", "android.intent.extra.MAX", std::to_string(WEIGHT_TOTAL), |
| 806 | }; |
| 807 | send_broadcast("android.intent.action.BUGREPORT_STARTED", am_args); |
Felipe Leme | 71bbfc5 | 2015-11-23 14:14:51 -0800 | [diff] [blame] | 808 | } |
| 809 | } |
| 810 | |
Jeff Brown | 1dc94e3 | 2014-09-11 14:15:27 -0700 | [diff] [blame] | 811 | /* open the vibrator before dropping root */ |
Felipe Leme | 6e01fa6 | 2015-11-11 19:35:14 -0800 | [diff] [blame] | 812 | std::unique_ptr<FILE, int(*)(FILE*)> vibrator(NULL, fclose); |
John Michelau | 1f794c4 | 2012-09-17 11:20:19 -0500 | [diff] [blame] | 813 | if (do_vibrate) { |
Felipe Leme | 6e01fa6 | 2015-11-11 19:35:14 -0800 | [diff] [blame] | 814 | vibrator.reset(fopen("/sys/class/timed_output/vibrator/enable", "we")); |
Jeff Brown | 1dc94e3 | 2014-09-11 14:15:27 -0700 | [diff] [blame] | 815 | if (vibrator) { |
Felipe Leme | 6e01fa6 | 2015-11-11 19:35:14 -0800 | [diff] [blame] | 816 | vibrate(vibrator.get(), 150); |
Jeff Brown | 1dc94e3 | 2014-09-11 14:15:27 -0700 | [diff] [blame] | 817 | } |
John Michelau | 1f794c4 | 2012-09-17 11:20:19 -0500 | [diff] [blame] | 818 | } |
Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 819 | |
Felipe Leme | 3634a1e | 2015-12-09 10:11:47 -0800 | [diff] [blame] | 820 | if (do_fb && do_early_screenshot) { |
| 821 | if (screenshot_path.empty()) { |
| 822 | // should not have happened |
| 823 | ALOGE("INTERNAL ERROR: skipping early screenshot because path was not set"); |
| 824 | } else { |
| 825 | ALOGI("taking early screenshot\n"); |
| 826 | take_screenshot(screenshot_path); |
| 827 | ALOGI("wrote screenshot: %s\n", screenshot_path.c_str()); |
| 828 | if (chown(screenshot_path.c_str(), AID_SHELL, AID_SHELL)) { |
| 829 | ALOGE("Unable to change ownership of screenshot file %s: %s\n", |
| 830 | screenshot_path.c_str(), strerror(errno)); |
| 831 | } |
Felipe Leme | e338bf6 | 2015-12-07 14:03:50 -0800 | [diff] [blame] | 832 | } |
| 833 | } |
| 834 | |
Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 835 | /* read /proc/cmdline before dropping root */ |
Nick Kralevich | cd67e9f | 2015-03-19 11:30:59 -0700 | [diff] [blame] | 836 | FILE *cmdline = fopen("/proc/cmdline", "re"); |
Felipe Leme | 6e01fa6 | 2015-11-11 19:35:14 -0800 | [diff] [blame] | 837 | if (cmdline) { |
Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 838 | fgets(cmdline_buf, sizeof(cmdline_buf), cmdline); |
| 839 | fclose(cmdline); |
| 840 | } |
| 841 | |
Jeff Brown | 1dc94e3 | 2014-09-11 14:15:27 -0700 | [diff] [blame] | 842 | /* collect stack traces from Dalvik and native processes (needs root) */ |
| 843 | dump_traces_path = dump_traces(); |
| 844 | |
| 845 | /* Get the tombstone fds here while we are running as root. */ |
| 846 | get_tombstone_fds(tombstone_data); |
| 847 | |
| 848 | /* ensure we will keep capabilities when we drop root */ |
Nick Kralevich | 1e33987 | 2012-04-25 13:38:45 -0700 | [diff] [blame] | 849 | if (prctl(PR_SET_KEEPCAPS, 1) < 0) { |
| 850 | ALOGE("prctl(PR_SET_KEEPCAPS) failed: %s\n", strerror(errno)); |
| 851 | return -1; |
| 852 | } |
Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 853 | |
Nick Kralevich | 1e33987 | 2012-04-25 13:38:45 -0700 | [diff] [blame] | 854 | /* switch to non-root user and group */ |
| 855 | gid_t groups[] = { AID_LOG, AID_SDCARD_R, AID_SDCARD_RW, |
Nick Kralevich | ab46a49 | 2015-11-07 17:05:41 -0800 | [diff] [blame] | 856 | AID_MOUNT, AID_INET, AID_NET_BW_STATS, AID_READPROC }; |
Nick Kralevich | 1e33987 | 2012-04-25 13:38:45 -0700 | [diff] [blame] | 857 | if (setgroups(sizeof(groups)/sizeof(groups[0]), groups) != 0) { |
| 858 | ALOGE("Unable to setgroups, aborting: %s\n", strerror(errno)); |
| 859 | return -1; |
| 860 | } |
| 861 | if (setgid(AID_SHELL) != 0) { |
| 862 | ALOGE("Unable to setgid, aborting: %s\n", strerror(errno)); |
| 863 | return -1; |
| 864 | } |
| 865 | if (setuid(AID_SHELL) != 0) { |
| 866 | ALOGE("Unable to setuid, aborting: %s\n", strerror(errno)); |
| 867 | return -1; |
| 868 | } |
Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 869 | |
Nick Kralevich | 1e33987 | 2012-04-25 13:38:45 -0700 | [diff] [blame] | 870 | struct __user_cap_header_struct capheader; |
| 871 | struct __user_cap_data_struct capdata[2]; |
| 872 | memset(&capheader, 0, sizeof(capheader)); |
| 873 | memset(&capdata, 0, sizeof(capdata)); |
| 874 | capheader.version = _LINUX_CAPABILITY_VERSION_3; |
| 875 | capheader.pid = 0; |
Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 876 | |
Nick Kralevich | 1e33987 | 2012-04-25 13:38:45 -0700 | [diff] [blame] | 877 | capdata[CAP_TO_INDEX(CAP_SYSLOG)].permitted = CAP_TO_MASK(CAP_SYSLOG); |
| 878 | capdata[CAP_TO_INDEX(CAP_SYSLOG)].effective = CAP_TO_MASK(CAP_SYSLOG); |
| 879 | capdata[0].inheritable = 0; |
| 880 | capdata[1].inheritable = 0; |
Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 881 | |
Nick Kralevich | 1e33987 | 2012-04-25 13:38:45 -0700 | [diff] [blame] | 882 | if (capset(&capheader, &capdata[0]) < 0) { |
| 883 | ALOGE("capset failed: %s\n", strerror(errno)); |
| 884 | return -1; |
Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 885 | } |
| 886 | |
Felipe Leme | 71bbfc5 | 2015-11-23 14:14:51 -0800 | [diff] [blame] | 887 | if (is_redirecting) { |
Felipe Leme | 6e01fa6 | 2015-11-11 19:35:14 -0800 | [diff] [blame] | 888 | /* TODO: rather than generating a text file now and zipping it later, |
| 889 | it would be more efficient to redirect stdout to the zip entry |
| 890 | directly, but the libziparchive doesn't support that option yet. */ |
| 891 | redirect_to_file(stdout, const_cast<char*>(tmp_path.c_str())); |
Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 892 | } |
| 893 | |
Felipe Leme | 3634a1e | 2015-12-09 10:11:47 -0800 | [diff] [blame] | 894 | dumpstate(do_early_screenshot ? "": screenshot_path); |
Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 895 | |
Jeff Brown | 1dc94e3 | 2014-09-11 14:15:27 -0700 | [diff] [blame] | 896 | /* done */ |
| 897 | if (vibrator) { |
| 898 | for (int i = 0; i < 3; i++) { |
Felipe Leme | 6e01fa6 | 2015-11-11 19:35:14 -0800 | [diff] [blame] | 899 | vibrate(vibrator.get(), 75); |
Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 900 | usleep((75 + 50) * 1000); |
| 901 | } |
Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 902 | } |
| 903 | |
Felipe Leme | 55b42a6 | 2015-11-10 17:39:08 -0800 | [diff] [blame] | 904 | /* close output if needed */ |
Felipe Leme | 71bbfc5 | 2015-11-23 14:14:51 -0800 | [diff] [blame] | 905 | if (is_redirecting) { |
Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 906 | fclose(stdout); |
Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 907 | } |
| 908 | |
Felipe Leme | 6e01fa6 | 2015-11-11 19:35:14 -0800 | [diff] [blame] | 909 | /* rename or zip the (now complete) .tmp file to its final location */ |
| 910 | if (use_outfile) { |
Felipe Leme | ad5f6c4 | 2015-11-30 14:26:46 -0800 | [diff] [blame] | 911 | |
| 912 | /* check if user changed the suffix using system properties */ |
| 913 | char key[PROPERTY_KEY_MAX]; |
| 914 | char value[PROPERTY_VALUE_MAX]; |
| 915 | sprintf(key, "dumpstate.%d.name", getpid()); |
| 916 | property_get(key, value, ""); |
| 917 | bool change_suffix= false; |
| 918 | if (value[0]) { |
| 919 | /* must whitelist which characters are allowed, otherwise it could cross directories */ |
| 920 | std::regex valid_regex("^[-_a-zA-Z0-9]+$"); |
| 921 | if (std::regex_match(value, valid_regex)) { |
| 922 | change_suffix = true; |
| 923 | } else { |
| 924 | ALOGE("invalid suffix provided by user: %s", value); |
| 925 | } |
| 926 | } |
| 927 | if (change_suffix) { |
| 928 | ALOGI("changing suffix from %s to %s", suffix.c_str(), value); |
| 929 | suffix = value; |
| 930 | if (!screenshot_path.empty()) { |
| 931 | std::string new_screenshot_path = |
| 932 | bugreport_dir + "/" + base_name + "-" + suffix + ".png"; |
| 933 | if (rename(screenshot_path.c_str(), new_screenshot_path.c_str())) { |
| 934 | ALOGE("rename(%s, %s): %s\n", screenshot_path.c_str(), |
| 935 | new_screenshot_path.c_str(), strerror(errno)); |
| 936 | } else { |
| 937 | screenshot_path = new_screenshot_path; |
| 938 | } |
| 939 | } |
| 940 | } |
| 941 | |
Felipe Leme | 6e01fa6 | 2015-11-11 19:35:14 -0800 | [diff] [blame] | 942 | bool do_text_file = true; |
| 943 | if (do_zip_file) { |
Felipe Leme | ad5f6c4 | 2015-11-30 14:26:46 -0800 | [diff] [blame] | 944 | ALOGD("Generating .zip bugreport"); |
| 945 | path = bugreport_dir + "/" + base_name + "-" + suffix + ".zip"; |
| 946 | if (!generate_zip_file(tmp_path, path, base_name + "-" + suffix + ".txt", now)) { |
Felipe Leme | 6e01fa6 | 2015-11-11 19:35:14 -0800 | [diff] [blame] | 947 | ALOGE("Failed to generate zip file; sending text bugreport instead\n"); |
| 948 | do_text_file = true; |
| 949 | } else { |
| 950 | do_text_file = false; |
| 951 | } |
| 952 | } |
| 953 | if (do_text_file) { |
Felipe Leme | ad5f6c4 | 2015-11-30 14:26:46 -0800 | [diff] [blame] | 954 | ALOGD("Generating .txt bugreport"); |
| 955 | path = bugreport_dir + "/" + base_name + "-" + suffix + ".txt"; |
| 956 | if (rename(tmp_path.c_str(), path.c_str())) { |
| 957 | ALOGE("rename(%s, %s): %s\n", tmp_path.c_str(), path.c_str(), strerror(errno)); |
Felipe Leme | 6e01fa6 | 2015-11-11 19:35:14 -0800 | [diff] [blame] | 958 | path.clear(); |
| 959 | } |
| 960 | } |
Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 961 | } |
| 962 | |
Jeff Brown | 1dc94e3 | 2014-09-11 14:15:27 -0700 | [diff] [blame] | 963 | /* tell activity manager we're done */ |
Felipe Leme | 71bbfc5 | 2015-11-23 14:14:51 -0800 | [diff] [blame] | 964 | if (do_broadcast) { |
Felipe Leme | 6e01fa6 | 2015-11-11 19:35:14 -0800 | [diff] [blame] | 965 | if (!path.empty()) { |
| 966 | ALOGI("Final bugreport path: %s\n", path.c_str()); |
Felipe Leme | 36b3f6f | 2015-11-19 15:41:04 -0800 | [diff] [blame] | 967 | std::vector<std::string> am_args = { |
| 968 | "--receiver-permission", "android.permission.DUMP", |
Felipe Leme | 71bbfc5 | 2015-11-23 14:14:51 -0800 | [diff] [blame] | 969 | "--ei", "android.intent.extra.PID", std::to_string(getpid()), |
Felipe Leme | 36b3f6f | 2015-11-19 15:41:04 -0800 | [diff] [blame] | 970 | "--es", "android.intent.extra.BUGREPORT", path |
| 971 | }; |
| 972 | if (do_fb) { |
| 973 | am_args.push_back("--es"); |
| 974 | am_args.push_back("android.intent.extra.SCREENSHOT"); |
| 975 | am_args.push_back(screenshot_path); |
| 976 | } |
| 977 | send_broadcast("android.intent.action.BUGREPORT_FINISHED", am_args); |
Felipe Leme | 6e01fa6 | 2015-11-11 19:35:14 -0800 | [diff] [blame] | 978 | } else { |
Felipe Leme | 71bbfc5 | 2015-11-23 14:14:51 -0800 | [diff] [blame] | 979 | ALOGE("Skipping finished broadcast because bugreport could not be generated\n"); |
Felipe Leme | 6e01fa6 | 2015-11-11 19:35:14 -0800 | [diff] [blame] | 980 | } |
Jeff Sharkey | 27f9e6d | 2013-03-13 15:45:50 -0700 | [diff] [blame] | 981 | } |
| 982 | |
Felipe Leme | e338bf6 | 2015-12-07 14:03:50 -0800 | [diff] [blame] | 983 | ALOGD("Final progress: %d/%d (originally %d)\n", progress, weight_total, WEIGHT_TOTAL); |
Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 984 | ALOGI("done\n"); |
| 985 | |
| 986 | return 0; |
| 987 | } |