Generate constants for enum values.

Test: Builds successfully, tests pass and statsd works (it seems).

This will allow us to use those constants instead of literals.
The generated code only augmentes the java constant file.
If needed, the same can be done for the C++ file.
Some of the constant names are very long, but this is due to enum value names that are unnecessarily redundant with the enum names, i.e.
enum ENUM_NAME {
  ENUM_NAME_UNKNOWN = 0;
  ENUM_NAME_VALUE1 = 1;
  ENUM_NAME_VALUE2 = 2;
  ...
}
which can be fixed by avoiding the 'ENUM_NAME_' part in the value names above.
So, when possible, we should use shorter value names in stats_events.proto.

Change-Id: I1ad19b86e28d0df0f8c15d4c995d101423cff4c2
diff --git a/tools/stats_log_api_gen/main.cpp b/tools/stats_log_api_gen/main.cpp
index aaea4f6..6350b72 100644
--- a/tools/stats_log_api_gen/main.cpp
+++ b/tools/stats_log_api_gen/main.cpp
@@ -56,6 +56,7 @@
         case JAVA_TYPE_BOOLEAN:
             return "bool";
         case JAVA_TYPE_INT:
+        case JAVA_TYPE_ENUM:
             return "int32_t";
         case JAVA_TYPE_LONG:
             return "int64_t";
@@ -77,6 +78,7 @@
         case JAVA_TYPE_BOOLEAN:
             return "boolean";
         case JAVA_TYPE_INT:
+        case JAVA_TYPE_ENUM:
             return "int";
         case JAVA_TYPE_LONG:
             return "long";
@@ -173,7 +175,7 @@
     fprintf(out, " */\n");
     fprintf(out, "\n");
     fprintf(out, "/**\n");
-    fprintf(out, " * Constants for event codes.\n");
+    fprintf(out, " * Constants for atom codes.\n");
     fprintf(out, " */\n");
     fprintf(out, "enum {\n");
 
@@ -240,9 +242,9 @@
     fprintf(out, " * @hide\n");
     fprintf(out, " */\n");
     fprintf(out, "public final class StatsLog {\n");
-    fprintf(out, "    // Constants for event codes.\n");
+    fprintf(out, "    // Constants for atom codes.\n");
 
-    // Print constants
+    // Print constants for the atom codes.
     for (set<AtomDecl>::const_iterator atom = atoms.decls.begin();
             atom != atoms.decls.end(); atom++) {
         string constant = make_constant_name(atom->name);
@@ -260,6 +262,27 @@
     }
     fprintf(out, "\n");
 
+    // Print constants for the enum values.
+    fprintf(out, "    // Constants for enum values.\n\n");
+    for (set<AtomDecl>::const_iterator atom = atoms.decls.begin();
+            atom != atoms.decls.end(); atom++) {
+        for (vector<AtomField>::const_iterator field = atom->fields.begin();
+                field != atom->fields.end(); field++) {
+          if (field->javaType == JAVA_TYPE_ENUM) {
+            fprintf(out, "    // Values for %s.%s\n", atom->message.c_str(), field->name.c_str());
+            for (map<int, string>::const_iterator value = field->enumValues.begin();
+                 value != field->enumValues.end(); value++) {
+              fprintf(out, "    public static final int %s__%s__%s = %d;\n",
+                      make_constant_name(atom->message).c_str(),
+                      make_constant_name(field->name).c_str(),
+                      make_constant_name(value->second).c_str(),
+                      value->first);
+            }
+            fprintf(out, "\n");
+          }
+        }
+    }
+
     // Print write methods
     fprintf(out, "    // Write methods\n");
     for (set<vector<java_type_t>>::const_iterator signature = atoms.signatures.begin();
@@ -286,6 +309,7 @@
         case JAVA_TYPE_BOOLEAN:
             return "jboolean";
         case JAVA_TYPE_INT:
+        case JAVA_TYPE_ENUM:
             return "jint";
         case JAVA_TYPE_LONG:
             return "jlong";
@@ -311,6 +335,7 @@
                 result += "_boolean";
                 break;
             case JAVA_TYPE_INT:
+            case JAVA_TYPE_ENUM:
                 result += "_int";
                 break;
             case JAVA_TYPE_LONG:
@@ -340,6 +365,7 @@
         case JAVA_TYPE_BOOLEAN:
             return "Z";
         case JAVA_TYPE_INT:
+        case JAVA_TYPE_ENUM:
             return "I";
         case JAVA_TYPE_LONG:
             return "J";