Prevent sessions from resuming once boot is completed

This will prevent sessions from resuming when system server crashes or
restarted.

Bug: 158283778
Test: staged a session and crashed system server to verify session stays
      unchanged
Test: atest StagedInstallInternalTest
Test: atest StagedInstallTest
Change-Id: I99337ea2898cfdf2cc515819b4f5b5db4b038f31
Merged-In: I99337ea2898cfdf2cc515819b4f5b5db4b038f31
diff --git a/services/core/java/com/android/server/pm/StagingManager.java b/services/core/java/com/android/server/pm/StagingManager.java
index 5adab3e..ff578a6 100644
--- a/services/core/java/com/android/server/pm/StagingManager.java
+++ b/services/core/java/com/android/server/pm/StagingManager.java
@@ -44,6 +44,7 @@
 import android.os.PowerManager;
 import android.os.RemoteException;
 import android.os.ServiceManager;
+import android.os.SystemProperties;
 import android.util.Slog;
 import android.util.SparseArray;
 import android.util.apk.ApkSignatureVerifier;
@@ -657,6 +658,11 @@
     }
 
     private void checkStateAndResume(@NonNull PackageInstallerSession session) {
+        // Do not resume session if boot completed already
+        if (SystemProperties.getBoolean("sys.boot_completed", false)) {
+            return;
+        }
+
         if (!session.isCommitted()) {
             // Session hasn't been committed yet, ignore.
             return;