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

Commit eaefe680 authored by Yisroel Forta's avatar Yisroel Forta
Browse files

Fix AppStartInfo crash on null in progress record

From bug linked, the in progress record can be null and cause a crash. The only path for a null in progress record I can find is when records load is in progress, so handle that case explicitly. Additionally, handle null potential in all accesses, even though this should not be possible anymore.

Test: presubmit as I don't have a specific repro
Bug: 328353697
Change-Id: If79a185d6a17d4c505dd1849e089ac26d3c88209
parent 68c7299b
Loading
Loading
Loading
Loading
+47 −18
Original line number Diff line number Diff line
@@ -210,11 +210,17 @@ public final class AppStartInfoTracker {
            if (!mEnabled) {
                return;
            }
            if (!mInProgRecords.containsKey(id)) {
            int index = mInProgRecords.indexOfKey(id);
            if (index < 0) {
                return;
            }
            mInProgRecords.get(id).setStartupState(ApplicationStartInfo.STARTUP_STATE_ERROR);
            mInProgRecords.remove(id);
            ApplicationStartInfo info = mInProgRecords.valueAt(index);
            if (info == null) {
                mInProgRecords.removeAt(index);
                return;
            }
            info.setStartupState(ApplicationStartInfo.STARTUP_STATE_ERROR);
            mInProgRecords.removeAt(index);
        }
    }

@@ -223,16 +229,24 @@ public final class AppStartInfoTracker {
            if (!mEnabled) {
                return;
            }
            if (!mInProgRecords.containsKey(id)) {
            int index = mInProgRecords.indexOfKey(id);
            if (index < 0) {
                return;
            }
            ApplicationStartInfo info = mInProgRecords.valueAt(index);
            if (info == null || app == null) {
                mInProgRecords.removeAt(index);
                return;
            }
            if (app != null) {
                ApplicationStartInfo info = mInProgRecords.get(id);
            info.setStartType((int) temperature);
            addBaseFieldsFromProcessRecord(info, app);
                mInProgRecords.put(id, addStartInfoLocked(info));
            ApplicationStartInfo newInfo = addStartInfoLocked(info);
            if (newInfo == null) {
                // newInfo can be null if records are added before load from storage is
                // complete. In this case the newly added record will be lost.
                mInProgRecords.removeAt(index);
            } else {
                mInProgRecords.remove(id);
                mInProgRecords.setValueAt(index, newInfo);
            }
        }
    }
@@ -242,12 +256,17 @@ public final class AppStartInfoTracker {
            if (!mEnabled) {
                return;
            }
            if (!mInProgRecords.containsKey(id)) {
            int index = mInProgRecords.indexOfKey(id);
            if (index < 0) {
                return;
            }
            ApplicationStartInfo info = mInProgRecords.valueAt(index);
            if (info == null) {
                mInProgRecords.removeAt(index);
                return;
            }
            ApplicationStartInfo info = mInProgRecords.get(id);
            info.setStartupState(ApplicationStartInfo.STARTUP_STATE_ERROR);
            mInProgRecords.remove(id);
            mInProgRecords.removeAt(index);
        }
    }

@@ -257,10 +276,15 @@ public final class AppStartInfoTracker {
            if (!mEnabled) {
                return;
            }
            if (!mInProgRecords.containsKey(id)) {
            int index = mInProgRecords.indexOfKey(id);
            if (index < 0) {
                return;
            }
            ApplicationStartInfo info = mInProgRecords.valueAt(index);
            if (info == null) {
                mInProgRecords.removeAt(index);
                return;
            }
            ApplicationStartInfo info = mInProgRecords.get(id);
            info.setStartupState(ApplicationStartInfo.STARTUP_STATE_FIRST_FRAME_DRAWN);
            info.setLaunchMode(launchMode);
            checkCompletenessAndCallback(info);
@@ -272,13 +296,18 @@ public final class AppStartInfoTracker {
            if (!mEnabled) {
                return;
            }
            if (!mInProgRecords.containsKey(id)) {
            int index = mInProgRecords.indexOfKey(id);
            if (index < 0) {
                return;
            }
            ApplicationStartInfo info = mInProgRecords.valueAt(index);
            if (info == null) {
                mInProgRecords.removeAt(index);
                return;
            }
            ApplicationStartInfo info = mInProgRecords.get(id);
            info.addStartupTimestamp(ApplicationStartInfo.START_TIMESTAMP_FULLY_DRAWN,
                    timestampNanos);
            mInProgRecords.remove(id);
            mInProgRecords.removeAt(index);
        }
    }