[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_test.cpp b/tools/aapt2/cmd/Link_test.cpp
index 7ceb351..10d0b1f 100644
--- a/tools/aapt2/cmd/Link_test.cpp
+++ b/tools/aapt2/cmd/Link_test.cpp
@@ -1021,9 +1021,11 @@
                           .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 @@
   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) {