| 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 09da34b73c374d8bb8c71e197ddfd5455fd7651c..02e9151f5f5811b54567ff5f20fc8a46ee0c3ea0 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
|
| @@ -38,6 +38,7 @@ class Fakes {
|
| static class FakeBluetoothAdapter extends Wrappers.BluetoothAdapterWrapper {
|
| private final FakeContext mFakeContext;
|
| private final FakeBluetoothLeScanner mFakeScanner;
|
| + private boolean mPowered = true;
|
| final long mNativeBluetoothTestAndroid;
|
|
|
| /**
|
| @@ -50,10 +51,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")
|
| @@ -66,6 +67,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);
|
| @@ -110,17 +115,27 @@ class Fakes {
|
| }
|
| }
|
|
|
| + @CalledByNative("FakeBluetoothAdapter")
|
| + public void forceIllegalStateException() {
|
| + if (mFakeScanner != null) {
|
| + mFakeScanner.forceIllegalStateException();
|
| + }
|
| + }
|
| +
|
| // -----------------------------------------------------------------------------------------
|
| // BluetoothAdapterWrapper overrides:
|
|
|
| @Override
|
| - public boolean isEnabled() {
|
| - return true;
|
| + public String getAddress() {
|
| + return "A1:B2:C3:D4:E5:F6";
|
| }
|
|
|
| @Override
|
| - public String getAddress() {
|
| - return "A1:B2:C3:D4:E5:F6";
|
| + public Wrappers.BluetoothLeScannerWrapper getBluetoothLeScanner() {
|
| + if (isEnabled()) {
|
| + return mFakeScanner;
|
| + }
|
| + return null;
|
| }
|
|
|
| @Override
|
| @@ -134,9 +149,20 @@ class Fakes {
|
| }
|
|
|
| @Override
|
| + public boolean isEnabled() {
|
| + return mPowered;
|
| + }
|
| +
|
| + @Override
|
| public boolean isDiscovering() {
|
| return false;
|
| }
|
| +
|
| + @Override
|
| + public boolean setPowered(boolean powered) {
|
| + mPowered = powered;
|
| + return true;
|
| + }
|
| }
|
|
|
| /**
|
| @@ -161,6 +187,7 @@ class Fakes {
|
| */
|
| static class FakeBluetoothLeScanner extends Wrappers.BluetoothLeScannerWrapper {
|
| public Wrappers.ScanCallbackWrapper mScanCallback;
|
| + private boolean mThrowException;
|
|
|
| private FakeBluetoothLeScanner() {
|
| super(null);
|
| @@ -173,6 +200,9 @@ class Fakes {
|
| throw new IllegalArgumentException(
|
| "FakeBluetoothLeScanner does not support multiple scans.");
|
| }
|
| + if (mThrowException) {
|
| + throw new IllegalStateException("Adapter is off.");
|
| + }
|
| mScanCallback = callback;
|
| }
|
|
|
| @@ -181,8 +211,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;
|
| + }
|
| }
|
|
|
| /**
|
| @@ -283,7 +320,7 @@ class Fakes {
|
|
|
| @Override
|
| public int getBluetoothClass_getDeviceClass() {
|
| - return 0x1F00; // Unspecified Device Class
|
| + return Wrappers.DEVICE_CLASS_UNSPECIFIED;
|
| }
|
|
|
| @Override
|
|
|