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

Commit 065913b5 authored by Jiakai Zhang's avatar Jiakai Zhang
Browse files

Update InstallLocationUtils.calculateInstalledSize.

Before the change, the method called
DexMetadataHelper.getPackageDexMetadataSize, to get the DM size. It was
out-of-sync from ART, and prevents us from removing DexMetadataHelper, a
file for the legacy dexopt.

This CL uses a different way to calculate the size.

Bug: 258223472
Test: atest CtsPackageInstallTestCases
Flag: android.content.pm.alternative_for_dexopt_cleanup
Change-Id: I0cfa204c06110e0d2017737e4498782e47c46e3c
parent 4549869e
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -349,3 +349,11 @@ flag {
        purpose: PURPOSE_BUGFIX
    }
}

flag {
    name: "alternative_for_dexopt_cleanup"
    namespace: "art_cloud"
    description: "Flag guarding the alternative code path replacing the legacy dexopt code, to allow legacy dexopt cleanup."
    bug: "258223472"
    is_fixed_read_only: true
}
+26 −7
Original line number Diff line number Diff line
@@ -47,6 +47,10 @@ import libcore.io.IoUtils;
import java.io.File;
import java.io.FileDescriptor;
import java.io.IOException;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Objects;
import java.util.UUID;

@@ -445,6 +449,20 @@ public class InstallLocationUtils {
            String abiOverride) throws IOException {
        long sizeBytes = 0;

        if (android.content.pm.Flags.alternativeForDexoptCleanup()) {
            Path path = pkg.getPath() != null ? Paths.get(pkg.getPath()) : null;
            if (path == null || !Files.isDirectory(path)) { // monolithic
                sizeBytes += Files.size(Paths.get(pkg.getBaseApkPath()));
            } else { // cluster
                try (DirectoryStream<Path> stream = Files.newDirectoryStream(path)) {
                    for (Path child : stream) {
                        if (!Files.isDirectory(child)) {
                            sizeBytes += Files.size(child);
                        }
                    }
                }
            }
        } else {
            // Include raw APKs, and possibly unpacked resources
            for (String codePath : pkg.getAllApkPaths()) {
                final File codeFile = new File(codePath);
@@ -453,6 +471,7 @@ public class InstallLocationUtils {

            // Include raw dex metadata files
            sizeBytes += DexMetadataHelper.getPackageDexMetadataSize(pkg);
        }

        if (pkg.isExtractNativeLibs()) {
            // Include all relevant native code