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

Commit 081add7b authored by Adam Lesinski's avatar Adam Lesinski Committed by Android Git Automerger
Browse files

am 247bc95c: Merge "AAPT2: Record public status in a more robust way" into mnc-dev

* commit '247bc95c':
  AAPT2: Record public status in a more robust way
parents bdb52436 247bc95c
Loading
Loading
Loading
Loading
+55 −4
Original line number Diff line number Diff line
@@ -396,6 +396,12 @@ bool BinaryResourceParser::parsePackage(const ResChunk_header* chunk) {
            }
            break;

        case RES_TABLE_PUBLIC_TYPE:
            if (!parsePublic(parser.getChunk())) {
                return false;
            }
            break;

        default:
            Logger::warn(mSource)
                    << "unexpected chunk of type "
@@ -429,6 +435,55 @@ bool BinaryResourceParser::parsePackage(const ResChunk_header* chunk) {
    return true;
}

bool BinaryResourceParser::parsePublic(const ResChunk_header* chunk) {
    const Public_header* header = convertTo<Public_header>(chunk);

    if (header->typeId == 0) {
        Logger::error(mSource)
                << "invalid type ID " << header->typeId << std::endl;
        return false;
    }

    const ResourceType* parsedType = parseResourceType(util::getString(mTypePool,
                                                                       header->typeId - 1));
    if (!parsedType) {
        Logger::error(mSource)
                << "invalid type " << util::getString(mTypePool, header->typeId - 1) << std::endl;
        return false;
    }

    const uintptr_t chunkEnd = reinterpret_cast<uintptr_t>(chunk) + chunk->size;
    const Public_entry* entry = reinterpret_cast<const Public_entry*>(
            getChunkData(header->header));
    for (uint32_t i = 0; i < header->count; i++) {
        if (reinterpret_cast<uintptr_t>(entry) + sizeof(*entry) > chunkEnd) {
            Logger::error(mSource)
                    << "Public_entry extends beyond chunk."
                    << std::endl;
            return false;
        }

        const ResourceId resId = { mTable->getPackageId(), header->typeId, entry->entryId };
        const ResourceName name = {
                mTable->getPackage(),
                *parsedType,
                util::getString(mKeyPool, entry->key.index).toString() };

        SourceLine source;
        if (mSourcePool.getError() == NO_ERROR) {
            source.path = util::utf16ToUtf8(util::getString(mSourcePool, entry->source.index));
            source.line = entry->sourceLine;
        }

        if (!mTable->markPublic(name, resId, source)) {
            return false;
        }

        entry++;
    }
    return true;
}

bool BinaryResourceParser::parseTypeSpec(const ResChunk_header* chunk) {
    if (mTypePool.getError() != NO_ERROR) {
        Logger::error(mSource)
@@ -636,10 +691,6 @@ std::unique_ptr<Item> BinaryResourceParser::parseValue(const ResourceNameRef& na
        return util::make_unique<BinaryPrimitive>(nullType);
    }

    if (value->dataType == ExtendedTypes::TYPE_SENTINEL) {
        return util::make_unique<Sentinel>();
    }

    if (value->dataType == ExtendedTypes::TYPE_RAW_STRING) {
        return util::make_unique<RawString>(
                mTable->getValueStringPool().makeRef(util::getString(mValuePool, value->data),
+1 −0
Original line number Diff line number Diff line
@@ -66,6 +66,7 @@ private:
    bool idToName(Reference* reference);

    bool parsePackage(const android::ResChunk_header* chunk);
    bool parsePublic(const android::ResChunk_header* chunk);
    bool parseTypeSpec(const android::ResChunk_header* chunk);
    bool parseType(const android::ResChunk_header* chunk);

+15 −12
Original line number Diff line number Diff line
@@ -67,6 +67,13 @@ bool Linker::linkAndValidate() {
                usedIds[type->typeId].insert(entry->entryId);
            }

            if (entry->publicStatus.isPublic && entry->values.empty()) {
                // A public resource has no values. It will not be encoded
                // properly without a symbol table. This is a unresolved symbol.
                addUnresolvedSymbol(ResourceNameRef{
                        mTable->getPackage(), type->type, entry->name },
                        entry->publicStatus.source);
            } else {
                for (auto& valueConfig : entry->values) {
                    // Dispatch to the right method of this linker
                    // based on the value's type.
@@ -77,6 +84,7 @@ bool Linker::linkAndValidate() {
                }
            }
        }
    }

    /*
     * Assign resource IDs that are available.
@@ -270,11 +278,6 @@ void Linker::visit(Styleable& styleable, ValueVisitorArgs& a) {
    }
}

void Linker::visit(Sentinel& sentinel, ValueVisitorArgs& a) {
    Args& args = static_cast<Args&>(a);
    addUnresolvedSymbol(args.referrer, args.source);
}

void Linker::visit(Array& array, ValueVisitorArgs& a) {
    Args& args = static_cast<Args&>(a);

+0 −1
Original line number Diff line number Diff line
@@ -88,7 +88,6 @@ private:
    void visit(Attribute& attribute, ValueVisitorArgs& args) override;
    void visit(Styleable& styleable, ValueVisitorArgs& args) override;
    void visit(Style& style, ValueVisitorArgs& args) override;
    void visit(Sentinel& sentinel, ValueVisitorArgs& args) override;
    void visit(Array& array, ValueVisitorArgs& args) override;
    void visit(Plural& plural, ValueVisitorArgs& args) override;

+1 −5
Original line number Diff line number Diff line
@@ -299,16 +299,12 @@ bool ResourceTable::markPublic(const ResourceNameRef& name, const ResourceId res

    type->publicStatus.isPublic = true;
    entry->publicStatus.isPublic = true;
    entry->publicStatus.source = source;

    if (resId.isValid()) {
        type->typeId = resId.typeId();
        entry->entryId = resId.entryId();
    }

    if (entry->values.empty()) {
        entry->values.push_back(ResourceConfigValue{ {}, source, {},
                                    util::make_unique<Sentinel>() });
    }
    return true;
}

Loading