Skip to content

Commit b888cab

Browse files
committed
Guard BLE scan start against SecurityException to avoid process crash
1 parent 8bb4ca4 commit b888cab

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

android/app/src/main/java/betaflight/configurator/protocols/bluetooth/BetaflightBluetoothPlugin.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -492,10 +492,19 @@ public void onScanFailed(int errorCode) {
492492
}
493493
};
494494

495-
bluetoothLeScanner.startScan(filters.isEmpty() ? null : filters, settings, activeScanCallback);
496-
497-
scanTimeoutRunnable = () -> rejectPendingScan("Scan timed out");
498-
mainHandler.postDelayed(scanTimeoutRunnable, timeoutMs);
495+
try {
496+
bluetoothLeScanner.startScan(
497+
filters.isEmpty() ? null : filters,
498+
settings,
499+
activeScanCallback
500+
);
501+
} catch (SecurityException ex) {
502+
Log.e(TAG, "Bluetooth LE scan failed due to missing permissions", ex);
503+
rejectPendingScan("Bluetooth scan permission denied");
504+
return;
505+
}
506+
scanTimeoutRunnable = () -> rejectPendingScan("Scan timed out");
507+
mainHandler.postDelayed(scanTimeoutRunnable, timeoutMs);
499508
}
500509

501510
private void handleScanResult(ScanResult result, ScanCriteria criteria) {

0 commit comments

Comments
 (0)