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

Commit 83de0d3a authored by Jiakai Zhang's avatar Jiakai Zhang Committed by Android (Google) Code Review
Browse files

Merge changes Ief7e3044,Ia64b81a4,I15ad14ed,Ie0494441 into main

* changes:
  Remove DexManager.
  Remove `mChangedAbiCodePath` from `ScanResult`.
  Remove the `instructionSets` parameter from `cleanUpResources`.
  Remove `mIsolated` from Installer.
parents e85ae8cb ec09ad29
Loading
Loading
Loading
Loading
+4 −14
Original line number Diff line number Diff line
@@ -23,20 +23,15 @@ import java.io.File;
final class CleanUpArgs {
    @NonNull
    private final String mPackageName;
    @NonNull
    private final File mCodeFile;
    @NonNull
    private final String[] mInstructionSets;
    @NonNull private final File mCodeFile;

    /**
     * Create args that describe an existing installed package. Typically used
     * when cleaning up old installs.
     * Create args that describe an existing installed package. Typically used when cleaning up old
     * installs.
     */
    CleanUpArgs(@NonNull String packageName, @NonNull String codePath,
                @NonNull String[] instructionSets) {
    CleanUpArgs(@NonNull String packageName, @NonNull String codePath) {
        mPackageName = packageName;
        mCodeFile = new File(codePath);
        mInstructionSets = instructionSets;
    }

    @NonNull
@@ -54,9 +49,4 @@ final class CleanUpArgs {
    String getCodePath() {
        return mCodeFile.getAbsolutePath();
    }

    @NonNull
    String[] getInstructionSets() {
        return mInstructionSets;
    }
}
+3 −6
Original line number Diff line number Diff line
@@ -26,7 +26,6 @@ import static android.content.pm.PackageManager.MATCH_KNOWN_PACKAGES;
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
import static android.os.UserHandle.USER_ALL;

import static com.android.server.pm.InstructionSets.getAppDexInstructionSets;
import static com.android.server.pm.PackageManagerService.DEBUG_COMPRESSION;
import static com.android.server.pm.PackageManagerService.DEBUG_REMOVE;
import static com.android.server.pm.PackageManagerService.EMPTY_INT_ARRAY;
@@ -285,8 +284,8 @@ final class DeletePackageHelper {
        // other processes clean up before deleting resources.
        try (PackageManagerTracedLock installLock = mPm.mInstallLock.acquireLock()) {
            if (info.mArgs != null) {
                mRemovePackageHelper.cleanUpResources(info.mArgs.getPackageName(),
                        info.mArgs.getCodeFile(), info.mArgs.getInstructionSets());
                mRemovePackageHelper.cleanUpResources(
                        info.mArgs.getPackageName(), info.mArgs.getCodeFile());
            }

            boolean reEnableStub = false;
@@ -580,9 +579,7 @@ final class DeletePackageHelper {

        // Delete application code and resources only for parent packages
        if (deleteCodeAndResources) {
            outInfo.mArgs = new CleanUpArgs(ps.getName(),
                    ps.getPathString(), getAppDexInstructionSets(
                            ps.getPrimaryCpuAbiLegacy(), ps.getSecondaryCpuAbiLegacy()));
            outInfo.mArgs = new CleanUpArgs(ps.getName(), ps.getPathString());
            if (DEBUG_SD_INSTALL) Slog.i(TAG, "args=" + outInfo.mArgs);
        }
    }
+50 −39
Original line number Diff line number Diff line
@@ -62,6 +62,7 @@ import android.text.TextUtils;
import android.util.ArraySet;
import android.util.Log;
import android.util.Slog;
import android.util.jar.StrictJarFile;

import com.android.internal.logging.MetricsLogger;
import com.android.internal.util.FrameworkStatsLog;
@@ -75,7 +76,7 @@ import com.android.server.art.model.ArtFlags;
import com.android.server.art.model.DexoptParams;
import com.android.server.art.model.DexoptResult;
import com.android.server.pinner.PinnerService;
import com.android.server.pm.dex.DexManager;
import com.android.server.pm.dex.InstallScenarioHelper;
import com.android.server.pm.dex.DexoptOptions;
import com.android.server.pm.local.PackageManagerLocalImpl;
import com.android.server.pm.pkg.AndroidPackage;
@@ -83,6 +84,7 @@ import com.android.server.pm.pkg.PackageState;
import com.android.server.pm.pkg.PackageStateInternal;

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
@@ -91,6 +93,7 @@ import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
@@ -98,6 +101,7 @@ import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.function.Predicate;
import java.util.zip.ZipEntry;

/**
 * Helper class for dex optimization operations in PackageManagerService.
@@ -113,6 +117,7 @@ public final class DexOptHelper {
    private static boolean sArtManagerLocalIsInitialized = false;

    private final PackageManagerService mPm;
    private final InstallScenarioHelper mInstallScenarioHelper;

    // Start time for the boot dexopt in performPackageDexOptUpgradeIfNeeded when ART Service is
    // used, to make it available to the onDexoptDone callback.
@@ -125,6 +130,7 @@ public final class DexOptHelper {

    DexOptHelper(PackageManagerService pm) {
        mPm = pm;
        mInstallScenarioHelper = new InstallScenarioHelper(mPm.mContext);
    }

    /**
@@ -396,8 +402,7 @@ public final class DexOptHelper {
    }

    /** Returns DexoptOptions by the given InstallRequest. */
    private static DexoptOptions getDexoptOptionsByInstallRequest(
            InstallRequest installRequest, DexManager dexManager) {
    private DexoptOptions getDexoptOptionsByInstallRequest(InstallRequest installRequest) {
        final PackageSetting ps = installRequest.getScannedPackageSetting();
        final String packageName = ps.getPackageName();
        final boolean isBackupOrRestore =
@@ -409,7 +414,7 @@ public final class DexOptHelper {
                | (isBackupOrRestore ? DexoptOptions.DEXOPT_FOR_RESTORE : 0);
        // Compute the compilation reason from the installation scenario.
        final int compilationReason =
                dexManager.getCompilationReasonForInstallScenario(
                mInstallScenarioHelper.getCompilationReasonForInstallScenario(
                        installRequest.getInstallScenario());
        final AndroidPackage pkg = ps.getPkg();
        var options = new DexoptOptions(packageName, compilationReason, dexoptFlags);
@@ -421,39 +426,8 @@ public final class DexOptHelper {
        return options;
    }

    /** Perform dexopt if needed for the installation */
    static void performDexoptIfNeeded(
            InstallRequest installRequest,
            DexManager dexManager,
            PackageManagerTracedLock.RawLock installLock) {
        if (!shouldCallArtService(installRequest)) {
            return;
        }

        // dexopt can take long, and ArtService doesn't require installd, so we release the lock
        // here and re-acquire the lock after dexopt is finished.
        if (installLock != null) {
            installLock.unlock();
        }
        try {
            Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "dexopt");
            DexoptOptions dexoptOptions =
                    getDexoptOptionsByInstallRequest(installRequest, dexManager);
            // Don't fail application installs if the dexopt step fails.
            DexoptResult dexOptResult =
                    DexOptHelper.dexoptPackageUsingArtService(installRequest, dexoptOptions);
            installRequest.onDexoptFinished(dexOptResult);
        } finally {
            Trace.traceEnd(TRACE_TAG_PACKAGE_MANAGER);
            if (installLock != null) {
                installLock.lock();
            }
        }
    }

    /** Same as above, but runs asynchronously. */
    static CompletableFuture<Void> performDexoptIfNeededAsync(
            InstallRequest installRequest, DexManager dexManager) {
    /** Perform dexopt asynchronously if needed for the installation. */
    CompletableFuture<Void> performDexoptIfNeededAsync(InstallRequest installRequest) {
        if (!shouldCallArtService(installRequest)) {
            return CompletableFuture.completedFuture(null);
        }
@@ -463,8 +437,7 @@ public final class DexOptHelper {
                            try {
                                Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "dexopt");
                                DexoptOptions dexoptOptions =
                                        getDexoptOptionsByInstallRequest(
                                                installRequest, dexManager);
                                        getDexoptOptionsByInstallRequest(installRequest);
                                // Don't fail application installs if the dexopt step fails.
                                // TODO(b/393076925): Make this async in ART Service.
                                DexoptResult dexOptResult =
@@ -543,6 +516,44 @@ public final class DexOptHelper {
        return !instantApp && pkg != null && !isApex && performDexOptForRollback;
    }

    /**
     * Returns true if the archive located at {@code fileName} has uncompressed dex file that can be
     * directly mapped.
     */
    public static boolean checkUncompressedDexInApk(String fileName) {
        StrictJarFile jarFile = null;
        try {
            jarFile = new StrictJarFile(fileName,
                    false /*verify*/, false /*signatureSchemeRollbackProtectionsEnforced*/);
            Iterator<ZipEntry> it = jarFile.iterator();
            boolean allCorrect = true;
            while (it.hasNext()) {
                ZipEntry entry = it.next();
                if (entry.getName().endsWith(".dex")) {
                    if (entry.getMethod() != ZipEntry.STORED) {
                        allCorrect = false;
                        Slog.w(TAG, "APK " + fileName + " has compressed dex code " +
                                entry.getName());
                    } else if ((entry.getDataOffset() & 0x3) != 0) {
                        allCorrect = false;
                        Slog.w(TAG, "APK " + fileName + " has unaligned dex code " +
                                entry.getName());
                    }
                }
            }
            return allCorrect;
        } catch (IOException ignore) {
            Slog.wtf(TAG, "Error when parsing APK " + fileName);
            return false;
        } finally {
            try {
                if (jarFile != null) {
                    jarFile.close();
                }
            } catch (IOException ignore) {}
        }
    }

    private static class StagedApexObserver extends IStagedApexObserver.Stub {
        private final @NonNull ArtManagerLocal mArtManager;

+9 −23
Original line number Diff line number Diff line
@@ -48,7 +48,6 @@ import static android.os.storage.StorageManager.FLAG_STORAGE_DE;
import static android.os.storage.StorageManager.FLAG_STORAGE_EXTERNAL;

import static com.android.server.pm.InitAppsHelper.ScanParams;
import static com.android.server.pm.InstructionSets.getAppDexInstructionSets;
import static com.android.server.pm.PackageManagerException.INTERNAL_ERROR_ARCHIVE_NO_INSTALLER_TITLE;
import static com.android.server.pm.PackageManagerService.APP_METADATA_FILE_NAME;
import static com.android.server.pm.PackageManagerService.DEBUG_COMPRESSION;
@@ -176,7 +175,6 @@ import com.android.internal.util.ArrayUtils;
import com.android.internal.util.CollectionUtils;
import com.android.server.EventLogTags;
import com.android.server.criticalevents.CriticalEventLog;
import com.android.server.pm.dex.DexManager;
import com.android.server.pm.parsing.PackageCacher;
import com.android.server.pm.parsing.pkg.AndroidPackageUtils;
import com.android.server.pm.permission.Permission;
@@ -223,7 +221,6 @@ final class InstallPackageHelper {
    private final DeletePackageHelper mDeletePackageHelper;
    private final IncrementalManager mIncrementalManager;
    private final ApexManager mApexManager;
    private final DexManager mDexManager;
    private final Context mContext;
    private final PackageAbiHelper mPackageAbiHelper;
    private final SharedLibrariesImpl mSharedLibraries;
@@ -252,7 +249,6 @@ final class InstallPackageHelper {
        mDeletePackageHelper = deletePackageHelper;
        mIncrementalManager = pm.mInjector.getIncrementalManager();
        mApexManager = pm.mInjector.getApexManager();
        mDexManager = pm.mInjector.getDexManager();
        mContext = pm.mInjector.getContext();
        mPackageAbiHelper = pm.mInjector.getAbiHelper();
        mSharedLibraries = pm.mInjector.getSharedLibrariesImpl();
@@ -1224,7 +1220,7 @@ final class InstallPackageHelper {
            request.setKeepArtProfile(true);

            CompletableFuture<Void> future =
                    DexOptHelper.performDexoptIfNeededAsync(request, mDexManager);
                    mPm.getDexOptHelper().performDexoptIfNeededAsync(request);
            completableFutures.add(future);
            request.onWaitDexoptStarted();
        }
@@ -2468,12 +2464,8 @@ final class InstallPackageHelper {
                        // We didn't need to disable the .apk as a current system package,
                        // which means we are replacing another update that is already
                        // installed.  We need to make sure to delete the older one's .apk.
                        installRequest.getRemovedInfo().mArgs = new CleanUpArgs(
                                packageName,
                                oldPackage.getPath(),
                                getAppDexInstructionSets(
                                        deletedPkgSetting.getPrimaryCpuAbi(),
                                        deletedPkgSetting.getSecondaryCpuAbi()));
                        installRequest.getRemovedInfo().mArgs =
                                new CleanUpArgs(packageName, oldPackage.getPath());
                    } else {
                        installRequest.getRemovedInfo().mArgs = null;
                    }
@@ -3088,8 +3080,7 @@ final class InstallPackageHelper {
            request.setReturnMessage("Package was removed before install could complete.");

            // Remove the update failed package's older resources safely now
            mRemovePackageHelper.cleanUpResources(packageName, request.getOldCodeFile(),
                    request.getOldInstructionSet());
            mRemovePackageHelper.cleanUpResources(packageName, request.getOldCodeFile());
            mPm.notifyInstallObserver(request);
            return;
        }
@@ -3178,8 +3169,7 @@ final class InstallPackageHelper {
                                packageName, pkgSetting.getPath(), pkgSetting.getOldPaths());
                    }
                } else {
                    mRemovePackageHelper.cleanUpResources(packageName, args.getCodeFile(),
                            args.getInstructionSets());
                    mRemovePackageHelper.cleanUpResources(packageName, args.getCodeFile());
                }
            } else {
                // Force a gc to clear up things. Ask for a background one, it's fine to go on
@@ -4422,10 +4412,8 @@ final class InstallPackageHelper {
                            + "; " + pkgSetting.getPathString()
                            + " --> " + parsedPackage.getPath());

            mRemovePackageHelper.cleanUpResources(pkgSetting.getPackageName(),
                    new File(pkgSetting.getPathString()),
                    getAppDexInstructionSets(pkgSetting.getPrimaryCpuAbiLegacy(),
                            pkgSetting.getSecondaryCpuAbiLegacy()));
            mRemovePackageHelper.cleanUpResources(
                    pkgSetting.getPackageName(), new File(pkgSetting.getPathString()));
            synchronized (mPm.mLock) {
                mPm.mSettings.enableSystemPackageLPw(pkgSetting.getPackageName());
            }
@@ -4528,10 +4516,8 @@ final class InstallPackageHelper {
                                + parsedPackage.getLongVersionCode()
                                + "; " + pkgSetting.getPathString() + " --> "
                                + parsedPackage.getPath());
                mRemovePackageHelper.cleanUpResources(pkgSetting.getPackageName(),
                        new File(pkgSetting.getPathString()),
                        getAppDexInstructionSets(
                                pkgSetting.getPrimaryCpuAbiLegacy(), pkgSetting.getSecondaryCpuAbiLegacy()));
                mRemovePackageHelper.cleanUpResources(
                        pkgSetting.getPackageName(), new File(pkgSetting.getPathString()));
            } else {
                // The application on /system is older than the application on /data. Hide
                // the application on /system and the version on /data will be scanned later
+0 −12
Original line number Diff line number Diff line
@@ -336,12 +336,6 @@ final class InstallRequest {
                ? mRemovedInfo.mArgs.getCodeFile() : null;
    }

    @Nullable
    public String[] getOldInstructionSet() {
        return (mRemovedInfo != null && mRemovedInfo.mArgs != null)
                ? mRemovedInfo.mArgs.getInstructionSets() : null;
    }

    public UserHandle getUser() {
        return new UserHandle(mUserId);
    }
@@ -600,12 +594,6 @@ final class InstallRequest {
        return mScanResult.mRequest.mRealPkgName;
    }

    @Nullable
    public List<String> getChangedAbiCodePath() {
        assertScanResultExists();
        return mScanResult.mChangedAbiCodePath;
    }

    public boolean isApplicationEnabledSettingPersistent() {
        return mInstallArgs == null ? false : mInstallArgs.mApplicationEnabledSettingPersistent;
    }
Loading