BimmerGestalt / AAIdrive

Implementations of some Android Auto features as unofficial IDrive apps
MIT License
557 stars 92 forks source link

Tidal is not working #137

Closed fonaminos closed 4 years ago

fonaminos commented 4 years ago

At first: many thanks for your work here!

With my f36(2017) i can't control tidal app at my smartphone (Pixel 3). What is working:

what isn't working:

Looks like idrive is hanging/freezing at some point while reading information from the smartphone.

I already tried the official AndroidAutoIdrive Versions 1.2.1, 1.2.2 and build my own 1.2.2 from your git source with android studio and tried some settings at the app like audiofocus and so on. Nothing helped. Can you help troubleshooting?

hufman commented 4 years ago

Thank you for trying the app and reporting this bug! I'm not a regular user of Tidal, so I appreciate your report! The Shuffle toolbar button is usually disabled, I haven't actually seen any apps that implement support for that feature.

Can you confirm that the app is running in Audioplayer mode? The current source version also supports a Spotify mode, and I just want to confirm which UI you are seeing. Please feel free to attach a picture of what you are seeing to additionally help me identify what's happening.

The app provides a debug mini player which exercises the same music control code as the car interface: After opening the phone ui, clicking the Tidal icon will open a window to provide basic interaction with the music app. Unfortunately this screen does not show the elapsed time, but the progress bar should update with the song's position, and the back/next buttons in this screen should trigger Tidal to skip forward and back.

Can you check the adb logcat output to see if there are any crashes? The current time in the car interface is updated with a regularly-scheduled Handler callback, and the time could be stuck if the Handler thread has crashed for some reason. However, even if this thread is crashed, events from the car are handled in separate threads. In particular, opening the player screen in the car will immediately refresh all of the displayed data, even if the Handler thread is dead. If the time is not displaying properly even then, there's another problem to figure out. The Handler thread is also used for music app callbacks, so directly telling Tidal to skip tracks (through its notification or the lock screen widgets) should update the car ui with the new title and coverart while the Handler thread is alive. Another (unlikely) thing to check for: A symptom of the car event threads somehow being dead is that the toolbar buttons will not respond at all. The app needs to be alive enough to acknowledge the button clicks before the car will transition to the next screen when clicking the Apps, Browse, Now Playing, or Actions toolbar buttons.

Audio Focus shouldn't be relevant: The only difference it will cause is to force the car to listen to audio over a USB apps connection, which is unlikely to work in modern Android, and it will have no effect if the apps are running over Bluetooth.

I'd recommend trying the phone UI's mini player to confirm whether the progress bar updates and whether the back/next buttons work, along with whether the title and coverart update when manually triggering Tidal to change tracks. This has the additional benefit of allowing the phone to stay plugged into Android Studio to watch the log output.

Thank you again for reporting this bug!

fonaminos commented 4 years ago

Thanks for your reply. Here what i've found out:

Can you confirm that the app is running in Audioplayer mode? The current source version also supports a Spotify mode, and I just want to confirm which UI you are seeing. Please feel free to attach a picture of what you are seeing to additionally help me identify what's happening.

definitely yes. PXL_20201103_130343260

The app provides a debug mini player which exercises the same music control code as the car interface: After opening the phone ui, clicking the Tidal icon will open a window to provide basic interaction with the music app. Unfortunately this screen does not show the elapsed time, but the progress bar should update with the song's position, and the back/next buttons in this screen should trigger Tidal to skip forward and back.

Mini player is working, progress bar works, back/next buttons are working. If i start a Playlist, the queue remains empty.

Can you check the adb logcat output to see if there are any crashes? The current time in the car interface is updated with a regularly-scheduled Handler callback, and the time could be stuck if the Handler thread has crashed for some reason. However, even if this thread is crashed, events from the car are handled in separate threads. In particular, opening the player screen in the car will immediately refresh all of the displayed data, even if the Handler thread is dead. If the time is not displaying properly even then, there's another problem to figure out. The Handler thread is also used for music app callbacks, so directly telling Tidal to skip tracks (through its notification or the lock screen widgets) should update the car ui with the new title and coverart while the Handler thread is alive. Another (unlikely) thing to check for: A symptom of the car event threads somehow being dead is that the toolbar buttons will not respond at all. The app needs to be alive enough to acknowledge the button clicks before the car will transition to the next screen when clicking the Apps, Browse, Now Playing, or Actions toolbar buttons.

I'd recommend trying the phone UI's mini player to confirm whether the progress bar updates and whether the back/next buttons work, along with whether the title and coverart update when manually triggering Tidal to change tracks. This has the additional benefit of allowing the phone to stay plugged into Android Studio to watch the log output.

Now the interesting part ;) Your guess with the handler crashing seems right. Idrive UI is not updating, if i chose the next song on my phone. Album Cover, title and so on remains at the old song. If i switch to any other view in idrive and then back to music view, it refreshs the Album, title and so on to the current song on the smartphone.

