use of android.bluetooth.BluetoothDevice in project android_frameworks_base by ParanoidAndroid.
the class BluetoothGatt method readDescriptor.
/**
* Reads the value for a given descriptor from the associated remote device.
*
* <p>Once the read operation has been completed, the
* {@link BluetoothGattCallback#onDescriptorRead} callback is
* triggered, signaling the result of the operation.
*
* <p>Requires {@link android.Manifest.permission#BLUETOOTH} permission.
*
* @param descriptor Descriptor value to read from the remote device
* @return true, if the read operation was initiated successfully
*/
public boolean readDescriptor(BluetoothGattDescriptor descriptor) {
if (DBG)
Log.d(TAG, "readDescriptor() - uuid: " + descriptor.getUuid());
if (mService == null || mClientIf == 0)
return false;
BluetoothGattCharacteristic characteristic = descriptor.getCharacteristic();
if (characteristic == null)
return false;
BluetoothGattService service = characteristic.getService();
if (service == null)
return false;
BluetoothDevice device = service.getDevice();
if (device == null)
return false;
try {
mService.readDescriptor(mClientIf, device.getAddress(), service.getType(), service.getInstanceId(), new ParcelUuid(service.getUuid()), characteristic.getInstanceId(), new ParcelUuid(characteristic.getUuid()), new ParcelUuid(descriptor.getUuid()), AUTHENTICATION_NONE);
} catch (RemoteException e) {
Log.e(TAG, "", e);
return false;
}
return true;
}
use of android.bluetooth.BluetoothDevice in project platform_frameworks_base by android.
the class BluetoothEventManager method readPairedDevices.
boolean readPairedDevices() {
Set<BluetoothDevice> bondedDevices = mLocalAdapter.getBondedDevices();
if (bondedDevices == null) {
return false;
}
boolean deviceAdded = false;
for (BluetoothDevice device : bondedDevices) {
CachedBluetoothDevice cachedDevice = mDeviceManager.findDevice(device);
if (cachedDevice == null) {
cachedDevice = mDeviceManager.addDevice(mLocalAdapter, mProfileManager, device);
dispatchDeviceAdded(cachedDevice);
deviceAdded = true;
}
}
return deviceAdded;
}
use of android.bluetooth.BluetoothDevice in project platform_frameworks_base by android.
the class PbapClientProfile method connect.
public boolean connect(BluetoothDevice device) {
if (V) {
Log.d(TAG, "PBAPClientProfile got connect request");
}
if (mService == null) {
return false;
}
List<BluetoothDevice> srcs = getConnectedDevices();
if (srcs != null) {
for (BluetoothDevice src : srcs) {
if (src.equals(device)) {
// Connect to same device, Ignore it
Log.d(TAG, "Ignoring Connect");
return true;
}
}
for (BluetoothDevice src : srcs) {
mService.disconnect(src);
}
}
Log.d(TAG, "PBAPClientProfile attempting to connect to " + device.getAddress());
return mService.connect(device);
}
use of android.bluetooth.BluetoothDevice in project platform_frameworks_base by android.
the class ScanFilter method matches.
/**
* Check if the scan filter matches a {@code scanResult}. A scan result is considered as a match
* if it matches all the field filters.
*/
public boolean matches(ScanResult scanResult) {
if (scanResult == null) {
return false;
}
BluetoothDevice device = scanResult.getDevice();
// Device match.
if (mDeviceAddress != null && (device == null || !mDeviceAddress.equals(device.getAddress()))) {
return false;
}
ScanRecord scanRecord = scanResult.getScanRecord();
// Scan record is null but there exist filters on it.
if (scanRecord == null && (mDeviceName != null || mServiceUuid != null || mManufacturerData != null || mServiceData != null)) {
return false;
}
// Local name match.
if (mDeviceName != null && !mDeviceName.equals(scanRecord.getDeviceName())) {
return false;
}
// UUID match.
if (mServiceUuid != null && !matchesServiceUuids(mServiceUuid, mServiceUuidMask, scanRecord.getServiceUuids())) {
return false;
}
// Service data match
if (mServiceDataUuid != null) {
if (!matchesPartialData(mServiceData, mServiceDataMask, scanRecord.getServiceData(mServiceDataUuid))) {
return false;
}
}
// Manufacturer data match.
if (mManufacturerId >= 0) {
if (!matchesPartialData(mManufacturerData, mManufacturerDataMask, scanRecord.getManufacturerSpecificData(mManufacturerId))) {
return false;
}
}
// All filters match.
return true;
}
use of android.bluetooth.BluetoothDevice in project platform_frameworks_base by android.
the class ScanFilterTest method setUp.
@Override
protected void setUp() throws Exception {
byte[] scanRecord = new byte[] { // advertising flags
0x02, // advertising flags
0x01, // advertising flags
0x1a, // 16 bit service uuids
0x05, // 16 bit service uuids
0x02, // 16 bit service uuids
0x0b, // 16 bit service uuids
0x11, // 16 bit service uuids
0x0a, // 16 bit service uuids
0x11, // setName
0x04, // setName
0x09, // setName
0x50, // setName
0x65, // setName
0x64, // tx power level
0x02, // tx power level
0x0A, // tx power level
(byte) 0xec, // service data
0x05, // service data
0x16, // service data
0x0b, // service data
0x11, // service data
0x50, // service data
0x64, // manufacturer specific data
0x05, // manufacturer specific data
(byte) 0xff, // manufacturer specific data
(byte) 0xe0, // manufacturer specific data
0x00, // manufacturer specific data
0x02, // manufacturer specific data
0x15, // an unknown data type won't cause trouble
0x03, // an unknown data type won't cause trouble
0x50, // an unknown data type won't cause trouble
0x01, // an unknown data type won't cause trouble
0x02 };
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
BluetoothDevice device = adapter.getRemoteDevice(DEVICE_MAC);
mScanResult = new ScanResult(device, ScanRecord.parseFromBytes(scanRecord), -10, 1397545200000000L);
mFilterBuilder = new ScanFilter.Builder();
}
Aggregations