diff options
3 files changed, 45 insertions, 11 deletions
diff --git a/android/app/src/com/android/bluetooth/le_audio/LeAudioService.java b/android/app/src/com/android/bluetooth/le_audio/LeAudioService.java index 812c021b09..fec11d32b9 100644 --- a/android/app/src/com/android/bluetooth/le_audio/LeAudioService.java +++ b/android/app/src/com/android/bluetooth/le_audio/LeAudioService.java @@ -364,13 +364,8 @@ public class LeAudioService extends ProfileService { } } - public List<BluetoothDevice> getConnectedGroupLeadDevices() { - List<BluetoothDevice> devices = new ArrayList<>(); - for (Map.Entry<Integer, LeAudioGroupDescriptor> entry : mGroupDescriptors.entrySet()) { - Integer groupId = entry.getKey(); - devices.add(getFirstDeviceFromGroup(groupId)); - } - return devices; + public BluetoothDevice getConnectedGroupLeadDevice(int groupId) { + return getFirstDeviceFromGroup(groupId); } List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states) { @@ -1321,13 +1316,13 @@ public class LeAudioService extends ProfileService { } @Override - public void getConnectedGroupLeadDevices(AttributionSource source, + public void getConnectedGroupLeadDevice(int groupId, AttributionSource source, SynchronousResultReceiver receiver) { try { LeAudioService service = getService(source); - List<BluetoothDevice> defaultValue = new ArrayList<>(0); + BluetoothDevice defaultValue = null; if (service != null) { - defaultValue = service.getConnectedGroupLeadDevices(); + defaultValue = service.getConnectedGroupLeadDevice(groupId); } receiver.send(defaultValue); } catch (RuntimeException e) { diff --git a/framework/java/android/bluetooth/BluetoothLeAudio.java b/framework/java/android/bluetooth/BluetoothLeAudio.java index 02df543445..0fda7e7a36 100644 --- a/framework/java/android/bluetooth/BluetoothLeAudio.java +++ b/framework/java/android/bluetooth/BluetoothLeAudio.java @@ -459,6 +459,45 @@ public final class BluetoothLeAudio implements BluetoothProfile, AutoCloseable { } /** + * Get lead device for a group. + * + * Lead device is the device that can be used as an active device in the system. + * Active devices points to the Audio Device for the Le Audio group. + * This method returns a list of Lead devices for all the connected LE Audio + * groups and those devices should be used in the setActiveDevice() method by other parts + * of the system, which wants to setActive a particular Le Audio Group. + * + * Note: getActiveDevice() returns the Lead device for the currently active LE Audio group. + * Note: When lead device gets disconnected, there will be new lead device for the group. + * + * @param groupId The group id. + * @return group lead device. + */ + @RequiresBluetoothConnectPermission + @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) + public @Nullable BluetoothDevice getConnectedGroupLeadDevice(int groupId) { + if (VDBG) log("getConnectedGroupLeadDevice()"); + final IBluetoothLeAudio service = getService(); + final BluetoothDevice defaultValue = null; + if (service == null) { + Log.w(TAG, "Proxy not attached to service"); + if (DBG) log(Log.getStackTraceString(new Throwable())); + } else if (mAdapter.isEnabled()) { + try { + final SynchronousResultReceiver<BluetoothDevice> recv = + new SynchronousResultReceiver(); + service.getConnectedGroupLeadDevice(groupId, mAttributionSource, recv); + return Attributable.setAttributionSource( + recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(defaultValue), + mAttributionSource); + } catch (RemoteException | TimeoutException e) { + Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable())); + } + } + return defaultValue; + } + + /** * {@inheritDoc} */ @Override diff --git a/system/binder/android/bluetooth/IBluetoothLeAudio.aidl b/system/binder/android/bluetooth/IBluetoothLeAudio.aidl index 15b82140c2..43969f7f54 100644 --- a/system/binder/android/bluetooth/IBluetoothLeAudio.aidl +++ b/system/binder/android/bluetooth/IBluetoothLeAudio.aidl @@ -48,7 +48,7 @@ oneway interface IBluetoothLeAudio { @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)") void getConnectionPolicy(in BluetoothDevice device, in AttributionSource attributionSource, in SynchronousResultReceiver receiver); @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)") - void getConnectedGroupLeadDevices(in AttributionSource attributionSource, in SynchronousResultReceiver receiver); + void getConnectedGroupLeadDevice(int groupId, in AttributionSource attributionSource, in SynchronousResultReceiver receiver); /* Same value as bluetooth::groups::kGroupUnknown */ const int LE_AUDIO_GROUP_ID_INVALID = -1; |
