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

Commit 1b46093d authored by Narayan Kamath's avatar Narayan Kamath
Browse files

Adjust instruction sets for shared UID apps.

Since shared UID apps are run in the same process,
we'll need to make sure they're compiled for the same
instruction set.

This change implements the recompilation of apps that
don't have any ABI constraints.

Apps that *do* have ABI constraints are harder to deal
with, since we'll need to rescan them to figure out the
full list of ABIs they support and then re-extract the
native libraries from these apps once we find an ABI we
can use throughout.

(cherry picked from commit 85703d58af1dac692d7d83c03220e45ab2a5aded)

Change-Id: I8311a683468488cc7e30381965487a3d391609ae
parent 2a9a0471
Loading
Loading
Loading
Loading
+60 −0
Original line number Diff line number Diff line
@@ -1476,6 +1476,12 @@ public class PackageManagerService extends IPackageManager.Stub {
            // the correct library paths.
            updateAllSharedLibrariesLPw();
            for (SharedUserSetting setting : mSettings.getAllSharedUsersLPw()) {
                adjustCpuAbisForSharedUserLPw(setting.packages, true /* do dexopt */,
                        false /* force dexopt */, false /* defer dexopt */);
            }
            EventLog.writeEvent(EventLogTags.BOOT_PROGRESS_PMS_SCAN_END,
                    SystemClock.uptimeMillis());
            Slog.i(TAG, "Time to scan packages: "
@@ -4968,6 +4974,12 @@ public class PackageManagerService extends IPackageManager.Stub {
        // writer
        synchronized (mPackages) {
            if ((scanMode&SCAN_BOOTING) == 0 && pkgSetting.sharedUser != null) {
                // We don't do this here during boot because we can do it all
                // at once after scanning all existing packages.
                adjustCpuAbisForSharedUserLPw(pkgSetting.sharedUser.packages,
                        true, forceDex, (scanMode & SCAN_DEFER_DEX) != 0);
            }
            // We don't expect installation to fail beyond this point,
            if ((scanMode&SCAN_MONITOR) != 0) {
                mAppDirs.put(pkg.mPath, pkg);
@@ -5311,6 +5323,54 @@ public class PackageManagerService extends IPackageManager.Stub {
        return pkg;
    }
    public void adjustCpuAbisForSharedUserLPw(Set<PackageSetting> packagesForUser,
            boolean doDexOpt, boolean forceDexOpt, boolean deferDexOpt) {
        String requiredInstructionSet = null;
        PackageSetting requirer = null;
        for (PackageSetting ps : packagesForUser) {
            if (ps.requiredCpuAbiString != null) {
                final String instructionSet = VMRuntime.getInstructionSet(ps.requiredCpuAbiString);
                if (requiredInstructionSet != null) {
                    if (!instructionSet.equals(requiredInstructionSet)) {
                        // We have a mismatch between instruction sets (say arm vs arm64).
                        //
                        // TODO: We should rescan all the packages in a shared UID to check if
                        // they do contain shared libs for other ABIs in addition to the ones we've
                        // already extracted. For example, the package might contain both arm64-v8a
                        // and armeabi-v7a shared libs, and we'd have chosen arm64-v8a on 64 bit
                        // devices.
                        String errorMessage = "Instruction set mismatch, " + requirer.pkg.packageName
                                + " requires " + requiredInstructionSet + " whereas " + ps.pkg.packageName
                                + " requires " + instructionSet;
                        Slog.e(TAG, errorMessage);
                        reportSettingsProblem(Log.WARN, errorMessage);
                        // Give up, don't bother making any other changes to the package settings.
                        return;
                    }
                } else {
                    requiredInstructionSet = instructionSet;
                    requirer = ps;
                }
            }
        }
        if (requiredInstructionSet != null) {
            for (PackageSetting ps : packagesForUser) {
                if (ps.requiredCpuAbiString == null) {
                    ps.requiredCpuAbiString = requirer.requiredCpuAbiString;
                    ps.pkg.applicationInfo.requiredCpuAbi = requirer.requiredCpuAbiString;
                    Slog.i(TAG, "Adjusting ABI for : " + ps.pkg.packageName + " to " + ps.requiredCpuAbiString);
                    if (doDexOpt) {
                        performDexOptLI(ps.pkg, forceDexOpt, deferDexOpt, true);
                        mInstaller.rmdex(ps.codePathString, getPreferredInstructionSet());
                    }
                }
            }
        }
    }
    private void setUpCustomResolverActivity(PackageParser.Package pkg) {
        synchronized (mPackages) {
            mResolverReplaced = true;
+6 −0
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import com.android.internal.util.JournaledFile;
import com.android.internal.util.XmlUtils;
import com.android.server.pm.PackageManagerService.DumpState;

import java.util.Collection;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlSerializer;
@@ -262,6 +263,11 @@ final class Settings {
        return s;
    }

    Collection<SharedUserSetting> getAllSharedUsersLPw() {
        return mSharedUsers.values();
    }


    boolean disableSystemPackageLPw(String name) {
        final PackageSetting p = mPackages.get(name);
        if(p == null) {