From cf573cdedee2e5e3e07d4c17c872c98c32a47636 Mon Sep 17 00:00:00 2001 From: Nikita Ioffe Date: Thu, 20 Jul 2023 00:05:49 +0100 Subject: Add --non-staged flag The child change will change the behaviour of --force-non-staged flag to perform a rebootless APEX update even for APEXes that don't support rebootless updates. This behaviour will be used to speed up development cycle for teams that have their code packaged in an APEX. However, some developers (and some tests) assume that adb install --force-non-staged will fail for APEXes that don't support rebootless updates. In order to preserve such behaviour, this change introduces a new --non-staged flag. Bug: 290750901 Test: adb install --non-staged apex-supporting-rebootless-update Test: verify install was successful Test: adb install --non-staged com.android.virt.apex Test: verify install failed with "does not support non-staged update" Merged-In: I27ac000207e1b6ec39890bd382b3751fbb62e265 Change-Id: I27ac000207e1b6ec39890bd382b3751fbb62e265 --- .../server/pm/PackageManagerShellCommand.java | 24 +++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/services/core/java/com/android/server/pm/PackageManagerShellCommand.java b/services/core/java/com/android/server/pm/PackageManagerShellCommand.java index e043c90f4f14..a096f330689c 100644 --- a/services/core/java/com/android/server/pm/PackageManagerShellCommand.java +++ b/services/core/java/com/android/server/pm/PackageManagerShellCommand.java @@ -3211,6 +3211,13 @@ class PackageManagerShellCommand extends ShellCommand { // Set package source to other by default sessionParams.setPackageSource(PackageInstaller.PACKAGE_SOURCE_OTHER); + // Encodes one of the states: + // 1. Install request explicitly specified --staged, then value will be true. + // 2. Install request explicitly specified --non-staged, then value will be false. + // 3. Install request did not specify either --staged or --non-staged, then for APEX + // installs the value will be true, and for apk installs it will be false. + Boolean staged = null; + String opt; boolean replaceExisting = true; boolean forceNonStaged = false; @@ -3319,7 +3326,6 @@ class PackageManagerShellCommand extends ShellCommand { break; case "--apex": sessionParams.setInstallAsApex(); - sessionParams.setStaged(); break; case "--force-non-staged": forceNonStaged = true; @@ -3328,7 +3334,10 @@ class PackageManagerShellCommand extends ShellCommand { sessionParams.setMultiPackage(); break; case "--staged": - sessionParams.setStaged(); + staged = true; + break; + case "--non-staged": + staged = false; break; case "--force-queryable": sessionParams.setForceQueryable(); @@ -3363,11 +3372,16 @@ class PackageManagerShellCommand extends ShellCommand { throw new IllegalArgumentException("Unknown option " + opt); } } + if (staged == null) { + staged = (sessionParams.installFlags & PackageManager.INSTALL_APEX) != 0; + } if (replaceExisting) { sessionParams.installFlags |= PackageManager.INSTALL_REPLACE_EXISTING; } if (forceNonStaged) { sessionParams.isStaged = false; + } else if (staged) { + sessionParams.setStaged(); } return params; } @@ -4231,7 +4245,8 @@ class PackageManagerShellCommand extends ShellCommand { pw.println(" [--preload] [--instant] [--full] [--dont-kill]"); pw.println(" [--enable-rollback]"); pw.println(" [--force-uuid internal|UUID] [--pkg PACKAGE] [-S BYTES]"); - pw.println(" [--apex] [--force-non-staged] [--staged-ready-timeout TIMEOUT]"); + pw.println(" [--apex] [--non-staged] [--force-non-staged]"); + pw.println(" [--staged-ready-timeout TIMEOUT]"); pw.println(" [PATH [SPLIT...]|-]"); pw.println(" Install an application. Must provide the apk data to install, either as"); pw.println(" file path(s) or '-' to read from stdin. Options are:"); @@ -4260,6 +4275,9 @@ class PackageManagerShellCommand extends ShellCommand { pw.println(" --update-ownership: request the update ownership enforcement"); pw.println(" --force-uuid: force install on to disk volume with given UUID"); pw.println(" --apex: install an .apex file, not an .apk"); + pw.println(" --non-staged: explicitly set this installation to be non-staged."); + pw.println(" This flag is only useful for APEX installs that are implicitly"); + pw.println(" assumed to be staged."); pw.println(" --force-non-staged: force the installation to run under a non-staged"); pw.println(" session, which may complete without requiring a reboot"); pw.println(" --staged-ready-timeout: By default, staged sessions wait " -- cgit v1.2.3-59-g8ed1b