-
-
Notifications
You must be signed in to change notification settings - Fork 684
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
Integrate car sensors with automotive, and added permissions #4122
Integrate car sensors with automotive, and added permissions #4122
Conversation
override val name: Int | ||
get() = R.string.sensor_name_car | ||
|
||
override suspend fun getAvailableSensors(context: Context): List<SensorManager.BasicSensor> { | ||
this.context = context.applicationContext |
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.
Those lateinit context set are a bit sketchy. I had to set it from more methods, as it wasn't set in some calls. I added it to every method accepting a context, just in case it happens again in the future.
I'm considering 2 other options: Adding it on construction (Not sure if possible), or simply drilling it through method calls, so we're sure we actually have a context when calling something that needs it.
I'd like to see more opinions about this
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.
So we do actually use a latestContext
method of storing the latest context received in the app for some sensors, very similar to what you are doing here.
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.
I see. Renaming to latestContext, to keep the same naming as the other sensors
app/src/main/java/io/homeassistant/companion/android/sensors/CarSensorManager.kt
Outdated
Show resolved
Hide resolved
app/src/main/java/io/homeassistant/companion/android/sensors/CarSensorManager.kt
Show resolved
Hide resolved
|
||
private fun allDisabled(): Boolean = sensorsList.none { isEnabled(context, it) } | ||
if (isAutomotive && !carSensor.automotiveEnabled || !isAutomotive && !carSensor.autoEnabled) { |
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.
Do we need to add some parenthesis here so the conditions are properly evaluated?
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.
Adding them to improve readability
Looks really good, will be following with interest |
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.
Ran a local test with the changes and don't see any issues. Thank you for taking this on!
Sorry if this is a poor phrased question but how does one access "Automotive Full flavor " version? I have a vehicle Google Automotive Services(GAS) w/AAOS and have installed Home Assistant from Play Store. Is there an APK I can download and sideload on this vehicle IVI of my own vehicle to get this functionality? |
currently you cannot access them if you have installed the app via the play store, but you can follow this PR which seeks to enable them #4652 you just need to have some patience and wait. |
Summary
Integrate car sensors with Android Automotive:
To better separate Auto from Automotive, I decided to add the core differences (Sensor availability and permissions) to the sensors themselves. This way, we have all the sensor logic and requirements in the same location, which is interesting when we start adding more sensors.
For that I made a CarSensor wrapper class of BasicSensor (I considered inheritance, but data classes are final, and I'm not sure changing them would have been worth it). Everything else is quite the same, but using the sensor objects instead.
Screenshots
Example entities on an Automotive emulator:
![imagen](https://private-user-images.githubusercontent.com/5280509/294718444-673e70d3-7f3e-4d90-8efa-778cd7492b2b.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk2MDM0NzksIm5iZiI6MTczOTYwMzE3OSwicGF0aCI6Ii81MjgwNTA5LzI5NDcxODQ0NC02NzNlNzBkMy03ZjNlLTRkOTAtOGVmYS03NzhjZDc0OTJiMmIucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIxNSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMTVUMDcwNjE5WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9NTcwMjgxODg0YzBhNjcyM2ZhOTM4YTJmNmIzYzBkNGFkODkzMTY3ZDhjNTZhNTVmOWNhYTJmM2ZiNDI5NGNhZiZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.8mzeagnBnkOYfvBwww7WN2RfL010Yny29NHINZXRAG4)
The permission request on enabling some sensors:
![imagen](https://private-user-images.githubusercontent.com/5280509/294719839-1fb4f28a-cd81-4af7-aea8-eb1e3fcc0da2.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk2MDM0NzksIm5iZiI6MTczOTYwMzE3OSwicGF0aCI6Ii81MjgwNTA5LzI5NDcxOTgzOS0xZmI0ZjI4YS1jZDgxLTRhZjctYWVhOC1lYjFlM2ZjYzBkYTIucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIxNSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMTVUMDcwNjE5WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9MjE3ODc0YWI0MGUyMDk2ZTk3MTBiN2UzOWZjMDI5YTllNGU4NWM5ZmU3YjMxMDE0OWU0YTJhOGY1OGRiZDE1NiZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.vqXgYb8zbN4KCcVmhYYj8bUmEsXmWkgcv4r2dg12nwo)
Link to pull request in Documentation repository
We could change the "Currently unavailabe for AAOS users" to "Currently unavailabe for AAOS users from Google Play" (Or similar). But I'd say it's not worth it yet, at least until the full flow is ready (?)
Any other notes
Only available in Automotive Full flavor (Not in the Google Play version yet). Sensors must be manually enabled, which can't be done in the minimal flavor. Enabling the sensors from the server won't ask for permissions from what I tested, so it may only work for some.