Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit aabfcae8 authored by Felipe Leme's avatar Felipe Leme
Browse files

Added a BEGIN:path message on bugreportz protocol.

BUG: 30451114
Change-Id: I3607c75b184e71a9a5a6393bdbf68200abe0fc16
parent ba5c79ab
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -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);
}
+3 −0
Original line number Diff line number Diff line
@@ -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.
@@ -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");
@@ -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"
+5 −3
Original line number Diff line number Diff line
@@ -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
+7 −0
Original line number Diff line number Diff line
@@ -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());
            }
        }
    }

@@ -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),
@@ -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");