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

Commit 3a0f2df3 authored by Riddle Hsu's avatar Riddle Hsu
Browse files

Avoid potential NPE by accessing ActivityRecord on logger thread

The r.getPid() is "return app != null ? app.getPid() : 0;".
If it is not in lock, the field "app" could be cleared by other
thread, which causes NPE on "app.getPid()".

Also change other log field to use info snapshot which is thread safe.

Fix: 364131071
Flag: EXEMPT bugfix
Test: atest ActivityMetricsLaunchObserverTests#testLaunchState
Change-Id: I0249c72fefffcba8589bb79135484e7b050f61f8
parent 2f4e0476
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -838,12 +838,13 @@ class ActivityMetricsLogger {
        }

        if (android.app.Flags.appStartInfoTimestamps()) {
            final int pid = r.getPid();
            // Log here to match StatsD for time to first frame.
            mLoggerHandler.post(
                    () -> mSupervisor.mService.mWindowManager.mAmInternal.addStartInfoTimestamp(
                            ApplicationStartInfo.START_TIMESTAMP_FIRST_FRAME,
                            timestampNs, r.getUid(), r.getPid(),
                            info.mLastLaunchedActivity.mUserId));
                            timestampNs, infoSnapshot.applicationInfo.uid, pid,
                            infoSnapshot.userId));
        }

        return infoSnapshot;