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

Commit f1aa3eb0 authored by Łukasz Rymanowski's avatar Łukasz Rymanowski
Browse files

VolumeControl: Fix possible NPE

This could happen when Bluetooth is turning OFF while Connected event is
arriving to VolumeControlService

Bug: 311089115
Test: atest VolumeControlServiceTest
Tag: feature
Change-Id: I727adc481e115f27f6f177a776b2d90965cdc512
parent e6055d18
Loading
Loading
Loading
Loading
+20 −12
Original line number Diff line number Diff line
@@ -1366,10 +1366,12 @@ public class VolumeControlService extends ProfileService {
        } else if (toState == BluetoothProfile.STATE_CONNECTED) {
            // Restore the group volume if it was changed while the device was not yet connected.
            CsipSetCoordinatorService csipClient = mFactory.getCsipSetCoordinatorService();
            if (csipClient != null) {
                Integer groupId = csipClient.getGroupId(device, BluetoothUuid.CAP);
                if (groupId != IBluetoothCsipSetCoordinator.CSIS_GROUP_ID_INVALID) {
                Integer groupVolume = mGroupVolumeCache.getOrDefault(groupId,
                        IBluetoothVolumeControl.VOLUME_CONTROL_UNKNOWN_VOLUME);
                    Integer groupVolume =
                            mGroupVolumeCache.getOrDefault(
                                    groupId, IBluetoothVolumeControl.VOLUME_CONTROL_UNKNOWN_VOLUME);
                    if (groupVolume != IBluetoothVolumeControl.VOLUME_CONTROL_UNKNOWN_VOLUME) {
                        mVolumeControlNativeInterface.setVolume(device, groupVolume);
                    }
@@ -1381,6 +1383,12 @@ public class VolumeControlService extends ProfileService {
                        mVolumeControlNativeInterface.unmute(device);
                    }
                }
            } else {
                /* It could happen when Bluetooth is stopping while VC is getting
                 * connection event
                 */
                Log.w(TAG, "CSIP is not available");
            }
        }
        mAdapterService.handleProfileConnectionStateChange(
                BluetoothProfile.VOLUME_CONTROL, device, fromState, toState);