AAPT2: Allow arbitrary entry names with aapt2 optimize

Presumably, the apps build fine for the developers, so just
feed the existing names through without validation. Validation
still exists when building an app from source.

Bug: 36051854
Change-Id: Idc64ee91b08dce67d3c28f3c5284a7afa1312df1
Test: run aapt2 optimize on the apks from b/36051854 and build aapt2_tests
diff --git a/tools/aapt2/ResourceTable.h b/tools/aapt2/ResourceTable.h
index 6b69aaf..b032121 100644
--- a/tools/aapt2/ResourceTable.h
+++ b/tools/aapt2/ResourceTable.h
@@ -113,8 +113,7 @@
                                  const android::StringPiece& product);
   ResourceConfigValue* FindOrCreateValue(const ConfigDescription& config,
                                          const android::StringPiece& product);
-  std::vector<ResourceConfigValue*> findAllValues(
-      const ConfigDescription& config);
+  std::vector<ResourceConfigValue*> FindAllValues(const ConfigDescription& config);
   std::vector<ResourceConfigValue*> FindValuesIf(
       const std::function<bool(ResourceConfigValue*)>& f);
 
@@ -189,8 +188,7 @@
    * When a collision of resources occurs, this method decides which value to
    * keep.
    */
-  static CollisionResult ResolveValueCollision(Value* existing,
-                                               Value* incoming);
+  static CollisionResult ResolveValueCollision(Value* existing, Value* incoming);
 
   bool AddResource(const ResourceNameRef& name, const ConfigDescription& config,
                    const android::StringPiece& product, std::unique_ptr<Value> value,
@@ -274,20 +272,24 @@
   std::map<size_t, std::string> included_packages_;
 
  private:
+  // The function type that validates a symbol name. Returns a non-empty StringPiece representing
+  // the offending character (which may be more than one byte in UTF-8). Returns an empty string
+  // if the name was valid.
+  using NameValidator = android::StringPiece(const android::StringPiece&);
+
   ResourceTablePackage* FindOrCreatePackage(const android::StringPiece& name);
 
   bool AddResourceImpl(const ResourceNameRef& name, const ResourceId& res_id,
                        const ConfigDescription& config, const android::StringPiece& product,
-                       std::unique_ptr<Value> value, const char* valid_chars,
+                       std::unique_ptr<Value> value, NameValidator name_validator,
                        const CollisionResolverFunc& conflict_resolver, IDiagnostics* diag);
 
   bool AddFileReferenceImpl(const ResourceNameRef& name, const ConfigDescription& config,
                             const Source& source, const android::StringPiece& path, io::IFile* file,
-                            const char* valid_chars, IDiagnostics* diag);
+                            NameValidator name_validator, IDiagnostics* diag);
 
   bool SetSymbolStateImpl(const ResourceNameRef& name, const ResourceId& res_id,
-                          const Symbol& symbol, const char* valid_chars,
-                          IDiagnostics* diag);
+                          const Symbol& symbol, NameValidator name_validator, IDiagnostics* diag);
 
   DISALLOW_COPY_AND_ASSIGN(ResourceTable);
 };