summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@qt.io>2016-10-05 14:36:45 +0200
committerAlex Blasche <alexander.blasche@qt.io>2017-01-23 07:16:11 +0000
commitf889b44788085f5c40c7923729913762ba9460b7 (patch)
treedcff5fa4dbb324d00ea7538fb9f6a24084f4122c /src
parentd3ef813db155158c9edbd3eed983da980431b21e (diff)
downloadqtconnectivity-f889b44788085f5c40c7923729913762ba9460b7.tar.gz
Connect QtBluetoothLEServer class to Qt's QLowEnergyController API
Change-Id: I4403a9d5c79fae2c6bbe9c478660ead01dc16fe4 Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io> Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothLEServer.java32
-rw-r--r--src/bluetooth/qlowenergycontroller_android.cpp23
2 files changed, 37 insertions, 18 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 343ab552..f0e554b3 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
@@ -150,7 +150,15 @@ public class QtBluetoothLEServer {
// }
};
- public void disconnect()
+ public boolean connectServer()
+ {
+ if (mGattServer == null)
+ return false;
+
+ return true;
+ }
+
+ public void disconnectServer()
{
if (mGattServer == null)
return;
@@ -158,26 +166,16 @@ public class QtBluetoothLEServer {
mGattServer.close();
}
- public void startAdvertising()
+ public boolean startAdvertising()
{
if (mLeAdvertiser == null)
- return;
-
- // TODO for now everything hardcoded to get basic working frame
- AdvertiseData.Builder dataBuilder = new AdvertiseData.Builder();
- dataBuilder.setIncludeDeviceName(true);
- dataBuilder.setIncludeTxPowerLevel(false);
+ return false;
- // randomly chosen UUID below
- dataBuilder.addServiceUuid(ParcelUuid.fromString("e8e10f95-1a70-4b27-9ccf-02010264e9c8"));
+ connectServer();
- AdvertiseSettings.Builder settingsBuilder = new AdvertiseSettings.Builder();
- settingsBuilder.setAdvertiseMode(AdvertiseSettings.ADVERTISE_MODE_BALANCED);
- settingsBuilder.setConnectable(true); // prevents beacon mode
- settingsBuilder.setTimeout(0);
- settingsBuilder.setTxPowerLevel(AdvertiseSettings.ADVERTISE_TX_POWER_MEDIUM);
+ Log.w(TAG, "Starting to advertise.");
- mLeAdvertiser.startAdvertising(settingsBuilder.build(), dataBuilder.build(), mAdvertiseListener);
+ return true;
}
public void stopAdvertising()
@@ -186,6 +184,7 @@ public class QtBluetoothLEServer {
return;
mLeAdvertiser.stopAdvertising(mAdvertiseListener);
+ Log.w(TAG, "Advertisement stopped.");
}
/*
@@ -200,6 +199,7 @@ public class QtBluetoothLEServer {
@Override
public void onStartFailure(int errorCode) {
+ Log.e(TAG, "Advertising failure: " + errorCode);
super.onStartFailure(errorCode);
}
};
diff --git a/src/bluetooth/qlowenergycontroller_android.cpp b/src/bluetooth/qlowenergycontroller_android.cpp
index 0ebe7564..cb49188c 100644
--- a/src/bluetooth/qlowenergycontroller_android.cpp
+++ b/src/bluetooth/qlowenergycontroller_android.cpp
@@ -56,6 +56,10 @@ QLowEnergyControllerPrivate::QLowEnergyControllerPrivate()
QLowEnergyControllerPrivate::~QLowEnergyControllerPrivate()
{
+ if (role == QLowEnergyController::PeripheralRole) {
+ if (hub)
+ hub->javaObject().callMethod<void>("disconnectServer");
+ }
}
void QLowEnergyControllerPrivate::init()
@@ -630,12 +634,27 @@ void QLowEnergyControllerPrivate::startAdvertising(const QLowEnergyAdvertisingPa
Q_UNUSED(params);
Q_UNUSED(advertisingData);
Q_UNUSED(scanResponseData);
- qCWarning(QT_BT_ANDROID) << "LE advertising not implemented for Android";
+
+ setState(QLowEnergyController::AdvertisingState);
+
+ if (!hub->javaObject().isValid()) {
+ qCWarning(QT_BT_ANDROID) << "Cannot initiate QtBluetoothLEServer";
+ setError(QLowEnergyController::AdvertisingError);
+ setState(QLowEnergyController::UnconnectedState);
+ return;
+ }
+
+ const bool result = hub->javaObject().callMethod<jboolean>("startAdvertising");
+ if (!result) {
+ setError(QLowEnergyController::AdvertisingError);
+ setState(QLowEnergyController::UnconnectedState);
+ }
}
void QLowEnergyControllerPrivate::stopAdvertising()
{
- qCWarning(QT_BT_ANDROID) << "LE advertising not implemented for Android";
+ setState(QLowEnergyController::UnconnectedState);
+ hub->javaObject().callMethod<void>("stopAdvertising");
}
void QLowEnergyControllerPrivate::requestConnectionUpdate(const QLowEnergyConnectionParameters &params)