summaryrefslogtreecommitdiffstats
path: root/src/bluetooth/android
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@digia.com>2014-10-17 11:24:07 +0200
committerAlex Blasche <alexander.blasche@digia.com>2014-10-28 13:59:35 +0100
commita7b0b599775864743d1436d3cbd9513f92eb2d06 (patch)
treefcd7ec468b78b94f0b412d0036bef721032a1f58 /src/bluetooth/android
parentf6183a49f93b83e6b7d634ef4ea20eb1d5a58248 (diff)
Android: Determine the Bluetooth type of the remote device
This requires Android version 18 or higher. Change-Id: I62495721ab888e48a7fdecb7d95c35d461904046 Reviewed-by: Timur Pocheptsov <Timur.Pocheptsov@digia.com> Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
Diffstat (limited to 'src/bluetooth/android')
-rw-r--r--src/bluetooth/android/devicediscoverybroadcastreceiver.cpp58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/bluetooth/android/devicediscoverybroadcastreceiver.cpp b/src/bluetooth/android/devicediscoverybroadcastreceiver.cpp
index ee594c5c..db02bc46 100644
--- a/src/bluetooth/android/devicediscoverybroadcastreceiver.cpp
+++ b/src/bluetooth/android/devicediscoverybroadcastreceiver.cpp
@@ -37,11 +37,58 @@
#include <QtBluetooth/QBluetoothAddress>
#include <QtBluetooth/QBluetoothDeviceInfo>
#include "android/jni_android_p.h"
+#include <QtCore/private/qjnihelpers_p.h>
+#include <QtCore/QHash>
QT_BEGIN_NAMESPACE
Q_DECLARE_LOGGING_CATEGORY(QT_BT_ANDROID)
+typedef QHash<jint, QBluetoothDeviceInfo::CoreConfigurations> JCachedBtTypes;
+Q_GLOBAL_STATIC(JCachedBtTypes, cachedBtTypes)
+
+// class name
+static const char * const javaBluetoothDeviceClassName = "android/bluetooth/BluetoothDevice";
+static const char * const javaDeviceTypeClassic = "DEVICE_TYPE_CLASSIC";
+static const char * const javaDeviceTypeDual = "DEVICE_TYPE_DUAL";
+static const char * const javaDeviceTypeLE = "DEVICE_TYPE_LE";
+static const char * const javaDeviceTypeUnknown = "DEVICE_TYPE_UNKNOWN";
+
+QBluetoothDeviceInfo::CoreConfigurations qtBtTypeForJavaBtType(jint javaType)
+{
+ const JCachedBtTypes::iterator it = cachedBtTypes()->find(javaType);
+ if (it == cachedBtTypes()->end()) {
+ QAndroidJniEnvironment env;
+
+ if (javaType == QAndroidJniObject::getStaticField<jint>(
+ javaBluetoothDeviceClassName, javaDeviceTypeClassic)) {
+ cachedBtTypes()->insert(javaType,
+ QBluetoothDeviceInfo::BaseRateCoreConfiguration);
+ return QBluetoothDeviceInfo::BaseRateCoreConfiguration;
+ } else if (javaType == QAndroidJniObject::getStaticField<jint>(
+ javaBluetoothDeviceClassName, javaDeviceTypeLE)) {
+ cachedBtTypes()->insert(javaType,
+ QBluetoothDeviceInfo::LowEnergyCoreConfiguration);
+ return QBluetoothDeviceInfo::LowEnergyCoreConfiguration;
+ } else if (javaType == QAndroidJniObject::getStaticField<jint>(
+ javaBluetoothDeviceClassName, javaDeviceTypeDual)) {
+ cachedBtTypes()->insert(javaType,
+ QBluetoothDeviceInfo::BaseRateAndLowEnergyCoreConfiguration);
+ return QBluetoothDeviceInfo::BaseRateAndLowEnergyCoreConfiguration;
+ } else if (javaType == QAndroidJniObject::getStaticField<jint>(
+ javaBluetoothDeviceClassName, javaDeviceTypeUnknown)) {
+ cachedBtTypes()->insert(javaType,
+ QBluetoothDeviceInfo::UnknownCoreConfiguration);
+ } else {
+ qCWarning(QT_BT_ANDROID) << "Unknown Bluetooth device type value";
+ }
+
+ return QBluetoothDeviceInfo::UnknownCoreConfiguration;
+ } else {
+ return it.value();
+ }
+}
+
DeviceDiscoveryBroadcastReceiver::DeviceDiscoveryBroadcastReceiver(QObject* parent): AndroidBroadcastReceiver(parent)
{
addAction(valueForStaticField(JavaNames::BluetoothDevice, JavaNames::ActionFound));
@@ -121,6 +168,17 @@ void DeviceDiscoveryBroadcastReceiver::onReceive(JNIEnv *env, jobject context, j
QBluetoothDeviceInfo info(deviceAddress, deviceName, classType);
info.setRssi(rssi);
+ if (QtAndroidPrivate::androidSdkVersion() >= 18) {
+ jint javaBtType = bluetoothDevice.callMethod<jint>("getType");
+
+ if (env->ExceptionCheck()) {
+ env->ExceptionDescribe();
+ env->ExceptionClear();
+ } else {
+ info.setCoreConfigurations(qtBtTypeForJavaBtType(javaBtType));
+ }
+ }
+
emit deviceDiscovered(info);
}
}