summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Song Chun Fan <schfan@google.com> 2025-03-06 16:55:51 -0800
committer Song Chun Fan <schfan@google.com> 2025-03-07 11:37:01 -0800
commite38fa24e5738513d721ec2d9fd2dd00f32e327c1 (patch)
tree9e207ae104783f0a9f71ae4659da5d677b1a9236
parent089efb6b1d10178082a0c65a8b38c5c9bd49b675 (diff)
[pm] block install/uninstall shell commands before boot_completed
We've observed in automated testing environments that occasionally a shell command to install/uninstall packages can be sent to PackageManagerService right after it is started during boot, but before the rest of the system (art service, broadcast controller, etc) is ready. The system crashes when PackageManagerService tries to process such install/uninstall requests and invokes other services that are not ready. This CL prevents that by checking if the system has finished booting before processing the shell commands. BUG: 370100381 FIXES: 370100381 BUG: 369993707 FIXES: 369993707 Test: manually install/uninstall via shell commands during boot and observe "Error: device is still booting." FLAG: EXEMPT bug fix Change-Id: I74759ceaacf59a99507256572b9ef1680a942e8d
-rw-r--r--services/core/java/com/android/server/pm/PackageManagerShellCommand.java14
1 files changed, 14 insertions, 0 deletions
diff --git a/services/core/java/com/android/server/pm/PackageManagerShellCommand.java b/services/core/java/com/android/server/pm/PackageManagerShellCommand.java
index cf598e89c988..62264dd73795 100644
--- a/services/core/java/com/android/server/pm/PackageManagerShellCommand.java
+++ b/services/core/java/com/android/server/pm/PackageManagerShellCommand.java
@@ -96,6 +96,7 @@ import android.os.ServiceManager;
import android.os.ServiceSpecificException;
import android.os.ShellCommand;
import android.os.SystemClock;
+import android.os.SystemProperties;
import android.os.Trace;
import android.os.UserHandle;
import android.os.UserManager;
@@ -1564,6 +1565,12 @@ class PackageManagerShellCommand extends ShellCommand {
private int doRunInstall(final InstallParams params) throws RemoteException {
final PrintWriter pw = getOutPrintWriter();
+ // Do not allow app installation if boot has not completed already
+ if (!SystemProperties.getBoolean("sys.boot_completed", false)) {
+ pw.println("Error: device is still booting.");
+ return 1;
+ }
+
int requestUserId = params.userId;
if (requestUserId != UserHandle.USER_ALL && requestUserId != UserHandle.USER_CURRENT) {
UserManagerInternal umi =
@@ -2174,6 +2181,13 @@ class PackageManagerShellCommand extends ShellCommand {
private int runUninstall() throws RemoteException {
final PrintWriter pw = getOutPrintWriter();
+
+ // Do not allow app uninstallation if boot has not completed already
+ if (!SystemProperties.getBoolean("sys.boot_completed", false)) {
+ pw.println("Error: device is still booting.");
+ return 1;
+ }
+
int flags = 0;
int userId = UserHandle.USER_ALL;
long versionCode = PackageManager.VERSION_CODE_HIGHEST;