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

Commit b181118b authored by Dianne Hackborn's avatar Dianne Hackborn
Browse files

Define TARGET_CPU_ABI for finding native code in .apks

parent 5b6a5cee
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -89822,6 +89822,16 @@
 visibility="public"
>
</field>
<field name="CPU_ABI"
 type="java.lang.String"
 transient="false"
 volatile="false"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="DEVICE"
 type="java.lang.String"
 transient="false"
+3 −0
Original line number Diff line number Diff line
@@ -543,6 +543,9 @@ public final class Pm {
        case PackageManager.INSTALL_FAILED_TEST_ONLY:
            s = "INSTALL_FAILED_TEST_ONLY";
            break;
        case PackageManager.INSTALL_FAILED_CPU_ABI_INCOMPATIBLE:
            s = "INSTALL_FAILED_CPU_ABI_INCOMPATIBLE";
            break;
        case PackageManager.INSTALL_PARSE_FAILED_NOT_APK:
            s = "INSTALL_PARSE_FAILED_NOT_APK";
            break;
+9 −0
Original line number Diff line number Diff line
@@ -397,6 +397,15 @@ public abstract class PackageManager {
     */
    public static final int INSTALL_FAILED_TEST_ONLY = -15;

    /**
     * Installation return code: this is passed to the {@link IPackageInstallObserver} by
     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)} if
     * the package being installed contains native code, but none that is
     * compatible with the the device's CPU_ABI.
     * @hide
     */
    public static final int INSTALL_FAILED_CPU_ABI_INCOMPATIBLE = -16;

    /**
     * Installation parse return code: this is passed to the {@link IPackageInstallObserver} by
     * {@link #installPackage(android.net.Uri, IPackageInstallObserver, int)}
+3 −0
Original line number Diff line number Diff line
@@ -38,6 +38,9 @@ public class Build {
    /** The name of the underlying board, like "goldfish". */
    public static final String BOARD = getString("ro.product.board");

    /** The name of the instruction set (CPU type + ABI convention) of native code. */
    public static final String CPU_ABI = getString("ro.product.cpu.abi");

    /** The manufacturer of the product/hardware. */
    public static final String MANUFACTURER = getString("ro.product.manufacturer");

+27 −20
Original line number Diff line number Diff line
@@ -2151,16 +2151,9 @@ class PackageManagerService extends IPackageManager.Stub {
            String path = scanFile.getPath();
            if (scanFileNewer) {
                Log.i(TAG, path + " changed; unpacking");
                try {
                    cachePackageSharedLibsLI(pkg, dataPath, scanFile);
                } catch (IOException e) {
                    Log.e(TAG, "Failure extracting shared libs", e);
                    if(mInstaller != null) {
                        mInstaller.remove(pkgName);
                    } else {
                        dataPath.delete();
                    }
                    mLastScanError = PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE;
                int err = cachePackageSharedLibsLI(pkg, dataPath, scanFile);
                if (err != PackageManager.INSTALL_SUCCEEDED) {
                    mLastScanError = err;
                    return null;
                }
            }
@@ -2444,14 +2437,15 @@ class PackageManagerService extends IPackageManager.Stub {
        return pkg;
    }

    private void cachePackageSharedLibsLI(PackageParser.Package pkg,
            File dataPath, File scanFile) throws IOException {
    private int cachePackageSharedLibsLI(PackageParser.Package pkg,
            File dataPath, File scanFile) {
        File sharedLibraryDir = new File(dataPath.getPath() + "/lib");
        final String sharedLibraryABI = "armeabi";
        final String sharedLibraryABI = Build.CPU_ABI;
        final String apkLibraryDirectory = "lib/" + sharedLibraryABI + "/";
        final String apkSharedLibraryPrefix = apkLibraryDirectory + "lib";
        final String sharedLibrarySuffix = ".so";
        boolean createdSharedLib = false;
        boolean hasNativeCode = false;
        boolean installedNativeCode = false;
        try {
            ZipFile zipFile = new ZipFile(scanFile);
            Enumeration<ZipEntry> entries =
@@ -2460,9 +2454,15 @@ class PackageManagerService extends IPackageManager.Stub {
            while (entries.hasMoreElements()) {
                ZipEntry entry = entries.nextElement();
                if (entry.isDirectory()) {
                    if (!hasNativeCode && entry.getName().startsWith("lib")) {
                        hasNativeCode = true;
                    }
                    continue;
                }
                String entryName = entry.getName();
                if (entryName.startsWith("lib/")) {
                    hasNativeCode = true;
                }
                if (! (entryName.startsWith(apkSharedLibraryPrefix)
                        && entryName.endsWith(sharedLibrarySuffix))) {
                    continue;
@@ -2473,6 +2473,9 @@ class PackageManagerService extends IPackageManager.Stub {
                        || (!FileUtils.isFilenameSafe(new File(libFileName)))) {
                    continue;
                }
                
                installedNativeCode = true;
                
                String sharedLibraryFilePath = sharedLibraryDir.getPath() +
                    File.separator + libFileName;
                File sharedLibraryFile = new File(sharedLibraryFilePath);
@@ -2484,19 +2487,23 @@ class PackageManagerService extends IPackageManager.Stub {
                    }
                    if (mInstaller == null) {
                        sharedLibraryDir.mkdir();
                        createdSharedLib = true;
                    }
                    cacheSharedLibLI(pkg, zipFile, entry, sharedLibraryDir,
                            sharedLibraryFile);
                }
            }
        } catch (IOException e) {
            Log.e(TAG, "Failed to cache package shared libs", e);
            if(createdSharedLib) {
                sharedLibraryDir.delete();
            Log.w(TAG, "Failed to cache package shared libs", e);
            return PackageManager.INSTALL_FAILED_INSUFFICIENT_STORAGE;
        }
            throw e;
        
        if (hasNativeCode && !installedNativeCode) {
            Log.w(TAG, "Install failed: .apk has native code but none for arch "
                    + Build.CPU_ABI);
            return PackageManager.INSTALL_FAILED_CPU_ABI_INCOMPATIBLE;
        }
        
        return PackageManager.INSTALL_SUCCEEDED;
    }

    private void cacheSharedLibLI(PackageParser.Package pkg,