Fix NPE caused by orphaned child sessions

A null session will cause NPE in mSessionCreationComparator.

Bug: 207814360
Test: adb shell dumpsys package
Change-Id: I15f2848bc40edab2ef09f44a28b2df9e9ad27e78
This commit is contained in:
JW Wang
2021-11-26 15:53:07 +08:00
committed by Chun-Wei Wang
parent 61a741d8f8
commit b5345b5c30

View File

@@ -1461,8 +1461,9 @@ public class PackageInstallerService extends IPackageInstaller.Stub implements
private TreeMap<PackageInstallerSession, TreeSet<PackageInstallerSession>> mSessionMap;
private final Comparator<PackageInstallerSession> mSessionCreationComparator =
Comparator.comparingLong((PackageInstallerSession sess) -> sess.createdMillis)
.thenComparingInt(sess -> sess.sessionId);
Comparator.comparingLong(
(PackageInstallerSession sess) -> sess != null ? sess.createdMillis : -1)
.thenComparingInt(sess -> sess != null ? sess.sessionId : -1);
ParentChildSessionMap() {
mSessionMap = new TreeMap<>(mSessionCreationComparator);
@@ -1500,10 +1501,12 @@ public class PackageInstallerService extends IPackageInstaller.Stub implements
for (Map.Entry<PackageInstallerSession, TreeSet<PackageInstallerSession>> entry
: mSessionMap.entrySet()) {
PackageInstallerSession parentSession = entry.getKey();
pw.print(tag + " ");
parentSession.dump(pw);
pw.println();
pw.increaseIndent();
if (parentSession != null) {
pw.print(tag + " ");
parentSession.dump(pw);
pw.println();
pw.increaseIndent();
}
for (PackageInstallerSession childSession : entry.getValue()) {
pw.print(tag + " Child ");