Allow to use 'aapt2 dump' to analyze APKs generated by aapt/custom tools.
This CL fixes four compatibility issues:
* verifies xml element is placed under valid parent tag inside Inflate;
* FindElement searches an element in a reverse order, this is
because aapt processes tags one-by-one and always takes the latest.
* allows to resolve string from StyledString resource type;
* bug that prevents 'payment' component to be detected.
At the momemnt aapt2 dump does not work correctly for APKs where xml
elements are placed in wrong place (For example if '<uses-permission>'
is declared under '<application>', aapt2 will still report it).
This is essential for Play migration from aapt to aapt2 because not
all our APKs are generated by aapt2 and might contain wrongly placed
elements.
CL is verified on our full APK database and confirmed to fix all issues.
Bug: b/260704482
Test: Dump_test, manual run on Play's DB of APKs
Change-Id: I0b10ecc15a712fd13674a239f91157aba58fa620
diff --git a/tools/aapt2/cmd/Dump_test.cpp b/tools/aapt2/cmd/Dump_test.cpp
index b1c69cd..df35ebb 100644
--- a/tools/aapt2/cmd/Dump_test.cpp
+++ b/tools/aapt2/cmd/Dump_test.cpp
@@ -108,4 +108,21 @@
ASSERT_EQ(output, expected);
}
+TEST_F(DumpTest, DumpBadgingApkBuiltWithAaptAndTagsInWrongPlace) {
+ auto apk_path = file::BuildPath({android::base::GetExecutableDirectory(), "integration-tests",
+ "DumpTest", "built_with_aapt.apk"});
+ auto loaded_apk = LoadedApk::LoadApkFromPath(apk_path, &noop_diag);
+
+ std::string output;
+ DumpBadgingToString(loaded_apk.get(), &output, /* include_meta_data= */ false,
+ /* only_permissions= */ false);
+
+ std::string expected;
+ auto expected_path =
+ file::BuildPath({android::base::GetExecutableDirectory(), "integration-tests", "DumpTest",
+ "built_with_aapt_expected.txt"});
+ ::android::base::ReadFileToString(expected_path, &expected);
+ ASSERT_EQ(output, expected);
+}
+
} // namespace aapt