summaryrefslogtreecommitdiff
path: root/cmds/pm
diff options
context:
space:
mode:
authorShunta Sato <Shunta.Sato@sonymobile.com>2016-06-28 09:29:19 +0900
committerTodd Kennedy <toddke@google.com>2016-10-11 06:33:22 -0700
commit4f26cb5a36487b3f5b497804faebe16241c15d54 (patch)
treea82c532a9243120d67e829ed622b90dff1c5e2c4 /cmds/pm
parent8999d5d8ce296a025bf65fb3d4c737b17b5eb612 (diff)
Fix: "adb install -s" adaptation for session based install
Internal implementation of "adb install" has been changed to session install. As a result '-s' option doesn't work. Size info is required when using '-s' option in session install. PackageHelper.fitsOnExternal() returns false and moving app to SD is failed when size info is not set. So set size info when '-s' option is used. And change identity on some method because shell doesn't have some permission to access to asec. Bug: 29932779 Author: Ryuki Nakamura <ryuki.x.nakamura@sonymobile.com> Change-Id: I65edcc0f01ceecaaba17792ad329791a9253d603
Diffstat (limited to 'cmds/pm')
-rw-r--r--cmds/pm/src/com/android/commands/pm/Pm.java22
1 files changed, 21 insertions, 1 deletions
diff --git a/cmds/pm/src/com/android/commands/pm/Pm.java b/cmds/pm/src/com/android/commands/pm/Pm.java
index 32a8088e9c4e..5f83d191a731 100644
--- a/cmds/pm/src/com/android/commands/pm/Pm.java
+++ b/cmds/pm/src/com/android/commands/pm/Pm.java
@@ -41,6 +41,10 @@ import android.content.pm.PackageInstaller;
import android.content.pm.PackageInstaller.SessionInfo;
import android.content.pm.PackageInstaller.SessionParams;
import android.content.pm.PackageManager;
+import android.content.pm.PackageParser;
+import android.content.pm.PackageParser.ApkLite;
+import android.content.pm.PackageParser.PackageLite;
+import android.content.pm.PackageParser.PackageParserException;
import android.content.pm.UserInfo;
import android.net.Uri;
import android.os.Binder;
@@ -362,11 +366,27 @@ public final class Pm {
*/
private int runInstall() throws RemoteException {
final InstallParams params = makeInstallParams();
+ final String inPath = nextArg();
+ 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;
+ }
+ }
+ }
+
final int sessionId = doCreateSession(params.sessionParams,
params.installerPackageName, params.userId);
try {
- final String inPath = nextArg();
if (inPath == null && params.sessionParams.sizeBytes == 0) {
System.err.println("Error: must either specify a package size or an APK file");
return 1;