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.BluetoothDevice; | 9 import android.bluetooth.BluetoothDevice; |
10 import android.bluetooth.le.ScanFilter; | 10 import android.bluetooth.le.ScanFilter; |
11 import android.bluetooth.le.ScanSettings; | 11 import android.bluetooth.le.ScanSettings; |
12 import android.content.BroadcastReceiver; | 12 import android.content.BroadcastReceiver; |
13 import android.content.Context; | 13 import android.content.Context; |
14 import android.content.Intent; | 14 import android.content.Intent; |
15 import android.content.IntentFilter; | 15 import android.content.IntentFilter; |
| 16 import android.location.LocationManager; |
16 | 17 |
17 import android.os.Build; | 18 import android.os.Build; |
18 import android.os.ParcelUuid; | 19 import android.os.ParcelUuid; |
19 | 20 |
20 import org.chromium.base.Log; | 21 import org.chromium.base.Log; |
21 import org.chromium.base.annotations.CalledByNative; | 22 import org.chromium.base.annotations.CalledByNative; |
22 import org.chromium.base.annotations.JNINamespace; | 23 import org.chromium.base.annotations.JNINamespace; |
23 | 24 |
24 import java.util.ArrayList; | 25 import java.util.ArrayList; |
25 import java.util.HashMap; | 26 import java.util.HashMap; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 mNativeBluetoothTestAndroid = nativeBluetoothTestAndroid; | 65 mNativeBluetoothTestAndroid = nativeBluetoothTestAndroid; |
65 mFakeContext = (FakeContext) mContext; | 66 mFakeContext = (FakeContext) mContext; |
66 mFakeScanner = new FakeBluetoothLeScanner(); | 67 mFakeScanner = new FakeBluetoothLeScanner(); |
67 } | 68 } |
68 | 69 |
69 @CalledByNative("FakeBluetoothAdapter") | 70 @CalledByNative("FakeBluetoothAdapter") |
70 public void denyPermission() { | 71 public void denyPermission() { |
71 mFakeContext.mPermissions.clear(); | 72 mFakeContext.mPermissions.clear(); |
72 } | 73 } |
73 | 74 |
| 75 @CalledByNative("FakeBluetoothAdapter") |
| 76 public void turnOffLocationServices() { |
| 77 mFakeContext.mLocationProviders.clear(); |
| 78 } |
| 79 |
74 /** | 80 /** |
75 * Creates and discovers a new device. | 81 * Creates and discovers a new device. |
76 */ | 82 */ |
77 @CalledByNative("FakeBluetoothAdapter") | 83 @CalledByNative("FakeBluetoothAdapter") |
78 public void simulateLowEnergyDevice(int deviceOrdinal) { | 84 public void simulateLowEnergyDevice(int deviceOrdinal) { |
79 if (mFakeScanner == null) { | 85 if (mFakeScanner == null) { |
80 return; | 86 return; |
81 } | 87 } |
82 | 88 |
83 switch (deviceOrdinal) { | 89 switch (deviceOrdinal) { |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 public boolean isDiscovering() { | 194 public boolean isDiscovering() { |
189 return false; | 195 return false; |
190 } | 196 } |
191 } | 197 } |
192 | 198 |
193 /** | 199 /** |
194 * Fakes android.content.Context. | 200 * Fakes android.content.Context. |
195 */ | 201 */ |
196 static class FakeContext extends Wrappers.ContextWrapper { | 202 static class FakeContext extends Wrappers.ContextWrapper { |
197 public final Set<String> mPermissions = new HashSet<String>(); | 203 public final Set<String> mPermissions = new HashSet<String>(); |
| 204 public final Set<String> mLocationProviders = new HashSet<String>(); |
198 | 205 |
199 public FakeContext() { | 206 public FakeContext() { |
200 super(null); | 207 super(null); |
201 mPermissions.add(Manifest.permission.ACCESS_COARSE_LOCATION); | 208 mPermissions.add(Manifest.permission.ACCESS_COARSE_LOCATION); |
| 209 mLocationProviders.add(LocationManager.NETWORK_PROVIDER); |
202 } | 210 } |
203 | 211 |
204 @Override | 212 @Override |
205 public boolean checkPermission(String permission) { | 213 public boolean checkPermission(String permission) { |
206 return mPermissions.contains(permission); | 214 return mPermissions.contains(permission); |
207 } | 215 } |
208 | 216 |
209 @Override | 217 @Override |
| 218 public Wrappers.LocationManagerWrapper getLocationManager() { |
| 219 return new FakeLocationManager(mLocationProviders); |
| 220 } |
| 221 |
| 222 @Override |
210 public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter
filter) { | 223 public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter
filter) { |
211 return null; | 224 return null; |
212 } | 225 } |
213 | 226 |
214 @Override | 227 @Override |
215 public void unregisterReceiver(BroadcastReceiver receiver) {} | 228 public void unregisterReceiver(BroadcastReceiver receiver) {} |
216 } | 229 } |
217 | 230 |
| 231 static class FakeLocationManager extends Wrappers.LocationManagerWrapper { |
| 232 public final Set<String> mProviders; |
| 233 |
| 234 FakeLocationManager(Set<String> providers) { |
| 235 super(null); |
| 236 mProviders = providers; |
| 237 } |
| 238 |
| 239 public boolean isProviderEnabled(String name) { |
| 240 return mProviders.contains(name); |
| 241 } |
| 242 } |
| 243 |
218 /** | 244 /** |
219 * Fakes android.bluetooth.le.BluetoothLeScanner. | 245 * Fakes android.bluetooth.le.BluetoothLeScanner. |
220 */ | 246 */ |
221 static class FakeBluetoothLeScanner extends Wrappers.BluetoothLeScannerWrapp
er { | 247 static class FakeBluetoothLeScanner extends Wrappers.BluetoothLeScannerWrapp
er { |
222 public Wrappers.ScanCallbackWrapper mScanCallback; | 248 public Wrappers.ScanCallbackWrapper mScanCallback; |
223 private boolean mThrowException; | 249 private boolean mThrowException; |
224 | 250 |
225 private FakeBluetoothLeScanner() { | 251 private FakeBluetoothLeScanner() { |
226 super(null); | 252 super(null); |
227 } | 253 } |
(...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
815 long nativeBluetoothTestAndroid, byte[] value); | 841 long nativeBluetoothTestAndroid, byte[] value); |
816 | 842 |
817 // Binds to BluetoothTestAndroid::OnFakeBluetoothGattReadDescriptor. | 843 // Binds to BluetoothTestAndroid::OnFakeBluetoothGattReadDescriptor. |
818 private static native void nativeOnFakeBluetoothGattReadDescriptor( | 844 private static native void nativeOnFakeBluetoothGattReadDescriptor( |
819 long nativeBluetoothTestAndroid); | 845 long nativeBluetoothTestAndroid); |
820 | 846 |
821 // Binds to BluetoothTestAndroid::OnFakeBluetoothGattWriteDescriptor. | 847 // Binds to BluetoothTestAndroid::OnFakeBluetoothGattWriteDescriptor. |
822 private static native void nativeOnFakeBluetoothGattWriteDescriptor( | 848 private static native void nativeOnFakeBluetoothGattWriteDescriptor( |
823 long nativeBluetoothTestAndroid, byte[] value); | 849 long nativeBluetoothTestAndroid, byte[] value); |
824 } | 850 } |
OLD | NEW |