maxrave-dev / maxrave-dev/SimpMusic
Crashes after Foreground Service Denial
Nobody has claimed this yet.
- Dominant language
- Kotlin
- Stars
- 11.4k
- Forks
- 599
- Avg merge
- 3d 18h
- Merged PRs (30d)
- 7
Description
SimpMusic crashes when Android 16 denies FGS promotion
6 crashes in one day
Description
SimpMusic (com.maxrave.simpmusic, UID 10265) repeatedly crashes on Android 16 with ForegroundServiceStartNotAllowedException when SimpleMediaService is denied a background foreground-service (FGS) start. This appears related to #2071, which reports the same exception for SimpleMediaService on Android 16.
Six crash events were captured across one day:
09:32:18 — first crash
15:59:00 — second crash
17:16:05–06 — process crashes, Android restarts the service, restarted process crashes again
18:00:00–02 — same pattern; restarted process crashes ~360 ms after being spawned
18:32:01–18:33:31 — five processes crash in sequence, with Android's automatic restart backoff climbing 1s → 4s → 16s → 64s → 256s
19:52:15–16 — crash inside a process that had been running normally for over an hour, during a foreground-state stop/restart; the auto-restarted process crashes again almost immediately
So this isn't just one process crashing twice. In the 17:16, 18:00, and 18:32 sequences, Android spawns a new process for SimpleMediaService after the previous one dies, and the new process hits the same denial.
The 19:52 event is different: the initial crash occurred during an otherwise normal playback session, before the subsequent Android service restart.
Evidence
Every event follows the same basic pattern.
Android denies the FGS start:
Background started FGS: Disallowed [callingPackage: com.maxrave.simpmusic; callingUid: 10265;
uidState: SVC ; code:DENIED; targetSdkVersion:36; callerTargetSdkVersion:36]
The app receives this as an uncaught exception that kills the process:
FATAL EXCEPTION: main
android.app.ForegroundServiceStartNotAllowedException: Service.startForeground() not allowed
due to mAllowStartForeground false: service com.maxrave.simpmusic/com.maxrave.media3.service.SimpleMediaService
at android.app.Service.startForeground(Service.java:862)
Android then reschedules the service:
Scheduling restart of crashed service com.maxrave.simpmusic/com.maxrave.media3.service.SimpleMediaService in 1000ms for start-requested
This same stack trace recurs at:
09:32:18.147 — PID 4567
15:59:00.873 — PID 27999
17:16:06.867 — PID 3219
18:00:02.409 — PID 6492
Only the PID and timestamp change.
18:00 restart sequence
The second process is denied almost immediately after Android starts it:
18:00:02.037 Start proc 6492 ... for service SimpleMediaService
18:00:02.398 Background started FGS: Disallowed
18:00:02.404 CustomActivityOnCrash: App has crashed
18:00:02.409 FATAL EXCEPTION: main [PID 6492]
That is approximately 361 ms from process creation to the FGS denial.
18:32 restart sequence
Five consecutive processes were denied and crashed, with Android's restart backoff increasing:
| Process | Started | FGS denied | Died | Next restart |
|---|---|---|---|---|
| 9178 | — | 18:32:01.024 | 18:32:01.271 | 1s |
| 10089 | 18:32:02.303 | 18:32:02.695 | 18:32:02.706 | 4s |
| 10209 | 18:32:09.698 | 18:32:10.171 | 18:32:10.268 | 16s |
| 10300 | 18:32:26.302 | 18:32:26.639 | 18:32:26.726 | 64s |
| 10629 | 18:33:30.767 | 18:33:31.108 | 18:33:31.191 | 256s |
Representative log:
Process com.maxrave.simpmusic (pid 9178) has died: cch SVC
Scheduling restart of crashed service ... in 1000ms for start-requested
Start proc 10089:com.maxrave.simpmusic/u0a265 for service {.../SimpleMediaService}
Background started FGS: Disallowed [... code:DENIED; ...]
FATAL EXCEPTION: main
android.app.ForegroundServiceStartNotAllowedException: ...
Process com.maxrave.simpmusic (pid 10089) has died: svc SVC
Scheduling restart of crashed service ... in 4000ms for start-requested
The backoff continued beyond this window: PID 11016 was also denied at 18:37:47, with the next scheduled restart increasing to 1024000 ms (~17 minutes).
19:52 event — crash during normal operation
Unlike the restart loops above, this crash occurred during an otherwise normal playback session. PID 11231 had been running since approximately 18:40, with startForegroundCount reaching 9 during normal playback state changes.
At 19:52, Media3 tears down the foreground state:
19:52:14.6xx setFgsIfNoSessionIsLinkedToNotification: record=.../SimpleMediaService/24
19:52:14.6xx setFgsInactiveLocked: pkg=com.maxrave.simpmusic uid=10265 notification=2026
19:52:14.6xx [...SimpleMediaService,1,PROC_STATE_TOP,...,STOP_FOREGROUND,2]
About 70 ms later, the app attempts to re-promote the service:
19:52:14.7xx Background started FGS: Disallowed [... code:DENIED; startForegroundCount:9]
19:52:14.7xx ForegroundServiceStartNotAllowedException: Service.startForeground() not allowed
19:52:15.381 Process com.maxrave.simpmusic (pid 11231) has died: cch SVC
19:52:15.4xx Scheduling restart of crashed service ... in 1000ms
Android then starts PID 22817, which is denied and hits the same exception almost immediately:
19:52:16.469 Start proc 22817:com.maxrave.simpmusic/u0a265 for service {.../SimpleMediaService}
19:52:17.1xx Background started FGS: Disallowed [... code:DENIED; startForegroundCount:9]
19:52:17.1xx ForegroundServiceStartNotAllowedException: ... (x3)
This shows that the failure can also occur during an otherwise normal playback session, before the subsequent Android service restart.
Possible root cause / theory
The logs establish that Android is denying the FGS promotion and that the resulting ForegroundServiceStartNotAllowedException is uncaught and kills the process.
The setFgsIfNoSessionIsLinkedToNotification / setFgsInactiveLocked / STOP_FOREGROUND sequence immediately preceding the 19:52 failure suggests a connection to Media3's (SimpleMediaService extends MediaSessionService) internal foreground-state handling, rather than only external service restarts.
A possible sequence is:
Media3/SimpMusic
→ foreground state stopped
→ service attempts to re-promote to foreground
→ Android 16 denies the FGS start
→ uncaught ForegroundServiceStartNotAllowedException
→ process dies
→ Android restarts the service
→ same failure can occur again
The logs do not conclusively establish whether Media3 is missing an eligibility check, SimpMusic is invoking the service at the wrong time, or another lifecycle condition is involved. That would require source tracing.
What the logs do establish is that the FGS denial is propagating as an uncaught exception rather than being handled as a recoverable state transition.
Expected behavior
An FGS denial (ForegroundServiceStartNotAllowedException) should not be allowed to kill the process.
Possible handling could include:
Catch/defer the failed foreground promotion.
Wait until FGS promotion is permitted.
Avoid immediately retrying a start that is expected to fail.
Surface an error/state indication instead of crashing.
Handle Media3's internal foreground-state transitions, not only system-triggered restarts after a crash.
This would also address the 19:52 case, where the failure occurred during an otherwise normal playback session.
Environment
Android: 16
Target SDK: 36
SimpMusic: V2.1.0
Package:
com.maxrave.simpmusicUID: 10265
Service:
com.maxrave.simpmusic/com.maxrave.media3.service.SimpleMediaServiceRelated issue: #2071
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing SimpleMediaService, which extends Media3's MediaSessionService, through foreground-state transitions around the Android 16 denial shown in the attached logcat. Reproduce the denial on Android 16 with target SDK 36 and verify that failed foreground promotion no longer produces an uncaught exception or process crash during service restart or normal playback.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, kotlin
- Domain
- mobile-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100