1 /*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #define LOG_TAG "NativeLibraryHelper"
18 //#define LOG_NDEBUG 0
19
20 #include "core_jni_helpers.h"
21
22 #include <nativehelper/ScopedUtfChars.h>
23 #include <androidfw/ZipFileRO.h>
24 #include <androidfw/ZipUtils.h>
25 #include <utils/Log.h>
26 #include <utils/Vector.h>
27
28 #include <zlib.h>
29
30 #include <errno.h>
31 #include <fcntl.h>
32 #include <stdlib.h>
33 #include <string.h>
34 #include <time.h>
35 #include <unistd.h>
36 #include <inttypes.h>
37 #include <sys/stat.h>
38 #include <sys/types.h>
39
40 #include <memory>
41
42 #define APK_LIB "lib/"
43 #define APK_LIB_LEN (sizeof(APK_LIB) - 1)
44
45 #define LIB_PREFIX "/lib"
46 #define LIB_PREFIX_LEN (sizeof(LIB_PREFIX) - 1)
47
48 #define LIB_SUFFIX ".so"
49 #define LIB_SUFFIX_LEN (sizeof(LIB_SUFFIX) - 1)
50
51 #define RS_BITCODE_SUFFIX ".bc"
52
53 #define TMP_FILE_PATTERN "/tmp.XXXXXX"
54 #define TMP_FILE_PATTERN_LEN (sizeof(TMP_FILE_PATTERN) - 1)
55
56 namespace android {
57
58 // These match PackageManager.java install codes
59 enum install_status_t {
60 INSTALL_SUCCEEDED = 1,
61 INSTALL_FAILED_INVALID_APK = -2,
62 INSTALL_FAILED_INSUFFICIENT_STORAGE = -4,
63 INSTALL_FAILED_CONTAINER_ERROR = -18,
64 INSTALL_FAILED_INTERNAL_ERROR = -110,
65 INSTALL_FAILED_NO_MATCHING_ABIS = -113,
66 NO_NATIVE_LIBRARIES = -114
67 };
68
69 typedef install_status_t (*iterFunc)(JNIEnv*, void*, ZipFileRO*, ZipEntryRO, const char*);
70
71 // Equivalent to android.os.FileUtils.isFilenameSafe
72 static bool
isFilenameSafe(const char * filename)73 isFilenameSafe(const char* filename)
74 {
75 off_t offset = 0;
76 for (;;) {
77 switch (*(filename + offset)) {
78 case 0:
79 // Null.
80 // If we've reached the end, all the other characters are good.
81 return true;
82
83 case 'A' ... 'Z':
84 case 'a' ... 'z':
85 case '0' ... '9':
86 case '+':
87 case ',':
88 case '-':
89 case '.':
90 case '/':
91 case '=':
92 case '_':
93 offset++;
94 break;
95
96 default:
97 // We found something that is not good.
98 return false;
99 }
100 }
101 // Should not reach here.
102 }
103
104 static bool
isFileDifferent(const char * filePath,uint32_t fileSize,time_t modifiedTime,uint32_t zipCrc,struct stat64 * st)105 isFileDifferent(const char* filePath, uint32_t fileSize, time_t modifiedTime,
106 uint32_t zipCrc, struct stat64* st)
107 {
108 if (lstat64(filePath, st) < 0) {
109 // File is not found or cannot be read.
110 ALOGV("Couldn't stat %s, copying: %s\n", filePath, strerror(errno));
111 return true;
112 }
113
114 if (!S_ISREG(st->st_mode)) {
115 return true;
116 }
117
118 if (static_cast<uint64_t>(st->st_size) != static_cast<uint64_t>(fileSize)) {
119 return true;
120 }
121
122 // For some reason, bionic doesn't define st_mtime as time_t
123 if (time_t(st->st_mtime) != modifiedTime) {
124 ALOGV("mod time doesn't match: %ld vs. %ld\n", st->st_mtime, modifiedTime);
125 return true;
126 }
127
128 int fd = TEMP_FAILURE_RETRY(open(filePath, O_RDONLY | O_CLOEXEC));
129 if (fd < 0) {
130 ALOGV("Couldn't open file %s: %s", filePath, strerror(errno));
131 return true;
132 }
133
134 // uLong comes from zlib.h. It's a bit of a wart that they're
135 // potentially using a 64-bit type for a 32-bit CRC.
136 uLong crc = crc32(0L, Z_NULL, 0);
137 unsigned char crcBuffer[16384];
138 ssize_t numBytes;
139 while ((numBytes = TEMP_FAILURE_RETRY(read(fd, crcBuffer, sizeof(crcBuffer)))) > 0) {
140 crc = crc32(crc, crcBuffer, numBytes);
141 }
142 close(fd);
143
144 ALOGV("%s: crc = %lx, zipCrc = %" PRIu32 "\n", filePath, crc, zipCrc);
145
146 if (crc != static_cast<uLong>(zipCrc)) {
147 return true;
148 }
149
150 return false;
151 }
152
153 static install_status_t
sumFiles(JNIEnv *,void * arg,ZipFileRO * zipFile,ZipEntryRO zipEntry,const char *)154 sumFiles(JNIEnv*, void* arg, ZipFileRO* zipFile, ZipEntryRO zipEntry, const char*)
155 {
156 size_t* total = (size_t*) arg;
157 uint32_t uncompLen;
158
159 if (!zipFile->getEntryInfo(zipEntry, NULL, &uncompLen, NULL, NULL, NULL, NULL)) {
160 return INSTALL_FAILED_INVALID_APK;
161 }
162
163 *total += static_cast<size_t>(uncompLen);
164
165 return INSTALL_SUCCEEDED;
166 }
167
168 /*
169 * Copy the native library if needed.
170 *
171 * This function assumes the library and path names passed in are considered safe.
172 */
173 static install_status_t
copyFileIfChanged(JNIEnv * env,void * arg,ZipFileRO * zipFile,ZipEntryRO zipEntry,const char * fileName)174 copyFileIfChanged(JNIEnv *env, void* arg, ZipFileRO* zipFile, ZipEntryRO zipEntry, const char* fileName)
175 {
176 void** args = reinterpret_cast<void**>(arg);
177 jstring* javaNativeLibPath = (jstring*) args[0];
178 jboolean extractNativeLibs = *(jboolean*) args[1];
179
180 ScopedUtfChars nativeLibPath(env, *javaNativeLibPath);
181
182 uint32_t uncompLen;
183 uint32_t when;
184 uint32_t crc;
185
186 uint16_t method;
187 off64_t offset;
188
189 if (!zipFile->getEntryInfo(zipEntry, &method, &uncompLen, NULL, &offset, &when, &crc)) {
190 ALOGE("Couldn't read zip entry info\n");
191 return INSTALL_FAILED_INVALID_APK;
192 }
193
194 if (!extractNativeLibs) {
195 // check if library is uncompressed and page-aligned
196 if (method != ZipFileRO::kCompressStored) {
197 ALOGE("Library '%s' is compressed - will not be able to open it directly from apk.\n",
198 fileName);
199 return INSTALL_FAILED_INVALID_APK;
200 }
201
202 if (offset % PAGE_SIZE != 0) {
203 ALOGE("Library '%s' is not page-aligned - will not be able to open it directly from"
204 " apk.\n", fileName);
205 return INSTALL_FAILED_INVALID_APK;
206 }
207
208 return INSTALL_SUCCEEDED;
209 }
210
211 // Build local file path
212 const size_t fileNameLen = strlen(fileName);
213 char localFileName[nativeLibPath.size() + fileNameLen + 2];
214
215 if (strlcpy(localFileName, nativeLibPath.c_str(), sizeof(localFileName)) != nativeLibPath.size()) {
216 ALOGE("Couldn't allocate local file name for library");
217 return INSTALL_FAILED_INTERNAL_ERROR;
218 }
219
220 *(localFileName + nativeLibPath.size()) = '/';
221
222 if (strlcpy(localFileName + nativeLibPath.size() + 1, fileName, sizeof(localFileName)
223 - nativeLibPath.size() - 1) != fileNameLen) {
224 ALOGE("Couldn't allocate local file name for library");
225 return INSTALL_FAILED_INTERNAL_ERROR;
226 }
227
228 // Only copy out the native file if it's different.
229 struct tm t;
230 ZipUtils::zipTimeToTimespec(when, &t);
231 const time_t modTime = mktime(&t);
232 struct stat64 st;
233 if (!isFileDifferent(localFileName, uncompLen, modTime, crc, &st)) {
234 return INSTALL_SUCCEEDED;
235 }
236
237 char localTmpFileName[nativeLibPath.size() + TMP_FILE_PATTERN_LEN + 1];
238 if (strlcpy(localTmpFileName, nativeLibPath.c_str(), sizeof(localTmpFileName))
239 != nativeLibPath.size()) {
240 ALOGE("Couldn't allocate local file name for library");
241 return INSTALL_FAILED_INTERNAL_ERROR;
242 }
243
244 if (strlcpy(localTmpFileName + nativeLibPath.size(), TMP_FILE_PATTERN,
245 TMP_FILE_PATTERN_LEN + 1) != TMP_FILE_PATTERN_LEN) {
246 ALOGE("Couldn't allocate temporary file name for library");
247 return INSTALL_FAILED_INTERNAL_ERROR;
248 }
249
250 int fd = mkstemp(localTmpFileName);
251 if (fd < 0) {
252 ALOGE("Couldn't open temporary file name: %s: %s\n", localTmpFileName, strerror(errno));
253 return INSTALL_FAILED_CONTAINER_ERROR;
254 }
255
256 if (!zipFile->uncompressEntry(zipEntry, fd)) {
257 ALOGE("Failed uncompressing %s to %s\n", fileName, localTmpFileName);
258 close(fd);
259 unlink(localTmpFileName);
260 return INSTALL_FAILED_CONTAINER_ERROR;
261 }
262
263 close(fd);
264
265 // Set the modification time for this file to the ZIP's mod time.
266 struct timeval times[2];
267 times[0].tv_sec = st.st_atime;
268 times[1].tv_sec = modTime;
269 times[0].tv_usec = times[1].tv_usec = 0;
270 if (utimes(localTmpFileName, times) < 0) {
271 ALOGE("Couldn't change modification time on %s: %s\n", localTmpFileName, strerror(errno));
272 unlink(localTmpFileName);
273 return INSTALL_FAILED_CONTAINER_ERROR;
274 }
275
276 // Set the mode to 755
277 static const mode_t mode = S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
278 if (chmod(localTmpFileName, mode) < 0) {
279 ALOGE("Couldn't change permissions on %s: %s\n", localTmpFileName, strerror(errno));
280 unlink(localTmpFileName);
281 return INSTALL_FAILED_CONTAINER_ERROR;
282 }
283
284 // Finally, rename it to the final name.
285 if (rename(localTmpFileName, localFileName) < 0) {
286 ALOGE("Couldn't rename %s to %s: %s\n", localTmpFileName, localFileName, strerror(errno));
287 unlink(localTmpFileName);
288 return INSTALL_FAILED_CONTAINER_ERROR;
289 }
290
291 ALOGV("Successfully moved %s to %s\n", localTmpFileName, localFileName);
292
293 return INSTALL_SUCCEEDED;
294 }
295
296 /*
297 * An iterator over all shared libraries in a zip file. An entry is
298 * considered to be a shared library if all of the conditions below are
299 * satisfied :
300 *
301 * - The entry is under the lib/ directory.
302 * - The entry name ends with ".so" and the entry name starts with "lib",
303 * an exception is made for entries whose name is "gdbserver".
304 * - The entry filename is "safe" (as determined by isFilenameSafe).
305 *
306 */
307 class NativeLibrariesIterator {
308 private:
NativeLibrariesIterator(ZipFileRO * zipFile,bool debuggable,void * cookie)309 NativeLibrariesIterator(ZipFileRO* zipFile, bool debuggable, void* cookie)
310 : mZipFile(zipFile), mDebuggable(debuggable), mCookie(cookie), mLastSlash(NULL) {
311 fileName[0] = '\0';
312 }
313
314 public:
create(ZipFileRO * zipFile,bool debuggable)315 static NativeLibrariesIterator* create(ZipFileRO* zipFile, bool debuggable) {
316 void* cookie = NULL;
317 // Do not specify a suffix to find both .so files and gdbserver.
318 if (!zipFile->startIteration(&cookie, APK_LIB, NULL /* suffix */)) {
319 return NULL;
320 }
321
322 return new NativeLibrariesIterator(zipFile, debuggable, cookie);
323 }
324
next()325 ZipEntryRO next() {
326 ZipEntryRO next = NULL;
327 while ((next = mZipFile->nextEntry(mCookie)) != NULL) {
328 // Make sure this entry has a filename.
329 if (mZipFile->getEntryFileName(next, fileName, sizeof(fileName))) {
330 continue;
331 }
332
333 // Make sure the filename is at least to the minimum library name size.
334 const size_t fileNameLen = strlen(fileName);
335 static const size_t minLength = APK_LIB_LEN + 2 + LIB_PREFIX_LEN + 1 + LIB_SUFFIX_LEN;
336 if (fileNameLen < minLength) {
337 continue;
338 }
339
340 const char* lastSlash = strrchr(fileName, '/');
341 ALOG_ASSERT(lastSlash != NULL, "last slash was null somehow for %s\n", fileName);
342
343 // Skip directories.
344 if (*(lastSlash + 1) == 0) {
345 continue;
346 }
347
348 // Make sure the filename is safe.
349 if (!isFilenameSafe(lastSlash + 1)) {
350 continue;
351 }
352
353 if (!mDebuggable) {
354 // Make sure the filename starts with lib and ends with ".so".
355 if (strncmp(fileName + fileNameLen - LIB_SUFFIX_LEN, LIB_SUFFIX, LIB_SUFFIX_LEN)
356 || strncmp(lastSlash, LIB_PREFIX, LIB_PREFIX_LEN)) {
357 continue;
358 }
359 }
360
361 mLastSlash = lastSlash;
362 break;
363 }
364
365 return next;
366 }
367
currentEntry() const368 inline const char* currentEntry() const {
369 return fileName;
370 }
371
lastSlash() const372 inline const char* lastSlash() const {
373 return mLastSlash;
374 }
375
~NativeLibrariesIterator()376 virtual ~NativeLibrariesIterator() {
377 mZipFile->endIteration(mCookie);
378 }
379 private:
380
381 char fileName[PATH_MAX];
382 ZipFileRO* const mZipFile;
383 const bool mDebuggable;
384 void* mCookie;
385 const char* mLastSlash;
386 };
387
388 static install_status_t
iterateOverNativeFiles(JNIEnv * env,jlong apkHandle,jstring javaCpuAbi,jboolean debuggable,iterFunc callFunc,void * callArg)389 iterateOverNativeFiles(JNIEnv *env, jlong apkHandle, jstring javaCpuAbi,
390 jboolean debuggable, iterFunc callFunc, void* callArg) {
391 ZipFileRO* zipFile = reinterpret_cast<ZipFileRO*>(apkHandle);
392 if (zipFile == NULL) {
393 return INSTALL_FAILED_INVALID_APK;
394 }
395
396 std::unique_ptr<NativeLibrariesIterator> it(
397 NativeLibrariesIterator::create(zipFile, debuggable));
398 if (it.get() == NULL) {
399 return INSTALL_FAILED_INVALID_APK;
400 }
401
402 const ScopedUtfChars cpuAbi(env, javaCpuAbi);
403 if (cpuAbi.c_str() == NULL) {
404 // This would've thrown, so this return code isn't observable by
405 // Java.
406 return INSTALL_FAILED_INVALID_APK;
407 }
408 ZipEntryRO entry = NULL;
409 while ((entry = it->next()) != NULL) {
410 const char* fileName = it->currentEntry();
411 const char* lastSlash = it->lastSlash();
412
413 // Check to make sure the CPU ABI of this file is one we support.
414 const char* cpuAbiOffset = fileName + APK_LIB_LEN;
415 const size_t cpuAbiRegionSize = lastSlash - cpuAbiOffset;
416
417 if (cpuAbi.size() == cpuAbiRegionSize && !strncmp(cpuAbiOffset, cpuAbi.c_str(), cpuAbiRegionSize)) {
418 install_status_t ret = callFunc(env, callArg, zipFile, entry, lastSlash + 1);
419
420 if (ret != INSTALL_SUCCEEDED) {
421 ALOGV("Failure for entry %s", lastSlash + 1);
422 return ret;
423 }
424 }
425 }
426
427 return INSTALL_SUCCEEDED;
428 }
429
430
findSupportedAbi(JNIEnv * env,jlong apkHandle,jobjectArray supportedAbisArray,jboolean debuggable)431 static int findSupportedAbi(JNIEnv *env, jlong apkHandle, jobjectArray supportedAbisArray,
432 jboolean debuggable) {
433 const int numAbis = env->GetArrayLength(supportedAbisArray);
434 Vector<ScopedUtfChars*> supportedAbis;
435
436 for (int i = 0; i < numAbis; ++i) {
437 supportedAbis.add(new ScopedUtfChars(env,
438 (jstring) env->GetObjectArrayElement(supportedAbisArray, i)));
439 }
440
441 ZipFileRO* zipFile = reinterpret_cast<ZipFileRO*>(apkHandle);
442 if (zipFile == NULL) {
443 return INSTALL_FAILED_INVALID_APK;
444 }
445
446 std::unique_ptr<NativeLibrariesIterator> it(
447 NativeLibrariesIterator::create(zipFile, debuggable));
448 if (it.get() == NULL) {
449 return INSTALL_FAILED_INVALID_APK;
450 }
451
452 ZipEntryRO entry = NULL;
453 int status = NO_NATIVE_LIBRARIES;
454 while ((entry = it->next()) != NULL) {
455 // We're currently in the lib/ directory of the APK, so it does have some native
456 // code. We should return INSTALL_FAILED_NO_MATCHING_ABIS if none of the
457 // libraries match.
458 if (status == NO_NATIVE_LIBRARIES) {
459 status = INSTALL_FAILED_NO_MATCHING_ABIS;
460 }
461
462 const char* fileName = it->currentEntry();
463 const char* lastSlash = it->lastSlash();
464
465 // Check to see if this CPU ABI matches what we are looking for.
466 const char* abiOffset = fileName + APK_LIB_LEN;
467 const size_t abiSize = lastSlash - abiOffset;
468 for (int i = 0; i < numAbis; i++) {
469 const ScopedUtfChars* abi = supportedAbis[i];
470 if (abi->size() == abiSize && !strncmp(abiOffset, abi->c_str(), abiSize)) {
471 // The entry that comes in first (i.e. with a lower index) has the higher priority.
472 if (((i < status) && (status >= 0)) || (status < 0) ) {
473 status = i;
474 }
475 }
476 }
477 }
478
479 for (int i = 0; i < numAbis; ++i) {
480 delete supportedAbis[i];
481 }
482
483 return status;
484 }
485
486 static jint
com_android_internal_content_NativeLibraryHelper_copyNativeBinaries(JNIEnv * env,jclass clazz,jlong apkHandle,jstring javaNativeLibPath,jstring javaCpuAbi,jboolean extractNativeLibs,jboolean debuggable)487 com_android_internal_content_NativeLibraryHelper_copyNativeBinaries(JNIEnv *env, jclass clazz,
488 jlong apkHandle, jstring javaNativeLibPath, jstring javaCpuAbi,
489 jboolean extractNativeLibs, jboolean debuggable)
490 {
491 void* args[] = { &javaNativeLibPath, &extractNativeLibs };
492 return (jint) iterateOverNativeFiles(env, apkHandle, javaCpuAbi, debuggable,
493 copyFileIfChanged, reinterpret_cast<void*>(args));
494 }
495
496 static jlong
com_android_internal_content_NativeLibraryHelper_sumNativeBinaries(JNIEnv * env,jclass clazz,jlong apkHandle,jstring javaCpuAbi,jboolean debuggable)497 com_android_internal_content_NativeLibraryHelper_sumNativeBinaries(JNIEnv *env, jclass clazz,
498 jlong apkHandle, jstring javaCpuAbi, jboolean debuggable)
499 {
500 size_t totalSize = 0;
501
502 iterateOverNativeFiles(env, apkHandle, javaCpuAbi, debuggable, sumFiles, &totalSize);
503
504 return totalSize;
505 }
506
507 static jint
com_android_internal_content_NativeLibraryHelper_findSupportedAbi(JNIEnv * env,jclass clazz,jlong apkHandle,jobjectArray javaCpuAbisToSearch,jboolean debuggable)508 com_android_internal_content_NativeLibraryHelper_findSupportedAbi(JNIEnv *env, jclass clazz,
509 jlong apkHandle, jobjectArray javaCpuAbisToSearch, jboolean debuggable)
510 {
511 return (jint) findSupportedAbi(env, apkHandle, javaCpuAbisToSearch, debuggable);
512 }
513
514 enum bitcode_scan_result_t {
515 APK_SCAN_ERROR = -1,
516 NO_BITCODE_PRESENT = 0,
517 BITCODE_PRESENT = 1,
518 };
519
520 static jint
com_android_internal_content_NativeLibraryHelper_hasRenderscriptBitcode(JNIEnv * env,jclass clazz,jlong apkHandle)521 com_android_internal_content_NativeLibraryHelper_hasRenderscriptBitcode(JNIEnv *env, jclass clazz,
522 jlong apkHandle) {
523 ZipFileRO* zipFile = reinterpret_cast<ZipFileRO*>(apkHandle);
524 void* cookie = NULL;
525 if (!zipFile->startIteration(&cookie, NULL /* prefix */, RS_BITCODE_SUFFIX)) {
526 return APK_SCAN_ERROR;
527 }
528
529 char fileName[PATH_MAX];
530 ZipEntryRO next = NULL;
531 while ((next = zipFile->nextEntry(cookie)) != NULL) {
532 if (zipFile->getEntryFileName(next, fileName, sizeof(fileName))) {
533 continue;
534 }
535 const char* lastSlash = strrchr(fileName, '/');
536 const char* baseName = (lastSlash == NULL) ? fileName : fileName + 1;
537 if (isFilenameSafe(baseName)) {
538 zipFile->endIteration(cookie);
539 return BITCODE_PRESENT;
540 }
541 }
542
543 zipFile->endIteration(cookie);
544 return NO_BITCODE_PRESENT;
545 }
546
547 static jlong
com_android_internal_content_NativeLibraryHelper_openApk(JNIEnv * env,jclass,jstring apkPath)548 com_android_internal_content_NativeLibraryHelper_openApk(JNIEnv *env, jclass, jstring apkPath)
549 {
550 ScopedUtfChars filePath(env, apkPath);
551 ZipFileRO* zipFile = ZipFileRO::open(filePath.c_str());
552
553 return reinterpret_cast<jlong>(zipFile);
554 }
555
556 static jlong
com_android_internal_content_NativeLibraryHelper_openApkFd(JNIEnv * env,jclass,jobject fileDescriptor,jstring debugPathName)557 com_android_internal_content_NativeLibraryHelper_openApkFd(JNIEnv *env, jclass,
558 jobject fileDescriptor, jstring debugPathName)
559 {
560 ScopedUtfChars debugFilePath(env, debugPathName);
561
562 int fd = jniGetFDFromFileDescriptor(env, fileDescriptor);
563 if (fd < 0) {
564 jniThrowException(env, "java/lang/IllegalArgumentException", "Bad FileDescriptor");
565 return 0;
566 }
567
568 int dupedFd = fcntl(fd, F_DUPFD_CLOEXEC, 0);
569 if (dupedFd == -1) {
570 jniThrowExceptionFmt(env, "java/lang/IllegalArgumentException",
571 "Failed to dup FileDescriptor: %s", strerror(errno));
572 return 0;
573 }
574
575 ZipFileRO* zipFile = ZipFileRO::openFd(dupedFd, debugFilePath.c_str());
576
577 return reinterpret_cast<jlong>(zipFile);
578 }
579
580 static void
com_android_internal_content_NativeLibraryHelper_close(JNIEnv * env,jclass,jlong apkHandle)581 com_android_internal_content_NativeLibraryHelper_close(JNIEnv *env, jclass, jlong apkHandle)
582 {
583 delete reinterpret_cast<ZipFileRO*>(apkHandle);
584 }
585
586 static const JNINativeMethod gMethods[] = {
587 {"nativeOpenApk",
588 "(Ljava/lang/String;)J",
589 (void *)com_android_internal_content_NativeLibraryHelper_openApk},
590 {"nativeOpenApkFd",
591 "(Ljava/io/FileDescriptor;Ljava/lang/String;)J",
592 (void *)com_android_internal_content_NativeLibraryHelper_openApkFd},
593 {"nativeClose",
594 "(J)V",
595 (void *)com_android_internal_content_NativeLibraryHelper_close},
596 {"nativeCopyNativeBinaries",
597 "(JLjava/lang/String;Ljava/lang/String;ZZ)I",
598 (void *)com_android_internal_content_NativeLibraryHelper_copyNativeBinaries},
599 {"nativeSumNativeBinaries",
600 "(JLjava/lang/String;Z)J",
601 (void *)com_android_internal_content_NativeLibraryHelper_sumNativeBinaries},
602 {"nativeFindSupportedAbi",
603 "(J[Ljava/lang/String;Z)I",
604 (void *)com_android_internal_content_NativeLibraryHelper_findSupportedAbi},
605 {"hasRenderscriptBitcode", "(J)I",
606 (void *)com_android_internal_content_NativeLibraryHelper_hasRenderscriptBitcode},
607 };
608
609
register_com_android_internal_content_NativeLibraryHelper(JNIEnv * env)610 int register_com_android_internal_content_NativeLibraryHelper(JNIEnv *env)
611 {
612 return RegisterMethodsOrDie(env,
613 "com/android/internal/content/NativeLibraryHelper", gMethods, NELEM(gMethods));
614 }
615
616 };
617