fix BLE permissions error found by the autotester:

/// The following call might return null if the user doesn't have bluetooth access permissions
            val s: BluetoothLeScanner? = bluetoothAdapter.bluetoothLeScanner

            if(s == null) {
                ScanUIState.errorText = "This application requires bluetooth access. Please grant access in android settings."
            }
1.2-legacy
Kevin Hester 2020-02-29 14:14:52 -08:00
rodzic 75b4b72ce1
commit e1753cfa18
1 zmienionych plików z 18 dodań i 13 usunięć

Wyświetl plik

@ -110,22 +110,27 @@ fun BTScanScreen() {
if (ScanUIState.selectedMacAddr == null) if (ScanUIState.selectedMacAddr == null)
ScanUIState.changeSelection(context, testnodes.first().macAddress) ScanUIState.changeSelection(context, testnodes.first().macAddress)
} else { } else {
val s = bluetoothAdapter.bluetoothLeScanner /// The following call might return null if the user doesn't have bluetooth access permissions
// ScanState.scanner = scanner val s: BluetoothLeScanner? = bluetoothAdapter.bluetoothLeScanner
ScanState.debug("starting scan") if(s == null) {
ScanUIState.errorText = "This application requires bluetooth access. Please grant access in android settings."
}
else {
ScanState.debug("starting scan")
// filter and only accept devices that have a sw update service // filter and only accept devices that have a sw update service
val filter = val filter =
ScanFilter.Builder() ScanFilter.Builder()
.setServiceUuid(ParcelUuid(RadioInterfaceService.BTM_SERVICE_UUID)) .setServiceUuid(ParcelUuid(RadioInterfaceService.BTM_SERVICE_UUID))
.build() .build()
val settings = val settings =
ScanSettings.Builder().setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY).build() ScanSettings.Builder().setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY).build()
s.startScan(listOf(filter), settings, scanCallback) s.startScan(listOf(filter), settings, scanCallback)
ScanState.scanner = s ScanState.scanner = s
ScanState.callback = scanCallback ScanState.callback = scanCallback
}
} }
onDispose { onDispose {