Loading flags/hap.aconfig +9 −0 Original line number Diff line number Diff line Loading @@ -25,3 +25,12 @@ flag { purpose: PURPOSE_BUGFIX } } flag { name: "aics_api" is_exported: true namespace: "bluetooth" description: "Expose new API to control AICS data" bug: "372328699" } framework/java/android/bluetooth/BluetoothVolumeControl.java +47 −107 Original line number Diff line number Diff line Loading @@ -61,8 +61,6 @@ import java.util.function.Consumer; @SystemApi public final class BluetoothVolumeControl implements BluetoothProfile, AutoCloseable { private static final String TAG = "BluetoothVolumeControl"; private static final boolean DBG = true; private static final boolean VDBG = false; private CloseGuard mCloseGuard; Loading Loading @@ -276,7 +274,7 @@ public final class BluetoothVolumeControl implements BluetoothProfile, AutoClose */ @Override public void close() { if (VDBG) log("close()"); Log.v(TAG, "close()"); mAdapter.closeProfileProxy(this); } Loading Loading @@ -326,18 +324,13 @@ public final class BluetoothVolumeControl implements BluetoothProfile, AutoClose */ @SystemApi @RequiresBluetoothConnectPermission @RequiresPermission( allOf = { BLUETOOTH_CONNECT, BLUETOOTH_PRIVILEGED, }) @RequiresPermission(allOf = {BLUETOOTH_CONNECT, BLUETOOTH_PRIVILEGED}) public @NonNull List<BluetoothDevice> getConnectedDevices() { if (DBG) log("getConnectedDevices()"); Log.d(TAG, "getConnectedDevices()"); final IBluetoothVolumeControl service = getService(); if (service == null) { Log.w(TAG, "Proxy not attached to service"); if (DBG) log(Log.getStackTraceString(new Throwable())); } else if (isEnabled()) { Log.d(TAG, "Proxy not attached to service" + Log.getStackTraceString(new Throwable())); } else if (mAdapter.isEnabled()) { try { return Attributable.setAttributionSource( service.getConnectedDevices(mAttributionSource), mAttributionSource); Loading @@ -357,12 +350,11 @@ public final class BluetoothVolumeControl implements BluetoothProfile, AutoClose @RequiresBluetoothConnectPermission @RequiresPermission(allOf = {BLUETOOTH_CONNECT, BLUETOOTH_PRIVILEGED}) public List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states) { if (DBG) log("getDevicesMatchingStates()"); Log.d(TAG, "getDevicesMatchingStates()"); final IBluetoothVolumeControl service = getService(); if (service == null) { Log.w(TAG, "Proxy not attached to service"); if (DBG) log(Log.getStackTraceString(new Throwable())); } else if (isEnabled()) { Log.d(TAG, "Proxy not attached to service" + Log.getStackTraceString(new Throwable())); } else if (mAdapter.isEnabled()) { try { return Attributable.setAttributionSource( service.getDevicesMatchingConnectionStates(states, mAttributionSource), Loading @@ -383,12 +375,11 @@ public final class BluetoothVolumeControl implements BluetoothProfile, AutoClose @RequiresBluetoothConnectPermission @RequiresPermission(BLUETOOTH_CONNECT) public int getConnectionState(BluetoothDevice device) { if (DBG) log("getConnectionState(" + device + ")"); Log.d(TAG, "getConnectionState(" + device + ")"); final IBluetoothVolumeControl service = getService(); if (service == null) { Log.w(TAG, "Proxy not attached to service"); if (DBG) log(Log.getStackTraceString(new Throwable())); } else if (isEnabled() && isValidDevice(device)) { Log.d(TAG, "Proxy not attached to service" + Log.getStackTraceString(new Throwable())); } else if (mAdapter.isEnabled() && isValidDevice(device)) { try { return service.getConnectionState(device, mAttributionSource); } catch (RemoteException e) { Loading @@ -413,16 +404,12 @@ public final class BluetoothVolumeControl implements BluetoothProfile, AutoClose */ @SystemApi @RequiresBluetoothConnectPermission @RequiresPermission( allOf = { BLUETOOTH_CONNECT, BLUETOOTH_PRIVILEGED, }) @RequiresPermission(allOf = {BLUETOOTH_CONNECT, BLUETOOTH_PRIVILEGED}) public void registerCallback( @NonNull @CallbackExecutor Executor executor, @NonNull Callback callback) { Objects.requireNonNull(executor, "executor cannot be null"); Objects.requireNonNull(callback, "callback cannot be null"); if (DBG) log("registerCallback"); Log.d(TAG, "registerCallback"); synchronized (mCallbackExecutorMap) { if (!mAdapter.isEnabled()) { /* If Bluetooth is off, just store callback and it will be registered Loading Loading @@ -477,14 +464,10 @@ public final class BluetoothVolumeControl implements BluetoothProfile, AutoClose */ @SystemApi @RequiresBluetoothConnectPermission @RequiresPermission( allOf = { BLUETOOTH_CONNECT, BLUETOOTH_PRIVILEGED, }) @RequiresPermission(allOf = {BLUETOOTH_CONNECT, BLUETOOTH_PRIVILEGED}) public void unregisterCallback(@NonNull Callback callback) { Objects.requireNonNull(callback, "callback cannot be null"); if (DBG) log("unregisterCallback"); Log.d(TAG, "unregisterCallback"); synchronized (mCallbackExecutorMap) { if (mCallbackExecutorMap.remove(callback) == null) { throw new IllegalArgumentException("This callback has not been registered"); Loading Loading @@ -518,11 +501,7 @@ public final class BluetoothVolumeControl implements BluetoothProfile, AutoClose @Deprecated @SystemApi @RequiresBluetoothConnectPermission @RequiresPermission( allOf = { BLUETOOTH_CONNECT, BLUETOOTH_PRIVILEGED, }) @RequiresPermission(allOf = {BLUETOOTH_CONNECT, BLUETOOTH_PRIVILEGED}) public void setVolumeOffset( @NonNull BluetoothDevice device, @IntRange(from = -255, to = 255) int volumeOffset) { final int defaultInstanceId = 1; Loading @@ -544,11 +523,7 @@ public final class BluetoothVolumeControl implements BluetoothProfile, AutoClose */ @SystemApi @RequiresBluetoothConnectPermission @RequiresPermission( allOf = { BLUETOOTH_CONNECT, BLUETOOTH_PRIVILEGED, }) @RequiresPermission(allOf = {BLUETOOTH_CONNECT, BLUETOOTH_PRIVILEGED}) public void setVolumeOffset( @NonNull BluetoothDevice device, @IntRange(from = 1, to = 255) int instanceId, Loading Loading @@ -576,8 +551,8 @@ public final class BluetoothVolumeControl implements BluetoothProfile, AutoClose @NonNull BluetoothDevice device, @IntRange(from = 1, to = 255) int instanceId, @IntRange(from = -255, to = 255) int volumeOffset) { if (DBG) { log( Log.d( TAG, "setVolumeOffset(" + device + "/" Loading @@ -585,12 +560,10 @@ public final class BluetoothVolumeControl implements BluetoothProfile, AutoClose + " volumeOffset: " + volumeOffset + ")"); } final IBluetoothVolumeControl service = getService(); if (service == null) { Log.w(TAG, "Proxy not attached to service"); if (DBG) log(Log.getStackTraceString(new Throwable())); } else if (isEnabled()) { Log.d(TAG, "Proxy not attached to service" + Log.getStackTraceString(new Throwable())); } else if (mAdapter.isEnabled()) { try { service.setVolumeOffset(device, instanceId, volumeOffset, mAttributionSource); } catch (RemoteException e) { Loading @@ -610,21 +583,16 @@ public final class BluetoothVolumeControl implements BluetoothProfile, AutoClose */ @SystemApi @RequiresBluetoothConnectPermission @RequiresPermission( allOf = { BLUETOOTH_CONNECT, BLUETOOTH_PRIVILEGED, }) @RequiresPermission(allOf = {BLUETOOTH_CONNECT, BLUETOOTH_PRIVILEGED}) public boolean isVolumeOffsetAvailable(@NonNull BluetoothDevice device) { if (DBG) log("isVolumeOffsetAvailable(" + device + ")"); Log.d(TAG, "isVolumeOffsetAvailable(" + device + ")"); final IBluetoothVolumeControl service = getService(); if (service == null) { Log.w(TAG, "Proxy not attached to service"); if (DBG) log(Log.getStackTraceString(new Throwable())); Log.d(TAG, "Proxy not attached to service" + Log.getStackTraceString(new Throwable())); return false; } if (!isEnabled()) { if (!mAdapter.isEnabled()) { return false; } Loading @@ -646,23 +614,18 @@ public final class BluetoothVolumeControl implements BluetoothProfile, AutoClose */ @SystemApi @RequiresBluetoothConnectPermission @RequiresPermission( allOf = { BLUETOOTH_CONNECT, BLUETOOTH_PRIVILEGED, }) @RequiresPermission(allOf = {BLUETOOTH_CONNECT, BLUETOOTH_PRIVILEGED}) public int getNumberOfVolumeOffsetInstances(@NonNull BluetoothDevice device) { if (DBG) log("getNumberOfVolumeOffsetInstances(" + device + ")"); Log.d(TAG, "getNumberOfVolumeOffsetInstances(" + device + ")"); final IBluetoothVolumeControl service = getService(); final int defaultValue = 0; if (service == null) { Log.w(TAG, "Proxy not attached to service"); if (DBG) log(Log.getStackTraceString(new Throwable())); Log.d(TAG, "Proxy not attached to service" + Log.getStackTraceString(new Throwable())); return defaultValue; } if (!isEnabled()) { if (!mAdapter.isEnabled()) { return defaultValue; } try { Loading @@ -688,19 +651,14 @@ public final class BluetoothVolumeControl implements BluetoothProfile, AutoClose */ @SystemApi @RequiresBluetoothConnectPermission @RequiresPermission( allOf = { BLUETOOTH_CONNECT, BLUETOOTH_PRIVILEGED, }) @RequiresPermission(allOf = {BLUETOOTH_CONNECT, BLUETOOTH_PRIVILEGED}) public boolean setConnectionPolicy( @NonNull BluetoothDevice device, @ConnectionPolicy int connectionPolicy) { if (DBG) log("setConnectionPolicy(" + device + ", " + connectionPolicy + ")"); Log.d(TAG, "setConnectionPolicy(" + device + ", " + connectionPolicy + ")"); final IBluetoothVolumeControl service = getService(); if (service == null) { Log.w(TAG, "Proxy not attached to service"); if (DBG) log(Log.getStackTraceString(new Throwable())); } else if (isEnabled() Log.d(TAG, "Proxy not attached to service" + Log.getStackTraceString(new Throwable())); } else if (mAdapter.isEnabled() && isValidDevice(device) && (connectionPolicy == BluetoothProfile.CONNECTION_POLICY_FORBIDDEN || connectionPolicy == BluetoothProfile.CONNECTION_POLICY_ALLOWED)) { Loading @@ -725,18 +683,13 @@ public final class BluetoothVolumeControl implements BluetoothProfile, AutoClose */ @SystemApi @RequiresBluetoothConnectPermission @RequiresPermission( allOf = { BLUETOOTH_CONNECT, BLUETOOTH_PRIVILEGED, }) @RequiresPermission(allOf = {BLUETOOTH_CONNECT, BLUETOOTH_PRIVILEGED}) public @ConnectionPolicy int getConnectionPolicy(@NonNull BluetoothDevice device) { if (VDBG) log("getConnectionPolicy(" + device + ")"); Log.v(TAG, "getConnectionPolicy(" + device + ")"); final IBluetoothVolumeControl service = getService(); if (service == null) { Log.w(TAG, "Proxy not attached to service"); if (DBG) log(Log.getStackTraceString(new Throwable())); } else if (isEnabled() && isValidDevice(device)) { Log.d(TAG, "Proxy not attached to service" + Log.getStackTraceString(new Throwable())); } else if (mAdapter.isEnabled() && isValidDevice(device)) { try { return service.getConnectionPolicy(device, mAttributionSource); } catch (RemoteException e) { Loading Loading @@ -767,11 +720,7 @@ public final class BluetoothVolumeControl implements BluetoothProfile, AutoClose @FlaggedApi(Flags.FLAG_LEAUDIO_BROADCAST_VOLUME_CONTROL_FOR_CONNECTED_DEVICES) @SystemApi @RequiresBluetoothConnectPermission @RequiresPermission( allOf = { BLUETOOTH_CONNECT, BLUETOOTH_PRIVILEGED, }) @RequiresPermission(allOf = {BLUETOOTH_CONNECT, BLUETOOTH_PRIVILEGED}) public void setDeviceVolume( @NonNull BluetoothDevice device, @IntRange(from = 0, to = 255) int volume, Loading @@ -781,9 +730,8 @@ public final class BluetoothVolumeControl implements BluetoothProfile, AutoClose } final IBluetoothVolumeControl service = getService(); if (service == null) { Log.w(TAG, "Proxy not attached to service"); if (DBG) log(Log.getStackTraceString(new Throwable())); } else if (isEnabled()) { Log.d(TAG, "Proxy not attached to service" + Log.getStackTraceString(new Throwable())); } else if (mAdapter.isEnabled()) { try { service.setDeviceVolume(device, volume, isGroupOperation, mAttributionSource); } catch (RemoteException e) { Loading @@ -792,15 +740,7 @@ public final class BluetoothVolumeControl implements BluetoothProfile, AutoClose } } private boolean isEnabled() { return mAdapter.getState() == BluetoothAdapter.STATE_ON; } private static boolean isValidDevice(@Nullable BluetoothDevice device) { return device != null && BluetoothAdapter.checkBluetoothAddress(device.getAddress()); } private static void log(String msg) { Log.d(TAG, msg); } } Loading
flags/hap.aconfig +9 −0 Original line number Diff line number Diff line Loading @@ -25,3 +25,12 @@ flag { purpose: PURPOSE_BUGFIX } } flag { name: "aics_api" is_exported: true namespace: "bluetooth" description: "Expose new API to control AICS data" bug: "372328699" }
framework/java/android/bluetooth/BluetoothVolumeControl.java +47 −107 Original line number Diff line number Diff line Loading @@ -61,8 +61,6 @@ import java.util.function.Consumer; @SystemApi public final class BluetoothVolumeControl implements BluetoothProfile, AutoCloseable { private static final String TAG = "BluetoothVolumeControl"; private static final boolean DBG = true; private static final boolean VDBG = false; private CloseGuard mCloseGuard; Loading Loading @@ -276,7 +274,7 @@ public final class BluetoothVolumeControl implements BluetoothProfile, AutoClose */ @Override public void close() { if (VDBG) log("close()"); Log.v(TAG, "close()"); mAdapter.closeProfileProxy(this); } Loading Loading @@ -326,18 +324,13 @@ public final class BluetoothVolumeControl implements BluetoothProfile, AutoClose */ @SystemApi @RequiresBluetoothConnectPermission @RequiresPermission( allOf = { BLUETOOTH_CONNECT, BLUETOOTH_PRIVILEGED, }) @RequiresPermission(allOf = {BLUETOOTH_CONNECT, BLUETOOTH_PRIVILEGED}) public @NonNull List<BluetoothDevice> getConnectedDevices() { if (DBG) log("getConnectedDevices()"); Log.d(TAG, "getConnectedDevices()"); final IBluetoothVolumeControl service = getService(); if (service == null) { Log.w(TAG, "Proxy not attached to service"); if (DBG) log(Log.getStackTraceString(new Throwable())); } else if (isEnabled()) { Log.d(TAG, "Proxy not attached to service" + Log.getStackTraceString(new Throwable())); } else if (mAdapter.isEnabled()) { try { return Attributable.setAttributionSource( service.getConnectedDevices(mAttributionSource), mAttributionSource); Loading @@ -357,12 +350,11 @@ public final class BluetoothVolumeControl implements BluetoothProfile, AutoClose @RequiresBluetoothConnectPermission @RequiresPermission(allOf = {BLUETOOTH_CONNECT, BLUETOOTH_PRIVILEGED}) public List<BluetoothDevice> getDevicesMatchingConnectionStates(int[] states) { if (DBG) log("getDevicesMatchingStates()"); Log.d(TAG, "getDevicesMatchingStates()"); final IBluetoothVolumeControl service = getService(); if (service == null) { Log.w(TAG, "Proxy not attached to service"); if (DBG) log(Log.getStackTraceString(new Throwable())); } else if (isEnabled()) { Log.d(TAG, "Proxy not attached to service" + Log.getStackTraceString(new Throwable())); } else if (mAdapter.isEnabled()) { try { return Attributable.setAttributionSource( service.getDevicesMatchingConnectionStates(states, mAttributionSource), Loading @@ -383,12 +375,11 @@ public final class BluetoothVolumeControl implements BluetoothProfile, AutoClose @RequiresBluetoothConnectPermission @RequiresPermission(BLUETOOTH_CONNECT) public int getConnectionState(BluetoothDevice device) { if (DBG) log("getConnectionState(" + device + ")"); Log.d(TAG, "getConnectionState(" + device + ")"); final IBluetoothVolumeControl service = getService(); if (service == null) { Log.w(TAG, "Proxy not attached to service"); if (DBG) log(Log.getStackTraceString(new Throwable())); } else if (isEnabled() && isValidDevice(device)) { Log.d(TAG, "Proxy not attached to service" + Log.getStackTraceString(new Throwable())); } else if (mAdapter.isEnabled() && isValidDevice(device)) { try { return service.getConnectionState(device, mAttributionSource); } catch (RemoteException e) { Loading @@ -413,16 +404,12 @@ public final class BluetoothVolumeControl implements BluetoothProfile, AutoClose */ @SystemApi @RequiresBluetoothConnectPermission @RequiresPermission( allOf = { BLUETOOTH_CONNECT, BLUETOOTH_PRIVILEGED, }) @RequiresPermission(allOf = {BLUETOOTH_CONNECT, BLUETOOTH_PRIVILEGED}) public void registerCallback( @NonNull @CallbackExecutor Executor executor, @NonNull Callback callback) { Objects.requireNonNull(executor, "executor cannot be null"); Objects.requireNonNull(callback, "callback cannot be null"); if (DBG) log("registerCallback"); Log.d(TAG, "registerCallback"); synchronized (mCallbackExecutorMap) { if (!mAdapter.isEnabled()) { /* If Bluetooth is off, just store callback and it will be registered Loading Loading @@ -477,14 +464,10 @@ public final class BluetoothVolumeControl implements BluetoothProfile, AutoClose */ @SystemApi @RequiresBluetoothConnectPermission @RequiresPermission( allOf = { BLUETOOTH_CONNECT, BLUETOOTH_PRIVILEGED, }) @RequiresPermission(allOf = {BLUETOOTH_CONNECT, BLUETOOTH_PRIVILEGED}) public void unregisterCallback(@NonNull Callback callback) { Objects.requireNonNull(callback, "callback cannot be null"); if (DBG) log("unregisterCallback"); Log.d(TAG, "unregisterCallback"); synchronized (mCallbackExecutorMap) { if (mCallbackExecutorMap.remove(callback) == null) { throw new IllegalArgumentException("This callback has not been registered"); Loading Loading @@ -518,11 +501,7 @@ public final class BluetoothVolumeControl implements BluetoothProfile, AutoClose @Deprecated @SystemApi @RequiresBluetoothConnectPermission @RequiresPermission( allOf = { BLUETOOTH_CONNECT, BLUETOOTH_PRIVILEGED, }) @RequiresPermission(allOf = {BLUETOOTH_CONNECT, BLUETOOTH_PRIVILEGED}) public void setVolumeOffset( @NonNull BluetoothDevice device, @IntRange(from = -255, to = 255) int volumeOffset) { final int defaultInstanceId = 1; Loading @@ -544,11 +523,7 @@ public final class BluetoothVolumeControl implements BluetoothProfile, AutoClose */ @SystemApi @RequiresBluetoothConnectPermission @RequiresPermission( allOf = { BLUETOOTH_CONNECT, BLUETOOTH_PRIVILEGED, }) @RequiresPermission(allOf = {BLUETOOTH_CONNECT, BLUETOOTH_PRIVILEGED}) public void setVolumeOffset( @NonNull BluetoothDevice device, @IntRange(from = 1, to = 255) int instanceId, Loading Loading @@ -576,8 +551,8 @@ public final class BluetoothVolumeControl implements BluetoothProfile, AutoClose @NonNull BluetoothDevice device, @IntRange(from = 1, to = 255) int instanceId, @IntRange(from = -255, to = 255) int volumeOffset) { if (DBG) { log( Log.d( TAG, "setVolumeOffset(" + device + "/" Loading @@ -585,12 +560,10 @@ public final class BluetoothVolumeControl implements BluetoothProfile, AutoClose + " volumeOffset: " + volumeOffset + ")"); } final IBluetoothVolumeControl service = getService(); if (service == null) { Log.w(TAG, "Proxy not attached to service"); if (DBG) log(Log.getStackTraceString(new Throwable())); } else if (isEnabled()) { Log.d(TAG, "Proxy not attached to service" + Log.getStackTraceString(new Throwable())); } else if (mAdapter.isEnabled()) { try { service.setVolumeOffset(device, instanceId, volumeOffset, mAttributionSource); } catch (RemoteException e) { Loading @@ -610,21 +583,16 @@ public final class BluetoothVolumeControl implements BluetoothProfile, AutoClose */ @SystemApi @RequiresBluetoothConnectPermission @RequiresPermission( allOf = { BLUETOOTH_CONNECT, BLUETOOTH_PRIVILEGED, }) @RequiresPermission(allOf = {BLUETOOTH_CONNECT, BLUETOOTH_PRIVILEGED}) public boolean isVolumeOffsetAvailable(@NonNull BluetoothDevice device) { if (DBG) log("isVolumeOffsetAvailable(" + device + ")"); Log.d(TAG, "isVolumeOffsetAvailable(" + device + ")"); final IBluetoothVolumeControl service = getService(); if (service == null) { Log.w(TAG, "Proxy not attached to service"); if (DBG) log(Log.getStackTraceString(new Throwable())); Log.d(TAG, "Proxy not attached to service" + Log.getStackTraceString(new Throwable())); return false; } if (!isEnabled()) { if (!mAdapter.isEnabled()) { return false; } Loading @@ -646,23 +614,18 @@ public final class BluetoothVolumeControl implements BluetoothProfile, AutoClose */ @SystemApi @RequiresBluetoothConnectPermission @RequiresPermission( allOf = { BLUETOOTH_CONNECT, BLUETOOTH_PRIVILEGED, }) @RequiresPermission(allOf = {BLUETOOTH_CONNECT, BLUETOOTH_PRIVILEGED}) public int getNumberOfVolumeOffsetInstances(@NonNull BluetoothDevice device) { if (DBG) log("getNumberOfVolumeOffsetInstances(" + device + ")"); Log.d(TAG, "getNumberOfVolumeOffsetInstances(" + device + ")"); final IBluetoothVolumeControl service = getService(); final int defaultValue = 0; if (service == null) { Log.w(TAG, "Proxy not attached to service"); if (DBG) log(Log.getStackTraceString(new Throwable())); Log.d(TAG, "Proxy not attached to service" + Log.getStackTraceString(new Throwable())); return defaultValue; } if (!isEnabled()) { if (!mAdapter.isEnabled()) { return defaultValue; } try { Loading @@ -688,19 +651,14 @@ public final class BluetoothVolumeControl implements BluetoothProfile, AutoClose */ @SystemApi @RequiresBluetoothConnectPermission @RequiresPermission( allOf = { BLUETOOTH_CONNECT, BLUETOOTH_PRIVILEGED, }) @RequiresPermission(allOf = {BLUETOOTH_CONNECT, BLUETOOTH_PRIVILEGED}) public boolean setConnectionPolicy( @NonNull BluetoothDevice device, @ConnectionPolicy int connectionPolicy) { if (DBG) log("setConnectionPolicy(" + device + ", " + connectionPolicy + ")"); Log.d(TAG, "setConnectionPolicy(" + device + ", " + connectionPolicy + ")"); final IBluetoothVolumeControl service = getService(); if (service == null) { Log.w(TAG, "Proxy not attached to service"); if (DBG) log(Log.getStackTraceString(new Throwable())); } else if (isEnabled() Log.d(TAG, "Proxy not attached to service" + Log.getStackTraceString(new Throwable())); } else if (mAdapter.isEnabled() && isValidDevice(device) && (connectionPolicy == BluetoothProfile.CONNECTION_POLICY_FORBIDDEN || connectionPolicy == BluetoothProfile.CONNECTION_POLICY_ALLOWED)) { Loading @@ -725,18 +683,13 @@ public final class BluetoothVolumeControl implements BluetoothProfile, AutoClose */ @SystemApi @RequiresBluetoothConnectPermission @RequiresPermission( allOf = { BLUETOOTH_CONNECT, BLUETOOTH_PRIVILEGED, }) @RequiresPermission(allOf = {BLUETOOTH_CONNECT, BLUETOOTH_PRIVILEGED}) public @ConnectionPolicy int getConnectionPolicy(@NonNull BluetoothDevice device) { if (VDBG) log("getConnectionPolicy(" + device + ")"); Log.v(TAG, "getConnectionPolicy(" + device + ")"); final IBluetoothVolumeControl service = getService(); if (service == null) { Log.w(TAG, "Proxy not attached to service"); if (DBG) log(Log.getStackTraceString(new Throwable())); } else if (isEnabled() && isValidDevice(device)) { Log.d(TAG, "Proxy not attached to service" + Log.getStackTraceString(new Throwable())); } else if (mAdapter.isEnabled() && isValidDevice(device)) { try { return service.getConnectionPolicy(device, mAttributionSource); } catch (RemoteException e) { Loading Loading @@ -767,11 +720,7 @@ public final class BluetoothVolumeControl implements BluetoothProfile, AutoClose @FlaggedApi(Flags.FLAG_LEAUDIO_BROADCAST_VOLUME_CONTROL_FOR_CONNECTED_DEVICES) @SystemApi @RequiresBluetoothConnectPermission @RequiresPermission( allOf = { BLUETOOTH_CONNECT, BLUETOOTH_PRIVILEGED, }) @RequiresPermission(allOf = {BLUETOOTH_CONNECT, BLUETOOTH_PRIVILEGED}) public void setDeviceVolume( @NonNull BluetoothDevice device, @IntRange(from = 0, to = 255) int volume, Loading @@ -781,9 +730,8 @@ public final class BluetoothVolumeControl implements BluetoothProfile, AutoClose } final IBluetoothVolumeControl service = getService(); if (service == null) { Log.w(TAG, "Proxy not attached to service"); if (DBG) log(Log.getStackTraceString(new Throwable())); } else if (isEnabled()) { Log.d(TAG, "Proxy not attached to service" + Log.getStackTraceString(new Throwable())); } else if (mAdapter.isEnabled()) { try { service.setDeviceVolume(device, volume, isGroupOperation, mAttributionSource); } catch (RemoteException e) { Loading @@ -792,15 +740,7 @@ public final class BluetoothVolumeControl implements BluetoothProfile, AutoClose } } private boolean isEnabled() { return mAdapter.getState() == BluetoothAdapter.STATE_ON; } private static boolean isValidDevice(@Nullable BluetoothDevice device) { return device != null && BluetoothAdapter.checkBluetoothAddress(device.getAddress()); } private static void log(String msg) { Log.d(TAG, msg); } }