Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b50ef041 authored by Jack He's avatar Jack He Committed by Gerrit Code Review
Browse files

Merge "VolumeControl: Early return in registerCallback" into main

parents d6503c2b b6d8b917
Loading
Loading
Loading
Loading
+73 −84
Original line number Diff line number Diff line
@@ -476,9 +476,11 @@ public final class BluetoothVolumeControl implements BluetoothProfile, AutoClose
                throw new IllegalArgumentException("This callback has already been registered");
            }

            try {
            final IBluetoothVolumeControl service = getService();
                if (service != null) {
            if (service == null) {
                return;
            }
            try {
                final SynchronousResultReceiver<Integer> recv = SynchronousResultReceiver.get();

                /* If the callback map is empty, we register the service-to-app callback.
@@ -495,12 +497,9 @@ public final class BluetoothVolumeControl implements BluetoothProfile, AutoClose
                            new IBluetoothVolumeControlCallback.Stub() {
                                @Override
                                public void onVolumeOffsetChanged(
                                            BluetoothDevice device,
                                            int instanceId,
                                            int volumeOffset)
                                        BluetoothDevice device, int instanceId, int volumeOffset)
                                        throws RemoteException {
                                        Attributable.setAttributionSource(
                                                device, mAttributionSource);
                                    Attributable.setAttributionSource(device, mAttributionSource);

                                    // The old API operates on the first instance only
                                    if (instanceId == 1) {
@@ -518,9 +517,7 @@ public final class BluetoothVolumeControl implements BluetoothProfile, AutoClose
                                        executor.execute(
                                                () ->
                                                        callback.onVolumeOffsetChanged(
                                                                    device,
                                                                    instanceId,
                                                                    volumeOffset));
                                                                device, instanceId, volumeOffset));
                                    }
                                }

@@ -533,11 +530,8 @@ public final class BluetoothVolumeControl implements BluetoothProfile, AutoClose
                                                device, mAttributionSource);
                                        executor.execute(
                                                () ->
                                                            callback
                                                                    .onVolumeOffsetAudioLocationChanged(
                                                                            device,
                                                                            instanceId,
                                                                            location));
                                                        callback.onVolumeOffsetAudioLocationChanged(
                                                                device, instanceId, location));
                                    }
                                }

@@ -562,21 +556,16 @@ public final class BluetoothVolumeControl implements BluetoothProfile, AutoClose

                                @Override
                                public void onDeviceVolumeChanged(
                                            BluetoothDevice device, int volume)
                                            throws RemoteException {
                                        Attributable.setAttributionSource(
                                                device, mAttributionSource);
                                        BluetoothDevice device, int volume) throws RemoteException {
                                    Attributable.setAttributionSource(device, mAttributionSource);
                                    executor.execute(
                                                () ->
                                                        callback.onDeviceVolumeChanged(
                                                                device, volume));
                                            () -> callback.onDeviceVolumeChanged(device, volume));
                                }
                            },
                            mAttributionSource,
                            recv);
                }
                recv.awaitResultNoInterrupt(getSyncTimeout()).getValue(null);
                }
            } catch (RemoteException e) {
                mCallbackExecutorMap.remove(callback);
                Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable()));