Index: device/bluetooth/android/java/src/org/chromium/device/bluetooth/ChromeBluetoothAdapter.java |
diff --git a/device/bluetooth/android/java/src/org/chromium/device/bluetooth/ChromeBluetoothAdapter.java b/device/bluetooth/android/java/src/org/chromium/device/bluetooth/ChromeBluetoothAdapter.java |
index 0774ea2401b20049095213c710fc17c5970db0a5..7891ea111768ddb40802d235f63927b255ba7a64 100644 |
--- a/device/bluetooth/android/java/src/org/chromium/device/bluetooth/ChromeBluetoothAdapter.java |
+++ b/device/bluetooth/android/java/src/org/chromium/device/bluetooth/ChromeBluetoothAdapter.java |
@@ -111,6 +111,12 @@ final class ChromeBluetoothAdapter { |
return isPresent() && mAdapter.isEnabled(); |
} |
+ // Implements BluetoothAdapterAndroid::SetPowered. |
+ @CalledByNative |
+ private boolean setPowered(boolean powered) { |
+ return isPresent() && mAdapter.setPowered(powered); |
+ } |
+ |
// Implements BluetoothAdapterAndroid::IsDiscoverable. |
@CalledByNative |
private boolean isDiscoverable() { |
@@ -184,6 +190,10 @@ final class ChromeBluetoothAdapter { |
private boolean startScan() { |
Wrappers.BluetoothLeScannerWrapper scanner = mAdapter.getBluetoothLeScanner(); |
+ if (scanner == null) { |
+ return false; |
+ } |
+ |
if (!canScan()) { |
return false; |
} |
@@ -199,6 +209,11 @@ final class ChromeBluetoothAdapter { |
scanner.startScan(null /* filters */, scanMode, mScanCallback); |
} catch (IllegalArgumentException e) { |
Log.e(TAG, "Cannot start scan: " + e); |
+ mScanCallback = null; |
+ return false; |
+ } catch (IllegalStateException e) { |
+ Log.e(TAG, "Adapter is off. Cannot start scan: " + e); |
+ mScanCallback = null; |
return false; |
} |
return true; |
@@ -212,12 +227,16 @@ final class ChromeBluetoothAdapter { |
if (mScanCallback == null) { |
return false; |
} |
+ |
try { |
- mAdapter.getBluetoothLeScanner().stopScan(mScanCallback); |
+ Wrappers.BluetoothLeScannerWrapper scanner = mAdapter.getBluetoothLeScanner(); |
+ if (scanner != null) { |
+ scanner.stopScan(mScanCallback); |
+ } |
} catch (IllegalArgumentException e) { |
Log.e(TAG, "Cannot stop scan: " + e); |
- mScanCallback = null; |
- return false; |
+ } catch (IllegalStateException e) { |
+ Log.e(TAG, "Adapter is off. Cannot stop scan: " + e); |
} |
mScanCallback = null; |
return true; |