home-assistant / android

:iphone: Home Assistant Companion for Android
https://companion.home-assistant.io/
Apache License 2.0
2.35k stars 656 forks source link

Prevent crash due to any Improv scanning failure #4740

Closed jpelgrom closed 1 month ago

jpelgrom commented 1 month ago

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