androidx / media

Jetpack Media3 support libraries for media use cases, including ExoPlayer, an extensible media player for Android
https://developer.android.com/media/media3
Apache License 2.0
1.75k stars 418 forks source link

Pausing media and then destroying app holds notification, and at the same time the media buttons do not respond #1136

Open AlexeyIWS opened 9 months ago

AlexeyIWS commented 9 months ago

Version

Media3 1.2.1

More version details

No response

Devices that reproduce the issue

xiaomi 12, Android 13, MIUI Global 14.0.8 https://www.mi.com/ru/product/xiaomi-12/

Devices that do not reproduce the issue

many devices, for example: pixels

Reproducible in the demo app?

Yes

Reproduction steps

play media (shown notification) pause destroy app notification stucked

Expected result

notification should cleared together with app

Actual result

notification stucked

Media

https://github.com/androidx/media/assets/44832968/0a528023-7ea7-447e-a2af-75c3b613d417

Bug Report

marcbaechinger commented 9 months ago

Thanks for your report!

destroy app

Can you elaborate how this happens?

marcbaechinger commented 9 months ago

Ah sorry, the screencast eludes it's by swiping away the app from recent tasks. I can n ot repro this on an emulator with API 33.

Can you please do a bug report just after this happens on this device and upload here?

AlexeyIWS commented 9 months ago

@marcbaechinger send to android-media-github@google.com (too large)

also some interesting information: commercial player have not this behavior (for example: https://play.google.com/store/apps/details?id=musicplayer.musicapps.music.mp3player), but chrome browser have

marcbaechinger commented 9 months ago

Thanks for the bugreport. Difficult to say from the bug report I'm afraid.

Here is the log that shows when the app is killed by ActivityManager:

02-28 18:08:28.417  1000  2635  2879 I ProcessSceneCleaner: SwipeUpClean: kill procName=androidx.media3.demo.session info=AS:010
02-28 18:08:28.417  1000  2635  2879 I ActivityManager: Killing 7746:androidx.media3.demo.session/u0a663 (adj 0): SwipeUpClean
02-28 18:08:28.419  1000  2635  2879 I SmartPower.androidx.media3.demo.session/10663(7746): background->died(957ms) R(process died ) adj=0.
02-28 18:08:28.419  1000  2635  3811 I SmartPower: androidx.media3.demo.session/10663 state=inactive adj=0 proc size=1 move to died process died 

on an emulator with Pixel this seems to be this line:

2024-02-28 16:45:55.374   616-1791  ActivityManager         system_server                        I  Killing 7668:androidx.media3.demo.session/u0a159 (adj 1001): remove task

If everything works as intended, then killing the app calls onTaskRemoved() and onDestroy() of the service. This releases the session and the player and results in such a line in the logs:

2024-02-28 16:45:55.326  7668-7668  ExoPlayerImpl           androidx.media3.demo.session         I  Release 54df3b3 [AndroidXMedia3/1.3.0] [emu64x, sdk_gphone64_x86_64, Google, 33] [media3.common, media3.exoplayer, media3.decoder, media3.session, media3.datasource, media3.ui, media3.extractor]

I can't find this line in your bug report. I can't find the Init line either though :).

Instead I find many of these after the app got killed:

02-28 18:08:29.846  1000  2635  4318 E MediaSessionRecord: Remote failure in play.
02-28 18:08:29.846  1000  2635  4318 E MediaSessionRecord: android.os.DeadObjectException
02-28 18:08:29.846  1000  2635  4318 E MediaSessionRecord:  at android.os.BinderProxy.transactNative(Native Method)
02-28 18:08:29.846  1000  2635  4318 E MediaSessionRecord:  at android.os.BinderProxy.transact(BinderProxy.java:643)
02-28 18:08:29.846  1000  2635  4318 E MediaSessionRecord:  at android.media.session.ISessionCallback$Stub$Proxy.onPlay(ISessionCallback.java:729)
02-28 18:08:29.846  1000  2635  4318 E MediaSessionRecord:  at com.android.server.media.MediaSessionRecord$SessionCb.play(MediaSessionRecord.java:1330)
02-28 18:08:29.846  1000  2635  4318 E MediaSessionRecord:  at com.android.server.media.MediaSessionRecord$ControllerStub.play(MediaSessionRecord.java:1687)
02-28 18:08:29.846  1000  2635  4318 E MediaSessionRecord:  at android.media.session.ISessionController$Stub.onTransact(ISessionController.java:523)
02-28 18:08:29.846  1000  2635  4318 E MediaSessionRecord:  at android.os.Binder.execTransactInternal(Binder.java:1290)
02-28 18:08:29.846  1000  2635  4318 E MediaSessionRecord:  at android.os.Binder.execTransact(Binder.java:1249)

Which is when you try hitting the buttons on the leaked notification. It looks like a session is leaked after the service has been terminated.

From all this, my guess would be onTaskRemoved and onDestroy() is not called on this device. The different log files regarding ActivityManager indicates that the code running on that device is different from what AOSP code does.

I can't really help with this with the bug report only I think. We would need to test this with such a device to see what is going on. Can you check with a logline in DemoPlaybackService.onDestroy() and DemoPlaybackService.onTaskRemoved() if my guessing is correct, as in these log lines are never written to the logs when the ActivityManager kills the app?

If this is the case I wouldn't know how to fix that though. :( Not calling these life-cycle methods by the OS on that device would not give an app a chance to properly cleanup.

AlexeyIWS commented 9 months ago

I can't really help with this with the bug report only I think. We would need to test this with such a device to see what is going on. Can you check with a logline in DemoPlaybackService.onDestroy() and DemoPlaybackService.onTaskRemoved() if my guessing is correct, as in these log lines are never written to the logs when the ActivityManager kills the app?

@marcbaechinger yes, that's it. methods onDestroy() and onTaskRemoved() are not called.

marcbaechinger commented 9 months ago

Internal bugref: b/328022018

lucasiturbide commented 9 months ago

I noticed the same in my app. Is this a bug in the library or something we're missing in our implementation?

marcbaechinger commented 9 months ago

@lucasiturbide On what device and with what Android version are you seeing this?

lucasiturbide commented 9 months ago

@lucasiturbide On what device and with what Android version are you seeing this?

The media lib version is 1.2.1 and my device is a Pixel 6 Pro with Android 14

marcbaechinger commented 9 months ago

Then you are suffering from a bug in Android 14 that is reported internally already. Please see #805 which is tracking this here on GitHub.