diff options
author | Treehugger Robot <treehugger-gerrit@google.com> | 2022-01-21 21:03:02 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2022-01-21 21:03:02 +0000 |
commit | 673f938b00164e3f3cd40310176735fbb0b410ea (patch) | |
tree | 177f8906a1362f0d64887bf8abb8bd3094fb3e32 /framework/java/android/bluetooth/BluetoothLeAudio.java | |
parent | d945a2f8fe935c32ce0ca7d01883c2517464a7b7 (diff) | |
parent | 42f37e1c4b71f6622c1c28b7e9132bb977ae2b7b (diff) |
Merge "leaudio: Add method to get device group lead"
Diffstat (limited to 'framework/java/android/bluetooth/BluetoothLeAudio.java')
-rw-r--r-- | framework/java/android/bluetooth/BluetoothLeAudio.java | 39 |
1 files changed, 39 insertions, 0 deletions
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 |