We can now list supported bluetooth services

This commit is contained in:
Alexandros Schillings
2015-07-13 17:13:06 +01:00
parent eae8e9c776
commit 4e173659e9
5 changed files with 83 additions and 0 deletions
@@ -7,7 +7,10 @@ import android.os.Parcelable;
import java.io.Serializable;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import uk.co.alt236.bluetoothlelib.device.adrecord.AdRecordStore;
import uk.co.alt236.bluetoothlelib.resolvers.BluetoothClassResolver;
@@ -55,6 +58,7 @@ public class BluetoothLeDevice implements Parcelable {
private final long mFirstTimestamp;
private int mCurrentRssi;
private long mCurrentTimestamp;
private transient Set<BluetoothService> mServiceSet;
/**
* Instantiates a new Bluetooth LE device.
@@ -221,6 +225,25 @@ public class BluetoothLeDevice implements Parcelable {
return BluetoothClassResolver.resolveMajorDeviceClass(mDevice.getBluetoothClass().getMajorDeviceClass());
}
public Set<BluetoothService> getBluetoothDeviceKnownSupportedServices() {
if (mServiceSet == null) {
synchronized (this) {
if (mServiceSet == null) {
final Set<BluetoothService> serviceSet = new HashSet<>();
for (final BluetoothService service : BluetoothService.values()) {
if (mDevice.getBluetoothClass().hasService(service.getAndroidConstant())) {
serviceSet.add(service);
}
}
mServiceSet = Collections.unmodifiableSet(serviceSet);
}
}
}
return mServiceSet;
}
/**
* Gets the device.
*
@@ -0,0 +1,28 @@
package uk.co.alt236.bluetoothlelib.device;
import android.bluetooth.BluetoothClass;
/**
*
*/
public enum BluetoothService {
AUDIO(BluetoothClass.Service.AUDIO),
CAPTURE(BluetoothClass.Service.CAPTURE),
INFORMATION(BluetoothClass.Service.INFORMATION),
LIMITED_DISCOVERABILITY(BluetoothClass.Service.LIMITED_DISCOVERABILITY),
NETWORKING(BluetoothClass.Service.NETWORKING),
OBJECT_TRANSFER(BluetoothClass.Service.OBJECT_TRANSFER),
POSITIONING(BluetoothClass.Service.POSITIONING),
RENDER(BluetoothClass.Service.RENDER),
TELEPHONY(BluetoothClass.Service.TELEPHONY);
private final int mAndroidConstant;
BluetoothService(final int androidCode){
mAndroidConstant = androidCode;
}
public int getAndroidConstant(){
return mAndroidConstant;
}
}