summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Yusuke Sato <yusukes@google.com> 2015-06-19 17:18:07 -0700
committer Yusuke Sato <yusukes@google.com> 2015-06-22 16:11:32 -0700
commit34fe3df8519523dbb4bc27010fa57f259d5e868d (patch)
tree08282d0b6cc64337f57e5d9964bf14d42580fddb
parent84a378f256bf7925ceb5d2c039a033d3e59b75df (diff)
Let findSupportedAbi and hasRenderscriptBitcode scan only relevant files
for better performance. Without the optimization, these two functions may check more than 100k file names in the pre-installed APK files, which can take a few seconds to finish even on a recent device. Bug: 21957428 Change-Id: I315fd3c6d5aa1076b993752525de449a9933de12
-rw-r--r--core/jni/com_android_internal_content_NativeLibraryHelper.cpp16
-rw-r--r--include/androidfw/ZipFileRO.h1
-rw-r--r--libs/androidfw/ZipFileRO.cpp12
3 files changed, 15 insertions, 14 deletions
diff --git a/core/jni/com_android_internal_content_NativeLibraryHelper.cpp b/core/jni/com_android_internal_content_NativeLibraryHelper.cpp
index a526223cf215..daa6f82ea122 100644
--- a/core/jni/com_android_internal_content_NativeLibraryHelper.cpp
+++ b/core/jni/com_android_internal_content_NativeLibraryHelper.cpp
@@ -48,7 +48,6 @@
#define LIB_SUFFIX_LEN (sizeof(LIB_SUFFIX) - 1)
#define RS_BITCODE_SUFFIX ".bc"
-#define RS_BITCODE_SUFFIX_LEN (sizeof(RS_BITCODE_SUFFIX) -1)
#define GDBSERVER "gdbserver"
#define GDBSERVER_LEN (sizeof(GDBSERVER) - 1)
@@ -322,7 +321,8 @@ private:
public:
static NativeLibrariesIterator* create(ZipFileRO* zipFile) {
void* cookie = NULL;
- if (!zipFile->startIteration(&cookie)) {
+ // Do not specify a suffix to find both .so files and gdbserver.
+ if (!zipFile->startIteration(&cookie, APK_LIB, NULL /* suffix */)) {
return NULL;
}
@@ -337,11 +337,6 @@ public:
continue;
}
- // Make sure we're in the lib directory of the ZIP.
- if (strncmp(fileName, APK_LIB, APK_LIB_LEN)) {
- continue;
- }
-
// Make sure the filename is at least to the minimum library name size.
const size_t fileNameLen = strlen(fileName);
static const size_t minLength = APK_LIB_LEN + 2 + LIB_PREFIX_LEN + 1 + LIB_SUFFIX_LEN;
@@ -529,7 +524,7 @@ com_android_internal_content_NativeLibraryHelper_hasRenderscriptBitcode(JNIEnv *
jlong apkHandle) {
ZipFileRO* zipFile = reinterpret_cast<ZipFileRO*>(apkHandle);
void* cookie = NULL;
- if (!zipFile->startIteration(&cookie)) {
+ if (!zipFile->startIteration(&cookie, NULL /* prefix */, RS_BITCODE_SUFFIX)) {
return APK_SCAN_ERROR;
}
@@ -539,12 +534,9 @@ com_android_internal_content_NativeLibraryHelper_hasRenderscriptBitcode(JNIEnv *
if (zipFile->getEntryFileName(next, fileName, sizeof(fileName))) {
continue;
}
-
- const size_t fileNameLen = strlen(fileName);
const char* lastSlash = strrchr(fileName, '/');
const char* baseName = (lastSlash == NULL) ? fileName : fileName + 1;
- if (!strncmp(fileName + fileNameLen - RS_BITCODE_SUFFIX_LEN, RS_BITCODE_SUFFIX,
- RS_BITCODE_SUFFIX_LEN) && isFilenameSafe(baseName)) {
+ if (isFilenameSafe(baseName)) {
zipFile->endIteration(cookie);
return BITCODE_PRESENT;
}
diff --git a/include/androidfw/ZipFileRO.h b/include/androidfw/ZipFileRO.h
index 1410d87f3e86..768034287afa 100644
--- a/include/androidfw/ZipFileRO.h
+++ b/include/androidfw/ZipFileRO.h
@@ -91,6 +91,7 @@ public:
* a matching call to endIteration with the same cookie.
*/
bool startIteration(void** cookie);
+ bool startIteration(void** cookie, const char* prefix, const char* suffix);
/**
* Return the next entry in iteration order, or NULL if there are no more
diff --git a/libs/androidfw/ZipFileRO.cpp b/libs/androidfw/ZipFileRO.cpp
index 6f927b41fa64..a6f6d8c4ff16 100644
--- a/libs/androidfw/ZipFileRO.cpp
+++ b/libs/androidfw/ZipFileRO.cpp
@@ -126,10 +126,18 @@ bool ZipFileRO::getEntryInfo(ZipEntryRO entry, uint16_t* pMethod,
return true;
}
-bool ZipFileRO::startIteration(void** cookie)
+bool ZipFileRO::startIteration(void** cookie) {
+ return startIteration(cookie, NULL, NULL);
+}
+
+bool ZipFileRO::startIteration(void** cookie, const char* prefix, const char* suffix)
{
_ZipEntryRO* ze = new _ZipEntryRO;
- int32_t error = StartIteration(mHandle, &(ze->cookie), NULL /* prefix */);
+ ZipEntryName pe(prefix ? prefix : "");
+ ZipEntryName se(suffix ? suffix : "");
+ int32_t error = StartIteration(mHandle, &(ze->cookie),
+ prefix ? &pe : NULL,
+ suffix ? &se : NULL);
if (error) {
ALOGW("Could not start iteration over %s: %s", mFileName, ErrorCodeString(error));
delete ze;