Skip to content

Commit 10410fc

Browse files
Anthony Mazzolakruton
authored andcommitted
Fix issue with selecting proper JNI libraries
Current code will load both abi and abi2 versions of the JNI libraries. The second one found will be the library in use. Update algorithm so that abi2 libraries will never be loaded once we find a library that supports the primary abi. This is consistent with the original implementation. Bug: 5787224 Change-Id: Ib4d30bea8316ca9bf62757c970dcc5b75cd969ec
1 parent c892e17 commit 10410fc

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

core/jni/com_android_internal_content_NativeLibraryHelper.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ iterateOverNativeFiles(JNIEnv *env, jstring javaFilePath, jstring javaCpuAbi, js
283283
const int N = zipFile.getNumEntries();
284284

285285
char fileName[PATH_MAX];
286+
bool hasPrimaryAbi = false;
286287

287288
for (int i = 0; i < N; i++) {
288289
const ZipEntryRO entry = zipFile.findEntryByIndex(i);
@@ -318,11 +319,22 @@ iterateOverNativeFiles(JNIEnv *env, jstring javaFilePath, jstring javaCpuAbi, js
318319
if (cpuAbi.size() == cpuAbiRegionSize
319320
&& *(cpuAbiOffset + cpuAbi.size()) == '/'
320321
&& !strncmp(cpuAbiOffset, cpuAbi.c_str(), cpuAbiRegionSize)) {
321-
LOGV("Using ABI %s\n", cpuAbi.c_str());
322+
LOGV("Using primary ABI %s\n", cpuAbi.c_str());
323+
hasPrimaryAbi = true;
322324
} else if (cpuAbi2.size() == cpuAbiRegionSize
323325
&& *(cpuAbiOffset + cpuAbi2.size()) == '/'
324326
&& !strncmp(cpuAbiOffset, cpuAbi2.c_str(), cpuAbiRegionSize)) {
325-
LOGV("Using ABI %s\n", cpuAbi2.c_str());
327+
328+
/*
329+
* If this library matches both the primary and secondary ABIs,
330+
* only use the primary ABI.
331+
*/
332+
if (hasPrimaryAbi) {
333+
LOGV("Already saw primary ABI, skipping secondary ABI %s\n", cpuAbi2.c_str());
334+
continue;
335+
} else {
336+
LOGV("Using secondary ABI %s\n", cpuAbi2.c_str());
337+
}
326338
} else {
327339
LOGV("abi didn't match anything: %s (end at %zd)\n", cpuAbiOffset, cpuAbiRegionSize);
328340
continue;

0 commit comments

Comments
 (0)