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

Commit f6762fc2 authored by Alexandria Cornwall's avatar Alexandria Cornwall
Browse files

AAPT2: Merge binary XML file attributes

AAPT2 generates extra versions of XML binaries based on the sdkVersion
that attributes were introduced, up to v21. This should only happen for
sdkVersions that are > minSdkVersion, as everything else can be included
in the main configuration (e.g. "layout" instead of "layout-v4").

This change handles the merging of XML binary sdkVersions that were created
implicitly.

Bug: 30705740
Change-Id: I854843dd6dbaca52896cea0c24c70c900cec3e8e
parent ed063d46
Loading
Loading
Loading
Loading
+18 −11
Original line number Diff line number Diff line
@@ -388,8 +388,10 @@ bool ResourceFileFlattener::linkAndVersionXmlFile(const ResourceEntry* entry,

        // Find the first SDK level used that is higher than this defined config and
        // not superseded by a lower or equal SDK level resource.
        const int minSdkVersion = mContext->getMinSdkVersion();
        for (int sdkLevel : xmlLinker.getSdkLevels()) {
            if (sdkLevel > outFileOp->xmlToFlatten->file.config.sdkVersion) {
            if (sdkLevel > minSdkVersion
                    && sdkLevel > outFileOp->xmlToFlatten->file.config.sdkVersion) {
                if (!shouldGenerateVersionedResource(entry, outFileOp->xmlToFlatten->file.config,
                                                     sdkLevel)) {
                    // If we shouldn't generate a versioned resource, stop checking.
@@ -498,7 +500,10 @@ bool ResourceFileFlattener::flatten(ResourceTable* table, IArchiveWriter* archiv
                if (fileOp.xmlToFlatten) {
                    Maybe<size_t> maxSdkLevel;
                    if (!mOptions.noAutoVersion && !fileOp.skipVersion) {
                        maxSdkLevel = std::max<size_t>(config.sdkVersion, 1u);
                        maxSdkLevel =
                                std::max<size_t>(
                                        std::max<size_t>(config.sdkVersion, 1u),
                                        mContext->getMinSdkVersion());
                    }

                    bool result = flattenXml(fileOp.xmlToFlatten.get(), fileOp.dstPath, maxSdkLevel,
@@ -1388,6 +1393,17 @@ public:
            return 1;
        }

        // Must come before ResourceFileFlattener as ResourceFileFlattener
        // relies on the minSdkVersion to properly flatten files.
        Maybe<AppInfo> maybeAppInfo = extractAppInfoFromManifest(manifestXml.get(),
                                                                 mContext->getDiagnostics());
        if (maybeAppInfo && maybeAppInfo.value().minSdkVersion) {
            if (Maybe<int> maybeMinSdkVersion =
                    ResourceUtils::tryParseSdkVersion(maybeAppInfo.value().minSdkVersion.value())) {
                mContext->setMinSdkVersion(maybeMinSdkVersion.value());
            }
        }

        ResourceFileFlattenerOptions fileFlattenerOptions;
        fileFlattenerOptions.keepRawValues = mOptions.staticLib;
        fileFlattenerOptions.doNotCompressAnything = mOptions.doNotCompressAnything;
@@ -1411,15 +1427,6 @@ public:
            }
        }

        Maybe<AppInfo> maybeAppInfo = extractAppInfoFromManifest(manifestXml.get(),
                                                                 mContext->getDiagnostics());
        if (maybeAppInfo && maybeAppInfo.value().minSdkVersion) {
            if (Maybe<int> maybeMinSdkVersion =
                    ResourceUtils::tryParseSdkVersion(maybeAppInfo.value().minSdkVersion.value())) {
                mContext->setMinSdkVersion(maybeMinSdkVersion.value());
            }
        }

        if (!mOptions.staticLib && mContext->getMinSdkVersion() > 0) {
            if (mContext->verbose()) {
                mContext->getDiagnostics()->note(