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

Side by Side Diff: device/bluetooth/bluetooth_device_android.h

Issue 1215303006: bluetooth: android: Initial BluetoothDeviceAndroid implementation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bta-discovery-
Patch Set: Created 5 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
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 #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
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.h" 10 #include "device/bluetooth/bluetooth_device.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 |java_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(jobject java_bluetooth_device_wrapper);
21 28
22 class BluetoothLowEnergyDeviceMac : public BluetoothDevice { 29 ~BluetoothDeviceAndroid() override;
23 public:
24 BluetoothLowEnergyDeviceMac(CBPeripheral* peripheral,
25 NSDictionary* advertisementData,
26 int rssi);
27 ~BluetoothLowEnergyDeviceMac() override;
28 30
29 int GetRSSI() const; 31 // Register C++ methods exposed to Java using JNI.
32 static bool RegisterJNI(JNIEnv* env);
30 33
31 // BluetoothDevice overrides. 34 // Updates cached copy of advertised UUIDs discovered during a scan.
32 std::string GetIdentifier() const override; 35 // Returns true if new UUIDs differed from cached values.
36 bool UpdateAdvertisedUUIDs(jobject advertised_uuids);
37
38 // BluetoothDevice:
33 uint32 GetBluetoothClass() const override; 39 uint32 GetBluetoothClass() const override;
34 std::string GetAddress() const override; 40 std::string GetAddress() const override;
35 BluetoothDevice::VendorIDSource GetVendorIDSource() const override; 41 VendorIDSource GetVendorIDSource() const override;
36 uint16 GetVendorID() const override; 42 uint16 GetVendorID() const override;
37 uint16 GetProductID() const override; 43 uint16 GetProductID() const override;
38 uint16 GetDeviceID() const override; 44 uint16 GetDeviceID() const override;
39 bool IsPaired() const override; 45 bool IsPaired() const override;
40 bool IsConnected() const override; 46 bool IsConnected() const override;
41 bool IsConnectable() const override; 47 bool IsConnectable() const override;
42 bool IsConnecting() const override; 48 bool IsConnecting() const override;
43 BluetoothDevice::UUIDList GetUUIDs() const override; 49 UUIDList GetUUIDs() const override;
44 int16 GetInquiryRSSI() const override; 50 int16 GetInquiryRSSI() const override;
45 int16 GetInquiryTxPower() const override; 51 int16 GetInquiryTxPower() const override;
46 bool ExpectingPinCode() const override; 52 bool ExpectingPinCode() const override;
47 bool ExpectingPasskey() const override; 53 bool ExpectingPasskey() const override;
48 bool ExpectingConfirmation() const override; 54 bool ExpectingConfirmation() const override;
49 void GetConnectionInfo(const ConnectionInfoCallback& callback) override; 55 void GetConnectionInfo(const ConnectionInfoCallback& callback) override;
50 void Connect(PairingDelegate* pairing_delegate, 56 void Connect(device::BluetoothDevice::PairingDelegate* pairing_delegate,
51 const base::Closure& callback, 57 const base::Closure& callback,
52 const ConnectErrorCallback& error_callback) override; 58 const ConnectErrorCallback& error_callback) override;
53 void SetPinCode(const std::string& pincode) override; 59 void SetPinCode(const std::string& pincode) override;
54 void SetPasskey(uint32 passkey) override; 60 void SetPasskey(uint32 passkey) override;
55 void ConfirmPairing() override; 61 void ConfirmPairing() override;
56 void RejectPairing() override; 62 void RejectPairing() override;
57 void CancelPairing() override; 63 void CancelPairing() override;
58 void Disconnect(const base::Closure& callback, 64 void Disconnect(const base::Closure& callback,
59 const ErrorCallback& error_callback) override; 65 const ErrorCallback& error_callback) override;
60 void Forget(const ErrorCallback& error_callback) override; 66 void Forget(const ErrorCallback& error_callback) override;
61 void ConnectToService( 67 void ConnectToService(
62 const BluetoothUUID& uuid, 68 const device::BluetoothUUID& uuid,
63 const ConnectToServiceCallback& callback, 69 const ConnectToServiceCallback& callback,
64 const ConnectToServiceErrorCallback& error_callback) override; 70 const ConnectToServiceErrorCallback& error_callback) override;
65 void ConnectToServiceInsecurely( 71 void ConnectToServiceInsecurely(
66 const device::BluetoothUUID& uuid, 72 const device::BluetoothUUID& uuid,
67 const ConnectToServiceCallback& callback, 73 const ConnectToServiceCallback& callback,
68 const ConnectToServiceErrorCallback& error_callback) override; 74 const ConnectToServiceErrorCallback& error_callback) override;
69 void CreateGattConnection( 75 void CreateGattConnection(
70 const GattConnectionCallback& callback, 76 const GattConnectionCallback& callback,
71 const ConnectErrorCallback& error_callback) override; 77 const ConnectErrorCallback& error_callback) override;
72 78
73 protected: 79 protected:
74 // BluetoothDevice override. 80 BluetoothDeviceAndroid();
81
82 // BluetoothDevice:
75 std::string GetDeviceName() const override; 83 std::string GetDeviceName() const override;
76 84
77 // Updates information about the device. 85 // Java object org.chromium.device.bluetooth.ChromeBluetoothDevice.
78 virtual void Update(CBPeripheral* peripheral, 86 base::android::ScopedJavaGlobalRef<jobject> j_device_;
79 NSDictionary* advertisementData,
80 int rssi);
81 87
82 static std::string GetPeripheralIdentifier(CBPeripheral* peripheral); 88 DISALLOW_COPY_AND_ASSIGN(BluetoothDeviceAndroid);
83
84 private:
85 friend class BluetoothAdapterMac;
86
87 // CoreBluetooth data structure.
88 base::scoped_nsobject<CBPeripheral> peripheral_;
89
90 // RSSI value.
91 int rssi_;
92
93 // Whether the device is connectable.
94 bool connectable_;
95
96 DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyDeviceMac);
97 }; 89 };
98 90
99 } // namespace device 91 } // namespace device
100 92
101 #endif // DEVICE_BLUETOOTH_BLUETOOTH_LOW_ENERGY_DEVICE_MAC_H_ 93 #endif // DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_ANDROID_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698