Merge "To transfer to a disconnected Bt device" into rvc-dev am: bca2800a96

Change-Id: I9793e3c10b8261885cf88c0e243de8679803b653
This commit is contained in:
tim peng
2020-03-25 02:50:07 +00:00
committed by Automerger Merge Worker
2 changed files with 37 additions and 3 deletions

View File

@@ -66,6 +66,7 @@ public class LocalMediaManager implements BluetoothCallback {
private LocalBluetoothManager mLocalBluetoothManager; private LocalBluetoothManager mLocalBluetoothManager;
private InfoMediaManager mInfoMediaManager; private InfoMediaManager mInfoMediaManager;
private String mPackageName; private String mPackageName;
private MediaDevice mOnTransferBluetoothDevice;
@VisibleForTesting @VisibleForTesting
List<MediaDevice> mMediaDevices = new ArrayList<>(); List<MediaDevice> mMediaDevices = new ArrayList<>();
@@ -143,7 +144,7 @@ public class LocalMediaManager implements BluetoothCallback {
final CachedBluetoothDevice cachedDevice = final CachedBluetoothDevice cachedDevice =
((BluetoothMediaDevice) device).getCachedDevice(); ((BluetoothMediaDevice) device).getCachedDevice();
if (!cachedDevice.isConnected() && !cachedDevice.isBusy()) { if (!cachedDevice.isConnected() && !cachedDevice.isBusy()) {
device.setState(MediaDeviceState.STATE_CONNECTING); mOnTransferBluetoothDevice = connectDevice;
cachedDevice.connect(); cachedDevice.connect();
return; return;
} }
@@ -389,6 +390,10 @@ public class LocalMediaManager implements BluetoothCallback {
mCurrentConnectedDevice = infoMediaDevice != null mCurrentConnectedDevice = infoMediaDevice != null
? infoMediaDevice : updateCurrentConnectedDevice(); ? infoMediaDevice : updateCurrentConnectedDevice();
dispatchDeviceListUpdate(); dispatchDeviceListUpdate();
if (mOnTransferBluetoothDevice != null && mOnTransferBluetoothDevice.isConnected()) {
connectDevice(mOnTransferBluetoothDevice);
mOnTransferBluetoothDevice = null;
}
} }
private List<MediaDevice> buildDisconnectedBluetoothDevice() { private List<MediaDevice> buildDisconnectedBluetoothDevice() {

View File

@@ -23,6 +23,7 @@ import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never; import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@@ -107,8 +108,8 @@ public class LocalMediaManagerTest {
when(mLocalProfileManager.getA2dpProfile()).thenReturn(mA2dpProfile); when(mLocalProfileManager.getA2dpProfile()).thenReturn(mA2dpProfile);
when(mLocalProfileManager.getHearingAidProfile()).thenReturn(mHapProfile); when(mLocalProfileManager.getHearingAidProfile()).thenReturn(mHapProfile);
mInfoMediaDevice1 = new InfoMediaDevice(mContext, mMediaRouter2Manager, mRouteInfo1, mInfoMediaDevice1 = spy(new InfoMediaDevice(mContext, mMediaRouter2Manager, mRouteInfo1,
TEST_PACKAGE_NAME); TEST_PACKAGE_NAME));
mInfoMediaDevice2 = new InfoMediaDevice(mContext, mMediaRouter2Manager, mRouteInfo2, mInfoMediaDevice2 = new InfoMediaDevice(mContext, mMediaRouter2Manager, mRouteInfo2,
TEST_PACKAGE_NAME); TEST_PACKAGE_NAME);
mLocalMediaManager = new LocalMediaManager(mContext, mLocalBluetoothManager, mLocalMediaManager = new LocalMediaManager(mContext, mLocalBluetoothManager,
@@ -564,6 +565,34 @@ public class LocalMediaManagerTest {
verify(mCallback).onDeviceListUpdate(any()); verify(mCallback).onDeviceListUpdate(any());
} }
@Test
public void onDeviceListAdded_transferToDisconnectedBluetooth_verifyConnectDevice() {
final List<MediaDevice> devices = new ArrayList<>();
final MediaDevice currentDevice = mock(MediaDevice.class);
final MediaDevice device = mock(BluetoothMediaDevice.class);
final CachedBluetoothDevice cachedDevice = mock(CachedBluetoothDevice.class);
mLocalMediaManager.mMediaDevices.add(device);
mLocalMediaManager.mMediaDevices.add(currentDevice);
when(device.getId()).thenReturn(TEST_DEVICE_ID_1);
when(currentDevice.getId()).thenReturn(TEST_CURRENT_DEVICE_ID);
when(((BluetoothMediaDevice) device).getCachedDevice()).thenReturn(cachedDevice);
when(cachedDevice.isConnected()).thenReturn(false);
when(cachedDevice.isBusy()).thenReturn(false);
mLocalMediaManager.registerCallback(mCallback);
mLocalMediaManager.connectDevice(device);
verify(cachedDevice).connect();
when(device.isConnected()).thenReturn(true);
mLocalMediaManager.mCurrentConnectedDevice = currentDevice;
devices.add(mInfoMediaDevice1);
devices.add(currentDevice);
mLocalMediaManager.mMediaDeviceCallback.onDeviceListAdded(devices);
verify(mInfoMediaDevice1).connect();
}
@Test @Test
public void onRequestFailed_shouldDispatchOnRequestFailed() { public void onRequestFailed_shouldDispatchOnRequestFailed() {
mLocalMediaManager.registerCallback(mCallback); mLocalMediaManager.registerCallback(mCallback);