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 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_DEVICE_MAC_H_ | 5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_ANDROID_H_ |
6 #define DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_DEVICE_MAC_H_ | 6 #define DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_ANDROID_H_ |
7 | 7 |
8 #if defined(OS_IOS) | 8 #include "base/android/jni_android.h" |
9 #import <CoreBluetooth/CoreBluetooth.h> | 9 #include "base/memory/weak_ptr.h" |
10 #else | 10 #include "device/bluetooth/bluetooth_device.h" |
11 #import <IOBluetooth/IOBluetooth.h> | |
12 #endif | |
13 | |
14 #include "base/mac/scoped_nsobject.h" | |
15 #include "base/mac/sdk_forward_declarations.h" | |
16 #include "device/bluetooth/bluetooth_device_mac.h" | |
17 | 11 |
18 namespace device { | 12 namespace device { |
19 | 13 |
20 class BluetoothLowEnergyDiscoverManagerMac; | 14 // BluetoothDeviceAndroid along with the Java class |
| 15 // org.chromium.device.bluetooth.BluetoothDevice implement BluetoothDevice. |
| 16 class DEVICE_BLUETOOTH_EXPORT BluetoothDeviceAndroid final |
| 17 : public BluetoothDevice { |
| 18 public: |
| 19 // Create a BluetoothDeviceAndroid instance and associated Java |
| 20 // ChromeBluetoothDevice using the provided |java_bluetooth_device_wrapper|. |
| 21 // |
| 22 // The ChromeBluetoothDevice instance will hold a Java reference |
| 23 // to |bluetooth_device_wrapper|. |
| 24 // |
| 25 // TODO(scheib): Return a scoped_ptr<>, but then adapter will need to handle |
| 26 // this correctly. http://crbug.com/506416 |
| 27 static BluetoothDeviceAndroid* Create( |
| 28 jobject bluetooth_device_wrapper); // Java Type: bluetoothDeviceWrapper |
21 | 29 |
22 class BluetoothLowEnergyDeviceMac : public BluetoothDeviceMac { | 30 ~BluetoothDeviceAndroid() override; |
23 public: | |
24 BluetoothLowEnergyDeviceMac(CBPeripheral* peripheral, | |
25 NSDictionary* advertisementData, | |
26 int rssi); | |
27 ~BluetoothLowEnergyDeviceMac() override; | |
28 | 31 |
29 int GetRSSI() const; | 32 // Register C++ methods exposed to Java using JNI. |
| 33 static bool RegisterJNI(JNIEnv* env); |
30 | 34 |
31 // BluetoothDevice overrides. | 35 // Updates cached copy of advertised UUIDs discovered during a scan. |
32 std::string GetIdentifier() const override; | 36 // Returns true if new UUIDs differed from cached values. |
| 37 bool UpdateAdvertisedUUIDs( |
| 38 jobject advertised_uuids); // Java Type: List<ParcelUuid> |
| 39 |
| 40 // BluetoothDevice: |
33 uint32 GetBluetoothClass() const override; | 41 uint32 GetBluetoothClass() const override; |
34 std::string GetAddress() const override; | 42 std::string GetAddress() const override; |
35 BluetoothDevice::VendorIDSource GetVendorIDSource() const override; | 43 VendorIDSource GetVendorIDSource() const override; |
36 uint16 GetVendorID() const override; | 44 uint16 GetVendorID() const override; |
37 uint16 GetProductID() const override; | 45 uint16 GetProductID() const override; |
38 uint16 GetDeviceID() const override; | 46 uint16 GetDeviceID() const override; |
39 bool IsPaired() const override; | 47 bool IsPaired() const override; |
40 bool IsConnected() const override; | 48 bool IsConnected() const override; |
41 bool IsConnectable() const override; | 49 bool IsConnectable() const override; |
42 bool IsConnecting() const override; | 50 bool IsConnecting() const override; |
43 BluetoothDevice::UUIDList GetUUIDs() const override; | 51 UUIDList GetUUIDs() const override; |
44 int16 GetInquiryRSSI() const override; | 52 int16 GetInquiryRSSI() const override; |
45 int16 GetInquiryTxPower() const override; | 53 int16 GetInquiryTxPower() const override; |
46 bool ExpectingPinCode() const override; | 54 bool ExpectingPinCode() const override; |
47 bool ExpectingPasskey() const override; | 55 bool ExpectingPasskey() const override; |
48 bool ExpectingConfirmation() const override; | 56 bool ExpectingConfirmation() const override; |
49 void GetConnectionInfo(const ConnectionInfoCallback& callback) override; | 57 void GetConnectionInfo(const ConnectionInfoCallback& callback) override; |
50 void Connect(PairingDelegate* pairing_delegate, | 58 void Connect(device::BluetoothDevice::PairingDelegate* pairing_delegate, |
51 const base::Closure& callback, | 59 const base::Closure& callback, |
52 const ConnectErrorCallback& error_callback) override; | 60 const ConnectErrorCallback& error_callback) override; |
53 void SetPinCode(const std::string& pincode) override; | 61 void SetPinCode(const std::string& pincode) override; |
54 void SetPasskey(uint32 passkey) override; | 62 void SetPasskey(uint32 passkey) override; |
55 void ConfirmPairing() override; | 63 void ConfirmPairing() override; |
56 void RejectPairing() override; | 64 void RejectPairing() override; |
57 void CancelPairing() override; | 65 void CancelPairing() override; |
58 void Disconnect(const base::Closure& callback, | 66 void Disconnect(const base::Closure& callback, |
59 const ErrorCallback& error_callback) override; | 67 const ErrorCallback& error_callback) override; |
60 void Forget(const ErrorCallback& error_callback) override; | 68 void Forget(const ErrorCallback& error_callback) override; |
61 void ConnectToService( | 69 void ConnectToService( |
62 const BluetoothUUID& uuid, | 70 const device::BluetoothUUID& uuid, |
63 const ConnectToServiceCallback& callback, | 71 const ConnectToServiceCallback& callback, |
64 const ConnectToServiceErrorCallback& error_callback) override; | 72 const ConnectToServiceErrorCallback& error_callback) override; |
65 void ConnectToServiceInsecurely( | 73 void ConnectToServiceInsecurely( |
66 const device::BluetoothUUID& uuid, | 74 const device::BluetoothUUID& uuid, |
67 const ConnectToServiceCallback& callback, | 75 const ConnectToServiceCallback& callback, |
68 const ConnectToServiceErrorCallback& error_callback) override; | 76 const ConnectToServiceErrorCallback& error_callback) override; |
69 void CreateGattConnection( | 77 void CreateGattConnection( |
70 const GattConnectionCallback& callback, | 78 const GattConnectionCallback& callback, |
71 const ConnectErrorCallback& error_callback) override; | 79 const ConnectErrorCallback& error_callback) override; |
72 | 80 |
73 // BluetoothDeviceMac override. | 81 protected: |
74 NSDate* GetLastUpdateTime() const override; | 82 BluetoothDeviceAndroid(); |
75 | 83 |
76 protected: | 84 // BluetoothDevice: |
77 // BluetoothDevice override. | |
78 std::string GetDeviceName() const override; | 85 std::string GetDeviceName() const override; |
79 | 86 |
80 // Updates information about the device. | 87 // Java object org.chromium.device.bluetooth.ChromeBluetoothDevice. |
81 virtual void Update(CBPeripheral* peripheral, | 88 base::android::ScopedJavaGlobalRef<jobject> j_device_; |
82 NSDictionary* advertisementData, | |
83 int rssi); | |
84 | 89 |
85 static std::string GetPeripheralIdentifier(CBPeripheral* peripheral); | 90 DISALLOW_COPY_AND_ASSIGN(BluetoothDeviceAndroid); |
86 | |
87 private: | |
88 friend class BluetoothAdapterMac; | |
89 | |
90 // CoreBluetooth data structure. | |
91 base::scoped_nsobject<CBPeripheral> peripheral_; | |
92 | |
93 // RSSI value. | |
94 int rssi_; | |
95 | |
96 // Whether the device is connectable. | |
97 bool connectable_; | |
98 | |
99 // Stores the time of the most recent call to Update(). | |
100 base::scoped_nsobject<NSDate> last_update_time_; | |
101 | |
102 DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyDeviceMac); | |
103 }; | 91 }; |
104 | 92 |
105 } // namespace device | 93 } // namespace device |
106 | 94 |
107 #endif // DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_DEVICE_MAC_H_ | 95 #endif // DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_ANDROID_H_ |
OLD | NEW |