Log.i(TAG, "Low on space, deleting oat files in an attempt to free up space: "
+ PackageManagerServiceUtils.packagesToString(others));
for (PackageParser.Package pkg : others) {
- deleteOatArtifactsOfPackage(pkg);
+ mPackageManagerService.deleteOatArtifactsOfPackage(pkg.packageName);
}
}
long spaceAvailableNow = getAvailableSpace();
return usableSpace - lowThreshold;
}
- private static String getOatDir(PackageParser.Package pkg) {
- if (!pkg.canHaveOatDir()) {
- return null;
- }
- File codePath = new File(pkg.codePath);
- if (codePath.isDirectory()) {
- return PackageDexOptimizer.getOatDir(codePath).getAbsolutePath();
- }
- return null;
- }
-
- private void deleteOatArtifactsOfPackage(PackageParser.Package pkg) {
- String[] instructionSets = getAppDexInstructionSets(pkg.applicationInfo);
- for (String codePath : pkg.getAllCodePaths()) {
- for (String isa : instructionSets) {
- try {
- mPackageManagerService.mInstaller.deleteOdex(codePath, isa, getOatDir(pkg));
- } catch (InstallerException e) {
- Log.e(TAG, "Failed deleting oat files for " + codePath, e);
- }
- }
- }
- }
-
/**
* Generate all dexopt commands for the given package.
*/
return mInstantAppRegistry.getInstantAppAndroidIdLPw(packageName, userId);
}
}
+
+ boolean canHaveOatDir(String packageName) {
+ synchronized (mPackages) {
+ PackageParser.Package p = mPackages.get(packageName);
+ if (p == null) {
+ return false;
+ }
+ return p.canHaveOatDir();
+ }
+ }
+
+ private String getOatDir(PackageParser.Package pkg) {
+ if (!pkg.canHaveOatDir()) {
+ return null;
+ }
+ File codePath = new File(pkg.codePath);
+ 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 PackageParser.Package pkg;
+ synchronized (mPackages) {
+ pkg = mPackages.get(packageName);
+ }
+ instructionSets = getAppDexInstructionSets(pkg.applicationInfo);
+ codePaths = pkg.getAllCodePaths();
+ oatDir = getOatDir(pkg);
+
+ 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);
+ }
+ }
+ }
+ }
}
interface PackageSender {