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

Commit f8e5993c authored by Dmitriy Ivanov's avatar Dmitriy Ivanov Committed by Android (Google) Code Review
Browse files

Merge "Fix abi detection for system apks" into mnc-dev

parents ed9d3494 a25a3d61
Loading
Loading
Loading
Loading
+38 −87
Original line number Diff line number Diff line
@@ -1876,7 +1876,7 @@ public class PackageManagerService extends IPackageManager.Stub {
            alreadyDexOpted.add(frameworkDir.getPath() + "/core-libart.jar");
            /**
             * And there are a number of commands implemented in Java, which
             * There are a number of commands implemented in Java, which
             * we currently need to do the dexopt on so that they can be
             * run from a non-root shell.
             */
@@ -6361,32 +6361,9 @@ public class PackageManagerService extends IPackageManager.Stub {
        final String path = scanFile.getPath();
        final String cpuAbiOverride = deriveAbiOverride(pkg.cpuAbiOverride, pkgSetting);
        if (isSystemApp(pkg) && !pkg.isUpdatedSystemApp()) {
            setBundledAppAbisAndRoots(pkg, pkgSetting);
            // If we haven't found any native libraries for the app, check if it has
            // renderscript code. We'll need to force the app to 32 bit if it has
            // renderscript bitcode.
            if (pkg.applicationInfo.primaryCpuAbi == null
                    && pkg.applicationInfo.secondaryCpuAbi == null
                    && Build.SUPPORTED_64_BIT_ABIS.length >  0) {
                NativeLibraryHelper.Handle handle = null;
                try {
                    handle = NativeLibraryHelper.Handle.create(scanFile);
                    if (NativeLibraryHelper.hasRenderscriptBitcode(handle)) {
                        pkg.applicationInfo.primaryCpuAbi = Build.SUPPORTED_32_BIT_ABIS[0];
                    }
                } catch (IOException ioe) {
                    Slog.w(TAG, "Error scanning system app : " + ioe);
                } finally {
                    IoUtils.closeQuietly(handle);
                }
            }
            setNativeLibraryPaths(pkg);
        } else {
        if ((scanFlags & SCAN_NEW_INSTALL) == 0) {
                deriveNonSystemPackageAbi(pkg, scanFile, cpuAbiOverride, true /* extract libs */);
            derivePackageAbi(pkg, scanFile, cpuAbiOverride, true /* extract libs */);
        } else {
            if ((scanFlags & SCAN_MOVE) != 0) {
                // We haven't run dex-opt for this move (since we've moved the compiled output too)
@@ -6421,7 +6398,6 @@ public class PackageManagerService extends IPackageManager.Stub {
                }
            }
        }
        }
        // This is a special case for the "system" package, where the ABI is
        // dictated by the zygote configuration (and init.rc). We should keep track
@@ -6946,7 +6922,7 @@ public class PackageManagerService extends IPackageManager.Stub {
     *
     * If {@code extractLibs} is true, native libraries are extracted from the app if required.
     */
    public void deriveNonSystemPackageAbi(PackageParser.Package pkg, File scanFile,
    public void derivePackageAbi(PackageParser.Package pkg, File scanFile,
                                 String cpuAbiOverride, boolean extractLibs)
            throws PackageManagerException {
        // TODO: We can probably be smarter about this stuff. For installed apps,
@@ -6959,8 +6935,10 @@ public class PackageManagerService extends IPackageManager.Stub {
        setNativeLibraryPaths(pkg);
        // We would never need to extract libs for forward-locked and external packages,
        // since the container service will do it for us.
        if (pkg.isForwardLocked() || isExternal(pkg)) {
        // since the container service will do it for us. We shouldn't attempt to
        // extract libs from system app when it was not updated.
        if (pkg.isForwardLocked() || isExternal(pkg) ||
            (isSystemApp(pkg) && !pkg.isUpdatedSystemApp()) ) {
            extractLibs = false;
        }
@@ -7290,33 +7268,6 @@ public class PackageManagerService extends IPackageManager.Stub {
        }
    }
    /**
     * Calculate the abis and roots for a bundled app. These can uniquely
     * be determined from the contents of the system partition, i.e whether
     * it contains 64 or 32 bit shared libraries etc. We do not validate any
     * of this information, and instead assume that the system was built
     * sensibly.
     */
    private void setBundledAppAbisAndRoots(PackageParser.Package pkg,
                                           PackageSetting pkgSetting) {
        final String apkName = deriveCodePathName(pkg.applicationInfo.getCodePath());
        // If "/system/lib64/apkname" exists, assume that is the per-package
        // native library directory to use; otherwise use "/system/lib/apkname".
        final String apkRoot = calculateBundledApkRoot(pkg.applicationInfo.sourceDir);
        setBundledAppAbi(pkg, apkRoot, apkName);
        // pkgSetting might be null during rescan following uninstall of updates
        // to a bundled app, so accommodate that possibility.  The settings in
        // that case will be established later from the parsed package.
        //
        // If the settings aren't null, sync them up with what we've just derived.
        // note that apkRoot isn't stored in the package settings.
        if (pkgSetting != null) {
            pkgSetting.primaryCpuAbiString = pkg.applicationInfo.primaryCpuAbi;
            pkgSetting.secondaryCpuAbiString = pkg.applicationInfo.secondaryCpuAbi;
        }
    }
    /**
     * Deduces the ABI of a bundled app and sets the relevant fields on the
     * parsed pkg object.
@@ -11695,7 +11646,7 @@ public class PackageManagerService extends IPackageManager.Stub {
            scanFlags |= SCAN_NO_DEX;
            try {
                deriveNonSystemPackageAbi(pkg, new File(pkg.codePath), args.abiOverride,
                derivePackageAbi(pkg, new File(pkg.codePath), args.abiOverride,
                        true /* extract libs */);
            } catch (PackageManagerException pme) {
                Slog.e(TAG, "Error deriving application ABI", pme);