No feedback when attempting to transfer to an unpowered BT device

-Set transfering state when trying to connect
-Reset to onTransferBluetoothDevice when failing connecting
-Add test cases

Bug: 152606143
Test: make -j50 RunSettingsLibRoboTests
Change-Id: Ifc4cb16a5d7d2b2c85b1171aa070651a5feaa4e2
This commit is contained in:
Tim Peng
2020-03-31 11:34:20 +08:00
committed by tim peng
parent bb5e6b49a7
commit 92fb2199d9
2 changed files with 30 additions and 0 deletions

View File

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

View File

@@ -463,6 +463,26 @@ public class LocalMediaManagerTest {
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
public void onRequestFailed_checkDevicesState() {
mLocalMediaManager.mMediaDevices.add(mInfoMediaDevice1);