summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Treehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com> 2024-01-29 19:42:12 +0000
committer Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> 2024-01-29 19:42:12 +0000
commit87e67eb20de9ea1b398bda65cb2906eeecb7bed4 (patch)
tree5670e87f833f7f9f2d47ae9017047a201a5fe274
parentc97f4daa53a059cc4a061f32cc31d79457c6dec6 (diff)
parentbbd2c4603c2a0a60a03a936bf650cc59c0e3861a (diff)
Merge "[aapt2] Always generate code for permissions" into main am: a148b9fae1 am: bbd2c4603c
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/2927411 Change-Id: I948fa67f1d1a9824722c2114074bcbae5e4bccac Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--tools/aapt2/cmd/Link.cpp9
-rw-r--r--tools/aapt2/cmd/Link_test.cpp8
2 files changed, 16 insertions, 1 deletions
diff --git a/tools/aapt2/cmd/Link.cpp b/tools/aapt2/cmd/Link.cpp
index f3f183815d0b..642a5618b6ad 100644
--- a/tools/aapt2/cmd/Link.cpp
+++ b/tools/aapt2/cmd/Link.cpp
@@ -1988,6 +1988,8 @@ class Linker {
context_->SetNameManglerPolicy(NameManglerPolicy{context_->GetCompilationPackage()});
context_->SetSplitNameDependencies(app_info_.split_name_dependencies);
+ std::unique_ptr<xml::XmlResource> pre_flags_filter_manifest_xml = manifest_xml->Clone();
+
FeatureFlagsFilterOptions flags_filter_options;
if (context_->GetMinSdkVersion() > SDK_UPSIDE_DOWN_CAKE) {
// For API version > U, PackageManager will dynamically read the flag values and disable
@@ -2297,7 +2299,12 @@ class Linker {
}
if (options_.generate_java_class_path) {
- if (!WriteManifestJavaFile(manifest_xml.get())) {
+ // The FeatureFlagsFilter may remove <permission> and <permission-group> elements that
+ // generate constants in the Manifest Java file. While we want those permissions and
+ // permission groups removed in the SDK (i.e., if a feature flag is disabled), the
+ // constants should still remain so that code referencing it (e.g., within a feature
+ // flag check) will still compile. Therefore we use the manifest XML before the filter.
+ if (!WriteManifestJavaFile(pre_flags_filter_manifest_xml.get())) {
error = true;
}
}
diff --git a/tools/aapt2/cmd/Link_test.cpp b/tools/aapt2/cmd/Link_test.cpp
index 9323f3b95eac..6cc42f17c0a1 100644
--- a/tools/aapt2/cmd/Link_test.cpp
+++ b/tools/aapt2/cmd/Link_test.cpp
@@ -1021,9 +1021,11 @@ TEST_F(LinkTest, FeatureFlagDisabled_SdkAtMostUDC) {
.AddContents(manifest_contents)
.Build();
+ const std::string app_java = GetTestPath("app-java");
auto app_link_args = LinkCommandBuilder(this)
.SetManifestFile(app_manifest)
.AddParameter("-I", android_apk)
+ .AddParameter("--java", app_java)
.AddParameter("--feature-flags", "flag=false");
const std::string app_apk = GetTestPath("app.apk");
@@ -1038,6 +1040,12 @@ TEST_F(LinkTest, FeatureFlagDisabled_SdkAtMostUDC) {
ASSERT_THAT(root, NotNull());
auto maybe_removed = root->FindChild({}, "permission");
ASSERT_THAT(maybe_removed, IsNull());
+
+ // Code for the permission should be generated even if the element is removed
+ const std::string manifest_java = app_java + "/com/example/app/Manifest.java";
+ std::string manifest_java_contents;
+ ASSERT_TRUE(android::base::ReadFileToString(manifest_java, &manifest_java_contents));
+ EXPECT_THAT(manifest_java_contents, HasSubstr(" public static final String FOO=\"FOO\";"));
}
TEST_F(LinkTest, FeatureFlagEnabled_SdkAtMostUDC) {