summaryrefslogtreecommitdiffstats
path: root/src/android
diff options
context:
space:
mode:
authorQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2018-04-24 03:00:19 +0200
committerQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2018-04-24 03:00:19 +0200
commitd5478ce1bda5f1ba112fb67eff9e1b8c66fd3973 (patch)
treef5e539813addca6222213ce74cbdb7b68984f6b9 /src/android
parentc7304d2c236be2e8902ea3df9c132fe5ac601ec4 (diff)
parentdc435c6ce0a6ecae776dc0dd032016453a0b4b56 (diff)
Merge remote-tracking branch 'origin/5.11' into dev
Diffstat (limited to 'src/android')
-rw-r--r--src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothLEServer.java29
1 files changed, 23 insertions, 6 deletions
diff --git a/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothLEServer.java b/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothLEServer.java
index 034190fd..cdd16686 100644
--- a/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothLEServer.java
+++ b/src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothLEServer.java
@@ -213,7 +213,6 @@ public class QtBluetoothLEServer {
return;
}
- mGattServer = manager.openGattServer(qtContext, mGattServerListener);
mLeAdvertiser = mBluetoothAdapter.getBluetoothLeAdvertiser();
if (!mBluetoothAdapter.isMultipleAdvertisementSupported())
@@ -229,7 +228,7 @@ public class QtBluetoothLEServer {
{
@Override
public void onConnectionStateChange(BluetoothDevice device, int status, int newState) {
- Log.w(TAG, "Our gatt server connection state changed, new state: " + newState);
+ Log.w(TAG, "Our gatt server connection state changed, new state: " + newState + " " + status);
super.onConnectionStateChange(device, status, newState);
int qtControllerState = 0;
@@ -237,6 +236,7 @@ public class QtBluetoothLEServer {
case BluetoothProfile.STATE_DISCONNECTED:
qtControllerState = 0; // QLowEnergyController::UnconnectedState
clientCharacteristicManager.markDeviceConnectivity(device, false);
+ mGattServer.close();
break;
case BluetoothProfile.STATE_CONNECTED:
clientCharacteristicManager.markDeviceConnectivity(device, true);
@@ -401,10 +401,18 @@ public class QtBluetoothLEServer {
public boolean connectServer()
{
- if (mGattServer == null)
+ if (mGattServer != null)
+ return true;
+
+ BluetoothManager manager = (BluetoothManager) qtContext.getSystemService(Context.BLUETOOTH_SERVICE);
+ if (manager == null) {
+ Log.w(TAG, "Bluetooth service not available.");
return false;
+ }
- return true;
+ mGattServer = manager.openGattServer(qtContext, mGattServerListener);
+
+ return (mGattServer != null);
}
public void disconnectServer()
@@ -413,6 +421,10 @@ public class QtBluetoothLEServer {
return;
mGattServer.close();
+ mGattServer = null;
+
+ mRemoteName = mRemoteAddress = "";
+ leServerConnectionStateChange(qtObject, 0 /*NoError*/, 0 /*QLowEnergyController::UnconnectedState*/);
}
public boolean startAdvertising(AdvertiseData advertiseData,
@@ -422,7 +434,10 @@ public class QtBluetoothLEServer {
if (mLeAdvertiser == null)
return false;
- connectServer();
+ if (!connectServer()) {
+ Log.w(TAG, "Server::startAdvertising: Cannot open GATT server");
+ return false;
+ }
Log.w(TAG, "Starting to advertise.");
mLeAdvertiser.startAdvertising(settings, advertiseData, scanResponse, mAdvertiseListener);
@@ -441,8 +456,10 @@ public class QtBluetoothLEServer {
public void addService(BluetoothGattService service)
{
- if (mGattServer == null)
+ if (!connectServer()) {
+ Log.w(TAG, "Server::addService: Cannot open GATT server");
return;
+ }
mGattServer.addService(service);
}