diff options
author | Adam Lesinski <adamlesinski@google.com> | 2017-01-23 12:58:11 -0800 |
---|---|---|
committer | Adam Lesinski <adamlesinski@google.com> | 2017-02-15 10:50:23 -0800 |
commit | d1ecd7af687bcad0f87c37fe33515ff6c5ea0f1d (patch) | |
tree | 63822987507c52532481ca86333751e4fb329953 /libs/androidfw/Asset.cpp | |
parent | c535d122c6a58a152ff2581f936070c2695c45ba (diff) |
AssetManager2: Various fixes
- Use FileMaps to open Assets (prevents closing of ApkAssets underlying
zip)
- Implement OpenDir and List methods
- Fix issue where DynamicRefTable wasn't properly constructed
Test: make libandroidfw_tests
Change-Id: Ib21a84e1114d028120744aa3bc1c6eb9d9399fa8
Diffstat (limited to 'libs/androidfw/Asset.cpp')
-rw-r--r-- | libs/androidfw/Asset.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/libs/androidfw/Asset.cpp b/libs/androidfw/Asset.cpp index 8e8c6a2e25a2..247458d3f4fd 100644 --- a/libs/androidfw/Asset.cpp +++ b/libs/androidfw/Asset.cpp @@ -23,6 +23,7 @@ #include <androidfw/Asset.h> #include <androidfw/StreamingZipInflater.h> +#include <androidfw/Util.h> #include <androidfw/ZipFileRO.h> #include <androidfw/ZipUtils.h> #include <utils/Atomic.h> @@ -298,6 +299,22 @@ Asset::Asset(void) return pAsset; } +/*static*/ std::unique_ptr<Asset> Asset::createFromUncompressedMap(std::unique_ptr<FileMap> dataMap, + AccessMode mode) +{ + std::unique_ptr<_FileAsset> pAsset = util::make_unique<_FileAsset>(); + + status_t result = pAsset->openChunk(dataMap.get()); + if (result != NO_ERROR) { + return NULL; + } + + // We succeeded, so relinquish control of dataMap + (void) dataMap.release(); + pAsset->mAccessMode = mode; + return std::move(pAsset); +} + /* * Create a new Asset from compressed data in a memory mapping. */ @@ -316,6 +333,21 @@ Asset::Asset(void) return pAsset; } +/*static*/ std::unique_ptr<Asset> Asset::createFromCompressedMap(std::unique_ptr<FileMap> dataMap, + size_t uncompressedLen, AccessMode mode) +{ + std::unique_ptr<_CompressedAsset> pAsset = util::make_unique<_CompressedAsset>(); + + status_t result = pAsset->openChunk(dataMap.get(), uncompressedLen); + if (result != NO_ERROR) { + return NULL; + } + + // We succeeded, so relinquish control of dataMap + (void) dataMap.release(); + pAsset->mAccessMode = mode; + return std::move(pAsset); +} /* * Do generic seek() housekeeping. Pass in the offset/whence values from |