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

Unified Diff: device/bluetooth/test/android/java/src/org/chromium/device/bluetooth/Fakes.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 | « device/bluetooth/bluetooth_adapter_unittest.cc ('k') | device/bluetooth/test/bluetooth_test_android.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/bluetooth/test/android/java/src/org/chromium/device/bluetooth/Fakes.java
diff --git a/device/bluetooth/test/android/java/src/org/chromium/device/bluetooth/Fakes.java b/device/bluetooth/test/android/java/src/org/chromium/device/bluetooth/Fakes.java
index 65705fa2ac99bee0d5fe68888484fa0d7754b147..538f618d6aa7efeadd0f9e9cea26a499a4920c99 100644
--- a/device/bluetooth/test/android/java/src/org/chromium/device/bluetooth/Fakes.java
+++ b/device/bluetooth/test/android/java/src/org/chromium/device/bluetooth/Fakes.java
@@ -43,6 +43,7 @@ class Fakes {
static class FakeBluetoothAdapter extends Wrappers.BluetoothAdapterWrapper {
private final FakeContext mFakeContext;
private final FakeBluetoothLeScanner mFakeScanner;
+ private boolean mPowered = true;
final long mNativeBluetoothTestAndroid;
/**
@@ -55,10 +56,10 @@ class Fakes {
}
private FakeBluetoothAdapter(long nativeBluetoothTestAndroid) {
- super(null, new FakeContext(), new FakeBluetoothLeScanner());
+ super(null, new FakeContext());
mNativeBluetoothTestAndroid = nativeBluetoothTestAndroid;
mFakeContext = (FakeContext) mContext;
- mFakeScanner = (FakeBluetoothLeScanner) mScanner;
+ mFakeScanner = new FakeBluetoothLeScanner();
}
@CalledByNative("FakeBluetoothAdapter")
@@ -71,6 +72,10 @@ class Fakes {
*/
@CalledByNative("FakeBluetoothAdapter")
public void discoverLowEnergyDevice(int deviceOrdinal) {
+ if (mFakeScanner == null) {
+ return;
+ }
+
switch (deviceOrdinal) {
case 1: {
ArrayList<ParcelUuid> uuids = new ArrayList<ParcelUuid>(2);
@@ -115,11 +120,25 @@ class Fakes {
}
}
+ @CalledByNative("FakeBluetoothAdapter")
+ public void forceIllegalStateException() {
+ if (mFakeScanner != null) {
+ mFakeScanner.forceIllegalStateException();
+ }
+ }
+
// -----------------------------------------------------------------------------------------
// BluetoothAdapterWrapper overrides:
@Override
- public boolean isEnabled() {
+ public boolean disable() {
+ mPowered = false;
+ return true;
+ }
+
+ @Override
+ public boolean enable() {
+ mPowered = true;
return true;
}
@@ -129,6 +148,14 @@ class Fakes {
}
@Override
+ public Wrappers.BluetoothLeScannerWrapper getBluetoothLeScanner() {
+ if (isEnabled()) {
+ return mFakeScanner;
+ }
+ return null;
+ }
+
+ @Override
public String getName() {
return "FakeBluetoothAdapter";
}
@@ -139,6 +166,11 @@ class Fakes {
}
@Override
+ public boolean isEnabled() {
+ return mPowered;
+ }
+
+ @Override
public boolean isDiscovering() {
return false;
}
@@ -166,6 +198,7 @@ class Fakes {
*/
static class FakeBluetoothLeScanner extends Wrappers.BluetoothLeScannerWrapper {
public Wrappers.ScanCallbackWrapper mScanCallback;
+ private boolean mThrowException;
private FakeBluetoothLeScanner() {
super(null);
@@ -178,6 +211,9 @@ class Fakes {
throw new IllegalArgumentException(
"FakeBluetoothLeScanner does not support multiple scans.");
}
+ if (mThrowException) {
+ throw new IllegalStateException("Adapter is off.");
+ }
mScanCallback = callback;
}
@@ -186,8 +222,15 @@ class Fakes {
if (mScanCallback != callback) {
throw new IllegalArgumentException("No scan in progress.");
}
+ if (mThrowException) {
+ throw new IllegalStateException("Adapter is off.");
+ }
mScanCallback = null;
}
+
+ void forceIllegalStateException() {
+ mThrowException = true;
+ }
}
/**
@@ -288,7 +331,7 @@ class Fakes {
@Override
public int getBluetoothClass_getDeviceClass() {
- return 0x1F00; // Unspecified Device Class
+ return Wrappers.DEVICE_CLASS_UNSPECIFIED;
}
@Override
« no previous file with comments | « device/bluetooth/bluetooth_adapter_unittest.cc ('k') | device/bluetooth/test/bluetooth_test_android.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698