Hi there, I attached some patches which can be used to fix the issues related to Bluetooth connectivity on Android platforms.
On Android, a connection to a service cannot be established using a port. The first patch should fix this issue using the uuid of the SPP service on the connection step. On my device with a Android 5.1.1 I observed that if I start the download process without waiting for the scanning process to end, then the devices gets stuck after downloading a few packages. I did over 20 tests for both my dive computers (HW OSTC2 and HW OSTCs) and I got the same results. I looked over the Android logs using the logcat tool and I saw that the download mode always gets stuck when the scanning process is stopped. I am not sure if this is a bug on the Android platform, or on the Qt framework. You can find some logs below. For the moment I created a patch which blocks the save button until the scanning process is finished. Best wishes, Claudiu [ 07-13 21:24:09.687 11588:11772 D/Subsurface ] (null):0 ((null)): [SUBSURFACE] read 1024 [ 07-13 21:24:09.837 11588:11772 D/Subsurface ] (null):0 ((null)): [SUBSURFACE] successfully read 1024 [ 07-13 21:24:09.837 11588:11772 D/Subsurface ] (null):0 ((null)): [SUBSURFACE] read 1024 [ 07-13 21:24:10.064 11588:11772 D/Subsurface ] (null):0 ((null)): [SUBSURFACE] successfully read 1024 [ 07-13 21:24:10.064 11588:11772 D/Subsurface ] (null):0 ((null)): [SUBSURFACE] read 1024 [ 07-13 21:24:10.359 11588:11772 D/Subsurface ] (null):0 ((null)): [SUBSURFACE] successfully read 1024 [ 07-13 21:24:10.359 11588:11772 D/Subsurface ] (null):0 ((null)): [SUBSURFACE] read 1024 [ 07-13 21:24:10.567 11588:11630 D/BluetoothAdapter ] stopLeScan() [ 07-13 21:24:10.577 2427: 2489 D/BtGatt.GattService ] stopScan() - queue size =1 [ 07-13 21:24:10.578 2427: 2501 D/BtGatt.ScanManager ] stop scan [ 07-13 21:24:10.582 2427: 2501 D/BtGatt.ScanManager ] configureRegularScanParams() - queue=0 [ 07-13 21:24:10.582 2427: 2501 D/BtGatt.ScanManager ] configureRegularScanParams() - ScanSetting Scan mode=-2147483648 mLastConfiguredScanSetting=2 [ 07-13 21:24:10.582 2427: 2501 D/BtGatt.ScanManager ] configureRegularScanParams() - queue emtpy, scan stopped [ 07-13 21:24:10.593 2427: 2443 D/BtGatt.GattService ] unregisterClient() - clientIf=5
From d66fad97993323ba3ed422e624cab47d7fe799f5 Mon Sep 17 00:00:00 2001 From: Claudiu Olteanu <olteanu.clau...@ymail.com> Date: Mon, 13 Jul 2015 23:37:49 +0300 Subject: [PATCH 1/2] 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.clau...@ymail.com> --- qtserialbluetooth.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/qtserialbluetooth.cpp b/qtserialbluetooth.cpp index f06f24e..95f3611 100644 --- a/qtserialbluetooth.cpp +++ b/qtserialbluetooth.cpp @@ -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 -- 2.1.4
From b535e9137bdcd67b9f92f097cc91a9961fb1a98d Mon Sep 17 00:00:00 2001 From: Claudiu Olteanu <olteanu.clau...@ymail.com> Date: Mon, 13 Jul 2015 23:44:09 +0300 Subject: [PATCH 2/2] Wait until the BT scanning process is done on Android platforms Block the Save button on Android platforms until the scanning for remote Bluetooth devices is finished. The reason we do that is because there is a bug on the Android platform or on the QtBluetooth library which stops the downloading process and blocks the devices on the Download mode. Signed-off-by: Claudiu Olteanu <olteanu.clau...@ymail.com> --- qt-ui/btdeviceselectiondialog.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/qt-ui/btdeviceselectiondialog.cpp b/qt-ui/btdeviceselectiondialog.cpp index 436dca5..9b97da3 100644 --- a/qt-ui/btdeviceselectiondialog.cpp +++ b/qt-ui/btdeviceselectiondialog.cpp @@ -108,6 +108,21 @@ void BtDeviceSelectionDialog::remoteDeviceScanFinished() { ui->dialogStatus->setText("Scanning finished."); ui->scan->setEnabled(true); + +#if defined(Q_OS_ANDROID) + // Check if there is a selected device and activate the Save button if it is paired + QListWidgetItem *currentItem = ui->discoveredDevicesList->currentItem(); + + if (currentItem != NULL) { + QBluetoothDeviceInfo remoteDeviceInfo = currentItem->data(Qt::UserRole).value<QBluetoothDeviceInfo>(); + QBluetoothLocalDevice::Pairing pairingStatus = localDevice->pairingStatus(remoteDeviceInfo.address()); + + if (pairingStatus != QBluetoothLocalDevice::Unpaired) { + ui->save->setEnabled(true); + ui->dialogStatus->setText("Scanning finished. You can press the Save button and start the download."); + } + } +#endif } void BtDeviceSelectionDialog::hostModeStateChanged(QBluetoothLocalDevice::HostMode mode) @@ -156,6 +171,13 @@ void BtDeviceSelectionDialog::itemActivated(QListWidgetItem *item) .arg(remoteDeviceInfo.address().toString())); ui->save->setEnabled(false); } else { +#if defined(Q_OS_ANDROID) + if (remoteDeviceDiscoveryAgent->isActive()) { + ui->dialogStatus->setText(QString("The device %1 can be used for connection. Wait until the device scanning is done and press the Save button.") + .arg(remoteDeviceInfo.address().toString())); + return; + } +#endif ui->dialogStatus->setText(QString("The device %1 can be used for connection. You can press the Save button.") .arg(remoteDeviceInfo.address().toString())); ui->save->setEnabled(true); -- 2.1.4
_______________________________________________ subsurface mailing list subsurface@subsurface-divelog.org http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface