#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);
}
// 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.
// 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");
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"
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
}
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());
+ }
}
}
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),
"--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");