From bc3859a4821e450b69f2f32005010562381b5d05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Rymanowski?= Date: Fri, 8 Oct 2021 20:19:12 +0000 Subject: [PATCH] leaudio: Add set volume API Bug: 150670922 Tag: #feature Sponsor: jpawlowski@ Test: Manual Change-Id: Icb2e7681e4b5e7ba2e796671ff6f4c59bbff29d7 --- .../android/bluetooth/BluetoothLeAudio.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/core/java/android/bluetooth/BluetoothLeAudio.java b/core/java/android/bluetooth/BluetoothLeAudio.java index 41617000805f4..a139eba34518c 100644 --- a/core/java/android/bluetooth/BluetoothLeAudio.java +++ b/core/java/android/bluetooth/BluetoothLeAudio.java @@ -511,6 +511,30 @@ public final class BluetoothLeAudio implements BluetoothProfile, AutoCloseable { } } + /** + * Set volume for the streaming devices + * + * @param volume volume to set + * @hide + */ + @RequiresBluetoothConnectPermission + @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) + public void setVolume(int volume) { + if (VDBG) log("setVolume(vol: " + volume + " )"); + try { + final IBluetoothLeAudio service = getService(); + if (service != null && mAdapter.isEnabled()) { + service.setVolume(volume, mAttributionSource); + return; + } + if (service == null) Log.w(TAG, "Proxy not attached to service"); + return; + } catch (RemoteException e) { + Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable())); + return; + } + } + /** * Set connection policy of the profile *