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

Commit 0157327b authored by Christopher Tate's avatar Christopher Tate Committed by Chris Tate
Browse files

Access process fields only when valid

In some cases we can tear down ServiceRecord bookkeeping before its
hosting ProcessRecord has been established.  Make sure that we don't
attempt to reference ProcessRecord information unless we've already
established that it's available.  In this case, the service can't be in
the FGS state until the app's code has begun running and has called
startForeground(), so checking `isForeground` provides the guarantee.

Fixes: 197070543
Test: atest CtsAppTestCases:android.app.cts.ServiceTest
Change-Id: I429c31c7ea87625b380a1ed70b6a1d9afa45bdb3
parent d06ba1aa
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -947,9 +947,9 @@ final class ServiceRecord extends Binder implements ComponentName.WithComponentN
    }

    public void postNotification() {
        if (isForeground && foregroundNoti != null) {
            final int appUid = appInfo.uid;
            final int appPid = app.getPid();
        if (isForeground && foregroundNoti != null) {
            // Do asynchronous communication with notification manager to
            // avoid deadlocks.
            final String localPackageName = packageName;