From 655252edfeca39adca9c1e0cfd1ea6b5e80081bb Mon Sep 17 00:00:00 2001 From: Bernardo Rufino Date: Wed, 6 Jan 2021 09:30:30 +0000 Subject: [PATCH] Perform null check before updating originating tokens Turns out it's possible that when the callback is processed there is no process attached to the ServiceRecord despite it being allowed for bg activity starts "by start". This can happen for example if we call allowBgActivityStartsOnServiceStart() twice without a process attached. This was handled before ag/12559801, so also needs to be handled in the new code-path. Bug: 176813978 Test: atest BackgroundActivityLaunchTest Change-Id: I2024f5cb4da78a93c868a63e45c00567c20848ba --- .../java/com/android/server/am/ServiceRecord.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/services/core/java/com/android/server/am/ServiceRecord.java b/services/core/java/com/android/server/am/ServiceRecord.java index e129561b8bc52..d9c83da69b930 100644 --- a/services/core/java/com/android/server/am/ServiceRecord.java +++ b/services/core/java/com/android/server/am/ServiceRecord.java @@ -749,9 +749,15 @@ final class ServiceRecord extends Binder implements ComponentName.WithComponentN // There are other callbacks in the queue, let's just update the originating // token if (mIsAllowedBgActivityStartsByStart) { - mAppForAllowingBgActivityStartsByStart - .addOrUpdateAllowBackgroundActivityStartsToken( - this, getExclusiveOriginatingToken()); + // mAppForAllowingBgActivityStartsByStart can be null here for example + // if get 2 calls to allowBgActivityStartsOnServiceStart() without a + // process attached to this ServiceRecord, so we need to perform a null + // check here. + if (mAppForAllowingBgActivityStartsByStart != null) { + mAppForAllowingBgActivityStartsByStart + .addOrUpdateAllowBackgroundActivityStartsToken( + this, getExclusiveOriginatingToken()); + } } else { Slog.wtf(TAG, "Service callback to revoke bg activity starts by service "