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

Commit 36b3f6ff authored by Felipe Leme's avatar Felipe Leme
Browse files

Allow broadcasting of bug reports without a screenshot.

BUG: 25751868
Change-Id: Ideaa6c549f639aa64b30225147b2fad6c5f2d556
parent 2b6afaa3
Loading
Loading
Loading
Loading
+13 −9
Original line number Diff line number Diff line
@@ -601,7 +601,7 @@ static void usage() {
            "  -b: play sound file instead of vibrate, at beginning of job\n"
            "  -e: play sound file instead of vibrate, at end of job\n"
            "  -q: disable vibrate\n"
            "  -B: send broadcast when finished (requires -o and -p)\n"
            "  -B: send broadcast when finished (requires -o)\n"
                );
}

@@ -729,7 +729,7 @@ int main(int argc, char *argv[]) {
        }
    }

    if ((do_zip_file || do_add_date) && !use_outfile) {
    if ((do_zip_file || do_add_date || do_broadcast) && !use_outfile) {
        usage();
        exit(1);
    }
@@ -870,15 +870,19 @@ int main(int argc, char *argv[]) {
    }

    /* tell activity manager we're done */
    if (do_broadcast && use_outfile && do_fb) {
    if (do_broadcast && use_outfile) {
        if (!path.empty()) {
            ALOGI("Final bugreport path: %s\n", path.c_str());
            const char *args[] = { "/system/bin/am", "broadcast", "--user", "0",
                  "-a", "android.intent.action.BUGREPORT_FINISHED",
                  "--es", "android.intent.extra.BUGREPORT", path.c_str(),
                  "--es", "android.intent.extra.SCREENSHOT", screenshot_path.c_str(),
                  "--receiver-permission", "android.permission.DUMP", NULL };
            run_command_always(NULL, 5, args);
            std::vector<std::string> am_args = {
                 "--receiver-permission", "android.permission.DUMP",
                 "--es", "android.intent.extra.BUGREPORT", path
            };
            if (do_fb) {
                am_args.push_back("--es");
                am_args.push_back("android.intent.extra.SCREENSHOT");
                am_args.push_back(screenshot_path);
            }
            send_broadcast("android.intent.action.BUGREPORT_FINISHED", am_args);
        } else {
            ALOGE("Skipping broadcast because bugreport could not be generated\n");
        }
+4 −0
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@
#include <unistd.h>
#include <stdbool.h>
#include <stdio.h>
#include <vector>

#define SU_PATH "/system/xbin/su"

@@ -70,6 +71,9 @@ int run_command(const char *title, int timeout_seconds, const char *command, ...
   command is always ran, even when _DUMPSTATE_DRY_RUN_ is defined. */
int run_command_always(const char *title, int timeout_seconds, const char *args[]);

/* sends a broadcast using Activity Manager */
void send_broadcast(const std::string& action, const std::vector<std::string>& args);

/* prints all the system properties */
void print_properties();

+19 −1
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <string.h>
#include <sys/inotify.h>
#include <sys/stat.h>
@@ -31,6 +32,7 @@
#include <sys/klog.h>
#include <time.h>
#include <unistd.h>
#include <vector>
#include <sys/prctl.h>

#include <cutils/debugger.h>
@@ -477,8 +479,8 @@ int run_command(const char *title, int timeout_seconds, const char *command, ...

/* forks a command and waits for it to finish */
int run_command_always(const char *title, int timeout_seconds, const char *args[]) {
    const char *command = args[0];

    const char *command = args[0];
    uint64_t start = nanotime();
    pid_t pid = fork();

@@ -538,6 +540,22 @@ int run_command_always(const char *title, int timeout_seconds, const char *args[
    return status;
}

void send_broadcast(const std::string& action, const std::vector<std::string>& args) {
    if (args.size() > 1000) {
        fprintf(stderr, "send_broadcast: too many arguments (%d)\n", args.size());
        return;
    }
    const char *am_args[1024] = { "/system/bin/am", "broadcast", "--user", "0",
                                  "-a", action.c_str() };
    size_t am_index = 5; // Starts at the index of last initial value above.
    for (const std::string& arg : args) {
        am_args[++am_index] = arg.c_str();
    }
    // Always terminate with NULL.
    am_args[am_index + 1] = NULL;
    run_command_always(NULL, 5, am_args);
}

size_t num_props = 0;
static char* props[2000];