Accept a file descriptor to write bugreport file
This will be used via the bugreporting api.
Changed dumpstate to do bugreport generation in its own directory
in the beginning and to copy over to the destination fd or directory
at the very end.
BUG: 111441001
Test: adb bugreport
Test: adb shell /data/nativetest64/dumpstate_test/dumpstate_test
Test: interactive bugreport
Change-Id: I83e24f0989a202e84266b6e0fdf8edc14ea639bf
diff --git a/cmds/dumpstate/dumpstate.h b/cmds/dumpstate/dumpstate.h
index 35cbdb1..94e3191 100644
--- a/cmds/dumpstate/dumpstate.h
+++ b/cmds/dumpstate/dumpstate.h
@@ -142,7 +142,7 @@
float growth_factor_;
int32_t n_runs_;
int32_t average_max_;
- const std::string& path_;
+ std::string path_;
};
/*
@@ -164,6 +164,11 @@
static std::string VERSION_DEFAULT = "default";
/*
+ * Directory used by Dumpstate binary to keep its local files.
+ */
+static const std::string DUMPSTATE_DIRECTORY = "/bugreports";
+
+/*
* Structure that contains the information of an open dump file.
*/
struct DumpData {
@@ -300,7 +305,11 @@
*/
bool FinishZipFile();
- /* Gets the path of a bugreport file with the given suffix. */
+ /* Constructs a full path inside directory with file name formatted using the given suffix. */
+ std::string GetPath(const std::string& directory, const std::string& suffix) const;
+
+ /* Constructs a full path inside bugreport_internal_dir_ with file name formatted using the
+ * given suffix. */
std::string GetPath(const std::string& suffix) const;
/* Returns true if the current version supports priority dump feature. */
@@ -314,7 +323,6 @@
/* Sets runtime options. */
void SetOptions(std::unique_ptr<DumpOptions> options);
- // TODO: add other options from DumpState.
/*
* Structure to hold options that determine the behavior of dumpstate.
*/
@@ -333,6 +341,10 @@
bool wifi_only = false;
// Whether progress updates should be published.
bool do_progress_updates = false;
+ // File descriptor to output zip file. -1 indicates not set. Takes precedence over
+ // use_outfile.
+ int fd = -1;
+ // Partial path to output file.
std::string use_outfile;
// TODO: rename to MODE.
// Extra options passed as system property.
@@ -381,12 +393,6 @@
// Bugreport format version;
std::string version_ = VERSION_CURRENT;
- // Full path of the directory where the bugreport files will be written.
- std::string bugreport_dir_;
-
- // Full path of the temporary file containing the screenshot (when requested).
- std::string screenshot_path_;
-
time_t now_;
// Base name (without suffix or extensions) of the bugreport files, typically
@@ -397,15 +403,30 @@
// `-d`), but it could be changed by the user..
std::string name_;
- // Full path of the temporary file containing the bugreport.
+ std::string bugreport_internal_dir_ = DUMPSTATE_DIRECTORY;
+
+ // Full path of the temporary file containing the bugreport, inside bugreport_internal_dir_.
+ // At the very end this file is pulled into the zip file.
std::string tmp_path_;
- // Full path of the file containing the dumpstate logs.
+ // Full path of the file containing the dumpstate logs, inside bugreport_internal_dir_.
+ // This is useful for debugging.
std::string log_path_;
- // Pointer to the actual path, be it zip or text.
+ // Full path of the bugreport file, be it zip or text, inside bugreport_internal_dir_.
std::string path_;
+ // TODO: If temporary this should be removed at the end.
+ // Full path of the temporary file containing the screenshot (when requested).
+ std::string screenshot_path_;
+
+ // TODO(b/111441001): remove when obsolete.
+ // Full path of the final zip file inside the caller-specified directory, if available.
+ std::string final_path_;
+
+ // The caller-specified directory, if available.
+ std::string bugreport_dir_;
+
// Pointer to the zipped file.
std::unique_ptr<FILE, int (*)(FILE*)> zip_file{nullptr, fclose};