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

Side by Side 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: Clean up Created 4 years, 3 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.device.bluetooth; 5 package org.chromium.device.bluetooth;
6 6
7 import android.annotation.TargetApi; 7 import android.annotation.TargetApi;
8 import android.bluetooth.BluetoothDevice; 8 import android.bluetooth.BluetoothDevice;
9 import android.bluetooth.le.ScanFilter; 9 import android.bluetooth.le.ScanFilter;
10 import android.bluetooth.le.ScanSettings; 10 import android.bluetooth.le.ScanSettings;
(...skipping 23 matching lines...) Expand all
34 * Fakes are contained in a single file to simplify code. Only one C++ file may 34 * Fakes are contained in a single file to simplify code. Only one C++ file may
35 * access a Java file via JNI, and all of these classes are accessed by 35 * access a Java file via JNI, and all of these classes are accessed by
36 * bluetooth_test_android.cc. The alternative would be a C++ .h, .cc file for 36 * bluetooth_test_android.cc. The alternative would be a C++ .h, .cc file for
37 * each of these classes. 37 * each of these classes.
38 */ 38 */
39 @JNINamespace("device") 39 @JNINamespace("device")
40 @TargetApi(Build.VERSION_CODES.LOLLIPOP) 40 @TargetApi(Build.VERSION_CODES.LOLLIPOP)
41 class Fakes { 41 class Fakes {
42 private static final String TAG = "cr.Bluetooth"; 42 private static final String TAG = "cr.Bluetooth";
43 43
44 // Test values copied from src/device/bluetooth/test/bluetooth_test.h
Jeffrey Yasskin 2016/08/24 04:32:02 Does GENERATED_JAVA_ENUM_PACKAGE work for mirrorin
ortuno 2016/08/24 21:29:09 Done.
45 private static final int TEST_RSSI1 = -81;
46 private static final int TEST_RSSI2 = -61;
47 private static final int TEST_RSSI3 = -41;
48 private static final int TEST_RSSI4 = -21;
49 private static final int TEST_RSSI5 = -1;
50 private static final int TEST_TX_POWER1 = -40;
51 private static final int TEST_TX_POWER2 = -20;
52
53 // Android uses Integer.MIN_VALUE to signal no Tx Power in advertisement
54 // packet.
55 private static final int NO_TX_POWER = Integer.MIN_VALUE;
56
44 /** 57 /**
45 * Sets the factory for LocationUtils to return an instance whose 58 * Sets the factory for LocationUtils to return an instance whose
46 * hasAndroidLocationPermission and isSystemLocationSettingEnabled return 59 * hasAndroidLocationPermission and isSystemLocationSettingEnabled return
47 * values depend on |hasPermission| and |isEnabled| respectively. 60 * values depend on |hasPermission| and |isEnabled| respectively.
48 */ 61 */
49 @CalledByNative 62 @CalledByNative
50 public static void setLocationServicesState( 63 public static void setLocationServicesState(
51 final boolean hasPermission, final boolean isEnabled) { 64 final boolean hasPermission, final boolean isEnabled) {
52 LocationUtils.setFactory(new LocationUtils.Factory() { 65 LocationUtils.setFactory(new LocationUtils.Factory() {
53 @Override 66 @Override
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 if (mFakeScanner == null) { 113 if (mFakeScanner == null) {
101 return; 114 return;
102 } 115 }
103 116
104 switch (deviceOrdinal) { 117 switch (deviceOrdinal) {
105 case 1: { 118 case 1: {
106 ArrayList<ParcelUuid> uuids = new ArrayList<ParcelUuid>(2); 119 ArrayList<ParcelUuid> uuids = new ArrayList<ParcelUuid>(2);
107 uuids.add(ParcelUuid.fromString("00001800-0000-1000-8000-008 05f9b34fb")); 120 uuids.add(ParcelUuid.fromString("00001800-0000-1000-8000-008 05f9b34fb"));
108 uuids.add(ParcelUuid.fromString("00001801-0000-1000-8000-008 05f9b34fb")); 121 uuids.add(ParcelUuid.fromString("00001801-0000-1000-8000-008 05f9b34fb"));
109 122
110 mFakeScanner.mScanCallback.onScanResult(ScanSettings.CALLBAC K_TYPE_ALL_MATCHES, 123 mFakeScanner.mScanCallback.onScanResult(
124 ScanSettings.CALLBACK_TYPE_ALL_MATCHES,
111 new FakeScanResult(new FakeBluetoothDevice(this, "01 :00:00:90:1E:BE", 125 new FakeScanResult(new FakeBluetoothDevice(this, "01 :00:00:90:1E:BE",
112 "FakeBluetoothDevice"), 126 "FakeBluetoothDevice"),
113 uuids)); 127 TEST_RSSI1, uuids, TEST_TX_POWER1));
114 break; 128 break;
115 } 129 }
116 case 2: { 130 case 2: {
117 ArrayList<ParcelUuid> uuids = new ArrayList<ParcelUuid>(2); 131 ArrayList<ParcelUuid> uuids = new ArrayList<ParcelUuid>(2);
118 uuids.add(ParcelUuid.fromString("00001802-0000-1000-8000-008 05f9b34fb")); 132 uuids.add(ParcelUuid.fromString("00001802-0000-1000-8000-008 05f9b34fb"));
119 uuids.add(ParcelUuid.fromString("00001803-0000-1000-8000-008 05f9b34fb")); 133 uuids.add(ParcelUuid.fromString("00001803-0000-1000-8000-008 05f9b34fb"));
120 134
121 mFakeScanner.mScanCallback.onScanResult(ScanSettings.CALLBAC K_TYPE_ALL_MATCHES, 135 mFakeScanner.mScanCallback.onScanResult(
136 ScanSettings.CALLBACK_TYPE_ALL_MATCHES,
122 new FakeScanResult(new FakeBluetoothDevice(this, "01 :00:00:90:1E:BE", 137 new FakeScanResult(new FakeBluetoothDevice(this, "01 :00:00:90:1E:BE",
123 "FakeBluetoothDevice"), 138 "FakeBluetoothDevice"),
124 uuids)); 139 TEST_RSSI2, uuids, TEST_TX_POWER2));
125 break; 140 break;
126 } 141 }
127 case 3: { 142 case 3: {
128 ArrayList<ParcelUuid> uuids = null; 143 ArrayList<ParcelUuid> uuids = null;
129 mFakeScanner.mScanCallback.onScanResult( 144 mFakeScanner.mScanCallback.onScanResult(
130 ScanSettings.CALLBACK_TYPE_ALL_MATCHES, 145 ScanSettings.CALLBACK_TYPE_ALL_MATCHES,
131 new FakeScanResult( 146 new FakeScanResult(
132 new FakeBluetoothDevice(this, "01:00:00:90:1 E:BE", ""), uuids)); 147 new FakeBluetoothDevice(this, "01:00:00:90:1 E:BE", ""),
148 TEST_RSSI3, uuids, NO_TX_POWER));
133 149
134 break; 150 break;
135 } 151 }
136 case 4: { 152 case 4: {
137 ArrayList<ParcelUuid> uuids = null; 153 ArrayList<ParcelUuid> uuids = null;
138 mFakeScanner.mScanCallback.onScanResult( 154 mFakeScanner.mScanCallback.onScanResult(
139 ScanSettings.CALLBACK_TYPE_ALL_MATCHES, 155 ScanSettings.CALLBACK_TYPE_ALL_MATCHES,
140 new FakeScanResult( 156 new FakeScanResult(
141 new FakeBluetoothDevice(this, "02:00:00:8B:7 4:63", ""), uuids)); 157 new FakeBluetoothDevice(this, "02:00:00:8B:7 4:63", ""),
158 TEST_RSSI4, uuids, NO_TX_POWER));
142 159
143 break; 160 break;
144 } 161 }
145 case 5: { 162 case 5: {
146 ArrayList<ParcelUuid> uuids = null; 163 ArrayList<ParcelUuid> uuids = null;
147 mFakeScanner.mScanCallback.onScanResult(ScanSettings.CALLBAC K_TYPE_ALL_MATCHES, 164 mFakeScanner.mScanCallback.onScanResult(
148 new FakeScanResult(new FakeBluetoothDevice( 165 ScanSettings.CALLBACK_TYPE_ALL_MATCHES,
149 this, "01:00:00:90:1E:BE" , null), 166 new FakeScanResult(
150 uuids)); 167 new FakeBluetoothDevice(this, "01:00:00:90:1 E:BE", null),
168 TEST_RSSI5, uuids, NO_TX_POWER));
151 break; 169 break;
152 } 170 }
153 } 171 }
154 } 172 }
155 173
156 @CalledByNative("FakeBluetoothAdapter") 174 @CalledByNative("FakeBluetoothAdapter")
157 public void forceIllegalStateException() { 175 public void forceIllegalStateException() {
158 if (mFakeScanner != null) { 176 if (mFakeScanner != null) {
159 mFakeScanner.forceIllegalStateException(); 177 mFakeScanner.forceIllegalStateException();
160 } 178 }
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 void forceIllegalStateException() { 284 void forceIllegalStateException() {
267 mThrowException = true; 285 mThrowException = true;
268 } 286 }
269 } 287 }
270 288
271 /** 289 /**
272 * Fakes android.bluetooth.le.ScanResult 290 * Fakes android.bluetooth.le.ScanResult
273 */ 291 */
274 static class FakeScanResult extends Wrappers.ScanResultWrapper { 292 static class FakeScanResult extends Wrappers.ScanResultWrapper {
275 private final FakeBluetoothDevice mDevice; 293 private final FakeBluetoothDevice mDevice;
294 private final int mRssi;
295 private final int mTxPower;
276 private final ArrayList<ParcelUuid> mUuids; 296 private final ArrayList<ParcelUuid> mUuids;
277 297
278 FakeScanResult(FakeBluetoothDevice device, ArrayList<ParcelUuid> uuids) { 298 FakeScanResult(
299 FakeBluetoothDevice device, int rssi, ArrayList<ParcelUuid> uuid s, int txPower) {
279 super(null); 300 super(null);
280 mDevice = device; 301 mDevice = device;
302 mRssi = rssi;
281 mUuids = uuids; 303 mUuids = uuids;
304 mTxPower = txPower;
282 } 305 }
283 306
284 @Override 307 @Override
285 public Wrappers.BluetoothDeviceWrapper getDevice() { 308 public Wrappers.BluetoothDeviceWrapper getDevice() {
286 return mDevice; 309 return mDevice;
287 } 310 }
288 311
289 @Override 312 @Override
313 public int getRssi() {
314 return mRssi;
315 }
316
317 @Override
290 public List<ParcelUuid> getScanRecord_getServiceUuids() { 318 public List<ParcelUuid> getScanRecord_getServiceUuids() {
291 return mUuids; 319 return mUuids;
292 } 320 }
321
322 @Override
323 public int getScanRecord_getTxPowerLevel() {
324 return mTxPower;
325 }
293 } 326 }
294 327
295 /** 328 /**
296 * Fakes android.bluetooth.BluetoothDevice. 329 * Fakes android.bluetooth.BluetoothDevice.
297 */ 330 */
298 static class FakeBluetoothDevice extends Wrappers.BluetoothDeviceWrapper { 331 static class FakeBluetoothDevice extends Wrappers.BluetoothDeviceWrapper {
299 final FakeBluetoothAdapter mAdapter; 332 final FakeBluetoothAdapter mAdapter;
300 private String mAddress; 333 private String mAddress;
301 private String mName; 334 private String mName;
302 final FakeBluetoothGatt mGatt; 335 final FakeBluetoothGatt mGatt;
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after
842 long nativeBluetoothTestAndroid, byte[] value); 875 long nativeBluetoothTestAndroid, byte[] value);
843 876
844 // Binds to BluetoothTestAndroid::OnFakeBluetoothGattReadDescriptor. 877 // Binds to BluetoothTestAndroid::OnFakeBluetoothGattReadDescriptor.
845 private static native void nativeOnFakeBluetoothGattReadDescriptor( 878 private static native void nativeOnFakeBluetoothGattReadDescriptor(
846 long nativeBluetoothTestAndroid); 879 long nativeBluetoothTestAndroid);
847 880
848 // Binds to BluetoothTestAndroid::OnFakeBluetoothGattWriteDescriptor. 881 // Binds to BluetoothTestAndroid::OnFakeBluetoothGattWriteDescriptor.
849 private static native void nativeOnFakeBluetoothGattWriteDescriptor( 882 private static native void nativeOnFakeBluetoothGattWriteDescriptor(
850 long nativeBluetoothTestAndroid, byte[] value); 883 long nativeBluetoothTestAndroid, byte[] value);
851 } 884 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698