Merge "No feedback when attempting to transfer to an unpowered BT device" into rvc-dev am: 064a827708

Change-Id: I9026ffbfb967589438e53df9e4bf2f1ed02ae741
This commit is contained in:
tim peng
2020-04-06 07:06:57 +00:00
committed by Automerger Merge Worker
2 changed files with 30 additions and 0 deletions

View File

@@ -146,6 +146,7 @@ public class LocalMediaManager implements BluetoothCallback {
((BluetoothMediaDevice) device).getCachedDevice(); ((BluetoothMediaDevice) device).getCachedDevice();
if (!cachedDevice.isConnected() && !cachedDevice.isBusy()) { if (!cachedDevice.isConnected() && !cachedDevice.isBusy()) {
mOnTransferBluetoothDevice = connectDevice; mOnTransferBluetoothDevice = connectDevice;
device.setState(MediaDeviceState.STATE_CONNECTING);
cachedDevice.connect(); cachedDevice.connect();
return; return;
} }
@@ -394,6 +395,7 @@ public class LocalMediaManager implements BluetoothCallback {
dispatchDeviceListUpdate(); dispatchDeviceListUpdate();
if (mOnTransferBluetoothDevice != null && mOnTransferBluetoothDevice.isConnected()) { if (mOnTransferBluetoothDevice != null && mOnTransferBluetoothDevice.isConnected()) {
connectDevice(mOnTransferBluetoothDevice); connectDevice(mOnTransferBluetoothDevice);
mOnTransferBluetoothDevice.setState(MediaDeviceState.STATE_CONNECTED);
mOnTransferBluetoothDevice = null; mOnTransferBluetoothDevice = null;
} }
} }
@@ -539,6 +541,14 @@ public class LocalMediaManager implements BluetoothCallback {
@Override @Override
public void onDeviceAttributesChanged() { public void onDeviceAttributesChanged() {
if (mOnTransferBluetoothDevice != null
&& !((BluetoothMediaDevice) mOnTransferBluetoothDevice).getCachedDevice()
.isBusy()
&& !mOnTransferBluetoothDevice.isConnected()) {
// Failed to connect
mOnTransferBluetoothDevice.setState(MediaDeviceState.STATE_DISCONNECTED);
mOnTransferBluetoothDevice = null;
}
dispatchDeviceAttributesChanged(); dispatchDeviceAttributesChanged();
} }
} }

View File

@@ -483,6 +483,26 @@ public class LocalMediaManagerTest {
verify(mCallback).onDeviceAttributesChanged(); verify(mCallback).onDeviceAttributesChanged();
} }
@Test
public void onDeviceAttributesChanged_failingTransferring_shouldResetState() {
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);
mLocalMediaManager.mDeviceAttributeChangeCallback.onDeviceAttributesChanged();
verify(device).setState(LocalMediaManager.MediaDeviceState.STATE_DISCONNECTED);
}
@Test @Test
public void onRequestFailed_checkDevicesState() { public void onRequestFailed_checkDevicesState() {
mLocalMediaManager.mMediaDevices.add(mInfoMediaDevice1); mLocalMediaManager.mMediaDevices.add(mInfoMediaDevice1);