Fixes regarding to comments in ag/2839267

1. use struct {} to instantiate privacy fields for efficiency reason
2. use vector<uint8_t>* instead of vector<uint8_t>& to indicate the
caller knows the value gets changed.
3. binary search privay policy for sections

Bug: 65595927
Test: unit test covers
Change-Id: Ic58c2f607465d1a7f10352b9a38c3d8b1a5cf352
diff --git a/tools/incident_section_gen/main.cpp b/tools/incident_section_gen/main.cpp
index 7966d88..900690c 100644
--- a/tools/incident_section_gen/main.cpp
+++ b/tools/incident_section_gen/main.cpp
@@ -135,7 +135,7 @@
                 if (generatePrivacyFlags(field->message_type(), field_name, msgNames) &&
                     isDefaultDest(field)) break;
 
-                printf("Privacy %s(%d, %s_LIST);\n", field_name, field->number(), field_name);
+                printf("Privacy %s { %d, %d, %s_LIST, %d, NULL };\n", field_name, field->number(), field->type(), field_name, p.dest());
                 hasDefaultFlags[i] = false;
                 break;
             case FieldDescriptor::TYPE_STRING:
@@ -147,12 +147,12 @@
                     printf("    \"%s\",\n", replaceAll(p.patterns(i), '\\', "\\\\").c_str());
                 }
                 printf("    NULL };\n");
-                printf("Privacy %s(%d, %d, %s_patterns);\n", field_name, field->number(), p.dest(), field_name);
+                printf("Privacy %s { %d, %d, NULL, %d, %s_patterns };\n", field_name, field->number(), field->type(), p.dest(), field_name);
                 hasDefaultFlags[i] = false;
                 break;
             default:
                 if (isDefaultDest(field)) break;
-                printf("Privacy %s(%d, %d, %d);\n", field_name, field->number(), (int) field->type(), p.dest());
+                printf("Privacy %s { %d, %d, NULL, %d, NULL };\n", field_name, field->number(), field->type(), p.dest());
                 hasDefaultFlags[i] = false;
         }
         // add the field name to message map, true means it has default flags
@@ -166,13 +166,23 @@
     if (allDefaults) return true;
 
     emptyline();
-    printf("const Privacy* %s_LIST[] = {\n", alias);
+
+    bool needConst = strcmp(alias, "PRIVACY_POLICY") == 0;
+    int policyCount = 0;
+
+    printf("%s Privacy* %s_LIST[] = {\n", needConst ? "const" : "", alias);
     for (int i=0; i<descriptor->field_count(); i++) {
         const FieldDescriptor* field = descriptor->field(i);
         if (hasDefaultFlags[i]) continue;
         printf("    &%s,\n", replaceAll(field->full_name(), '.', "__").c_str());
+        policyCount++;
     }
-    printf("    NULL };\n");
+    if (needConst) {
+        printf("};\n\n");
+        printf("const int PRIVACY_POLICY_COUNT = %d;\n", policyCount);
+    } else {
+        printf("    NULL };\n");
+    }
     emptyline();
     return false;
 }
@@ -214,7 +224,8 @@
     map<string, bool> messageNames;
     if (generatePrivacyFlags(descriptor, "PRIVACY_POLICY", messageNames)) {
         // if no privacy options set at all, define an empty list
-        printf("const Privacy* PRIVACY_POLICY_LIST[] = { NULL };\n");
+        printf("const Privacy* PRIVACY_POLICY_LIST[] = {};\n");
+        printf("const int PRIVACY_POLICY_COUNT = 0;\n");
     }
 
     return true;