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

Commit 8329e4cd authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Added a BEGIN:path message on bugreportz protocol." into nyc-mr1-dev

parents f9d4e44f aabfcae8
Loading
Loading
Loading
Loading
+5 −2
Original line number Original line Diff line number Diff line
@@ -27,14 +27,17 @@


#include "bugreportz.h"
#include "bugreportz.h"


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


static void write_line(const std::string& line, bool show_progress) {
static void write_line(const std::string& line, bool show_progress) {
    if (line.empty()) return;
    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).
    // 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);
    android::base::WriteStringToFd(line, STDOUT_FILENO);
}
}
+3 −0
Original line number Original line Diff line number Diff line
@@ -92,6 +92,7 @@ class BugreportzTest : public ::testing::Test {


// Tests 'bugreportz', without any argument - it will ignore progress lines.
// Tests 'bugreportz', without any argument - it will ignore progress lines.
TEST_F(BugreportzTest, NoArgument) {
TEST_F(BugreportzTest, NoArgument) {
    WriteToSocket("BEGIN:THE IGNORED PATH WARS HAS!\n");  // Should be ommited.
    WriteToSocket("What happens on 'dumpstate',");
    WriteToSocket("What happens on 'dumpstate',");
    WriteToSocket("stays on 'bugreportz'.\n");
    WriteToSocket("stays on 'bugreportz'.\n");
    WriteToSocket("PROGRESS:Y U NO OMITTED?\n");  // Should be ommited.
    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
// Tests 'bugreportz -p' - it will just echo dumpstate's output to stdout
TEST_F(BugreportzTest, WithProgress) {
TEST_F(BugreportzTest, WithProgress) {
    WriteToSocket("BEGIN:I AM YOUR PATH\n");
    WriteToSocket("What happens on 'dumpstate',");
    WriteToSocket("What happens on 'dumpstate',");
    WriteToSocket("stays on 'bugreportz'.\n");
    WriteToSocket("stays on 'bugreportz'.\n");
    WriteToSocket("PROGRESS:IS INEVITABLE\n");
    WriteToSocket("PROGRESS:IS INEVITABLE\n");
@@ -118,6 +120,7 @@ TEST_F(BugreportzTest, WithProgress) {
    Bugreportz(true);
    Bugreportz(true);


    AssertStdoutEquals(
    AssertStdoutEquals(
        "BEGIN:I AM YOUR PATH\n"
        "What happens on 'dumpstate',stays on 'bugreportz'.\n"
        "What happens on 'dumpstate',stays on 'bugreportz'.\n"
        "PROGRESS:IS INEVITABLE\n"
        "PROGRESS:IS INEVITABLE\n"
        "PROGRESS:IS NOT AUTOMATIC\n"
        "PROGRESS:IS NOT AUTOMATIC\n"
+5 −3
Original line number Original line Diff line number Diff line
@@ -4,10 +4,12 @@
the simple protocol defined below.
the simple protocol defined below.


# Version 1.1
# Version 1.1
On version 1.1, in addition to the `OK` and `FAILURE` lines, `bugreportz -p` generates progress
On version 1.1, in addition to the `OK` and `FAILURE` lines, when `bugreportz` is invoked with
lines in the following format:
`-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
## Version 1.0
On version 1.0, `bugreportz` does not generate any output on `stdout` until the bugreport is
On version 1.0, `bugreportz` does not generate any output on `stdout` until the bugreport is
+7 −0
Original line number Original line Diff line number Diff line
@@ -1270,14 +1270,19 @@ int main(int argc, char *argv[]) {
        }
        }


        if (do_update_progress && do_broadcast) {
        if (do_update_progress && do_broadcast) {
            // clang-format off
            std::vector<std::string> am_args = {
            std::vector<std::string> am_args = {
                 "--receiver-permission", "android.permission.DUMP", "--receiver-foreground",
                 "--receiver-permission", "android.permission.DUMP", "--receiver-foreground",
                 "--es", "android.intent.extra.NAME", suffix,
                 "--es", "android.intent.extra.NAME", suffix,
                 "--ei", "android.intent.extra.ID", std::to_string(id),
                 "--ei", "android.intent.extra.ID", std::to_string(id),
                 "--ei", "android.intent.extra.PID", std::to_string(getpid()),
                 "--ei", "android.intent.extra.PID", std::to_string(getpid()),
                 "--ei", "android.intent.extra.MAX", std::to_string(WEIGHT_TOTAL),
                 "--ei", "android.intent.extra.MAX", std::to_string(WEIGHT_TOTAL),
            // clang-format on
            };
            };
            send_broadcast("android.intent.action.BUGREPORT_STARTED", am_args);
            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 (do_broadcast) {
        if (!path.empty()) {
        if (!path.empty()) {
            MYLOGI("Final bugreport path: %s\n", path.c_str());
            MYLOGI("Final bugreport path: %s\n", path.c_str());
            // clang-format off
            std::vector<std::string> am_args = {
            std::vector<std::string> am_args = {
                 "--receiver-permission", "android.permission.DUMP", "--receiver-foreground",
                 "--receiver-permission", "android.permission.DUMP", "--receiver-foreground",
                 "--ei", "android.intent.extra.ID", std::to_string(id),
                 "--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.BUGREPORT", path,
                 "--es", "android.intent.extra.DUMPSTATE_LOG", log_path
                 "--es", "android.intent.extra.DUMPSTATE_LOG", log_path
            };
            };
            // clang-format on
            if (do_fb) {
            if (do_fb) {
                am_args.push_back("--es");
                am_args.push_back("--es");
                am_args.push_back("android.intent.extra.SCREENSHOT");
                am_args.push_back("android.intent.extra.SCREENSHOT");