Search in sources :

Example 41 with BluetoothDevice

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

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 42 with BluetoothDevice

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

the class MidiService method openBluetoothDevice.

@Override
public void openBluetoothDevice(IBinder token, BluetoothDevice bluetoothDevice, IMidiDeviceOpenCallback callback) {
    Client client = getClient(token);
    if (client == null)
        return;
    // Bluetooth devices are created on demand
    Device device;
    synchronized (mDevicesByInfo) {
        device = mBluetoothDevices.get(bluetoothDevice);
        if (device == null) {
            device = new Device(bluetoothDevice);
            mBluetoothDevices.put(bluetoothDevice, device);
        }
    }
    // clear calling identity so bindService does not fail
    long identity = Binder.clearCallingIdentity();
    try {
        client.addDeviceConnection(device, callback);
    } finally {
        Binder.restoreCallingIdentity(identity);
    }
}
Also used : BluetoothDevice(android.bluetooth.BluetoothDevice)

Example 43 with BluetoothDevice

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

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 44 with BluetoothDevice

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

the class MidiService method openBluetoothDevice.

@Override
public void openBluetoothDevice(IBinder token, BluetoothDevice bluetoothDevice, IMidiDeviceOpenCallback callback) {
    Client client = getClient(token);
    if (client == null)
        return;
    // Bluetooth devices are created on demand
    Device device;
    synchronized (mDevicesByInfo) {
        device = mBluetoothDevices.get(bluetoothDevice);
        if (device == null) {
            device = new Device(bluetoothDevice);
            mBluetoothDevices.put(bluetoothDevice, device);
        }
    }
    // clear calling identity so bindService does not fail
    long identity = Binder.clearCallingIdentity();
    try {
        client.addDeviceConnection(device, callback);
    } finally {
        Binder.restoreCallingIdentity(identity);
    }
}
Also used : BluetoothDevice(android.bluetooth.BluetoothDevice)

Example 45 with BluetoothDevice

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

the class ScanResultTest method testScanResultParceling.

/**
     * Test read and write parcel of ScanResult
     */
@SmallTest
public void testScanResultParceling() {
    BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice("01:02:03:04:05:06");
    byte[] scanRecord = new byte[] { 1, 2, 3 };
    int rssi = -10;
    long timestampMicros = 10000L;
    ScanResult result = new ScanResult(device, ScanRecord.parseFromBytes(scanRecord), rssi, timestampMicros);
    Parcel parcel = Parcel.obtain();
    result.writeToParcel(parcel, 0);
    // Need to reset parcel data position to the beginning.
    parcel.setDataPosition(0);
    ScanResult resultFromParcel = ScanResult.CREATOR.createFromParcel(parcel);
    assertEquals(result, resultFromParcel);
}
Also used : BluetoothDevice(android.bluetooth.BluetoothDevice) Parcel(android.os.Parcel) SmallTest(android.test.suitebuilder.annotation.SmallTest)

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