summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@theqtcompany.com>2014-11-26 14:42:16 +0100
committerAlex Blasche <alexander.blasche@theqtcompany.com>2014-12-01 11:08:44 +0100
commitae3847db3a4cb17113372cb59955bdaffcec1bea (patch)
treec6d891274c34f765229c0cc59dfe168a1e770165 /src
parent68332a47fbcc124efedf73b106b7e06bfacd65fd (diff)
Android: Implements QLEService::includedServices() and type()
Unfortunately it is not possible to say whether a service is primary or secondary on Android. The platform doesn't expose this information. Change-Id: I9b0aad191308120d2d1992a5e7736b985a375e30 Reviewed-by: Timur Pocheptsov <Timur.Pocheptsov@digia.com> Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
Diffstat (limited to 'src')
-rw-r--r--src/android/bluetooth/src/org/qtproject/qt5/android/bluetooth/QtBluetoothLE.java31
-rw-r--r--src/bluetooth/qlowenergycontroller_android.cpp26
2 files changed, 57 insertions, 0 deletions
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 618be1ea..12935b6a 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
@@ -657,6 +657,37 @@ public class QtBluetoothLE {
return true;
}
+ /*
+ Returns the uuids of the services included by the given service. Otherwise returns null.
+ Directly called from Qt.
+ */
+ public String includedServices(String serviceUuid)
+ {
+ UUID uuid;
+ try {
+ uuid = UUID.fromString(serviceUuid);
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ return null;
+ }
+
+ //TODO Breaks in case of two services with same uuid
+ BluetoothGattService service = mBluetoothGatt.getService(uuid);
+ if (service == null)
+ return null;
+
+ final List<BluetoothGattService> includes = service.getIncludedServices();
+ if (includes.isEmpty())
+ return null;
+
+ StringBuilder builder = new StringBuilder();
+ for (BluetoothGattService includedService: includes) {
+ builder.append(includedService.getUuid().toString()).append(" "); //space is separator
+ }
+
+ return builder.toString();
+ }
+
private void finishCurrentServiceDiscovery()
{
int currentEntry = currentServiceInDiscovery;
diff --git a/src/bluetooth/qlowenergycontroller_android.cpp b/src/bluetooth/qlowenergycontroller_android.cpp
index 16298c96..25bd35d7 100644
--- a/src/bluetooth/qlowenergycontroller_android.cpp
+++ b/src/bluetooth/qlowenergycontroller_android.cpp
@@ -321,6 +321,32 @@ void QLowEnergyControllerPrivate::serviceDetailsDiscoveryFinished(
pointer->startHandle = startHandle;
pointer->endHandle = endHandle;
+ if (hub && hub->javaObject().isValid()) {
+ QAndroidJniObject uuid = QAndroidJniObject::fromString(serviceUuid);
+ QAndroidJniObject javaIncludes = hub->javaObject().callObjectMethod(
+ "includedServices",
+ "(Ljava/lang/String;)Ljava/lang/String;",
+ uuid.object<jstring>());
+ if (javaIncludes.isValid()) {
+ const QStringList list = javaIncludes.toString()
+ .split(QStringLiteral(" "),
+ QString::SkipEmptyParts);
+ foreach (const QString &entry, list) {
+ const QBluetoothUuid service(entry);
+ if (service.isNull())
+ return;
+
+ pointer->includedServices.append(service);
+
+ // update the type of the included service
+ QSharedPointer<QLowEnergyServicePrivate> otherService =
+ serviceList.value(service);
+ if (!otherService.isNull())
+ otherService->type |= QLowEnergyService::IncludedService;
+ }
+ }
+ }
+
qCDebug(QT_BT_ANDROID) << "Service" << serviceUuid << "discovered (start:"
<< startHandle << "end:" << endHandle << ")" << pointer.data();