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

Commit 18d9a495 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Migrate deleteOdex functionality to DexManager" into sc-dev

parents cd9b0864 72e090b8
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -780,7 +780,8 @@ public class PackageDexOptimizer {
        return getOatDir(codePath).getAbsolutePath();
    }

    static File getOatDir(File codePath) {
    /** Returns the oat dir for the given code path */
    public static File getOatDir(File codePath) {
        return new File(codePath, OAT_DIR_NAME);
    }

+2 −30
Original line number Diff line number Diff line
@@ -369,6 +369,7 @@ import com.android.server.pm.Installer.InstallerException;
import com.android.server.pm.Settings.DatabaseVersion;
import com.android.server.pm.Settings.VersionInfo;
import com.android.server.pm.dex.ArtManagerService;
import com.android.server.pm.dex.ArtUtils;
import com.android.server.pm.dex.DexManager;
import com.android.server.pm.dex.DexoptOptions;
import com.android.server.pm.dex.PackageDexUsage;
@@ -27525,43 +27526,14 @@ public class PackageManagerService extends IPackageManager.Stub
        }
    }
    private String getOatDir(AndroidPackage pkg, @NonNull PackageSetting pkgSetting) {
        if (!AndroidPackageUtils.canHaveOatDir(pkg,
                pkgSetting.getPkgState().isUpdatedSystemApp())) {
            return null;
        }
        File codePath = new File(pkg.getPath());
        if (codePath.isDirectory()) {
            return PackageDexOptimizer.getOatDir(codePath).getAbsolutePath();
        }
        return null;
    }
    void deleteOatArtifactsOfPackage(String packageName) {
        final String[] instructionSets;
        final List<String> codePaths;
        final String oatDir;
        final AndroidPackage pkg;
        final PackageSetting pkgSetting;
        synchronized (mLock) {
            pkg = mPackages.get(packageName);
            pkgSetting = mSettings.getPackageLPr(packageName);
        }
        instructionSets = getAppDexInstructionSets(
                AndroidPackageUtils.getPrimaryCpuAbi(pkg, pkgSetting),
                AndroidPackageUtils.getSecondaryCpuAbi(pkg, pkgSetting));
        codePaths = AndroidPackageUtils.getAllCodePaths(pkg);
        oatDir = getOatDir(pkg, pkgSetting);
        for (String codePath : codePaths) {
            for (String isa : instructionSets) {
                try {
                    mInstaller.deleteOdex(codePath, isa, oatDir);
                } catch (InstallerException e) {
                    Log.e(TAG, "Failed deleting oat files for " + codePath, e);
                }
            }
        }
        mDexManager.deleteOptimizedFiles(ArtUtils.createArtPackageInfo(pkg, pkgSetting));
    }
    Set<String> getUnusedPackages(long downgradeTimeThresholdMillis) {
+58 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.server.pm.dex;

import java.util.List;

/**
 * Holds package information relevant to ART use cases.
 */
public class ArtPackageInfo {
    private final String mPackageName;
    private final List<String> mInstructionSets;
    private final List<String> mCodePaths;
    // TODO: This should be computed on the fly in PackageDexOptimizer / DexManager, but the
    // logic is too complicated to do it in a single re-factoring.
    private final String mOatDir;

    public ArtPackageInfo(
            String packageName,
            List<String> instructionSets,
            List<String> codePaths,
            String oatDir) {
        mPackageName = packageName;
        mInstructionSets = instructionSets;
        mCodePaths = codePaths;
        mOatDir = oatDir;
    }

    public String getPackageName() {
        return mPackageName;
    }

    public List<String> getInstructionSets() {
        return mInstructionSets;
    }

    public List<String> getCodePaths() {
        return mCodePaths;
    }

    public String getOatDir() {
        return mOatDir;
    }
}
+64 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.server.pm.dex;

import static com.android.server.pm.InstructionSets.getAppDexInstructionSets;

import android.annotation.NonNull;

import com.android.server.pm.PackageDexOptimizer;
import com.android.server.pm.PackageSetting;
import com.android.server.pm.parsing.pkg.AndroidPackage;
import com.android.server.pm.parsing.pkg.AndroidPackageUtils;

import java.io.File;
import java.util.Arrays;

/**
 * Utility class to interface between PM and ART tooling (e.g. DexManager).
 */
public final class ArtUtils {
    private ArtUtils() {
    }

    /**
     * Create the ART-representation of package info.
     */
    public static ArtPackageInfo createArtPackageInfo(
            AndroidPackage pkg, PackageSetting pkgSetting) {
        return new ArtPackageInfo(
                pkg.getPackageName(),
                Arrays.asList(getAppDexInstructionSets(
                        AndroidPackageUtils.getPrimaryCpuAbi(pkg, pkgSetting),
                        AndroidPackageUtils.getSecondaryCpuAbi(pkg, pkgSetting))),
                AndroidPackageUtils.getAllCodePaths(pkg),
                getOatDir(pkg, pkgSetting));
    }

    private static String getOatDir(AndroidPackage pkg, @NonNull PackageSetting pkgSetting) {
        if (!AndroidPackageUtils.canHaveOatDir(pkg,
                pkgSetting.getPkgState().isUpdatedSystemApp())) {
            return null;
        }
        File codePath = new File(pkg.getPath());
        if (codePath.isDirectory()) {
            return PackageDexOptimizer.getOatDir(codePath).getAbsolutePath();
        }
        return null;
    }

}
+16 −0
Original line number Diff line number Diff line
@@ -1000,6 +1000,22 @@ public class DexManager {
        return isBtmCritical;
    }

    /**
     * Deletes all the optimizations files generated by ART.
     * @param packageInfo the package information.
     */
    public void deleteOptimizedFiles(ArtPackageInfo packageInfo) {
        for (String codePath : packageInfo.getCodePaths()) {
            for (String isa : packageInfo.getInstructionSets()) {
                try {
                    mInstaller.deleteOdex(codePath, isa, packageInfo.getOatDir());
                } catch (InstallerException e) {
                    Log.e(TAG, "Failed deleting oat files for " + codePath, e);
                }
            }
        }
    }

    public static class RegisterDexModuleResult {
        public RegisterDexModuleResult() {
            this(false, null);