Search in sources :

Example 71 with ParcelUuid

use of android.os.ParcelUuid in project Gadgetbridge by Freeyourgadget.

the class PebbleIoThread method connect.

@Override
protected boolean connect() {
    String deviceAddress = gbDevice.getAddress();
    GBDevice.State originalState = gbDevice.getState();
    gbDevice.setState(GBDevice.State.CONNECTING);
    gbDevice.sendDeviceUpdateIntent(getContext());
    try {
        // contains only one ":"? then it is addr:port
        int firstColon = deviceAddress.indexOf(":");
        if (firstColon == deviceAddress.lastIndexOf(":")) {
            mIsTCP = true;
            InetAddress serverAddr = InetAddress.getByName(deviceAddress.substring(0, firstColon));
            mTCPSocket = new Socket(serverAddr, Integer.parseInt(deviceAddress.substring(firstColon + 1)));
            mInStream = mTCPSocket.getInputStream();
            mOutStream = mTCPSocket.getOutputStream();
        } else {
            mIsTCP = false;
            if (gbDevice.getVolatileAddress() != null && prefs.getBoolean("pebble_force_le", false)) {
                deviceAddress = gbDevice.getVolatileAddress();
            }
            BluetoothDevice btDevice = mBtAdapter.getRemoteDevice(deviceAddress);
            if (btDevice.getType() == BluetoothDevice.DEVICE_TYPE_LE) {
                LOG.info("This is a Pebble 2 or Pebble-LE/Pebble Time LE, will use BLE");
                mInStream = new PipedInputStream();
                mOutStream = new PipedOutputStream();
                mPebbleLESupport = new PebbleLESupport(this.getContext(), btDevice, (PipedInputStream) mInStream, (PipedOutputStream) mOutStream);
            } else {
                ParcelUuid[] uuids = btDevice.getUuids();
                if (uuids == null) {
                    return false;
                }
                for (ParcelUuid uuid : uuids) {
                    LOG.info("found service UUID " + uuid);
                }
                mBtSocket = btDevice.createRfcommSocketToServiceRecord(uuids[0].getUuid());
                mBtSocket.connect();
                mInStream = mBtSocket.getInputStream();
                mOutStream = mBtSocket.getOutputStream();
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
        gbDevice.setState(originalState);
        gbDevice.sendDeviceUpdateIntent(getContext());
        mInStream = null;
        mOutStream = null;
        mBtSocket = null;
        return false;
    }
    mPebbleProtocol.setForceProtocol(prefs.getBoolean("pebble_force_protocol", false));
    mIsConnected = true;
    write(mPebbleProtocol.encodeFirmwareVersionReq());
    gbDevice.setState(GBDevice.State.CONNECTED);
    gbDevice.sendDeviceUpdateIntent(getContext());
    return true;
}
Also used : ParcelUuid(android.os.ParcelUuid) BluetoothDevice(android.bluetooth.BluetoothDevice) PipedOutputStream(java.io.PipedOutputStream) PipedInputStream(java.io.PipedInputStream) IOException(java.io.IOException) GBDevice(nodomain.freeyourgadget.gadgetbridge.impl.GBDevice) PebbleLESupport(nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.ble.PebbleLESupport) InetAddress(java.net.InetAddress) BluetoothSocket(android.bluetooth.BluetoothSocket) Socket(java.net.Socket)

Example 72 with ParcelUuid

use of android.os.ParcelUuid in project Gadgetbridge by Freeyourgadget.

the class LiveviewIoThread method connect.

@Override
protected boolean connect() {
    GBDevice.State originalState = gbDevice.getState();
    setUpdateState(GBDevice.State.CONNECTING);
    try {
        BluetoothDevice btDevice = mBtAdapter.getRemoteDevice(gbDevice.getAddress());
        ParcelUuid[] uuids = btDevice.getUuids();
        if (uuids == null) {
            return false;
        }
        for (ParcelUuid uuid : uuids) {
            LOG.info("found service UUID " + uuid);
        }
        mBtSocket = btDevice.createRfcommSocketToServiceRecord(uuids[0].getUuid());
        mBtSocket.connect();
        mInStream = mBtSocket.getInputStream();
        mOutStream = mBtSocket.getOutputStream();
        setUpdateState(GBDevice.State.CONNECTED);
    } catch (IOException e) {
        LOG.error("Server socket cannot be started.");
        //LOG.error(e.getMessage());
        setUpdateState(originalState);
        mInStream = null;
        mOutStream = null;
        mBtSocket = null;
        return false;
    }
    write(mLiveviewProtocol.encodeSetTime());
    setUpdateState(GBDevice.State.INITIALIZED);
    return true;
}
Also used : ParcelUuid(android.os.ParcelUuid) BluetoothDevice(android.bluetooth.BluetoothDevice) IOException(java.io.IOException) GBDevice(nodomain.freeyourgadget.gadgetbridge.impl.GBDevice)

Example 73 with ParcelUuid

use of android.os.ParcelUuid in project Gadgetbridge by Freeyourgadget.

the class HPlusCoordinator method createBLEScanFilters.

@NonNull
@Override
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public Collection<? extends ScanFilter> createBLEScanFilters() {
    ParcelUuid hpService = new ParcelUuid(HPlusConstants.UUID_SERVICE_HP);
    ScanFilter filter = new ScanFilter.Builder().setServiceUuid(hpService).build();
    return Collections.singletonList(filter);
}
Also used : ParcelUuid(android.os.ParcelUuid) ScanFilter(android.bluetooth.le.ScanFilter) QueryBuilder(de.greenrobot.dao.query.QueryBuilder) NonNull(android.support.annotation.NonNull) TargetApi(android.annotation.TargetApi)

Example 74 with ParcelUuid

use of android.os.ParcelUuid in project Gadgetbridge by Freeyourgadget.

the class MiBand2Coordinator method createBLEScanFilters.

@NonNull
@Override
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public Collection<? extends ScanFilter> createBLEScanFilters() {
    ParcelUuid mi2Service = new ParcelUuid(MiBandService.UUID_SERVICE_MIBAND2_SERVICE);
    ScanFilter filter = new ScanFilter.Builder().setServiceUuid(mi2Service).build();
    return Collections.singletonList(filter);
}
Also used : ParcelUuid(android.os.ParcelUuid) ScanFilter(android.bluetooth.le.ScanFilter) NonNull(android.support.annotation.NonNull) TargetApi(android.annotation.TargetApi)

Example 75 with ParcelUuid

use of android.os.ParcelUuid in project Gadgetbridge by Freeyourgadget.

the class MiBandCoordinator method createBLEScanFilters.

@NonNull
@Override
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public Collection<? extends ScanFilter> createBLEScanFilters() {
    ParcelUuid mi1Service = new ParcelUuid(MiBandService.UUID_SERVICE_MIBAND_SERVICE);
    ScanFilter filter = new ScanFilter.Builder().setServiceUuid(mi1Service).build();
    return Collections.singletonList(filter);
}
Also used : ParcelUuid(android.os.ParcelUuid) ScanFilter(android.bluetooth.le.ScanFilter) QueryBuilder(de.greenrobot.dao.query.QueryBuilder) NonNull(android.support.annotation.NonNull) TargetApi(android.annotation.TargetApi)

Aggregations

ParcelUuid (android.os.ParcelUuid)147 SmallTest (android.test.suitebuilder.annotation.SmallTest)43 RemoteException (android.os.RemoteException)29 UUID (java.util.UUID)24 ArrayList (java.util.ArrayList)23 GenericSoundModel (android.hardware.soundtrigger.SoundTrigger.GenericSoundModel)20 Parcel (android.os.Parcel)20 ScanFilter (android.bluetooth.le.ScanFilter)19 RecognitionConfig (android.hardware.soundtrigger.SoundTrigger.RecognitionConfig)12 LargeTest (android.test.suitebuilder.annotation.LargeTest)12 ScanRecord (android.bluetooth.le.ScanRecord)10 BluetoothDevice (android.bluetooth.BluetoothDevice)9 Socket (java.net.Socket)9 DataOutputStream (java.io.DataOutputStream)8 ByteBuffer (java.nio.ByteBuffer)8 SparseArray (android.util.SparseArray)6 RequiresPermission (android.annotation.RequiresPermission)5 BluetoothClass (android.bluetooth.BluetoothClass)5 BluetoothLeScanner (android.bluetooth.le.BluetoothLeScanner)5 ScanCallback (android.bluetooth.le.ScanCallback)5