Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent crash due to any Improv scanning failure #4740

Merged
merged 2 commits into from
Oct 17, 2024

Conversation

jpelgrom
Copy link
Member

Summary

Prevent the app crash when Improv scanning fails in any way by catching the exceptions, we should always fail silently here. Also added a quick check in case the issue is caused by no BLE support but that seems unlikely.

Fixes:

Exception java.lang.NullPointerException: Attempt to invoke virtual method 'void android.bluetooth.le.BluetoothLeScanner.startScan(java.util.List, android.bluetooth.le.ScanSettings, android.bluetooth.le.ScanCallback)' on a null object reference
  at com.wifi.improv.ImprovManager.findDevices (ImprovManager.kt:243)
  at io.homeassistant.companion.android.improv.ImprovRepositoryImpl.startScanning (ImprovRepositoryImpl.kt:65)
  at io.homeassistant.companion.android.webview.WebViewPresenterImpl$startScanningForImprov$1$1.invokeSuspend (WebViewPresenterImpl.kt:488)
  at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith (ContinuationImpl.kt:33)
  at kotlinx.coroutines.DispatchedTask.run (DispatchedTask.kt:101)
  at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run (LimitedDispatcher.kt:113)
  at kotlinx.coroutines.scheduling.TaskImpl.run (Tasks.kt:89)
  at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely (CoroutineScheduler.kt:589)
  at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask (CoroutineScheduler.kt:823)
  at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker (CoroutineScheduler.kt:720)
  at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run (CoroutineScheduler.kt:707)

Screenshots

n/a

Link to pull request in Documentation repository

n/a

Any other notes

 - Catch NullPointerExceptions when starting scanning for Improv to prevent the app crashing (this should fail silently, like when missing permissions or BT is off)
 - Add a check if the device supports BLE before asking for permissions/starting scanning at all
@dshokouhi dshokouhi merged commit 6d8112f into home-assistant:master Oct 17, 2024
4 checks passed
@jpelgrom jpelgrom deleted the catch-improv-null branch October 17, 2024 17:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants