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.annotation.TargetApi; | 7 import android.annotation.TargetApi; |
8 import android.bluetooth.BluetoothDevice; | 8 import android.bluetooth.BluetoothDevice; |
9 import android.bluetooth.le.ScanFilter; | 9 import android.bluetooth.le.ScanFilter; |
10 import android.bluetooth.le.ScanSettings; | 10 import android.bluetooth.le.ScanSettings; |
11 import android.content.BroadcastReceiver; | 11 import android.content.BroadcastReceiver; |
12 import android.content.Context; | 12 import android.content.Context; |
13 import android.content.Intent; | 13 import android.content.Intent; |
14 import android.content.IntentFilter; | 14 import android.content.IntentFilter; |
15 | |
16 import android.os.Build; | 15 import android.os.Build; |
17 import android.os.ParcelUuid; | 16 import android.os.ParcelUuid; |
18 | |
19 import android.test.mock.MockContext; | 17 import android.test.mock.MockContext; |
20 | 18 |
21 import org.chromium.base.Log; | 19 import org.chromium.base.Log; |
22 import org.chromium.base.annotations.CalledByNative; | 20 import org.chromium.base.annotations.CalledByNative; |
23 import org.chromium.base.annotations.JNINamespace; | 21 import org.chromium.base.annotations.JNINamespace; |
24 import org.chromium.components.location.LocationUtils; | 22 import org.chromium.components.location.LocationUtils; |
25 import org.chromium.device.bluetooth.test.TestRSSI; | 23 import org.chromium.device.bluetooth.test.TestRSSI; |
26 import org.chromium.device.bluetooth.test.TestTxPower; | 24 import org.chromium.device.bluetooth.test.TestTxPower; |
27 | 25 |
28 import java.util.ArrayList; | 26 import java.util.ArrayList; |
(...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
640 private static void rememberCharacteristicForSubsequentAction( | 638 private static void rememberCharacteristicForSubsequentAction( |
641 ChromeBluetoothRemoteGattCharacteristic chromeCharacteristic) { | 639 ChromeBluetoothRemoteGattCharacteristic chromeCharacteristic) { |
642 sRememberedCharacteristic = | 640 sRememberedCharacteristic = |
643 (FakeBluetoothGattCharacteristic) chromeCharacteristic.mChar
acteristic; | 641 (FakeBluetoothGattCharacteristic) chromeCharacteristic.mChar
acteristic; |
644 } | 642 } |
645 | 643 |
646 // Simulate a value being read from a characteristic. | 644 // Simulate a value being read from a characteristic. |
647 @CalledByNative("FakeBluetoothGattCharacteristic") | 645 @CalledByNative("FakeBluetoothGattCharacteristic") |
648 private static void valueRead(ChromeBluetoothRemoteGattCharacteristic ch
romeCharacteristic, | 646 private static void valueRead(ChromeBluetoothRemoteGattCharacteristic ch
romeCharacteristic, |
649 int status, byte[] value) { | 647 int status, byte[] value) { |
650 if (chromeCharacteristic == null && sRememberedCharacteristic == nul
l) | 648 if (chromeCharacteristic == null && sRememberedCharacteristic == nul
l) { |
651 throw new IllegalArgumentException( | 649 throw new IllegalArgumentException( |
652 "rememberCharacteristic wasn't called previously."); | 650 "rememberCharacteristic wasn't called previously."); |
| 651 } |
653 | 652 |
654 FakeBluetoothGattCharacteristic fakeCharacteristic = (chromeCharacte
ristic == null) | 653 FakeBluetoothGattCharacteristic fakeCharacteristic = (chromeCharacte
ristic == null) |
655 ? sRememberedCharacteristic | 654 ? sRememberedCharacteristic |
656 : (FakeBluetoothGattCharacteristic) chromeCharacteristic.mCh
aracteristic; | 655 : (FakeBluetoothGattCharacteristic) chromeCharacteristic.mCh
aracteristic; |
657 | 656 |
658 fakeCharacteristic.mValue = value; | 657 fakeCharacteristic.mValue = value; |
659 fakeCharacteristic.mService.mDevice.mGattCallback.onCharacteristicRe
ad( | 658 fakeCharacteristic.mService.mDevice.mGattCallback.onCharacteristicRe
ad( |
660 fakeCharacteristic, status); | 659 fakeCharacteristic, status); |
661 } | 660 } |
662 | 661 |
663 // Simulate a value being written to a characteristic. | 662 // Simulate a value being written to a characteristic. |
664 @CalledByNative("FakeBluetoothGattCharacteristic") | 663 @CalledByNative("FakeBluetoothGattCharacteristic") |
665 private static void valueWrite( | 664 private static void valueWrite( |
666 ChromeBluetoothRemoteGattCharacteristic chromeCharacteristic, in
t status) { | 665 ChromeBluetoothRemoteGattCharacteristic chromeCharacteristic, in
t status) { |
667 if (chromeCharacteristic == null && sRememberedCharacteristic == nul
l) | 666 if (chromeCharacteristic == null && sRememberedCharacteristic == nul
l) { |
668 throw new IllegalArgumentException( | 667 throw new IllegalArgumentException( |
669 "rememberCharacteristic wasn't called previously."); | 668 "rememberCharacteristic wasn't called previously."); |
| 669 } |
670 | 670 |
671 FakeBluetoothGattCharacteristic fakeCharacteristic = (chromeCharacte
ristic == null) | 671 FakeBluetoothGattCharacteristic fakeCharacteristic = (chromeCharacte
ristic == null) |
672 ? sRememberedCharacteristic | 672 ? sRememberedCharacteristic |
673 : (FakeBluetoothGattCharacteristic) chromeCharacteristic.mCh
aracteristic; | 673 : (FakeBluetoothGattCharacteristic) chromeCharacteristic.mCh
aracteristic; |
674 | 674 |
675 fakeCharacteristic.mService.mDevice.mGattCallback.onCharacteristicWr
ite( | 675 fakeCharacteristic.mService.mDevice.mGattCallback.onCharacteristicWr
ite( |
676 fakeCharacteristic, status); | 676 fakeCharacteristic, status); |
677 } | 677 } |
678 | 678 |
679 // Cause subsequent notification of a characteristic to fail synchronous
ly. | 679 // Cause subsequent notification of a characteristic to fail synchronous
ly. |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
777 @CalledByNative("FakeBluetoothGattDescriptor") | 777 @CalledByNative("FakeBluetoothGattDescriptor") |
778 private static void rememberDescriptorForSubsequentAction( | 778 private static void rememberDescriptorForSubsequentAction( |
779 ChromeBluetoothRemoteGattDescriptor chromeDescriptor) { | 779 ChromeBluetoothRemoteGattDescriptor chromeDescriptor) { |
780 sRememberedDescriptor = (FakeBluetoothGattDescriptor) chromeDescript
or.mDescriptor; | 780 sRememberedDescriptor = (FakeBluetoothGattDescriptor) chromeDescript
or.mDescriptor; |
781 } | 781 } |
782 | 782 |
783 // Simulate a value being read from a descriptor. | 783 // Simulate a value being read from a descriptor. |
784 @CalledByNative("FakeBluetoothGattDescriptor") | 784 @CalledByNative("FakeBluetoothGattDescriptor") |
785 private static void valueRead( | 785 private static void valueRead( |
786 ChromeBluetoothRemoteGattDescriptor chromeDescriptor, int status
, byte[] value) { | 786 ChromeBluetoothRemoteGattDescriptor chromeDescriptor, int status
, byte[] value) { |
787 if (chromeDescriptor == null && sRememberedDescriptor == null) | 787 if (chromeDescriptor == null && sRememberedDescriptor == null) { |
788 throw new IllegalArgumentException("rememberDescriptor wasn't ca
lled previously."); | 788 throw new IllegalArgumentException("rememberDescriptor wasn't ca
lled previously."); |
| 789 } |
789 | 790 |
790 FakeBluetoothGattDescriptor fakeDescriptor = (chromeDescriptor == nu
ll) | 791 FakeBluetoothGattDescriptor fakeDescriptor = (chromeDescriptor == nu
ll) |
791 ? sRememberedDescriptor | 792 ? sRememberedDescriptor |
792 : (FakeBluetoothGattDescriptor) chromeDescriptor.mDescriptor
; | 793 : (FakeBluetoothGattDescriptor) chromeDescriptor.mDescriptor
; |
793 | 794 |
794 fakeDescriptor.mValue = value; | 795 fakeDescriptor.mValue = value; |
795 fakeDescriptor.mCharacteristic.mService.mDevice.mGattCallback.onDesc
riptorRead( | 796 fakeDescriptor.mCharacteristic.mService.mDevice.mGattCallback.onDesc
riptorRead( |
796 fakeDescriptor, status); | 797 fakeDescriptor, status); |
797 } | 798 } |
798 | 799 |
799 // Simulate a value being written to a descriptor. | 800 // Simulate a value being written to a descriptor. |
800 @CalledByNative("FakeBluetoothGattDescriptor") | 801 @CalledByNative("FakeBluetoothGattDescriptor") |
801 private static void valueWrite( | 802 private static void valueWrite( |
802 ChromeBluetoothRemoteGattDescriptor chromeDescriptor, int status
) { | 803 ChromeBluetoothRemoteGattDescriptor chromeDescriptor, int status
) { |
803 if (chromeDescriptor == null && sRememberedDescriptor == null) | 804 if (chromeDescriptor == null && sRememberedDescriptor == null) { |
804 throw new IllegalArgumentException("rememberDescriptor wasn't ca
lled previously."); | 805 throw new IllegalArgumentException("rememberDescriptor wasn't ca
lled previously."); |
| 806 } |
805 | 807 |
806 FakeBluetoothGattDescriptor fakeDescriptor = (chromeDescriptor == nu
ll) | 808 FakeBluetoothGattDescriptor fakeDescriptor = (chromeDescriptor == nu
ll) |
807 ? sRememberedDescriptor | 809 ? sRememberedDescriptor |
808 : (FakeBluetoothGattDescriptor) chromeDescriptor.mDescriptor
; | 810 : (FakeBluetoothGattDescriptor) chromeDescriptor.mDescriptor
; |
809 | 811 |
810 fakeDescriptor.mCharacteristic.mService.mDevice.mGattCallback.onDesc
riptorWrite( | 812 fakeDescriptor.mCharacteristic.mService.mDevice.mGattCallback.onDesc
riptorWrite( |
811 fakeDescriptor, status); | 813 fakeDescriptor, status); |
812 } | 814 } |
813 | 815 |
814 // Cause subsequent value read of a descriptor to fail synchronously. | 816 // Cause subsequent value read of a descriptor to fail synchronously. |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
895 long nativeBluetoothTestAndroid, byte[] value); | 897 long nativeBluetoothTestAndroid, byte[] value); |
896 | 898 |
897 // Binds to BluetoothTestAndroid::OnFakeBluetoothGattReadDescriptor. | 899 // Binds to BluetoothTestAndroid::OnFakeBluetoothGattReadDescriptor. |
898 private static native void nativeOnFakeBluetoothGattReadDescriptor( | 900 private static native void nativeOnFakeBluetoothGattReadDescriptor( |
899 long nativeBluetoothTestAndroid); | 901 long nativeBluetoothTestAndroid); |
900 | 902 |
901 // Binds to BluetoothTestAndroid::OnFakeBluetoothGattWriteDescriptor. | 903 // Binds to BluetoothTestAndroid::OnFakeBluetoothGattWriteDescriptor. |
902 private static native void nativeOnFakeBluetoothGattWriteDescriptor( | 904 private static native void nativeOnFakeBluetoothGattWriteDescriptor( |
903 long nativeBluetoothTestAndroid, byte[] value); | 905 long nativeBluetoothTestAndroid, byte[] value); |
904 } | 906 } |
OLD | NEW |