AAPT2: Implement density stripping and initial Split support

When a preferred density is supplied, the closest matching densities
will be selected, the rest stripped from the APK.

Split support will be enabled in a later CL. Command line support is still
needed, but the foundation is ready.

Bug:25958912
Change-Id: I56d599806b4ec4ffa24e17aad48d47130ca05c08
diff --git a/tools/aapt2/ResourceTable.cpp b/tools/aapt2/ResourceTable.cpp
index 3e73be4..8d734f3 100644
--- a/tools/aapt2/ResourceTable.cpp
+++ b/tools/aapt2/ResourceTable.cpp
@@ -277,20 +277,31 @@
                                      const Source& source,
                                      const StringPiece16& path,
                                      IDiagnostics* diag) {
-    return addFileReference(name, config, source, path, resolveValueCollision, diag);
+    return addFileReferenceImpl(name, config, source, path, nullptr, kValidNameChars, diag);
 }
 
-bool ResourceTable::addFileReference(const ResourceNameRef& name,
-                                     const ConfigDescription& config,
-                                     const Source& source,
-                                     const StringPiece16& path,
-                                     std::function<int(Value*,Value*)> conflictResolver,
-                                     IDiagnostics* diag) {
+bool ResourceTable::addFileReferenceAllowMangled(const ResourceNameRef& name,
+                                                 const ConfigDescription& config,
+                                                 const Source& source,
+                                                 const StringPiece16& path,
+                                                 io::IFile* file,
+                                                 IDiagnostics* diag) {
+    return addFileReferenceImpl(name, config, source, path, file, kValidNameMangledChars, diag);
+}
+
+bool ResourceTable::addFileReferenceImpl(const ResourceNameRef& name,
+                                         const ConfigDescription& config,
+                                         const Source& source,
+                                         const StringPiece16& path,
+                                         io::IFile* file,
+                                         const char16_t* validChars,
+                                         IDiagnostics* diag) {
     std::unique_ptr<FileReference> fileRef = util::make_unique<FileReference>(
             stringPool.makeRef(path));
     fileRef->setSource(source);
+    fileRef->file = file;
     return addResourceImpl(name, ResourceId{}, config, StringPiece{}, std::move(fileRef),
-                           kValidNameChars, conflictResolver, diag);
+                           kValidNameChars, resolveValueCollision, diag);
 }
 
 bool ResourceTable::addResourceAllowMangled(const ResourceNameRef& name,