Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(277)

Unified Diff: device/bluetooth/android/java/src/org/chromium/device/bluetooth/ChromeBluetoothAdapter.java

Issue 1610053005: bluetooth: android: Fix a couple of crashes when adapter is turned on/off. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased on latest master Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | device/bluetooth/android/java/src/org/chromium/device/bluetooth/Wrappers.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..0a54a0bdfe73f817a2cff9c0ee24783c91842eed 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,16 @@ final class ChromeBluetoothAdapter {
return isPresent() && mAdapter.isEnabled();
}
+ // Implements BluetoothAdapterAndroid::SetPowered.
+ @CalledByNative
+ private boolean setPowered(boolean powered) {
+ if (powered) {
+ return isPresent() && mAdapter.enable();
+ } else {
+ return isPresent() && mAdapter.disable();
+ }
+ }
+
// Implements BluetoothAdapterAndroid::IsDiscoverable.
@CalledByNative
private boolean isDiscoverable() {
@@ -184,6 +194,10 @@ final class ChromeBluetoothAdapter {
private boolean startScan() {
Wrappers.BluetoothLeScannerWrapper scanner = mAdapter.getBluetoothLeScanner();
+ if (scanner == null) {
+ return false;
+ }
+
if (!canScan()) {
return false;
}
@@ -199,6 +213,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 +231,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;
« no previous file with comments | « no previous file | device/bluetooth/android/java/src/org/chromium/device/bluetooth/Wrappers.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698