[aapt2] Always generate code for permissions
We will generate the String constant in Manifest.java for a permission
or permission group even if it is removed via feature flag. This is so
that code referencing the string will still compile.
Bug: 297373084
Bug: 318014882
Test: atest aapt2_tests
Test: Modified framework-res to build with SDK version 34 and forced
removal of a permission with a disabled feature flag. The entire
Android source could still be built even if the framework-res.apk no
longer had the removed permission in the manifest.
Change-Id: I982a8988e35e09e73bcbe065f0d7cf47c2907d54
diff --git a/tools/aapt2/cmd/Link.cpp b/tools/aapt2/cmd/Link.cpp
index 24699bf..c739d77 100644
--- a/tools/aapt2/cmd/Link.cpp
+++ b/tools/aapt2/cmd/Link.cpp
@@ -1987,6 +1987,8 @@
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
@@ -2296,7 +2298,12 @@
}
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;
}
}