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
3 // found in the LICENSE file.
5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_ANDROID_H_
6 #define DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_ANDROID_H_
8 #include "base/android/jni_android.h"
9 #include "base/memory/weak_ptr.h"
10 #include "device/bluetooth/bluetooth_device.h"
14 class BluetoothAdapterAndroid
;
16 // BluetoothDeviceAndroid along with the Java class
17 // org.chromium.device.bluetooth.ChromeBluetoothDevice implement
19 class DEVICE_BLUETOOTH_EXPORT BluetoothDeviceAndroid final
20 : public BluetoothDevice
{
22 // Create a BluetoothDeviceAndroid instance and associated Java
23 // ChromeBluetoothDevice using the provided |java_bluetooth_device_wrapper|.
25 // The ChromeBluetoothDevice instance will hold a Java reference
26 // to |bluetooth_device_wrapper|.
28 // TODO(scheib): Return a scoped_ptr<>, but then adapter will need to handle
29 // this correctly. http://crbug.com/506416
30 static BluetoothDeviceAndroid
* Create(
31 BluetoothAdapterAndroid
* adapter
,
32 jobject bluetooth_device_wrapper
); // Java Type: bluetoothDeviceWrapper
34 ~BluetoothDeviceAndroid() override
;
36 // Register C++ methods exposed to Java using JNI.
37 static bool RegisterJNI(JNIEnv
* env
);
39 // Updates cached copy of advertised UUIDs discovered during a scan.
40 // Returns true if new UUIDs differed from cached values.
41 bool UpdateAdvertisedUUIDs(
42 jobject advertised_uuids
); // Java Type: List<ParcelUuid>
45 uint32
GetBluetoothClass() const override
;
46 std::string
GetAddress() const override
;
47 VendorIDSource
GetVendorIDSource() const override
;
48 uint16
GetVendorID() const override
;
49 uint16
GetProductID() const override
;
50 uint16
GetDeviceID() const override
;
51 bool IsPaired() const override
;
52 bool IsConnected() const override
;
53 bool IsGattConnected() const override
;
54 bool IsConnectable() const override
;
55 bool IsConnecting() const override
;
56 UUIDList
GetUUIDs() const override
;
57 int16
GetInquiryRSSI() const override
;
58 int16
GetInquiryTxPower() const override
;
59 bool ExpectingPinCode() const override
;
60 bool ExpectingPasskey() const override
;
61 bool ExpectingConfirmation() const override
;
62 void GetConnectionInfo(const ConnectionInfoCallback
& callback
) override
;
63 void Connect(device::BluetoothDevice::PairingDelegate
* pairing_delegate
,
64 const base::Closure
& callback
,
65 const ConnectErrorCallback
& error_callback
) override
;
66 void SetPinCode(const std::string
& pincode
) override
;
67 void SetPasskey(uint32 passkey
) override
;
68 void ConfirmPairing() override
;
69 void RejectPairing() override
;
70 void CancelPairing() override
;
71 void Disconnect(const base::Closure
& callback
,
72 const ErrorCallback
& error_callback
) override
;
73 void Forget(const ErrorCallback
& error_callback
) override
;
74 void ConnectToService(
75 const device::BluetoothUUID
& uuid
,
76 const ConnectToServiceCallback
& callback
,
77 const ConnectToServiceErrorCallback
& error_callback
) override
;
78 void ConnectToServiceInsecurely(
79 const device::BluetoothUUID
& uuid
,
80 const ConnectToServiceCallback
& callback
,
81 const ConnectToServiceErrorCallback
& error_callback
) override
;
84 BluetoothDeviceAndroid(BluetoothAdapterAndroid
* adapter
);
87 std::string
GetDeviceName() const override
;
88 void CreateGattConnectionImpl() override
;
89 void DisconnectGatt() override
;
91 // Java object org.chromium.device.bluetooth.ChromeBluetoothDevice.
92 base::android::ScopedJavaGlobalRef
<jobject
> j_device_
;
94 bool gatt_connected_
= false;
96 DISALLOW_COPY_AND_ASSIGN(BluetoothDeviceAndroid
);
101 #endif // DEVICE_BLUETOOTH_BLUETOOTH_DEVICE_ANDROID_H_