summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndré Klitzing <aklitzing@gmail.com>2016-11-03 16:28:25 +0100
committerAlex Blasche <alexander.blasche@qt.io>2016-11-04 07:14:22 +0000
commitcb439dd54878c546a85b1ed1282bca7e340875c0 (patch)
treef36a4fe6c15cbb6ec7227c518383781085ba54e9
parentb6bf84ed241a74d796a435163019c6a1c5af12af (diff)
Android: Fix crash in QBluetoothDeviceDiscoveryAgent ctor due to Java exception
In general BluetoothAdapter.getDefaultAdapter should not throw an exception. If the device does not support Bluetooth the function should return a null reference only. However some devices throw a RuntimeException as well. Specially the smartphone HTC 10! Even that phone supports Bluetooth. So we need to catch it to prevent unwinding of the stack. This fix is a sibling of 669b427653f8f708269431917f720f7e76680191. Task-number: QTBUG-45066 Change-Id: I6d5f71e5cc988eed02ae35665b6ef6c9e8769868 Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io> Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
-rw-r--r--src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp
index e20fa723..2c2d41c9 100644
--- a/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp
+++ b/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp
@@ -62,9 +62,17 @@ QBluetoothDeviceDiscoveryAgentPrivate::QBluetoothDeviceDiscoveryAgentPrivate(
pendingStart(false),
q_ptr(parent)
{
+ QAndroidJniEnvironment env;
adapter = QAndroidJniObject::callStaticObjectMethod("android/bluetooth/BluetoothAdapter",
"getDefaultAdapter",
"()Landroid/bluetooth/BluetoothAdapter;");
+ if (!adapter.isValid()) {
+ if (env->ExceptionCheck()) {
+ env->ExceptionDescribe();
+ env->ExceptionClear();
+ }
+ qCWarning(QT_BT_ANDROID) << "Device does not support Bluetooth";
+ }
}
QBluetoothDeviceDiscoveryAgentPrivate::~QBluetoothDeviceDiscoveryAgentPrivate()