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
This commit is contained in:
Christopher Tate
2021-09-08 10:34:55 -07:00
committed by Chris Tate
parent d06ba1aa9e
commit 0157327ba2

View File

@@ -947,9 +947,9 @@ final class ServiceRecord extends Binder implements ComponentName.WithComponentN
}
public void postNotification() {
final int appUid = appInfo.uid;
final int appPid = app.getPid();
if (isForeground && foregroundNoti != null) {
final int appUid = appInfo.uid;
final int appPid = app.getPid();
// Do asynchronous communication with notification manager to
// avoid deadlocks.
final String localPackageName = packageName;