diff --git a/framework/java/android/bluetooth/BluetoothVolumeControl.java b/framework/java/android/bluetooth/BluetoothVolumeControl.java index cffce77e95e062175d7b9e2ff19942589528538f..76c92ed2b63a366a1b98832d399ca413ffd5284f 100644 --- a/framework/java/android/bluetooth/BluetoothVolumeControl.java +++ b/framework/java/android/bluetooth/BluetoothVolumeControl.java @@ -604,21 +604,23 @@ public final class BluetoothVolumeControl implements BluetoothProfile, AutoClose } } + if (!mCallbackExecutorMap.isEmpty()) { + return; + } + // If the callback map is empty, we unregister the service-to-app callback - if (mCallbackExecutorMap.isEmpty()) { - try { - final IBluetoothVolumeControl service = getService(); - if (service != null) { - final SynchronousResultReceiver<Integer> recv = SynchronousResultReceiver.get(); - service.unregisterCallback(mCallback, mAttributionSource, recv); - recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(null); - } - } catch (RemoteException e) { - Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable())); - throw e.rethrowAsRuntimeException(); - } catch (IllegalStateException | TimeoutException e) { - Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable())); + try { + final IBluetoothVolumeControl service = getService(); + if (service != null) { + final SynchronousResultReceiver<Integer> recv = SynchronousResultReceiver.get(); + service.unregisterCallback(mCallback, mAttributionSource, recv); + recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(null); } + } catch (RemoteException e) { + Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable())); + throw e.rethrowAsRuntimeException(); + } catch (IllegalStateException | TimeoutException e) { + Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable())); } }