Closed Bug 1802620 Opened 1 year ago Closed 1 year ago

Crash in [@ android.app.ForegroundServiceStartNotAllowedException: at android.app.ForegroundServiceStartNotAllowedException$1.createFromParcel(ForegroundServiceStartNotAllowedException.java)]

Categories

(Fenix :: Crash Reporting, defect, P1)

Unspecified
Android

Tracking

(relnote-firefox 111+, firefox107 wontfix, firefox108 wontfix, firefox109 wontfix, firefox110 wontfix, firefox111 fixed)

RESOLVED FIXED
111 Branch
Tracking Status
relnote-firefox --- 111+
firefox107 --- wontfix
firefox108 --- wontfix
firefox109 --- wontfix
firefox110 --- wontfix
firefox111 --- fixed

People

(Reporter: cpeterson, Assigned: boek)

References

(Blocks 1 open bug)

Details

(Keywords: crash, topcrash, Whiteboard: [geckoview:m110] [geckoview:m111])

Crash Data

Crash report: https://crash-stats.mozilla.org/report/index/6410e7cb-ce07-4e04-9cfc-cac910221123

Java stack trace:

android.app.ForegroundServiceStartNotAllowedException: Service.startForeground() not allowed due to mAllowStartForeground false: service org.mozilla.fenix/.media.MediaSessionService
	at android.app.ForegroundServiceStartNotAllowedException$1.createFromParcel(ForegroundServiceStartNotAllowedException.java:54)
	at android.app.ForegroundServiceStartNotAllowedException$1.createFromParcel(ForegroundServiceStartNotAllowedException.java:50)
	at android.os.Parcel.readParcelableInternal(Parcel.java:4801)
	at android.os.Parcel.readValue(Parcel.java:4558)
	at android.os.Parcel.readValue(Parcel.java:4341)
	at android.os.Parcel.-$$Nest$mreadValue(Unknown Source:0)
	at android.os.Parcel$LazyValue.apply(Parcel.java:4436)
	at android.os.Parcel$LazyValue.apply(Parcel.java:4395)
	at android.os.BaseBundle.getValueAt(BaseBundle.java:394)
	at android.os.BaseBundle.getValue(BaseBundle.java:374)
	at android.os.BaseBundle.getValue(BaseBundle.java:357)
	at android.os.BaseBundle.get(BaseBundle.java:693)
	at android.os.BaseBundle.getSerializable(BaseBundle.java:1474)
	at android.os.Bundle.getSerializable(Bundle.java:1162)
	at mozilla.components.support.utils.ext.BundleKt.getSerializableCompat(Bundle.kt:7)
	at mozilla.components.lib.crash.Crash$Companion.fromIntent(Crash.kt:44)
	at mozilla.components.lib.crash.prompt.CrashReporterActivity$crash$2.invoke(CrashReporterActivity.kt:12)
	at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:21)
	at mozilla.components.lib.crash.prompt.CrashReporterActivity.onCreate(CrashReporterActivity.kt:3)
	at android.app.Activity.performCreate(Activity.java:8395)
	at android.app.Activity.performCreate(Activity.java:8374)
	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1403)
	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3837)
	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4006)
	at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:111)
	at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
	at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2466)
	at android.os.Handler.dispatchMessage(Handler.java:106)
	at android.os.Looper.loopOnce(Looper.java:240)
	at android.os.Looper.loop(Looper.java:351)
	at android.app.ActivityThread.main(ActivityThread.java:8321)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:584)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1012)

This looks like an exception in the crash reporter itself:

	at mozilla.components.lib.crash.Crash$Companion.fromIntent(Crash.kt:44)
	at mozilla.components.lib.crash.prompt.CrashReporterActivity$crash$2.invoke(CrashReporterActivity.kt:12)

This crash spiked starting around 2022-07-28.

Severity: -- → S2
Component: General → Crash Reporting

Jeff says ForegroundServiceStartNotAllowedException was added in Android API 31.

android.app.ForegroundServiceStartNotAllowedException: Service.startForeground() not allowed due to mAllowStartForeground false: service org.mozilla.fenix/.media.MediaSessionService

Why is the exception complaining about the Fenix MediaSessionService? Was that the source of the crash the crash reporter was trying to report?

Could this be related Roger made some crash reporter changes in July?

https://github.com/mozilla-mobile/fenix/issues/25223
https://github.com/mozilla-mobile/fenix/issues/26080

Priority: -- → P2
Whiteboard: [geckoview:m110]

The bug is linked to a topcrash signature, which matches the following criterion:

  • Top 10 AArch64 and ARM crashes on release

For more information, please visit auto_nag documentation.

Keywords: topcrash
Assignee: nobody → jboek
Status: NEW → ASSIGNED
Priority: P2 → P1

After some investigation I found out that the stack trace for this crash gets lost in the serialization/deserialization process in the crash reporter

