Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added code to get bonded devices from adapter #46

Merged
merged 5 commits into from
Jul 22, 2016
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import com.polidea.rxandroidble.internal.RxBleLog;

import java.util.Set;
import java.util.UUID;

import rx.Observable;
Expand Down Expand Up @@ -41,6 +42,8 @@ public static void setLogLevel(@RxBleLog.LogLevel int logLevel) {
*/
public abstract RxBleDevice getBleDevice(@NonNull String macAddress);

public abstract Set<RxBleDevice> getBondedDevices();

/**
* Returns an infinite observable emitting BLE scan results.
* Scan is automatically started and stopped based on the Observable lifecycle.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,17 @@ public RxBleDevice getBleDevice(@NonNull String macAddress) {
return rxBleDeviceProvider.getBleDevice(macAddress);
}

@Override
public Set<RxBleDevice> getBondedDevices() {
Set<RxBleDevice> rxBleDevices = null;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this line should look: Set<RxBleDevice> rxBleDevices = new HashSet(size);
Otherwise the function will throw NPE in line 73 or I have missed where the rxBleDevices is set.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are probably correct. I will make that change.

Copy link
Owner

@dariuszseweryn dariuszseweryn Jul 14, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a test scenario in RxBleClientTest.groovy as well.

Set<BluetoothDevice> bluetoothDevices = rxBleAdapterWrapper.getBondedDevices();
for (BluetoothDevice bluetoothDevice : bluetoothDevices) {
rxBleDevices.add(getBleDevice(bluetoothDevice.getAddress()));
}

return rxBleDevices;
}

@Override
public Observable<RxBleScanResult> scanBleDevices(@Nullable UUID... filterServiceUUIDs) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ protected void protectedRun() {
}
}

public synchronized void stop() { // synchronized keyword added to be sure that operation will be stopped no matter which thread will call it
// synchronized keyword added to be sure that operation will be stopped no matter which thread will call it
public synchronized void stop() {
isStopped = true;
if (isStarted) {
// TODO: [PU] 29.01.2016 https://code.google.com/p/android/issues/detail?id=160503
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import android.bluetooth.BluetoothDevice;
import android.support.annotation.Nullable;

import java.util.Set;

public class RxBleAdapterWrapper {

private final BluetoothAdapter bluetoothAdapter;
Expand Down Expand Up @@ -31,4 +33,8 @@ public boolean startLeScan(BluetoothAdapter.LeScanCallback leScanCallback) {
public void stopLeScan(BluetoothAdapter.LeScanCallback leScanCallback) {
bluetoothAdapter.stopLeScan(leScanCallback);
}

public Set<BluetoothDevice> getBondedDevices() {
return bluetoothAdapter.getBondedDevices();
}
}