summaryrefslogtreecommitdiffstats
path: root/src/android
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@qt.io>2017-01-03 17:21:17 +0100
committerAlex Blasche <alexander.blasche@qt.io>2017-01-23 09:03:43 +0000
commitd66b34100ad3e5ddd226ba85c4e974ad08e22205 (patch)
treec212ce7a0a30c9c94e17ec57986522b6186969b7 /src/android
parent46a776eb70d7b3e40bb80cb4f4314d3462801b62 (diff)
Android: Implement QLEC::stateChanged() notification
Change-Id: Id2cabd9df7b5387fe5e6f1c898fe02e40f7c0a3d Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io> Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'src/android')
-rw-r--r--src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothLEServer.java27
1 files changed, 27 insertions, 0 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 c4337660..685b9161 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
@@ -45,9 +45,11 @@ import android.bluetooth.BluetoothGattDescriptor;
import android.bluetooth.BluetoothGattService;
import android.content.Context;
import android.bluetooth.BluetoothAdapter;
+import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattServer;
import android.bluetooth.BluetoothGattServerCallback;
import android.bluetooth.BluetoothManager;
+import android.bluetooth.BluetoothProfile;
import android.bluetooth.le.AdvertiseCallback;
import android.bluetooth.le.AdvertiseData;
import android.bluetooth.le.AdvertiseData.Builder;
@@ -105,7 +107,30 @@ public class QtBluetoothLEServer {
{
@Override
public void onConnectionStateChange(BluetoothDevice device, int status, int newState) {
+ Log.w(TAG, "Our gatt server connection state changed, new state: " + Integer.toString(newState));
super.onConnectionStateChange(device, status, newState);
+
+ int qtControllerState = 0;
+ switch (newState) {
+ case BluetoothProfile.STATE_DISCONNECTED:
+ qtControllerState = 0; // QLowEnergyController::UnconnectedState
+ break;
+ case BluetoothProfile.STATE_CONNECTED:
+ qtControllerState = 2; // QLowEnergyController::ConnectedState
+ break;
+ }
+
+ int qtErrorCode;
+ switch (status) {
+ case BluetoothGatt.GATT_SUCCESS:
+ qtErrorCode = 0; break;
+ default:
+ Log.w(TAG, "Unhandled error code on peripheral connectionStateChanged: " + status + " " + newState);
+ qtErrorCode = status;
+ break;
+ }
+
+ leServerConnectionStateChange(qtObject, qtErrorCode, qtControllerState);
}
@Override
@@ -215,4 +240,6 @@ public class QtBluetoothLEServer {
}
};
+ public native void leServerConnectionStateChange(long qtObject, int errorCode, int newState);
+
}