How to disable feature:android.hardware.bluetooth in aosp_car_x86_64-userdebug (android 11 automotive emulator)

1.4k views Asked by At

I want to disable the feature:android.hardware.bluetooth for android automotive emulator 11.

Version that I synced with repo: android-11.0.0_r3 Version that I lunch: aosp_car_x86_64-userdebug

Changed files to comment out the permissions:

car.mk

#    frameworks/native/data/etc/android.hardware.bluetooth_le.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.bluetooth_le.xml \
#    frameworks/native/data/etc/android.hardware.bluetooth.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.bluetooth.xml \

Commented the permission in:

car_core_hardware.xml

<!--    <feature name="android.hardware.bluetooth" /> -->

If I run the emulator and ask the packagemanager, it is still convinced Bluetooth feature is enabled:

pm list features
feature:android.hardware.bluetooth
feature:android.hardware.bluetooth_le
2

There are 2 answers

0
twasilczyk On

android.hardware.bluetooth.xml may have slipped through some other .mk file in your device build config (it may be copied to /etc/permissions multiple times). Try removing it from running device:

adb root && adb remount && adb reboot
adb root && adb remount
export BT=etc/permissions/android.hardware.bluetooth.xml
adb shell rm /$BT /*/$BT /*/*/$BT
export BT=etc/permissions/android.hardware.bluetooth_le.xml
adb shell rm /$BT /*/$BT /*/*/$BT
adb reboot
adb shell pm list features | grep blue

For me, it removed android.hardware.bluetooth_le but not android.hardware.bluetooth feature. The latter disappeared after editing the <target type>_core_hardware.xml file you mentioned.

After you verify if removing the xml files helps, you need to review all mk files your device might be using to track where it was copied (with PRODUCT_COPY_FILES). After each try, review the contents of your $OUT directory (you may need to manually remove the xml file from output before the build, buildsystem doesn't always do it cleanly).

0
Michel Horvers On

When I removed the files (android.hardware.bluetooth.xml) from the out folder it got disabled. Problem is that Automotive cannot handle this disabling because it starts to crash:

01-07 15:12:08.833  8509  8509 D PerUserCarService: onCreate()
01-07 15:12:08.834  8509  8509 E BluetoothAdapter: Bluetooth binder is null
01-07 15:12:08.835  8509  8509 D AndroidRuntime: Shutting down VM
01-07 15:12:08.835  8509  8509 E AndroidRuntime: FATAL EXCEPTION: main
01-07 15:12:08.835  8509  8509 E AndroidRuntime: Process: com.android.car, PID: 8509
01-07 15:12:08.835  8509  8509 E AndroidRuntime: java.lang.RuntimeException: Unable to create service com.android.car.PerUserCarService: java.lang.NullPointerException: Bluetooth adapter cannot be null
01-07 15:12:08.835  8509  8509 E AndroidRuntime:    at android.app.ActivityThread.handleCreateService(ActivityThread.java:4204)
01-07 15:12:08.835  8509  8509 E AndroidRuntime:    at android.app.ActivityThread.access$1500(ActivityThread.java:237)
01-07 15:12:08.835  8509  8509 E AndroidRuntime:    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1932)
01-07 15:12:08.835  8509  8509 E AndroidRuntime:    at android.os.Handler.dispatchMessage(Handler.java:106)
01-07 15:12:08.835  8509  8509 E AndroidRuntime:    at android.os.Looper.loop(Looper.java:223)
01-07 15:12:08.835  8509  8509 E AndroidRuntime:    at android.app.ActivityThread.main(ActivityThread.java:7656)
01-07 15:12:08.835  8509  8509 E AndroidRuntime:    at java.lang.reflect.Method.invoke(Native Method)
01-07 15:12:08.835  8509  8509 E AndroidRuntime:    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
01-07 15:12:08.835  8509  8509 E AndroidRuntime:    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
01-07 15:12:08.835  8509  8509 E AndroidRuntime: Caused by: java.lang.NullPointerException: Bluetooth adapter cannot be null
01-07 15:12:08.835  8509  8509 E AndroidRuntime:    at java.util.Objects.requireNonNull(Objects.java:245)
01-07 15:12:08.835  8509  8509 E AndroidRuntime:    at com.android.car.CarBluetoothUserService.<init>(CarBluetoothUserService.java:84)
01-07 15:12:08.835  8509  8509 E AndroidRuntime:    at com.android.car.PerUserCarService.onCreate(PerUserCarService.java:66)
01-07 15:12:08.835  8509  8509 E AndroidRuntime:    at android.app.ActivityThread.handleCreateService(ActivityThread.java:4192)