Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b80b6dab authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "AAPT2: Parse coreApp in <manifest> as boolean"

parents 086184d6 6b17d2ce
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -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>
+17 −0
Original line number Diff line number Diff line
@@ -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) {
@@ -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) {
+20 −0
Original line number Diff line number Diff line
@@ -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
+3 −2
Original line number Diff line number Diff line
@@ -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);
            }