Android Auto Car Sensors: unavailable when testing on a real car

193 views Asked by At

I'm using Car Sensors library from androidx.car. I retrieve car sensor data with listeners inside an onGetTemplate() of a MainScreen with a carContext.

        try {
            createCompassListener()
            createHwLocationListener()
            createAccelerationListener()
            createGyroscopeListener()
            createSpeedListener()
        } catch (e: SecurityException) {
            carContext.requestPermissions(
                listOf(
                    ACCESS_FINE_LOCATION
                )
            ) { grantedPermission, _ ->
                if (grantedPermission.size > 0) {
                    createCompassListener()
                    createHwLocationListener()
                    createAccelerationListener()
                    createGyroscopeListener()
                    createSpeedListener()
                }
            }
        }

An example of listener:

    private fun createHwLocationListener() {
        val hwLocationListener = OnCarDataAvailableListener<CarHardwareLocation> { data ->
            if (data.location.status == CarValue.STATUS_SUCCESS) {
                carPhysicsRepository.hardwareLocation.apply {
                    value = data.location.value
                    time = System.currentTimeMillis()
                }
            }
        }
        carSensors.addCarHardwareLocationListener(CarSensors.UPDATE_RATE_NORMAL, carContext.mainExecutor, hwLocationListener)
    }

I print those values in a logfile I created inside host's filesystem, to make sure they've been read. All works fine with emulated head unit when I prompt mocked values from cli. Some days ago I decided to give it a go on a real car, a Peugeot 208 from 2017. With some disappointment, I noticed no real car values from Car Sensors API were available to my app whilst it was running.

There are few sources online about this topic and they mainly say: car sensors data may not be available as it depends on the OEM. But no manifacturer or technical data sheets states whether a car provides any, all or none of the car sensors specified in the API (acceleration, compass, location, and more here).

In a few weeks, my company is going to rent a car, Wolkswagen ID-3, to test the app, it's quite expensive and we are in the situation that we don't have any guess whether or not it will provide car sensor data. It's weird that there's so much documentation about simulating useless fake data and when it comes to real data, no information about cars providing those. Maybe it's too early for this kind of technology.

Can you guys suggest any sources about this sensors availability based on car brand? Or should I strive to try all Android Auto cars in the market until I find the good one? :O

Thanks!

1

There are 1 answers

2
Xuân Tâm On

This is very common when we talk about Android for Automotive, Especially in IVI. I was in 1 workshop between many major OEMs and Google before where this topic bring into discussion , and i think it still not having a common solution today. What google expected OEM to do is expose Vehicle Data according to Google Suggested way . (CarService , VHAL ...) , but it is not what OEM wanted to do.. because it breaks many requirements they have eg : Safety , Security... So it is not same as Sensor in Phone.

So answer for you question (if sensor actually not available as you tried). CarSensors will not work for all Car running Android OS. It really depend on what OEM offer in OEM custom IVI-AOSP, so dont expect too much. But what i think you might try is to look at what available in your Car and try to use it other way arround, Example : https://source.android.com/docs/automotive/vhal/system-properties Here hopefully some properties you can Set or Get and what OEM usually offer to Application Layer.