BimmerGestalt / AAIdrive

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

Unlocking phone to finish connection #355

Closed Azza899 closed 3 years ago

Azza899 commented 3 years ago

First off I have to say this app is amazing and breathes new life into ID6 on my F30 (even making the buttons work on the steering wheel to change Spotify tracks!)

I have a new issue that seems to be happening, I'm running the nightly build 1.3rc2-56-b54121f and I've noticed I now have to unlock my phone for the connection to finish establishing.

For example if I get in the car and start it, AAI kicks in and i see a single Spotify icon on the idrive, but it is unusable and doesn't allow me to select it BUT if I unlock my phone I then see Spotify/jellyfin/plex all show up in the list almost instantly the car then defaults back to Spotify and starts playing as usual.

wondering if this has been mentioned before or if there is any work around's its not a major deal in any case.

hufman commented 3 years ago

That's curious! The fact that it creates the Spotify icon indicates that the connection is alive and well (specifically reached this line). Clicking through that Spotify icon triggers this callback, which needs to complete within a few seconds for the car to continue into the screen. The other music app icons are created after MusicAppDiscovery finishes loading its state, a little later in the startup process.

It's hard to say what's getting stuck, Would you be able to share an adb logcat to help me understand what's going on?

Azza899 commented 3 years ago

Its definitely a new one, previously if it didn't start correctly it wouldn't show anything. bit of supporting information, i left the car for about an hour got in and it connected right back up, so perhaps its when the car is being left to fully power down (ive heard the infotainment can stay awake a while?)

I have no idea how to do the logcat but if you let me know im sure i can give it a bash.

hufman commented 3 years ago

Oh very curious! These random failures are frustrating bugs to figure out! The car itself has been pretty reliable in my experience, if anything I'd look suspiciously at the MyBMW app. I have noticed a problem (not sure if it's been fixed) where the Bluetooth connection to the car sometimes appears to drop very briefly during startup, which confused the MyBMW connection code and interrupted the first connection attempt. This showed a similar symptom, where sometimes the Music app gets far enough to show the Spotify icon but then the connection fails, and after the 30 second heartbeat timeout it closes the connection (removing the Spotify icon) and starts everything up again successfully. Do you observe the Spotify icon disappearing by itself and coming back, perhaps right at 30 seconds when you decide to open up the phone and check?

The main piece you'll need is the ADB command itself, which comes as part of the Android SDK or Android Studio IDE. After installing that and plugging in your phone, check that you can run adb logcat in a terminal and see logging output from your phone. Normal phone activity is relatively busy, and so it might not remember the last time you were out in the car. With that ready, go out to the car and try some tests, and then go back to your computer and run adb logcat -d > logcat.txt and email that to me.

hufman commented 3 years ago

I believe MyBMW upgraded over the weekend, do you see any change in behavior?

Azza899 commented 3 years ago

I was out and about today and the issue remained. ive got something i want to try, i use an app called jellyfin (plex alternative) that shows up on the idrive i cant be sue if its happened since i installed that but im going to bin it off so that its only spotify thats on.

in regards to the logcat do i need the laptop with me in the car or is it something you run and then take the phone out > test > then run again?

cheers

hufman commented 3 years ago

No, the presence of certain music apps shouldn't affect whether the connection starts up successfully. You can bring the laptop out with you, if you have one, sure. I develop on a desktop, and the phone's log buffer is long enough for me to go back inside and grab the adb logcat -d after a test. Running the adb command before going outside is just a one-time check to make sure everything is working (development mode and drivers and so on).

Azza899 commented 3 years ago

Email should be winging its way to you with a logcat, once i replicated the issue i hooked my phone straight back up so hopefully not too much junk in it

hufman commented 3 years ago

Thank you for that log! One line that stuck out at me is the Activity Manager saying the app targets O+, restricted, which comes from a code path due to the app is under background processing restrictions. I see the connection process start up right when the car connects, and the Car Information and Assistant modules finish initializing before.. the phone's log pauses for 20 seconds until you unlock the phone. 10 seconds later when you open the app, then processing continues and the Music app finishes initializing and adds the other music apps to the car.

Can you share a screenshot of the power management settings for AAIdrive? Does AAIdrive successfully detect whether it has background processing restricted and show a checkmark on the main screen, indicating that "The app can not run in the background" and "Automatic connections work better if background activity is allowed"? I only developed that checkmark against the Pixel2 power management, and perhaps the logic needs to be extended for Huawei.

Azza899 commented 3 years ago

seems you were correct, in the huawei settings under Battery > App launch i have taken off automatic management from AAID and the BMW apps which seems to have solved the issue so far. ill keep an eye on it and report in any changes going forward.

Appreciate the time you have taken to look into this.

Cheers

hufman commented 3 years ago

Can I ask you to try out this test build that adds a checkbox indicating whether Batttery Optimizations are detected? On an emulated Nexus 5, it detects the Battery Optimizations setting, and I wonder how it reacts on your phone. It might only read the default Battery Optimizations, and it might also detect those App Launch settings too, not sure!

Azza899 commented 3 years ago

Yep no problem ill give it a shot when i get back from work tonight

Azza899 commented 3 years ago

So i installed that build and the check box says "can be ran in the background" but if i set app's launch to be managed by the phone it still says it can be ran in the background (even after a reboot).

no doubt a weird quirk of the P30 pro as you can no longer turn off the power drain notifications when an app runs for a long time

hufman commented 3 years ago

Does the new checkbox about Battery Saving change at all? I apologize, I should've included this screenshot in the original request. photo1629229531

Azza899 commented 3 years ago

so setting app launch to automatic or manual doesnt trigger that check box.

hufman commented 3 years ago

Great, thank you so much for the testing and feedback!

Azza899 commented 3 years ago

no problem, happy to help where i can.