cordova-plugin-ble-central icon indicating copy to clipboard operation
cordova-plugin-ble-central copied to clipboard

stopScan reports a null reference when command executed before Bluetooth is enabled

Open peitschie opened this issue 3 years ago • 1 comments

Noticed on some Android 11 variants, might affect other Android versions.

If Bluetooth is disabled when the first BLE Central command is executed bluetoothAdapter.getBluetoothLeScanner() will be null. This null value is cached https://github.com/don/cordova-plugin-ble-central/blob/966e3a5a783e1d710f0c552edb07c93f6921d1c4/src/android/BLECentralPlugin.java#L152, and won't be re-initialised until startScan is called.

Suggest two fixes here:

  1. stopScan should return success if bluetoothLeScanner is null
  2. bluetoothLeScanner should be initialised in it's own guard, so that if BLE does become enabled in the above condition it can immediately work.

peitschie avatar Nov 15 '21 06:11 peitschie

This has some relation to #826

peitschie avatar Jul 12 '22 08:07 peitschie

Fixed in https://github.com/don/cordova-plugin-ble-central/commit/26a142dcc9a4330591cf2b90a32987bc897b8db8

peitschie avatar Oct 18 '22 13:10 peitschie