From cb439dd54878c546a85b1ed1282bca7e340875c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Klitzing?= Date: Thu, 3 Nov 2016 16:28:25 +0100 Subject: 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 Reviewed-by: Alex Blasche --- src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) 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() -- cgit v1.2.3