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/Collation.cpp b/tools/stats_log_api_gen/Collation.cpp
index 5d29268..f76196d 100644
--- a/tools/stats_log_api_gen/Collation.cpp
+++ b/tools/stats_log_api_gen/Collation.cpp
@@ -22,6 +22,7 @@
 namespace android {
 namespace stats_log_api_gen {
 
+using google::protobuf::EnumDescriptor;
 using google::protobuf::FieldDescriptor;
 using google::protobuf::FileDescriptor;
 using google::protobuf::SourceLocation;
@@ -120,7 +121,7 @@
         case FieldDescriptor::TYPE_UINT32:
             return JAVA_TYPE_INT;
         case FieldDescriptor::TYPE_ENUM:
-            return JAVA_TYPE_INT;
+            return JAVA_TYPE_ENUM;
         case FieldDescriptor::TYPE_SFIXED32:
             return JAVA_TYPE_INT;
         case FieldDescriptor::TYPE_SFIXED64:
@@ -208,7 +209,6 @@
                 errorCount++;
                 continue;
             }
-
         }
 
         // Check that if there's a WorkSource, it's at position 1.
@@ -228,15 +228,26 @@
 
         AtomDecl atomDecl(atomField->number(), atomField->name(), atom->name());
 
-        // Build the type signature
+        // Build the type signature and the atom data.
         vector<java_type_t> signature;
         for (map<int,const FieldDescriptor*>::const_iterator it = fields.begin();
                 it != fields.end(); it++) {
             const FieldDescriptor* field = it->second;
             java_type_t javaType = java_type(field);
 
-            atomDecl.fields.push_back(AtomField(field->name(), javaType));
-            signature.push_back(javaType);
+            AtomField atField(field->name(), javaType);
+            if (javaType == JAVA_TYPE_ENUM) {
+                // All enums are treated as ints when it comes to function signatures.
+                signature.push_back(JAVA_TYPE_INT);
+                const EnumDescriptor* enumDescriptor = field->enum_type();
+                for (int i = 0; i < enumDescriptor->value_count(); i++) {
+                    atField.enumValues[enumDescriptor->value(i)->number()] =
+                        enumDescriptor->value(i)->name().c_str();
+                }
+            } else {
+                signature.push_back(javaType);
+            }
+            atomDecl.fields.push_back(atField);
         }
 
         atoms->signatures.insert(signature);
@@ -261,5 +272,3 @@
 
 }  // namespace stats_log_api_gen
 }  // namespace android
-
-