NPE happens when there is an orphaned session which we've
tried to prevent in all cases.

Log an error message if this situation happens.

Bug: 227342978
Test: atest CtsRootPackageInstallerHostTestCases
Change-Id: Ia21323926bd9db1a6f05461904deb45b4c3dd0bc
(cherry picked from commit 07e31dfb1e)
Merged-In: Ia21323926bd9db1a6f05461904deb45b4c3dd0bc
This commit is contained in:
JW Wang
2022-03-31 10:06:06 +08:00
committed by Songchun Fan
parent 6923c0d102
commit f562aadd77

View File

@@ -332,7 +332,10 @@ public class PackageInstallerService extends IPackageInstaller.Stub implements
// Their staging dirs will be removed too // Their staging dirs will be removed too
PackageInstallerSession root = !session.hasParentSessionId() PackageInstallerSession root = !session.hasParentSessionId()
? session : mSessions.get(session.getParentSessionId()); ? session : mSessions.get(session.getParentSessionId());
if (!root.isDestroyed() && if (root == null) {
Slog.e(TAG, "freeStageDirs: found an orphaned session: "
+ session.sessionId + " parent=" + session.getParentSessionId());
} else if (!root.isDestroyed() &&
(!root.isStaged() || (root.isStaged() && root.isStagedSessionReady()))) (!root.isStaged() || (root.isStaged() && root.isStagedSessionReady())))
{ {
root.abandon(); root.abandon();