Merge "Pseudolocalizer improvements."
diff --git a/cmds/app_process/app_main.cpp b/cmds/app_process/app_main.cpp
index 3e8d6a0..859d83b 100644
--- a/cmds/app_process/app_main.cpp
+++ b/cmds/app_process/app_main.cpp
@@ -97,7 +97,7 @@
virtual void onExit(int code)
{
- if (mClassName == NULL) {
+ if (mClassName.isEmpty()) {
// if zygote
IPCThreadState::self()->stopProcess();
}
@@ -138,8 +138,10 @@
#if defined(__LP64__)
static const char ABI_LIST_PROPERTY[] = "ro.product.cpu.abilist64";
+static const char ZYGOTE_NICE_NAME[] = "zygote64";
#else
static const char ABI_LIST_PROPERTY[] = "ro.product.cpu.abilist32";
+static const char ZYGOTE_NICE_NAME[] = "zygote";
#endif
int main(int argc, char* const argv[])
@@ -185,16 +187,19 @@
const char* arg = argv[i++];
if (strcmp(arg, "--zygote") == 0) {
zygote = true;
- niceName = "zygote";
+ niceName = ZYGOTE_NICE_NAME;
} else if (strcmp(arg, "--start-system-server") == 0) {
startSystemServer = true;
} else if (strcmp(arg, "--application") == 0) {
application = true;
} else if (strncmp(arg, "--nice-name=", 12) == 0) {
niceName = arg + 12;
- } else {
+ } else if (strncmp(arg, "--", 2) != 0) {
className.setTo(arg);
break;
+ } else {
+ --i;
+ break;
}
}
diff --git a/core/java/android/content/pm/ApplicationInfo.java b/core/java/android/content/pm/ApplicationInfo.java
index 9c46d96..1a1610d 100644
--- a/core/java/android/content/pm/ApplicationInfo.java
+++ b/core/java/android/content/pm/ApplicationInfo.java
@@ -441,6 +441,15 @@
public String nativeLibraryDir;
/**
+ * The ABI that this application requires, This is inferred from the ABIs
+ * of the native JNI libraries the application bundles. Will be {@code null}
+ * if this application does not require any particular ABI.
+ *
+ * {@hide}
+ */
+ public String requiredCpuAbi;
+
+ /**
* The kernel user-ID that has been assigned to this application;
* currently this is not a unique ID (multiple applications can have
* the same uid).
@@ -570,6 +579,7 @@
sourceDir = orig.sourceDir;
publicSourceDir = orig.publicSourceDir;
nativeLibraryDir = orig.nativeLibraryDir;
+ requiredCpuAbi = orig.requiredCpuAbi;
resourceDirs = orig.resourceDirs;
seinfo = orig.seinfo;
sharedLibraryFiles = orig.sharedLibraryFiles;
@@ -610,6 +620,7 @@
dest.writeString(sourceDir);
dest.writeString(publicSourceDir);
dest.writeString(nativeLibraryDir);
+ dest.writeString(requiredCpuAbi);
dest.writeStringArray(resourceDirs);
dest.writeString(seinfo);
dest.writeStringArray(sharedLibraryFiles);
@@ -649,6 +660,7 @@
sourceDir = source.readString();
publicSourceDir = source.readString();
nativeLibraryDir = source.readString();
+ requiredCpuAbi = source.readString();
resourceDirs = source.readStringArray();
seinfo = source.readString();
sharedLibraryFiles = source.readStringArray();
diff --git a/core/java/android/content/pm/PackageManager.java b/core/java/android/content/pm/PackageManager.java
index c97c2b8..8ce7e97 100644
--- a/core/java/android/content/pm/PackageManager.java
+++ b/core/java/android/content/pm/PackageManager.java
@@ -675,6 +675,25 @@
public static final int INSTALL_FAILED_USER_RESTRICTED = -111;
/**
+ * Installation failed return code: this is passed to the {@link IPackageInstallObserver} by
+ * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)}
+ * if the system failed to install the package because its packaged native code did not
+ * match any of the ABIs supported by the system.
+ *
+ * @hide
+ */
+ public static final int INSTALL_FAILED_NO_MATCHING_ABIS = -112;
+
+ /**
+ * Internal return code for NativeLibraryHelper methods to indicate that the package
+ * being processed did not contain any native code. This is placed here only so that
+ * it can belong to the same value space as the other install failure codes.
+ *
+ * @hide
+ */
+ public static final int NO_NATIVE_LIBRARIES = -113;
+
+ /**
* Flag parameter for {@link #deletePackage} to indicate that you don't want to delete the
* package's data directory.
*
diff --git a/core/java/android/os/Build.java b/core/java/android/os/Build.java
index bc51a60..c3313c5 100644
--- a/core/java/android/os/Build.java
+++ b/core/java/android/os/Build.java
@@ -74,7 +74,14 @@
/** A hardware serial number, if available. Alphanumeric only, case-insensitive. */
public static final String SERIAL = getString("ro.serialno");
-
+
+ /**
+ * A list of ABIs (in priority) order supported by this device.
+ *
+ * @hide
+ */
+ public static final String[] SUPPORTED_ABIS = getString("ro.product.cpu.abilist").split(",");
+
/** Various version strings. */
public static class VERSION {
/**
diff --git a/core/java/android/os/Process.java b/core/java/android/os/Process.java
index 7d2d051..96f42cc 100644
--- a/core/java/android/os/Process.java
+++ b/core/java/android/os/Process.java
@@ -372,7 +372,7 @@
for (int i = 0; i < tries; i++) {
if (i > 0) {
try {
- Log.i("Zygote", "Zygote not up yet, sleeping...");
+ Log.i(LOG_TAG, "Zygote not up yet, sleeping...");
Thread.sleep(ZYGOTE_RETRY_MILLIS);
} catch (InterruptedException ex) {
throw new ZygoteStartFailedEx(ex);
@@ -466,6 +466,7 @@
* @param debugFlags Additional flags.
* @param targetSdkVersion The target SDK version for the app.
* @param seInfo null-ok SELinux information for the new process.
+ * @param abi non-null the ABI this app should be started with.
* @param zygoteArgs Additional arguments to supply to the zygote process.
*
* @return An object that describes the result of the attempt to start the process.
@@ -479,12 +480,12 @@
int debugFlags, int mountExternal,
int targetSdkVersion,
String seInfo,
+ String abi,
String[] zygoteArgs) {
try {
return startViaZygote(processClass, niceName, uid, gid, gids,
debugFlags, mountExternal, targetSdkVersion, seInfo,
- null, /* zygoteAbi TODO: Replace this with the real ABI */
- zygoteArgs);
+ abi, zygoteArgs);
} catch (ZygoteStartFailedEx ex) {
Log.e(LOG_TAG,
"Starting VM process through Zygote failed");
@@ -702,14 +703,17 @@
primaryZygoteState = ZygoteState.connect(ZYGOTE_SOCKET, getNumTries(primaryZygoteState));
}
- // TODO: Revert this temporary change. This is required to test
- // and submit this change ahead of the package manager changes
- // that supply this abi.
- if (abi == null) {
+ if (primaryZygoteState.matches(abi)) {
return primaryZygoteState;
}
- if (primaryZygoteState.matches(abi)) {
+ // TODO: Get rid of this. This is a temporary workaround until all the
+ // compilation related pieces for the dual zygote stack are ready.
+ // b/3647418.
+ if (System.getenv("ANDROID_SOCKET_" + SECONDARY_ZYGOTE_SOCKET) == null) {
+ Log.e(LOG_TAG, "Forcing app to primary zygote, secondary unavailable (ABI= " + abi + ")");
+ // Should be :
+ // throw new ZygoteStartFailedEx("Unsupported zygote ABI: " + abi);
return primaryZygoteState;
}
diff --git a/core/java/android/util/Log.java b/core/java/android/util/Log.java
index abd173a..2b81072 100644
--- a/core/java/android/util/Log.java
+++ b/core/java/android/util/Log.java
@@ -352,6 +352,7 @@
/** @hide */ public static final int LOG_ID_RADIO = 1;
/** @hide */ public static final int LOG_ID_EVENTS = 2;
/** @hide */ public static final int LOG_ID_SYSTEM = 3;
+ /** @hide */ public static final int LOG_ID_CRASH = 4;
/** @hide */ public static native int println_native(int bufID,
int priority, String tag, String msg);
diff --git a/core/java/android/widget/NumberPicker.java b/core/java/android/widget/NumberPicker.java
index c0fde2e..26c5732 100644
--- a/core/java/android/widget/NumberPicker.java
+++ b/core/java/android/widget/NumberPicker.java
@@ -1944,7 +1944,16 @@
, '\u0669',
// Extended Arabic-Indic
'\u06f0', '\u06f1', '\u06f2', '\u06f3', '\u06f4', '\u06f5', '\u06f6', '\u06f7', '\u06f8'
- , '\u06f9'
+ , '\u06f9',
+ // Hindi and Marathi (Devanagari script)
+ '\u0966', '\u0967', '\u0968', '\u0969', '\u096a', '\u096b', '\u096c', '\u096d', '\u096e'
+ , '\u096f',
+ // Bengali
+ '\u09e6', '\u09e7', '\u09e8', '\u09e9', '\u09ea', '\u09eb', '\u09ec', '\u09ed', '\u09ee'
+ , '\u09ef',
+ // Kannada
+ '\u0ce6', '\u0ce7', '\u0ce8', '\u0ce9', '\u0cea', '\u0ceb', '\u0cec', '\u0ced', '\u0cee'
+ , '\u0cef'
};
/**
diff --git a/core/java/com/android/internal/content/NativeLibraryHelper.java b/core/java/com/android/internal/content/NativeLibraryHelper.java
index 6d65782..ba419f9 100644
--- a/core/java/com/android/internal/content/NativeLibraryHelper.java
+++ b/core/java/com/android/internal/content/NativeLibraryHelper.java
@@ -16,7 +16,7 @@
package com.android.internal.content;
-import android.os.Build;
+import android.content.pm.PackageManager;
import android.util.Slog;
import java.io.File;
@@ -31,38 +31,76 @@
private static final boolean DEBUG_NATIVE = false;
- private static native long nativeSumNativeBinaries(String file, String cpuAbi, String cpuAbi2);
-
/**
- * Sums the size of native binaries in an APK.
+ * A handle to an opened APK. Used as input to the various NativeLibraryHelper
+ * methods. Allows us to scan and parse the APK exactly once instead of doing
+ * it multiple times.
*
- * @param apkFile APK file to scan for native libraries
- * @return size of all native binary files in bytes
+ * @hide
*/
- public static long sumNativeBinariesLI(File apkFile) {
- final String cpuAbi = Build.CPU_ABI;
- final String cpuAbi2 = Build.CPU_ABI2;
- return nativeSumNativeBinaries(apkFile.getPath(), cpuAbi, cpuAbi2);
+ public static class ApkHandle {
+ final String apkPath;
+ final long apkHandle;
+
+ public ApkHandle(String path) {
+ apkPath = path;
+ apkHandle = nativeOpenApk(apkPath);
+ }
+
+ public ApkHandle(File apkFile) {
+ apkPath = apkFile.getPath();
+ apkHandle = nativeOpenApk(apkPath);
+ }
+
+ public void close() {
+ nativeClose(apkHandle);
+ }
}
- private native static int nativeCopyNativeBinaries(String filePath, String sharedLibraryPath,
- String cpuAbi, String cpuAbi2);
+
+ private static native long nativeOpenApk(String path);
+ private static native void nativeClose(long handle);
+
+ private static native long nativeSumNativeBinaries(long handle, String cpuAbi);
+
+ /**
+ * Sums the size of native binaries in an APK for a given ABI.
+ *
+ * @return size of all native binary files in bytes
+ */
+ public static long sumNativeBinariesLI(ApkHandle handle, String abi) {
+ return nativeSumNativeBinaries(handle.apkHandle, abi);
+ }
+
+ private native static int nativeCopyNativeBinaries(long handle,
+ String sharedLibraryPath, String abiToCopy);
/**
* Copies native binaries to a shared library directory.
*
- * @param apkFile APK file to scan for native libraries
+ * @param handle APK file to scan for native libraries
* @param sharedLibraryDir directory for libraries to be copied to
* @return {@link PackageManager#INSTALL_SUCCEEDED} if successful or another
* error code from that class if not
*/
- public static int copyNativeBinariesIfNeededLI(File apkFile, File sharedLibraryDir) {
- final String cpuAbi = Build.CPU_ABI;
- final String cpuAbi2 = Build.CPU_ABI2;
- return nativeCopyNativeBinaries(apkFile.getPath(), sharedLibraryDir.getPath(), cpuAbi,
- cpuAbi2);
+ public static int copyNativeBinariesIfNeededLI(ApkHandle handle, File sharedLibraryDir,
+ String abi) {
+ return nativeCopyNativeBinaries(handle.apkHandle, sharedLibraryDir.getPath(), abi);
}
+ /**
+ * Checks if a given APK contains native code for any of the provided
+ * {@code supportedAbis}. Returns an index into {@code supportedAbis} if a matching
+ * ABI is found, {@link PackageManager#NO_NATIVE_LIBRARIES} if the
+ * APK doesn't contain any native code, and
+ * {@link PackageManager#INSTALL_FAILED_NO_MATCHING_ABIS} if none of the ABIs match.
+ */
+ public static int findSupportedAbi(ApkHandle handle, String[] supportedAbis) {
+ return nativeFindSupportedAbi(handle.apkHandle, supportedAbis);
+ }
+
+ private native static int nativeFindSupportedAbi(long handle, String[] supportedAbis);
+
// Convenience method to call removeNativeBinariesFromDirLI(File)
public static boolean removeNativeBinariesLI(String nativeLibraryPath) {
return removeNativeBinariesFromDirLI(new File(nativeLibraryPath));
diff --git a/core/java/com/android/internal/os/RuntimeInit.java b/core/java/com/android/internal/os/RuntimeInit.java
index 5538dca..4a26b4b 100644
--- a/core/java/com/android/internal/os/RuntimeInit.java
+++ b/core/java/com/android/internal/os/RuntimeInit.java
@@ -55,6 +55,11 @@
private static final native void nativeFinishInit();
private static final native void nativeSetExitWithoutCleanup(boolean exitWithoutCleanup);
+ private static int Clog_e(String tag, String msg, Throwable tr) {
+ return Log.println_native(Log.LOG_ID_CRASH, Log.ERROR, tag,
+ msg + '\n' + Log.getStackTraceString(tr));
+ }
+
/**
* Use this to log a message when a thread exits due to an uncaught
* exception. The framework catches these for the main threads, so
@@ -68,7 +73,7 @@
mCrashing = true;
if (mApplicationObject == null) {
- Slog.e(TAG, "*** FATAL EXCEPTION IN SYSTEM PROCESS: " + t.getName(), e);
+ Clog_e(TAG, "*** FATAL EXCEPTION IN SYSTEM PROCESS: " + t.getName(), e);
} else {
StringBuilder message = new StringBuilder();
message.append("FATAL EXCEPTION: ").append(t.getName()).append("\n");
@@ -77,7 +82,7 @@
message.append("Process: ").append(processName).append(", ");
}
message.append("PID: ").append(Process.myPid());
- Slog.e(TAG, message.toString(), e);
+ Clog_e(TAG, message.toString(), e);
}
// Bring up crash dialog, wait for it to be dismissed
@@ -85,9 +90,9 @@
mApplicationObject, new ApplicationErrorReport.CrashInfo(e));
} catch (Throwable t2) {
try {
- Slog.e(TAG, "Error reporting crash", t2);
+ Clog_e(TAG, "Error reporting crash", t2);
} catch (Throwable t3) {
- // Even Slog.e() fails! Oh well.
+ // Even Clog_e() fails! Oh well.
}
} finally {
// Try everything to make sure this process goes away.
diff --git a/core/jni/android_database_CursorWindow.cpp b/core/jni/android_database_CursorWindow.cpp
index 67f3879..af6cc72 100644
--- a/core/jni/android_database_CursorWindow.cpp
+++ b/core/jni/android_database_CursorWindow.cpp
@@ -17,6 +17,7 @@
#undef LOG_TAG
#define LOG_TAG "CursorWindow"
+#include <inttypes.h>
#include <jni.h>
#include <JNIHelp.h>
#include <android_runtime/AndroidRuntime.h>
@@ -225,7 +226,7 @@
} else if (type == CursorWindow::FIELD_TYPE_INTEGER) {
int64_t value = window->getFieldSlotValueLong(fieldSlot);
char buf[32];
- snprintf(buf, sizeof(buf), "%lld", value);
+ snprintf(buf, sizeof(buf), "%" PRId64, value);
return env->NewStringUTF(buf);
} else if (type == CursorWindow::FIELD_TYPE_FLOAT) {
double value = window->getFieldSlotValueDouble(fieldSlot);
@@ -314,7 +315,7 @@
} else if (type == CursorWindow::FIELD_TYPE_INTEGER) {
int64_t value = window->getFieldSlotValueLong(fieldSlot);
char buf[32];
- snprintf(buf, sizeof(buf), "%lld", value);
+ snprintf(buf, sizeof(buf), "%" PRId64, value);
fillCharArrayBufferUTF(env, bufferObj, buf, strlen(buf));
} else if (type == CursorWindow::FIELD_TYPE_FLOAT) {
double value = window->getFieldSlotValueDouble(fieldSlot);
diff --git a/core/jni/android_net_TrafficStats.cpp b/core/jni/android_net_TrafficStats.cpp
index f904b62..031637f 100644
--- a/core/jni/android_net_TrafficStats.cpp
+++ b/core/jni/android_net_TrafficStats.cpp
@@ -19,6 +19,7 @@
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
+#include <inttypes.h>
#include <sys/stat.h>
#include <sys/types.h>
@@ -85,9 +86,9 @@
uint64_t rxBytes, rxPackets, txBytes, txPackets, tcpRxPackets, tcpTxPackets;
while (fgets(buffer, sizeof(buffer), fp) != NULL) {
- int matched = sscanf(buffer, "%31s %llu %llu %llu %llu "
- "%*u %llu %*u %*u %*u %*u "
- "%*u %llu %*u %*u %*u %*u", cur_iface, &rxBytes,
+ int matched = sscanf(buffer, "%31s %" SCNu64 " %" SCNu64 " %" SCNu64
+ " %" SCNu64 " " "%*u %" SCNu64 " %*u %*u %*u %*u "
+ "%*u %" SCNu64 " %*u %*u %*u %*u", cur_iface, &rxBytes,
&rxPackets, &txBytes, &txPackets, &tcpRxPackets, &tcpTxPackets);
if (matched >= 5) {
if (matched == 7) {
@@ -129,9 +130,11 @@
uint64_t tag, rxBytes, rxPackets, txBytes, txPackets;
while (fgets(buffer, sizeof(buffer), fp) != NULL) {
- if (sscanf(buffer, "%d %31s 0x%llx %u %u %llu %llu %llu %llu", &idx,
- iface, &tag, &cur_uid, &set, &rxBytes, &rxPackets, &txBytes,
- &txPackets) == 9) {
+ if (sscanf(buffer,
+ "%" SCNu32 " %31s 0x%" SCNx64 " %u %u %" SCNu64 " %" SCNu64
+ " %" SCNu64 " %" SCNu64 "",
+ &idx, iface, &tag, &cur_uid, &set, &rxBytes, &rxPackets,
+ &txBytes, &txPackets) == 9) {
if (uid == cur_uid && tag == 0L) {
stats->rxBytes += rxBytes;
stats->rxPackets += rxPackets;
diff --git a/core/jni/android_os_Debug.cpp b/core/jni/android_os_Debug.cpp
index d4873d6..86207f0 100644
--- a/core/jni/android_os_Debug.cpp
+++ b/core/jni/android_os_Debug.cpp
@@ -24,6 +24,7 @@
#include <cutils/log.h>
#include <fcntl.h>
+#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -824,9 +825,9 @@
break;
} else {
#ifdef __LP64__
- fprintf(fp, " %016x", backtrace[bt]);
+ fprintf(fp, " %016" PRIxPTR, backtrace[bt]);
#else
- fprintf(fp, " %08x", backtrace[bt]);
+ fprintf(fp, " %08" PRIxPTR, backtrace[bt]);
#endif
}
}
diff --git a/core/jni/android_util_Binder.cpp b/core/jni/android_util_Binder.cpp
index 475e926..662af89 100644
--- a/core/jni/android_util_Binder.cpp
+++ b/core/jni/android_util_Binder.cpp
@@ -23,6 +23,7 @@
#include "JNIHelp.h"
#include <fcntl.h>
+#include <inttypes.h>
#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
@@ -334,7 +335,7 @@
if (b == NULL) {
b = new JavaBBinder(env, obj);
mBinder = b;
- ALOGV("Creating JavaBinder %p (refs %p) for Object %p, weakCount=%d\n",
+ ALOGV("Creating JavaBinder %p (refs %p) for Object %p, weakCount=%" PRId32 "\n",
b.get(), b->getWeakRefs(), obj, b->getWeakRefs()->getWeakCount());
}
@@ -697,9 +698,9 @@
"Not allowed to write file descriptors here");
break;
default:
- ALOGE("Unknown binder error code. 0x%x", err);
+ ALOGE("Unknown binder error code. 0x%" PRIx32, err);
String8 msg;
- msg.appendFormat("Unknown binder error code. 0x%x", err);
+ msg.appendFormat("Unknown binder error code. 0x%" PRIx32, err);
// RemoteException is a checked exception, only throw from certain methods.
jniThrowException(env, canThrowRemoteException
? "android/os/RemoteException" : "java/lang/RuntimeException", msg.string());
@@ -733,7 +734,7 @@
if (uid > 0 && uid < 999) {
// In Android currently there are no uids in this range.
char buf[128];
- sprintf(buf, "Restoring bad calling ident: 0x%Lx", token);
+ sprintf(buf, "Restoring bad calling ident: 0x%" PRIx64, token);
jniThrowException(env, "java/lang/IllegalStateException", buf);
return;
}
@@ -965,8 +966,8 @@
jint len = strlen(str);
int space_needed = 1 + sizeof(len) + len;
if (end - *pos < space_needed) {
- ALOGW("not enough space for string. remain=%d; needed=%d",
- (end - *pos), space_needed);
+ ALOGW("not enough space for string. remain=%" PRIdPTR "; needed=%d",
+ end - *pos, space_needed);
return false;
}
**pos = EVENT_TYPE_STRING;
@@ -981,8 +982,8 @@
static bool push_eventlog_int(char** pos, const char* end, jint val) {
int space_needed = 1 + sizeof(val);
if (end - *pos < space_needed) {
- ALOGW("not enough space for int. remain=%d; needed=%d",
- (end - *pos), space_needed);
+ ALOGW("not enough space for int. remain=%" PRIdPTR "; needed=%d",
+ end - *pos, space_needed);
return false;
}
**pos = EVENT_TYPE_INT;
@@ -1068,7 +1069,7 @@
return JNI_FALSE;
}
- ALOGV("Java code calling transact on %p in Java object %p with code %d\n",
+ ALOGV("Java code calling transact on %p in Java object %p with code %" PRId32 "\n",
target, obj, code);
#if ENABLE_BINDER_SAMPLE
diff --git a/core/jni/com_android_internal_content_NativeLibraryHelper.cpp b/core/jni/com_android_internal_content_NativeLibraryHelper.cpp
index a860918..2004576 100644
--- a/core/jni/com_android_internal_content_NativeLibraryHelper.cpp
+++ b/core/jni/com_android_internal_content_NativeLibraryHelper.cpp
@@ -19,11 +19,12 @@
#include <android_runtime/AndroidRuntime.h>
-#include <utils/Log.h>
-#include <androidfw/ZipFileRO.h>
-#include <androidfw/ZipUtils.h>
#include <ScopedUtfChars.h>
#include <UniquePtr.h>
+#include <androidfw/ZipFileRO.h>
+#include <androidfw/ZipUtils.h>
+#include <utils/Log.h>
+#include <utils/Vector.h>
#include <zlib.h>
@@ -54,17 +55,19 @@
namespace android {
// These match PackageManager.java install codes
-typedef enum {
+enum install_status_t {
INSTALL_SUCCEEDED = 1,
INSTALL_FAILED_INVALID_APK = -2,
INSTALL_FAILED_INSUFFICIENT_STORAGE = -4,
INSTALL_FAILED_CONTAINER_ERROR = -18,
INSTALL_FAILED_INTERNAL_ERROR = -110,
-} install_status_t;
+ INSTALL_FAILED_NO_MATCHING_ABIS = -112,
+ NO_NATIVE_LIBRARIES = -113
+};
typedef install_status_t (*iterFunc)(JNIEnv*, void*, ZipFileRO*, ZipEntryRO, const char*);
-// Equivalent to isFilenameSafe
+// Equivalent to android.os.FileUtils.isFilenameSafe
static bool
isFilenameSafe(const char* filename)
{
@@ -268,126 +271,252 @@
return INSTALL_SUCCEEDED;
}
-static install_status_t
-iterateOverNativeFiles(JNIEnv *env, jstring javaFilePath, jstring javaCpuAbi, jstring javaCpuAbi2,
- iterFunc callFunc, void* callArg) {
- ScopedUtfChars filePath(env, javaFilePath);
- ScopedUtfChars cpuAbi(env, javaCpuAbi);
- ScopedUtfChars cpuAbi2(env, javaCpuAbi2);
-
- UniquePtr<ZipFileRO> zipFile(ZipFileRO::open(filePath.c_str()));
- if (zipFile.get() == NULL) {
- ALOGI("Couldn't open APK %s\n", filePath.c_str());
- return INSTALL_FAILED_INVALID_APK;
+/*
+ * An iterator over all shared libraries in a zip file. An entry is
+ * considered to be a shared library if all of the conditions below are
+ * satisfied :
+ *
+ * - The entry is under the lib/ directory.
+ * - The entry name ends with ".so" and the entry name starts with "lib",
+ * an exception is made for entries whose name is "gdbserver".
+ * - The entry filename is "safe" (as determined by isFilenameSafe).
+ *
+ */
+class NativeLibrariesIterator {
+private:
+ NativeLibrariesIterator(ZipFileRO* zipFile, void* cookie)
+ : mZipFile(zipFile), mCookie(cookie), mLastSlash(NULL) {
+ fileName[0] = '\0';
}
+public:
+ static NativeLibrariesIterator* create(ZipFileRO* zipFile) {
+ void* cookie = NULL;
+ if (!zipFile->startIteration(&cookie)) {
+ return NULL;
+ }
+
+ return new NativeLibrariesIterator(zipFile, cookie);
+ }
+
+ ZipEntryRO next() {
+ ZipEntryRO next = NULL;
+ while ((next = mZipFile->nextEntry(mCookie)) != NULL) {
+ // Make sure this entry has a filename.
+ if (mZipFile->getEntryFileName(next, fileName, sizeof(fileName))) {
+ 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;
+ if (fileNameLen < minLength) {
+ continue;
+ }
+
+ const char* lastSlash = strrchr(fileName, '/');
+ ALOG_ASSERT(lastSlash != NULL, "last slash was null somehow for %s\n", fileName);
+
+ // Exception: If we find the gdbserver binary, return it.
+ if (!strncmp(lastSlash + 1, GDBSERVER, GDBSERVER_LEN)) {
+ break;
+ }
+
+ // Make sure the filename starts with lib and ends with ".so".
+ if (strncmp(fileName + fileNameLen - LIB_SUFFIX_LEN, LIB_SUFFIX, LIB_SUFFIX_LEN)
+ || strncmp(lastSlash, LIB_PREFIX, LIB_PREFIX_LEN)) {
+ continue;
+ }
+
+ // Make sure the filename is safe.
+ if (!isFilenameSafe(lastSlash + 1)) {
+ continue;
+ }
+
+ mLastSlash = lastSlash;
+ break;
+ }
+
+ return next;
+ }
+
+ inline const char* currentEntry() const {
+ return fileName;
+ }
+
+ inline const char* lastSlash() const {
+ return mLastSlash;
+ }
+
+ virtual ~NativeLibrariesIterator() {
+ mZipFile->endIteration(mCookie);
+ }
+private:
+
char fileName[PATH_MAX];
- bool hasPrimaryAbi = false;
+ ZipFileRO* const mZipFile;
+ void* mCookie;
+ const char* mLastSlash;
+};
- void* cookie = NULL;
- if (!zipFile->startIteration(&cookie)) {
- ALOGI("Couldn't iterate over APK%s\n", filePath.c_str());
+static install_status_t
+iterateOverNativeFiles(JNIEnv *env, jlong apkHandle, jstring javaCpuAbi,
+ iterFunc callFunc, void* callArg) {
+ ZipFileRO* zipFile = reinterpret_cast<ZipFileRO*>(apkHandle);
+ if (zipFile == NULL) {
return INSTALL_FAILED_INVALID_APK;
}
+ UniquePtr<NativeLibrariesIterator> it(NativeLibrariesIterator::create(zipFile));
+ if (it.get() == NULL) {
+ return INSTALL_FAILED_INVALID_APK;
+ }
+
+ const ScopedUtfChars cpuAbi(env, javaCpuAbi);
+ if (cpuAbi.c_str() == NULL) {
+ // This would've thrown, so this return code isn't observable by
+ // Java.
+ return INSTALL_FAILED_INVALID_APK;
+ }
ZipEntryRO entry = NULL;
- while ((entry = zipFile->nextEntry(cookie)) != NULL) {
- // Make sure this entry has a filename.
- if (zipFile->getEntryFileName(entry, fileName, sizeof(fileName))) {
- 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;
- if (fileNameLen < minLength) {
- continue;
- }
-
- const char* lastSlash = strrchr(fileName, '/');
- ALOG_ASSERT(lastSlash != NULL, "last slash was null somehow for %s\n", fileName);
+ while ((entry = it->next()) != NULL) {
+ const char* fileName = it->currentEntry();
+ const char* lastSlash = it->lastSlash();
// Check to make sure the CPU ABI of this file is one we support.
const char* cpuAbiOffset = fileName + APK_LIB_LEN;
const size_t cpuAbiRegionSize = lastSlash - cpuAbiOffset;
- ALOGV("Comparing ABIs %s and %s versus %s\n", cpuAbi.c_str(), cpuAbi2.c_str(), cpuAbiOffset);
- if (cpuAbi.size() == cpuAbiRegionSize
- && *(cpuAbiOffset + cpuAbi.size()) == '/'
- && !strncmp(cpuAbiOffset, cpuAbi.c_str(), cpuAbiRegionSize)) {
- ALOGV("Using primary ABI %s\n", cpuAbi.c_str());
- hasPrimaryAbi = true;
- } else if (cpuAbi2.size() == cpuAbiRegionSize
- && *(cpuAbiOffset + cpuAbi2.size()) == '/'
- && !strncmp(cpuAbiOffset, cpuAbi2.c_str(), cpuAbiRegionSize)) {
-
- /*
- * If this library matches both the primary and secondary ABIs,
- * only use the primary ABI.
- */
- if (hasPrimaryAbi) {
- ALOGV("Already saw primary ABI, skipping secondary ABI %s\n", cpuAbi2.c_str());
- continue;
- } else {
- ALOGV("Using secondary ABI %s\n", cpuAbi2.c_str());
- }
- } else {
- ALOGV("abi didn't match anything: %s (end at %zd)\n", cpuAbiOffset, cpuAbiRegionSize);
- continue;
- }
-
- // If this is a .so file, check to see if we need to copy it.
- if ((!strncmp(fileName + fileNameLen - LIB_SUFFIX_LEN, LIB_SUFFIX, LIB_SUFFIX_LEN)
- && !strncmp(lastSlash, LIB_PREFIX, LIB_PREFIX_LEN)
- && isFilenameSafe(lastSlash + 1))
- || !strncmp(lastSlash + 1, GDBSERVER, GDBSERVER_LEN)) {
-
- install_status_t ret = callFunc(env, callArg, zipFile.get(), entry, lastSlash + 1);
+ if (cpuAbi.size() == cpuAbiRegionSize && !strncmp(cpuAbiOffset, cpuAbi.c_str(), cpuAbiRegionSize)) {
+ install_status_t ret = callFunc(env, callArg, zipFile, entry, lastSlash + 1);
if (ret != INSTALL_SUCCEEDED) {
ALOGV("Failure for entry %s", lastSlash + 1);
- zipFile->endIteration(cookie);
return ret;
}
}
}
- zipFile->endIteration(cookie);
-
return INSTALL_SUCCEEDED;
}
+
+static int findSupportedAbi(JNIEnv *env, jlong apkHandle, jobjectArray supportedAbisArray) {
+ const int numAbis = env->GetArrayLength(supportedAbisArray);
+ Vector<ScopedUtfChars*> supportedAbis;
+
+ for (int i = 0; i < numAbis; ++i) {
+ supportedAbis.add(new ScopedUtfChars(env,
+ (jstring) env->GetObjectArrayElement(supportedAbisArray, i)));
+ }
+
+ ZipFileRO* zipFile = reinterpret_cast<ZipFileRO*>(apkHandle);
+ if (zipFile == NULL) {
+ return INSTALL_FAILED_INVALID_APK;
+ }
+
+ UniquePtr<NativeLibrariesIterator> it(NativeLibrariesIterator::create(zipFile));
+ if (it.get() == NULL) {
+ return INSTALL_FAILED_INVALID_APK;
+ }
+
+ ZipEntryRO entry = NULL;
+ char fileName[PATH_MAX];
+ int status = NO_NATIVE_LIBRARIES;
+ while ((entry = it->next()) != NULL) {
+ // We're currently in the lib/ directory of the APK, so it does have some native
+ // code. We should return INSTALL_FAILED_NO_MATCHING_ABIS if none of the
+ // libraries match.
+ if (status == NO_NATIVE_LIBRARIES) {
+ status = INSTALL_FAILED_NO_MATCHING_ABIS;
+ }
+
+ const char* fileName = it->currentEntry();
+ const char* lastSlash = it->lastSlash();
+
+ // Check to see if this CPU ABI matches what we are looking for.
+ const char* abiOffset = fileName + APK_LIB_LEN;
+ const size_t abiSize = lastSlash - abiOffset;
+ for (int i = 0; i < numAbis; i++) {
+ const ScopedUtfChars* abi = supportedAbis[i];
+ if (abi->size() == abiSize && !strncmp(abiOffset, abi->c_str(), abiSize)) {
+ // The entry that comes in first (i.e. with a lower index) has the higher priority.
+ if (((i < status) && (status >= 0)) || (status < 0) ) {
+ status = i;
+ }
+ }
+ }
+ }
+
+ for (int i = 0; i < numAbis; ++i) {
+ delete supportedAbis[i];
+ }
+
+ return status;
+}
+
static jint
com_android_internal_content_NativeLibraryHelper_copyNativeBinaries(JNIEnv *env, jclass clazz,
- jstring javaFilePath, jstring javaNativeLibPath, jstring javaCpuAbi, jstring javaCpuAbi2)
+ jlong apkHandle, jstring javaNativeLibPath, jstring javaCpuAbi)
{
- return (jint) iterateOverNativeFiles(env, javaFilePath, javaCpuAbi, javaCpuAbi2,
+ return (jint) iterateOverNativeFiles(env, apkHandle, javaCpuAbi,
copyFileIfChanged, &javaNativeLibPath);
}
static jlong
com_android_internal_content_NativeLibraryHelper_sumNativeBinaries(JNIEnv *env, jclass clazz,
- jstring javaFilePath, jstring javaCpuAbi, jstring javaCpuAbi2)
+ jlong apkHandle, jstring javaCpuAbi)
{
size_t totalSize = 0;
- iterateOverNativeFiles(env, javaFilePath, javaCpuAbi, javaCpuAbi2, sumFiles, &totalSize);
+ iterateOverNativeFiles(env, apkHandle, javaCpuAbi, sumFiles, &totalSize);
return totalSize;
}
+static jint
+com_android_internal_content_NativeLibraryHelper_findSupportedAbi(JNIEnv *env, jclass clazz,
+ jlong apkHandle, jobjectArray javaCpuAbisToSearch)
+{
+ return (jint) findSupportedAbi(env, apkHandle, javaCpuAbisToSearch);
+}
+
+static jlong
+com_android_internal_content_NativeLibraryHelper_openApk(JNIEnv *env, jclass, jstring apkPath)
+{
+ ScopedUtfChars filePath(env, apkPath);
+ ZipFileRO* zipFile = ZipFileRO::open(filePath.c_str());
+
+ return reinterpret_cast<jlong>(zipFile);
+}
+
+static void
+com_android_internal_content_NativeLibraryHelper_close(JNIEnv *env, jclass, jlong apkHandle)
+{
+ delete reinterpret_cast<ZipFileRO*>(apkHandle);
+}
+
static JNINativeMethod gMethods[] = {
+ {"nativeOpenApk",
+ "(Ljava/lang/String;)J",
+ (void *)com_android_internal_content_NativeLibraryHelper_openApk},
+ {"nativeClose",
+ "(J)V",
+ (void *)com_android_internal_content_NativeLibraryHelper_close},
{"nativeCopyNativeBinaries",
- "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)I",
+ "(JLjava/lang/String;Ljava/lang/String;)I",
(void *)com_android_internal_content_NativeLibraryHelper_copyNativeBinaries},
{"nativeSumNativeBinaries",
- "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)J",
+ "(JLjava/lang/String;)J",
(void *)com_android_internal_content_NativeLibraryHelper_sumNativeBinaries},
+ {"nativeFindSupportedAbi",
+ "(J[Ljava/lang/String;)I",
+ (void *)com_android_internal_content_NativeLibraryHelper_findSupportedAbi},
};
diff --git a/media/java/android/media/videoeditor/VideoEditorImpl.java b/media/java/android/media/videoeditor/VideoEditorImpl.java
index 2446c2f..fbf2eab 100644
--- a/media/java/android/media/videoeditor/VideoEditorImpl.java
+++ b/media/java/android/media/videoeditor/VideoEditorImpl.java
@@ -47,6 +47,8 @@
import android.os.SystemProperties;
import android.os.Environment;
+import libcore.io.IoUtils;
+
/**
* The VideoEditor implementation {@hide}
*/
@@ -1859,15 +1861,15 @@
}
}
+ FileOutputStream stream = null;
try {
- FileOutputStream stream = new FileOutputStream(mProjectPath + "/"
- + THUMBNAIL_FILENAME);
+ stream = new FileOutputStream(mProjectPath + "/" + THUMBNAIL_FILENAME);
projectBitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
stream.flush();
- stream.close();
} catch (IOException e) {
throw new IllegalArgumentException ("Error creating project thumbnail");
} finally {
+ IoUtils.closeQuietly(stream);
projectBitmap.recycle();
}
}
diff --git a/media/jni/android_media_MediaRecorder.cpp b/media/jni/android_media_MediaRecorder.cpp
index 0cfd2ff..b74d0fb3 100644
--- a/media/jni/android_media_MediaRecorder.cpp
+++ b/media/jni/android_media_MediaRecorder.cpp
@@ -14,6 +14,13 @@
* limitations under the License.
*/
+#include <assert.h>
+#include <fcntl.h>
+#include <inttypes.h>
+#include <limits.h>
+#include <stdio.h>
+#include <unistd.h>
+
//#define LOG_NDEBUG 0
#define LOG_TAG "MediaRecorderJNI"
#include <utils/Log.h>
@@ -22,11 +29,6 @@
#include <camera/ICameraService.h>
#include <camera/Camera.h>
#include <media/mediarecorder.h>
-#include <stdio.h>
-#include <assert.h>
-#include <limits.h>
-#include <unistd.h>
-#include <fcntl.h>
#include <utils/threads.h>
#include "jni.h"
@@ -303,7 +305,7 @@
sp<MediaRecorder> mr = getMediaRecorder(env, thiz);
char params[64];
- sprintf(params, "max-filesize=%lld", max_filesize_bytes);
+ sprintf(params, "max-filesize=%" PRId64, max_filesize_bytes);
process_media_recorder_call(env, mr->setParameters(String8(params)), "java/lang/RuntimeException", "setMaxFileSize failed.");
}
diff --git a/media/jni/mediaeditor/VideoEditorMain.cpp b/media/jni/mediaeditor/VideoEditorMain.cpp
index 058012b..0894d74 100644
--- a/media/jni/mediaeditor/VideoEditorMain.cpp
+++ b/media/jni/mediaeditor/VideoEditorMain.cpp
@@ -16,6 +16,7 @@
#define LOG_NDEBUG 1
#define LOG_TAG "VideoEditorMain"
#include <dlfcn.h>
+#include <inttypes.h>
#include <stdio.h>
#include <unistd.h>
#include <utils/Log.h>
@@ -24,7 +25,6 @@
#include <VideoEditorJava.h>
#include <VideoEditorOsal.h>
#include <VideoEditorLogging.h>
-#include <marker.h>
#include <VideoEditorClasses.h>
#include <VideoEditorThumbnailMain.h>
#include <M4OSA_Debug.h>
@@ -438,7 +438,7 @@
M4VS, (M4OSA_Char*)"videoEdito JNI overlayFile");
if (pContext->mOverlayFileName != NULL) {
strncpy (pContext->mOverlayFileName,
- (const char*)pContext->pEditSettings->\
+ (const char*)pContext->pEditSettings->
Effects[overlayEffectIndex].xVSS.pFramingFilePath, overlayFileNameLen);
//Change the name to png file
extPos = strstr(pContext->mOverlayFileName, ".rgb");
@@ -1560,9 +1560,6 @@
int *pOverlayIndex = M4OSA_NULL;
M4OSA_Char* pTempChar = M4OSA_NULL;
- // Add a code marker (the condition must always be true).
- ADD_CODE_MARKER_FUN(NULL != pEnv)
-
// Validate the settings parameter.
videoEditJava_checkAndThrowIllegalArgumentException(&needToBeLoaded, pEnv,
(NULL == settings),
@@ -2196,10 +2193,6 @@
M4OSA_Context mContext = M4OSA_NULL;
jint* m_dst32 = M4OSA_NULL;
-
- // Add a text marker (the condition must always be true).
- ADD_TEXT_MARKER_FUN(NULL != env)
-
const char *pString = env->GetStringUTFChars(path, NULL);
if (pString == M4OSA_NULL) {
if (env != NULL) {
@@ -2537,9 +2530,6 @@
VIDEOEDIT_LOG_API(ANDROID_LOG_INFO, "VIDEO_EDITOR", "videoEditor_init()");
- // Add a text marker (the condition must always be true).
- ADD_TEXT_MARKER_FUN(NULL != pEnv)
-
// Get the context.
pContext = (ManualEditContext*)videoEditClasses_getContext(&initialized, pEnv, thiz);
@@ -2948,9 +2938,6 @@
VIDEOEDIT_LOG_API(ANDROID_LOG_INFO, "VIDEO_EDITOR", "videoEditor_loadSettings()");
- // Add a code marker (the condition must always be true).
- ADD_CODE_MARKER_FUN(NULL != pEnv)
-
// Get the context.
pContext = (ManualEditContext*)videoEditClasses_getContext(&needToBeLoaded,
pEnv, thiz);
@@ -3123,9 +3110,6 @@
VIDEOEDIT_LOG_API(ANDROID_LOG_INFO, "VIDEO_EDITOR", "videoEditor_release()");
- // Add a text marker (the condition must always be true).
- ADD_TEXT_MARKER_FUN(NULL != pEnv)
-
// Get the context.
pContext = (ManualEditContext*)videoEditClasses_getContext(&released, pEnv, thiz);
@@ -3388,7 +3372,7 @@
err = M4OSA_fileReadOpen (&inputFileHandle, pInputFileURL, M4OSA_kFileRead);
if (inputFileHandle == M4OSA_NULL) {
VIDEOEDIT_LOG_ERROR(ANDROID_LOG_INFO, "VIDEO_EDITOR",
- "M4MA_generateAudioGraphFile: Cannot open input file 0x%lx", err);
+ "M4MA_generateAudioGraphFile: Cannot open input file 0x%" PRIx32, err);
return err;
}
@@ -3422,7 +3406,7 @@
bufferIn.m_bufferSize = samplesCountInBytes*sizeof(M4OSA_UInt16);
} else {
VIDEOEDIT_LOG_ERROR(ANDROID_LOG_INFO, "VIDEO_EDITOR",
- "M4MA_generateAudioGraphFile: Malloc failed for bufferIn.m_dataAddress 0x%lx",
+ "M4MA_generateAudioGraphFile: Malloc failed for bufferIn.m_dataAddress 0x%" PRIx32,
M4ERR_ALLOC);
return M4ERR_ALLOC;
}
@@ -3462,7 +3446,7 @@
if (err != M4NO_ERROR) {
// if out value of bytes-read is 0, break
if ( numBytesToRead == 0) {
- VIDEOEDIT_LOG_ERROR(ANDROID_LOG_INFO, "VIDEO_EDITOR", "numBytesToRead 0x%lx",
+ VIDEOEDIT_LOG_ERROR(ANDROID_LOG_INFO, "VIDEO_EDITOR", "numBytesToRead 0x%" PRIx32,
numBytesToRead);
break; /* stop if file is empty or EOF */
}
@@ -3514,7 +3498,7 @@
} while (numBytesToRead != 0);
- VIDEOEDIT_LOG_ERROR(ANDROID_LOG_INFO, "VIDEO_EDITOR", "loop 0x%lx", volumeValuesCount);
+ VIDEOEDIT_LOG_ERROR(ANDROID_LOG_INFO, "VIDEO_EDITOR", "loop 0x%" PRIx32, volumeValuesCount);
/* if some error occured in fwrite */
if (numBytesToRead != 0) {
@@ -3633,15 +3617,9 @@
VIDEOEDIT_LOG_FUNCTION(ANDROID_LOG_INFO, "VIDEO_EDITOR", "JNI_OnLoad()");
- // Add a text marker (the condition must always be true).
- ADD_TEXT_MARKER_FUN(NULL != pVm)
-
// Check the JNI version.
if (pVm->GetEnv(&pEnv, JNI_VERSION_1_4) == JNI_OK)
{
- // Add a code marker (the condition must always be true).
- ADD_CODE_MARKER_FUN(NULL != pEnv)
-
// Register the manual edit JNI methods.
if (videoEditor_registerManualEditMethods((JNIEnv*)pEnv) == 0)
{
diff --git a/media/jni/mediaeditor/VideoEditorPropertiesMain.cpp b/media/jni/mediaeditor/VideoEditorPropertiesMain.cpp
index 2f8e357..ae1a80e 100644
--- a/media/jni/mediaeditor/VideoEditorPropertiesMain.cpp
+++ b/media/jni/mediaeditor/VideoEditorPropertiesMain.cpp
@@ -26,7 +26,6 @@
#include <VideoEditorOsal.h>
#include <VideoEditorLogging.h>
#include <VideoEditorOsal.h>
-#include <marker.h>
extern "C" {
#include <M4OSA_Clock.h>
@@ -107,9 +106,6 @@
ANDROID_LOG_INFO, "VIDEO_EDITOR_PROPERTIES",
"videoEditProp_getProperties()");
- // Add a text marker (the condition must always be true).
- ADD_TEXT_MARKER_FUN(NULL != pEnv)
-
// Initialize the classes.
videoEditPropClass_init(&initialized, (JNIEnv*)pEnv);
@@ -192,9 +188,6 @@
// dereferencing of pClipProperties).
if (gotten)
{
- // Add a code marker (the condition must always be true).
- ADD_CODE_MARKER_FUN(NULL != pClipProperties)
-
// Log the API call.
VIDEOEDIT_LOG_API(
ANDROID_LOG_INFO, "VIDEO_EDITOR_PROPERTIES",
@@ -316,9 +309,6 @@
videoEditOsal_free(pFile);
pFile = M4OSA_NULL;
- // Add a text marker (the condition must always be true).
- ADD_TEXT_MARKER_FUN(NULL != pEnv)
-
// Return the Properties object.
return(properties);
}
diff --git a/packages/DefaultContainerService/src/com/android/defcontainer/DefaultContainerService.java b/packages/DefaultContainerService/src/com/android/defcontainer/DefaultContainerService.java
index 6e34bbb..48ef9db 100644
--- a/packages/DefaultContainerService/src/com/android/defcontainer/DefaultContainerService.java
+++ b/packages/DefaultContainerService/src/com/android/defcontainer/DefaultContainerService.java
@@ -30,6 +30,7 @@
import android.content.res.ObbInfo;
import android.content.res.ObbScanner;
import android.net.Uri;
+import android.os.Build;
import android.os.Environment;
import android.os.Environment.UserEnvironment;
import android.os.FileUtils;
@@ -39,10 +40,8 @@
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.StatFs;
-import android.os.SystemClock;
import android.provider.Settings;
import android.util.DisplayMetrics;
-import android.util.Log;
import android.util.Slog;
import com.android.internal.app.IMediaContainerService;
@@ -343,11 +342,13 @@
// The .apk file
String codePath = packageURI.getPath();
File codeFile = new File(codePath);
+ NativeLibraryHelper.ApkHandle handle = new NativeLibraryHelper.ApkHandle(codePath);
+ final int abi = NativeLibraryHelper.findSupportedAbi(handle, Build.SUPPORTED_ABIS);
// Calculate size of container needed to hold base APK.
final int sizeMb;
try {
- sizeMb = calculateContainerSize(codeFile, isForwardLocked);
+ sizeMb = calculateContainerSize(handle, codeFile, abi, isForwardLocked);
} catch (IOException e) {
Slog.w(TAG, "Problem when trying to copy " + codeFile.getPath());
return null;
@@ -410,7 +411,14 @@
final File sharedLibraryDir = new File(newCachePath, LIB_DIR_NAME);
if (sharedLibraryDir.mkdir()) {
- int ret = NativeLibraryHelper.copyNativeBinariesIfNeededLI(codeFile, sharedLibraryDir);
+ int ret = PackageManager.INSTALL_SUCCEEDED;
+ if (abi >= 0) {
+ ret = NativeLibraryHelper.copyNativeBinariesIfNeededLI(handle,
+ sharedLibraryDir, Build.SUPPORTED_ABIS[abi]);
+ } else if (abi != PackageManager.NO_NATIVE_LIBRARIES) {
+ ret = abi;
+ }
+
if (ret != PackageManager.INSTALL_SUCCEEDED) {
Slog.e(TAG, "Could not copy native libraries to " + sharedLibraryDir.getPath());
PackageHelper.destroySdDir(newCid);
@@ -824,6 +832,17 @@
return availSdMb > sizeMb;
}
+ private int calculateContainerSize(File apkFile, boolean forwardLocked) throws IOException {
+ NativeLibraryHelper.ApkHandle handle = new NativeLibraryHelper.ApkHandle(apkFile);
+ final int abi = NativeLibraryHelper.findSupportedAbi(handle, Build.SUPPORTED_ABIS);
+
+ try {
+ return calculateContainerSize(handle, apkFile, abi, forwardLocked);
+ } finally {
+ handle.close();
+ }
+ }
+
/**
* Calculate the container size for an APK. Takes into account the
*
@@ -831,7 +850,8 @@
* @return size in megabytes (2^20 bytes)
* @throws IOException when there is a problem reading the file
*/
- private int calculateContainerSize(File apkFile, boolean forwardLocked) throws IOException {
+ private int calculateContainerSize(NativeLibraryHelper.ApkHandle apkHandle,
+ File apkFile, int abiIndex, boolean forwardLocked) throws IOException {
// Calculate size of container needed to hold base APK.
long sizeBytes = apkFile.length();
if (sizeBytes == 0 && !apkFile.exists()) {
@@ -840,7 +860,10 @@
// Check all the native files that need to be copied and add that to the
// container size.
- sizeBytes += NativeLibraryHelper.sumNativeBinariesLI(apkFile);
+ if (abiIndex >= 0) {
+ sizeBytes += NativeLibraryHelper.sumNativeBinariesLI(apkHandle,
+ Build.SUPPORTED_ABIS[abiIndex]);
+ }
if (forwardLocked) {
sizeBytes += PackageHelper.extractPublicFiles(apkFile.getPath(), null);
diff --git a/preloaded-classes b/preloaded-classes
index 02bd0bc..b60a379 100644
--- a/preloaded-classes
+++ b/preloaded-classes
@@ -400,7 +400,6 @@
android.ddm.DdmHandleThread
android.ddm.DdmHandleViewDebug
android.ddm.DdmRegister
-android.debug.JNITest
android.drm.DrmManagerClient
android.emoji.EmojiFactory
android.graphics.AvoidXfermode
diff --git a/rs/java/android/renderscript/ScriptIntrinsicResize.java b/rs/java/android/renderscript/ScriptIntrinsicResize.java
new file mode 100644
index 0000000..cc37120
--- /dev/null
+++ b/rs/java/android/renderscript/ScriptIntrinsicResize.java
@@ -0,0 +1,113 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.renderscript;
+
+/**
+ * Intrinsic for performing a resize of a 2D allocation.
+ * @hide
+ */
+public final class ScriptIntrinsicResize extends ScriptIntrinsic {
+ private Allocation mInput;
+
+ private ScriptIntrinsicResize(long id, RenderScript rs) {
+ super(id, rs);
+ }
+
+ /**
+ * Supported elements types are {@link Element#U8}, {@link
+ * Element#U8_2}, {@link Element#U8_3}, {@link Element#U8_4}
+ *
+ * @param rs The RenderScript context
+ *
+ * @return ScriptIntrinsicResize
+ */
+ public static ScriptIntrinsicResize create(RenderScript rs) {
+ long id = rs.nScriptIntrinsicCreate(12, 0);
+ ScriptIntrinsicResize si = new ScriptIntrinsicResize(id, rs);
+ return si;
+
+ }
+
+ /**
+ * Set the input of the resize.
+ * Must match the element type supplied during create.
+ *
+ * @param ain The input allocation.
+ */
+ public void setInput(Allocation ain) {
+ Element e = ain.getElement();
+ if (!e.isCompatible(Element.U8(mRS)) &&
+ !e.isCompatible(Element.U8_2(mRS)) &&
+ !e.isCompatible(Element.U8_3(mRS)) &&
+ !e.isCompatible(Element.U8_4(mRS))) {
+ throw new RSIllegalArgumentException("Unsuported element type.");
+ }
+
+ mInput = ain;
+ setVar(0, ain);
+ }
+
+ /**
+ * Get a FieldID for the input field of this intrinsic.
+ *
+ * @return Script.FieldID The FieldID object.
+ */
+ public Script.FieldID getFieldID_Input() {
+ return createFieldID(0, null);
+ }
+
+
+ /**
+ * Resize copy the input allocation to the output specified. The
+ * Allocation is rescaled if necessary using bi-cubic
+ * interpolation.
+ *
+ * @param aout Output allocation. Element type must match
+ * current input. Must not be same as input.
+ */
+ public void forEach_bicubic(Allocation aout) {
+ if (aout == mInput) {
+ throw new RSIllegalArgumentException("Output cannot be same as Input.");
+ }
+ forEach_bicubic(aout, null);
+ }
+
+ /**
+ * Resize copy the input allocation to the output specified. The
+ * Allocation is rescaled if necessary using bi-cubic
+ * interpolation.
+ *
+ * @param aout Output allocation. Element type must match
+ * current input.
+ * @param opt LaunchOptions for clipping
+ */
+ public void forEach_bicubic(Allocation aout, Script.LaunchOptions opt) {
+ forEach(0, null, aout, null, opt);
+ }
+
+ /**
+ * Get a KernelID for this intrinsic kernel.
+ *
+ * @return Script.KernelID The KernelID object.
+ */
+ public Script.KernelID getKernelID_bicubic() {
+ return createKernelID(0, 2, null, null);
+ }
+
+
+}
+
diff --git a/rs/jni/android_renderscript_RenderScript.cpp b/rs/jni/android_renderscript_RenderScript.cpp
index 9b89eb9..0d75f4c 100644
--- a/rs/jni/android_renderscript_RenderScript.cpp
+++ b/rs/jni/android_renderscript_RenderScript.cpp
@@ -50,24 +50,29 @@
using namespace android;
-#define PER_ARRAY_TYPE(flag, fnc, ...) { \
+#define PER_ARRAY_TYPE(flag, fnc, readonly, ...) { \
jint len = 0; \
void *ptr = NULL; \
size_t typeBytes = 0; \
+ jint relFlag = 0; \
+ if (readonly) { \
+ /* The on-release mode should only be JNI_ABORT for read-only accesses. */ \
+ relFlag = JNI_ABORT; \
+ } \
switch(dataType) { \
case RS_TYPE_FLOAT_32: \
len = _env->GetArrayLength((jfloatArray)data); \
ptr = _env->GetFloatArrayElements((jfloatArray)data, flag); \
typeBytes = 4; \
fnc(__VA_ARGS__); \
- _env->ReleaseFloatArrayElements((jfloatArray)data, (jfloat *)ptr, JNI_ABORT); \
+ _env->ReleaseFloatArrayElements((jfloatArray)data, (jfloat *)ptr, relFlag); \
return; \
case RS_TYPE_FLOAT_64: \
len = _env->GetArrayLength((jdoubleArray)data); \
ptr = _env->GetDoubleArrayElements((jdoubleArray)data, flag); \
typeBytes = 8; \
fnc(__VA_ARGS__); \
- _env->ReleaseDoubleArrayElements((jdoubleArray)data, (jdouble *)ptr, JNI_ABORT);\
+ _env->ReleaseDoubleArrayElements((jdoubleArray)data, (jdouble *)ptr, relFlag); \
return; \
case RS_TYPE_SIGNED_8: \
case RS_TYPE_UNSIGNED_8: \
@@ -75,7 +80,7 @@
ptr = _env->GetByteArrayElements((jbyteArray)data, flag); \
typeBytes = 1; \
fnc(__VA_ARGS__); \
- _env->ReleaseByteArrayElements((jbyteArray)data, (jbyte*)ptr, JNI_ABORT); \
+ _env->ReleaseByteArrayElements((jbyteArray)data, (jbyte*)ptr, relFlag); \
return; \
case RS_TYPE_SIGNED_16: \
case RS_TYPE_UNSIGNED_16: \
@@ -83,7 +88,7 @@
ptr = _env->GetShortArrayElements((jshortArray)data, flag); \
typeBytes = 2; \
fnc(__VA_ARGS__); \
- _env->ReleaseShortArrayElements((jshortArray)data, (jshort *)ptr, JNI_ABORT); \
+ _env->ReleaseShortArrayElements((jshortArray)data, (jshort *)ptr, relFlag); \
return; \
case RS_TYPE_SIGNED_32: \
case RS_TYPE_UNSIGNED_32: \
@@ -91,7 +96,7 @@
ptr = _env->GetIntArrayElements((jintArray)data, flag); \
typeBytes = 4; \
fnc(__VA_ARGS__); \
- _env->ReleaseIntArrayElements((jintArray)data, (jint *)ptr, JNI_ABORT); \
+ _env->ReleaseIntArrayElements((jintArray)data, (jint *)ptr, relFlag); \
return; \
case RS_TYPE_SIGNED_64: \
case RS_TYPE_UNSIGNED_64: \
@@ -99,7 +104,7 @@
ptr = _env->GetLongArrayElements((jlongArray)data, flag); \
typeBytes = 8; \
fnc(__VA_ARGS__); \
- _env->ReleaseLongArrayElements((jlongArray)data, (jlong *)ptr, JNI_ABORT); \
+ _env->ReleaseLongArrayElements((jlongArray)data, (jlong *)ptr, relFlag); \
return; \
default: \
break; \
@@ -675,6 +680,7 @@
}
+// Copies from the Java object data into the Allocation pointed to by _alloc.
static void
nAllocationData1D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint offset, jint lod,
jint count, jobject data, jint sizeBytes, jint dataType)
@@ -682,9 +688,10 @@
RsAllocation *alloc = (RsAllocation *)_alloc;
LOG_API("nAllocation1DData, con(%p), adapter(%p), offset(%i), count(%i), sizeBytes(%i), dataType(%i)",
(RsContext)con, (RsAllocation)alloc, offset, count, sizeBytes, dataType);
- PER_ARRAY_TYPE(NULL, rsAllocation1DData, (RsContext)con, alloc, offset, lod, count, ptr, sizeBytes);
+ PER_ARRAY_TYPE(NULL, rsAllocation1DData, true, (RsContext)con, alloc, offset, lod, count, ptr, sizeBytes);
}
+// Copies from the Java array data into the Allocation pointed to by alloc.
static void
// native void rsnAllocationElementData1D(long con, long id, int xoff, int compIdx, byte[] d, int sizeBytes);
nAllocationElementData1D(JNIEnv *_env, jobject _this, jlong con, jlong alloc, jint offset, jint lod, jint compIdx, jbyteArray data, jint sizeBytes)
@@ -696,6 +703,7 @@
_env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
}
+// Copies from the Java object data into the Allocation pointed to by _alloc.
static void
nAllocationData2D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint lod, jint _face,
jint w, jint h, jobject data, jint sizeBytes, jint dataType)
@@ -704,9 +712,11 @@
RsAllocationCubemapFace face = (RsAllocationCubemapFace)_face;
LOG_API("nAllocation2DData, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i) type(%i)",
(RsContext)con, alloc, xoff, yoff, w, h, sizeBytes, dataType);
- PER_ARRAY_TYPE(NULL, rsAllocation2DData, (RsContext)con, alloc, xoff, yoff, lod, face, w, h, ptr, sizeBytes, 0);
+ PER_ARRAY_TYPE(NULL, rsAllocation2DData, true, (RsContext)con, alloc, xoff, yoff, lod, face, w, h, ptr, sizeBytes, 0);
}
+// Copies from the Allocation pointed to by srcAlloc into the Allocation
+// pointed to by dstAlloc.
static void
nAllocationData2D_alloc(JNIEnv *_env, jobject _this, jlong con,
jlong dstAlloc, jint dstXoff, jint dstYoff,
@@ -731,6 +741,7 @@
srcMip, srcFace);
}
+// Copies from the Java object data into the Allocation pointed to by _alloc.
static void
nAllocationData3D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint zoff, jint lod,
jint w, jint h, jint d, jobject data, int sizeBytes, int dataType)
@@ -738,9 +749,11 @@
RsAllocation *alloc = (RsAllocation *)_alloc;
LOG_API("nAllocation3DData, con(%p), alloc(%p), xoff(%i), yoff(%i), zoff(%i), lod(%i), w(%i), h(%i), d(%i), sizeBytes(%i)",
(RsContext)con, (RsAllocation)alloc, xoff, yoff, zoff, lod, w, h, d, sizeBytes);
- PER_ARRAY_TYPE(NULL, rsAllocation3DData, (RsContext)con, alloc, xoff, yoff, zoff, lod, w, h, d, ptr, sizeBytes, 0);
+ PER_ARRAY_TYPE(NULL, rsAllocation3DData, true, (RsContext)con, alloc, xoff, yoff, zoff, lod, w, h, d, ptr, sizeBytes, 0);
}
+// Copies from the Allocation pointed to by srcAlloc into the Allocation
+// pointed to by dstAlloc.
static void
nAllocationData3D_alloc(JNIEnv *_env, jobject _this, jlong con,
jlong dstAlloc, jint dstXoff, jint dstYoff, jint dstZoff,
@@ -764,14 +777,16 @@
}
+// Copies from the Allocation pointed to by _alloc into the Java object data.
static void
nAllocationRead(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jobject data, int dataType)
{
RsAllocation *alloc = (RsAllocation *)_alloc;
LOG_API("nAllocationRead, con(%p), alloc(%p)", (RsContext)con, (RsAllocation)alloc);
- PER_ARRAY_TYPE(0, rsAllocationRead, (RsContext)con, alloc, ptr, len * typeBytes);
+ PER_ARRAY_TYPE(0, rsAllocationRead, false, (RsContext)con, alloc, ptr, len * typeBytes);
}
+// Copies from the Allocation pointed to by _alloc into the Java object data.
static void
nAllocationRead1D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint offset, jint lod,
jint count, jobject data, int sizeBytes, int dataType)
@@ -779,9 +794,10 @@
RsAllocation *alloc = (RsAllocation *)_alloc;
LOG_API("nAllocation1DRead, con(%p), adapter(%p), offset(%i), count(%i), sizeBytes(%i), dataType(%i)",
(RsContext)con, alloc, offset, count, sizeBytes, dataType);
- PER_ARRAY_TYPE(0, rsAllocation1DRead, (RsContext)con, alloc, offset, lod, count, ptr, sizeBytes);
+ PER_ARRAY_TYPE(0, rsAllocation1DRead, false, (RsContext)con, alloc, offset, lod, count, ptr, sizeBytes);
}
+// Copies from the Allocation pointed to by _alloc into the Java object data.
static void
nAllocationRead2D(JNIEnv *_env, jobject _this, jlong con, jlong _alloc, jint xoff, jint yoff, jint lod, jint _face,
jint w, jint h, jobject data, int sizeBytes, int dataType)
@@ -790,7 +806,7 @@
RsAllocationCubemapFace face = (RsAllocationCubemapFace)_face;
LOG_API("nAllocation2DRead, con(%p), adapter(%p), xoff(%i), yoff(%i), w(%i), h(%i), len(%i) type(%i)",
(RsContext)con, alloc, xoff, yoff, w, h, sizeBytes, dataType);
- PER_ARRAY_TYPE(0, rsAllocation2DRead, (RsContext)con, alloc, xoff, yoff, lod, face, w, h, ptr, sizeBytes, 0);
+ PER_ARRAY_TYPE(0, rsAllocation2DRead, false, (RsContext)con, alloc, xoff, yoff, lod, face, w, h, ptr, sizeBytes, 0);
}
static jlong
@@ -1026,7 +1042,7 @@
jint len = _env->GetArrayLength(data);
jbyte *ptr = _env->GetByteArrayElements(data, NULL);
rsScriptGetVarV((RsContext)con, (RsScript)script, slot, ptr, len);
- _env->ReleaseByteArrayElements(data, ptr, JNI_ABORT);
+ _env->ReleaseByteArrayElements(data, ptr, 0);
}
static void
diff --git a/services/java/com/android/server/am/ActivityManagerService.java b/services/java/com/android/server/am/ActivityManagerService.java
index 2b0c0c9..16b9963 100644
--- a/services/java/com/android/server/am/ActivityManagerService.java
+++ b/services/java/com/android/server/am/ActivityManagerService.java
@@ -2780,11 +2780,16 @@
debugFlags |= Zygote.DEBUG_ENABLE_ASSERT;
}
+ String requiredAbi = app.info.requiredCpuAbi;
+ if (requiredAbi == null) {
+ requiredAbi = Build.SUPPORTED_ABIS[0];
+ }
+
// Start the process. It will either succeed and return a result containing
// the PID of the new process, or else throw a RuntimeException.
Process.ProcessStartResult startResult = Process.start("android.app.ActivityThread",
app.processName, uid, uid, gids, debugFlags, mountExternal,
- app.info.targetSdkVersion, app.info.seinfo, null);
+ app.info.targetSdkVersion, app.info.seinfo, requiredAbi, null);
BatteryStatsImpl bs = mBatteryStatsService.getActiveStatistics();
synchronized (bs) {
diff --git a/services/java/com/android/server/pm/PackageManagerService.java b/services/java/com/android/server/pm/PackageManagerService.java
index f33f7394..44765a5 100755
--- a/services/java/com/android/server/pm/PackageManagerService.java
+++ b/services/java/com/android/server/pm/PackageManagerService.java
@@ -59,8 +59,8 @@
import android.content.Intent;
import android.content.IntentFilter;
import android.content.IntentSender;
-import android.content.ServiceConnection;
import android.content.IntentSender.SendIntentException;
+import android.content.ServiceConnection;
import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.ContainerEncryptionParams;
@@ -72,14 +72,15 @@
import android.content.pm.IPackageMoveObserver;
import android.content.pm.IPackageStatsObserver;
import android.content.pm.InstrumentationInfo;
+import android.content.pm.ManifestDigest;
import android.content.pm.PackageCleanItem;
import android.content.pm.PackageInfo;
import android.content.pm.PackageInfoLite;
import android.content.pm.PackageManager;
import android.content.pm.PackageParser;
-import android.content.pm.PackageUserState;
import android.content.pm.PackageParser.ActivityIntentInfo;
import android.content.pm.PackageStats;
+import android.content.pm.PackageUserState;
import android.content.pm.ParceledListSlice;
import android.content.pm.PermissionGroupInfo;
import android.content.pm.PermissionInfo;
@@ -87,7 +88,6 @@
import android.content.pm.ResolveInfo;
import android.content.pm.ServiceInfo;
import android.content.pm.Signature;
-import android.content.pm.ManifestDigest;
import android.content.pm.VerificationParams;
import android.content.pm.VerifierDeviceIdentity;
import android.content.pm.VerifierInfo;
@@ -97,6 +97,7 @@
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
+import android.os.Environment.UserEnvironment;
import android.os.FileObserver;
import android.os.FileUtils;
import android.os.Handler;
@@ -113,7 +114,6 @@
import android.os.SystemClock;
import android.os.SystemProperties;
import android.os.UserHandle;
-import android.os.Environment.UserEnvironment;
import android.os.UserManager;
import android.security.KeyStore;
import android.security.SystemKeyStore;
@@ -2005,6 +2005,7 @@
pkg.applicationInfo.dataDir =
getDataPathForPackage(packageName, 0).getPath();
pkg.applicationInfo.nativeLibraryDir = ps.nativeLibraryPathString;
+ pkg.applicationInfo.requiredCpuAbi = ps.requiredCpuAbiString;
}
return generatePackageInfo(pkg, flags, userId);
}
@@ -3823,6 +3824,8 @@
codePath = pkg.mScanPath;
// Set application objects path explicitly.
setApplicationInfoPaths(pkg, codePath, resPath);
+ // Applications can run with the primary Cpu Abi unless otherwise is specified
+ pkg.applicationInfo.requiredCpuAbi = null;
// Note that we invoke the following method only if we are about to unpack an application
PackageParser.Package scannedPkg = scanPackageLI(pkg, parseFlags, scanMode
| SCAN_UPDATE_SIGNATURE, currentTime, user);
@@ -4395,6 +4398,7 @@
// the PkgSetting exists already and doesn't have to be created.
pkgSetting = mSettings.getPackageLPw(pkg, origPackage, realName, suid, destCodeFile,
destResourceFile, pkg.applicationInfo.nativeLibraryDir,
+ pkg.applicationInfo.requiredCpuAbi,
pkg.applicationInfo.flags, user, false);
if (pkgSetting == null) {
Slog.w(TAG, "Creating application package " + pkg.packageName + " failed");
@@ -4700,11 +4704,20 @@
}
try {
- if (copyNativeLibrariesForInternalApp(scanFile, nativeLibraryDir) != PackageManager.INSTALL_SUCCEEDED) {
+ int copyRet = copyNativeLibrariesForInternalApp(scanFile, nativeLibraryDir);
+ if (copyRet < 0 && copyRet != PackageManager.NO_NATIVE_LIBRARIES) {
Slog.e(TAG, "Unable to copy native libraries");
mLastScanError = PackageManager.INSTALL_FAILED_INTERNAL_ERROR;
return null;
}
+
+ // We've successfully copied native libraries across, so we make a
+ // note of what ABI we're using
+ if (copyRet != PackageManager.NO_NATIVE_LIBRARIES) {
+ pkg.applicationInfo.requiredCpuAbi = Build.SUPPORTED_ABIS[copyRet];
+ } else {
+ pkg.applicationInfo.requiredCpuAbi = null;
+ }
} catch (IOException e) {
Slog.e(TAG, "Unable to copy native libraries", e);
mLastScanError = PackageManager.INSTALL_FAILED_INTERNAL_ERROR;
@@ -5251,7 +5264,21 @@
* If this is an internal application or our nativeLibraryPath points to
* the app-lib directory, unpack the libraries if necessary.
*/
- return NativeLibraryHelper.copyNativeBinariesIfNeededLI(scanFile, nativeLibraryDir);
+ final NativeLibraryHelper.ApkHandle handle = new NativeLibraryHelper.ApkHandle(scanFile);
+ try {
+ int abi = NativeLibraryHelper.findSupportedAbi(handle, Build.SUPPORTED_ABIS);
+ if (abi >= 0) {
+ int copyRet = NativeLibraryHelper.copyNativeBinariesIfNeededLI(handle,
+ nativeLibraryDir, Build.SUPPORTED_ABIS[abi]);
+ if (copyRet != PackageManager.INSTALL_SUCCEEDED) {
+ return copyRet;
+ }
+ }
+
+ return abi;
+ } finally {
+ handle.close();
+ }
}
private void killApplication(String pkgName, int appId, String reason) {
@@ -8137,7 +8164,7 @@
}
try {
int copyRet = copyNativeLibrariesForInternalApp(codeFile, nativeLibraryFile);
- if (copyRet != PackageManager.INSTALL_SUCCEEDED) {
+ if (copyRet < 0 && copyRet != PackageManager.NO_NATIVE_LIBRARIES) {
return copyRet;
}
} catch (IOException e) {
@@ -11512,8 +11539,17 @@
final File newNativeDir = new File(newNativePath);
if (!isForwardLocked(pkg) && !isExternal(pkg)) {
- NativeLibraryHelper.copyNativeBinariesIfNeededLI(
- new File(newCodePath), newNativeDir);
+ // NOTE: We do not report any errors from the APK scan and library
+ // copy at this point.
+ NativeLibraryHelper.ApkHandle handle =
+ new NativeLibraryHelper.ApkHandle(newCodePath);
+ final int abi = NativeLibraryHelper.findSupportedAbi(
+ handle, Build.SUPPORTED_ABIS);
+ if (abi >= 0) {
+ NativeLibraryHelper.copyNativeBinariesIfNeededLI(
+ handle, newNativeDir, Build.SUPPORTED_ABIS[abi]);
+ }
+ handle.close();
}
final int[] users = sUserManager.getUserIds();
for (int user : users) {
diff --git a/services/java/com/android/server/pm/PackageSetting.java b/services/java/com/android/server/pm/PackageSetting.java
index b447861..15df3d2 100644
--- a/services/java/com/android/server/pm/PackageSetting.java
+++ b/services/java/com/android/server/pm/PackageSetting.java
@@ -30,8 +30,8 @@
SharedUserSetting sharedUser;
PackageSetting(String name, String realName, File codePath, File resourcePath,
- String nativeLibraryPathString, int pVersionCode, int pkgFlags) {
- super(name, realName, codePath, resourcePath, nativeLibraryPathString, pVersionCode,
+ String nativeLibraryPathString, String requiredCpuAbiString, int pVersionCode, int pkgFlags) {
+ super(name, realName, codePath, resourcePath, nativeLibraryPathString, requiredCpuAbiString, pVersionCode,
pkgFlags);
}
diff --git a/services/java/com/android/server/pm/PackageSettingBase.java b/services/java/com/android/server/pm/PackageSettingBase.java
index 7747c8f..ba95b9a 100644
--- a/services/java/com/android/server/pm/PackageSettingBase.java
+++ b/services/java/com/android/server/pm/PackageSettingBase.java
@@ -53,6 +53,7 @@
File resourcePath;
String resourcePathString;
String nativeLibraryPathString;
+ String requiredCpuAbiString;
long timeStamp;
long firstInstallTime;
long lastUpdateTime;
@@ -80,11 +81,11 @@
/* package name of the app that installed this package */
String installerPackageName;
PackageSettingBase(String name, String realName, File codePath, File resourcePath,
- String nativeLibraryPathString, int pVersionCode, int pkgFlags) {
+ String nativeLibraryPathString, String requiredCpuAbiString, int pVersionCode, int pkgFlags) {
super(pkgFlags);
this.name = name;
this.realName = realName;
- init(codePath, resourcePath, nativeLibraryPathString, pVersionCode);
+ init(codePath, resourcePath, nativeLibraryPathString, requiredCpuAbiString, pVersionCode);
}
/**
@@ -101,6 +102,7 @@
resourcePath = base.resourcePath;
resourcePathString = base.resourcePathString;
nativeLibraryPathString = base.nativeLibraryPathString;
+ requiredCpuAbiString = base.requiredCpuAbiString;
timeStamp = base.timeStamp;
firstInstallTime = base.firstInstallTime;
lastUpdateTime = base.lastUpdateTime;
@@ -128,12 +130,13 @@
}
void init(File codePath, File resourcePath, String nativeLibraryPathString,
- int pVersionCode) {
+ String requiredCpuAbiString, int pVersionCode) {
this.codePath = codePath;
this.codePathString = codePath.toString();
this.resourcePath = resourcePath;
this.resourcePathString = resourcePath.toString();
this.nativeLibraryPathString = nativeLibraryPathString;
+ this.requiredCpuAbiString = requiredCpuAbiString;
this.versionCode = pVersionCode;
}
@@ -164,6 +167,7 @@
grantedPermissions = base.grantedPermissions;
gids = base.gids;
+ requiredCpuAbiString = base.requiredCpuAbiString;
timeStamp = base.timeStamp;
firstInstallTime = base.firstInstallTime;
lastUpdateTime = base.lastUpdateTime;
diff --git a/services/java/com/android/server/pm/PendingPackage.java b/services/java/com/android/server/pm/PendingPackage.java
index c17cc46..36c3a34 100644
--- a/services/java/com/android/server/pm/PendingPackage.java
+++ b/services/java/com/android/server/pm/PendingPackage.java
@@ -22,8 +22,8 @@
final int sharedId;
PendingPackage(String name, String realName, File codePath, File resourcePath,
- String nativeLibraryPathString, int sharedId, int pVersionCode, int pkgFlags) {
- super(name, realName, codePath, resourcePath, nativeLibraryPathString, pVersionCode,
+ String nativeLibraryPathString, String requiredCpuAbiString, int sharedId, int pVersionCode, int pkgFlags) {
+ super(name, realName, codePath, resourcePath, nativeLibraryPathString, requiredCpuAbiString, pVersionCode,
pkgFlags);
this.sharedId = sharedId;
}
diff --git a/services/java/com/android/server/pm/Settings.java b/services/java/com/android/server/pm/Settings.java
index ed025e1..a50c689 100644
--- a/services/java/com/android/server/pm/Settings.java
+++ b/services/java/com/android/server/pm/Settings.java
@@ -213,10 +213,10 @@
PackageSetting getPackageLPw(PackageParser.Package pkg, PackageSetting origPackage,
String realName, SharedUserSetting sharedUser, File codePath, File resourcePath,
- String nativeLibraryPathString, int pkgFlags, UserHandle user, boolean add) {
+ String nativeLibraryPathString, String requiredCpuAbiString, int pkgFlags, UserHandle user, boolean add) {
final String name = pkg.packageName;
PackageSetting p = getPackageLPw(name, origPackage, realName, sharedUser, codePath,
- resourcePath, nativeLibraryPathString, pkg.mVersionCode, pkgFlags,
+ resourcePath, nativeLibraryPathString, requiredCpuAbiString, pkg.mVersionCode, pkgFlags,
user, add, true /* allowInstall */);
return p;
}
@@ -298,7 +298,7 @@
p.pkg.applicationInfo.flags &= ~ApplicationInfo.FLAG_UPDATED_SYSTEM_APP;
}
PackageSetting ret = addPackageLPw(name, p.realName, p.codePath, p.resourcePath,
- p.nativeLibraryPathString, p.appId, p.versionCode, p.pkgFlags);
+ p.nativeLibraryPathString, p.requiredCpuAbiString, p.appId, p.versionCode, p.pkgFlags);
mDisabledSysPackages.remove(name);
return ret;
}
@@ -312,7 +312,7 @@
}
PackageSetting addPackageLPw(String name, String realName, File codePath, File resourcePath,
- String nativeLibraryPathString, int uid, int vc, int pkgFlags) {
+ String nativeLibraryPathString, String requiredCpuAbiString, int uid, int vc, int pkgFlags) {
PackageSetting p = mPackages.get(name);
if (p != null) {
if (p.appId == uid) {
@@ -322,7 +322,7 @@
"Adding duplicate package, keeping first: " + name);
return null;
}
- p = new PackageSetting(name, realName, codePath, resourcePath, nativeLibraryPathString,
+ p = new PackageSetting(name, realName, codePath, resourcePath, nativeLibraryPathString, requiredCpuAbiString,
vc, pkgFlags);
p.appId = uid;
if (addUserIdLPw(uid, p, name)) {
@@ -391,10 +391,11 @@
private PackageSetting getPackageLPw(String name, PackageSetting origPackage,
String realName, SharedUserSetting sharedUser, File codePath, File resourcePath,
- String nativeLibraryPathString, int vc, int pkgFlags,
+ String nativeLibraryPathString, String requiredCpuAbiString, int vc, int pkgFlags,
UserHandle installUser, boolean add, boolean allowInstall) {
PackageSetting p = mPackages.get(name);
if (p != null) {
+ p.requiredCpuAbiString = requiredCpuAbiString;
if (!p.codePath.equals(codePath)) {
// Check to see if its a disabled system app
if ((p.pkgFlags & ApplicationInfo.FLAG_SYSTEM) != 0) {
@@ -438,7 +439,7 @@
if (origPackage != null) {
// We are consuming the data from an existing package.
p = new PackageSetting(origPackage.name, name, codePath, resourcePath,
- nativeLibraryPathString, vc, pkgFlags);
+ nativeLibraryPathString, requiredCpuAbiString, vc, pkgFlags);
if (PackageManagerService.DEBUG_UPGRADE) Log.v(PackageManagerService.TAG, "Package "
+ name + " is adopting original package " + origPackage.name);
// Note that we will retain the new package's signature so
@@ -455,7 +456,7 @@
p.setTimeStamp(codePath.lastModified());
} else {
p = new PackageSetting(name, realName, codePath, resourcePath,
- nativeLibraryPathString, vc, pkgFlags);
+ nativeLibraryPathString, requiredCpuAbiString, vc, pkgFlags);
p.setTimeStamp(codePath.lastModified());
p.sharedUser = sharedUser;
// If this is not a system app, it starts out stopped.
@@ -581,6 +582,8 @@
&& !nativeLibraryPath.equalsIgnoreCase(p.nativeLibraryPathString)) {
p.nativeLibraryPathString = nativeLibraryPath;
}
+ // Update the required Cpu Abi
+ p.requiredCpuAbiString = pkg.applicationInfo.requiredCpuAbi;
// Update version code if needed
if (pkg.mVersionCode != p.versionCode) {
p.versionCode = pkg.mVersionCode;
@@ -1498,6 +1501,9 @@
if (pkg.nativeLibraryPathString != null) {
serializer.attribute(null, "nativeLibraryPath", pkg.nativeLibraryPathString);
}
+ if (pkg.requiredCpuAbiString != null) {
+ serializer.attribute(null, "requiredCpuAbi", pkg.requiredCpuAbiString);
+ }
if (pkg.sharedUser == null) {
serializer.attribute(null, "userId", Integer.toString(pkg.appId));
} else {
@@ -1540,6 +1546,9 @@
if (pkg.nativeLibraryPathString != null) {
serializer.attribute(null, "nativeLibraryPath", pkg.nativeLibraryPathString);
}
+ if (pkg.requiredCpuAbiString != null) {
+ serializer.attribute(null, "requiredCpuAbi", pkg.requiredCpuAbiString);
+ }
serializer.attribute(null, "flags", Integer.toString(pkg.pkgFlags));
serializer.attribute(null, "ft", Long.toHexString(pkg.timeStamp));
serializer.attribute(null, "it", Long.toHexString(pkg.firstInstallTime));
@@ -1804,7 +1813,7 @@
if (idObj != null && idObj instanceof SharedUserSetting) {
PackageSetting p = getPackageLPw(pp.name, null, pp.realName,
(SharedUserSetting) idObj, pp.codePath, pp.resourcePath,
- pp.nativeLibraryPathString, pp.versionCode, pp.pkgFlags,
+ pp.nativeLibraryPathString, pp.requiredCpuAbiString, pp.versionCode, pp.pkgFlags,
null, true /* add */, false /* allowInstall */);
if (p == null) {
PackageManagerService.reportSettingsProblem(Log.WARN,
@@ -2224,6 +2233,8 @@
String codePathStr = parser.getAttributeValue(null, "codePath");
String resourcePathStr = parser.getAttributeValue(null, "resourcePath");
String nativeLibraryPathStr = parser.getAttributeValue(null, "nativeLibraryPath");
+ String requiredCpuAbiString = parser.getAttributeValue(null, "requiredCpuAbi");
+
if (resourcePathStr == null) {
resourcePathStr = codePathStr;
}
@@ -2243,7 +2254,7 @@
pkgFlags |= ApplicationInfo.FLAG_PRIVILEGED;
}
PackageSetting ps = new PackageSetting(name, realName, codePathFile,
- new File(resourcePathStr), nativeLibraryPathStr, versionCode, pkgFlags);
+ new File(resourcePathStr), nativeLibraryPathStr, requiredCpuAbiString, versionCode, pkgFlags);
String timeStampStr = parser.getAttributeValue(null, "ft");
if (timeStampStr != null) {
try {
@@ -2310,6 +2321,7 @@
String codePathStr = null;
String resourcePathStr = null;
String nativeLibraryPathStr = null;
+ String requiredCpuAbiString = null;
String systemStr = null;
String installerPackageName = null;
String uidError = null;
@@ -2329,6 +2341,8 @@
codePathStr = parser.getAttributeValue(null, "codePath");
resourcePathStr = parser.getAttributeValue(null, "resourcePath");
nativeLibraryPathStr = parser.getAttributeValue(null, "nativeLibraryPath");
+ requiredCpuAbiString = parser.getAttributeValue(null, "requiredCpuAbi");
+
version = parser.getAttributeValue(null, "version");
if (version != null) {
try {
@@ -2405,7 +2419,7 @@
+ parser.getPositionDescription());
} else if (userId > 0) {
packageSetting = addPackageLPw(name.intern(), realName, new File(codePathStr),
- new File(resourcePathStr), nativeLibraryPathStr, userId, versionCode,
+ new File(resourcePathStr), nativeLibraryPathStr, requiredCpuAbiString, userId, versionCode,
pkgFlags);
if (PackageManagerService.DEBUG_SETTINGS)
Log.i(PackageManagerService.TAG, "Reading package " + name + ": userId="
@@ -2423,7 +2437,7 @@
userId = sharedIdStr != null ? Integer.parseInt(sharedIdStr) : 0;
if (userId > 0) {
packageSetting = new PendingPackage(name.intern(), realName, new File(
- codePathStr), new File(resourcePathStr), nativeLibraryPathStr, userId,
+ codePathStr), new File(resourcePathStr), nativeLibraryPathStr, requiredCpuAbiString, userId,
versionCode, pkgFlags);
packageSetting.setTimeStamp(timeStamp);
packageSetting.firstInstallTime = firstInstallTime;
@@ -2452,6 +2466,7 @@
packageSetting.uidError = "true".equals(uidError);
packageSetting.installerPackageName = installerPackageName;
packageSetting.nativeLibraryPathString = nativeLibraryPathStr;
+ packageSetting.requiredCpuAbiString = requiredCpuAbiString;
// Handle legacy string here for single-user mode
final String enabledStr = parser.getAttributeValue(null, ATTR_ENABLED);
if (enabledStr != null) {
@@ -2915,6 +2930,7 @@
pw.print(prefix); pw.print(" codePath="); pw.println(ps.codePathString);
pw.print(prefix); pw.print(" resourcePath="); pw.println(ps.resourcePathString);
pw.print(prefix); pw.print(" nativeLibraryPath="); pw.println(ps.nativeLibraryPathString);
+ pw.print(prefix); pw.print(" requiredCpuAbi="); pw.println(ps.requiredCpuAbiString);
pw.print(prefix); pw.print(" versionCode="); pw.print(ps.versionCode);
if (ps.pkg != null) {
pw.print(" targetSdk="); pw.print(ps.pkg.applicationInfo.targetSdkVersion);
diff --git a/services/java/com/android/server/usb/UsbDeviceManager.java b/services/java/com/android/server/usb/UsbDeviceManager.java
index 5a60de0..5f07517 100644
--- a/services/java/com/android/server/usb/UsbDeviceManager.java
+++ b/services/java/com/android/server/usb/UsbDeviceManager.java
@@ -573,14 +573,19 @@
intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
intent.putExtra("state", (enabled ? 1 : 0));
if (enabled) {
+ Scanner scanner = null;
try {
- Scanner scanner = new Scanner(new File(AUDIO_SOURCE_PCM_PATH));
+ scanner = new Scanner(new File(AUDIO_SOURCE_PCM_PATH));
int card = scanner.nextInt();
int device = scanner.nextInt();
intent.putExtra("card", card);
intent.putExtra("device", device);
} catch (FileNotFoundException e) {
Slog.e(TAG, "could not open audio source PCM file", e);
+ } finally {
+ if (scanner != null) {
+ scanner.close();
+ }
}
}
mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL);