Skip to content
This repository has been archived by the owner on Mar 25, 2024. It is now read-only.

Commit

Permalink
Do not crash inside the emulator (#1150)
Browse files Browse the repository at this point in the history
As there is no bluetooth support in the emulator
  • Loading branch information
boun authored and cpfeiffer committed Jul 12, 2018
1 parent 355f2e6 commit 11c5453
Showing 1 changed file with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ private void startDiscovery(Scanning what) {
} else if (what == Scanning.SCANNING_NEW_BTLE) {
if (GB.supportsBluetoothLE()) {
startNEWBTLEDiscovery();
} else {
} else {
discoveryFinished();
}
}
Expand Down Expand Up @@ -433,15 +433,20 @@ private void stopDiscovery() {
}

private void stopBTLEDiscovery() {
adapter.stopLeScan(leScanCallback);
if (adapter != null)
adapter.stopLeScan(leScanCallback);
}

private void stopBTDiscovery() {
adapter.cancelDiscovery();
if (adapter != null)
adapter.cancelDiscovery();
}

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void stopNewBTLEDiscovery() {
if (adapter == null)
return;

BluetoothLeScanner bluetoothLeScanner = adapter.getBluetoothLeScanner();
if (bluetoothLeScanner == null) {
LOG.warn("could not get BluetoothLeScanner()!");
Expand Down Expand Up @@ -520,10 +525,10 @@ private boolean checkBluetoothAvailable() {
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void startNEWBTLEDiscovery() {
// Only use new API when user uses Lollipop+ device
LOG.info("Start New BTLE Discovery");
handler.removeMessages(0, stopRunnable);
handler.sendMessageDelayed(getPostMessage(stopRunnable), SCAN_DURATION);
adapter.getBluetoothLeScanner().startScan(getScanFilters(), getScanSettings(), getScanCallback());
LOG.info("Start New BTLE Discovery");
handler.removeMessages(0, stopRunnable);
handler.sendMessageDelayed(getPostMessage(stopRunnable), SCAN_DURATION);
adapter.getBluetoothLeScanner().startScan(getScanFilters(), getScanSettings(), getScanCallback());
}

private List<ScanFilter> getScanFilters() {
Expand Down

0 comments on commit 11c5453

Please sign in to comment.