Generate code for AIDL defined string constants

Also validate that constant names are not duplicated between
integer and string constants.

Bug: 28233277
Test: Unittests expanded to reflect this change.
      Integration tests expanded to reflect this change.

Change-Id: If46619151cf6ff0146a2dfa90b863b096435a30a
diff --git a/aidl.cpp b/aidl.cpp
index d74c376..3602d1e 100644
--- a/aidl.cpp
+++ b/aidl.cpp
@@ -424,6 +424,32 @@
     return 0;
 }
 
+bool validate_constants(const AidlInterface& interface) {
+  bool success = true;
+  set<string> names;
+  for (const std::unique_ptr<AidlIntConstant>& int_constant :
+       interface.GetIntConstants()) {
+    if (names.count(int_constant->GetName()) > 0) {
+      LOG(ERROR) << "Found duplicate constant name '" << int_constant->GetName()
+                 << "'";
+      success = false;
+    }
+    names.insert(int_constant->GetName());
+  }
+  for (const std::unique_ptr<AidlStringConstant>& string_constant :
+       interface.GetStringConstants()) {
+    if (names.count(string_constant->GetName()) > 0) {
+      LOG(ERROR) << "Found duplicate constant name '" << string_constant->GetName()
+                 << "'";
+      success = false;
+    }
+    names.insert(string_constant->GetName());
+    // We've logged an error message for this on object construction.
+    success = success && string_constant->IsValid();
+  }
+  return success;
+}
+
 // TODO: Remove this in favor of using the YACC parser b/25479378
 bool ParsePreprocessedLine(const string& line, string* decl,
                            vector<string>* package, string* class_name) {
@@ -636,6 +662,9 @@
                                   interface->GetMethods()) != 0) {
     return AidlError::BAD_METHOD_ID;
   }
+  if (!validate_constants(*interface)) {
+    return AidlError::BAD_CONSTANTS;
+  }
 
   if (returned_interface)
     *returned_interface = std::move(interface);