Loading tools/aapt2/integration-tests/AppOne/AndroidManifest.xml +4 −1 Original line number Diff line number Diff line Loading @@ -14,4 +14,7 @@ limitations under the License. --> <manifest package="com.android.aapt.app.one" /> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.android.aapt.app.one" coreApp="true"> <uses-sdk android:minSdkVersion="21" /> </manifest> tools/aapt2/link/ManifestFixer.cpp +17 −0 Original line number Diff line number Diff line Loading @@ -81,6 +81,22 @@ static bool verifyManifest(xml::Element* el, SourcePathDiagnostics* diag) { return true; } /** * The coreApp attribute in <manifest> is not a regular AAPT attribute, so type checking on it * is manual. */ static bool fixCoreAppAttribute(xml::Element* el, SourcePathDiagnostics* diag) { if (xml::Attribute* attr = el->findAttribute("", "coreApp")) { std::unique_ptr<BinaryPrimitive> result = ResourceUtils::tryParseBool(attr->value); if (!result) { diag->error(DiagMessage(el->lineNumber) << "attribute coreApp must be a boolean"); return false; } attr->compiledValue = std::move(result); } return true; } bool ManifestFixer::buildRules(xml::XmlActionExecutor* executor, IDiagnostics* diag) { // First verify some options. if (mOptions.renameManifestPackage) { Loading Loading @@ -111,6 +127,7 @@ bool ManifestFixer::buildRules(xml::XmlActionExecutor* executor, IDiagnostics* d // Manifest actions. xml::XmlNodeAction& manifestAction = (*executor)["manifest"]; manifestAction.action(verifyManifest); manifestAction.action(fixCoreAppAttribute); manifestAction.action([&](xml::Element* el) -> bool { if (mOptions.versionNameDefault) { if (el->findAttribute(xml::kSchemaAndroid, "versionName") == nullptr) { Loading tools/aapt2/link/ManifestFixer_test.cpp +20 −0 Original line number Diff line number Diff line Loading @@ -253,4 +253,24 @@ TEST_F(ManifestFixerTest, UseDefaultVersionNameAndCode) { EXPECT_EQ(std::string("0x10000000"), attr->value); } TEST_F(ManifestFixerTest, EnsureManifestAttributesAreTyped) { EXPECT_EQ(nullptr, verify("<manifest package=\"android\" coreApp=\"hello\" />")); EXPECT_EQ(nullptr, verify("<manifest package=\"android\" coreApp=\"1dp\" />")); std::unique_ptr<xml::XmlResource> doc = verify("<manifest package=\"android\" coreApp=\"true\" />"); ASSERT_NE(nullptr, doc); xml::Element* el = xml::findRootElement(doc.get()); ASSERT_NE(nullptr, el); EXPECT_EQ("manifest", el->name); xml::Attribute* attr = el->findAttribute("", "coreApp"); ASSERT_NE(nullptr, attr); EXPECT_NE(nullptr, attr->compiledValue); EXPECT_NE(nullptr, valueCast<BinaryPrimitive>(attr->compiledValue.get())); } } // namespace aapt tools/aapt2/link/XmlReferenceLinker.cpp +3 −2 Original line number Diff line number Diff line Loading @@ -126,8 +126,9 @@ public: mError = true; } } else { // We still encode references. } else if (!attr.compiledValue) { // We still encode references, but only if we haven't manually set this to // another compiled value. attr.compiledValue = ResourceUtils::tryParseReference(attr.value); } Loading Loading
tools/aapt2/integration-tests/AppOne/AndroidManifest.xml +4 −1 Original line number Diff line number Diff line Loading @@ -14,4 +14,7 @@ limitations under the License. --> <manifest package="com.android.aapt.app.one" /> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.android.aapt.app.one" coreApp="true"> <uses-sdk android:minSdkVersion="21" /> </manifest>
tools/aapt2/link/ManifestFixer.cpp +17 −0 Original line number Diff line number Diff line Loading @@ -81,6 +81,22 @@ static bool verifyManifest(xml::Element* el, SourcePathDiagnostics* diag) { return true; } /** * The coreApp attribute in <manifest> is not a regular AAPT attribute, so type checking on it * is manual. */ static bool fixCoreAppAttribute(xml::Element* el, SourcePathDiagnostics* diag) { if (xml::Attribute* attr = el->findAttribute("", "coreApp")) { std::unique_ptr<BinaryPrimitive> result = ResourceUtils::tryParseBool(attr->value); if (!result) { diag->error(DiagMessage(el->lineNumber) << "attribute coreApp must be a boolean"); return false; } attr->compiledValue = std::move(result); } return true; } bool ManifestFixer::buildRules(xml::XmlActionExecutor* executor, IDiagnostics* diag) { // First verify some options. if (mOptions.renameManifestPackage) { Loading Loading @@ -111,6 +127,7 @@ bool ManifestFixer::buildRules(xml::XmlActionExecutor* executor, IDiagnostics* d // Manifest actions. xml::XmlNodeAction& manifestAction = (*executor)["manifest"]; manifestAction.action(verifyManifest); manifestAction.action(fixCoreAppAttribute); manifestAction.action([&](xml::Element* el) -> bool { if (mOptions.versionNameDefault) { if (el->findAttribute(xml::kSchemaAndroid, "versionName") == nullptr) { Loading
tools/aapt2/link/ManifestFixer_test.cpp +20 −0 Original line number Diff line number Diff line Loading @@ -253,4 +253,24 @@ TEST_F(ManifestFixerTest, UseDefaultVersionNameAndCode) { EXPECT_EQ(std::string("0x10000000"), attr->value); } TEST_F(ManifestFixerTest, EnsureManifestAttributesAreTyped) { EXPECT_EQ(nullptr, verify("<manifest package=\"android\" coreApp=\"hello\" />")); EXPECT_EQ(nullptr, verify("<manifest package=\"android\" coreApp=\"1dp\" />")); std::unique_ptr<xml::XmlResource> doc = verify("<manifest package=\"android\" coreApp=\"true\" />"); ASSERT_NE(nullptr, doc); xml::Element* el = xml::findRootElement(doc.get()); ASSERT_NE(nullptr, el); EXPECT_EQ("manifest", el->name); xml::Attribute* attr = el->findAttribute("", "coreApp"); ASSERT_NE(nullptr, attr); EXPECT_NE(nullptr, attr->compiledValue); EXPECT_NE(nullptr, valueCast<BinaryPrimitive>(attr->compiledValue.get())); } } // namespace aapt
tools/aapt2/link/XmlReferenceLinker.cpp +3 −2 Original line number Diff line number Diff line Loading @@ -126,8 +126,9 @@ public: mError = true; } } else { // We still encode references. } else if (!attr.compiledValue) { // We still encode references, but only if we haven't manually set this to // another compiled value. attr.compiledValue = ResourceUtils::tryParseReference(attr.value); } Loading