@Implementation protected BluetoothAdapter getAdapter() { return BluetoothAdapter.getDefaultAdapter(); } }
private Object getIBluetoothManager() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (bluetoothAdapter == null) { return null; } Method getBluetoothManagerMethod = getMethodFromClass(bluetoothAdapter.getClass(), "getBluetoothManager"); return getBluetoothManagerMethod.invoke(bluetoothAdapter); }
@Provides @Nullable static BluetoothAdapter provideBluetoothAdapter() { return BluetoothAdapter.getDefaultAdapter(); }
@Before public void setUp() throws Exception { device1 = BluetoothAdapter.getDefaultAdapter().getRemoteDevice("00:11:22:33:AA:BB"); device2 = BluetoothAdapter.getDefaultAdapter().getRemoteDevice("11:22:33:AA:BB:00"); bluetoothHeadset = Shadow.newInstanceOf(BluetoothHeadset.class); }
@Test public void getAdapter_shouldReturnBluetoothAdapter() { assertThat(manager.getAdapter()).isSameAs(BluetoothAdapter.getDefaultAdapter()); } }
distinctBluetoothAddresses.size()); LogManager.w(TAG, "Stopping LE Scan"); BluetoothAdapter.getDefaultAdapter().stopLeScan(scanner); startRecovery(); processStateChange();
@Test public void getUuids_setUuidsNotCalled_shouldReturnNull() throws Exception { BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(MOCK_MAC_ADDRESS); assertThat(device.getUuids()).isNull(); }
private void cancelDiscovery() { try { Thread.sleep(TIME_TO_LET_DISCOVERY_RUN_MILLIS); if (!discoveryStartConfirmed) { LogManager.w(TAG, "BluetoothAdapter.ACTION_DISCOVERY_STARTED never received. Recovery may fail."); } final BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); if (adapter.isDiscovering()) { LogManager.d(TAG, "Cancelling discovery"); adapter.cancelDiscovery(); } else { LogManager.d(TAG, "Discovery not running. Won't cancel it"); } } catch (InterruptedException e) { LogManager.d(TAG, "DiscoveryCanceller sleep interrupted."); } } }
@Test @Config(minSdk = JELLY_BEAN_MR2) public void canSetAndGetType() throws Exception { BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(MOCK_MAC_ADDRESS); shadowOf(device).setType(DEVICE_TYPE_CLASSIC); assertThat(device.getType()).isEqualTo(DEVICE_TYPE_CLASSIC); } }
@Test @Config(minSdk = LOLLIPOP) public void canGetAndSetMultipleAdvertisementSupport() throws Exception { BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); // By default, multiple advertising is supported. assertThat(adapter.isMultipleAdvertisementSupported()).isTrue(); // Flipping it off should update state accordingly. shadowOf(adapter).setIsMultipleAdvertisementSupported(false); assertThat(adapter.isMultipleAdvertisementSupported()).isFalse(); }
@Test public void canGetAndSetAddress() throws Exception { BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); shadowOf(adapter).setAddress("expected"); assertThat(adapter.getAddress()).isEqualTo("expected"); }
@Test public void canGetProfileConnectionState() throws Exception { BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); assertThat(adapter.getProfileConnectionState(BluetoothProfile.HEADSET)) .isEqualTo(BluetoothProfile.STATE_DISCONNECTED); shadowOf(adapter) .setProfileConnectionState(BluetoothProfile.HEADSET, BluetoothProfile.STATE_CONNECTED); assertThat(adapter.getProfileConnectionState(BluetoothProfile.HEADSET)) .isEqualTo(BluetoothProfile.STATE_CONNECTED); assertThat(adapter.getProfileConnectionState(BluetoothProfile.A2DP)) .isEqualTo(BluetoothProfile.STATE_DISCONNECTED); }
@Test public void canSetAndGetCreatedBond() { BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(MOCK_MAC_ADDRESS); assertThat(device.createBond()).isFalse(); shadowOf(device).setCreatedBond(true); assertThat(device.createBond()).isTrue(); }
@Test public void canSetAndGetFetchUuidsWithSdpResult() throws Exception { BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(MOCK_MAC_ADDRESS); assertThat(device.fetchUuidsWithSdp()).isFalse(); shadowOf(device).setFetchUuidsWithSdpResult(true); assertThat(device.fetchUuidsWithSdp()).isTrue(); }
@Test public void canSetAndGetBondState() throws Exception { BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(MOCK_MAC_ADDRESS); assertThat(device.getBondState()).isEqualTo(BOND_NONE); shadowOf(device).setBondState(BOND_BONDED); assertThat(device.getBondState()).isEqualTo(BOND_BONDED); }
@Test public void canSetAndGetUuids() throws Exception { BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(MOCK_MAC_ADDRESS); ParcelUuid[] uuids = new ParcelUuid[] { ParcelUuid.fromString("00000000-1111-2222-3333-000000000011"), ParcelUuid.fromString("00000000-1111-2222-3333-0000000000aa") }; shadowOf(device).setUuids(uuids); assertThat(device.getUuids()).isEqualTo(uuids); }
@Test public void getCorrectFetchUuidsWithSdpCount() throws Exception { BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(MOCK_MAC_ADDRESS); assertThat(shadowOf(device).getFetchUuidsWithSdpCount()).isEqualTo(0); device.fetchUuidsWithSdp(); assertThat(shadowOf(device).getFetchUuidsWithSdpCount()).isEqualTo(1); device.fetchUuidsWithSdp(); assertThat(shadowOf(device).getFetchUuidsWithSdpCount()).isEqualTo(2); }
@Override public synchronized void initAndCheckEligibility() throws ScannerException { if (Build.VERSION.SDK_INT < ScannerFactory.OS_VERSION_LOLLIPOP) { throw new ScannerException(ScannerException.Type.NOT_SUPPORTED); } if (!Validate.hasBluetoothPermission(context)) { throw new ScannerException(ScannerException.Type.PERMISSION_DENIED); } if (!Validate.hasLocationPermission(context)) { throw new ScannerException(ScannerException.Type.PERMISSION_DENIED); } bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (bluetoothAdapter == null || !bluetoothAdapter.isEnabled()) { throw new ScannerException(ScannerException.Type.DISABLED); } bluetoothLeScanner = bluetoothAdapter.getBluetoothLeScanner(); if (bluetoothLeScanner == null) { throw new ScannerException(ScannerException.Type.UNKNOWN_ERROR); } }
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); LogManager.d(TAG, "about to check if discovery is active"); if (!adapter.isDiscovering()) {
/** * private constructor for singleton * * @param context context */ private BtHelperClient(Context context) { mContext = context.getApplicationContext(); mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); }