Skip to content

fix: Android 14 foreground service killed randomly #684

@elisunou

Description

@elisunou

On Android 14, TorrServer binary is killed randomly by the system.
Root cause: Android 14 requires explicit foregroundServiceType declared in both the manifest and startForeground() call.
Suggested fix in AndroidManifest.xml:
Add permissions after existing FOREGROUND_SERVICE:
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" /> <uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK" /> <uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" /> <uses-permission android:name="android.permission.WAKE_LOCK" />

Add 2 attributes to <service android:name=".service.TorrService">: android:foregroundServiceType="dataSync|mediaPlayback" android:stopWithTask="false" So the service declaration will look like this: <service android:name=".service.TorrService" android:exported="false" android:foregroundServiceType="dataSync|mediaPlayback" android:stopWithTask="false" />
Changes:
Added FOREGROUND_SERVICE_DATA_SYNC permission
Added FOREGROUND_SERVICE_MEDIA_PLAYBACK permission
Added REQUEST_IGNORE_BATTERY_OPTIMIZATIONS permission
Added WAKE_LOCK permission
Added foregroundServiceType="dataSync|mediaPlayback" to TorrService
Added stopWithTask="false" to keep service alive when app is closed
Tested on: Android 14

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions