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

Commit a7bf2a21 authored by Nicolas Geoffray's avatar Nicolas Geoffray Committed by Gerrit Code Review
Browse files

Merge "Move code around for deleting oat artifacts."

parents 107899c5 575697a5
Loading
Loading
Loading
Loading
+1 −25
Original line number Original line Diff line number Diff line
@@ -152,7 +152,7 @@ public class OtaDexoptService extends IOtaDexopt.Stub {
            Log.i(TAG, "Low on space, deleting oat files in an attempt to free up space: "
            Log.i(TAG, "Low on space, deleting oat files in an attempt to free up space: "
                    + PackageManagerServiceUtils.packagesToString(others));
                    + PackageManagerServiceUtils.packagesToString(others));
            for (PackageParser.Package pkg : others) {
            for (PackageParser.Package pkg : others) {
                deleteOatArtifactsOfPackage(pkg);
                mPackageManagerService.deleteOatArtifactsOfPackage(pkg.packageName);
            }
            }
        }
        }
        long spaceAvailableNow = getAvailableSpace();
        long spaceAvailableNow = getAvailableSpace();
@@ -242,30 +242,6 @@ public class OtaDexoptService extends IOtaDexopt.Stub {
        return usableSpace - lowThreshold;
        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.
     * Generate all dexopt commands for the given package.
     */
     */
+44 −0
Original line number Original line Diff line number Diff line
@@ -24878,6 +24878,50 @@ Slog.v(TAG, ":: stepped forward, applying functor at tag " + parser.getName());
            return mInstantAppRegistry.getInstantAppAndroidIdLPw(packageName, userId);
            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 {
interface PackageSender {