summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Jing Ji <jji@google.com> 2021-06-15 11:44:23 -0700
committer Jing Ji <jji@google.com> 2021-06-15 11:44:23 -0700
commitae5a219b955d63cbfcc15465d145a9303aafb807 (patch)
tree44d0cb6d0fd724180f766051aa97dd936413d072
parentaa9c6c2de6b6cf5228f8e95bdd43825ce19ad56e (diff)
Validate the ServiceRecord state while handling misbehaving FGS
Fix a race condition where the previous misbehaving FGS's notifcation is being posted, but that FGS's being stopped, and meanwhile a new FGS is coming up, the system would get confused and results in IllegalStateException. Bug: 182160371 Test: atest CtsAppTestCases:ServiceTest Change-Id: If18e1d7ba88aef693349b82dc6e70f7d98c68665 Merged-In: If18e1d7ba88aef693349b82dc6e70f7d98c68665
-rw-r--r--services/core/java/com/android/server/am/ActiveServices.java13
1 files changed, 12 insertions, 1 deletions
diff --git a/services/core/java/com/android/server/am/ActiveServices.java b/services/core/java/com/android/server/am/ActiveServices.java
index 1062e141060f..5abb87cedc71 100644
--- a/services/core/java/com/android/server/am/ActiveServices.java
+++ b/services/core/java/com/android/server/am/ActiveServices.java
@@ -935,7 +935,18 @@ public final class ActiveServices {
void killMisbehavingService(ServiceRecord r,
int appUid, int appPid, String localPackageName) {
synchronized (mAm) {
- stopServiceLocked(r);
+ if (!r.destroying) {
+ // This service is still alive, stop it.
+ stopServiceLocked(r);
+ } else {
+ // Check if there is another instance of it being started in parallel,
+ // if so, stop that too to avoid spamming the system.
+ final ServiceMap smap = getServiceMapLocked(r.userId);
+ final ServiceRecord found = smap.mServicesByInstanceName.remove(r.instanceName);
+ if (found != null) {
+ stopServiceLocked(found);
+ }
+ }
mAm.crashApplication(appUid, appPid, localPackageName, -1,
"Bad notification for startForeground", true /*force*/);
}