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

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

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

Powered by Google App Engine
This is Rietveld 408576698