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.Context; | 13 import android.content.Context; |
| 14 import android.content.Intent; |
| 15 import android.content.IntentFilter; |
| 16 |
13 import android.os.Build; | 17 import android.os.Build; |
14 import android.os.ParcelUuid; | 18 import android.os.ParcelUuid; |
15 | 19 |
16 import org.chromium.base.Log; | 20 import org.chromium.base.Log; |
17 import org.chromium.base.annotations.CalledByNative; | 21 import org.chromium.base.annotations.CalledByNative; |
18 import org.chromium.base.annotations.JNINamespace; | 22 import org.chromium.base.annotations.JNINamespace; |
19 | 23 |
20 import java.util.ArrayList; | 24 import java.util.ArrayList; |
21 import java.util.HashMap; | 25 import java.util.HashMap; |
22 import java.util.HashSet; | 26 import java.util.HashSet; |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 mFakeScanner.forceIllegalStateException(); | 130 mFakeScanner.forceIllegalStateException(); |
127 } | 131 } |
128 } | 132 } |
129 | 133 |
130 // ---------------------------------------------------------------------
-------------------- | 134 // ---------------------------------------------------------------------
-------------------- |
131 // BluetoothAdapterWrapper overrides: | 135 // BluetoothAdapterWrapper overrides: |
132 | 136 |
133 @Override | 137 @Override |
134 public boolean disable() { | 138 public boolean disable() { |
135 mPowered = false; | 139 mPowered = false; |
| 140 nativeOnFakeAdapterStateChanged(mNativeBluetoothTestAndroid, false); |
136 return true; | 141 return true; |
137 } | 142 } |
138 | 143 |
139 @Override | 144 @Override |
140 public boolean enable() { | 145 public boolean enable() { |
141 mPowered = true; | 146 mPowered = true; |
| 147 nativeOnFakeAdapterStateChanged(mNativeBluetoothTestAndroid, true); |
142 return true; | 148 return true; |
143 } | 149 } |
144 | 150 |
145 @Override | 151 @Override |
146 public String getAddress() { | 152 public String getAddress() { |
147 return "A1:B2:C3:D4:E5:F6"; | 153 return "A1:B2:C3:D4:E5:F6"; |
148 } | 154 } |
149 | 155 |
150 @Override | 156 @Override |
151 public Wrappers.BluetoothLeScannerWrapper getBluetoothLeScanner() { | 157 public Wrappers.BluetoothLeScannerWrapper getBluetoothLeScanner() { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 | 190 |
185 public FakeContext() { | 191 public FakeContext() { |
186 super(null); | 192 super(null); |
187 mPermissions.add(Manifest.permission.ACCESS_COARSE_LOCATION); | 193 mPermissions.add(Manifest.permission.ACCESS_COARSE_LOCATION); |
188 } | 194 } |
189 | 195 |
190 @Override | 196 @Override |
191 public boolean checkPermission(String permission) { | 197 public boolean checkPermission(String permission) { |
192 return mPermissions.contains(permission); | 198 return mPermissions.contains(permission); |
193 } | 199 } |
| 200 |
| 201 @Override |
| 202 public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter
filter) { |
| 203 return null; |
| 204 } |
| 205 |
| 206 @Override |
| 207 public void unregisterReceiver(BroadcastReceiver receiver) {} |
194 } | 208 } |
195 | 209 |
196 /** | 210 /** |
197 * Fakes android.bluetooth.le.BluetoothLeScanner. | 211 * Fakes android.bluetooth.le.BluetoothLeScanner. |
198 */ | 212 */ |
199 static class FakeBluetoothLeScanner extends Wrappers.BluetoothLeScannerWrapp
er { | 213 static class FakeBluetoothLeScanner extends Wrappers.BluetoothLeScannerWrapp
er { |
200 public Wrappers.ScanCallbackWrapper mScanCallback; | 214 public Wrappers.ScanCallbackWrapper mScanCallback; |
201 private boolean mThrowException; | 215 private boolean mThrowException; |
202 | 216 |
203 private FakeBluetoothLeScanner() { | 217 private FakeBluetoothLeScanner() { |
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
708 @Override | 722 @Override |
709 public boolean setValue(byte[] value) { | 723 public boolean setValue(byte[] value) { |
710 mValue = value; | 724 mValue = value; |
711 return true; | 725 return true; |
712 } | 726 } |
713 } | 727 } |
714 | 728 |
715 // -------------------------------------------------------------------------
-------------------- | 729 // -------------------------------------------------------------------------
-------------------- |
716 // BluetoothTestAndroid C++ methods declared for access from java: | 730 // BluetoothTestAndroid C++ methods declared for access from java: |
717 | 731 |
| 732 // Binds to BluetoothTestAndroid::OnFakeAdapterStateChanged. |
| 733 private static native void nativeOnFakeAdapterStateChanged( |
| 734 long nativeBluetoothTestAndroid, boolean powered); |
| 735 |
718 // Binds to BluetoothTestAndroid::OnFakeBluetoothDeviceConnectGattCalled. | 736 // Binds to BluetoothTestAndroid::OnFakeBluetoothDeviceConnectGattCalled. |
719 private static native void nativeOnFakeBluetoothDeviceConnectGattCalled( | 737 private static native void nativeOnFakeBluetoothDeviceConnectGattCalled( |
720 long nativeBluetoothTestAndroid); | 738 long nativeBluetoothTestAndroid); |
721 | 739 |
722 // Binds to BluetoothTestAndroid::OnFakeBluetoothGattDisconnect. | 740 // Binds to BluetoothTestAndroid::OnFakeBluetoothGattDisconnect. |
723 private static native void nativeOnFakeBluetoothGattDisconnect(long nativeBl
uetoothTestAndroid); | 741 private static native void nativeOnFakeBluetoothGattDisconnect(long nativeBl
uetoothTestAndroid); |
724 | 742 |
725 // Binds to BluetoothTestAndroid::OnFakeBluetoothGattClose. | 743 // Binds to BluetoothTestAndroid::OnFakeBluetoothGattClose. |
726 private static native void nativeOnFakeBluetoothGattClose(long nativeBluetoo
thTestAndroid); | 744 private static native void nativeOnFakeBluetoothGattClose(long nativeBluetoo
thTestAndroid); |
727 | 745 |
(...skipping 10 matching lines...) Expand all Loading... |
738 long nativeBluetoothTestAndroid); | 756 long nativeBluetoothTestAndroid); |
739 | 757 |
740 // Binds to BluetoothTestAndroid::OnFakeBluetoothGattWriteCharacteristic. | 758 // Binds to BluetoothTestAndroid::OnFakeBluetoothGattWriteCharacteristic. |
741 private static native void nativeOnFakeBluetoothGattWriteCharacteristic( | 759 private static native void nativeOnFakeBluetoothGattWriteCharacteristic( |
742 long nativeBluetoothTestAndroid, byte[] value); | 760 long nativeBluetoothTestAndroid, byte[] value); |
743 | 761 |
744 // Binds to BluetoothTestAndroid::OnFakeBluetoothGattWriteDescriptor. | 762 // Binds to BluetoothTestAndroid::OnFakeBluetoothGattWriteDescriptor. |
745 private static native void nativeOnFakeBluetoothGattWriteDescriptor( | 763 private static native void nativeOnFakeBluetoothGattWriteDescriptor( |
746 long nativeBluetoothTestAndroid, byte[] value); | 764 long nativeBluetoothTestAndroid, byte[] value); |
747 } | 765 } |
OLD | NEW |