From 0c01abb1b0190fc820f1183b167b37d891c1f784 Mon Sep 17 00:00:00 2001 From: Jackal Guo Date: Fri, 30 Jul 2021 22:17:43 +0800 Subject: [PATCH] Fix the manifest when requiredSplitTypes presents The attribute isSplitRequired should be also true, when the attribute requiredSplitTypes is true. Add an auto generation function to inject it. Bug: 189882156 Test: manually check if the attriubte is correctly generated. Change-Id: I3a4f3bc68a4582f46f0c1c0394128485be29920a --- tools/aapt2/link/ManifestFixer.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tools/aapt2/link/ManifestFixer.cpp b/tools/aapt2/link/ManifestFixer.cpp index 1bb06964e31cc..63b2fcd662479 100644 --- a/tools/aapt2/link/ManifestFixer.cpp +++ b/tools/aapt2/link/ManifestFixer.cpp @@ -163,6 +163,31 @@ static bool AutoGenerateIsFeatureSplit(xml::Element* el, SourcePathDiagnostics* return true; } +static bool AutoGenerateIsSplitRequired(xml::Element* el, SourcePathDiagnostics* diag) { + constexpr const char* kRequiredSplitTypes = "requiredSplitTypes"; + constexpr const char* kIsSplitRequired = "isSplitRequired"; + + xml::Attribute* attr = el->FindAttribute(xml::kSchemaAndroid, kRequiredSplitTypes); + if (attr != nullptr) { + // Now inject the android:isSplitRequired="true" attribute. + xml::Attribute* attr = el->FindAttribute(xml::kSchemaAndroid, kIsSplitRequired); + if (attr != nullptr) { + if (!ResourceUtils::ParseBool(attr->value).value_or(false)) { + // The isFeatureSplit attribute is false, which conflicts with the use + // of "featureSplit". + diag->Error(DiagMessage(el->line_number) + << "attribute 'requiredSplitTypes' used in but " + "'android:isSplitRequired' is not 'true'"); + return false; + } + // The attribute is already there and set to true, nothing to do. + } else { + el->attributes.push_back(xml::Attribute{xml::kSchemaAndroid, kIsSplitRequired, "true"}); + } + } + return true; +} + static bool VerifyManifest(xml::Element* el, xml::XmlActionExecutorPolicy policy, SourcePathDiagnostics* diag) { xml::Attribute* attr = el->FindAttribute({}, "package"); @@ -329,6 +354,7 @@ bool ManifestFixer::BuildRules(xml::XmlActionExecutor* executor, // Manifest actions. xml::XmlNodeAction& manifest_action = (*executor)["manifest"]; manifest_action.Action(AutoGenerateIsFeatureSplit); + manifest_action.Action(AutoGenerateIsSplitRequired); manifest_action.Action(VerifyManifest); manifest_action.Action(FixCoreAppAttribute); manifest_action.Action([&](xml::Element* el) -> bool {