Loading android/app/src/com/android/bluetooth/vc/VolumeControlService.java +49 −35 Original line number Diff line number Diff line Loading @@ -269,15 +269,33 @@ public class VolumeControlService extends ProfileService { } public List<BluetoothDevice> getConnectedDevices() { synchronized (mStateMachines) { List<BluetoothDevice> devices = new ArrayList<>(); synchronized (mStateMachines) { for (VolumeControlStateMachine sm : mStateMachines.values()) { if (sm.isConnected()) { devices.add(sm.getDevice()); } } } return devices; } private List<BluetoothDevice> getConnectedDevices(int groupId) { List<BluetoothDevice> devices = new ArrayList<>(); LeAudioService leAudioService = mFactory.getLeAudioService(); if (leAudioService == null) { Log.e(TAG, "leAudioService not available"); return devices; } synchronized (mStateMachines) { for (BluetoothDevice dev : leAudioService.getGroupDevices(groupId)) { VolumeControlStateMachine sm = mStateMachines.get(dev); if (sm != null && sm.isConnected()) { devices.add(sm.getDevice()); } } } return devices; } /** Loading Loading @@ -460,13 +478,13 @@ public class VolumeControlService extends ProfileService { TAG, "setDeviceVolume: " + device + ", volume: " + volume + ", isGroupOp: " + isGroupOp); if (isGroupOp) { LeAudioService leAudioService = mFactory.getLeAudioService(); if (leAudioService == null) { Log.e(TAG, "leAudioService not available"); return; } if (isGroupOp) { int groupId = leAudioService.getGroupId(device); if (groupId == IBluetoothLeAudio.LE_AUDIO_GROUP_ID_INVALID) { Log.e(TAG, "Device not a part of a group"); Loading @@ -482,6 +500,8 @@ public class VolumeControlService extends ProfileService { } public void setGroupVolume(int groupId, int volume) { Log.d(TAG, "setGroupVolume: " + groupId + ", volume: " + volume); if (volume < 0) { Log.w(TAG, "Tried to set invalid volume " + volume + ". Ignored."); return; Loading Loading @@ -658,22 +678,12 @@ public class VolumeControlService extends ProfileService { if (sm == null) { return; } if (sm.getConnectionState() != STATE_CONNECTED) { if (!sm.isConnected()) { return; } } // Correct the volume level only if device was already reported as connected. boolean can_change_volume = false; synchronized (mStateMachines) { VolumeControlStateMachine sm = mStateMachines.get(device); if (sm != null) { can_change_volume = (sm.getConnectionState() == STATE_CONNECTED); } } // If group volume has already changed, the new group member should set it if (can_change_volume) { Integer groupVolume = mGroupVolumeCache.getOrDefault( groupId, IBluetoothVolumeControl.VOLUME_CONTROL_UNKNOWN_VOLUME); Loading @@ -690,7 +700,6 @@ public class VolumeControlService extends ProfileService { mNativeInterface.unmute(device); } } } void updateGroupCacheAndAudioSystem(int groupId, int volume, boolean mute, boolean showInUI) { Log.d( Loading Loading @@ -797,7 +806,7 @@ public class VolumeControlService extends ProfileService { * Note, to match BR/EDR behavior, don't show volume change in UI here */ if (((flags & VOLUME_FLAGS_PERSISTED_USER_SET_VOLUME_MASK) == 0x01) && (getConnectedDevices().size() == 1)) { && (getConnectedDevices(groupId).size() == 1)) { updateGroupCacheAndAudioSystem(groupId, volume, mute, false); return; } Loading @@ -815,7 +824,12 @@ public class VolumeControlService extends ProfileService { return; } Log.i(TAG, "handleVolumeControlChanged: " + device + "; volume: " + volume); Log.i( TAG, "handleVolumeControlChanged: " + ("device: " + device) + (", groupId: " + groupId) + (", volume: " + volume)); if (device == null) { // notify group devices volume changed LeAudioService leAudioService = mFactory.getLeAudioService(); Loading Loading @@ -854,7 +868,7 @@ public class VolumeControlService extends ProfileService { synchronized (mStateMachines) { VolumeControlStateMachine sm = mStateMachines.get(device); if (sm != null) { can_change_volume = (sm.getConnectionState() == STATE_CONNECTED); can_change_volume = sm.isConnected(); } } Loading android/app/src/com/android/bluetooth/vc/VolumeControlStateMachine.java +4 −4 Original line number Diff line number Diff line Loading @@ -158,7 +158,7 @@ class VolumeControlStateMachine extends StateMachine { processConnectionEvent(event.valueInt1); } default -> { Log.e(TAG, "Disconnected: forwarding stack event: " + event); Log.d(TAG, "Disconnected: forwarding stack event: " + event); mService.handleStackEvent(event); } } Loading Loading @@ -270,7 +270,7 @@ class VolumeControlStateMachine extends StateMachine { deferMessage(message); } default -> { Log.e(TAG, "Connecting: forwarding stack event: " + event); Log.d(TAG, "Connecting: forwarding stack event: " + event); mService.handleStackEvent(event); } } Loading Loading @@ -366,7 +366,7 @@ class VolumeControlStateMachine extends StateMachine { processConnectionEvent(event.valueInt1); } default -> { Log.e(TAG, "Disconnecting: forwarding stack event: " + event); Log.d(TAG, "Disconnecting: forwarding stack event: " + event); mService.handleStackEvent(event); } } Loading Loading @@ -465,7 +465,7 @@ class VolumeControlStateMachine extends StateMachine { processConnectionEvent(event.valueInt1); } default -> { Log.e(TAG, "Connected: forwarding stack event: " + event); Log.d(TAG, "Connected: forwarding stack event: " + event); mService.handleStackEvent(event); } } Loading android/app/tests/unit/src/com/android/bluetooth/vc/VolumeControlServiceTest.java +2 −2 Original line number Diff line number Diff line Loading @@ -589,8 +589,8 @@ public class VolumeControlServiceTest { boolean initialAutonomousFlag = true; // Both devices are in the same group when(mCsipService.getGroupId(mDevice, BluetoothUuid.CAP)).thenReturn(groupId); when(mCsipService.getGroupId(mDeviceTwo, BluetoothUuid.CAP)).thenReturn(groupId); when(mLeAudioService.getGroupDevices(groupId)) .thenReturn(Arrays.asList(mDevice, mDeviceTwo)); generateDeviceAvailableMessageFromNative(mDevice, 1); generateConnectionMessageFromNative(mDevice, STATE_CONNECTED, STATE_DISCONNECTED); Loading Loading
android/app/src/com/android/bluetooth/vc/VolumeControlService.java +49 −35 Original line number Diff line number Diff line Loading @@ -269,15 +269,33 @@ public class VolumeControlService extends ProfileService { } public List<BluetoothDevice> getConnectedDevices() { synchronized (mStateMachines) { List<BluetoothDevice> devices = new ArrayList<>(); synchronized (mStateMachines) { for (VolumeControlStateMachine sm : mStateMachines.values()) { if (sm.isConnected()) { devices.add(sm.getDevice()); } } } return devices; } private List<BluetoothDevice> getConnectedDevices(int groupId) { List<BluetoothDevice> devices = new ArrayList<>(); LeAudioService leAudioService = mFactory.getLeAudioService(); if (leAudioService == null) { Log.e(TAG, "leAudioService not available"); return devices; } synchronized (mStateMachines) { for (BluetoothDevice dev : leAudioService.getGroupDevices(groupId)) { VolumeControlStateMachine sm = mStateMachines.get(dev); if (sm != null && sm.isConnected()) { devices.add(sm.getDevice()); } } } return devices; } /** Loading Loading @@ -460,13 +478,13 @@ public class VolumeControlService extends ProfileService { TAG, "setDeviceVolume: " + device + ", volume: " + volume + ", isGroupOp: " + isGroupOp); if (isGroupOp) { LeAudioService leAudioService = mFactory.getLeAudioService(); if (leAudioService == null) { Log.e(TAG, "leAudioService not available"); return; } if (isGroupOp) { int groupId = leAudioService.getGroupId(device); if (groupId == IBluetoothLeAudio.LE_AUDIO_GROUP_ID_INVALID) { Log.e(TAG, "Device not a part of a group"); Loading @@ -482,6 +500,8 @@ public class VolumeControlService extends ProfileService { } public void setGroupVolume(int groupId, int volume) { Log.d(TAG, "setGroupVolume: " + groupId + ", volume: " + volume); if (volume < 0) { Log.w(TAG, "Tried to set invalid volume " + volume + ". Ignored."); return; Loading Loading @@ -658,22 +678,12 @@ public class VolumeControlService extends ProfileService { if (sm == null) { return; } if (sm.getConnectionState() != STATE_CONNECTED) { if (!sm.isConnected()) { return; } } // Correct the volume level only if device was already reported as connected. boolean can_change_volume = false; synchronized (mStateMachines) { VolumeControlStateMachine sm = mStateMachines.get(device); if (sm != null) { can_change_volume = (sm.getConnectionState() == STATE_CONNECTED); } } // If group volume has already changed, the new group member should set it if (can_change_volume) { Integer groupVolume = mGroupVolumeCache.getOrDefault( groupId, IBluetoothVolumeControl.VOLUME_CONTROL_UNKNOWN_VOLUME); Loading @@ -690,7 +700,6 @@ public class VolumeControlService extends ProfileService { mNativeInterface.unmute(device); } } } void updateGroupCacheAndAudioSystem(int groupId, int volume, boolean mute, boolean showInUI) { Log.d( Loading Loading @@ -797,7 +806,7 @@ public class VolumeControlService extends ProfileService { * Note, to match BR/EDR behavior, don't show volume change in UI here */ if (((flags & VOLUME_FLAGS_PERSISTED_USER_SET_VOLUME_MASK) == 0x01) && (getConnectedDevices().size() == 1)) { && (getConnectedDevices(groupId).size() == 1)) { updateGroupCacheAndAudioSystem(groupId, volume, mute, false); return; } Loading @@ -815,7 +824,12 @@ public class VolumeControlService extends ProfileService { return; } Log.i(TAG, "handleVolumeControlChanged: " + device + "; volume: " + volume); Log.i( TAG, "handleVolumeControlChanged: " + ("device: " + device) + (", groupId: " + groupId) + (", volume: " + volume)); if (device == null) { // notify group devices volume changed LeAudioService leAudioService = mFactory.getLeAudioService(); Loading Loading @@ -854,7 +868,7 @@ public class VolumeControlService extends ProfileService { synchronized (mStateMachines) { VolumeControlStateMachine sm = mStateMachines.get(device); if (sm != null) { can_change_volume = (sm.getConnectionState() == STATE_CONNECTED); can_change_volume = sm.isConnected(); } } Loading
android/app/src/com/android/bluetooth/vc/VolumeControlStateMachine.java +4 −4 Original line number Diff line number Diff line Loading @@ -158,7 +158,7 @@ class VolumeControlStateMachine extends StateMachine { processConnectionEvent(event.valueInt1); } default -> { Log.e(TAG, "Disconnected: forwarding stack event: " + event); Log.d(TAG, "Disconnected: forwarding stack event: " + event); mService.handleStackEvent(event); } } Loading Loading @@ -270,7 +270,7 @@ class VolumeControlStateMachine extends StateMachine { deferMessage(message); } default -> { Log.e(TAG, "Connecting: forwarding stack event: " + event); Log.d(TAG, "Connecting: forwarding stack event: " + event); mService.handleStackEvent(event); } } Loading Loading @@ -366,7 +366,7 @@ class VolumeControlStateMachine extends StateMachine { processConnectionEvent(event.valueInt1); } default -> { Log.e(TAG, "Disconnecting: forwarding stack event: " + event); Log.d(TAG, "Disconnecting: forwarding stack event: " + event); mService.handleStackEvent(event); } } Loading Loading @@ -465,7 +465,7 @@ class VolumeControlStateMachine extends StateMachine { processConnectionEvent(event.valueInt1); } default -> { Log.e(TAG, "Connected: forwarding stack event: " + event); Log.d(TAG, "Connected: forwarding stack event: " + event); mService.handleStackEvent(event); } } Loading
android/app/tests/unit/src/com/android/bluetooth/vc/VolumeControlServiceTest.java +2 −2 Original line number Diff line number Diff line Loading @@ -589,8 +589,8 @@ public class VolumeControlServiceTest { boolean initialAutonomousFlag = true; // Both devices are in the same group when(mCsipService.getGroupId(mDevice, BluetoothUuid.CAP)).thenReturn(groupId); when(mCsipService.getGroupId(mDeviceTwo, BluetoothUuid.CAP)).thenReturn(groupId); when(mLeAudioService.getGroupDevices(groupId)) .thenReturn(Arrays.asList(mDevice, mDeviceTwo)); generateDeviceAvailableMessageFromNative(mDevice, 1); generateConnectionMessageFromNative(mDevice, STATE_CONNECTED, STATE_DISCONNECTED); Loading