-
Notifications
You must be signed in to change notification settings - Fork 6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Foreground service types are required since Android 14 #11239
Comments
This is the fun part about Android 14 and the future :) DownloadService should be "dataSync" with the corresponding permission (FOREGROUND_SERVICE_DATA_SYNC). But they already warn that "dataSync" will be deprecated and removed in the future (And guarded by Google Play review team). So according to Google DownloadService should not exist and should be migrated to user-initiated data transfer jobs / workmanager. I have hope that teams like Media3 can explain to the other Google team that syncing data should be possible without using an ultra limiting API. (The new API requires that you put constraints on Internet conditions and can't run without connectivity). TL;DR; For Android 14 use "dataSync", but keep in mind that they may break everything as soon as Android 15 and should plan. |
The answer to your questions depends on which type of service we are talking about exactly.
I'll leave this issue open as an enhancement to clarify the open question about whether the media playback use case needs to be declared in the manifest too and to track alternative solutions for our |
@tonihei The permission is mandatory too and it does not seem to be present for now (in media3 or here)
For the rest shortService limits to 3 minutes is really short to transcode video on low end devices. And downloads / transformer can often be time critical. (And those kind of jobs should not be cancelled as not really resumable in most of the cases). Not everyone play media from servers with different streams and all the nice stuff :) Some apps play user content stored on simple web servers that does not support transcode or things like that and the playback action is actually download / transform to something that the device can play then play. Relying on APIs that can delay the start of the job for undetermined time based on impossible to know limits at the time the job start is just not an acceptable from the user POV. Blocking of foreground services started when the app is visible for those kind of use case without an appropriate solution will trigger issues. Of course the workaround will simply be to bind everything to the playback service and have the playback notification show a preparing media but then this defeat everything and does not solve what all those changes are supposed to do. |
Thanks for the additional details!
If the task is that tightly coupled to the actual playback, then I think
The best way to integrate this is probably via a |
This triggers many UX/UI issues to properly notify the user about what is going on, estimated time for end of transcoding or at least a percentage and everything needed for the user to not click everywhere as he think the media is started when it's not. We have the buffering state to handle relatively fast case like when we can transcode server side and just need to wait for the process to have transcoded enough to start playback. But for longer things like described above this does not really fit. Not sure this is something that can easily be handled / exposed directly via ExoPlayer. But even for the fast case of starting the transcode on server then wait for enough data to be buffered, having an internal state in ExoPlayer for long media preparation would effectively solve this and allow usage of WrappingMediaSource or equivalent and properly be a mediaPlayback foreground service type. |
We made some changes to improve Android 14 foreground service compatibility:
I think this addresses all of the issues here. @Tolriq The points you raise in your last post are all valid and you may be able to achieve this by customizing the notification that gets created for |
This helps to highlight and document new requirements for apps, e.g. to add the FOREGROUND_SERVICE_MEDIA_PLAYBACK permission for background playback. Issue: #11239 PiperOrigin-RevId: 548666056
This ensures the DownloadService stays functional on Android 14 where defining this type is required. On Android 14 and above, the app also needs to define the DATA_SYNC permission, which is added to the demo app as well. In the future, this service type will no longer be supported and DownloadService needs to be rewritten with another background scheduling framework. Issue: #11239 PiperOrigin-RevId: 548994842
This helps to highlight and document new requirements for apps, e.g. to add the FOREGROUND_SERVICE_MEDIA_PLAYBACK permission for background playback. Issue: google/ExoPlayer#11239 PiperOrigin-RevId: 548666056
This ensures the DownloadService stays functional on Android 14 where defining this type is required. On Android 14 and above, the app also needs to define the DATA_SYNC permission, which is added to the demo app as well. In the future, this service type will no longer be supported and DownloadService needs to be rewritten with another background scheduling framework. Issue: google/ExoPlayer#11239 PiperOrigin-RevId: 548994842
In the service type I used ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK and it is also necessary to use the permissions in the manifest
for me it works |
Hello,
Regarding to the behavior changes since Android 14, If your app targets Android 14, it must specify appropriate foreground service types.
https://developer.android.com/about/versions/14/changes/fgs-types-required
Can you tell me what service type that we should use for all service class of ExoPlayer ?
For example: DownloadService.etc..
The text was updated successfully, but these errors were encountered: