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

Commit ff0c4708 authored by Ramin Zaghi's avatar Ramin Zaghi Committed by Narayan Kamath
Browse files

System services detect and register app CPU ABIs

This patch uses the NativeLibraryHelper class to
match native libraries in an .apk package with
those listed in 'ro.cpu.abilist' property.
The result is stored in packages.xml and the
ApplicationInfo class.

This information will be used by the ActivityManager
to decide which zygote to use to launch the given
app.

Change-Id: I3ec3d050996d8f4621f286ca331b9ad47ea26fa0
parent 1378aba7
Loading
Loading
Loading
Loading
+12 −0
Original line number Original line Diff line number Diff line
@@ -440,6 +440,15 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable {
     */
     */
    public String nativeLibraryDir;
    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;
     * The kernel user-ID that has been assigned to this application;
     * currently this is not a unique ID (multiple applications can have
     * currently this is not a unique ID (multiple applications can have
@@ -570,6 +579,7 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable {
        sourceDir = orig.sourceDir;
        sourceDir = orig.sourceDir;
        publicSourceDir = orig.publicSourceDir;
        publicSourceDir = orig.publicSourceDir;
        nativeLibraryDir = orig.nativeLibraryDir;
        nativeLibraryDir = orig.nativeLibraryDir;
        requiredCpuAbi = orig.requiredCpuAbi;
        resourceDirs = orig.resourceDirs;
        resourceDirs = orig.resourceDirs;
        seinfo = orig.seinfo;
        seinfo = orig.seinfo;
        sharedLibraryFiles = orig.sharedLibraryFiles;
        sharedLibraryFiles = orig.sharedLibraryFiles;
@@ -610,6 +620,7 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable {
        dest.writeString(sourceDir);
        dest.writeString(sourceDir);
        dest.writeString(publicSourceDir);
        dest.writeString(publicSourceDir);
        dest.writeString(nativeLibraryDir);
        dest.writeString(nativeLibraryDir);
        dest.writeString(requiredCpuAbi);
        dest.writeStringArray(resourceDirs);
        dest.writeStringArray(resourceDirs);
        dest.writeString(seinfo);
        dest.writeString(seinfo);
        dest.writeStringArray(sharedLibraryFiles);
        dest.writeStringArray(sharedLibraryFiles);
@@ -649,6 +660,7 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable {
        sourceDir = source.readString();
        sourceDir = source.readString();
        publicSourceDir = source.readString();
        publicSourceDir = source.readString();
        nativeLibraryDir = source.readString();
        nativeLibraryDir = source.readString();
        requiredCpuAbi = source.readString();
        resourceDirs = source.readStringArray();
        resourceDirs = source.readStringArray();
        seinfo = source.readString();
        seinfo = source.readString();
        sharedLibraryFiles = source.readStringArray();
        sharedLibraryFiles = source.readStringArray();
+3 −9
Original line number Original line Diff line number Diff line
@@ -466,6 +466,7 @@ public class Process {
     * @param debugFlags Additional flags.
     * @param debugFlags Additional flags.
     * @param targetSdkVersion The target SDK version for the app.
     * @param targetSdkVersion The target SDK version for the app.
     * @param seInfo null-ok SELinux information for the new process.
     * @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.
     * @param zygoteArgs Additional arguments to supply to the zygote process.
     * 
     * 
     * @return An object that describes the result of the attempt to start the process.
     * @return An object that describes the result of the attempt to start the process.
@@ -479,12 +480,12 @@ public class Process {
                                  int debugFlags, int mountExternal,
                                  int debugFlags, int mountExternal,
                                  int targetSdkVersion,
                                  int targetSdkVersion,
                                  String seInfo,
                                  String seInfo,
                                  String abi,
                                  String[] zygoteArgs) {
                                  String[] zygoteArgs) {
        try {
        try {
            return startViaZygote(processClass, niceName, uid, gid, gids,
            return startViaZygote(processClass, niceName, uid, gid, gids,
                    debugFlags, mountExternal, targetSdkVersion, seInfo,
                    debugFlags, mountExternal, targetSdkVersion, seInfo,
                    null, /* zygoteAbi TODO: Replace this with the real ABI */
                    abi, zygoteArgs);
                    zygoteArgs);
        } catch (ZygoteStartFailedEx ex) {
        } catch (ZygoteStartFailedEx ex) {
            Log.e(LOG_TAG,
            Log.e(LOG_TAG,
                    "Starting VM process through Zygote failed");
                    "Starting VM process through Zygote failed");
@@ -702,13 +703,6 @@ public class Process {
            primaryZygoteState = ZygoteState.connect(ZYGOTE_SOCKET, getNumTries(primaryZygoteState));
            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) {
            return primaryZygoteState;
        }

        if (primaryZygoteState.matches(abi)) {
        if (primaryZygoteState.matches(abi)) {
            return primaryZygoteState;
            return primaryZygoteState;
        }
        }
+6 −1
Original line number Original line Diff line number Diff line
@@ -2780,11 +2780,16 @@ public final class ActivityManagerService extends ActivityManagerNative
                debugFlags |= Zygote.DEBUG_ENABLE_ASSERT;
                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
            // Start the process.  It will either succeed and return a result containing
            // the PID of the new process, or else throw a RuntimeException.
            // the PID of the new process, or else throw a RuntimeException.
            Process.ProcessStartResult startResult = Process.start("android.app.ActivityThread",
            Process.ProcessStartResult startResult = Process.start("android.app.ActivityThread",
                    app.processName, uid, uid, gids, debugFlags, mountExternal,
                    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();
            BatteryStatsImpl bs = mBatteryStatsService.getActiveStatistics();
            synchronized (bs) {
            synchronized (bs) {
+12 −0
Original line number Original line Diff line number Diff line
@@ -2005,6 +2005,7 @@ public class PackageManagerService extends IPackageManager.Stub {
                pkg.applicationInfo.dataDir =
                pkg.applicationInfo.dataDir =
                        getDataPathForPackage(packageName, 0).getPath();
                        getDataPathForPackage(packageName, 0).getPath();
                pkg.applicationInfo.nativeLibraryDir = ps.nativeLibraryPathString;
                pkg.applicationInfo.nativeLibraryDir = ps.nativeLibraryPathString;
                pkg.applicationInfo.requiredCpuAbi = ps.requiredCpuAbiString;
            }
            }
            return generatePackageInfo(pkg, flags, userId);
            return generatePackageInfo(pkg, flags, userId);
        }
        }
@@ -3823,6 +3824,8 @@ public class PackageManagerService extends IPackageManager.Stub {
        codePath = pkg.mScanPath;
        codePath = pkg.mScanPath;
        // Set application objects path explicitly.
        // Set application objects path explicitly.
        setApplicationInfoPaths(pkg, codePath, resPath);
        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
        // Note that we invoke the following method only if we are about to unpack an application
        PackageParser.Package scannedPkg = scanPackageLI(pkg, parseFlags, scanMode
        PackageParser.Package scannedPkg = scanPackageLI(pkg, parseFlags, scanMode
                | SCAN_UPDATE_SIGNATURE, currentTime, user);
                | SCAN_UPDATE_SIGNATURE, currentTime, user);
@@ -4395,6 +4398,7 @@ public class PackageManagerService extends IPackageManager.Stub {
            // the PkgSetting exists already and doesn't have to be created.
            // the PkgSetting exists already and doesn't have to be created.
            pkgSetting = mSettings.getPackageLPw(pkg, origPackage, realName, suid, destCodeFile,
            pkgSetting = mSettings.getPackageLPw(pkg, origPackage, realName, suid, destCodeFile,
                    destResourceFile, pkg.applicationInfo.nativeLibraryDir,
                    destResourceFile, pkg.applicationInfo.nativeLibraryDir,
                    pkg.applicationInfo.requiredCpuAbi,
                    pkg.applicationInfo.flags, user, false);
                    pkg.applicationInfo.flags, user, false);
            if (pkgSetting == null) {
            if (pkgSetting == null) {
                Slog.w(TAG, "Creating application package " + pkg.packageName + " failed");
                Slog.w(TAG, "Creating application package " + pkg.packageName + " failed");
@@ -4706,6 +4710,14 @@ public class PackageManagerService extends IPackageManager.Stub {
                                mLastScanError = PackageManager.INSTALL_FAILED_INTERNAL_ERROR;
                                mLastScanError = PackageManager.INSTALL_FAILED_INTERNAL_ERROR;
                                return null;
                                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) {
                        } catch (IOException e) {
                            Slog.e(TAG, "Unable to copy native libraries", e);
                            Slog.e(TAG, "Unable to copy native libraries", e);
                            mLastScanError = PackageManager.INSTALL_FAILED_INTERNAL_ERROR;
                            mLastScanError = PackageManager.INSTALL_FAILED_INTERNAL_ERROR;
+2 −2
Original line number Original line Diff line number Diff line
@@ -30,8 +30,8 @@ final class PackageSetting extends PackageSettingBase {
    SharedUserSetting sharedUser;
    SharedUserSetting sharedUser;


    PackageSetting(String name, String realName, File codePath, File resourcePath,
    PackageSetting(String name, String realName, File codePath, File resourcePath,
            String nativeLibraryPathString, int pVersionCode, int pkgFlags) {
            String nativeLibraryPathString, String requiredCpuAbiString, int pVersionCode, int pkgFlags) {
        super(name, realName, codePath, resourcePath, nativeLibraryPathString, pVersionCode,
        super(name, realName, codePath, resourcePath, nativeLibraryPathString, requiredCpuAbiString, pVersionCode,
                pkgFlags);
                pkgFlags);
    }
    }


Loading