OLD | NEW |
---|---|
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.Manifest; | 7 import android.Manifest; |
8 import android.annotation.TargetApi; | 8 import android.annotation.TargetApi; |
9 import android.bluetooth.BluetoothAdapter; | 9 import android.bluetooth.BluetoothAdapter; |
10 import android.bluetooth.BluetoothDevice; | 10 import android.bluetooth.BluetoothDevice; |
(...skipping 28 matching lines...) Expand all Loading... | |
39 * | 39 * |
40 * Each Wrapper base class accepts an Android API object and passes through | 40 * Each Wrapper base class accepts an Android API object and passes through |
41 * calls to it. When under test, Fake subclasses override all methods that | 41 * calls to it. When under test, Fake subclasses override all methods that |
42 * pass through to the Android object and instead provide fake implementations. | 42 * pass through to the Android object and instead provide fake implementations. |
43 */ | 43 */ |
44 @JNINamespace("device") | 44 @JNINamespace("device") |
45 @TargetApi(Build.VERSION_CODES.LOLLIPOP) | 45 @TargetApi(Build.VERSION_CODES.LOLLIPOP) |
46 class Wrappers { | 46 class Wrappers { |
47 private static final String TAG = "Bluetooth"; | 47 private static final String TAG = "Bluetooth"; |
48 | 48 |
49 public static final int DEVICE_CLASS_UNSPECIFIED = 0x1F00; | |
50 | |
49 /** | 51 /** |
50 * Wraps android.bluetooth.BluetoothAdapter. | 52 * Wraps android.bluetooth.BluetoothAdapter. |
51 */ | 53 */ |
52 static class BluetoothAdapterWrapper { | 54 static class BluetoothAdapterWrapper { |
53 private final BluetoothAdapter mAdapter; | 55 private final BluetoothAdapter mAdapter; |
54 protected final ContextWrapper mContext; | 56 protected final ContextWrapper mContext; |
55 protected final BluetoothLeScannerWrapper mScanner; | 57 protected final BluetoothLeScannerWrapper mScanner; |
56 | 58 |
57 /** | 59 /** |
58 * Creates a BluetoothAdapterWrapper using the default | 60 * Creates a BluetoothAdapterWrapper using the default |
(...skipping 28 matching lines...) Expand all Loading... | |
87 if (!hasLowEnergyFeature) { | 89 if (!hasLowEnergyFeature) { |
88 Log.i(TAG, "BluetoothAdapterWrapper.create failed: No Low Energy support."); | 90 Log.i(TAG, "BluetoothAdapterWrapper.create failed: No Low Energy support."); |
89 return null; | 91 return null; |
90 } | 92 } |
91 | 93 |
92 BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); | 94 BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); |
93 if (adapter == null) { | 95 if (adapter == null) { |
94 Log.i(TAG, "BluetoothAdapterWrapper.create failed: Default adapt er not found."); | 96 Log.i(TAG, "BluetoothAdapterWrapper.create failed: Default adapt er not found."); |
95 return null; | 97 return null; |
96 } else { | 98 } else { |
97 return new BluetoothAdapterWrapper(adapter, new ContextWrapper(c ontext), | 99 BluetoothLeScanner scanner = adapter.getBluetoothLeScanner(); |
scheib
2016/01/21 05:33:51
In my patch you'll see that I moved the code for o
| |
98 new BluetoothLeScannerWrapper(adapter.getBluetoothLeScan ner())); | 100 if (scanner != null) { |
101 return new BluetoothAdapterWrapper(adapter, new ContextWrapp er(context), | |
102 new BluetoothLeScannerWrapper(scanner)); | |
103 } else { | |
104 return null; | |
105 } | |
99 } | 106 } |
100 } | 107 } |
101 | 108 |
102 public BluetoothAdapterWrapper(BluetoothAdapter adapter, ContextWrapper context, | 109 public BluetoothAdapterWrapper(BluetoothAdapter adapter, ContextWrapper context, |
103 BluetoothLeScannerWrapper scanner) { | 110 BluetoothLeScannerWrapper scanner) { |
104 mAdapter = adapter; | 111 mAdapter = adapter; |
105 mContext = context; | 112 mContext = context; |
106 mScanner = scanner; | 113 mScanner = scanner; |
107 } | 114 } |
108 | 115 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
164 } | 171 } |
165 | 172 |
166 public void startScan( | 173 public void startScan( |
167 List<ScanFilter> filters, int scanSettingsScanMode, ScanCallback Wrapper callback) { | 174 List<ScanFilter> filters, int scanSettingsScanMode, ScanCallback Wrapper callback) { |
168 ScanSettings settings = | 175 ScanSettings settings = |
169 new ScanSettings.Builder().setScanMode(scanSettingsScanMode) .build(); | 176 new ScanSettings.Builder().setScanMode(scanSettingsScanMode) .build(); |
170 | 177 |
171 ForwardScanCallbackToWrapper callbackForwarder = | 178 ForwardScanCallbackToWrapper callbackForwarder = |
172 new ForwardScanCallbackToWrapper(callback); | 179 new ForwardScanCallbackToWrapper(callback); |
173 mCallbacks.put(callback, callbackForwarder); | 180 mCallbacks.put(callback, callbackForwarder); |
174 | |
175 mScanner.startScan(filters, settings, callbackForwarder); | 181 mScanner.startScan(filters, settings, callbackForwarder); |
176 } | 182 } |
177 | 183 |
178 public void stopScan(ScanCallbackWrapper callback) { | 184 public void stopScan(ScanCallbackWrapper callback) { |
179 ForwardScanCallbackToWrapper callbackForwarder = mCallbacks.remove(c allback); | 185 ForwardScanCallbackToWrapper callbackForwarder = mCallbacks.remove(c allback); |
180 mScanner.stopScan(callbackForwarder); | 186 mScanner.stopScan(callbackForwarder); |
181 } | 187 } |
182 } | 188 } |
183 | 189 |
184 /** | 190 /** |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
269 mDevice.connectGatt(context, autoConnect, | 275 mDevice.connectGatt(context, autoConnect, |
270 new ForwardBluetoothGattCallbackToWrapper(callback, this)), | 276 new ForwardBluetoothGattCallbackToWrapper(callback, this)), |
271 this); | 277 this); |
272 } | 278 } |
273 | 279 |
274 public String getAddress() { | 280 public String getAddress() { |
275 return mDevice.getAddress(); | 281 return mDevice.getAddress(); |
276 } | 282 } |
277 | 283 |
278 public int getBluetoothClass_getDeviceClass() { | 284 public int getBluetoothClass_getDeviceClass() { |
285 if (mDevice == null || mDevice.getBluetoothClass() == null) { | |
scheib
2016/01/21 05:33:51
OK, no test needed here because we don't Fake getB
| |
286 // BluetoothDevice.getBluetoothClass() returns null if adapter h as been powered off. | |
287 // Return DEVICE_CLASS_UNSPECIFIED in these cases. | |
288 return DEVICE_CLASS_UNSPECIFIED; | |
289 } | |
279 return mDevice.getBluetoothClass().getDeviceClass(); | 290 return mDevice.getBluetoothClass().getDeviceClass(); |
280 } | 291 } |
281 | 292 |
282 public int getBondState() { | 293 public int getBondState() { |
283 return mDevice.getBondState(); | 294 return mDevice.getBondState(); |
284 } | 295 } |
285 | 296 |
286 public String getName() { | 297 public String getName() { |
287 return mDevice.getName(); | 298 return mDevice.getName(); |
288 } | 299 } |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
506 | 517 |
507 public byte[] getValue() { | 518 public byte[] getValue() { |
508 return mDescriptor.getValue(); | 519 return mDescriptor.getValue(); |
509 } | 520 } |
510 | 521 |
511 public boolean setValue(byte[] value) { | 522 public boolean setValue(byte[] value) { |
512 return mDescriptor.setValue(value); | 523 return mDescriptor.setValue(value); |
513 } | 524 } |
514 } | 525 } |
515 } | 526 } |
OLD | NEW |