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

Commit 3d44ed0d authored by David Brazdil's avatar David Brazdil
Browse files

Pass targetSdkVersion to installd

Dex2oat now accepts targetSdkVersion as a parameter to determine
whether ART should treat the app as "legacy" and allow or restrict
access to private APIs.

We also bump arguments of otapreopt to v4 to accommodate the new value.

Bug: 64382372
Test: manual
Change-Id: Iae3867325dfaf8deaba51626ab04b97ad797d3b6
parent f779d7e3
Loading
Loading
Loading
Loading
+3 −1
Original line number Original line Diff line number Diff line
@@ -572,10 +572,12 @@ public class ZygoteInit {
                final String seInfo = null;
                final String seInfo = null;
                final String classLoaderContext =
                final String classLoaderContext =
                        getSystemServerClassLoaderContext(classPathForElement);
                        getSystemServerClassLoaderContext(classPathForElement);
                final int targetSdkVersion = 0;  // SystemServer targets the system's SDK version
                try {
                try {
                    installd.dexopt(classPathElement, Process.SYSTEM_UID, packageName,
                    installd.dexopt(classPathElement, Process.SYSTEM_UID, packageName,
                            instructionSet, dexoptNeeded, outputPath, dexFlags, compilerFilter,
                            instructionSet, dexoptNeeded, outputPath, dexFlags, compilerFilter,
                            uuid, classLoaderContext, seInfo, false /* downgrade */);
                            uuid, classLoaderContext, seInfo, false /* downgrade */,
                            targetSdkVersion);
                } catch (RemoteException | ServiceSpecificException e) {
                } catch (RemoteException | ServiceSpecificException e) {
                    // Ignore (but log), we need this on the classpath for fallback mode.
                    // Ignore (but log), we need this on the classpath for fallback mode.
                    Log.w(TAG, "Failed compiling classpath element for system server: "
                    Log.w(TAG, "Failed compiling classpath element for system server: "
+3 −2
Original line number Original line Diff line number Diff line
@@ -281,13 +281,14 @@ public class Installer extends SystemService {
    public void dexopt(String apkPath, int uid, @Nullable String pkgName, String instructionSet,
    public void dexopt(String apkPath, int uid, @Nullable String pkgName, String instructionSet,
            int dexoptNeeded, @Nullable String outputPath, int dexFlags,
            int dexoptNeeded, @Nullable String outputPath, int dexFlags,
            String compilerFilter, @Nullable String volumeUuid, @Nullable String sharedLibraries,
            String compilerFilter, @Nullable String volumeUuid, @Nullable String sharedLibraries,
            @Nullable String seInfo, boolean downgrade)
            @Nullable String seInfo, boolean downgrade, int targetSdkVersion)
            throws InstallerException {
            throws InstallerException {
        assertValidInstructionSet(instructionSet);
        assertValidInstructionSet(instructionSet);
        if (!checkBeforeRemote()) return;
        if (!checkBeforeRemote()) return;
        try {
        try {
            mInstalld.dexopt(apkPath, uid, pkgName, instructionSet, dexoptNeeded, outputPath,
            mInstalld.dexopt(apkPath, uid, pkgName, instructionSet, dexoptNeeded, outputPath,
                    dexFlags, compilerFilter, volumeUuid, sharedLibraries, seInfo, downgrade);
                    dexFlags, compilerFilter, volumeUuid, sharedLibraries, seInfo, downgrade,
                    targetSdkVersion);
        } catch (Exception e) {
        } catch (Exception e) {
            throw InstallerException.from(e);
            throw InstallerException.from(e);
        }
        }
+5 −3
Original line number Original line Diff line number Diff line
@@ -260,12 +260,13 @@ public class OtaDexoptService extends IOtaDexopt.Stub {
            public void dexopt(String apkPath, int uid, @Nullable String pkgName,
            public void dexopt(String apkPath, int uid, @Nullable String pkgName,
                    String instructionSet, int dexoptNeeded, @Nullable String outputPath,
                    String instructionSet, int dexoptNeeded, @Nullable String outputPath,
                    int dexFlags, String compilerFilter, @Nullable String volumeUuid,
                    int dexFlags, String compilerFilter, @Nullable String volumeUuid,
                    @Nullable String sharedLibraries, @Nullable String seInfo, boolean downgrade)
                    @Nullable String sharedLibraries, @Nullable String seInfo, boolean downgrade,
                    int targetSdkVersion)
                    throws InstallerException {
                    throws InstallerException {
                final StringBuilder builder = new StringBuilder();
                final StringBuilder builder = new StringBuilder();


                // The version. Right now it's 3.
                // The version. Right now it's 4.
                builder.append("3 ");
                builder.append("4 ");


                builder.append("dexopt");
                builder.append("dexopt");


@@ -281,6 +282,7 @@ public class OtaDexoptService extends IOtaDexopt.Stub {
                encodeParameter(builder, sharedLibraries);
                encodeParameter(builder, sharedLibraries);
                encodeParameter(builder, seInfo);
                encodeParameter(builder, seInfo);
                encodeParameter(builder, downgrade);
                encodeParameter(builder, downgrade);
                encodeParameter(builder, targetSdkVersion);


                commands.add(builder.toString());
                commands.add(builder.toString());
            }
            }
+2 −2
Original line number Original line Diff line number Diff line
@@ -274,7 +274,7 @@ public class PackageDexOptimizer {
            // primary dex files.
            // primary dex files.
            mInstaller.dexopt(path, uid, pkg.packageName, isa, dexoptNeeded, oatDir, dexoptFlags,
            mInstaller.dexopt(path, uid, pkg.packageName, isa, dexoptNeeded, oatDir, dexoptFlags,
                    compilerFilter, pkg.volumeUuid, classLoaderContext, pkg.applicationInfo.seInfo,
                    compilerFilter, pkg.volumeUuid, classLoaderContext, pkg.applicationInfo.seInfo,
                    false /* downgrade*/);
                    false /* downgrade*/, pkg.applicationInfo.targetSdkVersion);


            if (packageStats != null) {
            if (packageStats != null) {
                long endTime = System.currentTimeMillis();
                long endTime = System.currentTimeMillis();
@@ -395,7 +395,7 @@ public class PackageDexOptimizer {
                mInstaller.dexopt(path, info.uid, info.packageName, isa, /*dexoptNeeded*/ 0,
                mInstaller.dexopt(path, info.uid, info.packageName, isa, /*dexoptNeeded*/ 0,
                        /*oatDir*/ null, dexoptFlags,
                        /*oatDir*/ null, dexoptFlags,
                        compilerFilter, info.volumeUuid, classLoaderContext, info.seInfoUser,
                        compilerFilter, info.volumeUuid, classLoaderContext, info.seInfoUser,
                        options.isDowngrade());
                        options.isDowngrade(), info.targetSdkVersion);
            }
            }


            return DEX_OPT_PERFORMED;
            return DEX_OPT_PERFORMED;