diff options
| author | 2018-03-02 09:34:18 +0100 | |
|---|---|---|
| committer | 2018-09-28 09:40:20 +0200 | |
| commit | 3f1f4fc11d2e19c4b297a97d21293d05ac3db622 (patch) | |
| tree | 45756e77808f87ef376117a89028ba8a1dd43f7d /libs/androidfw/LoadedArsc.cpp | |
| parent | 0b925f85c00a9a3a942269236a16e77040a3eeb3 (diff) | |
libandroidfw: add resource ID iterator
Add an iterator to LoadedPackage which allows the caller to iterate over
the resource IDs in the package. This will be used by idmap when
constructing the idmap file.
Bug: 78815803
Test: make libandroidfw_tests
Change-Id: Ia47daa21390d67ea2ef3665e88eb407837c4764f
Diffstat (limited to 'libs/androidfw/LoadedArsc.cpp')
| -rw-r--r-- | libs/androidfw/LoadedArsc.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/libs/androidfw/LoadedArsc.cpp b/libs/androidfw/LoadedArsc.cpp index 04d506a2d71c..21f023dc0f05 100644 --- a/libs/androidfw/LoadedArsc.cpp +++ b/libs/androidfw/LoadedArsc.cpp @@ -203,6 +203,39 @@ static bool VerifyResTableEntry(const ResTable_type* type, uint32_t entry_offset return true; } +LoadedPackage::iterator::iterator(const LoadedPackage* lp, size_t ti, size_t ei) + : loadedPackage_(lp), + typeIndex_(ti), + entryIndex_(ei), + typeIndexEnd_(lp->resource_ids_.size() + 1) { + while (typeIndex_ < typeIndexEnd_ && loadedPackage_->resource_ids_[typeIndex_] == 0) { + typeIndex_++; + } +} + +LoadedPackage::iterator& LoadedPackage::iterator::operator++() { + while (typeIndex_ < typeIndexEnd_) { + if (entryIndex_ + 1 < loadedPackage_->resource_ids_[typeIndex_]) { + entryIndex_++; + break; + } + entryIndex_ = 0; + typeIndex_++; + if (typeIndex_ < typeIndexEnd_ && loadedPackage_->resource_ids_[typeIndex_] != 0) { + break; + } + } + return *this; +} + +uint32_t LoadedPackage::iterator::operator*() const { + if (typeIndex_ >= typeIndexEnd_) { + return 0; + } + return make_resid(loadedPackage_->package_id_, typeIndex_ + loadedPackage_->type_id_offset_, + entryIndex_); +} + const ResTable_entry* LoadedPackage::GetEntry(const ResTable_type* type_chunk, uint16_t entry_index) { uint32_t entry_offset = GetEntryOffset(type_chunk, entry_index); @@ -488,6 +521,7 @@ std::unique_ptr<const LoadedPackage> LoadedPackage::Load(const Chunk& chunk, std::unique_ptr<TypeSpecPtrBuilder>& builder_ptr = type_builder_map[type_spec->id - 1]; if (builder_ptr == nullptr) { builder_ptr = util::make_unique<TypeSpecPtrBuilder>(type_spec, idmap_entry_header); + loaded_package->resource_ids_.set(type_spec->id, entry_count); } else { LOG(WARNING) << StringPrintf("RES_TABLE_TYPE_SPEC_TYPE already defined for ID %02x", type_spec->id); |