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

Commit 69f51063 authored by Jiakai Zhang's avatar Jiakai Zhang
Browse files

Ignore I/O errors in the new code path of calculateInstalledSize.

There's a subtle difference between Java's `File.length` and
`Files.size`. The former returns 0 on I/O errors, while the latter
throws IOException when an I/O error occurs.

When an app uses PM shell commands to install an APK, it may place the
APK in its own data directory, where system_server doesn't have access
but installd does. In this case, the old code path of
calculateInstalledSize returns 0 and the installation still succeeds. To
achieve parity, this CL changes the new code path to use `File.length`
too.

Bug: 258223472
Test: atest CtsPackageInstallTestCases
Test: atest NexusLauncherImageTests:com.google.android.apps.nexuslauncher.imagecomparison.AppTitleContrastPillImageTest
Flag: android.content.pm.alternative_for_dexopt_cleanup
Change-Id: If041f831a95f1822624ee0ad556fcafd6676abb4
parent 549084ff
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -452,12 +452,12 @@ public class InstallLocationUtils {
        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()));
                sizeBytes += new File(pkg.getBaseApkPath()).length();
            } else { // cluster
                try (DirectoryStream<Path> stream = Files.newDirectoryStream(path)) {
                    for (Path child : stream) {
                        if (!Files.isDirectory(child)) {
                            sizeBytes += Files.size(child);
                            sizeBytes += child.toFile().length();
                        }
                    }
                }