From 0157327ba2ae94df049474928f982c78044f0f48 Mon Sep 17 00:00:00 2001 From: Christopher Tate Date: Wed, 8 Sep 2021 10:34:55 -0700 Subject: [PATCH] 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 --- services/core/java/com/android/server/am/ServiceRecord.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/core/java/com/android/server/am/ServiceRecord.java b/services/core/java/com/android/server/am/ServiceRecord.java index 97ed0a38fabe5..3e59eeac1d4e2 100644 --- a/services/core/java/com/android/server/am/ServiceRecord.java +++ b/services/core/java/com/android/server/am/ServiceRecord.java @@ -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;