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

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

Issue 1226103005: Revert of bluetooth: android: Initial Low Energy Discovery Sessions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bta-manifest-
Patch Set: Created 5 years, 5 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
« no previous file with comments | « device/bluetooth/bluetooth_adapter_unittest.cc ('k') | device/bluetooth/test/bluetooth_test.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
8 import android.bluetooth.le.ScanFilter;
9 import android.os.Build;
10
11 import org.chromium.base.CalledByNative; 7 import org.chromium.base.CalledByNative;
12 import org.chromium.base.Log; 8 import org.chromium.base.Log;
13 9
14 import java.util.List;
15
16 /** 10 /**
17 * Fake implementations of android.bluetooth.* classes for testing. 11 * Fake implementations of android.bluetooth.* classes for testing.
18 */ 12 */
19 @TargetApi(Build.VERSION_CODES.LOLLIPOP)
20 class Fakes { 13 class Fakes {
21 private static final String TAG = "cr.Bluetooth"; 14 private static final String TAG = "cr.Bluetooth";
22 15
23 /** 16 /**
24 * Fakes android.bluetooth.BluetoothAdapter. 17 * Fakes android.bluetooth.BluetoothAdapter.
25 */ 18 */
26 static class FakeBluetoothAdapter extends Wrappers.BluetoothAdapterWrapper { 19 static class FakeBluetoothAdapter extends Wrappers.BluetoothAdapterWrapper {
27 private final FakeBluetoothLeScanner mFakeScanner;
28
29 /** 20 /**
30 * Creates a FakeBluetoothAdapter. 21 * Creates a FakeBluetoothAdapter.
31 */ 22 */
32 @CalledByNative("FakeBluetoothAdapter") 23 @CalledByNative("FakeBluetoothAdapter")
33 public static FakeBluetoothAdapter create() { 24 public static FakeBluetoothAdapter create() {
34 Log.v(TAG, "FakeBluetoothAdapter created."); 25 Log.v(TAG, "FakeBluetoothAdapter created.");
35 return new FakeBluetoothAdapter(); 26 return new FakeBluetoothAdapter();
36 } 27 }
37 28
38 private FakeBluetoothAdapter() { 29 private FakeBluetoothAdapter() {
39 super(null, new FakeBluetoothLeScanner()); 30 super(null);
40 mFakeScanner = (FakeBluetoothLeScanner) mScanner;
41 } 31 }
42 32
43 // --------------------------------------------------------------------- -------------------- 33 // --------------------------------------------------------------------- --------------------
44 // BluetoothAdapterWrapper overrides: 34 // BluetoothAdapterWrapper overrides:
45 35
46 @Override 36 @Override
47 public boolean isEnabled() { 37 public boolean isEnabled() {
48 return true; 38 return true;
49 } 39 }
50 40
(...skipping 10 matching lines...) Expand all
61 @Override 51 @Override
62 public int getScanMode() { 52 public int getScanMode() {
63 return android.bluetooth.BluetoothAdapter.SCAN_MODE_NONE; 53 return android.bluetooth.BluetoothAdapter.SCAN_MODE_NONE;
64 } 54 }
65 55
66 @Override 56 @Override
67 public boolean isDiscovering() { 57 public boolean isDiscovering() {
68 return false; 58 return false;
69 } 59 }
70 } 60 }
71
72 /**
73 * Fakes android.bluetooth.le.BluetoothLeScanner.
74 */
75 static class FakeBluetoothLeScanner extends Wrappers.BluetoothLeScannerWrapp er {
76 public Wrappers.ScanCallbackWrapper mCallback;
77
78 private FakeBluetoothLeScanner() {
79 super(null);
80 }
81
82 @Override
83 public void startScan(List<ScanFilter> filters, int scanSettingsScanMode ,
84 Wrappers.ScanCallbackWrapper callback) {
85 if (mCallback != null) {
86 throw new IllegalArgumentException(
87 "FakeBluetoothLeScanner does not support multiple scans. ");
88 }
89 mCallback = callback;
90 }
91
92 @Override
93 public void stopScan(Wrappers.ScanCallbackWrapper callback) {
94 if (mCallback != callback) {
95 throw new IllegalArgumentException("No scan in progress.");
96 }
97 mCallback = null;
98 }
99 }
100
101 /**
102 * Fakes android.bluetooth.le.ScanResult
103 */
104 static class FakeScanResult extends Wrappers.ScanResultWrapper {
105 private final FakeBluetoothDevice mDevice;
106
107 FakeScanResult(FakeBluetoothDevice device) {
108 super(null);
109 mDevice = device;
110 }
111
112 @Override
113 public Wrappers.BluetoothDeviceWrapper getDevice() {
114 return mDevice;
115 }
116 }
117
118 /**
119 * Fakes android.bluetooth.BluetoothDevice.
120 */
121 static class FakeBluetoothDevice extends Wrappers.BluetoothDeviceWrapper {
122 private static final String ADDRESS = "A1:B2:C3:DD:DD:DD";
123 private static final String NAME = "FakeBluetoothDevice";
124
125 public FakeBluetoothDevice() {
126 super(null);
127 }
128
129 @Override
130 public String getAddress() {
131 return ADDRESS;
132 }
133
134 @Override
135 public String getName() {
136 return NAME;
137 }
138 }
139 } 61 }
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_adapter_unittest.cc ('k') | device/bluetooth/test/bluetooth_test.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698