summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Ryan Mitchell <rtmitchell@google.com> 2018-05-10 15:35:31 -0700
committer Ryan Mitchell <rtmitchell@google.com> 2018-05-10 15:37:37 -0700
commit7cb82a86beda55a178d76dc8dd90d0b01a4b9c91 (patch)
tree32d4b8fc40aea3087d36ef451761c015652e2a71
parent1822926cfbf55cc68a85cdfd588802f4a106cdb5 (diff)
AAPT2: Insert platformBuild information
Inserts platformBuildVersionName and platformBuildVersionName when the attributes are not currrently present. The attributes are set to the values of versionName and versionCode. Bug: 77541121 Test: Build apk using aapt and appt2 and dumped using xmltree to confirm the presence of the attributes Change-Id: I5330381905c878fb877214b42f83d7e2e48cd062
-rw-r--r--tools/aapt2/link/ManifestFixer.cpp17
-rw-r--r--tools/aapt2/link/ManifestFixer_test.cpp52
2 files changed, 69 insertions, 0 deletions
diff --git a/tools/aapt2/link/ManifestFixer.cpp b/tools/aapt2/link/ManifestFixer.cpp
index 165702ca42cd..bfff1487d4be 100644
--- a/tools/aapt2/link/ManifestFixer.cpp
+++ b/tools/aapt2/link/ManifestFixer.cpp
@@ -275,6 +275,23 @@ bool ManifestFixer::BuildRules(xml::XmlActionExecutor* executor,
options_.version_code_default.value()});
}
}
+
+ if (el->FindAttribute("", "platformBuildVersionCode") == nullptr) {
+ auto versionCode = el->FindAttribute(xml::kSchemaAndroid, "versionCode");
+ if (versionCode != nullptr) {
+ el->attributes.push_back(xml::Attribute{"", "platformBuildVersionCode",
+ versionCode->value});
+ }
+ }
+
+ if (el->FindAttribute("", "platformBuildVersionName") == nullptr) {
+ auto versionName = el->FindAttribute(xml::kSchemaAndroid, "versionName");
+ if (versionName != nullptr) {
+ el->attributes.push_back(xml::Attribute{"", "platformBuildVersionName",
+ versionName->value});
+ }
+ }
+
return true;
});
diff --git a/tools/aapt2/link/ManifestFixer_test.cpp b/tools/aapt2/link/ManifestFixer_test.cpp
index 8db937439c55..5f406e81f65d 100644
--- a/tools/aapt2/link/ManifestFixer_test.cpp
+++ b/tools/aapt2/link/ManifestFixer_test.cpp
@@ -556,6 +556,58 @@ TEST_F(ManifestFixerTest, UnexpectedElementsInManifest) {
ASSERT_THAT(manifest, IsNull());
}
+TEST_F(ManifestFixerTest, InsertPlatformBuildVersions) {
+ // Test for insertion when versionCode and versionName are included in the manifest
+ {
+ std::string input = R"(
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="android"
+ android:versionCode="27" android:versionName="O"/>)";
+ std::unique_ptr<xml::XmlResource> manifest = Verify(input);
+ ASSERT_THAT(manifest, NotNull());
+
+ xml::Attribute* attr = manifest->root->FindAttribute("", "platformBuildVersionCode");
+ ASSERT_THAT(attr, NotNull());
+ EXPECT_THAT(attr->value, StrEq("27"));
+ attr = manifest->root->FindAttribute("", "platformBuildVersionName");
+ ASSERT_THAT(attr, NotNull());
+ EXPECT_THAT(attr->value, StrEq("O"));
+ }
+
+ // Test for insertion when versionCode and versionName defaults are specified
+ {
+ std::string input = R"(
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="android"/>)";
+ ManifestFixerOptions options;
+ options.version_code_default = {"27"};
+ options.version_name_default = {"O"};
+ std::unique_ptr<xml::XmlResource> manifest = VerifyWithOptions(input, options);
+ ASSERT_THAT(manifest, NotNull());
+
+ xml::Attribute* attr = manifest->root->FindAttribute("", "platformBuildVersionCode");
+ ASSERT_THAT(attr, NotNull());
+ EXPECT_THAT(attr->value, StrEq("27"));
+ attr = manifest->root->FindAttribute("", "platformBuildVersionName");
+ ASSERT_THAT(attr, NotNull());
+ EXPECT_THAT(attr->value, StrEq("O"));
+ }
+
+ // Test that the platform build version attributes are not changed if they are currently present
+ {
+ std::string input = R"(
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="android"
+ android:versionCode="28" android:versionName="P"
+ platformBuildVersionCode="27" platformBuildVersionName="O"/>)";
+ std::unique_ptr<xml::XmlResource> manifest = Verify(input);
+ ASSERT_THAT(manifest, NotNull());
+
+ xml::Attribute* attr = manifest->root->FindAttribute("", "platformBuildVersionCode");
+ ASSERT_THAT(attr, NotNull());
+ EXPECT_THAT(attr->value, StrEq("27"));
+ attr = manifest->root->FindAttribute("", "platformBuildVersionName");
+ ASSERT_THAT(attr, NotNull());
+ EXPECT_THAT(attr->value, StrEq("O"));
+ }
+}
TEST_F(ManifestFixerTest, UsesLibraryMustHaveNonEmptyName) {
std::string input = R"(