Use SPP's uuid to connect to a device on Android platform

On Android, a Bluetooth connection to a service cannot be
established using a port. Therefore we use the uuid of the
Serial Port Profile service to connect to the remote BT
device.

Signed-off-by: Claudiu Olteanu <olteanu.claudiu@ymail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Claudiu Olteanu 2015-07-13 23:37:49 +03:00 committed by Dirk Hohndel
parent 521183dc73
commit c6c706c28a

View file

@ -54,6 +54,7 @@ static int qt_serial_open(serial_t **out, dc_context_t *context, const char* dev
timer.setSingleShot(true);
loop.connect(&timer, SIGNAL(timeout()), SLOT(quit()));
#if defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID)
// First try to connect on RFCOMM channel 1. This is the default channel for most devices
QBluetoothAddress remoteDeviceAddress(devaddr);
serial_port->socket->connectToService(remoteDeviceAddress, 1);
@ -79,8 +80,22 @@ static int qt_serial_open(serial_t **out, dc_context_t *context, const char* dev
loop.exec();
}
}
#elif defined(Q_OS_ANDROID)
// Try to connect to the device using the uuid of the Serial Port Profile service
QBluetoothAddress remoteDeviceAddress(devaddr);
serial_port->socket->connectToService(remoteDeviceAddress, QBluetoothUuid(QBluetoothUuid::SerialPort));
timer.start(msec);
loop.exec();
if (serial_port->socket->socketDescriptor() == -1 || serial_port->socket->state() != QBluetoothSocket::ConnectedState) {
if (serial_port->socket->state() == QBluetoothSocket::ConnectingState ||
serial_port->socket->state() == QBluetoothSocket::ServiceLookupState) {
// It seems that the connection step took more than expected. Wait another 20 seconds.
qDebug() << "The connection step took more than expected. Wait another 20 seconds";
timer.start(4 * msec);
loop.exec();
}
#endif
if (serial_port->socket->state() != QBluetoothSocket::ConnectedState) {
free (serial_port);
// Get the latest error and try to match it with one from libdivecomputer