summaryrefslogtreecommitdiff
path: root/libs/androidfw/AssetManager.cpp
diff options
context:
space:
mode:
author Narayan Kamath <narayan@google.com> 2013-12-03 13:16:03 +0000
committer Adam Lesinski <adamlesinski@google.com> 2014-01-27 10:31:11 -0800
commit560566d2915c03bed338fc532ac7f7aa3620cfdf (patch)
tree05c38c1fdcea2989eab2ff6e2934afa4f1f09326 /libs/androidfw/AssetManager.cpp
parente1aa223657dd1def8609b377afa86a024bfd4e14 (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 (cherry picked from commit afd31e08299008fdc5c2813f21b2573f29dc53df) Change-Id: Iae67e62f1dc6dfc3f43e29bc38e3ffd1cb14d191
Diffstat (limited to 'libs/androidfw/AssetManager.cpp')
-rw-r--r--libs/androidfw/AssetManager.cpp44
1 files changed, 23 insertions, 21 deletions
diff --git a/libs/androidfw/AssetManager.cpp b/libs/androidfw/AssetManager.cpp
index 1f0d5309f2bc..86517648814a 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;
}
}