What i got from android studio logs: when connecting to my bmw there is following crash: 2020-11-03 17:37:59.355 1551-1551/? E/NotificationListeners: notification listener ComponentInfo{me.hufman.androidautoidrive/me.hufman.androidautoidrive.notifications.NotificationListenerServiceImpl} could not be unbound java.lang.IllegalArgumentException: Service not registered: com.android.server.notification.ManagedServices$1@4620726 at android.app.LoadedApk.forgetServiceDispatcher(LoadedApk.java:1757) at android.app.ContextImpl.unbindService(ContextImpl.java:1874) at com.android.server.notification.ManagedServices.unbindService(ManagedServices.java:1496) at com.android.server.notification.ManagedServices.registerServiceLocked(ManagedServices.java:1307) at com.android.server.notification.ManagedServices.registerServiceLocked(ManagedServices.java:1283) at com.android.server.notification.ManagedServices.registerService(ManagedServices.java:1269) at com.android.server.notification.ManagedServices.bindToServices(ManagedServices.java:1256) at com.android.server.notification.ManagedServices.rebindServices(ManagedServices.java:1219) at com.android.server.notification.ManagedServices.onPackagesChanged(ManagedServices.java:821) at com.android.server.notification.NotificationManagerService.handleOnPackageChanged(NotificationManagerService.java:7443) at com.android.server.notification.NotificationManagerService$WorkerHandler.handleMessage(NotificationManagerService.java:7489) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:223) at com.android.server.SystemServer.run(SystemServer.java:622) at com.android.server.SystemServer.main(SystemServer.java:408) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:925) 2020-11-03 17:38:01.353 27749-27810/me.hufman.androidautoidrive E/libc: Access denied finding property "vendor.gralloc.disable_ahardware_buffer"

when switching to another idrive ui page back to music page i get that: 2020-11-03 17:39:06.708 27749-27920/me.hufman.androidautoidrive E/MusicApp: Received exception while handling rhmi_onHmiEvent android.content.res.Resources$NotFoundException: Resource ID #0x7f080158 at android.content.res.ResourcesImpl.getValueForDensity(ResourcesImpl.java:246) at android.content.res.Resources.getDrawableForDensity(Resources.java:982) at android.content.res.Resources.getDrawable(Resources.java:922) at me.hufman.androidautoidrive.music.CustomAction$Companion.fromMediaCustomAction(CustomAction.kt:13) at me.hufman.androidautoidrive.music.controllers.GenericMusicAppController.getCustomActions(GenericMusicAppController.kt:143) at me.hufman.androidautoidrive.music.controllers.CombinedMusicAppController.getCustomActions(CombinedMusicAppController.kt:223) at me.hufman.androidautoidrive.music.MusicController.getCustomActions(MusicController.kt:288) at me.hufman.androidautoidrive.carapp.music.views.PlaybackView.redrawActions(PlaybackView.kt:352) at me.hufman.androidautoidrive.carapp.music.views.PlaybackView.redraw(PlaybackView.kt:268) at me.hufman.androidautoidrive.carapp.music.views.PlaybackView.show(PlaybackView.kt:249) at me.hufman.androidautoidrive.carapp.music.MusicApp$CarAppListener.rhmi_onHmiEvent(MusicApp.kt:190) at de.bmw.idrive.StubBMWRemotingClient$4.run(StubBMWRemotingClient.java:120) at de.bmw.idrive.StubBMWRemotingClient$4.run(StubBMWRemotingClient.java:115) at org.apache.etch.bindings.java.support.StubBase$StubPoolRunnable.run(StubBase.java:202) at org.apache.etch.bindings.java.support.QueuedPool$1.doit(QueuedPool.java:57) at org.apache.etch.util.TodoManager.run(TodoManager.java:125) at java.lang.Thread.run(Thread.java:923)

Do you need the whole log? If yes, at what loglevel?

hufman commented 4 years ago

Great, that's very clear! I haven't seen this "disable_ahardware_buffer" error before and don't know what it means, and Google isn't being very helpful. Perhaps the notification service is dying as part of the crash in the music app shutting down the entire application.

That crash in the custom action rendering points precisely to the problem. Can you try this patch to catch the exception and use a blank icon? If it works, feel free to submit it as a PR!

index 5a4b3d8..37a8781 100644
--- a/app/src/main/java/me/hufman/androidautoidrive/music/CustomAction.kt
+++ b/app/src/main/java/me/hufman/androidautoidrive/music/CustomAction.kt
@@ -5,13 +5,23 @@ import android.content.res.Resources
 import android.graphics.drawable.Drawable
 import android.os.Bundle
 import android.support.v4.media.session.PlaybackStateCompat
+import java.lang.Exception

 open class CustomAction(val packageName: String, val action: String, val name: String, val icon: Drawable?, val extras: Bundle?) {
        companion object {
                fun fromMediaCustomAction(context: Context, packageName: String, action: PlaybackStateCompat.CustomAction): CustomAction {
                        val resources = context.packageManager.getResourcesForApplication(packageName)
-                       val icon = resources.getDrawable(action.icon, null) ?:
+                       val icon = try {
+                               resources.getDrawable(action.icon, null)
+                       } catch (e: Exception) {
+                               try {
                                        Resources.getSystem().getDrawable(action.icon, null)
+                               } catch (e: Exception) {
+                                       null
+                               }
+                       } catch (e: Exception) {
+                               null
+                       }
                        return formatCustomActionDisplay(
                                        CustomAction(packageName, action.action, action.name.toString(), icon, action.extras)
                        )
fonaminos commented 4 years ago

This is working very well. The First crash still happens but i can now control the music via idrive. Many thanks!

hufman commented 4 years ago

Thank you so much!!