weliem / blessed-android

BLESSED, a Bluetooth Low Energy (BLE) library for Android
MIT License
557 stars 119 forks source link

BluetoothCentralManager RuntimeException #145

Closed Macksly closed 2 years ago

Macksly commented 2 years ago

Hey,

We use your library in an production app and it works really good!! However I do see some crashes being logged in firebase from which I cannot pin point the origin. For context, we have about 2000 active users each day, however these crashes only occur for a few users once or twice.

Could you help me out?

` Fatal Exception: java.lang.RuntimeException: Error receiving broadcast Intent { act=android.bluetooth.adapter.action.STATE_CHANGED flg=0x5000010 (has extras) } in com.welie.blessed.BluetoothCentralManager$12@15f76bc at android.app.LoadedApk$ReceiverDispatcher$Args.lambda$getRunnable$0$LoadedApk$ReceiverDispatcher$Args(LoadedApk.java:1575) at android.app.-$$Lambda$LoadedApk$ReceiverDispatcher$Args$_BumDX2UKsnxLVrE6UJsJZkotuA.run(-.java:2) at android.os.Handler.handleCallback(Handler.java:883) at android.os.Handler.dispatchMessage(Handler.java:100) at android.os.Looper.loop(Looper.java:214) at android.app.ActivityThread.main(ActivityThread.java:7711) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:516) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)

Caused by java.lang.NullPointerException: Attempt to invoke virtual method 'void android.bluetooth.le.BluetoothLeScanner.stopScan(android.bluetooth.le.ScanCallback)' on a null object reference at com.welie.blessed.BluetoothCentralManager.handleAdapterState(BluetoothCentralManager.java:6) at com.welie.blessed.BluetoothCentralManager$12.onReceive(BluetoothCentralManager.java:6) at android.app.LoadedApk$ReceiverDispatcher$Args.lambda$getRunnable$0$LoadedApk$ReceiverDispatcher$Args(LoadedApk.java:1560) at android.app.-$$Lambda$LoadedApk$ReceiverDispatcher$Args$_BumDX2UKsnxLVrE6UJsJZkotuA.run(-.java:2) at android.os.Handler.handleCallback(Handler.java:883) at android.os.Handler.dispatchMessage(Handler.java:100) at android.os.Looper.loop(Looper.java:214) at android.app.ActivityThread.main(ActivityThread.java:7711) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:516) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950) `

weliem commented 2 years ago

Hi this crash is related to somebody turning off bluetooth. But I thought I fixed this already some time ago...

Which version of the library are you using?

Macksly commented 2 years ago

I am using version 2.2.0

weliem commented 2 years ago

Ok, I just added a potential fix.

Can you try 2.2.1 which I just released?

Macksly commented 2 years ago

I tested the new version and I cannot reproduce the crash in the app now. I'll make a hotfix for our app with this version of the library and monitor the analytics to see if the issue will surface again :)

Thanks a lot for your help!

Macksly commented 2 years ago

Today I saw the same crash happening in our logs. It happened on a Android 10 device (if that might help).

Fatal Exception: java.lang.RuntimeException: Error receiving broadcast Intent { act=android.bluetooth.adapter.action.STATE_CHANGED flg=0x5000010 (has extras) } in com.welie.blessed.BluetoothCentralManager$12@8c53ce7 at android.app.LoadedApk$ReceiverDispatcher$Args.lambda$getRunnable$0$LoadedApk$ReceiverDispatcher$Args(LoadedApk.java:1575) at android.app.-$$Lambda$LoadedApk$ReceiverDispatcher$Args$_BumDX2UKsnxLVrE6UJsJZkotuA.run(-.java:2) at android.os.Handler.handleCallback(Handler.java:883) at android.os.Handler.dispatchMessage(Handler.java:100) at android.os.Looper.loop(Looper.java:214) at android.app.ActivityThread.main(ActivityThread.java:7711) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:516) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)

Caused by java.lang.NullPointerException: Attempt to invoke virtual method 'void android.bluetooth.le.BluetoothLeScanner.stopScan(android.bluetooth.le.ScanCallback)' on a null object reference at com.welie.blessed.BluetoothCentralManager.handleAdapterState(BluetoothCentralManager.java:6) at com.welie.blessed.BluetoothCentralManager$12.onReceive(BluetoothCentralManager.java:6) at android.app.LoadedApk$ReceiverDispatcher$Args.lambda$getRunnable$0$LoadedApk$ReceiverDispatcher$Args(LoadedApk.java:1560) at android.app.-$$Lambda$LoadedApk$ReceiverDispatcher$Args$_BumDX2UKsnxLVrE6UJsJZkotuA.run(-.java:2) at android.os.Handler.handleCallback(Handler.java:883) at android.os.Handler.dispatchMessage(Handler.java:100) at android.os.Looper.loop(Looper.java:214) at android.app.ActivityThread.main(ActivityThread.java:7711) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:516) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)

weliem commented 2 years ago

but are you sure this user was using the updated library and not the old one?

weliem commented 2 years ago

Added another fix....release 2.2.2

Macksly commented 2 years ago

but are you sure this user was using the updated library and not the old one?

I am sure that he is using the new version of the library, since he is using the new version of the app we released. I'd have to check with my team if we can release another hotfix soon. However I'll check if I can reproduce the crash and if the new version of the library will fix it 👍

Macksly commented 2 years ago

I released a patch today, so fingers crossed :)

weliem commented 2 years ago

...let's see...

By the way, which phone was the crash happening on? And which version of Android. I never managed to reproduce this crash so I wonder which phone it was.

Macksly commented 2 years ago

It was happening on a One Plus Nord running Android 10

Macksly commented 2 years ago

I haven't noticed the issue anymore! Good job on fixing this :)