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

Support operating Bluetooth LE Audio and HFP profiles #226

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

ko1in1u
Copy link
Collaborator

@ko1in1u ko1in1u commented Feb 18, 2025

  • getAudioDeviceTypes: For checking if a BLE Headset is connected to Android system.
  • btIsLeAudioSupported: For checking if LE Audio is supported.
  • btLeAudioGetConnectedDevices: For checking all devices connected via LE Audio profile.
  • btLeAudioConnect: : For connecting via LE Audio profile.
  • btLeAudioDisonnect: : For disconnecting from LE Audio profile.
  • btHfpConnect: : For connecting via HFP profile.
  • btHfpDisonnect: : For disconnecting from HFP profile.

See also #183 and #208


This change is Reviewable

- getAudioDeviceTypes: For checking if a BLE Headset is connected to
  Android system.
- btIsLeAudioSupported: For checking if LE Audio is supported.
- btLeAudioGetConnectedDevices: For checking all devices connected via
  LE Audio profile.
@ko1in1u ko1in1u self-assigned this Feb 18, 2025
@ko1in1u
Copy link
Collaborator Author

ko1in1u commented Feb 20, 2025

Update connect and disconnect methods.

@ko1in1u ko1in1u requested a review from mhaoli February 20, 2025 01:48
Copy link
Collaborator

@xpconanfan xpconanfan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't mix version bumping with feature additions.

I'm not sure whether this feature justifies bumping to 1.0 from 0.1 either.
So let's change the version code later.

description =
"Connects to a paired or discovered device with HEADSET profile."
+ "If a device has been discovered but not paired, this will pair it.")
public void btHfpConnect(String deviceAddress) throws Throwable {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not seem specific to LE audio?

Keep the code changes aligned with the PR descriptions.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated PR title and description to align the changes in this PR.

public BluetoothLeAudioSnippet() {
mContext = InstrumentationRegistry.getInstrumentation().getContext();
BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
bluetoothAdapter.getProfileProxy(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This getter call returns nothing?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is for starting BluetoothProfile.ServiceListener to get BluetoothLeAudio profile when it is registered.

BluetoothDevice device = BluetoothAdapterSnippet.getKnownDeviceByAddress(deviceAddress);
IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_PAIRING_REQUEST);
mContext.registerReceiver(new PairingBroadcastReceiver(mContext), filter);
Utils.invokeByReflection(sLeAudioProfile, "connect", device);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need reflection here?

Would this work on user builds?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the connect and disconnect methods are not public APIs, need to use reflection to call them at runtime.

I've tried user builds on Pixel and Samsung phones, the APIs can work.

@ko1in1u ko1in1u changed the title Support checking Bluetooth LE Audio status Support operating Bluetooth LE Audio and HFP profiles Feb 20, 2025
@ko1in1u ko1in1u requested a review from xpconanfan February 20, 2025 18:21
@ko1in1u
Copy link
Collaborator Author

ko1in1u commented Feb 20, 2025

Please don't mix version bumping with feature additions.

I'm not sure whether this feature justifies bumping to 1.0 from 0.1 either. So let's change the version code later.

Thanks for reminding, I've reverted the changes.

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

Successfully merging this pull request may close these issues.

2 participants