OSDN Git Service

Allow broadcasting of bug reports without a screenshot.
authorFelipe Leme <felipeal@google.com>
Thu, 19 Nov 2015 23:41:04 +0000 (15:41 -0800)
committerFelipe Leme <felipeal@google.com>
Fri, 20 Nov 2015 19:12:58 +0000 (11:12 -0800)
BUG: 25751868
Change-Id: Ideaa6c549f639aa64b30225147b2fad6c5f2d556

cmds/dumpstate/dumpstate.cpp
cmds/dumpstate/dumpstate.h
cmds/dumpstate/utils.cpp

index b349a23..4703c2f 100644 (file)
@@ -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");
         }
index 25ae453..18ee168 100644 (file)
@@ -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();
 
index 585242e..4316c96 100644 (file)
@@ -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];