AAPT2: Fix issue where generated XML would be tagged with UNKNOWN type

CompiledFiles with UNKNOWN type are copied through, leading to protobuf
outputs in the final APK.

Test: make aapt2_tests
Change-Id: Ia0c464caa3951ff27436d1d50c2a8555bc89302b
diff --git a/tools/aapt2/compile/InlineXmlFormatParser.cpp b/tools/aapt2/compile/InlineXmlFormatParser.cpp
index a179260..99b4c31 100644
--- a/tools/aapt2/compile/InlineXmlFormatParser.cpp
+++ b/tools/aapt2/compile/InlineXmlFormatParser.cpp
@@ -118,10 +118,11 @@
 
   size_t name_suffix_counter = 0;
   for (const InlineDeclaration& decl : visitor.GetInlineDeclarations()) {
-    auto new_doc = util::make_unique<xml::XmlResource>();
-    new_doc->file.config = doc->file.config;
-    new_doc->file.source = doc->file.source.WithLine(decl.el->line_number);
-    new_doc->file.name = doc->file.name;
+    // Create a new XmlResource with the same ResourceFile as the base XmlResource.
+    auto new_doc = util::make_unique<xml::XmlResource>(doc->file);
+
+    // Attach the line number.
+    new_doc->file.source.line = decl.el->line_number;
 
     // Modify the new entry name. We need to suffix the entry with a number to
     // avoid local collisions, then mangle it with the empty package, such that it won't show up
diff --git a/tools/aapt2/compile/InlineXmlFormatParser_test.cpp b/tools/aapt2/compile/InlineXmlFormatParser_test.cpp
index de7739a..d6d734d 100644
--- a/tools/aapt2/compile/InlineXmlFormatParser_test.cpp
+++ b/tools/aapt2/compile/InlineXmlFormatParser_test.cpp
@@ -54,6 +54,7 @@
       </View1>)");
 
   doc->file.name = test::ParseNameOrDie("layout/main");
+  doc->file.type = ResourceFile::Type::kProtoXml;
 
   InlineXmlFormatParser parser;
   ASSERT_TRUE(parser.Consume(context.get(), doc.get()));
@@ -81,6 +82,9 @@
   // Make sure the generated reference is correct.
   EXPECT_THAT(extracted_doc->file.name, Eq(name_ref));
 
+  // Make sure the ResourceFile::Type is the same.
+  EXPECT_THAT(extracted_doc->file.type, Eq(ResourceFile::Type::kProtoXml));
+
   // Verify the structure of the extracted XML.
   el = extracted_doc->root.get();
   ASSERT_THAT(el, NotNull());