summaryrefslogtreecommitdiff
path: root/cmds/incident/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cmds/incident/main.cpp')
-rw-r--r--cmds/incident/main.cpp69
1 files changed, 63 insertions, 6 deletions
diff --git a/cmds/incident/main.cpp b/cmds/incident/main.cpp
index 91b7c22b2038..cdec6a01d086 100644
--- a/cmds/incident/main.cpp
+++ b/cmds/incident/main.cpp
@@ -25,6 +25,7 @@
#include <binder/IServiceManager.h>
#include <utils/Looper.h>
+#include <cstring>
#include <fcntl.h>
#include <getopt.h>
#include <stdio.h>
@@ -94,6 +95,33 @@ StatusListener::onReportFailed()
}
// ================================================================================
+static void section_list(FILE* out) {
+ IncidentSection sections[INCIDENT_SECTION_COUNT];
+ int i = 0;
+ int j = 0;
+ // sort the sections based on id
+ while (i < INCIDENT_SECTION_COUNT) {
+ IncidentSection curr = INCIDENT_SECTIONS[i];
+ for (int k = 0; k < j; k++) {
+ if (curr.id > sections[k].id) {
+ continue;
+ }
+ IncidentSection tmp = curr;
+ curr = sections[k];
+ sections[k] = tmp;
+ }
+ sections[j] = curr;
+ i++;
+ j++;
+ }
+
+ fprintf(out, "available sections:\n");
+ for (int i = 0; i < INCIDENT_SECTION_COUNT; ++i) {
+ fprintf(out, "id: %4d, name: %s\n", sections[i].id, sections[i].name);
+ }
+}
+
+// ================================================================================
static IncidentSection const*
find_section(const char* name)
{
@@ -117,6 +145,26 @@ find_section(const char* name)
}
// ================================================================================
+static int
+get_dest(const char* arg)
+{
+ if (strcmp(arg, "L") == 0
+ || strcmp(arg, "LOCAL") == 0) {
+ return DEST_LOCAL;
+ }
+ if (strcmp(arg, "E") == 0
+ || strcmp(arg, "EXPLICIT") == 0) {
+ return DEST_EXPLICIT;
+ }
+ if (strcmp(arg, "A") == 0
+ || strcmp(arg, "AUTO") == 0
+ || strcmp(arg, "AUTOMATIC") == 0) {
+ return DEST_AUTOMATIC;
+ }
+ return -1; // return the default value
+}
+
+// ================================================================================
static void
usage(FILE* out)
{
@@ -127,6 +175,8 @@ usage(FILE* out)
fprintf(out, "OPTIONS\n");
fprintf(out, " -b (default) print the report to stdout (in proto format)\n");
fprintf(out, " -d send the report into dropbox\n");
+ fprintf(out, " -l list available sections\n");
+ fprintf(out, " -p privacy spec, LOCAL, EXPLICIT or AUTOMATIC\n");
fprintf(out, "\n");
fprintf(out, " SECTION the field numbers of the incident report fields to include\n");
fprintf(out, "\n");
@@ -138,20 +188,27 @@ main(int argc, char** argv)
Status status;
IncidentReportArgs args;
enum { DEST_DROPBOX, DEST_STDOUT } destination = DEST_STDOUT;
+ int dest = -1; // default
// Parse the args
int opt;
- while ((opt = getopt(argc, argv, "bhd")) != -1) {
+ while ((opt = getopt(argc, argv, "bhdlp:")) != -1) {
switch (opt) {
- case 'b':
- destination = DEST_STDOUT;
- break;
case 'h':
usage(stdout);
return 0;
+ case 'l':
+ section_list(stdout);
+ return 0;
+ case 'b':
+ destination = DEST_STDOUT;
+ break;
case 'd':
destination = DEST_DROPBOX;
break;
+ case 'p':
+ dest = get_dest(optarg);
+ break;
default:
usage(stderr);
return 1;
@@ -179,8 +236,7 @@ main(int argc, char** argv)
}
}
}
-
-
+ args.setDest(dest);
// Start the thread pool.
sp<ProcessState> ps(ProcessState::self());
@@ -209,6 +265,7 @@ main(int argc, char** argv)
if (!status.isOk()) {
fprintf(stderr, "reportIncident returned \"%s\"\n", status.toString8().string());
+ return 1;
}
// Wait for the result and print out the data they send.