Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 59877e42 authored by Maunik Shah's avatar Maunik Shah Committed by Shibin George
Browse files

frameworks/base: Adjust ABI for 3rd party apps

Scan for libraries in assets folder and adjust the ABI accordingly.

Change-Id: I123367ba996ff4c04a5c37dc4525cd6373e0a135
parent 09ecabc3
Loading
Loading
Loading
Loading
+35 −1
Original line number Diff line number Diff line
@@ -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 @@ enum install_status_t {

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 @@ static int findSupportedAbi(JNIEnv *env, jlong apkHandle, jobjectArray supported
            }
        }
    }
    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];