summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2017-01-24 13:54:45 +0100
committerLiang Qi <liang.qi@qt.io>2017-01-24 13:54:45 +0100
commita8604157818e21d7b70e2853258fc4569db770be (patch)
tree2b5297bf4140bad1c7b357047f6515fa0f7c4e22
parent498020954fd00e3de545dbc414ba09196e0f59b7 (diff)
parent468e3c38a893b9293a9f0ede432ce54d72b46966 (diff)
Merge remote-tracking branch 'origin/5.8' into dev
-rw-r--r--dist/changes-5.7.14
-rw-r--r--src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothLE.java37
2 files changed, 37 insertions, 4 deletions
diff --git a/dist/changes-5.7.1 b/dist/changes-5.7.1
index 2638ceac..e04fa837 100644
--- a/dist/changes-5.7.1
+++ b/dist/changes-5.7.1
@@ -56,12 +56,12 @@ Android
This happened when SDP and BTLE scan revealed the same device with
different names.
-iOS/OS X
+iOS/macOS
---------
- Fixed potential linker error on iOS.
- Added some minor code cleanups.
- - Added support for iOS 10 and MacOSX10.12 SDK.
+ - Added support for iOS 10 and macOS 10.12 SDKs.
Linux/Bluez
-----------
diff --git a/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothLE.java b/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothLE.java
index 53c7305f..cb7b2dc9 100644
--- a/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothLE.java
+++ b/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothLE.java
@@ -51,6 +51,7 @@ import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
+import java.lang.reflect.Method;
import java.util.concurrent.atomic.AtomicInteger;
import java.lang.reflect.Method;
@@ -187,9 +188,11 @@ public class QtBluetoothLE {
case BluetoothGatt.GATT_SUCCESS:
errorCode = 0; break; //QLowEnergyController::NoError
case 8: // link loss
+ case 22: // BTA_GATT_CONN_LMP_TIMEOUT
+ Log.w(TAG, "Connection Error: Try to delay connect() call after previous activity");
errorCode = 5; break; //QLowEnergyController::ConnectionError
default:
- Log.w(TAG, "Unhandled error code on connectionStateChanged: " + status);
+ Log.w(TAG, "Unhandled error code on connectionStateChanged: " + status + " " + newState);
errorCode = status; break; //TODO deal with all errors
}
leConnectionStateChange(qtObject, errorCode, qLowEnergyController_State);
@@ -479,7 +482,31 @@ public class QtBluetoothLE {
return false;
}
- mBluetoothGatt = mRemoteGattDevice.connectGatt(qtContext, false, gattCallback);
+ try {
+ // BluetoothDevice.,connectGatt(Context, boolean, BluetoothGattCallback, int) was
+ // officially introduced by Android API v23. Earlier Android versions have a private
+ // implementation already though. Let's check at runtime and use it if possible.
+ //
+ // In general the new connectGatt() seems to be much more reliable than the function
+ // that doesn't specify the transport layer.
+
+ Class[] args = new Class[4];
+ args[0] = android.content.Context.class;
+ args[1] = boolean.class;
+ args[2] = android.bluetooth.BluetoothGattCallback.class;
+ args[3] = int.class;
+ Method connectMethod = mRemoteGattDevice.getClass().getDeclaredMethod("connectGatt", args);
+ if (connectMethod != null) {
+ mBluetoothGatt = (BluetoothGatt) connectMethod.invoke(mRemoteGattDevice, qtContext,
+ false, gattCallback,
+ 2 /*TRANSPORT_LE*/);
+ Log.w(TAG, "Using Android v23 BluetoothDevice.connectGatt()");
+ }
+ } catch (Exception ex) {
+ // fallback to less reliable API 18 version
+ mBluetoothGatt = mRemoteGattDevice.connectGatt(qtContext, false, gattCallback);
+ }
+
return mBluetoothGatt != null;
}
@@ -819,6 +846,12 @@ public class QtBluetoothLE {
GattEntry serviceEntry = entries.get(serviceHandle);
final int endHandle = serviceEntry.endHandle;
+ if (serviceHandle == endHandle) {
+ Log.w(TAG, "scheduleServiceDetailDiscovery: service is empty; nothing to discover");
+ finishCurrentServiceDiscovery(serviceHandle);
+ return;
+ }
+
synchronized (readWriteQueue) {
// entire block inside mutex to ensure all service discovery jobs go in one after the other
// ensures that serviceDiscovered() signal is sent when required