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

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

Issue 2248913002: bluetooth: Implement RSSI and Tx Power on macOS and Android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-refactor-adv-data
Patch Set: Address jyasskin's comments Created 4 years, 4 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
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 636e67c8d6bdefd702adb84d79b6041631a4d854..998450a3a49b79e304583e73de3cb9a86d215947 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
@@ -22,6 +22,8 @@ import org.chromium.base.Log;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace;
import org.chromium.components.location.LocationUtils;
+import org.chromium.device.bluetooth.test.TestRSSI;
+import org.chromium.device.bluetooth.test.TestTxPower;
import java.util.ArrayList;
import java.util.HashMap;
@@ -41,6 +43,11 @@ import java.util.UUID;
class Fakes {
private static final String TAG = "cr.Bluetooth";
+ // Android uses Integer.MIN_VALUE to signal no Tx Power in advertisement
+ // packet.
+ // https://developer.android.com/reference/android/bluetooth/le/ScanRecord.html#getTxPowerLevel()
+ private static final int NO_TX_POWER = Integer.MIN_VALUE;
+
/**
* Sets the factory for LocationUtils to return an instance whose
* hasAndroidLocationPermission and isSystemLocationSettingEnabled return
@@ -107,10 +114,11 @@ class Fakes {
uuids.add(ParcelUuid.fromString("00001800-0000-1000-8000-00805f9b34fb"));
uuids.add(ParcelUuid.fromString("00001801-0000-1000-8000-00805f9b34fb"));
- mFakeScanner.mScanCallback.onScanResult(ScanSettings.CALLBACK_TYPE_ALL_MATCHES,
+ mFakeScanner.mScanCallback.onScanResult(
+ ScanSettings.CALLBACK_TYPE_ALL_MATCHES,
new FakeScanResult(new FakeBluetoothDevice(this, "01:00:00:90:1E:BE",
"FakeBluetoothDevice"),
- uuids));
+ TestRSSI.LOWEST, uuids, TestTxPower.LOWEST));
break;
}
case 2: {
@@ -118,10 +126,11 @@ class Fakes {
uuids.add(ParcelUuid.fromString("00001802-0000-1000-8000-00805f9b34fb"));
uuids.add(ParcelUuid.fromString("00001803-0000-1000-8000-00805f9b34fb"));
- mFakeScanner.mScanCallback.onScanResult(ScanSettings.CALLBACK_TYPE_ALL_MATCHES,
+ mFakeScanner.mScanCallback.onScanResult(
+ ScanSettings.CALLBACK_TYPE_ALL_MATCHES,
new FakeScanResult(new FakeBluetoothDevice(this, "01:00:00:90:1E:BE",
"FakeBluetoothDevice"),
- uuids));
+ TestRSSI.LOWER, uuids, TestTxPower.LOWER));
break;
}
case 3: {
@@ -129,7 +138,8 @@ class Fakes {
mFakeScanner.mScanCallback.onScanResult(
ScanSettings.CALLBACK_TYPE_ALL_MATCHES,
new FakeScanResult(
- new FakeBluetoothDevice(this, "01:00:00:90:1E:BE", ""), uuids));
+ new FakeBluetoothDevice(this, "01:00:00:90:1E:BE", ""),
+ TestRSSI.LOW, uuids, NO_TX_POWER));
break;
}
@@ -138,16 +148,18 @@ class Fakes {
mFakeScanner.mScanCallback.onScanResult(
ScanSettings.CALLBACK_TYPE_ALL_MATCHES,
new FakeScanResult(
- new FakeBluetoothDevice(this, "02:00:00:8B:74:63", ""), uuids));
+ new FakeBluetoothDevice(this, "02:00:00:8B:74:63", ""),
+ TestRSSI.MEDIUM, uuids, NO_TX_POWER));
break;
}
case 5: {
ArrayList<ParcelUuid> uuids = null;
- mFakeScanner.mScanCallback.onScanResult(ScanSettings.CALLBACK_TYPE_ALL_MATCHES,
- new FakeScanResult(new FakeBluetoothDevice(
- this, "01:00:00:90:1E:BE", null),
- uuids));
+ mFakeScanner.mScanCallback.onScanResult(
+ ScanSettings.CALLBACK_TYPE_ALL_MATCHES,
+ new FakeScanResult(
+ new FakeBluetoothDevice(this, "01:00:00:90:1E:BE", null),
+ TestRSSI.HIGH, uuids, NO_TX_POWER));
break;
}
}
@@ -273,12 +285,17 @@ class Fakes {
*/
static class FakeScanResult extends Wrappers.ScanResultWrapper {
private final FakeBluetoothDevice mDevice;
+ private final int mRssi;
+ private final int mTxPower;
private final ArrayList<ParcelUuid> mUuids;
- FakeScanResult(FakeBluetoothDevice device, ArrayList<ParcelUuid> uuids) {
+ FakeScanResult(
+ FakeBluetoothDevice device, int rssi, ArrayList<ParcelUuid> uuids, int txPower) {
super(null);
mDevice = device;
+ mRssi = rssi;
mUuids = uuids;
+ mTxPower = txPower;
}
@Override
@@ -287,9 +304,19 @@ class Fakes {
}
@Override
+ public int getRssi() {
+ return mRssi;
+ }
+
+ @Override
public List<ParcelUuid> getScanRecord_getServiceUuids() {
return mUuids;
}
+
+ @Override
+ public int getScanRecord_getTxPowerLevel() {
+ return mTxPower;
+ }
}
/**

Powered by Google App Engine
This is Rietveld 408576698