Skip to content

Commit

Permalink
Added a BEGIN:path message on bugreportz protocol.
Browse files Browse the repository at this point in the history
BUG: 30451114
Change-Id: I3607c75b184e71a9a5a6393bdbf68200abe0fc16
  • Loading branch information
the-felipeal committed Aug 1, 2016
1 parent ba5c79a commit aabfcae
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
7 changes: 5 additions & 2 deletions cmds/bugreportz/bugreportz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,17 @@

#include "bugreportz.h"

static constexpr char BEGIN_PREFIX[] = "BEGIN:";
static constexpr char PROGRESS_PREFIX[] = "PROGRESS:";

static void write_line(const std::string& line, bool show_progress) {
if (line.empty()) return;

// When not invoked with the -p option, it must skip PROGRESS lines otherwise it
// When not invoked with the -p option, it must skip BEGIN and PROGRESS lines otherwise it
// will break adb (which is expecting either OK or FAIL).
if (!show_progress && android::base::StartsWith(line, PROGRESS_PREFIX)) return;
if (!show_progress && (android::base::StartsWith(line, PROGRESS_PREFIX) ||
android::base::StartsWith(line, BEGIN_PREFIX)))
return;

android::base::WriteStringToFd(line, STDOUT_FILENO);
}
Expand Down
3 changes: 3 additions & 0 deletions cmds/bugreportz/bugreportz_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class BugreportzTest : public ::testing::Test {

// Tests 'bugreportz', without any argument - it will ignore progress lines.
TEST_F(BugreportzTest, NoArgument) {
WriteToSocket("BEGIN:THE IGNORED PATH WARS HAS!\n"); // Should be ommited.
WriteToSocket("What happens on 'dumpstate',");
WriteToSocket("stays on 'bugreportz'.\n");
WriteToSocket("PROGRESS:Y U NO OMITTED?\n"); // Should be ommited.
Expand All @@ -108,6 +109,7 @@ TEST_F(BugreportzTest, NoArgument) {

// Tests 'bugreportz -p' - it will just echo dumpstate's output to stdout
TEST_F(BugreportzTest, WithProgress) {
WriteToSocket("BEGIN:I AM YOUR PATH\n");
WriteToSocket("What happens on 'dumpstate',");
WriteToSocket("stays on 'bugreportz'.\n");
WriteToSocket("PROGRESS:IS INEVITABLE\n");
Expand All @@ -118,6 +120,7 @@ TEST_F(BugreportzTest, WithProgress) {
Bugreportz(true);

AssertStdoutEquals(
"BEGIN:I AM YOUR PATH\n"
"What happens on 'dumpstate',stays on 'bugreportz'.\n"
"PROGRESS:IS INEVITABLE\n"
"PROGRESS:IS NOT AUTOMATIC\n"
Expand Down
8 changes: 5 additions & 3 deletions cmds/bugreportz/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
the simple protocol defined below.

# Version 1.1
On version 1.1, in addition to the `OK` and `FAILURE` lines, `bugreportz -p` generates progress
lines in the following format:
On version 1.1, in addition to the `OK` and `FAILURE` lines, when `bugreportz` is invoked with
`-p`, it outputs the following lines:

- `PROGRESS:<progress>/<total>`, where `<progress>` is the current progress units out of a max of `<total>`.
- `BEGIN:<path_to_bugreport_file>` right away.
- `PROGRESS:<progress>/<total>` as `dumpstate` progresses (where `<progress>` is the current
progress units out of a max of `<total>`).

## Version 1.0
On version 1.0, `bugreportz` does not generate any output on `stdout` until the bugreport is
Expand Down
7 changes: 7 additions & 0 deletions cmds/dumpstate/dumpstate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1270,14 +1270,19 @@ int main(int argc, char *argv[]) {
}

if (do_update_progress && do_broadcast) {
// clang-format off
std::vector<std::string> am_args = {
"--receiver-permission", "android.permission.DUMP", "--receiver-foreground",
"--es", "android.intent.extra.NAME", suffix,
"--ei", "android.intent.extra.ID", std::to_string(id),
"--ei", "android.intent.extra.PID", std::to_string(getpid()),
"--ei", "android.intent.extra.MAX", std::to_string(WEIGHT_TOTAL),
// clang-format on
};
send_broadcast("android.intent.action.BUGREPORT_STARTED", am_args);
if (use_control_socket) {
dprintf(control_socket_fd, "BEGIN:%s\n", path.c_str());
}
}
}

Expand Down Expand Up @@ -1460,6 +1465,7 @@ int main(int argc, char *argv[]) {
if (do_broadcast) {
if (!path.empty()) {
MYLOGI("Final bugreport path: %s\n", path.c_str());
// clang-format off
std::vector<std::string> am_args = {
"--receiver-permission", "android.permission.DUMP", "--receiver-foreground",
"--ei", "android.intent.extra.ID", std::to_string(id),
Expand All @@ -1468,6 +1474,7 @@ int main(int argc, char *argv[]) {
"--es", "android.intent.extra.BUGREPORT", path,
"--es", "android.intent.extra.DUMPSTATE_LOG", log_path
};
// clang-format on
if (do_fb) {
am_args.push_back("--es");
am_args.push_back("android.intent.extra.SCREENSHOT");
Expand Down

0 comments on commit aabfcae

Please sign in to comment.