Loading tools/aapt2/cmd/Link.cpp +8 −1 Original line number Diff line number Diff line Loading @@ -1987,6 +1987,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 Loading Loading @@ -2296,7 +2298,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; } } Loading tools/aapt2/cmd/Link_test.cpp +8 −0 Original line number Diff line number Diff line Loading @@ -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"); Loading @@ -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) { Loading Loading
tools/aapt2/cmd/Link.cpp +8 −1 Original line number Diff line number Diff line Loading @@ -1987,6 +1987,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 Loading Loading @@ -2296,7 +2298,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; } } Loading
tools/aapt2/cmd/Link_test.cpp +8 −0 Original line number Diff line number Diff line Loading @@ -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"); Loading @@ -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) { Loading