Streaming bugreport content to stdout 1/2
Add a -s option to bugreportz to support streaming data.
Bug: 162910469
Test: adb bugreport --stream > test.txt
Test: adb shell bugreportz -s > test2.txt
Test: atest dumpstate_test
Test: atest bugreportz_test
Change-Id: I33d68bf742c92a7359a925838827a0033ee68658
diff --git a/cmds/bugreportz/main.cpp b/cmds/bugreportz/main.cpp
index 1d48e08..cd2652c 100644
--- a/cmds/bugreportz/main.cpp
+++ b/cmds/bugreportz/main.cpp
@@ -26,13 +26,14 @@
#include "bugreportz.h"
-static constexpr char VERSION[] = "1.1";
+static constexpr char VERSION[] = "1.2";
static void show_usage() {
fprintf(stderr,
- "usage: bugreportz [-hpv]\n"
+ "usage: bugreportz [-hpsv]\n"
" -h: to display this help message\n"
" -p: display progress\n"
+ " -s: stream content to standard output\n"
" -v: to display the version\n"
" or no arguments to generate a zipped bugreport\n");
}
@@ -43,10 +44,11 @@
int main(int argc, char* argv[]) {
bool show_progress = false;
+ bool stream_data = false;
if (argc > 1) {
/* parse arguments */
int c;
- while ((c = getopt(argc, argv, "hpv")) != -1) {
+ while ((c = getopt(argc, argv, "hpsv")) != -1) {
switch (c) {
case 'h':
show_usage();
@@ -54,6 +56,9 @@
case 'p':
show_progress = true;
break;
+ case 's':
+ stream_data = true;
+ break;
case 'v':
show_version();
return EXIT_SUCCESS;
@@ -75,7 +80,11 @@
// should be reused instead.
// Start the dumpstatez service.
- property_set("ctl.start", "dumpstatez");
+ if (stream_data) {
+ property_set("ctl.start", "dumpstate");
+ } else {
+ property_set("ctl.start", "dumpstatez");
+ }
// Socket will not be available until service starts.
int s = -1;
@@ -103,7 +112,12 @@
strerror(errno));
}
- int ret = bugreportz(s, show_progress);
+ int ret;
+ if (stream_data) {
+ ret = bugreportz_stream(s);
+ } else {
+ ret = bugreportz(s, show_progress);
+ }
if (close(s) == -1) {
fprintf(stderr, "WARNING: error closing socket: %s\n", strerror(errno));