Loading core/java/com/android/internal/content/NativeLibraryHelper.java +15 −0 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import android.content.pm.PackageManager; import android.util.Slog; import java.io.File; import java.io.IOException; /** * Native libraries helper. Loading Loading @@ -141,4 +142,18 @@ public class NativeLibraryHelper { return deletedFiles; } // We don't care about the other return values for now. private static final int BITCODE_PRESENT = 1; public static boolean hasRenderscriptBitcode(ApkHandle handle) throws IOException { final int returnVal = hasRenderscriptBitcode(handle.apkHandle); if (returnVal < 0) { throw new IOException("Error scanning APK, code: " + returnVal); } return (returnVal == BITCODE_PRESENT); } private static native int hasRenderscriptBitcode(long apkHandle); } core/jni/com_android_internal_content_NativeLibraryHelper.cpp +41 −0 Original line number Diff line number Diff line Loading @@ -46,6 +46,9 @@ #define LIB_SUFFIX ".so" #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) Loading Loading @@ -486,6 +489,42 @@ com_android_internal_content_NativeLibraryHelper_findSupportedAbi(JNIEnv *env, j return (jint) findSupportedAbi(env, apkHandle, javaCpuAbisToSearch); } enum bitcode_scan_result_t { APK_SCAN_ERROR = -1, NO_BITCODE_PRESENT = 0, BITCODE_PRESENT = 1, }; static jint com_android_internal_content_NativeLibraryHelper_hasRenderscriptBitcode(JNIEnv *env, jclass clazz, jlong apkHandle) { ZipFileRO* zipFile = reinterpret_cast<ZipFileRO*>(apkHandle); void* cookie = NULL; if (!zipFile->startIteration(&cookie)) { return APK_SCAN_ERROR; } char fileName[PATH_MAX]; ZipEntryRO next = NULL; while ((next = zipFile->nextEntry(cookie)) != NULL) { 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)) { zipFile->endIteration(cookie); return BITCODE_PRESENT; } } zipFile->endIteration(cookie); return NO_BITCODE_PRESENT; } static jlong com_android_internal_content_NativeLibraryHelper_openApk(JNIEnv *env, jclass, jstring apkPath) { Loading Loading @@ -517,6 +556,8 @@ static JNINativeMethod gMethods[] = { {"nativeFindSupportedAbi", "(J[Ljava/lang/String;)I", (void *)com_android_internal_content_NativeLibraryHelper_findSupportedAbi}, {"hasRenderscriptBitcode", "(J)I", (void *)com_android_internal_content_NativeLibraryHelper_hasRenderscriptBitcode}, }; Loading packages/DefaultContainerService/src/com/android/defcontainer/DefaultContainerService.java +16 −3 Original line number Diff line number Diff line Loading @@ -88,7 +88,7 @@ public class DefaultContainerService extends IntentService { private IMediaContainerService.Stub mBinder = new IMediaContainerService.Stub() { /** * Creates a new container and copies resource there. * @param paackageURI the uri of resource to be copied. Can be either * @param packageURI the uri of resource to be copied. Can be either * a content uri or a file uri * @param cid the id of the secure container that should * be used for creating a secure container into which the resource Loading Loading @@ -342,9 +342,22 @@ public class DefaultContainerService extends IntentService { // The .apk file String codePath = packageURI.getPath(); File codeFile = new File(codePath); String[] abiList = (abiOverride != null) ? new String[] { abiOverride } : Build.SUPPORTED_ABIS; NativeLibraryHelper.ApkHandle handle = new NativeLibraryHelper.ApkHandle(codePath); String[] abiList = Build.SUPPORTED_ABIS; if (abiOverride != null) { abiList = new String[] { abiList }; } else { try { if (Build.SUPPORTED_64_BIT_ABIS.length > 0 && NativeLibraryHelper.hasRenderscriptBitcode(handle)) { abiList = Build.SUPPORTED_32_BIT_ABIS; } } catch (IOException ioe) { Slog.w(TAG, "Problem determining ABI for: " + codeFile.getPath()); return null; } } final int abi = NativeLibraryHelper.findSupportedAbi(handle, abiList); // Calculate size of container needed to hold base APK. Loading services/java/com/android/server/pm/PackageManagerService.java +31 −13 Original line number Diff line number Diff line Loading @@ -5041,12 +5041,23 @@ public class PackageManagerService extends IPackageManager.Stub { if (pkg.applicationInfo.nativeLibraryDir != null) { final NativeLibraryHelper.ApkHandle handle = new NativeLibraryHelper.ApkHandle(scanFile); try { // Enable gross and lame hacks for apps that are built with old // SDK tools. We must scan their APKs for renderscript bitcode and // not launch them if it's present. Don't bother checking on devices // that don't have 64 bit support. String[] abiList = Build.SUPPORTED_ABIS; boolean hasLegacyRenderscriptBitcode = false; if (abiOverride != null) { abiList = new String[] { abiOverride }; } else if (Build.SUPPORTED_64_BIT_ABIS.length > 0 && NativeLibraryHelper.hasRenderscriptBitcode(handle)) { abiList = Build.SUPPORTED_32_BIT_ABIS; hasLegacyRenderscriptBitcode = true; } File nativeLibraryDir = new File(pkg.applicationInfo.nativeLibraryDir); final String dataPathString = dataPath.getCanonicalPath(); final String[] abiList = (abiOverride != null) ? new String[] { abiOverride } : Build.SUPPORTED_ABIS; if (isSystemApp(pkg) && !isUpdatedSystemApp(pkg)) { /* * Upgrading from a previous version of the OS sometimes Loading @@ -5059,8 +5070,9 @@ public class PackageManagerService extends IPackageManager.Stub { Log.i(TAG, "removed obsolete native libraries for system package " + path); } if (abiOverride != null) { pkg.applicationInfo.cpuAbi = abiOverride; if (abiOverride != null || hasLegacyRenderscriptBitcode) { pkg.applicationInfo.cpuAbi = abiList[0]; pkgSetting.cpuAbiString = abiList[0]; } else { setInternalAppAbi(pkg, pkgSetting); } Loading Loading @@ -5088,8 +5100,8 @@ public class PackageManagerService extends IPackageManager.Stub { // note of what ABI we're using if (copyRet != PackageManager.NO_NATIVE_LIBRARIES) { pkg.applicationInfo.cpuAbi = abiList[copyRet]; } else if (abiOverride != null) { pkg.applicationInfo.cpuAbi = abiOverride; } else if (abiOverride != null || hasLegacyRenderscriptBitcode) { pkg.applicationInfo.cpuAbi = abiList[0]; } else { pkg.applicationInfo.cpuAbi = null; } Loading @@ -5113,8 +5125,8 @@ public class PackageManagerService extends IPackageManager.Stub { // Note that (non upgraded) system apps will not have any native // libraries bundled in their APK, but we're guaranteed not to be // such an app at this point. if (abiOverride != null) { pkg.applicationInfo.cpuAbi = abiOverride; if (abiOverride != null || hasLegacyRenderscriptBitcode) { pkg.applicationInfo.cpuAbi = abiList[0]; } else { pkg.applicationInfo.cpuAbi = null; } Loading Loading @@ -8777,9 +8789,15 @@ public class PackageManagerService extends IPackageManager.Stub { } final NativeLibraryHelper.ApkHandle handle = new NativeLibraryHelper.ApkHandle(codeFile); final String[] abiList = (abiOverride != null) ? String[] abiList = (abiOverride != null) ? new String[] { abiOverride } : Build.SUPPORTED_ABIS; try { if (Build.SUPPORTED_64_BIT_ABIS.length > 0 && abiOverride == null && NativeLibraryHelper.hasRenderscriptBitcode(handle)) { abiList = Build.SUPPORTED_32_BIT_ABIS; } int copyRet = copyNativeLibrariesForInternalApp(handle, nativeLibraryFile, abiList); if (copyRet < 0 && copyRet != PackageManager.NO_NATIVE_LIBRARIES) { return copyRet; Loading Loading
core/java/com/android/internal/content/NativeLibraryHelper.java +15 −0 Original line number Diff line number Diff line Loading @@ -20,6 +20,7 @@ import android.content.pm.PackageManager; import android.util.Slog; import java.io.File; import java.io.IOException; /** * Native libraries helper. Loading Loading @@ -141,4 +142,18 @@ public class NativeLibraryHelper { return deletedFiles; } // We don't care about the other return values for now. private static final int BITCODE_PRESENT = 1; public static boolean hasRenderscriptBitcode(ApkHandle handle) throws IOException { final int returnVal = hasRenderscriptBitcode(handle.apkHandle); if (returnVal < 0) { throw new IOException("Error scanning APK, code: " + returnVal); } return (returnVal == BITCODE_PRESENT); } private static native int hasRenderscriptBitcode(long apkHandle); }
core/jni/com_android_internal_content_NativeLibraryHelper.cpp +41 −0 Original line number Diff line number Diff line Loading @@ -46,6 +46,9 @@ #define LIB_SUFFIX ".so" #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) Loading Loading @@ -486,6 +489,42 @@ com_android_internal_content_NativeLibraryHelper_findSupportedAbi(JNIEnv *env, j return (jint) findSupportedAbi(env, apkHandle, javaCpuAbisToSearch); } enum bitcode_scan_result_t { APK_SCAN_ERROR = -1, NO_BITCODE_PRESENT = 0, BITCODE_PRESENT = 1, }; static jint com_android_internal_content_NativeLibraryHelper_hasRenderscriptBitcode(JNIEnv *env, jclass clazz, jlong apkHandle) { ZipFileRO* zipFile = reinterpret_cast<ZipFileRO*>(apkHandle); void* cookie = NULL; if (!zipFile->startIteration(&cookie)) { return APK_SCAN_ERROR; } char fileName[PATH_MAX]; ZipEntryRO next = NULL; while ((next = zipFile->nextEntry(cookie)) != NULL) { 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)) { zipFile->endIteration(cookie); return BITCODE_PRESENT; } } zipFile->endIteration(cookie); return NO_BITCODE_PRESENT; } static jlong com_android_internal_content_NativeLibraryHelper_openApk(JNIEnv *env, jclass, jstring apkPath) { Loading Loading @@ -517,6 +556,8 @@ static JNINativeMethod gMethods[] = { {"nativeFindSupportedAbi", "(J[Ljava/lang/String;)I", (void *)com_android_internal_content_NativeLibraryHelper_findSupportedAbi}, {"hasRenderscriptBitcode", "(J)I", (void *)com_android_internal_content_NativeLibraryHelper_hasRenderscriptBitcode}, }; Loading
packages/DefaultContainerService/src/com/android/defcontainer/DefaultContainerService.java +16 −3 Original line number Diff line number Diff line Loading @@ -88,7 +88,7 @@ public class DefaultContainerService extends IntentService { private IMediaContainerService.Stub mBinder = new IMediaContainerService.Stub() { /** * Creates a new container and copies resource there. * @param paackageURI the uri of resource to be copied. Can be either * @param packageURI the uri of resource to be copied. Can be either * a content uri or a file uri * @param cid the id of the secure container that should * be used for creating a secure container into which the resource Loading Loading @@ -342,9 +342,22 @@ public class DefaultContainerService extends IntentService { // The .apk file String codePath = packageURI.getPath(); File codeFile = new File(codePath); String[] abiList = (abiOverride != null) ? new String[] { abiOverride } : Build.SUPPORTED_ABIS; NativeLibraryHelper.ApkHandle handle = new NativeLibraryHelper.ApkHandle(codePath); String[] abiList = Build.SUPPORTED_ABIS; if (abiOverride != null) { abiList = new String[] { abiList }; } else { try { if (Build.SUPPORTED_64_BIT_ABIS.length > 0 && NativeLibraryHelper.hasRenderscriptBitcode(handle)) { abiList = Build.SUPPORTED_32_BIT_ABIS; } } catch (IOException ioe) { Slog.w(TAG, "Problem determining ABI for: " + codeFile.getPath()); return null; } } final int abi = NativeLibraryHelper.findSupportedAbi(handle, abiList); // Calculate size of container needed to hold base APK. Loading
services/java/com/android/server/pm/PackageManagerService.java +31 −13 Original line number Diff line number Diff line Loading @@ -5041,12 +5041,23 @@ public class PackageManagerService extends IPackageManager.Stub { if (pkg.applicationInfo.nativeLibraryDir != null) { final NativeLibraryHelper.ApkHandle handle = new NativeLibraryHelper.ApkHandle(scanFile); try { // Enable gross and lame hacks for apps that are built with old // SDK tools. We must scan their APKs for renderscript bitcode and // not launch them if it's present. Don't bother checking on devices // that don't have 64 bit support. String[] abiList = Build.SUPPORTED_ABIS; boolean hasLegacyRenderscriptBitcode = false; if (abiOverride != null) { abiList = new String[] { abiOverride }; } else if (Build.SUPPORTED_64_BIT_ABIS.length > 0 && NativeLibraryHelper.hasRenderscriptBitcode(handle)) { abiList = Build.SUPPORTED_32_BIT_ABIS; hasLegacyRenderscriptBitcode = true; } File nativeLibraryDir = new File(pkg.applicationInfo.nativeLibraryDir); final String dataPathString = dataPath.getCanonicalPath(); final String[] abiList = (abiOverride != null) ? new String[] { abiOverride } : Build.SUPPORTED_ABIS; if (isSystemApp(pkg) && !isUpdatedSystemApp(pkg)) { /* * Upgrading from a previous version of the OS sometimes Loading @@ -5059,8 +5070,9 @@ public class PackageManagerService extends IPackageManager.Stub { Log.i(TAG, "removed obsolete native libraries for system package " + path); } if (abiOverride != null) { pkg.applicationInfo.cpuAbi = abiOverride; if (abiOverride != null || hasLegacyRenderscriptBitcode) { pkg.applicationInfo.cpuAbi = abiList[0]; pkgSetting.cpuAbiString = abiList[0]; } else { setInternalAppAbi(pkg, pkgSetting); } Loading Loading @@ -5088,8 +5100,8 @@ public class PackageManagerService extends IPackageManager.Stub { // note of what ABI we're using if (copyRet != PackageManager.NO_NATIVE_LIBRARIES) { pkg.applicationInfo.cpuAbi = abiList[copyRet]; } else if (abiOverride != null) { pkg.applicationInfo.cpuAbi = abiOverride; } else if (abiOverride != null || hasLegacyRenderscriptBitcode) { pkg.applicationInfo.cpuAbi = abiList[0]; } else { pkg.applicationInfo.cpuAbi = null; } Loading @@ -5113,8 +5125,8 @@ public class PackageManagerService extends IPackageManager.Stub { // Note that (non upgraded) system apps will not have any native // libraries bundled in their APK, but we're guaranteed not to be // such an app at this point. if (abiOverride != null) { pkg.applicationInfo.cpuAbi = abiOverride; if (abiOverride != null || hasLegacyRenderscriptBitcode) { pkg.applicationInfo.cpuAbi = abiList[0]; } else { pkg.applicationInfo.cpuAbi = null; } Loading Loading @@ -8777,9 +8789,15 @@ public class PackageManagerService extends IPackageManager.Stub { } final NativeLibraryHelper.ApkHandle handle = new NativeLibraryHelper.ApkHandle(codeFile); final String[] abiList = (abiOverride != null) ? String[] abiList = (abiOverride != null) ? new String[] { abiOverride } : Build.SUPPORTED_ABIS; try { if (Build.SUPPORTED_64_BIT_ABIS.length > 0 && abiOverride == null && NativeLibraryHelper.hasRenderscriptBitcode(handle)) { abiList = Build.SUPPORTED_32_BIT_ABIS; } int copyRet = copyNativeLibrariesForInternalApp(handle, nativeLibraryFile, abiList); if (copyRet < 0 && copyRet != PackageManager.NO_NATIVE_LIBRARIES) { return copyRet; Loading