diff options
author | 2013-12-03 13:16:03 +0000 | |
---|---|---|
committer | 2013-12-09 16:23:16 +0000 | |
commit | afd31e08299008fdc5c2813f21b2573f29dc53df (patch) | |
tree | 7f83dd8f1e7ed71d4fe8ce280841e43ce275ac6d /libs/androidfw/AssetManager.cpp | |
parent | 6e2d0c1d91f644ab50e0c0b7cae4306262a4ca41 (diff) |
Reimplement ZipFileRO in terms of libziparchive.
This lets us share zip archive processing code with both
the runtime (Art, dalvik) and critical java code
(StrictJarFile).
This change also moves several utility methods to ZipUtils
and dedups code across several zip inflation methods.
One of the side effects of this change is that several
processing loops are now O(n) instead of O(n^2).
bug: 10193060
Change-Id: I3c7188496837a47246c4f342e45485a70fef3169
Diffstat (limited to 'libs/androidfw/AssetManager.cpp')
-rw-r--r-- | libs/androidfw/AssetManager.cpp | 44 |
1 files changed, 23 insertions, 21 deletions
diff --git a/libs/androidfw/AssetManager.cpp b/libs/androidfw/AssetManager.cpp index 10667157bed2..503c0306d18f 100644 --- a/libs/androidfw/AssetManager.cpp +++ b/libs/androidfw/AssetManager.cpp @@ -305,10 +305,11 @@ bool AssetManager::getZipEntryCrcLocked(const String8& zipPath, const char* entr if (entry == NULL) { return false; } - if (!zip->getEntryInfo(entry, NULL, NULL, NULL, NULL, NULL, (long*)pCrc)) { - return false; - } - return true; + + const bool gotInfo = zip->getEntryInfo(entry, NULL, NULL, NULL, NULL, NULL, (long*)pCrc); + zip->releaseEntry(entry); + + return gotInfo; } bool AssetManager::createIdmapFileLocked(const String8& originalPath, const String8& overlayPath, @@ -821,16 +822,14 @@ Asset* AssetManager::openNonAssetInPathLocked(const char* fileName, AccessMode m String8 path(fileName); /* check the appropriate Zip file */ - ZipFileRO* pZip; - ZipEntryRO entry; - - pZip = getZipFileLocked(ap); + ZipFileRO* pZip = getZipFileLocked(ap); if (pZip != NULL) { //printf("GOT zip, checking NA '%s'\n", (const char*) path); - entry = pZip->findEntryByName(path.string()); + ZipEntryRO entry = pZip->findEntryByName(path.string()); if (entry != NULL) { //printf("FOUND NA in Zip file for %s\n", appName ? appName : kAppCommon); pAsset = openAssetFromZipLocked(pZip, entry, mode, path); + pZip->releaseEntry(entry); } } @@ -975,17 +974,15 @@ Asset* AssetManager::openInLocaleVendorLocked(const char* fileName, AccessMode m path.appendPath(fileName); /* check the appropriate Zip file */ - ZipFileRO* pZip; - ZipEntryRO entry; - - pZip = getZipFileLocked(ap); + ZipFileRO* pZip = getZipFileLocked(ap); if (pZip != NULL) { //printf("GOT zip, checking '%s'\n", (const char*) path); - entry = pZip->findEntryByName(path.string()); + ZipEntryRO entry = pZip->findEntryByName(path.string()); if (entry != NULL) { //printf("FOUND in Zip file for %s/%s-%s\n", // appName, locale, vendor); pAsset = openAssetFromZipLocked(pZip, entry, mode, path); + pZip->releaseEntry(entry); } } @@ -1487,11 +1484,16 @@ bool AssetManager::scanAndMergeZipLocked(SortedVector<AssetDir::FileInfo>* pMerg * semantics. */ int dirNameLen = dirName.length(); - for (int i = 0; i < pZip->getNumEntries(); i++) { - ZipEntryRO entry; + void *iterationCookie; + if (!pZip->startIteration(&iterationCookie)) { + ALOGW("ZipFileRO::startIteration returned false"); + return false; + } + + ZipEntryRO entry; + while ((entry = pZip->nextEntry(iterationCookie)) != NULL) { char nameBuf[256]; - entry = pZip->findEntryByIndex(i); if (pZip->getEntryFileName(entry, nameBuf, sizeof(nameBuf)) != 0) { // TODO: fix this if we expect to have long names ALOGE("ARGH: name too long?\n"); @@ -1541,6 +1543,8 @@ bool AssetManager::scanAndMergeZipLocked(SortedVector<AssetDir::FileInfo>* pMerg } } + pZip->endIteration(iterationCookie); + /* * Add the set of unique directories. */ @@ -1814,12 +1818,10 @@ AssetManager::SharedZip::SharedZip(const String8& path, time_t modWhen) mResourceTableAsset(NULL), mResourceTable(NULL) { //ALOGI("Creating SharedZip %p %s\n", this, (const char*)mPath); - mZipFile = new ZipFileRO; ALOGV("+++ opening zip '%s'\n", mPath.string()); - if (mZipFile->open(mPath.string()) != NO_ERROR) { + mZipFile = ZipFileRO::open(mPath.string()); + if (mZipFile == NULL) { ALOGD("failed to open Zip archive '%s'\n", mPath.string()); - delete mZipFile; - mZipFile = NULL; } } |