It only writes the message, not the stacktrace to the Parcel. When we submit the crash it recreates the trace with the stack from the crash reporter.

I was able to reproduce this crash by playing a song on Soundcloud, backgrounding the app and toggling play/pause from the notification widget. Once the current song playing finishes it will toggle media playing in MediaSessionServiceDelegate which will restart the service. This will give us a real stack trace:

Uncaught exception handled: 
android.app.ForegroundServiceStartNotAllowedException: Service.startForeground() not allowed due to mAllowStartForeground false: service org.mozilla.firefox/org.mozilla.fenix.media.MediaSessionService
	at android.app.ForegroundServiceStartNotAllowedException$1.createFromParcel(ForegroundServiceStartNotAllowedException.java:54)
	at android.app.ForegroundServiceStartNotAllowedException$1.createFromParcel(ForegroundServiceStartNotAllowedException.java:50)
	at android.os.Parcel.readParcelableInternal(Parcel.java:4784)
	at android.os.Parcel.readParcelable(Parcel.java:4752)
	at android.os.Parcel.createExceptionOrNull(Parcel.java:3018)
	at android.os.Parcel.createException(Parcel.java:3007)
	at android.os.Parcel.readException(Parcel.java:2990)
	at android.os.Parcel.readException(Parcel.java:2932)
	at android.app.IActivityManager$Stub$Proxy.setServiceForeground(IActivityManager.java:6978)
	at android.app.Service.startForeground(Service.java:743)
	at mozilla.components.feature.media.service.MediaSessionServiceDelegate$startForeground$1.invokeSuspend(MediaSessionServiceDelegate.kt:186)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
	at kotlinx.coroutines.internal.ScopeCoroutine.afterResume(Scopes.kt:33)
	at kotlinx.coroutines.AbstractCoroutine.resumeWith(AbstractCoroutine.kt:102)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:46)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104)
	at android.os.Handler.handleCallback(Handler.java:942)
	at android.os.Handler.dispatchMessage(Handler.java:99)
	at android.os.Looper.loopOnce(Looper.java:226)
	at android.os.Looper.loop(Looper.java:313)
	at android.app.ActivityThread.main(ActivityThread.java:8741)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)
	Suppressed: kotlinx.coroutines.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@d9d2d47, Dispatchers.Main]

When I add android:foregroundServiceType="mediaPlayback" to the Service in the app manifest I was no longer able to reproduce the crash. I'm not sure if this is the right fix.

(In reply to Jeff Boek [:boek] from comment #4)

I was able to reproduce this crash by playing a song on Soundcloud, backgrounding the app and toggling play/pause from the notification widget. Once the current song playing finishes it will toggle media playing in MediaSessionServiceDelegate which will restart the service. This will give us a real stack trace:

Do we have other Fenix or AC services that might be affected and need a similar fix?

(In reply to Chris Peterson [:cpeterson] from comment #5)

(In reply to Jeff Boek [:boek] from comment #4)

I was able to reproduce this crash by playing a song on Soundcloud, backgrounding the app and toggling play/pause from the notification widget. Once the current song playing finishes it will toggle media playing in MediaSessionServiceDelegate which will restart the service. This will give us a real stack trace:

Do we have other Fenix or AC services that might be affected and need a similar fix?

I looked through the other services that we have and nothing is jumping out at me. But since the stack trace is getting erased it's hard to rule out. I think we should also add our own error handling to this case to make it easier to determine if there are other culprits.

Jeff has a PR, but there are still open questions.

https://github.com/mozilla-mobile/firefox-android/pull/505

111

Whiteboard: [geckoview:m110] → [geckoview:m110] [geckoview:m111]
Rank: 110
Status: ASSIGNED → RESOLVED
Closed: 1 year ago
Resolution: --- → FIXED
Target Milestone: --- → 111 Branch

Jeff, should we uplift your ForegroundServiceStartNotAllowedException fix to Beta 110? Was this a bug in the MediaSessionService or the crash reporter itself?

Flags: needinfo?(jboek)

(In reply to Chris Peterson [:cpeterson] from comment #9)

Jeff, should we uplift your ForegroundServiceStartNotAllowedException fix to Beta 110? Was this a bug in the MediaSessionService or the crash reporter itself?

It was a crash in MediaSessionService. I think giving it time to bake into 111 would be good.

Flags: needinfo?(jboek)

Release Note Request (optional, but appreciated)
[Why is this notable]: Fixed crash with known steps
[Affects Firefox for Android]: only
[Suggested wording]: Already added to the release notes
[Links (documentation, blog post, etc)]:

relnote-firefox: --- → ?
Depends on: 1834130
No longer depends on: 1834130
See Also: → 1834130
Blocks: 1834647
You need to log in before you can comment on or make changes to this bug.