OSDN Git Service

[DO NOT MERGE] Only setSize if -s arg is specified
authorFyodor Kupolov <fkupolov@google.com>
Thu, 27 Oct 2016 01:36:57 +0000 (18:36 -0700)
committerFyodor Kupolov <fkupolov@google.com>
Thu, 27 Oct 2016 22:29:41 +0000 (15:29 -0700)
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

cmds/pm/src/com/android/commands/pm/Pm.java
services/core/java/com/android/server/pm/PackageManagerShellCommand.java

index 5f83d19..1b4eda8 100644 (file)
@@ -367,18 +367,24 @@ 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()) {
-                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));
-                } catch (PackageParserException | IOException e) {
-                    System.err.println("Error: Failed to parse APK file : " + e);
-                    return 1;
+                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));
+                    } catch (PackageParserException | IOException e) {
+                        System.err.println("Error: Failed to parse APK file : " + e);
+                        return 1;
+                    }
+                } else {
+                    params.sessionParams.setSize(file.length());
                 }
             }
         }
index e18d4e0..3bfa6b8 100644 (file)
@@ -143,17 +143,24 @@ 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()) {
-                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));
-                } catch (PackageParserException | IOException e) {
-                    pw.println("Error: Failed to parse APK file : " + e);
-                    return 1;
+                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));
+                    } catch (PackageParserException | IOException e) {
+                        pw.println("Error: Failed to parse APK file : " + e);
+                        return 1;
+                    }
+                } else {
+                    params.sessionParams.setSize(file.length());
                 }
             }
         }