The UI only shows the active LE device
At the media device, it only shows the active LE device which is connected. Bug: 232892046 Test: make RunSettingsRoboTests ROBOTEST_FILTER=AvailableMediaBluetoothDeviceUpdaterTest make RunSettingsRoboTests ROBOTEST_FILTER=ConnectedBluetoothDeviceUpdaterTest make RunSettingsRoboTests ROBOTEST_FILTER=SavedBluetoothDeviceUpdaterTest Change-Id: Iac661206def4d43bc40ab9bb1938f084926899c2 Merged-In: Iac661206def4d43bc40ab9bb1938f084926899c2
This commit is contained in:
@@ -66,7 +66,7 @@ public class AvailableMediaBluetoothDeviceUpdater extends BluetoothDeviceUpdater
|
||||
}
|
||||
|
||||
boolean isFilterMatched = false;
|
||||
if (isDeviceConnected(cachedDevice)) {
|
||||
if (isDeviceConnected(cachedDevice) && isDeviceInCachedDevicesList(cachedDevice)) {
|
||||
if (DBG) {
|
||||
Log.d(TAG, "isFilterMatched() current audio profile : " + currentAudioProfile);
|
||||
}
|
||||
@@ -74,6 +74,8 @@ public class AvailableMediaBluetoothDeviceUpdater extends BluetoothDeviceUpdater
|
||||
// It would show in Available Devices group.
|
||||
if (cachedDevice.isConnectedHearingAidDevice()
|
||||
|| cachedDevice.isConnectedLeAudioDevice()) {
|
||||
Log.d(TAG, "isFilterMatched() device : " +
|
||||
cachedDevice.getName() + ", the profile is connected.");
|
||||
return true;
|
||||
}
|
||||
// According to the current audio profile type,
|
||||
|
@@ -326,4 +326,8 @@ public abstract class BluetoothDeviceUpdater implements BluetoothCallback,
|
||||
((BluetoothDevicePreference) preference).onPreferenceAttributesChanged();
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean isDeviceInCachedDevicesList(CachedBluetoothDevice cachedDevice){
|
||||
return mLocalManager.getCachedDeviceManager().getCachedDevicesCopy().contains(cachedDevice);
|
||||
}
|
||||
}
|
||||
|
@@ -66,7 +66,7 @@ public class ConnectedBluetoothDeviceUpdater extends BluetoothDeviceUpdater {
|
||||
}
|
||||
|
||||
boolean isFilterMatched = false;
|
||||
if (isDeviceConnected(cachedDevice)) {
|
||||
if (isDeviceConnected(cachedDevice) && isDeviceInCachedDevicesList(cachedDevice)) {
|
||||
if (DBG) {
|
||||
Log.d(TAG, "isFilterMatched() current audio profile : " + currentAudioProfile);
|
||||
}
|
||||
|
@@ -105,7 +105,8 @@ public class SavedBluetoothDeviceUpdater extends BluetoothDeviceUpdater
|
||||
+ cachedDevice.isConnected());
|
||||
}
|
||||
return device.getBondState() == BluetoothDevice.BOND_BONDED
|
||||
&& (mDisplayConnected || !device.isConnected());
|
||||
&& (mDisplayConnected || (!device.isConnected() && isDeviceInCachedDevicesList(
|
||||
cachedDevice)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -86,6 +86,7 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
|
||||
mShadowCachedBluetoothDeviceManager = Shadow.extract(
|
||||
Utils.getLocalBtManager(mContext).getCachedDeviceManager());
|
||||
mCachedDevices = new ArrayList<>();
|
||||
mCachedDevices.add(mCachedBluetoothDevice);
|
||||
mShadowCachedBluetoothDeviceManager.setCachedDevicesCopy(mCachedDevices);
|
||||
Pair<Drawable, String> pairs = new Pair<>(mDrawable, "fake_device");
|
||||
|
||||
@@ -109,7 +110,6 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
|
||||
when(mBluetoothDeviceUpdater.
|
||||
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
||||
when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true);
|
||||
mCachedDevices.add(mCachedBluetoothDevice);
|
||||
|
||||
mBluetoothDeviceUpdater.onAudioModeChanged();
|
||||
|
||||
@@ -122,7 +122,6 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
|
||||
when(mBluetoothDeviceUpdater.
|
||||
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
||||
when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true);
|
||||
mCachedDevices.add(mCachedBluetoothDevice);
|
||||
|
||||
mBluetoothDeviceUpdater.onAudioModeChanged();
|
||||
|
||||
@@ -135,7 +134,6 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
|
||||
when(mBluetoothDeviceUpdater.
|
||||
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
||||
when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true);
|
||||
mCachedDevices.add(mCachedBluetoothDevice);
|
||||
|
||||
mBluetoothDeviceUpdater.onAudioModeChanged();
|
||||
|
||||
@@ -148,7 +146,6 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
|
||||
when(mBluetoothDeviceUpdater.
|
||||
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
||||
when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true);
|
||||
mCachedDevices.add(mCachedBluetoothDevice);
|
||||
|
||||
mBluetoothDeviceUpdater.onAudioModeChanged();
|
||||
|
||||
@@ -260,6 +257,35 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
|
||||
verify(mBluetoothDeviceUpdater).addPreference(mCachedBluetoothDevice);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void
|
||||
onProfileConnectionStateChanged_deviceIsNotInList_notInCall_invokesRemovePreference() {
|
||||
mAudioManager.setMode(AudioManager.MODE_NORMAL);
|
||||
when(mBluetoothDeviceUpdater
|
||||
.isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
||||
when(mCachedBluetoothDevice.isConnectedLeAudioDevice()).thenReturn(true);
|
||||
mCachedDevices.clear();
|
||||
|
||||
mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice,
|
||||
BluetoothProfile.STATE_CONNECTED, BluetoothProfile.LE_AUDIO);
|
||||
|
||||
verify(mBluetoothDeviceUpdater).removePreference(mCachedBluetoothDevice);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onProfileConnectionStateChanged_deviceIsNotInList_inCall_invokesRemovePreference() {
|
||||
mAudioManager.setMode(AudioManager.MODE_IN_CALL);
|
||||
when(mBluetoothDeviceUpdater
|
||||
.isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
||||
when(mCachedBluetoothDevice.isConnectedLeAudioDevice()).thenReturn(true);
|
||||
mCachedDevices.clear();
|
||||
|
||||
mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice,
|
||||
BluetoothProfile.STATE_CONNECTED, BluetoothProfile.LE_AUDIO);
|
||||
|
||||
verify(mBluetoothDeviceUpdater).removePreference(mCachedBluetoothDevice);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onProfileConnectionStateChanged_deviceDisconnected_removePreference() {
|
||||
mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice,
|
||||
|
@@ -90,6 +90,7 @@ public class ConnectedBluetoothDeviceUpdaterTest {
|
||||
Utils.getLocalBtManager(mContext).getCachedDeviceManager());
|
||||
doReturn(mContext).when(mDashboardFragment).getContext();
|
||||
mCachedDevices = new ArrayList<>();
|
||||
mCachedDevices.add(mCachedBluetoothDevice);
|
||||
|
||||
when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice);
|
||||
when(mCachedBluetoothDevice.getAddress()).thenReturn(MAC_ADDRESS);
|
||||
@@ -108,7 +109,6 @@ public class ConnectedBluetoothDeviceUpdaterTest {
|
||||
when(mBluetoothDeviceUpdater.
|
||||
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
||||
when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true);
|
||||
mCachedDevices.add(mCachedBluetoothDevice);
|
||||
|
||||
mBluetoothDeviceUpdater.onAudioModeChanged();
|
||||
|
||||
@@ -121,7 +121,6 @@ public class ConnectedBluetoothDeviceUpdaterTest {
|
||||
when(mBluetoothDeviceUpdater.
|
||||
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
||||
when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true);
|
||||
mCachedDevices.add(mCachedBluetoothDevice);
|
||||
|
||||
mBluetoothDeviceUpdater.onAudioModeChanged();
|
||||
|
||||
@@ -134,7 +133,6 @@ public class ConnectedBluetoothDeviceUpdaterTest {
|
||||
when(mBluetoothDeviceUpdater.
|
||||
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
||||
when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true);
|
||||
mCachedDevices.add(mCachedBluetoothDevice);
|
||||
|
||||
mBluetoothDeviceUpdater.onAudioModeChanged();
|
||||
|
||||
@@ -147,7 +145,6 @@ public class ConnectedBluetoothDeviceUpdaterTest {
|
||||
when(mBluetoothDeviceUpdater.
|
||||
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
||||
when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true);
|
||||
mCachedDevices.add(mCachedBluetoothDevice);
|
||||
|
||||
mBluetoothDeviceUpdater.onAudioModeChanged();
|
||||
|
||||
@@ -167,6 +164,20 @@ public class ConnectedBluetoothDeviceUpdaterTest {
|
||||
verify(mBluetoothDeviceUpdater).addPreference(mCachedBluetoothDevice);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onProfileConnectionStateChanged_deviceIsNotInList_inCall_invokesRemovePreference() {
|
||||
mAudioManager.setMode(AudioManager.MODE_IN_CALL);
|
||||
when(mBluetoothDeviceUpdater.
|
||||
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
||||
when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true);
|
||||
mCachedDevices.clear();
|
||||
|
||||
mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice,
|
||||
BluetoothProfile.STATE_CONNECTED, BluetoothProfile.A2DP);
|
||||
|
||||
verify(mBluetoothDeviceUpdater).removePreference(mCachedBluetoothDevice);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onProfileConnectionStateChanged_a2dpDeviceConnected_notInCall_removePreference() {
|
||||
mAudioManager.setMode(AudioManager.MODE_NORMAL);
|
||||
@@ -260,6 +271,35 @@ public class ConnectedBluetoothDeviceUpdaterTest {
|
||||
|
||||
verify(mBluetoothDeviceUpdater).removePreference(mCachedBluetoothDevice);
|
||||
}
|
||||
@Test
|
||||
public void onProfileConnectionStateChanged_deviceIsNotInList_inCall_invokesRemovesPreference()
|
||||
{
|
||||
mAudioManager.setMode(AudioManager.MODE_IN_CALL);
|
||||
when(mBluetoothDeviceUpdater
|
||||
.isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
||||
when(mCachedBluetoothDevice.isConnectedLeAudioDevice()).thenReturn(true);
|
||||
mCachedDevices.clear();
|
||||
|
||||
mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice,
|
||||
BluetoothProfile.STATE_CONNECTED, BluetoothProfile.LE_AUDIO);
|
||||
|
||||
verify(mBluetoothDeviceUpdater).removePreference(mCachedBluetoothDevice);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onProfileConnectionStateChanged_deviceIsNotInList_notInCall_invokesRemovesPreference
|
||||
() {
|
||||
mAudioManager.setMode(AudioManager.MODE_NORMAL);
|
||||
when(mBluetoothDeviceUpdater
|
||||
.isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
||||
when(mCachedBluetoothDevice.isConnectedLeAudioDevice()).thenReturn(true);
|
||||
mCachedDevices.clear();
|
||||
|
||||
mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice,
|
||||
BluetoothProfile.STATE_CONNECTED, BluetoothProfile.LE_AUDIO);
|
||||
|
||||
verify(mBluetoothDeviceUpdater).removePreference(mCachedBluetoothDevice);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onProfileConnectionStateChanged_deviceDisconnected_removePreference() {
|
||||
|
@@ -77,6 +77,7 @@ public class SavedBluetoothDeviceUpdaterTest {
|
||||
private Context mContext;
|
||||
private SavedBluetoothDeviceUpdater mBluetoothDeviceUpdater;
|
||||
private BluetoothDevicePreference mPreference;
|
||||
private List<CachedBluetoothDevice> mCachedDevices = new ArrayList<>();
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@@ -99,6 +100,10 @@ public class SavedBluetoothDeviceUpdaterTest {
|
||||
false, BluetoothDevicePreference.SortType.TYPE_DEFAULT);
|
||||
doNothing().when(mBluetoothDeviceUpdater).addPreference(any());
|
||||
doNothing().when(mBluetoothDeviceUpdater).removePreference(any());
|
||||
mCachedDevices.add(mCachedBluetoothDevice);
|
||||
when(mBluetoothManager.getCachedDeviceManager()).thenReturn(mDeviceManager);
|
||||
when(mDeviceManager.getCachedDevicesCopy()).thenReturn(mCachedDevices);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -143,6 +148,31 @@ public class SavedBluetoothDeviceUpdaterTest {
|
||||
BluetoothDevicePreference.SortType.TYPE_NO_SORT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void
|
||||
onProfileConnectionStateChanged_leDeviceDisconnected_inDeviceList_invokesAddPreference()
|
||||
{
|
||||
when(mBluetoothDevice.isConnected()).thenReturn(false);
|
||||
|
||||
mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice,
|
||||
BluetoothProfile.STATE_DISCONNECTED, BluetoothProfile.LE_AUDIO);
|
||||
|
||||
verify(mBluetoothDeviceUpdater).addPreference(mCachedBluetoothDevice,
|
||||
BluetoothDevicePreference.SortType.TYPE_NO_SORT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void
|
||||
onProfileConnectionStateChanged_deviceDisconnected_notInDeviceList_invokesRemovePreference() {
|
||||
when(mBluetoothDevice.isConnected()).thenReturn(false);
|
||||
mCachedDevices.clear();
|
||||
|
||||
mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice,
|
||||
BluetoothProfile.STATE_DISCONNECTED, BluetoothProfile.LE_AUDIO);
|
||||
|
||||
verify(mBluetoothDeviceUpdater).removePreference(mCachedBluetoothDevice);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onClick_Preference_setConnect() {
|
||||
mBluetoothDeviceUpdater.onPreferenceClick(mPreference);
|
||||
|
Reference in New Issue
Block a user