diff --git a/src/com/android/settings/bluetooth/AvailableMediaBluetoothDeviceUpdater.java b/src/com/android/settings/bluetooth/AvailableMediaBluetoothDeviceUpdater.java index bd160e17527..dab696e5e0b 100644 --- a/src/com/android/settings/bluetooth/AvailableMediaBluetoothDeviceUpdater.java +++ b/src/com/android/settings/bluetooth/AvailableMediaBluetoothDeviceUpdater.java @@ -79,7 +79,8 @@ public class AvailableMediaBluetoothDeviceUpdater extends BluetoothDeviceUpdater // If device is LE Audio, it is compatible with HFP and A2DP. // It would show in Available Devices group if the audio sharing flag is disabled or // the device is not in the audio sharing session. - if (cachedDevice.isConnectedLeAudioDevice()) { + if (cachedDevice.isConnectedLeAudioDevice() + || cachedDevice.hasConnectedLeAudioMemberDevice()) { if (BluetoothUtils.isAudioSharingUIAvailable(mContext) && BluetoothUtils.hasConnectedBroadcastSource( cachedDevice, mLocalBtManager)) { diff --git a/src/com/android/settings/bluetooth/ConnectedBluetoothDeviceUpdater.java b/src/com/android/settings/bluetooth/ConnectedBluetoothDeviceUpdater.java index 7cc874caba9..a0f5ea23050 100644 --- a/src/com/android/settings/bluetooth/ConnectedBluetoothDeviceUpdater.java +++ b/src/com/android/settings/bluetooth/ConnectedBluetoothDeviceUpdater.java @@ -77,7 +77,12 @@ public class ConnectedBluetoothDeviceUpdater extends BluetoothDeviceUpdater { // If device is Hearing Aid or LE Audio, it is compatible with HFP and A2DP. // It would not show in Connected Devices group. if (cachedDevice.isConnectedAshaHearingAidDevice() - || cachedDevice.isConnectedLeAudioDevice()) { + || cachedDevice.isConnectedLeAudioDevice() + || cachedDevice.hasConnectedLeAudioMemberDevice()) { + if (DBG) { + Log.d(TAG, "isFilterMatched() device : " + cachedDevice.getName() + + ", isFilterMatched : false, ha or lea device"); + } return false; } // According to the current audio profile type, diff --git a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingBluetoothDeviceUpdater.java b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingBluetoothDeviceUpdater.java index e5b984d707c..884c7813434 100644 --- a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingBluetoothDeviceUpdater.java +++ b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingBluetoothDeviceUpdater.java @@ -56,7 +56,8 @@ public class AudioSharingBluetoothDeviceUpdater extends BluetoothDeviceUpdater // If device is LE audio device and has a broadcast source, // it would show in audio sharing devices group. if (BluetoothUtils.isAudioSharingUIAvailable(mContext) - && cachedDevice.isConnectedLeAudioDevice() + && (cachedDevice.isConnectedLeAudioDevice() + || cachedDevice.hasConnectedLeAudioMemberDevice()) && BluetoothUtils.hasConnectedBroadcastSource(cachedDevice, mLocalBtManager)) { isFilterMatched = true; } diff --git a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDeviceVolumeControlUpdater.java b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDeviceVolumeControlUpdater.java index 548d17cc9ce..7f12ec84b3b 100644 --- a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDeviceVolumeControlUpdater.java +++ b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDeviceVolumeControlUpdater.java @@ -62,7 +62,8 @@ public class AudioSharingDeviceVolumeControlUpdater extends BluetoothDeviceUpdat if (isDeviceConnected(cachedDevice) && isDeviceInCachedDevicesList(cachedDevice)) { // If device is LE audio device and in a sharing session on current sharing device, // it would show in volume control group. - if (cachedDevice.isConnectedLeAudioDevice() + if ((cachedDevice.isConnectedLeAudioDevice() + || cachedDevice.hasConnectedLeAudioMemberDevice()) && BluetoothUtils.isBroadcasting(mBtManager) && BluetoothUtils.hasConnectedBroadcastSource(cachedDevice, mBtManager)) { isFilterMatched = true; diff --git a/tests/robotests/src/com/android/settings/bluetooth/AvailableMediaBluetoothDeviceUpdaterTest.java b/tests/robotests/src/com/android/settings/bluetooth/AvailableMediaBluetoothDeviceUpdaterTest.java index 2251c3bff5a..87d7aed8f19 100644 --- a/tests/robotests/src/com/android/settings/bluetooth/AvailableMediaBluetoothDeviceUpdaterTest.java +++ b/tests/robotests/src/com/android/settings/bluetooth/AvailableMediaBluetoothDeviceUpdaterTest.java @@ -282,6 +282,28 @@ public class AvailableMediaBluetoothDeviceUpdaterTest { verify(mBluetoothDeviceUpdater).addPreference(mCachedBluetoothDevice); } + @Test + public void + onProfileConnectionStateChanged_hasLeaMemberConnected_notInCallFlagOff_addPref() { + mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING); + setUpDeviceUpdaterWithAudioMode(AudioManager.MODE_NORMAL); + when(mBluetoothDeviceUpdater.isDeviceConnected(any(CachedBluetoothDevice.class))) + .thenReturn(true); + when(mCachedBluetoothDevice.isConnectedLeAudioDevice()).thenReturn(false); + when(mCachedBluetoothDevice.hasConnectedLeAudioMemberDevice()).thenReturn(true); + when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of(mBroadcastReceiveState)); + List bisSyncState = new ArrayList<>(); + bisSyncState.add(1L); + when(mBroadcastReceiveState.getBisSyncState()).thenReturn(bisSyncState); + + mBluetoothDeviceUpdater.onProfileConnectionStateChanged( + mCachedBluetoothDevice, + BluetoothProfile.STATE_CONNECTED, + BluetoothProfile.LE_AUDIO); + + verify(mBluetoothDeviceUpdater).addPreference(mCachedBluetoothDevice); + } + @Test public void onProfileConnectionStateChanged_leaConnected_notInCallNotInSharing_addPref() { mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING); @@ -299,6 +321,25 @@ public class AvailableMediaBluetoothDeviceUpdaterTest { verify(mBluetoothDeviceUpdater).addPreference(mCachedBluetoothDevice); } + @Test + public void + onProfileConnectionStateChanged_hasLeaMemberConnected_notInCallNotInSharing_addPref() { + mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING); + setUpDeviceUpdaterWithAudioMode(AudioManager.MODE_NORMAL); + when(mBluetoothDeviceUpdater.isDeviceConnected(any(CachedBluetoothDevice.class))) + .thenReturn(true); + when(mCachedBluetoothDevice.isConnectedLeAudioDevice()).thenReturn(false); + when(mCachedBluetoothDevice.hasConnectedLeAudioMemberDevice()).thenReturn(true); + when(mAssistant.getAllSources(any())).thenReturn(ImmutableList.of()); + + mBluetoothDeviceUpdater.onProfileConnectionStateChanged( + mCachedBluetoothDevice, + BluetoothProfile.STATE_CONNECTED, + BluetoothProfile.LE_AUDIO); + + verify(mBluetoothDeviceUpdater).addPreference(mCachedBluetoothDevice); + } + @Test public void onProfileConnectionStateChanged_leaConnected_inCallSharingFlagOff_addPref() { mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING); diff --git a/tests/robotests/src/com/android/settings/bluetooth/ConnectedBluetoothDeviceUpdaterTest.java b/tests/robotests/src/com/android/settings/bluetooth/ConnectedBluetoothDeviceUpdaterTest.java index f68a8d4cf6a..b2babc310ae 100644 --- a/tests/robotests/src/com/android/settings/bluetooth/ConnectedBluetoothDeviceUpdaterTest.java +++ b/tests/robotests/src/com/android/settings/bluetooth/ConnectedBluetoothDeviceUpdaterTest.java @@ -269,6 +269,20 @@ public class ConnectedBluetoothDeviceUpdaterTest { verify(mBluetoothDeviceUpdater).removePreference(mCachedBluetoothDevice); } + @Test + public void onProfileConnectionStateChanged_hasLeaMemberConnected_inCall_removesPreference() { + setUpDeviceUpdaterWithAudioMode(AudioManager.MODE_IN_CALL); + when(mBluetoothDeviceUpdater + .isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true); + when(mCachedBluetoothDevice.isConnectedLeAudioDevice()).thenReturn(false); + when(mCachedBluetoothDevice.hasConnectedLeAudioMemberDevice()).thenReturn(true); + + mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice, + BluetoothProfile.STATE_CONNECTED, BluetoothProfile.LE_AUDIO); + + verify(mBluetoothDeviceUpdater).removePreference(mCachedBluetoothDevice); + } + @Test public void onProfileConnectionStateChanged_leAudioDeviceConnected_notInCall_removesPreference() { @@ -282,6 +296,22 @@ public class ConnectedBluetoothDeviceUpdaterTest { verify(mBluetoothDeviceUpdater).removePreference(mCachedBluetoothDevice); } + + @Test + public void + onProfileConnectionStateChanged_hasLeaMemberConnected_notInCall_removesPreference() { + setUpDeviceUpdaterWithAudioMode(AudioManager.MODE_NORMAL); + when(mBluetoothDeviceUpdater + .isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true); + when(mCachedBluetoothDevice.isConnectedLeAudioDevice()).thenReturn(false); + when(mCachedBluetoothDevice.hasConnectedLeAudioMemberDevice()).thenReturn(true); + + mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice, + BluetoothProfile.STATE_CONNECTED, BluetoothProfile.LE_AUDIO); + + verify(mBluetoothDeviceUpdater).removePreference(mCachedBluetoothDevice); + } + @Test public void onProfileConnectionStateChanged_deviceIsNotInList_inCall_invokesRemovesPreference() { diff --git a/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingBluetoothDeviceUpdaterTest.java b/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingBluetoothDeviceUpdaterTest.java index 12e03d4cd63..84fd820323f 100644 --- a/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingBluetoothDeviceUpdaterTest.java +++ b/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingBluetoothDeviceUpdaterTest.java @@ -153,6 +153,11 @@ public class AudioSharingBluetoothDeviceUpdaterTest { @Test public void onProfileConnectionStateChanged_leaDeviceConnected_flagOff_removesPref() { setupPreferenceMapWithDevice(false); + mDeviceUpdater.onProfileConnectionStateChanged( + mCachedBluetoothDevice, + BluetoothProfile.STATE_CONNECTED, + BluetoothProfile.LE_AUDIO); + shadowOf(Looper.getMainLooper()).idle(); mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING); ArgumentCaptor captor = ArgumentCaptor.forClass(Preference.class); @@ -172,6 +177,11 @@ public class AudioSharingBluetoothDeviceUpdaterTest { @Test public void onProfileConnectionStateChanged_leaConnected_flagOff_hysteresisMode_removesPref() { setupPreferenceMapWithDevice(true); + mDeviceUpdater.onProfileConnectionStateChanged( + mCachedBluetoothDevice, + BluetoothProfile.STATE_CONNECTED, + BluetoothProfile.LE_AUDIO); + shadowOf(Looper.getMainLooper()).idle(); mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_LE_AUDIO_SHARING); ArgumentCaptor captor = ArgumentCaptor.forClass(Preference.class); @@ -191,6 +201,11 @@ public class AudioSharingBluetoothDeviceUpdaterTest { @Test public void onProfileConnectionStateChanged_leaConnected_noSource_removesPref() { setupPreferenceMapWithDevice(false); + mDeviceUpdater.onProfileConnectionStateChanged( + mCachedBluetoothDevice, + BluetoothProfile.STATE_CONNECTED, + BluetoothProfile.LE_AUDIO); + shadowOf(Looper.getMainLooper()).idle(); when(mAssistant.getAllSources(mBluetoothDevice)).thenReturn(ImmutableList.of()); ArgumentCaptor captor = ArgumentCaptor.forClass(Preference.class); @@ -210,6 +225,11 @@ public class AudioSharingBluetoothDeviceUpdaterTest { @Test public void onProfileConnectionStateChanged_leaConnected_noSource_hysteresisMode_removesPref() { setupPreferenceMapWithDevice(true); + mDeviceUpdater.onProfileConnectionStateChanged( + mCachedBluetoothDevice, + BluetoothProfile.STATE_CONNECTED, + BluetoothProfile.LE_AUDIO); + shadowOf(Looper.getMainLooper()).idle(); when(mAssistant.getAllSources(mBluetoothDevice)).thenReturn(ImmutableList.of()); ArgumentCaptor captor = ArgumentCaptor.forClass(Preference.class); @@ -229,6 +249,11 @@ public class AudioSharingBluetoothDeviceUpdaterTest { @Test public void onProfileConnectionStateChanged_deviceIsNotInList_removesPref() { setupPreferenceMapWithDevice(false); + mDeviceUpdater.onProfileConnectionStateChanged( + mCachedBluetoothDevice, + BluetoothProfile.STATE_CONNECTED, + BluetoothProfile.LE_AUDIO); + shadowOf(Looper.getMainLooper()).idle(); mCachedDevices.clear(); when(mCachedDeviceManager.getCachedDevicesCopy()).thenReturn(mCachedDevices); @@ -249,6 +274,11 @@ public class AudioSharingBluetoothDeviceUpdaterTest { @Test public void onProfileConnectionStateChanged_deviceIsNotInList_hysteresisMode_removesPref() { setupPreferenceMapWithDevice(true); + mDeviceUpdater.onProfileConnectionStateChanged( + mCachedBluetoothDevice, + BluetoothProfile.STATE_CONNECTED, + BluetoothProfile.LE_AUDIO); + shadowOf(Looper.getMainLooper()).idle(); mCachedDevices.clear(); when(mCachedDeviceManager.getCachedDevicesCopy()).thenReturn(mCachedDevices); @@ -269,6 +299,11 @@ public class AudioSharingBluetoothDeviceUpdaterTest { @Test public void onProfileConnectionStateChanged_leaDisconnected_removesPref() { setupPreferenceMapWithDevice(false); + mDeviceUpdater.onProfileConnectionStateChanged( + mCachedBluetoothDevice, + BluetoothProfile.STATE_CONNECTED, + BluetoothProfile.LE_AUDIO); + shadowOf(Looper.getMainLooper()).idle(); when(mDeviceUpdater.isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(false); ArgumentCaptor captor = ArgumentCaptor.forClass(Preference.class); @@ -288,6 +323,11 @@ public class AudioSharingBluetoothDeviceUpdaterTest { @Test public void onProfileConnectionStateChanged_leaDisconnected_hysteresisMode_removesPref() { setupPreferenceMapWithDevice(true); + mDeviceUpdater.onProfileConnectionStateChanged( + mCachedBluetoothDevice, + BluetoothProfile.STATE_CONNECTED, + BluetoothProfile.LE_AUDIO); + shadowOf(Looper.getMainLooper()).idle(); when(mDeviceUpdater.isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(false); ArgumentCaptor captor = ArgumentCaptor.forClass(Preference.class); @@ -307,6 +347,11 @@ public class AudioSharingBluetoothDeviceUpdaterTest { @Test public void onProfileConnectionStateChanged_leaDisconnecting_removesPref() { setupPreferenceMapWithDevice(false); + mDeviceUpdater.onProfileConnectionStateChanged( + mCachedBluetoothDevice, + BluetoothProfile.STATE_CONNECTED, + BluetoothProfile.LE_AUDIO); + shadowOf(Looper.getMainLooper()).idle(); doReturn(false).when(mCachedBluetoothDevice).isConnectedLeAudioDevice(); ArgumentCaptor captor = ArgumentCaptor.forClass(Preference.class); @@ -325,6 +370,11 @@ public class AudioSharingBluetoothDeviceUpdaterTest { @Test public void onProfileConnectionStateChanged_leaDisconnecting_hysteresisMode_removesPref() { setupPreferenceMapWithDevice(true); + mDeviceUpdater.onProfileConnectionStateChanged( + mCachedBluetoothDevice, + BluetoothProfile.STATE_CONNECTED, + BluetoothProfile.LE_AUDIO); + shadowOf(Looper.getMainLooper()).idle(); doReturn(false).when(mCachedBluetoothDevice).isConnectedLeAudioDevice(); ArgumentCaptor captor = ArgumentCaptor.forClass(Preference.class); @@ -344,6 +394,29 @@ public class AudioSharingBluetoothDeviceUpdaterTest { public void onProfileConnectionStateChanged_leaConnected_hasSource_addsPref() { ArgumentCaptor captor = ArgumentCaptor.forClass(Preference.class); setupPreferenceMapWithDevice(false); + mDeviceUpdater.onProfileConnectionStateChanged( + mCachedBluetoothDevice, + BluetoothProfile.STATE_CONNECTED, + BluetoothProfile.LE_AUDIO); + shadowOf(Looper.getMainLooper()).idle(); + + verify(mDevicePreferenceCallback).onDeviceAdded(captor.capture()); + assertThat(captor.getValue() instanceof BluetoothDevicePreference).isTrue(); + assertThat(((BluetoothDevicePreference) captor.getValue()).getBluetoothDevice()) + .isEqualTo(mCachedBluetoothDevice); + } + + @Test + public void onProfileConnectionStateChanged_hasLeaMemberConnected_hasSource_addsPref() { + ArgumentCaptor captor = ArgumentCaptor.forClass(Preference.class); + setupPreferenceMapWithDevice(false); + when(mCachedBluetoothDevice.isConnectedLeAudioDevice()).thenReturn(false); + when(mCachedBluetoothDevice.hasConnectedLeAudioMemberDevice()).thenReturn(true); + mDeviceUpdater.onProfileConnectionStateChanged( + mCachedBluetoothDevice, + BluetoothProfile.STATE_CONNECTED, + BluetoothProfile.LE_AUDIO); + shadowOf(Looper.getMainLooper()).idle(); verify(mDevicePreferenceCallback).onDeviceAdded(captor.capture()); assertThat(captor.getValue() instanceof BluetoothDevicePreference).isTrue(); @@ -355,6 +428,30 @@ public class AudioSharingBluetoothDeviceUpdaterTest { public void onProfileConnectionStateChanged_leaConnected_hasSource_hysteresisMode_addsPref() { ArgumentCaptor captor = ArgumentCaptor.forClass(Preference.class); setupPreferenceMapWithDevice(true); + mDeviceUpdater.onProfileConnectionStateChanged( + mCachedBluetoothDevice, + BluetoothProfile.STATE_CONNECTED, + BluetoothProfile.LE_AUDIO); + shadowOf(Looper.getMainLooper()).idle(); + + verify(mDevicePreferenceCallback).onDeviceAdded(captor.capture()); + assertThat(captor.getValue() instanceof BluetoothDevicePreference).isTrue(); + assertThat(((BluetoothDevicePreference) captor.getValue()).getBluetoothDevice()) + .isEqualTo(mCachedBluetoothDevice); + } + + @Test + public void + onProfileConnectionStateChanged_hasLeaMemberConnected_hasSource_hysteresis_addsPref() { + ArgumentCaptor captor = ArgumentCaptor.forClass(Preference.class); + setupPreferenceMapWithDevice(true); + when(mCachedBluetoothDevice.isConnectedLeAudioDevice()).thenReturn(false); + when(mCachedBluetoothDevice.hasConnectedLeAudioMemberDevice()).thenReturn(true); + mDeviceUpdater.onProfileConnectionStateChanged( + mCachedBluetoothDevice, + BluetoothProfile.STATE_CONNECTED, + BluetoothProfile.LE_AUDIO); + shadowOf(Looper.getMainLooper()).idle(); verify(mDevicePreferenceCallback).onDeviceAdded(captor.capture()); assertThat(captor.getValue() instanceof BluetoothDevicePreference).isTrue(); @@ -397,10 +494,5 @@ public class AudioSharingBluetoothDeviceUpdaterTest { when(mAssistant.getAllSources(mBluetoothDevice)).thenReturn(ImmutableList.of(mState)); when(mDeviceUpdater.isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true); doReturn(true).when(mCachedBluetoothDevice).isConnectedLeAudioDevice(); - mDeviceUpdater.onProfileConnectionStateChanged( - mCachedBluetoothDevice, - BluetoothProfile.STATE_CONNECTED, - BluetoothProfile.LE_AUDIO); - shadowOf(Looper.getMainLooper()).idle(); } } diff --git a/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDeviceVolumeControlUpdaterTest.java b/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDeviceVolumeControlUpdaterTest.java index 95e51e99d51..2bdd0da243f 100644 --- a/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDeviceVolumeControlUpdaterTest.java +++ b/tests/robotests/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDeviceVolumeControlUpdaterTest.java @@ -127,6 +127,11 @@ public class AudioSharingDeviceVolumeControlUpdaterTest { @Test public void onProfileConnectionStateChanged_leaDeviceConnected_noSharing_removesPref() { setupPreferenceMapWithDevice(); + mDeviceUpdater.onProfileConnectionStateChanged( + mCachedBluetoothDevice, + BluetoothProfile.STATE_CONNECTED, + BluetoothProfile.LE_AUDIO); + shadowOf(Looper.getMainLooper()).idle(); when(mBroadcast.isEnabled(null)).thenReturn(false); ArgumentCaptor captor = ArgumentCaptor.forClass(Preference.class); @@ -146,6 +151,11 @@ public class AudioSharingDeviceVolumeControlUpdaterTest { @Test public void onProfileConnectionStateChanged_leaDeviceConnected_noSource_removesPref() { setupPreferenceMapWithDevice(); + mDeviceUpdater.onProfileConnectionStateChanged( + mCachedBluetoothDevice, + BluetoothProfile.STATE_CONNECTED, + BluetoothProfile.LE_AUDIO); + shadowOf(Looper.getMainLooper()).idle(); when(mAssistant.getAllSources(mBluetoothDevice)).thenReturn(ImmutableList.of()); ArgumentCaptor captor = ArgumentCaptor.forClass(Preference.class); @@ -165,6 +175,11 @@ public class AudioSharingDeviceVolumeControlUpdaterTest { @Test public void onProfileConnectionStateChanged_deviceIsNotInList_removesPref() { setupPreferenceMapWithDevice(); + mDeviceUpdater.onProfileConnectionStateChanged( + mCachedBluetoothDevice, + BluetoothProfile.STATE_CONNECTED, + BluetoothProfile.LE_AUDIO); + shadowOf(Looper.getMainLooper()).idle(); mCachedDevices.clear(); when(mCachedDeviceManager.getCachedDevicesCopy()).thenReturn(mCachedDevices); @@ -185,6 +200,11 @@ public class AudioSharingDeviceVolumeControlUpdaterTest { @Test public void onProfileConnectionStateChanged_leaDeviceDisconnected_removesPref() { setupPreferenceMapWithDevice(); + mDeviceUpdater.onProfileConnectionStateChanged( + mCachedBluetoothDevice, + BluetoothProfile.STATE_CONNECTED, + BluetoothProfile.LE_AUDIO); + shadowOf(Looper.getMainLooper()).idle(); when(mDeviceUpdater.isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(false); ArgumentCaptor captor = ArgumentCaptor.forClass(Preference.class); @@ -204,6 +224,11 @@ public class AudioSharingDeviceVolumeControlUpdaterTest { @Test public void onProfileConnectionStateChanged_leaDeviceDisconnecting_removesPref() { setupPreferenceMapWithDevice(); + mDeviceUpdater.onProfileConnectionStateChanged( + mCachedBluetoothDevice, + BluetoothProfile.STATE_CONNECTED, + BluetoothProfile.LE_AUDIO); + shadowOf(Looper.getMainLooper()).idle(); when(mCachedBluetoothDevice.isConnectedLeAudioDevice()).thenReturn(false); ArgumentCaptor captor = ArgumentCaptor.forClass(Preference.class); @@ -224,6 +249,29 @@ public class AudioSharingDeviceVolumeControlUpdaterTest { public void onProfileConnectionStateChanged_leaDeviceConnected_hasSource_addsPreference() { ArgumentCaptor captor = ArgumentCaptor.forClass(Preference.class); setupPreferenceMapWithDevice(); + mDeviceUpdater.onProfileConnectionStateChanged( + mCachedBluetoothDevice, + BluetoothProfile.STATE_CONNECTED, + BluetoothProfile.LE_AUDIO); + shadowOf(Looper.getMainLooper()).idle(); + + verify(mDevicePreferenceCallback).onDeviceAdded(captor.capture()); + assertThat(captor.getValue() instanceof AudioSharingDeviceVolumePreference).isTrue(); + assertThat(((AudioSharingDeviceVolumePreference) captor.getValue()).getCachedDevice()) + .isEqualTo(mCachedBluetoothDevice); + } + + @Test + public void onProfileConnectionStateChanged_hasLeaMemberConnected_hasSource_addsPreference() { + ArgumentCaptor captor = ArgumentCaptor.forClass(Preference.class); + setupPreferenceMapWithDevice(); + when(mCachedBluetoothDevice.isConnectedLeAudioDevice()).thenReturn(false); + when(mCachedBluetoothDevice.hasConnectedLeAudioMemberDevice()).thenReturn(true); + mDeviceUpdater.onProfileConnectionStateChanged( + mCachedBluetoothDevice, + BluetoothProfile.STATE_CONNECTED, + BluetoothProfile.LE_AUDIO); + shadowOf(Looper.getMainLooper()).idle(); verify(mDevicePreferenceCallback).onDeviceAdded(captor.capture()); assertThat(captor.getValue() instanceof AudioSharingDeviceVolumePreference).isTrue(); @@ -262,6 +310,12 @@ public class AudioSharingDeviceVolumeControlUpdaterTest { @Test public void refreshPreference_doNothing() { setupPreferenceMapWithDevice(); + mDeviceUpdater.onProfileConnectionStateChanged( + mCachedBluetoothDevice, + BluetoothProfile.STATE_CONNECTED, + BluetoothProfile.LE_AUDIO); + shadowOf(Looper.getMainLooper()).idle(); + verify(mDevicePreferenceCallback).onDeviceAdded(any(Preference.class)); when(mCachedDeviceManager.getCachedDevicesCopy()).thenReturn(ImmutableList.of()); mDeviceUpdater.refreshPreference(); @@ -276,10 +330,5 @@ public class AudioSharingDeviceVolumeControlUpdaterTest { when(mAssistant.getAllSources(mBluetoothDevice)).thenReturn(ImmutableList.of(mState)); when(mDeviceUpdater.isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true); when(mCachedBluetoothDevice.isConnectedLeAudioDevice()).thenReturn(true); - mDeviceUpdater.onProfileConnectionStateChanged( - mCachedBluetoothDevice, - BluetoothProfile.STATE_CONNECTED, - BluetoothProfile.LE_AUDIO); - shadowOf(Looper.getMainLooper()).idle(); } }