Merge "Fixed NPE in package installer session." into qt-qpr1-dev

This commit is contained in:
Rhed Jao
2020-02-06 05:35:06 +00:00
committed by Android (Google) Code Review
2 changed files with 14 additions and 4 deletions

View File

@@ -258,12 +258,15 @@ public class PackageInstallerService extends IPackageInstaller.Stub implements
}
// Don't hold mSessions lock when calling restoreSession, since it might trigger an APK
// atomic install which needs to query sessions, which requires lock on mSessions.
boolean isDeviceUpgrading = mPm.isDeviceUpgrading();
for (PackageInstallerSession session : stagedSessionsToRestore) {
if (mPm.isDeviceUpgrading() && !session.isStagedAndInTerminalState()) {
if (!session.isStagedAndInTerminalState() && session.hasParentSessionId()
&& getSession(session.getParentSessionId()) == null) {
session.setStagedSessionFailed(SessionInfo.STAGED_SESSION_ACTIVATION_FAILED,
"Build fingerprint has changed");
"An orphan staged session " + session.sessionId + " is found, "
+ "parent " + session.getParentSessionId() + " is missing");
}
mStagingManager.restoreSession(session);
mStagingManager.restoreSession(session, isDeviceUpgrading);
}
// Broadcasts are not sent while we restore sessions on boot, since no processes would be
// ready to listen to them. From now on, we greedily assume that broadcasts requests are

View File

@@ -619,7 +619,7 @@ public class StagingManager {
return false;
}
void restoreSession(@NonNull PackageInstallerSession session) {
void restoreSession(@NonNull PackageInstallerSession session, boolean isDeviceUpgrading) {
PackageInstallerSession sessionToResume = session;
synchronized (mStagedSessions) {
mStagedSessions.append(session.sessionId, session);
@@ -636,6 +636,13 @@ public class StagingManager {
}
}
}
// The preconditions used during pre-reboot verification might have changed when device
// is upgrading. Updated staged sessions to activation failed before we resume the session.
if (isDeviceUpgrading && !sessionToResume.isStagedAndInTerminalState()) {
sessionToResume.setStagedSessionFailed(SessionInfo.STAGED_SESSION_ACTIVATION_FAILED,
"Build fingerprint has changed");
return;
}
checkStateAndResume(sessionToResume);
}