Merge "Migrate deleteOdex functionality to DexManager"
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -355,6 +355,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;
|
||||
@@ -25538,43 +25539,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.getCodePath());
|
||||
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) {
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* 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
services/core/java/com/android/server/pm/dex/ArtUtils.java
Normal file
64
services/core/java/com/android/server/pm/dex/ArtUtils.java
Normal file
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* 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.getCodePath());
|
||||
if (codePath.isDirectory()) {
|
||||
return PackageDexOptimizer.getOatDir(codePath).getAbsolutePath();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1015,6 +1015,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);
|
||||
|
||||
Reference in New Issue
Block a user