Skip to content

Commit f968bde

Browse files
Jing Jiandroid-build-team Robot
authored andcommitted
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 (cherry picked from commit ae5a219b955d63cbfcc15465d145a9303aafb807)
1 parent 7b82cbb commit f968bde

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

services/core/java/com/android/server/am/ActiveServices.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -935,7 +935,18 @@ void stopInBackgroundLocked(int uid) {
935935
void killMisbehavingService(ServiceRecord r,
936936
int appUid, int appPid, String localPackageName) {
937937
synchronized (mAm) {
938-
stopServiceLocked(r);
938+
if (!r.destroying) {
939+
// This service is still alive, stop it.
940+
stopServiceLocked(r);
941+
} else {
942+
// Check if there is another instance of it being started in parallel,
943+
// if so, stop that too to avoid spamming the system.
944+
final ServiceMap smap = getServiceMapLocked(r.userId);
945+
final ServiceRecord found = smap.mServicesByInstanceName.remove(r.instanceName);
946+
if (found != null) {
947+
stopServiceLocked(found);
948+
}
949+
}
939950
mAm.crashApplication(appUid, appPid, localPackageName, -1,
940951
"Bad notification for startForeground", true /*force*/);
941952
}

0 commit comments

Comments
 (0)