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 9751247135ad4f61ef889d21b251dbdabdcb00db..5e63b66fbfa9d3bc63d5615d75d1f666a29e7048 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 |
@@ -5,12 +5,16 @@ |
package org.chromium.device.bluetooth; |
import android.annotation.TargetApi; |
+import android.bluetooth.BluetoothDevice; |
import android.bluetooth.le.ScanFilter; |
+import android.bluetooth.le.ScanSettings; |
import android.os.Build; |
+import android.os.ParcelUuid; |
import org.chromium.base.CalledByNative; |
import org.chromium.base.Log; |
+import java.util.ArrayList; |
import java.util.List; |
/** |
@@ -40,6 +44,53 @@ class Fakes { |
mFakeScanner = (FakeBluetoothLeScanner) mScanner; |
} |
+ /** |
+ * Creates and discovers a new device. |
+ */ |
+ @CalledByNative("FakeBluetoothAdapter") |
+ public void discoverLowEnergyDevice(int deviceOrdinal) { |
+ switch (deviceOrdinal) { |
+ case 1: { |
+ ArrayList<ParcelUuid> uuids = new ArrayList<ParcelUuid>(2); |
+ uuids.add(ParcelUuid.fromString("00001800-0000-1000-8000-00805f9b34fb")); |
+ uuids.add(ParcelUuid.fromString("00001801-0000-1000-8000-00805f9b34fb")); |
+ |
+ mFakeScanner.mCallback.onScanResult(ScanSettings.CALLBACK_TYPE_ALL_MATCHES, |
+ new FakeScanResult(new FakeBluetoothDevice( |
+ "AA:00:00:00:00:01", "FakeBluetoothDevice"), |
+ uuids)); |
+ break; |
+ } |
+ case 2: { |
+ ArrayList<ParcelUuid> uuids = new ArrayList<ParcelUuid>(2); |
+ uuids.add(ParcelUuid.fromString("00001802-0000-1000-8000-00805f9b34fb")); |
+ uuids.add(ParcelUuid.fromString("00001803-0000-1000-8000-00805f9b34fb")); |
+ |
+ mFakeScanner.mCallback.onScanResult(ScanSettings.CALLBACK_TYPE_ALL_MATCHES, |
+ new FakeScanResult(new FakeBluetoothDevice( |
+ "AA:00:00:00:00:01", "FakeBluetoothDevice"), |
+ uuids)); |
+ break; |
+ } |
+ case 3: { |
+ ArrayList<ParcelUuid> uuids = null; |
+ mFakeScanner.mCallback.onScanResult(ScanSettings.CALLBACK_TYPE_ALL_MATCHES, |
+ new FakeScanResult(new FakeBluetoothDevice("AA:00:00:00:00:01", ""), |
+ uuids)); |
+ |
+ break; |
+ } |
+ case 4: { |
+ ArrayList<ParcelUuid> uuids = null; |
+ mFakeScanner.mCallback.onScanResult(ScanSettings.CALLBACK_TYPE_ALL_MATCHES, |
+ new FakeScanResult(new FakeBluetoothDevice("BB:00:00:00:00:02", ""), |
+ uuids)); |
+ |
+ break; |
+ } |
+ } |
+ } |
+ |
// ----------------------------------------------------------------------------------------- |
// BluetoothAdapterWrapper overrides: |
@@ -103,37 +154,56 @@ class Fakes { |
*/ |
static class FakeScanResult extends Wrappers.ScanResultWrapper { |
private final FakeBluetoothDevice mDevice; |
+ private final ArrayList<ParcelUuid> mUuids; |
- FakeScanResult(FakeBluetoothDevice device) { |
+ FakeScanResult(FakeBluetoothDevice device, ArrayList<ParcelUuid> uuids) { |
super(null); |
mDevice = device; |
+ mUuids = uuids; |
} |
@Override |
public Wrappers.BluetoothDeviceWrapper getDevice() { |
return mDevice; |
} |
+ |
+ @Override |
+ public List<ParcelUuid> getScanRecord_getServiceUuids() { |
+ return mUuids; |
+ } |
} |
/** |
* Fakes android.bluetooth.BluetoothDevice. |
*/ |
static class FakeBluetoothDevice extends Wrappers.BluetoothDeviceWrapper { |
- private static final String ADDRESS = "A1:B2:C3:DD:DD:DD"; |
- private static final String NAME = "FakeBluetoothDevice"; |
+ private String mAddress; |
+ private String mName; |
- public FakeBluetoothDevice() { |
+ public FakeBluetoothDevice(String address, String name) { |
super(null); |
+ mAddress = address; |
+ mName = name; |
} |
@Override |
public String getAddress() { |
- return ADDRESS; |
+ return mAddress; |
+ } |
+ |
+ @Override |
+ public int getBluetoothClass_getDeviceClass() { |
+ return 0x1F00; // Unspecified Device Class |
+ } |
+ |
+ @Override |
+ public int getBondState() { |
+ return BluetoothDevice.BOND_BONDED; |
} |
@Override |
public String getName() { |
- return NAME; |
+ return mName; |
} |
} |
} |