Streaming bugreport content to stdout 2/2
- Stream compressed content via the socket from dumpstate
- Remove do_zip_file, do_add_data vars in dumpstate
- getopt '-d' and '-z' options are now no-op
- Rename use_control_socket -> progress_updates_to_socket
- Rename use_socket -> stream_to_socket
do_zip_file and do_add_data are now default behaviors.
Also adding a function interface to hook dumpstate `open_socket`
function that would make it easy to do integration tests of streaming
zipped bugreport via socket. Stub the function and capture data from
target file to verify content.
Bug: 162910469
Test: adb bugreport --stream > test.zip; 7z t test.zip
Test: adb shell bugreportz -s > test.zip; 7z t test.zip
Test: atest dumpstate_test
Test: atest dumpstate_test:ZippedBugReportStreamTest
Test: atest dumpstate_smoke_test
Test: manually test combo keys voldown+volup+power to trigger bugreport
verify logcat kernel buffer shows "Starting service 'bugreport'
from keychord 114 115 116" and device viberated as expected
Change-Id: Icf79bbc42a5616e85625bd604e543fbf973911da
diff --git a/cmds/dumpstate/dumpstate.h b/cmds/dumpstate/dumpstate.h
index 9582c9d..efe06dc 100644
--- a/cmds/dumpstate/dumpstate.h
+++ b/cmds/dumpstate/dumpstate.h
@@ -54,6 +54,7 @@
class DumpstateTest;
class ProgressTest;
+class ZippedBugReportStreamTest;
} // namespace dumpstate
} // namespace os
@@ -197,6 +198,7 @@
*/
class Dumpstate {
friend class android::os::dumpstate::DumpstateTest;
+ friend class android::os::dumpstate::ZippedBugReportStreamTest;
public:
enum RunStatus { OK, HELP, INVALID_INPUT, ERROR, USER_CONSENT_DENIED, USER_CONSENT_TIMED_OUT };
@@ -388,12 +390,11 @@
* Structure to hold options that determine the behavior of dumpstate.
*/
struct DumpOptions {
- bool do_add_date = false;
- bool do_zip_file = false;
bool do_vibrate = true;
- // Writes bugreport content to a socket; only flatfile format is supported.
- bool use_socket = false;
- bool use_control_socket = false;
+ // Writes bugreport zipped file to a socket.
+ bool stream_to_socket = false;
+ // Writes generation progress updates to a socket.
+ bool progress_updates_to_socket = false;
bool do_screenshot = false;
bool is_screenshot_copied = false;
bool is_remote_mode = false;
@@ -434,13 +435,6 @@
/* Returns true if the options set so far are consistent. */
bool ValidateOptions() const;
- /* Returns if options specified require writing bugreport to a file */
- bool OutputToFile() const {
- // If we are not writing to socket, we will write to a file. If bugreport_fd is
- // specified, it is preferred. If not bugreport is written to /bugreports.
- return !use_socket;
- }
-
/* Returns if options specified require writing to custom file location */
bool OutputToCustomFile() {
// Custom location is only honored in limited mode.
@@ -466,7 +460,8 @@
std::unique_ptr<Progress> progress_;
- // When set, defines a socket file-descriptor use to report progress to bugreportz.
+ // When set, defines a socket file-descriptor use to report progress to bugreportz
+ // or to stream the zipped file to.
int control_socket_fd_ = -1;
// Bugreport format version;
@@ -478,8 +473,8 @@
// `bugreport-BUILD_ID`.
std::string base_name_;
- // Name is the suffix part of the bugreport files - it's typically the date (when invoked with
- // `-d`), but it could be changed by the user..
+ // Name is the suffix part of the bugreport files - it's typically the date,
+ // but it could be changed by the user..
std::string name_;
std::string bugreport_internal_dir_ = DUMPSTATE_DIRECTORY;
@@ -568,6 +563,8 @@
// called by Shell.
RunStatus CopyBugreportIfUserConsented(int32_t calling_uid);
+ std::function<int(const char *)> open_socket_fn_;
+
// Used by GetInstance() only.
explicit Dumpstate(const std::string& version = VERSION_CURRENT);
@@ -601,16 +598,6 @@
int dump_files(const std::string& title, const char* dir, bool (*skip)(const char* path),
int (*dump_from_fd)(const char* title, const char* path, int fd));
-/** opens a socket and returns its file descriptor */
-int open_socket(const char *service);
-
-/*
- * Redirects 'redirect' to a service control socket.
- *
- * Returns true if redirect succeeds.
- */
-bool redirect_to_socket(FILE* redirect, const char* service);
-
/*
* Redirects 'redirect' to a file indicated by 'path', truncating it.
*