Search in sources :

Example 46 with BluetoothDevice

use of android.bluetooth.BluetoothDevice in project android_frameworks_base by crdroidandroid.

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();
}
Also used : BluetoothDevice(android.bluetooth.BluetoothDevice) ScanFilter(android.bluetooth.le.ScanFilter) BluetoothAdapter(android.bluetooth.BluetoothAdapter)

Example 47 with BluetoothDevice

use of android.bluetooth.BluetoothDevice in project android_frameworks_base by crdroidandroid.

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(device);
        }
    }
    Log.d(TAG, "PBAPClientProfile attempting to connect to " + device.getAddress());
    return mService.connect(device);
}
Also used : BluetoothDevice(android.bluetooth.BluetoothDevice)

Example 48 with BluetoothDevice

use of android.bluetooth.BluetoothDevice in project android_frameworks_base by crdroidandroid.

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;
}
Also used : BluetoothDevice(android.bluetooth.BluetoothDevice)

Example 49 with BluetoothDevice

use of android.bluetooth.BluetoothDevice in project android_frameworks_base by AOSPA.

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(device);
        }
    }
    Log.d(TAG, "PBAPClientProfile attempting to connect to " + device.getAddress());
    return mService.connect(device);
}
Also used : BluetoothDevice(android.bluetooth.BluetoothDevice)

Example 50 with BluetoothDevice

use of android.bluetooth.BluetoothDevice in project android_frameworks_base by AOSPA.

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;
}
Also used : BluetoothDevice(android.bluetooth.BluetoothDevice)

Aggregations

BluetoothDevice (android.bluetooth.BluetoothDevice)101 Intent (android.content.Intent)13 BluetoothAdapter (android.bluetooth.BluetoothAdapter)12 CachedBluetoothDevice (com.android.settingslib.bluetooth.CachedBluetoothDevice)11 ParcelUuid (android.os.ParcelUuid)9 RemoteException (android.os.RemoteException)9 ScanFilter (android.bluetooth.le.ScanFilter)5 Parcel (android.os.Parcel)5 SmallTest (android.test.suitebuilder.annotation.SmallTest)5 IOException (java.io.IOException)5 GBDevice (nodomain.freeyourgadget.gadgetbridge.impl.GBDevice)5 IntentFilter (android.content.IntentFilter)4 MidiDeviceInfo (android.media.midi.MidiDeviceInfo)4 View (android.view.View)4 AdapterView (android.widget.AdapterView)3 ListView (android.widget.ListView)3 TextView (android.widget.TextView)3 Method (java.lang.reflect.Method)3 ArrayList (java.util.ArrayList)3 PendingIntent (android.app.PendingIntent)2