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; | |
8 import android.annotation.TargetApi; | 7 import android.annotation.TargetApi; |
9 import android.bluetooth.BluetoothDevice; | 8 import android.bluetooth.BluetoothDevice; |
10 import android.bluetooth.le.ScanFilter; | 9 import android.bluetooth.le.ScanFilter; |
11 import android.bluetooth.le.ScanSettings; | 10 import android.bluetooth.le.ScanSettings; |
12 import android.content.BroadcastReceiver; | 11 import android.content.BroadcastReceiver; |
13 import android.content.Context; | 12 import android.content.Context; |
14 import android.content.Intent; | 13 import android.content.Intent; |
15 import android.content.IntentFilter; | 14 import android.content.IntentFilter; |
16 | 15 |
17 import android.os.Build; | 16 import android.os.Build; |
18 import android.os.ParcelUuid; | 17 import android.os.ParcelUuid; |
19 | 18 |
20 import org.chromium.base.Log; | 19 import org.chromium.base.Log; |
21 import org.chromium.base.annotations.CalledByNative; | 20 import org.chromium.base.annotations.CalledByNative; |
22 import org.chromium.base.annotations.JNINamespace; | 21 import org.chromium.base.annotations.JNINamespace; |
23 | 22 |
24 import java.util.ArrayList; | 23 import java.util.ArrayList; |
25 import java.util.HashMap; | 24 import java.util.HashMap; |
26 import java.util.HashSet; | |
27 import java.util.List; | 25 import java.util.List; |
28 import java.util.Set; | |
29 import java.util.UUID; | 26 import java.util.UUID; |
30 | 27 |
31 /** | 28 /** |
32 * Fake implementations of android.bluetooth.* classes for testing. | 29 * Fake implementations of android.bluetooth.* classes for testing. |
33 * | 30 * |
34 * Fakes are contained in a single file to simplify code. Only one C++ file may | 31 * 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 | 32 * 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 | 33 * bluetooth_test_android.cc. The alternative would be a C++ .h, .cc file for |
37 * each of these classes. | 34 * each of these classes. |
38 */ | 35 */ |
(...skipping 22 matching lines...) Expand all Loading... |
61 | 58 |
62 private FakeBluetoothAdapter(long nativeBluetoothTestAndroid) { | 59 private FakeBluetoothAdapter(long nativeBluetoothTestAndroid) { |
63 super(null, new FakeContext()); | 60 super(null, new FakeContext()); |
64 mNativeBluetoothTestAndroid = nativeBluetoothTestAndroid; | 61 mNativeBluetoothTestAndroid = nativeBluetoothTestAndroid; |
65 mFakeContext = (FakeContext) mContext; | 62 mFakeContext = (FakeContext) mContext; |
66 mFakeScanner = new FakeBluetoothLeScanner(); | 63 mFakeScanner = new FakeBluetoothLeScanner(); |
67 } | 64 } |
68 | 65 |
69 @CalledByNative("FakeBluetoothAdapter") | 66 @CalledByNative("FakeBluetoothAdapter") |
70 public void denyPermission() { | 67 public void denyPermission() { |
71 mFakeContext.mPermissions.clear(); | 68 mFakeContext.mHasLocation = false; |
72 } | 69 } |
73 | 70 |
74 /** | 71 /** |
75 * Creates and discovers a new device. | 72 * Creates and discovers a new device. |
76 */ | 73 */ |
77 @CalledByNative("FakeBluetoothAdapter") | 74 @CalledByNative("FakeBluetoothAdapter") |
78 public void simulateLowEnergyDevice(int deviceOrdinal) { | 75 public void simulateLowEnergyDevice(int deviceOrdinal) { |
79 if (mFakeScanner == null) { | 76 if (mFakeScanner == null) { |
80 return; | 77 return; |
81 } | 78 } |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 @Override | 184 @Override |
188 public boolean isDiscovering() { | 185 public boolean isDiscovering() { |
189 return false; | 186 return false; |
190 } | 187 } |
191 } | 188 } |
192 | 189 |
193 /** | 190 /** |
194 * Fakes android.content.Context. | 191 * Fakes android.content.Context. |
195 */ | 192 */ |
196 static class FakeContext extends Wrappers.ContextWrapper { | 193 static class FakeContext extends Wrappers.ContextWrapper { |
197 public final Set<String> mPermissions = new HashSet<String>(); | 194 public boolean mHasLocation = true; |
198 | 195 |
199 public FakeContext() { | 196 public FakeContext() { |
200 super(null); | 197 super(null); |
201 mPermissions.add(Manifest.permission.ACCESS_COARSE_LOCATION); | |
202 } | 198 } |
203 | 199 |
204 @Override | 200 @Override |
205 public boolean checkPermission(String permission) { | 201 public boolean hasAndroidLocationPermission() { |
206 return mPermissions.contains(permission); | 202 return mHasLocation; |
207 } | 203 } |
208 | 204 |
209 @Override | 205 @Override |
210 public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter
filter) { | 206 public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter
filter) { |
211 return null; | 207 return null; |
212 } | 208 } |
213 | 209 |
214 @Override | 210 @Override |
215 public void unregisterReceiver(BroadcastReceiver receiver) {} | 211 public void unregisterReceiver(BroadcastReceiver receiver) {} |
216 } | 212 } |
(...skipping 598 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
815 long nativeBluetoothTestAndroid, byte[] value); | 811 long nativeBluetoothTestAndroid, byte[] value); |
816 | 812 |
817 // Binds to BluetoothTestAndroid::OnFakeBluetoothGattReadDescriptor. | 813 // Binds to BluetoothTestAndroid::OnFakeBluetoothGattReadDescriptor. |
818 private static native void nativeOnFakeBluetoothGattReadDescriptor( | 814 private static native void nativeOnFakeBluetoothGattReadDescriptor( |
819 long nativeBluetoothTestAndroid); | 815 long nativeBluetoothTestAndroid); |
820 | 816 |
821 // Binds to BluetoothTestAndroid::OnFakeBluetoothGattWriteDescriptor. | 817 // Binds to BluetoothTestAndroid::OnFakeBluetoothGattWriteDescriptor. |
822 private static native void nativeOnFakeBluetoothGattWriteDescriptor( | 818 private static native void nativeOnFakeBluetoothGattWriteDescriptor( |
823 long nativeBluetoothTestAndroid, byte[] value); | 819 long nativeBluetoothTestAndroid, byte[] value); |
824 } | 820 } |
OLD | NEW |