-
-
Notifications
You must be signed in to change notification settings - Fork 671
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make changes to allow health connect to work on Android 9 and higher #4790
Make changes to allow health connect to work on Android 9 and higher #4790
Conversation
Broadcast receivers are short lived and as I understand it may be killed even earlier if you launch (run work asynchronously) without indicating it to the system. Have you tested/encountered this with the app running in the background? Some nice discussions and a Kotlin extension function for it here: https://stackoverflow.com/questions/22741202/how-to-use-goasync-for-broadcastreceiver |
24 hours later all enabled sensors including location tracking still working as expected |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're using MainScope().launch { }
in a couple of places, but also a regular CoroutineScope
in another one or two. Would it be worth it to introduce a helper function for it, or a custom scope like sensorWorkerScope
(which is defined in the base class as = MainScope()
) so it is easier to track and update later?
...va/io/homeassistant/companion/android/onboarding/integration/MobileAppIntegrationFragment.kt
Outdated
Show resolved
Hide resolved
The reason for that is because we had it split up. Specifically the android auto connection sensors requires the CoroutineScope or it fails to update.
if we were to do this it would need to be teh CoroutineScope |
That's odd because you're still using the main/UI thread, only difference is the supervisor behavior which shouldn't matter. |
was failing due to the thread not calling |
...on/src/main/java/io/homeassistant/companion/android/common/sensors/BluetoothSensorManager.kt
Outdated
Show resolved
Hide resolved
app/src/full/java/io/homeassistant/companion/android/sensors/AndroidAutoSensorManager.kt
Show resolved
Hide resolved
app/src/main/java/io/homeassistant/companion/android/sensors/CarSensorManager.kt
Outdated
Show resolved
Hide resolved
app/src/full/java/io/homeassistant/companion/android/sensors/HealthConnectSensorManager.kt
Outdated
Show resolved
Hide resolved
Testing this on Android 13, requesting Health Connect permissions seems to be broken (immediately denied) and tapping on settings in the snackbar crashes the app:
|
thanks I was able to hunt down an older device will use that for testing and update this PR |
Fixed, also the snackbar has been fixed too. Just an FYI these permissions are also subject to not being prompted multiple times if they are continuously denied. Verified on my old Pixel 3 XL running android 12 |
I'm not completely sure what you mean. For me, if I deny the permission twice tapping Settings on the snackbar will completely stop working (nothing happens/the system auto-denies). Shouldn't the settings button link to an intent with ACTION_MANAGE_HEALTH_PERMISSIONS? That seems like it would always work. |
that should behave like the other sensors right?
thats only for android 14+, we can launch the HC app though |
Currently: no it doesn't, anything normal opens system settings for permissions which always works. Ideally: yes it should behave like others and always work.
Oops / that seems like a good option :) (need to put it in the SM to avoid the dependency in minimal) |
app/src/main/java/io/homeassistant/companion/android/settings/sensor/views/SensorDetailView.kt
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good and seems to work as before during testing, but this should be in beta for a while to make sure there is no unexpected impact.
Agreed this needs beta time |
Summary
Makes
requestSensorUpdate
andcheckPermissions
suspend functions to allow health connect to work on Android 9 and higher devices instead of just Android 14+. Some other methods were also converted to make the changes here easier to follow (I hope)Screenshots
Link to pull request in Documentation repository
Documentation: home-assistant/companion.home-assistant#1135
Any other notes