summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuha Vuolle <juha.vuolle@qt.io>2023-01-25 13:29:15 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2023-02-04 22:28:05 +0000
commit809f007d111b41263ff80ca8dcd157048cb88d03 (patch)
treefa0484b60acb615fab2622505a8f5e529c64b5c3
parent8363df31ff4712f97874e9c0ea2a0aeacda47ca2 (diff)
Catch broadcast receiver unregistration exception on Android
Reproducing the issue reliably has proven to be near impossible, but the stack trace can be seen every now and then, and it does not seem to cause any functional harm. The strong suspicion on what happens is that in some places of the code we create a temporary QBluetoothLocalDevice object to check for example address(). This happens for example when creating a QLowEnergyController object, which is one of the scenarios I recall seeing the unhandled exception. The localdevice creation triggers broadcast receiver registration, and the ~immediate destruction triggers unregistration. Reading the address() works as it does not rely on any broadcast events. It seems plausible that in some cases the registration is not yet fully complete on Android side when the unregistration is ~immediately called. Fixes: QTBUG-106938 Change-Id: Iac734f17fb9d2a1879fca39d9b2839cb530e5df5 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> (cherry picked from commit 29e73453ed653782fd885e79974de76bd60fc734) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/android/bluetooth/src/org/qtproject/qt/android/bluetooth/QtBluetoothBroadcastReceiver.java6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/android/bluetooth/src/org/qtproject/qt/android/bluetooth/QtBluetoothBroadcastReceiver.java b/src/android/bluetooth/src/org/qtproject/qt/android/bluetooth/QtBluetoothBroadcastReceiver.java
index 7b163efb..6c74c3e3 100644
--- a/src/android/bluetooth/src/org/qtproject/qt/android/bluetooth/QtBluetoothBroadcastReceiver.java
+++ b/src/android/bluetooth/src/org/qtproject/qt/android/bluetooth/QtBluetoothBroadcastReceiver.java
@@ -51,7 +51,11 @@ public class QtBluetoothBroadcastReceiver extends BroadcastReceiver
{
synchronized (qtContext) {
qtObject = 0;
- qtContext.unregisterReceiver(this);
+ try {
+ qtContext.unregisterReceiver(this);
+ } catch (Exception ex) {
+ Log.d(TAG, "Trying to unregister a BroadcastReceiver which is not yet registered");
+ }
}
}