frameworks/base: Adjust ABI for 3rd party apps
Scan for libraries in assets folder and adjust the ABI accordingly.
Change-Id: I123367ba996ff4c04a5c37dc4525cd6373e0a135
diff --git a/core/jni/com_android_internal_content_NativeLibraryHelper.cpp b/core/jni/com_android_internal_content_NativeLibraryHelper.cpp
index daa6f82..f7f19b4 100644
--- a/core/jni/com_android_internal_content_NativeLibraryHelper.cpp
+++ b/core/jni/com_android_internal_content_NativeLibraryHelper.cpp
@@ -36,7 +36,7 @@
#include <inttypes.h>
#include <sys/stat.h>
#include <sys/types.h>
-
+#include <dlfcn.h>
#define APK_LIB "lib/"
#define APK_LIB_LEN (sizeof(APK_LIB) - 1)
@@ -55,6 +55,10 @@
#define TMP_FILE_PATTERN "/tmp.XXXXXX"
#define TMP_FILE_PATTERN_LEN (sizeof(TMP_FILE_PATTERN) - 1)
+#define LIB_UNINIT 0
+#define LIB_INITED_AND_FAIL -1
+#define LIB_INITED_AND_SUCCESS 1
+
namespace android {
// These match PackageManager.java install codes
@@ -70,6 +74,24 @@
typedef install_status_t (*iterFunc)(JNIEnv*, void*, ZipFileRO*, ZipEntryRO, const char*);
+typedef int (*PGetAssetsStatusFunc) (ZipFileRO*, Vector<ScopedUtfChars*>, const int);
+static PGetAssetsStatusFunc GetAssetsStatusFunc = NULL;
+static int g_assetLibInit = LIB_UNINIT;
+
+static int initAssetsVerifierLib() {
+ if (g_assetLibInit != LIB_UNINIT) return g_assetLibInit;
+ void* handle = dlopen("libassetsverifier.so", RTLD_NOW);
+ if (handle != NULL) {
+ GetAssetsStatusFunc = (PGetAssetsStatusFunc)dlsym(handle, "getAssetsStatus");
+ if (GetAssetsStatusFunc != NULL) {
+ g_assetLibInit = LIB_INITED_AND_SUCCESS;
+ } else {
+ g_assetLibInit = LIB_INITED_AND_FAIL;
+ }
+ }
+ return g_assetLibInit;
+}
+
// Equivalent to android.os.FileUtils.isFilenameSafe
static bool
isFilenameSafe(const char* filename)
@@ -477,6 +499,18 @@
}
}
}
+ int asset_status = NO_NATIVE_LIBRARIES;
+
+ int rc = initAssetsVerifierLib();
+ if (rc == LIB_INITED_AND_SUCCESS) {
+ asset_status = GetAssetsStatusFunc(zipFile, supportedAbis, numAbis);
+ } else {
+ ALOGE("Failed to load assets verifier: %d", rc);
+ }
+ if (asset_status == 1) {
+ // override the status if asset_status hints at 32-bit abi
+ status = 1;
+ }
for (int i = 0; i < numAbis; ++i) {
delete supportedAbis[i];