Skip to content
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

Android Studio Emulator Bluetooth not working #331

Open
McMelonTV opened this issue Nov 12, 2023 · 10 comments
Open

Android Studio Emulator Bluetooth not working #331

McMelonTV opened this issue Nov 12, 2023 · 10 comments

Comments

@McMelonTV
Copy link

Hi, I tried to get bluetooth to work through bumble in my android emulator so I followed the instructions at https://google.github.io/bumble/platforms/android.html#connecting-a-custom-virtual-controller but I am having a problem where the bluetooth mac address just switches back and forth from 00:00:00:00:00:00 to unavailable and the bluetooth is just constantly turning on and off. I'm not sure whether I messed up or if it's an issue with my bluetooth dongle or if it's a bug. Any help would be appreciated

Code_Ugy533qzKT.mp4
@McMelonTV
Copy link
Author

Oh also, I'm using windows 10 if that matters

@McMelonTV
Copy link
Author

I managed to get the mac address to work by following these instructions instead https://google.github.io/bumble/platforms/android.html#connecting-to-netsim but it still cant find any available devices

@barbibulle
Copy link
Collaborator

Hi. Which version of the emulator are you using? (you can see it from the 'SDK Tools' tab in the 'SDK Manager' window from Android Studio). One thing you may want to try also is to start the Bumble HCI bridge first, then boot/reboot the emulator. This will ensure that you start with a fresh Android Bluetooth stack, in case toggling BT on/off doesn't completely clean the state.
Also, the second thing you've tried (connecting to netsim) is a different mode: that won't allow you to connect to a physical USB dongle. Netsim behaves as a virtual BT radio. You can connect multiple virtual devices to netsim, including the Android emulator as well as Bumble virtual devices/apps, but you can't bridge the netsim virtual radio and a USB physical radio. It's either or. In summary: either 1: Android <-> HCI-bridge <-> USB dongle <-> physical device. (that's the "controller" mode you tried first), or 2: Android <-> Netsim <-> Some other virtual device (that's the second case here).

@McMelonTV
Copy link
Author

Ohhh, that makes sense. I use emulator version 34.1.10 and I have tried starting the HCI bridge before starting the emulator but that resulted in the same weird null mac.

@McMelonTV
Copy link
Author

In the emulator I use this OS version
image

@barbibulle
Copy link
Collaborator

I have tried to replicate this issue, but wasn't able to so far. I'm running version 34.1.11 of the emulator, but that shouldn't make a big difference. Running on a mac, the emulator does connect to my USB dongle via a Bumble HCI bridge, and I can scan/connect to local devices. Just to be sure we're looking at the same thing, could you try updating to version 34.1.11 of the emulator and trying again?

@Shmuel930
Copy link

Shmuel930 commented Dec 26, 2023

I have tried to replicate this issue but wasn't able to so far. I'm running version 34.1.11 of the emulator, but that shouldn't make a big difference. Running on a Mac, the emulator does connect to my USB dongle via a Bumble HCI bridge, and I can scan/connect to local devices. Just to be sure we're looking at the same thing, could you try updating to version 34.1.11 of the emulator and trying again?

Hey, joining to the question here.
I'm also trying to get my Android emulator to work with Bluetooth.
I have a physical Bluetooth dongle that is connected to my MacBook (via a small adapter from USB 2.0 -> Type C)

I can see the details of the dongle when running lsusb
"Bus 002 Device 002: ID 0bda:8771 Realtek Semiconductor Corp. Bluetooth Radio Serial: 00E04C239987"

But I'm still getting the same issue that the guy who posted this question got.
I'm running
bumble-hci-bridge android-netsim:_:8877,mode=controller usb:0

Then run the emulator on another shell like that:
emulator -packet-streamer-endpoint localhost:8877 -avd Pixel_6_API_33 -no-snapshot-load

It seems like when the phone boot, the hci-bridge console starts printing lots of messages (like in the video of the question)
but I can't find any device when I try to discover it.

my emulator version is 33.1.23.0 and I can't see a way to update it (when I click "check for updates" Android Studio tells me there is no update pending)

Would you be able to regrade this?

EDIT: I've tried to manually download android emulator (with your version, 34.4.11, same issue)

@barbibulle
Copy link
Collaborator

The issue here may be that the USB dongle you’re using may need a special driver to load a binary firmware image/patch to it. Bumble does include such a driver for Realtek devices, but that works when you use the Bumble stack with the USB dongle. In your case, the Bumble host stack isn’t used, but the Android host stack is used instead, only using the HCI transport part of the Bumble library. The Android host stack doesn’t know how to initialize the dongle by loading FW into it.
however, it should be possible to use Bumble’s bumble-rtk-util tool to load the FW, then start the HCI bridge. The FW should stay loaded until you unpower/unplug the dongle. See https://google.github.io/bumble/drivers/realtek.html for details on how to obtain the FW files and use the comma and line tool.

@Shmuel930
Copy link

The issue here may be that the USB dongle you’re using may need a special driver to load a binary firmware image/patch to it. Bumble does include such a driver for Realtek devices, but that works when you use the Bumble stack with the USB dongle. In your case, the Bumble host stack isn’t used, but the Android host stack is used instead, only using the HCI transport part of the Bumble library. The Android host stack doesn’t know how to initialize the dongle by loading FW into it. however, it should be possible to use Bumble’s bumble-rtk-util tool to load the FW, then start the HCI bridge. The FW should stay loaded until you unpower/unplug the dongle. See https://google.github.io/bumble/drivers/realtek.html for details on how to obtain the FW files and use the comma and line tool.

Thank you so much, it worked :)

@stalniy
Copy link

stalniy commented Apr 1, 2024

I'm in the same situation. Bridge console shows found Bleutooth devices, but Android emulator doesn't see anything:

$ sudo  python tools/rtk_util.py  info usb:0
Driver:
  ROM:      8761
  Firmware: rtl8761bu_fw.bin
  Config:   rtl8761bu_config.bin

$ sudo  python tools/rtk_util.py  load usb:0
<no output>

$ sudo python apps/hci_bridge.py android-netsim:_:8877,mode=controller usb:0
>>> connecting to HCI...
>>> connected
>>> connecting to HCI...
>>> connected

Then I do

emulator -packet-streamer-endpoint localhost:8877 -avd Pixel_3a_API_34_extension_level_7_x86_64 -no-snapshot-load

Then I see discovered by Bluetooth devices in my computer terminal:

INFO:bumble.bridge:[CONTROLLER->HOST] HCI_LE_EXTENDED_ADVERTISING_REPORT_EVENT:
0:
  event_type:                    0x0010 [LEGACY_ADVERTISING_PDU_USED,COMPLETE](ADV_NONCONN_IND)
  address_type:                  PUBLIC_DEVICE_ADDRESS
  address:                       38:98:00:00:62:20/P
  primary_phy:                   LE 1M
  secondary_phy:                 0
  advertising_sid:               255
  tx_power:                      127
  rssi:                          -66
  periodic_advertising_interval: 0
  direct_address_type:           PUBLIC_DEVICE_ADDRESS
  direct_address:                00:00:00:00:00:00/P
  data:                          [Complete List of 16-bit Service Class UUIDs]: UUID-16:27A5, [Shortened Local Name]: "BR", [Manufacturer Specific Data]: company=0x1E28, data=1b015135e0

but it seems emulator doesn't see anything. however I can discover it from my iPhone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants