Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b5345b5c authored by JW Wang's avatar JW Wang Committed by Chun-Wei Wang
Browse files

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
parent 61a741d8
Loading
Loading
Loading
Loading
+9 −6
Original line number Diff line number Diff line
@@ -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();
                if (parentSession != null) {
                    pw.print(tag + " ");
                    parentSession.dump(pw);
                    pw.println();
                    pw.increaseIndent();
                }

                for (PackageInstallerSession childSession : entry.getValue()) {
                    pw.print(tag + " Child ");