summaryrefslogtreecommitdiffstats
path: root/src/bluetooth/android/devicediscoverybroadcastreceiver.cpp
diff options
context:
space:
mode:
authorAlex Blasche <alexander.blasche@digia.com>2014-03-03 13:45:04 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-03-11 10:58:35 +0100
commitb2cd03fb14c9727e23d5ada409551ab236d1abc6 (patch)
treecf81bfc2da2a9f5148cee8e1c5a8aa96a99bc4a7 /src/bluetooth/android/devicediscoverybroadcastreceiver.cpp
parent6106ea0ebf52845a34a291a44730e81d4a3e9108 (diff)
Android: Don't directly use the action string values but refer to the fields.
This increases the robustness of the code since the field value is not an implementation detail. In addition we guard the action field lookup against fields which have been introduced later than the standard SDK version 10 supported by Qt. Task-number: QTBUG-36810 Change-Id: Ib6582e77202d40aaf116fe8dfa81562d89367ea2 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com>
Diffstat (limited to 'src/bluetooth/android/devicediscoverybroadcastreceiver.cpp')
-rw-r--r--src/bluetooth/android/devicediscoverybroadcastreceiver.cpp29
1 files changed, 17 insertions, 12 deletions
diff --git a/src/bluetooth/android/devicediscoverybroadcastreceiver.cpp b/src/bluetooth/android/devicediscoverybroadcastreceiver.cpp
index 16a6afe4..ca62f013 100644
--- a/src/bluetooth/android/devicediscoverybroadcastreceiver.cpp
+++ b/src/bluetooth/android/devicediscoverybroadcastreceiver.cpp
@@ -44,6 +44,7 @@
#include <QtCore/QLoggingCategory>
#include <QtBluetooth/QBluetoothAddress>
#include <QtBluetooth/QBluetoothDeviceInfo>
+#include "android/jni_android_p.h"
QT_BEGIN_NAMESPACE
@@ -51,9 +52,9 @@ Q_DECLARE_LOGGING_CATEGORY(QT_BT_ANDROID)
DeviceDiscoveryBroadcastReceiver::DeviceDiscoveryBroadcastReceiver(QObject* parent): AndroidBroadcastReceiver(parent)
{
- addAction(QStringLiteral("android.bluetooth.device.action.FOUND"));
- addAction(QStringLiteral("android.bluetooth.adapter.action.DISCOVERY_STARTED"));
- addAction(QStringLiteral("android.bluetooth.adapter.action.DISCOVERY_FINISHED"));
+ addAction(valueForStaticField(JavaNames::BluetoothDevice, JavaNames::ActionFound));
+ addAction(valueForStaticField(JavaNames::BluetoothAdapter, JavaNames::ActionDiscoveryStarted));
+ addAction(valueForStaticField(JavaNames::BluetoothAdapter, JavaNames::ActionDiscoveryFinished));
}
void DeviceDiscoveryBroadcastReceiver::onReceive(JNIEnv *env, jobject context, jobject intent)
@@ -66,15 +67,18 @@ void DeviceDiscoveryBroadcastReceiver::onReceive(JNIEnv *env, jobject context, j
qCDebug(QT_BT_ANDROID) << "DeviceDiscoveryBroadcastReceiver::onReceive() - event:" << action;
- if (action == QStringLiteral("android.bluetooth.adapter.action.DISCOVERY_FINISHED") ) {
+ if (action == valueForStaticField(JavaNames::BluetoothAdapter,
+ JavaNames::ActionDiscoveryFinished).toString()) {
emit finished();
- } else if (action == QStringLiteral("android.bluetooth.adapter.action.DISCOVERY_STARTED") ) {
+ } else if (action == valueForStaticField(JavaNames::BluetoothAdapter,
+ JavaNames::ActionDiscoveryStarted).toString()) {
- } else if (action == QStringLiteral("android.bluetooth.device.action.FOUND")) {
+ } else if (action == valueForStaticField(JavaNames::BluetoothDevice,
+ JavaNames::ActionFound).toString()) {
//get BluetoothDevice
- QAndroidJniObject keyExtra = QAndroidJniObject::fromString(
- QStringLiteral("android.bluetooth.device.extra.DEVICE"));
- QAndroidJniObject bluetoothDevice =
+ QAndroidJniObject keyExtra = valueForStaticField(JavaNames::BluetoothDevice,
+ JavaNames::ExtraDevice);
+ const QAndroidJniObject bluetoothDevice =
intentObject.callObjectMethod("getParcelableExtra",
"(Ljava/lang/String;)Landroid/os/Parcelable;",
keyExtra.object<jstring>());
@@ -84,13 +88,14 @@ void DeviceDiscoveryBroadcastReceiver::onReceive(JNIEnv *env, jobject context, j
const QString deviceName = bluetoothDevice.callObjectMethod<jstring>("getName").toString();
const QBluetoothAddress deviceAddress(bluetoothDevice.callObjectMethod<jstring>("getAddress").toString());
- keyExtra = QAndroidJniObject::fromString(
- QStringLiteral("android.bluetooth.device.extra.RSSI"));
+ keyExtra = valueForStaticField(JavaNames::BluetoothDevice,
+ JavaNames::ExtraRssi);
+
int rssi = intentObject.callMethod<jshort>("getShortExtra",
"(Ljava/lang/String;S)S",
keyExtra.object<jstring>(),
0);
- QAndroidJniObject bluetoothClass = bluetoothDevice.callObjectMethod("getBluetoothClass",
+ const QAndroidJniObject bluetoothClass = bluetoothDevice.callObjectMethod("getBluetoothClass",
"()Landroid/bluetooth/BluetoothClass;");
if (!bluetoothClass.isValid())
return;