element-hq / element-hq/element-android
Cannot start foreground service after `BOOT_COMPLETED`
- Dominant language
- Kotlin
- Stars
- 3.7k
- Forks
- 917
- PR merge metrics
- No merged PRs in 30d
Description
### Steps to reproduce
Set the "Notification method" to "Background synchronization" from "Settings -> Notifications". This will start a foreground service (with a corresponding notification) that keeps Element running in the background to check for new messages.
### Outcome
#### What did you expect?
When rebooting the phone, the foreground service should restart automatically, so I keep receiving notifications. This worked fine on Android 14 and previous versions.
#### What happened instead?
Ever since I updated to Android 15, element crashes on startup and is unable to setup the "Background synchronization" foreground service. Android system shows a popup saying that "Element is not responding". I collected the following logcat, the relevant part is **ForegroundServiceStartNotAllowedException: FGS type dataSync not allowed to start from BOOT_COMPLETED!**:
```logcat
09:33:30.683 6130-6130 JitsiMeetSDK im.vector.app E JitsiMeetUncaughtExceptionHandler FATAL ERROR
java.lang.RuntimeException: Unable to start service im.vector.app.fdroid.service.GuardAndroidService@f72f9db with Intent { cmp=im.vector.app/.fdroid.service.GuardAndroidService }: android.app.ForegroundServiceStartNotAllowedException: FGS type dataSync not allowed to start from BOOT_COMPLETED!
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:5323)
at android.app.ActivityThread.-$$Nest$mhandleServiceArgs(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2597)
at android.os.Handler.dispatchMessage(Handler.java:109)
at android.os.Looper.loopOnce(Looper.java:232)
at android.os.Looper.loop(Looper.java:317)
at android.app.ActivityThread.main(ActivityThread.java:8934)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:591)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:911)
Caused by: android.app.ForegroundServiceStartNotAllowedException: FGS type dataSync not allowed to start from BOOT_COMPLETED!
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:5094)
at android.os.Parcel.readParcelable(Parcel.java:5076)
at android.os.Parcel.createExceptionOrNull(Parcel.java:3256)
at android.os.Parcel.createException(Parcel.java:3245)
at android.os.Parcel.readException(Parcel.java:3228)
at android.os.Parcel.readException(Parcel.java:3170)
at android.app.IActivityManager$Stub$Proxy.setServiceForeground(IActivityManager.java:7268)
at android.app.Service.startForeground(Service.java:776)
at im.vector.app.fdroid.service.GuardAndroidService.onStartCommand(SourceFile:14)
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:5305)
at android.app.ActivityThread.-$$Nest$mhandleServiceArgs(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2597)
at android.os.Handler.dispatchMessage(Handler.java:109)
at android.os.Looper.loopOnce(Looper.java:232)
at android.os.Looper.loop(Looper.java:317)
at android.app.ActivityThread.main(ActivityThread.java:8934)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:591)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:911)
```
### Your phone model
Fairphone 3
### Operating system version
Android 15 (/e/OS)
### Application version and app store
Element 1.6.44 from F-Droid
### Homeserver
matrix.org
### Will you send logs?
No
### Are you willing to provide a PR?
Yes
Contributor guide
Assessment
This issue has not been assessed yet.