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.73k stars 414 forks source link

Media resumption results in DeadObjectException #1557

Open WSteverink opened 4 months ago

WSteverink commented 4 months ago

Version

Media3 pre-release (alpha, beta or RC not in this list)

More version details

1.4.0-rc01

Devices that reproduce the issue

Android Studio emulator: Pixel 8 Pro API 34 - Android 14 Asus zenfone 9 Android 14

Devices that do not reproduce the issue

Pixel 7 Android 14

Reproducible in the demo app?

No

Reproduction steps

I am trying to fix a bug for MediaResumption that occurs on some devices. My problem occurs in the following scenario :

  1. Play something
  2. Pause it
  3. Swipe app away from recents.
  4. See a dead/stale notification that does not trigger onPlaybackResumption

Steps to reproduce With UAMP (media3 branch) i am able to reproduce the issue by doing the following:

1 . Use the latest Media3 version 1.4.0-rc01 because it contains pauseAllPlayersAndStopSelf().

  1. In the MusicService.kt implement this:
    override fun onTaskRemoved(rootIntent: Intent?) {
        super.onTaskRemoved(rootIntent)
        Log.d("[DEBUG]", "onTaskRemoved: ")
        pauseAllPlayersAndStopSelf()
    }

    override fun onDestroy() {
        super.onDestroy()
        Log.d("[DEBUG]", "onDestroy: ")
    }

3 . Add this to the MusicServiceCallback in the MediaService

        override fun onPlaybackResumption(
            mediaSession: MediaSession,
            controller: MediaSession.ControllerInfo
        ): ListenableFuture<MediaSession.MediaItemsWithStartPosition> {
            Log.d("[DEBUG]", "onPlaybackResumption: <------------")
            return super.onPlaybackResumption(mediaSession, controller)
        }

By doing the above we cannot expect MediaResumption to work because onPlaybackResumption does nothing but printing a log. But it should get called.

  1. Run the app with Android Studio and

    1. Play something
    2. Pause it
    3. Swipe app away from recents.
    4. See a dead/stale notification that does not trigger onPlaybackResumption
  2. Open logcat and CLEAR all the filters and observe this exception

    
    2024-07-19 12:02:05.434   524-852   MediaSessionRecord      system_server                        E  Remote failure in play.
                                                                                                    android.os.DeadObjectException
                                                                                                        at android.os.BinderProxy.transactNative(Native Method)
                                                                                                        at android.os.BinderProxy.transact(BinderProxy.java:584)
                                                                                                        at android.media.session.ISessionCallback$Stub$Proxy.onPlay(ISessionCallback.java:729)
                                                                                                        at com.android.server.media.MediaSessionRecord$SessionCb.play(MediaSessionRecord.java:1408)
                                                                                                        at com.android.server.media.MediaSessionRecord$ControllerStub.play(MediaSessionRecord.java:1743)
                                                                                                        at android.media.session.ISessionController$Stub.onTransact(ISessionController.java:523)
                                                                                                        at android.os.Binder.execTransactInternal(Binder.java:1344)
                                                                                                        at android.os.Binder.execTransact(Binder.java:1275)

The fact that pauseAllPlayersAndStopSelf got introduced helped me to address a bug that restarted my MediaService, which is nice. But also resulted in the above for some devices.

### Expected result

onPlaybackResumption() should get called so we can load items to resume.

### Actual result

Stale notification and an exception is thrown:

Remote failure in play. android.os.DeadObjectException at android.os.BinderProxy.transactNative(Native Method) at android.os.BinderProxy.transact(BinderProxy.java:584) at android.media.session.ISessionCallback$Stub$Proxy.onPlay(ISessionCallback.java:729) at com.android.server.media.MediaSessionRecord$SessionCb.play(MediaSessionRecord.java:1408) at com.android.server.media.MediaSessionRecord$ControllerStub.play(MediaSessionRecord.java:1743) at android.media.session.ISessionController$Stub.onTransact(ISessionController.java:523) at android.os.Binder.execTransactInternal(Binder.java:1344) at android.os.Binder.execTransact(Binder.java:1275)



**Note**
Probably related to [this](https://github.com/androidx/media/issues/493)
marcbaechinger commented 4 months ago

Thanks for your report.

When you can NOT repro on the Pixel 7, do you see the output of Log.d("[DEBUG]", "onTaskRemoved: ") in the logs? If you see the log then but not on the other devices, then this is a duplicate of #805 and we can close that issue.

All devices that you list are running Android 14. Seeing the log line onTaskRemoved indicates the bugfix has landed. Can you verify whether this is the case?

That the dead notification would trigger onPlaybackResumption isn't expected. The stack trace looks like an attempt of pressing the play button on the dead notification with a stale controller. System UI still has a controller that wants to send a play command to a session of a process that already died. This is usually the case when the service crashed or the session wasn't properly released for other reasons. #805 would be such a reason on Android 14 in case that device hasn't a fix on the OS side for this.

If this is not about #805 (when you see the log line from onTaskRemoved on all devices), then please do the repro step with UAMP and do a bug report right after terminating the app by swiping the app off the recent apps. If you're unable to share bug reports or test content publicly, please send them to android-media-github@google.com using a subject in the format "Issue #1557", Please also update this issue to indicate you’ve done this.

WSteverink commented 4 months ago

All devices that you list are running Android 14. Seeing the log line onTaskRemoved indicates the bugfix has landed. Can you verify whether this is the case?

"Unfortunately" i can see onTaskRemoved being called on both devices.

So to reproduce it with UAMP you can grab the steps at mentioned above in "Steps to reproduce" .

I did sent a LogCat dump towards the email address you have mentioned. But the output is so massive that reproducing it is probably faster than using it!

I you have a working version for UAMP or the Media sample app, you could also share a branch. So i can try it on my end. Anyways, i am looking forward to your response and thanks already 👍

WSteverink commented 2 months ago

Any updates on this? Thanks in advance.