I am trying to read information from an AVD running Android Automotive OS 13. I am using AndroidX and attempting to access the vehicle's speed. A minimal example that does not work:
AutomotiveCarHardwareManager(context).carInfo.addSpeedListener(Executors.newSingleThreadExecutor()) {}
It requires a permission to work:
java.lang.RuntimeException: java.lang.SecurityException: Missed permission: android.car.permission.CAR_SPEED
When I add this permission to AndroidManifest.xml
it does not change anything (same error output with/without). Note: The manifest is 'set up' correctly and does work with other general permissions.
<uses-permission android:name="android.car.permission.CAR_INFO"/>
<uses-permission android:name="android.car.permission.CAR_SPEED"/>
I am not able to import android.car.permission.CAR_SPEED
in my main code and following the sources in the error, those files appear to have many import errors too.
Is there a possibility that I need a custom build or something like that in order to access privileged information such as vehicle speed?
Thank you!
Full exception:
FATAL EXCEPTION: main
Process: com.example.autodemo, PID: 11953
java.lang.RuntimeException: java.lang.SecurityException: Missed permission: android.car.permission.CAR_SPEED
at androidx.car.app.utils.RemoteUtils.lambda$dispatchCallFromHost$0(RemoteUtils.java:155)
at androidx.car.app.utils.RemoteUtils$$ExternalSyntheticLambda1.run(Unknown Source:6)
at androidx.car.app.utils.ThreadUtils.runOnMain(ThreadUtils.java:39)
at androidx.car.app.utils.RemoteUtils.dispatchCallFromHost(RemoteUtils.java:147)
at androidx.car.app.utils.RemoteUtils.lambda$dispatchCallFromHost$1(RemoteUtils.java:186)
at androidx.car.app.utils.RemoteUtils$$ExternalSyntheticLambda2.run(Unknown Source:8)
at android.os.Handler.handleCallback(Handler.java:942)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7924)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
Caused by: java.lang.SecurityException: Missed permission: android.car.permission.CAR_SPEED
at androidx.car.app.hardware.common.PropertyManager.checkPermissions(PropertyManager.java:310)
at androidx.car.app.hardware.common.PropertyManager.submitRegisterListenerRequest(PropertyManager.java:105)
at androidx.car.app.hardware.info.AutomotiveCarInfo.addSpeedListener(AutomotiveCarInfo.java:188)
at com.example.autodemo.InfoScreen.onGetTemplate(InfoScreen.kt:69)
at androidx.car.app.Screen.getTemplateWrapper(Screen.java:361)
at androidx.car.app.ScreenManager.getTopTemplate(ScreenManager.java:279)
at androidx.car.app.AppManager$1$$ExternalSyntheticLambda1.dispatch(Unknown Source:2)
at androidx.car.app.utils.RemoteUtils.lambda$dispatchCallFromHost$0(RemoteUtils.java:150)
at androidx.car.app.utils.RemoteUtils$$ExternalSyntheticLambda1.run(Unknown Source:6)
at androidx.car.app.utils.ThreadUtils.runOnMain(ThreadUtils.java:39)
at androidx.car.app.utils.RemoteUtils.dispatchCallFromHost(RemoteUtils.java:147)
at androidx.car.app.utils.RemoteUtils.lambda$dispatchCallFromHost$1(RemoteUtils.java:186)
at androidx.car.app.utils.RemoteUtils$$ExternalSyntheticLambda2.run(Unknown Source:8)
at android.os.Handler.handleCallback(Handler.java:942)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7924)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
android.car.permission.CAR_SPEED is dangerous runtime permission. Did you request runtime permission properly?
android.car.permission.CAR_INFO is normal permission, so declare it's usage in manifest should be enough.