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;
|
boolean isFilterMatched = false;
|
||||||
if (isDeviceConnected(cachedDevice)) {
|
if (isDeviceConnected(cachedDevice) && isDeviceInCachedDevicesList(cachedDevice)) {
|
||||||
if (DBG) {
|
if (DBG) {
|
||||||
Log.d(TAG, "isFilterMatched() current audio profile : " + currentAudioProfile);
|
Log.d(TAG, "isFilterMatched() current audio profile : " + currentAudioProfile);
|
||||||
}
|
}
|
||||||
@@ -74,6 +74,8 @@ public class AvailableMediaBluetoothDeviceUpdater extends BluetoothDeviceUpdater
|
|||||||
// It would show in Available Devices group.
|
// It would show in Available Devices group.
|
||||||
if (cachedDevice.isConnectedHearingAidDevice()
|
if (cachedDevice.isConnectedHearingAidDevice()
|
||||||
|| cachedDevice.isConnectedLeAudioDevice()) {
|
|| cachedDevice.isConnectedLeAudioDevice()) {
|
||||||
|
Log.d(TAG, "isFilterMatched() device : " +
|
||||||
|
cachedDevice.getName() + ", the profile is connected.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// According to the current audio profile type,
|
// According to the current audio profile type,
|
||||||
|
@@ -326,4 +326,8 @@ public abstract class BluetoothDeviceUpdater implements BluetoothCallback,
|
|||||||
((BluetoothDevicePreference) preference).onPreferenceAttributesChanged();
|
((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;
|
boolean isFilterMatched = false;
|
||||||
if (isDeviceConnected(cachedDevice)) {
|
if (isDeviceConnected(cachedDevice) && isDeviceInCachedDevicesList(cachedDevice)) {
|
||||||
if (DBG) {
|
if (DBG) {
|
||||||
Log.d(TAG, "isFilterMatched() current audio profile : " + currentAudioProfile);
|
Log.d(TAG, "isFilterMatched() current audio profile : " + currentAudioProfile);
|
||||||
}
|
}
|
||||||
|
@@ -105,7 +105,8 @@ public class SavedBluetoothDeviceUpdater extends BluetoothDeviceUpdater
|
|||||||
+ cachedDevice.isConnected());
|
+ cachedDevice.isConnected());
|
||||||
}
|
}
|
||||||
return device.getBondState() == BluetoothDevice.BOND_BONDED
|
return device.getBondState() == BluetoothDevice.BOND_BONDED
|
||||||
&& (mDisplayConnected || !device.isConnected());
|
&& (mDisplayConnected || (!device.isConnected() && isDeviceInCachedDevicesList(
|
||||||
|
cachedDevice)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -86,6 +86,7 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
|
|||||||
mShadowCachedBluetoothDeviceManager = Shadow.extract(
|
mShadowCachedBluetoothDeviceManager = Shadow.extract(
|
||||||
Utils.getLocalBtManager(mContext).getCachedDeviceManager());
|
Utils.getLocalBtManager(mContext).getCachedDeviceManager());
|
||||||
mCachedDevices = new ArrayList<>();
|
mCachedDevices = new ArrayList<>();
|
||||||
|
mCachedDevices.add(mCachedBluetoothDevice);
|
||||||
mShadowCachedBluetoothDeviceManager.setCachedDevicesCopy(mCachedDevices);
|
mShadowCachedBluetoothDeviceManager.setCachedDevicesCopy(mCachedDevices);
|
||||||
Pair<Drawable, String> pairs = new Pair<>(mDrawable, "fake_device");
|
Pair<Drawable, String> pairs = new Pair<>(mDrawable, "fake_device");
|
||||||
|
|
||||||
@@ -109,7 +110,6 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
|
|||||||
when(mBluetoothDeviceUpdater.
|
when(mBluetoothDeviceUpdater.
|
||||||
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
||||||
when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true);
|
when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true);
|
||||||
mCachedDevices.add(mCachedBluetoothDevice);
|
|
||||||
|
|
||||||
mBluetoothDeviceUpdater.onAudioModeChanged();
|
mBluetoothDeviceUpdater.onAudioModeChanged();
|
||||||
|
|
||||||
@@ -122,7 +122,6 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
|
|||||||
when(mBluetoothDeviceUpdater.
|
when(mBluetoothDeviceUpdater.
|
||||||
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
||||||
when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true);
|
when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true);
|
||||||
mCachedDevices.add(mCachedBluetoothDevice);
|
|
||||||
|
|
||||||
mBluetoothDeviceUpdater.onAudioModeChanged();
|
mBluetoothDeviceUpdater.onAudioModeChanged();
|
||||||
|
|
||||||
@@ -135,7 +134,6 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
|
|||||||
when(mBluetoothDeviceUpdater.
|
when(mBluetoothDeviceUpdater.
|
||||||
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
||||||
when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true);
|
when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true);
|
||||||
mCachedDevices.add(mCachedBluetoothDevice);
|
|
||||||
|
|
||||||
mBluetoothDeviceUpdater.onAudioModeChanged();
|
mBluetoothDeviceUpdater.onAudioModeChanged();
|
||||||
|
|
||||||
@@ -148,7 +146,6 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
|
|||||||
when(mBluetoothDeviceUpdater.
|
when(mBluetoothDeviceUpdater.
|
||||||
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
||||||
when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true);
|
when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true);
|
||||||
mCachedDevices.add(mCachedBluetoothDevice);
|
|
||||||
|
|
||||||
mBluetoothDeviceUpdater.onAudioModeChanged();
|
mBluetoothDeviceUpdater.onAudioModeChanged();
|
||||||
|
|
||||||
@@ -260,6 +257,35 @@ public class AvailableMediaBluetoothDeviceUpdaterTest {
|
|||||||
verify(mBluetoothDeviceUpdater).addPreference(mCachedBluetoothDevice);
|
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
|
@Test
|
||||||
public void onProfileConnectionStateChanged_deviceDisconnected_removePreference() {
|
public void onProfileConnectionStateChanged_deviceDisconnected_removePreference() {
|
||||||
mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice,
|
mBluetoothDeviceUpdater.onProfileConnectionStateChanged(mCachedBluetoothDevice,
|
||||||
|
@@ -90,6 +90,7 @@ public class ConnectedBluetoothDeviceUpdaterTest {
|
|||||||
Utils.getLocalBtManager(mContext).getCachedDeviceManager());
|
Utils.getLocalBtManager(mContext).getCachedDeviceManager());
|
||||||
doReturn(mContext).when(mDashboardFragment).getContext();
|
doReturn(mContext).when(mDashboardFragment).getContext();
|
||||||
mCachedDevices = new ArrayList<>();
|
mCachedDevices = new ArrayList<>();
|
||||||
|
mCachedDevices.add(mCachedBluetoothDevice);
|
||||||
|
|
||||||
when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice);
|
when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice);
|
||||||
when(mCachedBluetoothDevice.getAddress()).thenReturn(MAC_ADDRESS);
|
when(mCachedBluetoothDevice.getAddress()).thenReturn(MAC_ADDRESS);
|
||||||
@@ -108,7 +109,6 @@ public class ConnectedBluetoothDeviceUpdaterTest {
|
|||||||
when(mBluetoothDeviceUpdater.
|
when(mBluetoothDeviceUpdater.
|
||||||
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
||||||
when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true);
|
when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true);
|
||||||
mCachedDevices.add(mCachedBluetoothDevice);
|
|
||||||
|
|
||||||
mBluetoothDeviceUpdater.onAudioModeChanged();
|
mBluetoothDeviceUpdater.onAudioModeChanged();
|
||||||
|
|
||||||
@@ -121,7 +121,6 @@ public class ConnectedBluetoothDeviceUpdaterTest {
|
|||||||
when(mBluetoothDeviceUpdater.
|
when(mBluetoothDeviceUpdater.
|
||||||
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
||||||
when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true);
|
when(mCachedBluetoothDevice.isConnectedHfpDevice()).thenReturn(true);
|
||||||
mCachedDevices.add(mCachedBluetoothDevice);
|
|
||||||
|
|
||||||
mBluetoothDeviceUpdater.onAudioModeChanged();
|
mBluetoothDeviceUpdater.onAudioModeChanged();
|
||||||
|
|
||||||
@@ -134,7 +133,6 @@ public class ConnectedBluetoothDeviceUpdaterTest {
|
|||||||
when(mBluetoothDeviceUpdater.
|
when(mBluetoothDeviceUpdater.
|
||||||
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
||||||
when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true);
|
when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true);
|
||||||
mCachedDevices.add(mCachedBluetoothDevice);
|
|
||||||
|
|
||||||
mBluetoothDeviceUpdater.onAudioModeChanged();
|
mBluetoothDeviceUpdater.onAudioModeChanged();
|
||||||
|
|
||||||
@@ -147,7 +145,6 @@ public class ConnectedBluetoothDeviceUpdaterTest {
|
|||||||
when(mBluetoothDeviceUpdater.
|
when(mBluetoothDeviceUpdater.
|
||||||
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
isDeviceConnected(any(CachedBluetoothDevice.class))).thenReturn(true);
|
||||||
when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true);
|
when(mCachedBluetoothDevice.isConnectedA2dpDevice()).thenReturn(true);
|
||||||
mCachedDevices.add(mCachedBluetoothDevice);
|
|
||||||
|
|
||||||
mBluetoothDeviceUpdater.onAudioModeChanged();
|
mBluetoothDeviceUpdater.onAudioModeChanged();
|
||||||
|
|
||||||
@@ -167,6 +164,20 @@ public class ConnectedBluetoothDeviceUpdaterTest {
|
|||||||
verify(mBluetoothDeviceUpdater).addPreference(mCachedBluetoothDevice);
|
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
|
@Test
|
||||||
public void onProfileConnectionStateChanged_a2dpDeviceConnected_notInCall_removePreference() {
|
public void onProfileConnectionStateChanged_a2dpDeviceConnected_notInCall_removePreference() {
|
||||||
mAudioManager.setMode(AudioManager.MODE_NORMAL);
|
mAudioManager.setMode(AudioManager.MODE_NORMAL);
|
||||||
@@ -260,6 +271,35 @@ public class ConnectedBluetoothDeviceUpdaterTest {
|
|||||||
|
|
||||||
verify(mBluetoothDeviceUpdater).removePreference(mCachedBluetoothDevice);
|
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
|
@Test
|
||||||
public void onProfileConnectionStateChanged_deviceDisconnected_removePreference() {
|
public void onProfileConnectionStateChanged_deviceDisconnected_removePreference() {
|
||||||
|
@@ -77,6 +77,7 @@ public class SavedBluetoothDeviceUpdaterTest {
|
|||||||
private Context mContext;
|
private Context mContext;
|
||||||
private SavedBluetoothDeviceUpdater mBluetoothDeviceUpdater;
|
private SavedBluetoothDeviceUpdater mBluetoothDeviceUpdater;
|
||||||
private BluetoothDevicePreference mPreference;
|
private BluetoothDevicePreference mPreference;
|
||||||
|
private List<CachedBluetoothDevice> mCachedDevices = new ArrayList<>();
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
@@ -99,6 +100,10 @@ public class SavedBluetoothDeviceUpdaterTest {
|
|||||||
false, BluetoothDevicePreference.SortType.TYPE_DEFAULT);
|
false, BluetoothDevicePreference.SortType.TYPE_DEFAULT);
|
||||||
doNothing().when(mBluetoothDeviceUpdater).addPreference(any());
|
doNothing().when(mBluetoothDeviceUpdater).addPreference(any());
|
||||||
doNothing().when(mBluetoothDeviceUpdater).removePreference(any());
|
doNothing().when(mBluetoothDeviceUpdater).removePreference(any());
|
||||||
|
mCachedDevices.add(mCachedBluetoothDevice);
|
||||||
|
when(mBluetoothManager.getCachedDeviceManager()).thenReturn(mDeviceManager);
|
||||||
|
when(mDeviceManager.getCachedDevicesCopy()).thenReturn(mCachedDevices);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -143,6 +148,31 @@ public class SavedBluetoothDeviceUpdaterTest {
|
|||||||
BluetoothDevicePreference.SortType.TYPE_NO_SORT);
|
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
|
@Test
|
||||||
public void onClick_Preference_setConnect() {
|
public void onClick_Preference_setConnect() {
|
||||||
mBluetoothDeviceUpdater.onPreferenceClick(mPreference);
|
mBluetoothDeviceUpdater.onPreferenceClick(mPreference);
|
||||||
|
Reference in New Issue
Block a user