Implement Pii Stripper Part 3

The incident request args sets privacy spec. Strip action is optimized
to run once for each type of spec and ready for flush multiple times.
Incident command is updated to take -p option to specify privacy spec.

Bug: 64687253
Test: unit tests written, manually run incident command to test as well
Change-Id: I6753df117f76dc1a5f4d2152baa3fbbf56b490e4
diff --git a/cmds/incident/main.cpp b/cmds/incident/main.cpp
index 47f1db8..519852d 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>
@@ -144,6 +145,16 @@
 }
 
 // ================================================================================
+static int
+get_dest(const char* arg)
+{
+    if (strcmp(arg, "LOCAL") == 0) return 0;
+    if (strcmp(arg, "EXPLICIT") == 0) return 1;
+    if (strcmp(arg, "AUTOMATIC") == 0) return 2;
+    return -1; // return the default value
+}
+
+// ================================================================================
 static void
 usage(FILE* out)
 {
@@ -155,6 +166,7 @@
     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");
@@ -166,10 +178,11 @@
     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, "bhdl")) != -1) {
+    while ((opt = getopt(argc, argv, "bhdlp:")) != -1) {
         switch (opt) {
             case 'h':
                 usage(stdout);
@@ -183,6 +196,9 @@
             case 'd':
                 destination = DEST_DROPBOX;
                 break;
+            case 'p':
+                dest = get_dest(optarg);
+                break;
             default:
                 usage(stderr);
                 return 1;
@@ -210,8 +226,7 @@
             }
         }
     }
-
-
+    args.setDest(dest);
 
     // Start the thread pool.
     sp<ProcessState> ps(ProcessState::self());