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

Commit b87a491d authored by Fyodor Kupolov's avatar Fyodor Kupolov
Browse files

[DO NOT MERGE] Only setSize if -s arg is specified

Calculate size of installed APKs only when INSTALL_EXTERNAL flag is set.
calculateInstalledSize is expensive and may take up to 20% of total
installation time.

Bug: 32180551
Bug: 29932779
Change-Id: I173d2b38820cc86cbfacecd1bacef57369d10af7
parent e9db00e3
Loading
Loading
Loading
Loading
+15 −9
Original line number Diff line number Diff line
@@ -367,9 +367,12 @@ public final class Pm {
    private int runInstall() throws RemoteException {
        final InstallParams params = makeInstallParams();
        final String inPath = nextArg();
        boolean installExternal =
                (params.sessionParams.installFlags & PackageManager.INSTALL_EXTERNAL) != 0;
        if (params.sessionParams.sizeBytes < 0 && inPath != null) {
            File file = new File(inPath);
            if (file.isFile()) {
                if (installExternal) {
                    try {
                        ApkLite baseApk = PackageParser.parseApkLite(file, 0);
                        PackageLite pkgLite = new PackageLite(null, baseApk, null, null, null);
@@ -380,6 +383,9 @@ public final class Pm {
                        System.err.println("Error: Failed to parse APK file : " + e);
                        return 1;
                    }
                } else {
                    params.sessionParams.setSize(file.length());
                }
            }
        }

+15 −8
Original line number Diff line number Diff line
@@ -143,18 +143,25 @@ class PackageManagerShellCommand extends ShellCommand {
        final PrintWriter pw = getOutPrintWriter();
        final InstallParams params = makeInstallParams();
        final String inPath = getNextArg();
        boolean installExternal =
                (params.sessionParams.installFlags & PackageManager.INSTALL_EXTERNAL) != 0;
        if (params.sessionParams.sizeBytes < 0 && inPath != null) {
            File file = new File(inPath);
            if (file.isFile()) {
                if (installExternal) {
                    try {
                        ApkLite baseApk = PackageParser.parseApkLite(file, 0);
                        PackageLite pkgLite = new PackageLite(null, baseApk, null, null, null);
                        params.sessionParams.setSize(
                            PackageHelper.calculateInstalledSize(pkgLite,false, params.sessionParams.abiOverride));
                                PackageHelper.calculateInstalledSize(pkgLite, false,
                                        params.sessionParams.abiOverride));
                    } catch (PackageParserException | IOException e) {
                        pw.println("Error: Failed to parse APK file : " + e);
                        return 1;
                    }
                } else {
                    params.sessionParams.setSize(file.length());
                }
            }
        }