Show paired devices on Bluetooth device slice card
- support tapping to activate for all available media devices including Hearing aid and Headset - support tapping to connect for previously connected devices Bug: 149667096 Test: robotest Change-Id: I25f74b1b20fbb1876200a561775aa675ff60ac37
This commit is contained in:
@@ -102,7 +102,7 @@ public class BluetoothDeviceUpdaterTest {
|
||||
mPreference = new BluetoothDevicePreference(mContext, mCachedBluetoothDevice,
|
||||
false, BluetoothDevicePreference.SortType.TYPE_DEFAULT);
|
||||
mBluetoothDeviceUpdater =
|
||||
new BluetoothDeviceUpdater(mDashboardFragment, mDevicePreferenceCallback,
|
||||
new BluetoothDeviceUpdater(mContext, mDashboardFragment, mDevicePreferenceCallback,
|
||||
mLocalManager) {
|
||||
@Override
|
||||
public boolean isFilterMatched(CachedBluetoothDevice cachedBluetoothDevice) {
|
||||
|
@@ -23,12 +23,15 @@ import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.PendingIntent;
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
@@ -62,6 +65,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(shadows = ShadowBluetoothAdapter.class)
|
||||
public class BluetoothDevicesSliceTest {
|
||||
|
||||
private static final String BLUETOOTH_MOCK_ADDRESS = "00:11:00:11:00:11";
|
||||
@@ -96,6 +100,13 @@ public class BluetoothDevicesSliceTest {
|
||||
|
||||
// Initial Bluetooth device list.
|
||||
mBluetoothDeviceList = new ArrayList<>();
|
||||
|
||||
final BluetoothAdapter defaultAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||
if (defaultAdapter != null) {
|
||||
final ShadowBluetoothAdapter shadowBluetoothAdapter = Shadow.extract(defaultAdapter);
|
||||
shadowBluetoothAdapter.setEnabled(true);
|
||||
shadowBluetoothAdapter.setState(BluetoothAdapter.STATE_ON);
|
||||
}
|
||||
}
|
||||
|
||||
@After
|
||||
@@ -114,7 +125,6 @@ public class BluetoothDevicesSliceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = ShadowBluetoothAdapter.class)
|
||||
public void getSlice_hasBluetoothHardware_shouldHaveBluetoothDevicesTitleAndPairNewDevice() {
|
||||
final Slice slice = mBluetoothDevicesSlice.getSlice();
|
||||
|
||||
@@ -127,12 +137,9 @@ public class BluetoothDevicesSliceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = ShadowBluetoothAdapter.class)
|
||||
public void getSlice_hasBluetoothDevices_shouldMatchBluetoothMockTitle() {
|
||||
final ShadowBluetoothAdapter adapter = Shadow.extract(BluetoothAdapter.getDefaultAdapter());
|
||||
adapter.setState(BluetoothAdapter.STATE_ON);
|
||||
mockBluetoothDeviceList(1);
|
||||
doReturn(mBluetoothDeviceList).when(mBluetoothDevicesSlice).getConnectedBluetoothDevices();
|
||||
doReturn(mBluetoothDeviceList).when(mBluetoothDevicesSlice).getPairedBluetoothDevices();
|
||||
|
||||
final Slice slice = mBluetoothDevicesSlice.getSlice();
|
||||
|
||||
@@ -141,39 +148,43 @@ public class BluetoothDevicesSliceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = ShadowBluetoothAdapter.class)
|
||||
public void getSlice_hasMediaBluetoothDevice_shouldBuildMediaBluetoothAction() {
|
||||
final ShadowBluetoothAdapter adapter = Shadow.extract(BluetoothAdapter.getDefaultAdapter());
|
||||
adapter.setState(BluetoothAdapter.STATE_ON);
|
||||
mockBluetoothDeviceList(1 /* deviceCount */);
|
||||
doReturn(true).when(mBluetoothDeviceList.get(0)).isConnectedA2dpDevice();
|
||||
doReturn(mBluetoothDeviceList).when(mBluetoothDevicesSlice).getConnectedBluetoothDevices();
|
||||
public void getSlice_hasAvailableMediaDevice_shouldBuildPrimaryBluetoothAction() {
|
||||
mockBluetoothDeviceList(1);
|
||||
when(mBluetoothDeviceList.get(0).getDevice().isConnected()).thenReturn(true);
|
||||
doReturn(true).when(mBluetoothDeviceList.get(0)).isConnectedHearingAidDevice();
|
||||
doReturn(mBluetoothDeviceList).when(mBluetoothDevicesSlice).getPairedBluetoothDevices();
|
||||
|
||||
mBluetoothDevicesSlice.getSlice();
|
||||
|
||||
verify(mBluetoothDevicesSlice).buildMediaBluetoothAction(any());
|
||||
verify(mBluetoothDevicesSlice).buildPrimaryBluetoothAction(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = ShadowBluetoothAdapter.class)
|
||||
public void getSlice_noMediaBluetoothDevice_shouldNotBuildMediaBluetoothAction() {
|
||||
final ShadowBluetoothAdapter adapter = Shadow.extract(BluetoothAdapter.getDefaultAdapter());
|
||||
adapter.setState(BluetoothAdapter.STATE_ON);
|
||||
mockBluetoothDeviceList(1 /* deviceCount */);
|
||||
doReturn(mBluetoothDeviceList).when(mBluetoothDevicesSlice).getConnectedBluetoothDevices();
|
||||
public void getSlice_hasPreviouslyConnectedDevice_shouldBuildPrimaryBluetoothAction() {
|
||||
mockBluetoothDeviceList(1);
|
||||
when(mBluetoothDeviceList.get(0).getDevice().isConnected()).thenReturn(false);
|
||||
doReturn(mBluetoothDeviceList).when(mBluetoothDevicesSlice).getPairedBluetoothDevices();
|
||||
|
||||
mBluetoothDevicesSlice.getSlice();
|
||||
|
||||
verify(mBluetoothDevicesSlice, never()).buildMediaBluetoothAction(any());
|
||||
verify(mBluetoothDevicesSlice).buildPrimaryBluetoothAction(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSlice_hasNonMediaDeviceConnected_shouldNotBuildPrimaryBluetoothAction() {
|
||||
mockBluetoothDeviceList(1);
|
||||
when(mBluetoothDeviceList.get(0).getDevice().isConnected()).thenReturn(true);
|
||||
doReturn(mBluetoothDeviceList).when(mBluetoothDevicesSlice).getPairedBluetoothDevices();
|
||||
|
||||
mBluetoothDevicesSlice.getSlice();
|
||||
|
||||
verify(mBluetoothDevicesSlice, never()).buildPrimaryBluetoothAction(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = ShadowBluetoothAdapter.class)
|
||||
public void getSlice_exceedDefaultRowCount_shouldOnlyShowDefaultRows() {
|
||||
final ShadowBluetoothAdapter adapter = Shadow.extract(BluetoothAdapter.getDefaultAdapter());
|
||||
adapter.setState(BluetoothAdapter.STATE_ON);
|
||||
mockBluetoothDeviceList(BluetoothDevicesSlice.DEFAULT_EXPANDED_ROW_COUNT + 1);
|
||||
doReturn(mBluetoothDeviceList).when(mBluetoothDevicesSlice).getConnectedBluetoothDevices();
|
||||
doReturn(mBluetoothDeviceList).when(mBluetoothDevicesSlice).getPairedBluetoothDevices();
|
||||
|
||||
final Slice slice = mBluetoothDevicesSlice.getSlice();
|
||||
|
||||
@@ -183,9 +194,10 @@ public class BluetoothDevicesSliceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onNotifyChange_mediaDevice_shouldActivateDevice() {
|
||||
public void onNotifyChange_connectedDevice_shouldActivateDevice() {
|
||||
mockBluetoothDeviceList(1);
|
||||
doReturn(mBluetoothDeviceList).when(mBluetoothDevicesSlice).getConnectedBluetoothDevices();
|
||||
doReturn(true).when(mBluetoothDeviceList.get(0)).isConnected();
|
||||
doReturn(mBluetoothDeviceList).when(mBluetoothDevicesSlice).getPairedBluetoothDevices();
|
||||
final Intent intent = new Intent().putExtra(
|
||||
BluetoothDevicesSlice.BLUETOOTH_DEVICE_HASH_CODE,
|
||||
mCachedBluetoothDevice.hashCode());
|
||||
@@ -195,7 +207,41 @@ public class BluetoothDevicesSliceTest {
|
||||
verify(mCachedBluetoothDevice).setActive();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onNotifyChange_availableDisconnectedDevice_shouldConnectToDevice() {
|
||||
mockBluetoothDeviceList(1);
|
||||
doReturn(false).when(mBluetoothDeviceList.get(0)).isConnected();
|
||||
doReturn(false).when(mBluetoothDeviceList.get(0)).isBusy();
|
||||
doReturn(mBluetoothDeviceList).when(mBluetoothDevicesSlice).getPairedBluetoothDevices();
|
||||
final Intent intent = new Intent().putExtra(
|
||||
BluetoothDevicesSlice.BLUETOOTH_DEVICE_HASH_CODE,
|
||||
mCachedBluetoothDevice.hashCode());
|
||||
|
||||
mBluetoothDevicesSlice.onNotifyChange(intent);
|
||||
|
||||
verify(mCachedBluetoothDevice).connect();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onNotifyChange_busyDisconnectedDevice_shouldDoNothing() {
|
||||
mockBluetoothDeviceList(1);
|
||||
doReturn(false).when(mBluetoothDeviceList.get(0)).isConnected();
|
||||
doReturn(true).when(mBluetoothDeviceList.get(0)).isBusy();
|
||||
doReturn(mBluetoothDeviceList).when(mBluetoothDevicesSlice).getPairedBluetoothDevices();
|
||||
final Intent intent = new Intent().putExtra(
|
||||
BluetoothDevicesSlice.BLUETOOTH_DEVICE_HASH_CODE,
|
||||
mCachedBluetoothDevice.hashCode());
|
||||
|
||||
mBluetoothDevicesSlice.onNotifyChange(intent);
|
||||
|
||||
verify(mCachedBluetoothDevice, never()).setActive();
|
||||
verify(mCachedBluetoothDevice, never()).connect();
|
||||
}
|
||||
|
||||
private void mockBluetoothDeviceList(int deviceCount) {
|
||||
final BluetoothDevice device = mock(BluetoothDevice.class);
|
||||
doReturn(BluetoothDevice.BOND_BONDED).when(device).getBondState();
|
||||
doReturn(device).when(mCachedBluetoothDevice).getDevice();
|
||||
doReturn(BLUETOOTH_MOCK_TITLE).when(mCachedBluetoothDevice).getName();
|
||||
doReturn(BLUETOOTH_MOCK_SUMMARY).when(mCachedBluetoothDevice).getConnectionSummary();
|
||||
doReturn(BLUETOOTH_MOCK_ADDRESS).when(mCachedBluetoothDevice).getAddress();
|
||||
|
Reference in New Issue
Block a user