daneren2005 / Subsonic

Home of the DSub Android client fork
GNU General Public License v3.0
582 stars 162 forks source link

When connecting Android Auto to the app, music auto plays #1154

Open gravelld opened 1 year ago

gravelld commented 1 year ago

When I run the Android Auto desktop-head-unit and connect it to a physical Android device running D-Sub, the playback seems to resume its last state.

The trouble is that this contravenes the Android Auto quality guidelines (MA-1). Apps submitted to the Play Store may be rejected as a result.

I've been looking through the code and I can see that doPlay is called on our MediaSessionCompat.Callback as registered in RemoteControlClientLP.

However, the same callback is called when someone presses the play button, and there's no contextual information for the event. So how do we know when to prevent playback, and when to allow it?

I've found that...

In AutoMediaBrowserService I can create a MediaBrowserCompat and register a MediaBrowserCompat.ConnectionCallback with that which tells us when Android Auto connects. This occurs before the doPlay().

If I remove the call in AutoMediaBrowserService to setSessionToken() with the RemoveControlClientLP's MediaSessionCompat then the auto play doesn't happen. I stepped through this code, but nothing seems to be done with that token directly from that call and I can't see any other requests on the session token, so I'm puzzled as to why that affects things.

Anyone got any guidance about how to debug this?