| 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 |  | 
| Felipe Leme | 8268ed2 | 2016-08-02 18:18:25 -0700 | [diff] [blame] | 17 | #ifndef FRAMEWORK_NATIVE_CMD_DUMPSTATE_H_ | 
|  | 18 | #define FRAMEWORK_NATIVE_CMD_DUMPSTATE_H_ | 
| Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 19 |  | 
|  | 20 | #include <time.h> | 
|  | 21 | #include <unistd.h> | 
| Colin Cross | 0c22e8b | 2012-11-02 15:46:56 -0700 | [diff] [blame] | 22 | #include <stdbool.h> | 
| Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 23 | #include <stdio.h> | 
| Felipe Leme | 30dbfa1 | 2016-09-02 12:43:26 -0700 | [diff] [blame] | 24 |  | 
|  | 25 | #include <string> | 
| Felipe Leme | 36b3f6f | 2015-11-19 15:41:04 -0800 | [diff] [blame] | 26 | #include <vector> | 
| Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 27 |  | 
| Felipe Leme | c6bc8bc | 2016-10-27 15:58:27 -0700 | [diff] [blame] | 28 | #include <android-base/macros.h> | 
| Luis Hector Chavez | 91c2ae5 | 2018-03-14 15:12:46 -0700 | [diff] [blame] | 29 | #include <android-base/unique_fd.h> | 
| Nandana Dutt | d2f5f08 | 2019-01-18 17:13:52 +0000 | [diff] [blame] | 30 | #include <android/os/BnIncidentAuthListener.h> | 
| Nandana Dutt | 197661d | 2018-11-16 16:40:21 +0000 | [diff] [blame] | 31 | #include <android/os/IDumpstate.h> | 
| Jiyong Park | b22e65d | 2017-06-23 21:23:16 +0900 | [diff] [blame] | 32 | #include <android/os/IDumpstateListener.h> | 
|  | 33 | #include <utils/StrongPointer.h> | 
| Felipe Leme | c6bc8bc | 2016-10-27 15:58:27 -0700 | [diff] [blame] | 34 | #include <ziparchive/zip_writer.h> | 
|  | 35 |  | 
| Felipe Leme | bda15a0 | 2016-11-16 17:48:25 -0800 | [diff] [blame] | 36 | #include "DumpstateUtil.h" | 
| Felipe Leme | 75876a2 | 2016-10-27 16:31:27 -0700 | [diff] [blame] | 37 |  | 
| Felipe Leme | 35c94f3 | 2016-08-12 10:51:54 -0700 | [diff] [blame] | 38 | // Workaround for const char *args[MAX_ARGS_ARRAY_SIZE] variables until they're converted to | 
|  | 39 | // std::vector<std::string> | 
| Felipe Leme | 30dbfa1 | 2016-09-02 12:43:26 -0700 | [diff] [blame] | 40 | // TODO: remove once not used | 
| Felipe Leme | 35c94f3 | 2016-08-12 10:51:54 -0700 | [diff] [blame] | 41 | #define MAX_ARGS_ARRAY_SIZE 1000 | 
|  | 42 |  | 
| Felipe Leme | 47e9be2 | 2016-12-21 15:37:07 -0800 | [diff] [blame] | 43 | // TODO: move everything under this namespace | 
|  | 44 | // TODO: and then remove explicitly android::os::dumpstate:: prefixes | 
|  | 45 | namespace android { | 
|  | 46 | namespace os { | 
| Nandana Dutt | 58d72e2 | 2018-11-16 10:30:48 +0000 | [diff] [blame] | 47 |  | 
|  | 48 | struct DumpstateOptions; | 
|  | 49 |  | 
| Felipe Leme | 47e9be2 | 2016-12-21 15:37:07 -0800 | [diff] [blame] | 50 | namespace dumpstate { | 
|  | 51 |  | 
|  | 52 | class DumpstateTest; | 
|  | 53 | class ProgressTest; | 
|  | 54 |  | 
|  | 55 | }  // namespace dumpstate | 
|  | 56 | }  // namespace os | 
|  | 57 | }  // namespace android | 
|  | 58 |  | 
| Jiyong Park | b22e65d | 2017-06-23 21:23:16 +0900 | [diff] [blame] | 59 | class ZipWriter; | 
|  | 60 |  | 
| Felipe Leme | 30dbfa1 | 2016-09-02 12:43:26 -0700 | [diff] [blame] | 61 | // TODO: remove once moved to HAL | 
| Felipe Leme | 8620bb4 | 2015-11-10 11:04:45 -0800 | [diff] [blame] | 62 | #ifdef __cplusplus | 
|  | 63 | extern "C" { | 
|  | 64 | #endif | 
|  | 65 |  | 
| Felipe Leme | 30dbfa1 | 2016-09-02 12:43:26 -0700 | [diff] [blame] | 66 | /* | 
| Felipe Leme | 30dbfa1 | 2016-09-02 12:43:26 -0700 | [diff] [blame] | 67 | * Helper class used to report how long it takes for a section to finish. | 
|  | 68 | * | 
|  | 69 | * Typical usage: | 
|  | 70 | * | 
|  | 71 | *    DurationReporter duration_reporter(title); | 
|  | 72 | * | 
|  | 73 | */ | 
|  | 74 | class DurationReporter { | 
|  | 75 | public: | 
| Nandana Dutt | a8470b8 | 2019-03-11 11:00:58 +0000 | [diff] [blame] | 76 | explicit DurationReporter(const std::string& title, bool logcat_only = false); | 
| Felipe Leme | 30dbfa1 | 2016-09-02 12:43:26 -0700 | [diff] [blame] | 77 |  | 
|  | 78 | ~DurationReporter(); | 
|  | 79 |  | 
| Felipe Leme | 30dbfa1 | 2016-09-02 12:43:26 -0700 | [diff] [blame] | 80 | private: | 
| Felipe Leme | 678727a | 2016-09-21 17:22:11 -0700 | [diff] [blame] | 81 | std::string title_; | 
| Nandana Dutt | a8470b8 | 2019-03-11 11:00:58 +0000 | [diff] [blame] | 82 | bool logcat_only_; | 
| Felipe Leme | b0f669d | 2016-09-26 18:26:11 -0700 | [diff] [blame] | 83 | uint64_t started_; | 
| Felipe Leme | 062926e | 2016-10-27 15:51:12 -0700 | [diff] [blame] | 84 |  | 
|  | 85 | DISALLOW_COPY_AND_ASSIGN(DurationReporter); | 
| Felipe Leme | 30dbfa1 | 2016-09-02 12:43:26 -0700 | [diff] [blame] | 86 | }; | 
|  | 87 |  | 
|  | 88 | /* | 
| Felipe Leme | 7447d7c | 2016-11-03 18:12:22 -0700 | [diff] [blame] | 89 | * Keeps track of current progress and estimated max, saving stats on file to tune up future runs. | 
| Felipe Leme | 71bbfc5 | 2015-11-23 14:14:51 -0800 | [diff] [blame] | 90 | * | 
| Felipe Leme | 7447d7c | 2016-11-03 18:12:22 -0700 | [diff] [blame] | 91 | * Each `dumpstate` section contributes to the total weight by an individual weight, so the overall | 
|  | 92 | * progress can be calculated by dividing the estimate max progress by the current progress. | 
| Felipe Leme | 71bbfc5 | 2015-11-23 14:14:51 -0800 | [diff] [blame] | 93 | * | 
| Felipe Leme | 7447d7c | 2016-11-03 18:12:22 -0700 | [diff] [blame] | 94 | * The estimated max progress is initially set to a value (`kDefaultMax) defined empirically, but | 
|  | 95 | * it's adjusted after each dumpstate run by storing the average duration in a file. | 
| Felipe Leme | ad5f6c4 | 2015-11-30 14:26:46 -0800 | [diff] [blame] | 96 | * | 
| Felipe Leme | 71bbfc5 | 2015-11-23 14:14:51 -0800 | [diff] [blame] | 97 | */ | 
| Felipe Leme | 7447d7c | 2016-11-03 18:12:22 -0700 | [diff] [blame] | 98 | class Progress { | 
| Felipe Leme | 47e9be2 | 2016-12-21 15:37:07 -0800 | [diff] [blame] | 99 | friend class android::os::dumpstate::ProgressTest; | 
|  | 100 | friend class android::os::dumpstate::DumpstateTest; | 
| Felipe Leme | 7447d7c | 2016-11-03 18:12:22 -0700 | [diff] [blame] | 101 |  | 
|  | 102 | public: | 
|  | 103 | /* | 
|  | 104 | * Default estimation of the max duration of a bugreport generation. | 
|  | 105 | * | 
|  | 106 | * It does not need to match the exact sum of all sections, but ideally it should to be slight | 
|  | 107 | * more than such sum: a value too high will cause the bugreport to finish before the user | 
|  | 108 | * expected (for example, jumping from 70% to 100%), while a value too low will cause the | 
|  | 109 | * progress to get stuck at an almost-finished value (like 99%) for a while. | 
|  | 110 | * | 
|  | 111 | * This constant is only used when the average duration from previous runs cannot be used. | 
|  | 112 | */ | 
|  | 113 | static const int kDefaultMax; | 
|  | 114 |  | 
| Chih-Hung Hsieh | d0937e6 | 2018-12-20 15:43:57 -0800 | [diff] [blame] | 115 | explicit Progress(const std::string& path = ""); | 
| Felipe Leme | 7447d7c | 2016-11-03 18:12:22 -0700 | [diff] [blame] | 116 |  | 
|  | 117 | // Gets the current progress. | 
|  | 118 | int32_t Get() const; | 
|  | 119 |  | 
|  | 120 | // Gets the current estimated max progress. | 
|  | 121 | int32_t GetMax() const; | 
|  | 122 |  | 
|  | 123 | // Gets the initial estimated max progress. | 
|  | 124 | int32_t GetInitialMax() const; | 
|  | 125 |  | 
|  | 126 | // Increments progress (ignored if not positive). | 
|  | 127 | // Returns `true` if the max progress increased as well. | 
|  | 128 | bool Inc(int32_t delta); | 
|  | 129 |  | 
|  | 130 | // Persist the stats. | 
|  | 131 | void Save(); | 
|  | 132 |  | 
|  | 133 | void Dump(int fd, const std::string& prefix) const; | 
|  | 134 |  | 
|  | 135 | private: | 
|  | 136 | Progress(int32_t initial_max, float growth_factor, | 
|  | 137 | const std::string& path = "");                                // Used by test cases. | 
|  | 138 | Progress(int32_t initial_max, int32_t progress, float growth_factor);  // Used by test cases. | 
|  | 139 | void Load(); | 
|  | 140 | int32_t initial_max_; | 
|  | 141 | int32_t progress_; | 
|  | 142 | int32_t max_; | 
|  | 143 | float growth_factor_; | 
|  | 144 | int32_t n_runs_; | 
|  | 145 | int32_t average_max_; | 
| Nandana Dutt | 979388e | 2018-11-30 16:48:55 +0000 | [diff] [blame] | 146 | std::string path_; | 
| Felipe Leme | 7447d7c | 2016-11-03 18:12:22 -0700 | [diff] [blame] | 147 | }; | 
| Felipe Leme | 71bbfc5 | 2015-11-23 14:14:51 -0800 | [diff] [blame] | 148 |  | 
| Felipe Leme | 71bbfc5 | 2015-11-23 14:14:51 -0800 | [diff] [blame] | 149 | /* | 
| Felipe Leme | bbaf3c1 | 2016-10-11 14:32:25 -0700 | [diff] [blame] | 150 | * List of supported zip format versions. | 
|  | 151 | * | 
|  | 152 | * See bugreport-format.md for more info. | 
|  | 153 | */ | 
| Vishnu Nair | 64afc02 | 2018-02-01 15:29:34 -0800 | [diff] [blame] | 154 | static std::string VERSION_CURRENT = "2.0"; | 
| Felipe Leme | d071c68 | 2016-10-20 16:48:00 -0700 | [diff] [blame] | 155 |  | 
|  | 156 | /* | 
| Felipe Leme | e184f66 | 2016-10-27 10:04:47 -0700 | [diff] [blame] | 157 | * Temporary version that adds a anr-traces.txt entry. Once tools support it, the current version | 
| Vishnu Nair | 64afc02 | 2018-02-01 15:29:34 -0800 | [diff] [blame] | 158 | * will be bumped to 3.0. | 
| Felipe Leme | e184f66 | 2016-10-27 10:04:47 -0700 | [diff] [blame] | 159 | */ | 
| Vishnu Nair | 64afc02 | 2018-02-01 15:29:34 -0800 | [diff] [blame] | 160 | static std::string VERSION_SPLIT_ANR = "3.0-dev-split-anr"; | 
| Felipe Leme | e184f66 | 2016-10-27 10:04:47 -0700 | [diff] [blame] | 161 |  | 
|  | 162 | /* | 
| Felipe Leme | d071c68 | 2016-10-20 16:48:00 -0700 | [diff] [blame] | 163 | * "Alias" for the current version. | 
|  | 164 | */ | 
|  | 165 | static std::string VERSION_DEFAULT = "default"; | 
| Felipe Leme | bbaf3c1 | 2016-10-11 14:32:25 -0700 | [diff] [blame] | 166 |  | 
|  | 167 | /* | 
| Nandana Dutt | 979388e | 2018-11-30 16:48:55 +0000 | [diff] [blame] | 168 | * Directory used by Dumpstate binary to keep its local files. | 
|  | 169 | */ | 
|  | 170 | static const std::string DUMPSTATE_DIRECTORY = "/bugreports"; | 
|  | 171 |  | 
|  | 172 | /* | 
| Luis Hector Chavez | 91c2ae5 | 2018-03-14 15:12:46 -0700 | [diff] [blame] | 173 | * Structure that contains the information of an open dump file. | 
|  | 174 | */ | 
|  | 175 | struct DumpData { | 
|  | 176 | // Path of the file. | 
|  | 177 | std::string name; | 
|  | 178 |  | 
|  | 179 | // Open file descriptor for the file. | 
|  | 180 | android::base::unique_fd fd; | 
|  | 181 |  | 
|  | 182 | // Modification time of the file. | 
|  | 183 | time_t mtime; | 
|  | 184 | }; | 
|  | 185 |  | 
|  | 186 | /* | 
| Felipe Leme | e844a9d | 2016-09-21 15:01:39 -0700 | [diff] [blame] | 187 | * Main class driving a bugreport generation. | 
|  | 188 | * | 
|  | 189 | * Currently, it only contains variables that are accessed externally, but gradually the functions | 
|  | 190 | * that are spread accross utils.cpp and dumpstate.cpp will be moved to it. | 
|  | 191 | */ | 
|  | 192 | class Dumpstate { | 
| Felipe Leme | 4c2d663 | 2016-09-28 14:32:00 -0700 | [diff] [blame] | 193 | friend class DumpstateTest; | 
|  | 194 |  | 
| Felipe Leme | e844a9d | 2016-09-21 15:01:39 -0700 | [diff] [blame] | 195 | public: | 
| Nandana Dutt | d2f5f08 | 2019-01-18 17:13:52 +0000 | [diff] [blame] | 196 | enum RunStatus { OK, HELP, INVALID_INPUT, ERROR, USER_CONSENT_DENIED, USER_CONSENT_TIMED_OUT }; | 
| Nandana Dutt | 5fb117b | 2018-09-27 09:23:36 +0100 | [diff] [blame] | 197 |  | 
| Nandana Dutt | 58d72e2 | 2018-11-16 10:30:48 +0000 | [diff] [blame] | 198 | // The mode under which the bugreport should be run. Each mode encapsulates a few options. | 
|  | 199 | enum BugreportMode { | 
| Nandana Dutt | 197661d | 2018-11-16 16:40:21 +0000 | [diff] [blame] | 200 | BUGREPORT_FULL = android::os::IDumpstate::BUGREPORT_MODE_FULL, | 
|  | 201 | BUGREPORT_INTERACTIVE = android::os::IDumpstate::BUGREPORT_MODE_INTERACTIVE, | 
|  | 202 | BUGREPORT_REMOTE = android::os::IDumpstate::BUGREPORT_MODE_REMOTE, | 
|  | 203 | BUGREPORT_WEAR = android::os::IDumpstate::BUGREPORT_MODE_WEAR, | 
|  | 204 | BUGREPORT_TELEPHONY = android::os::IDumpstate::BUGREPORT_MODE_TELEPHONY, | 
| Abhijeet Kaur | 904e0e0 | 2018-12-05 14:03:01 +0000 | [diff] [blame] | 205 | BUGREPORT_WIFI = android::os::IDumpstate::BUGREPORT_MODE_WIFI, | 
|  | 206 | BUGREPORT_DEFAULT = android::os::IDumpstate::BUGREPORT_MODE_DEFAULT | 
| Nandana Dutt | 58d72e2 | 2018-11-16 10:30:48 +0000 | [diff] [blame] | 207 | }; | 
|  | 208 |  | 
| Felipe Leme | 47e9be2 | 2016-12-21 15:37:07 -0800 | [diff] [blame] | 209 | static android::os::dumpstate::CommandOptions DEFAULT_DUMPSYS; | 
| Felipe Leme | bda15a0 | 2016-11-16 17:48:25 -0800 | [diff] [blame] | 210 |  | 
| Felipe Leme | e844a9d | 2016-09-21 15:01:39 -0700 | [diff] [blame] | 211 | static Dumpstate& GetInstance(); | 
| Felipe Leme | 71bbfc5 | 2015-11-23 14:14:51 -0800 | [diff] [blame] | 212 |  | 
| Felipe Leme | 1d486fe | 2016-10-14 18:06:47 -0700 | [diff] [blame] | 213 | /* Checkes whether dumpstate is generating a zipped bugreport. */ | 
|  | 214 | bool IsZipping() const; | 
|  | 215 |  | 
| Felipe Leme | 6ad9c06 | 2016-09-28 11:58:36 -0700 | [diff] [blame] | 216 | /* | 
| Felipe Leme | 678727a | 2016-09-21 17:22:11 -0700 | [diff] [blame] | 217 | * Forks a command, waits for it to finish, and returns its status. | 
|  | 218 | * | 
|  | 219 | * |title| description of the command printed on `stdout` (or empty to skip | 
|  | 220 | * description). | 
|  | 221 | * |full_command| array containing the command (first entry) and its arguments. | 
|  | 222 | * Must contain at least one element. | 
|  | 223 | * |options| optional argument defining the command's behavior. | 
|  | 224 | */ | 
|  | 225 | int RunCommand(const std::string& title, const std::vector<std::string>& fullCommand, | 
| Felipe Leme | 47e9be2 | 2016-12-21 15:37:07 -0800 | [diff] [blame] | 226 | const android::os::dumpstate::CommandOptions& options = | 
|  | 227 | android::os::dumpstate::CommandOptions::DEFAULT); | 
| Felipe Leme | 678727a | 2016-09-21 17:22:11 -0700 | [diff] [blame] | 228 |  | 
|  | 229 | /* | 
|  | 230 | * Runs `dumpsys` with the given arguments, automatically setting its timeout | 
| Vishnu Nair | 6921f80 | 2017-11-22 09:17:23 -0800 | [diff] [blame] | 231 | * (`-T` argument) | 
| Felipe Leme | 678727a | 2016-09-21 17:22:11 -0700 | [diff] [blame] | 232 | * according to the command options. | 
|  | 233 | * | 
|  | 234 | * |title| description of the command printed on `stdout` (or empty to skip | 
|  | 235 | * description). | 
|  | 236 | * |dumpsys_args| `dumpsys` arguments (except `-t`). | 
|  | 237 | * |options| optional argument defining the command's behavior. | 
| Vishnu Nair | 6921f80 | 2017-11-22 09:17:23 -0800 | [diff] [blame] | 238 | * |dumpsys_timeout| when > 0, defines the value passed to `dumpsys -T` (otherwise it uses the | 
| Felipe Leme | 6ad9c06 | 2016-09-28 11:58:36 -0700 | [diff] [blame] | 239 | * timeout from `options`) | 
| Felipe Leme | 678727a | 2016-09-21 17:22:11 -0700 | [diff] [blame] | 240 | */ | 
| Felipe Leme | 9a523ae | 2016-10-20 15:10:33 -0700 | [diff] [blame] | 241 | void RunDumpsys(const std::string& title, const std::vector<std::string>& dumpsys_args, | 
| Felipe Leme | 47e9be2 | 2016-12-21 15:37:07 -0800 | [diff] [blame] | 242 | const android::os::dumpstate::CommandOptions& options = DEFAULT_DUMPSYS, | 
| Vishnu Nair | 6921f80 | 2017-11-22 09:17:23 -0800 | [diff] [blame] | 243 | long dumpsys_timeout_ms = 0); | 
| Felipe Leme | 678727a | 2016-09-21 17:22:11 -0700 | [diff] [blame] | 244 |  | 
|  | 245 | /* | 
|  | 246 | * Prints the contents of a file. | 
|  | 247 | * | 
|  | 248 | * |title| description of the command printed on `stdout` (or empty to skip | 
|  | 249 | * description). | 
|  | 250 | * |path| location of the file to be dumped. | 
|  | 251 | */ | 
|  | 252 | int DumpFile(const std::string& title, const std::string& path); | 
|  | 253 |  | 
| Felipe Leme | bbaf3c1 | 2016-10-11 14:32:25 -0700 | [diff] [blame] | 254 | /* | 
| Felipe Leme | 1d486fe | 2016-10-14 18:06:47 -0700 | [diff] [blame] | 255 | * Adds a new entry to the existing zip file. | 
|  | 256 | * */ | 
|  | 257 | bool AddZipEntry(const std::string& entry_name, const std::string& entry_path); | 
|  | 258 |  | 
|  | 259 | /* | 
|  | 260 | * Adds a new entry to the existing zip file. | 
| Vishnu Nair | e97d612 | 2018-01-18 13:58:56 -0800 | [diff] [blame] | 261 | * | 
|  | 262 | * |entry_name| destination path of the new entry. | 
|  | 263 | * |fd| file descriptor to read from. | 
|  | 264 | * |timeout| timeout to terminate the read if not completed. Set | 
|  | 265 | * value of 0s (default) to disable timeout. | 
| Felipe Leme | 1d486fe | 2016-10-14 18:06:47 -0700 | [diff] [blame] | 266 | */ | 
| Vishnu Nair | e97d612 | 2018-01-18 13:58:56 -0800 | [diff] [blame] | 267 | android::status_t AddZipEntryFromFd(const std::string& entry_name, int fd, | 
|  | 268 | std::chrono::milliseconds timeout); | 
| Felipe Leme | 1d486fe | 2016-10-14 18:06:47 -0700 | [diff] [blame] | 269 |  | 
|  | 270 | /* | 
| Nandana Dutt | a7db634 | 2018-11-21 14:53:34 +0000 | [diff] [blame] | 271 | * Adds a text entry to the existing zip file. | 
| Felipe Leme | 1d486fe | 2016-10-14 18:06:47 -0700 | [diff] [blame] | 272 | */ | 
|  | 273 | bool AddTextZipEntry(const std::string& entry_name, const std::string& content); | 
|  | 274 |  | 
|  | 275 | /* | 
|  | 276 | * Adds all files from a directory to the zipped bugreport file. | 
|  | 277 | */ | 
|  | 278 | void AddDir(const std::string& dir, bool recursive); | 
|  | 279 |  | 
|  | 280 | /* | 
| Felipe Leme | bbaf3c1 | 2016-10-11 14:32:25 -0700 | [diff] [blame] | 281 | * Takes a screenshot and save it to the given `path`. | 
|  | 282 | * | 
|  | 283 | * If `path` is empty, uses a standard path based on the bugreport name. | 
|  | 284 | */ | 
|  | 285 | void TakeScreenshot(const std::string& path = ""); | 
|  | 286 |  | 
| Felipe Leme | 7447d7c | 2016-11-03 18:12:22 -0700 | [diff] [blame] | 287 | ///////////////////////////////////////////////////////////////////// | 
|  | 288 | // TODO: members below should be private once refactor is finished // | 
|  | 289 | ///////////////////////////////////////////////////////////////////// | 
|  | 290 |  | 
|  | 291 | // TODO: temporary method until Dumpstate object is properly set | 
|  | 292 | void SetProgress(std::unique_ptr<Progress> progress); | 
| Felipe Leme | d80e6b6 | 2016-10-03 13:08:14 -0700 | [diff] [blame] | 293 |  | 
| Nandana Dutt | cf419a7 | 2019-03-14 10:40:17 +0000 | [diff] [blame] | 294 | // Dumps Dalvik and native stack traces, sets the trace file location to path | 
|  | 295 | // if it succeeded. | 
|  | 296 | // Note that it returns early if user consent is denied with status USER_CONSENT_DENIED. | 
|  | 297 | // Returns OK in all other cases. | 
|  | 298 | RunStatus DumpTraces(const char** path); | 
| Nandana Dutt | faafd52 | 2019-03-11 09:23:09 +0000 | [diff] [blame] | 299 |  | 
| Felipe Leme | 6f674ae | 2016-11-18 17:10:33 -0800 | [diff] [blame] | 300 | void DumpstateBoard(); | 
|  | 301 |  | 
| Felipe Leme | d80e6b6 | 2016-10-03 13:08:14 -0700 | [diff] [blame] | 302 | /* | 
|  | 303 | * Updates the overall progress of the bugreport generation by the given weight increment. | 
|  | 304 | */ | 
| Felipe Leme | 7447d7c | 2016-11-03 18:12:22 -0700 | [diff] [blame] | 305 | void UpdateProgress(int32_t delta); | 
| Felipe Leme | d80e6b6 | 2016-10-03 13:08:14 -0700 | [diff] [blame] | 306 |  | 
| Felipe Leme | bbaf3c1 | 2016-10-11 14:32:25 -0700 | [diff] [blame] | 307 | /* Prints the dumpstate header on `stdout`. */ | 
| Felipe Leme | 2b9b06c | 2016-10-14 09:13:06 -0700 | [diff] [blame] | 308 | void PrintHeader() const; | 
| Felipe Leme | bbaf3c1 | 2016-10-11 14:32:25 -0700 | [diff] [blame] | 309 |  | 
| Felipe Leme | 1d486fe | 2016-10-14 18:06:47 -0700 | [diff] [blame] | 310 | /* | 
|  | 311 | * Adds the temporary report to the existing .zip file, closes the .zip file, and removes the | 
|  | 312 | * temporary file. | 
|  | 313 | */ | 
|  | 314 | bool FinishZipFile(); | 
|  | 315 |  | 
| Nandana Dutt | 979388e | 2018-11-30 16:48:55 +0000 | [diff] [blame] | 316 | /* Constructs a full path inside directory with file name formatted using the given suffix. */ | 
|  | 317 | std::string GetPath(const std::string& directory, const std::string& suffix) const; | 
|  | 318 |  | 
|  | 319 | /* Constructs a full path inside bugreport_internal_dir_ with file name formatted using the | 
|  | 320 | * given suffix. */ | 
| Felipe Leme | 2b9b06c | 2016-10-14 09:13:06 -0700 | [diff] [blame] | 321 | std::string GetPath(const std::string& suffix) const; | 
| Felipe Leme | bbaf3c1 | 2016-10-11 14:32:25 -0700 | [diff] [blame] | 322 |  | 
| Vishnu Nair | 780b128 | 2017-10-10 13:57:24 -0700 | [diff] [blame] | 323 | /* Returns true if the current version supports priority dump feature. */ | 
|  | 324 | bool CurrentVersionSupportsPriorityDumps() const; | 
|  | 325 |  | 
| Nandana Dutt | 5fb117b | 2018-09-27 09:23:36 +0100 | [diff] [blame] | 326 | struct DumpOptions; | 
| Felipe Leme | e844a9d | 2016-09-21 15:01:39 -0700 | [diff] [blame] | 327 |  | 
| Nandana Dutt | 197661d | 2018-11-16 16:40:21 +0000 | [diff] [blame] | 328 | /* Main entry point for running a complete bugreport. */ | 
| Nandana Dutt | d2f5f08 | 2019-01-18 17:13:52 +0000 | [diff] [blame] | 329 | RunStatus Run(int32_t calling_uid, const std::string& calling_package); | 
| Nandana Dutt | 197661d | 2018-11-16 16:40:21 +0000 | [diff] [blame] | 330 |  | 
| Nandana Dutt | f02564e | 2019-02-15 15:24:24 +0000 | [diff] [blame] | 331 | RunStatus ParseCommandlineAndRun(int argc, char* argv[]); | 
|  | 332 |  | 
| Nandana Dutt | 197661d | 2018-11-16 16:40:21 +0000 | [diff] [blame] | 333 | /* Sets runtime options. */ | 
|  | 334 | void SetOptions(std::unique_ptr<DumpOptions> options); | 
| Nandana Dutt | 3f8c717 | 2018-09-25 12:01:54 +0100 | [diff] [blame] | 335 |  | 
| Nandana Dutt | 3f8c717 | 2018-09-25 12:01:54 +0100 | [diff] [blame] | 336 | /* | 
| Nandana Dutt | bbdb5b4 | 2019-03-12 10:52:56 +0000 | [diff] [blame] | 337 | * Returns true if user consent is necessary and has been denied. | 
|  | 338 | * Consent is only necessary if the caller has asked to copy over the bugreport to a file they | 
|  | 339 | * provided. | 
|  | 340 | */ | 
|  | 341 | bool IsUserConsentDenied() const; | 
|  | 342 |  | 
|  | 343 | /* | 
| Nandana Dutt | 3f8c717 | 2018-09-25 12:01:54 +0100 | [diff] [blame] | 344 | * Structure to hold options that determine the behavior of dumpstate. | 
|  | 345 | */ | 
|  | 346 | struct DumpOptions { | 
|  | 347 | bool do_add_date = false; | 
|  | 348 | bool do_zip_file = false; | 
|  | 349 | bool do_vibrate = true; | 
| Nandana Dutt | 9a76d20 | 2019-01-21 15:56:48 +0000 | [diff] [blame] | 350 | // Writes bugreport content to a socket; only flatfile format is supported. | 
| Nandana Dutt | 3f8c717 | 2018-09-25 12:01:54 +0100 | [diff] [blame] | 351 | bool use_socket = false; | 
|  | 352 | bool use_control_socket = false; | 
|  | 353 | bool do_fb = false; | 
|  | 354 | bool do_broadcast = false; | 
|  | 355 | bool is_remote_mode = false; | 
|  | 356 | bool show_header_only = false; | 
|  | 357 | bool do_start_service = false; | 
|  | 358 | bool telephony_only = false; | 
|  | 359 | bool wifi_only = false; | 
| Nandana Dutt | 5fb117b | 2018-09-27 09:23:36 +0100 | [diff] [blame] | 360 | // Whether progress updates should be published. | 
|  | 361 | bool do_progress_updates = false; | 
| Nandana Dutt | 9a76d20 | 2019-01-21 15:56:48 +0000 | [diff] [blame] | 362 | // File descriptor to output zip file. | 
| Nandana Dutt | 54dbd67 | 2019-01-11 12:58:05 +0000 | [diff] [blame] | 363 | android::base::unique_fd bugreport_fd; | 
|  | 364 | // File descriptor to screenshot file. | 
| Nandana Dutt | 54dbd67 | 2019-01-11 12:58:05 +0000 | [diff] [blame] | 365 | android::base::unique_fd screenshot_fd; | 
| Nandana Dutt | 58d72e2 | 2018-11-16 10:30:48 +0000 | [diff] [blame] | 366 | // TODO: rename to MODE. | 
| Nandana Dutt | 5fb117b | 2018-09-27 09:23:36 +0100 | [diff] [blame] | 367 | // Extra options passed as system property. | 
|  | 368 | std::string extra_options; | 
|  | 369 | // Command-line arguments as string | 
|  | 370 | std::string args; | 
|  | 371 | // Notification title and description | 
|  | 372 | std::string notification_title; | 
|  | 373 | std::string notification_description; | 
|  | 374 |  | 
|  | 375 | /* Initializes options from commandline arguments and system properties. */ | 
|  | 376 | RunStatus Initialize(int argc, char* argv[]); | 
|  | 377 |  | 
| Nandana Dutt | 58d72e2 | 2018-11-16 10:30:48 +0000 | [diff] [blame] | 378 | /* Initializes options from the requested mode. */ | 
| Nandana Dutt | 54dbd67 | 2019-01-11 12:58:05 +0000 | [diff] [blame] | 379 | void Initialize(BugreportMode bugreport_mode, const android::base::unique_fd& bugreport_fd, | 
|  | 380 | const android::base::unique_fd& screenshot_fd); | 
| Nandana Dutt | 58d72e2 | 2018-11-16 10:30:48 +0000 | [diff] [blame] | 381 |  | 
| Nandana Dutt | 5fb117b | 2018-09-27 09:23:36 +0100 | [diff] [blame] | 382 | /* Returns true if the options set so far are consistent. */ | 
|  | 383 | bool ValidateOptions() const; | 
| Nandana Dutt | 9a76d20 | 2019-01-21 15:56:48 +0000 | [diff] [blame] | 384 |  | 
|  | 385 | /* Returns if options specified require writing bugreport to a file */ | 
|  | 386 | bool OutputToFile() const { | 
|  | 387 | // If we are not writing to socket, we will write to a file. If bugreport_fd is | 
|  | 388 | // specified, it is preferred. If not bugreport is written to /bugreports. | 
|  | 389 | return !use_socket; | 
|  | 390 | } | 
| Nandana Dutt | 3f8c717 | 2018-09-25 12:01:54 +0100 | [diff] [blame] | 391 | }; | 
|  | 392 |  | 
|  | 393 | // TODO: initialize fields on constructor | 
| Felipe Leme | e844a9d | 2016-09-21 15:01:39 -0700 | [diff] [blame] | 394 | // dumpstate id - unique after each device reboot. | 
| Felipe Leme | 7447d7c | 2016-11-03 18:12:22 -0700 | [diff] [blame] | 395 | uint32_t id_; | 
| Felipe Leme | e844a9d | 2016-09-21 15:01:39 -0700 | [diff] [blame] | 396 |  | 
| Felipe Leme | 75876a2 | 2016-10-27 16:31:27 -0700 | [diff] [blame] | 397 | // dumpstate pid | 
|  | 398 | pid_t pid_; | 
|  | 399 |  | 
| Nandana Dutt | 3f8c717 | 2018-09-25 12:01:54 +0100 | [diff] [blame] | 400 | // Runtime options. | 
| Nandana Dutt | 5fb117b | 2018-09-27 09:23:36 +0100 | [diff] [blame] | 401 | std::unique_ptr<DumpOptions> options_; | 
| Felipe Leme | e844a9d | 2016-09-21 15:01:39 -0700 | [diff] [blame] | 402 |  | 
| Felipe Leme | 009ecbb | 2016-11-07 10:18:44 -0800 | [diff] [blame] | 403 | // How frequently the progess should be updated;the listener will only be notificated when the | 
|  | 404 | // delta from the previous update is more than the threshold. | 
|  | 405 | int32_t update_progress_threshold_ = 100; | 
|  | 406 |  | 
|  | 407 | // Last progress that triggered a listener updated | 
|  | 408 | int32_t last_updated_progress_; | 
|  | 409 |  | 
| Felipe Leme | bbaf3c1 | 2016-10-11 14:32:25 -0700 | [diff] [blame] | 410 | // Whether it should take an screenshot earlier in the process. | 
| Felipe Leme | 9a523ae | 2016-10-20 15:10:33 -0700 | [diff] [blame] | 411 | bool do_early_screenshot_ = false; | 
| Felipe Leme | bbaf3c1 | 2016-10-11 14:32:25 -0700 | [diff] [blame] | 412 |  | 
| Felipe Leme | 7447d7c | 2016-11-03 18:12:22 -0700 | [diff] [blame] | 413 | std::unique_ptr<Progress> progress_; | 
| Felipe Leme | e844a9d | 2016-09-21 15:01:39 -0700 | [diff] [blame] | 414 |  | 
|  | 415 | // When set, defines a socket file-descriptor use to report progress to bugreportz. | 
| Felipe Leme | 9a523ae | 2016-10-20 15:10:33 -0700 | [diff] [blame] | 416 | int control_socket_fd_ = -1; | 
| Felipe Leme | e844a9d | 2016-09-21 15:01:39 -0700 | [diff] [blame] | 417 |  | 
| Felipe Leme | bbaf3c1 | 2016-10-11 14:32:25 -0700 | [diff] [blame] | 418 | // Bugreport format version; | 
| Felipe Leme | d071c68 | 2016-10-20 16:48:00 -0700 | [diff] [blame] | 419 | std::string version_ = VERSION_CURRENT; | 
| Felipe Leme | e844a9d | 2016-09-21 15:01:39 -0700 | [diff] [blame] | 420 |  | 
| Felipe Leme | bbaf3c1 | 2016-10-11 14:32:25 -0700 | [diff] [blame] | 421 | time_t now_; | 
|  | 422 |  | 
| Felipe Leme | 2b9b06c | 2016-10-14 09:13:06 -0700 | [diff] [blame] | 423 | // Base name (without suffix or extensions) of the bugreport files, typically | 
|  | 424 | // `bugreport-BUILD_ID`. | 
| Felipe Leme | 9a523ae | 2016-10-20 15:10:33 -0700 | [diff] [blame] | 425 | std::string base_name_; | 
| Felipe Leme | bbaf3c1 | 2016-10-11 14:32:25 -0700 | [diff] [blame] | 426 |  | 
| Felipe Leme | 2b9b06c | 2016-10-14 09:13:06 -0700 | [diff] [blame] | 427 | // Name is the suffix part of the bugreport files - it's typically the date (when invoked with | 
|  | 428 | // `-d`), but it could be changed by the user.. | 
|  | 429 | std::string name_; | 
|  | 430 |  | 
| Nandana Dutt | 979388e | 2018-11-30 16:48:55 +0000 | [diff] [blame] | 431 | std::string bugreport_internal_dir_ = DUMPSTATE_DIRECTORY; | 
|  | 432 |  | 
|  | 433 | // Full path of the temporary file containing the bugreport, inside bugreport_internal_dir_. | 
|  | 434 | // At the very end this file is pulled into the zip file. | 
| Felipe Leme | 9a523ae | 2016-10-20 15:10:33 -0700 | [diff] [blame] | 435 | std::string tmp_path_; | 
| Felipe Leme | 1d486fe | 2016-10-14 18:06:47 -0700 | [diff] [blame] | 436 |  | 
| Nandana Dutt | 979388e | 2018-11-30 16:48:55 +0000 | [diff] [blame] | 437 | // Full path of the file containing the dumpstate logs, inside bugreport_internal_dir_. | 
|  | 438 | // This is useful for debugging. | 
| Felipe Leme | 9a523ae | 2016-10-20 15:10:33 -0700 | [diff] [blame] | 439 | std::string log_path_; | 
| Felipe Leme | 1d486fe | 2016-10-14 18:06:47 -0700 | [diff] [blame] | 440 |  | 
| Nandana Dutt | 979388e | 2018-11-30 16:48:55 +0000 | [diff] [blame] | 441 | // Full path of the bugreport file, be it zip or text, inside bugreport_internal_dir_. | 
| Felipe Leme | 9a523ae | 2016-10-20 15:10:33 -0700 | [diff] [blame] | 442 | std::string path_; | 
| Felipe Leme | 1d486fe | 2016-10-14 18:06:47 -0700 | [diff] [blame] | 443 |  | 
| Nandana Dutt | 979388e | 2018-11-30 16:48:55 +0000 | [diff] [blame] | 444 | // TODO: If temporary this should be removed at the end. | 
|  | 445 | // Full path of the temporary file containing the screenshot (when requested). | 
|  | 446 | std::string screenshot_path_; | 
|  | 447 |  | 
| Felipe Leme | 1d486fe | 2016-10-14 18:06:47 -0700 | [diff] [blame] | 448 | // Pointer to the zipped file. | 
|  | 449 | std::unique_ptr<FILE, int (*)(FILE*)> zip_file{nullptr, fclose}; | 
|  | 450 |  | 
| Felipe Leme | c6bc8bc | 2016-10-27 15:58:27 -0700 | [diff] [blame] | 451 | // Pointer to the zip structure. | 
|  | 452 | std::unique_ptr<ZipWriter> zip_writer_; | 
|  | 453 |  | 
| Vishnu Nair | 20cf503 | 2018-01-05 13:15:49 -0800 | [diff] [blame] | 454 | // Binder object listening to progress. | 
| Felipe Leme | 75876a2 | 2016-10-27 16:31:27 -0700 | [diff] [blame] | 455 | android::sp<android::os::IDumpstateListener> listener_; | 
|  | 456 | std::string listener_name_; | 
| Vishnu Nair | 20cf503 | 2018-01-05 13:15:49 -0800 | [diff] [blame] | 457 | bool report_section_; | 
| Felipe Leme | 75876a2 | 2016-10-27 16:31:27 -0700 | [diff] [blame] | 458 |  | 
| Luis Hector Chavez | 91c2ae5 | 2018-03-14 15:12:46 -0700 | [diff] [blame] | 459 | // List of open tombstone dump files. | 
|  | 460 | std::vector<DumpData> tombstone_data_; | 
|  | 461 |  | 
|  | 462 | // List of open ANR dump files. | 
|  | 463 | std::vector<DumpData> anr_data_; | 
|  | 464 |  | 
| Nandana Dutt | d2f5f08 | 2019-01-18 17:13:52 +0000 | [diff] [blame] | 465 | // A callback to IncidentCompanion service, which checks user consent for sharing the | 
|  | 466 | // bugreport with the calling app. If the user has not responded yet to the dialog it will | 
|  | 467 | // be neither confirmed nor denied. | 
|  | 468 | class ConsentCallback : public android::os::BnIncidentAuthListener { | 
|  | 469 | public: | 
|  | 470 | ConsentCallback(); | 
|  | 471 | android::binder::Status onReportApproved() override; | 
|  | 472 | android::binder::Status onReportDenied() override; | 
|  | 473 |  | 
|  | 474 | enum ConsentResult { APPROVED, DENIED, UNAVAILABLE }; | 
|  | 475 |  | 
|  | 476 | ConsentResult getResult(); | 
|  | 477 |  | 
|  | 478 | // Returns the time since creating this listener | 
|  | 479 | uint64_t getElapsedTimeMs() const; | 
|  | 480 |  | 
|  | 481 | private: | 
|  | 482 | ConsentResult result_; | 
|  | 483 | uint64_t start_time_; | 
|  | 484 | std::mutex lock_; | 
|  | 485 | }; | 
|  | 486 |  | 
| Felipe Leme | e844a9d | 2016-09-21 15:01:39 -0700 | [diff] [blame] | 487 | private: | 
| Nandana Dutt | d2f5f08 | 2019-01-18 17:13:52 +0000 | [diff] [blame] | 488 | RunStatus RunInternal(int32_t calling_uid, const std::string& calling_package); | 
|  | 489 |  | 
|  | 490 | void CheckUserConsent(int32_t calling_uid, const android::String16& calling_package); | 
|  | 491 |  | 
|  | 492 | // Removes the in progress files output files (tmp file, zip/txt file, screenshot), | 
|  | 493 | // but leaves the log file alone. | 
|  | 494 | void CleanupFiles(); | 
|  | 495 |  | 
|  | 496 | RunStatus HandleUserConsentDenied(); | 
|  | 497 |  | 
|  | 498 | // Copies bugreport artifacts over to the caller's directories provided there is user consent. | 
|  | 499 | RunStatus CopyBugreportIfUserConsented(); | 
| Nandana Dutt | babf6c7 | 2019-01-15 14:11:12 +0000 | [diff] [blame] | 500 |  | 
| Felipe Leme | d80e6b6 | 2016-10-03 13:08:14 -0700 | [diff] [blame] | 501 | // Used by GetInstance() only. | 
| Chih-Hung Hsieh | d0937e6 | 2018-12-20 15:43:57 -0800 | [diff] [blame] | 502 | explicit Dumpstate(const std::string& version = VERSION_CURRENT); | 
| Felipe Leme | 062926e | 2016-10-27 15:51:12 -0700 | [diff] [blame] | 503 |  | 
| Nandana Dutt | d2f5f08 | 2019-01-18 17:13:52 +0000 | [diff] [blame] | 504 | android::sp<ConsentCallback> consent_callback_; | 
|  | 505 |  | 
| Felipe Leme | 062926e | 2016-10-27 15:51:12 -0700 | [diff] [blame] | 506 | DISALLOW_COPY_AND_ASSIGN(Dumpstate); | 
| Felipe Leme | e844a9d | 2016-09-21 15:01:39 -0700 | [diff] [blame] | 507 | }; | 
|  | 508 |  | 
|  | 509 | // for_each_pid_func = void (*)(int, const char*); | 
|  | 510 | // for_each_tid_func = void (*)(int, int, const char*); | 
|  | 511 |  | 
|  | 512 | typedef void(for_each_pid_func)(int, const char*); | 
|  | 513 | typedef void(for_each_tid_func)(int, int, const char*); | 
| Felipe Leme | 71ca15e | 2016-05-19 16:18:17 -0700 | [diff] [blame] | 514 |  | 
| Felipe Leme | 71a74ac | 2016-03-17 15:43:25 -0700 | [diff] [blame] | 515 | /* saves the the contents of a file as a long */ | 
|  | 516 | int read_file_as_long(const char *path, long int *output); | 
|  | 517 |  | 
| Christopher Ferris | 54bcc5f | 2015-02-10 12:15:01 -0800 | [diff] [blame] | 518 | /* prints the contents of the fd | 
|  | 519 | * fd must have been opened with the flag O_NONBLOCK. | 
|  | 520 | */ | 
| Christopher Ferris | 1fe6107 | 2014-07-22 16:08:19 -0700 | [diff] [blame] | 521 | int dump_file_from_fd(const char *title, const char *path, int fd); | 
| Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 522 |  | 
| Mark Salyzyn | 326842f | 2015-04-30 09:49:41 -0700 | [diff] [blame] | 523 | /* calls skip to gate calling dump_from_fd recursively | 
|  | 524 | * in the specified directory. dump_from_fd defaults to | 
|  | 525 | * dump_file_from_fd above when set to NULL. skip defaults | 
|  | 526 | * to false when set to NULL. dump_from_fd will always be | 
|  | 527 | * called with title NULL. | 
|  | 528 | */ | 
| Felipe Leme | 678727a | 2016-09-21 17:22:11 -0700 | [diff] [blame] | 529 | int dump_files(const std::string& title, const char* dir, bool (*skip)(const char* path), | 
|  | 530 | int (*dump_from_fd)(const char* title, const char* path, int fd)); | 
| Mark Salyzyn | 326842f | 2015-04-30 09:49:41 -0700 | [diff] [blame] | 531 |  | 
| Felipe Leme | 2628e9e | 2016-04-12 16:36:51 -0700 | [diff] [blame] | 532 | /** opens a socket and returns its file descriptor */ | 
|  | 533 | int open_socket(const char *service); | 
|  | 534 |  | 
| Nandana Dutt | a344cb6 | 2019-02-22 15:12:35 +0000 | [diff] [blame] | 535 | /* | 
|  | 536 | * Redirects 'redirect' to a service control socket. | 
|  | 537 | * | 
|  | 538 | * Returns true if redirect succeeds. | 
|  | 539 | */ | 
|  | 540 | bool redirect_to_socket(FILE* redirect, const char* service); | 
| Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 541 |  | 
| Nandana Dutt | a344cb6 | 2019-02-22 15:12:35 +0000 | [diff] [blame] | 542 | /* | 
|  | 543 | * Redirects 'redirect' to a file indicated by 'path', truncating it. | 
|  | 544 | * | 
|  | 545 | * Returns true if redirect succeeds. | 
|  | 546 | */ | 
|  | 547 | bool redirect_to_file(FILE* redirect, char* path); | 
| Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 548 |  | 
| Nandana Dutt | a344cb6 | 2019-02-22 15:12:35 +0000 | [diff] [blame] | 549 | /* | 
|  | 550 | * Redirects 'redirect' to an existing file indicated by 'path', appending it. | 
|  | 551 | * | 
|  | 552 | * Returns true if redirect succeeds. | 
|  | 553 | */ | 
|  | 554 | bool redirect_to_existing_file(FILE* redirect, char* path); | 
| Felipe Leme | 0f3fb20 | 2016-06-10 17:10:53 -0700 | [diff] [blame] | 555 |  | 
| Felipe Leme | 111b9d0 | 2016-02-03 09:28:24 -0800 | [diff] [blame] | 556 | /* create leading directories, if necessary */ | 
|  | 557 | void create_parent_dirs(const char *path); | 
|  | 558 |  | 
| Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 559 | /* for each process in the system, run the specified function */ | 
| Colin Cross | 0c22e8b | 2012-11-02 15:46:56 -0700 | [diff] [blame] | 560 | void for_each_pid(for_each_pid_func func, const char *header); | 
|  | 561 |  | 
|  | 562 | /* for each thread in the system, run the specified function */ | 
|  | 563 | void for_each_tid(for_each_tid_func func, const char *header); | 
| Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 564 |  | 
|  | 565 | /* Displays a blocked processes in-kernel wait channel */ | 
| Colin Cross | 0c22e8b | 2012-11-02 15:46:56 -0700 | [diff] [blame] | 566 | void show_wchan(int pid, int tid, const char *name); | 
| Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 567 |  | 
| Mark Salyzyn | a297c32 | 2016-02-05 15:33:17 -0800 | [diff] [blame] | 568 | /* Displays a processes times */ | 
|  | 569 | void show_showtime(int pid, const char *name); | 
|  | 570 |  | 
| Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 571 | /* Runs "showmap" for a process */ | 
|  | 572 | void do_showmap(int pid, const char *name); | 
|  | 573 |  | 
|  | 574 | /* Gets the dmesg output for the kernel */ | 
|  | 575 | void do_dmesg(); | 
|  | 576 |  | 
| Sreeram Ramachandran | 2b3bba3 | 2014-07-08 15:40:55 -0700 | [diff] [blame] | 577 | /* Prints the contents of all the routing tables, both IPv4 and IPv6. */ | 
|  | 578 | void dump_route_tables(); | 
|  | 579 |  | 
| Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 580 | /* Play a sound via Stagefright */ | 
| Christopher Ferris | 1fe6107 | 2014-07-22 16:08:19 -0700 | [diff] [blame] | 581 | void play_sound(const char *path); | 
| Colin Cross | f45fa6b | 2012-03-26 12:38:26 -0700 | [diff] [blame] | 582 |  | 
| Felipe Leme | 0c80cf0 | 2016-01-05 13:25:34 -0800 | [diff] [blame] | 583 | /* Checks if a given path is a directory. */ | 
|  | 584 | bool is_dir(const char* pathname); | 
|  | 585 |  | 
|  | 586 | /** Gets the last modification time of a file, or default time if file is not found. */ | 
|  | 587 | time_t get_mtime(int fd, time_t default_mtime); | 
|  | 588 |  | 
| Calvin On | 249beee | 2016-06-03 15:17:07 -0700 | [diff] [blame] | 589 | /* Dumps eMMC Extended CSD data. */ | 
| Felipe Leme | 78f2c86 | 2015-12-21 09:55:22 -0800 | [diff] [blame] | 590 | void dump_emmc_ecsd(const char *ext_csd_path); | 
|  | 591 |  | 
| Calvin On | 249beee | 2016-06-03 15:17:07 -0700 | [diff] [blame] | 592 | /** Gets command-line arguments. */ | 
| Felipe Leme | a34efb7 | 2016-03-11 09:33:32 -0800 | [diff] [blame] | 593 | void format_args(int argc, const char *argv[], std::string *args); | 
| Felipe Leme | 88c7933 | 2016-02-22 11:06:49 -0800 | [diff] [blame] | 594 |  | 
| Vishnu Nair | 20cf503 | 2018-01-05 13:15:49 -0800 | [diff] [blame] | 595 | /** Main entry point for dumpstate. */ | 
|  | 596 | int run_main(int argc, char* argv[]); | 
|  | 597 |  | 
| Felipe Leme | 8620bb4 | 2015-11-10 11:04:45 -0800 | [diff] [blame] | 598 | #ifdef __cplusplus | 
|  | 599 | } | 
|  | 600 | #endif | 
|  | 601 |  | 
| Felipe Leme | 8268ed2 | 2016-08-02 18:18:25 -0700 | [diff] [blame] | 602 | #endif /* FRAMEWORK_NATIVE_CMD_DUMPSTATE_H_ */ |