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 #include "device/bluetooth/bluetooth_device_android.h"
7 #include "base/android/jni_android.h"
8 #include "base/android/jni_array.h"
9 #include "base/android/jni_string.h"
10 #include "jni/ChromeBluetoothDevice_jni.h"
12 using base::android::AttachCurrentThread
;
13 using base::android::AppendJavaStringArrayToStringVector
;
17 BluetoothDeviceAndroid
* BluetoothDeviceAndroid::Create(
18 jobject bluetooth_device_wrapper
) { // Java Type: bluetoothDeviceWrapper
19 BluetoothDeviceAndroid
* device
= new BluetoothDeviceAndroid();
21 device
->j_device_
.Reset(Java_ChromeBluetoothDevice_create(
22 AttachCurrentThread(), bluetooth_device_wrapper
));
27 BluetoothDeviceAndroid::~BluetoothDeviceAndroid() {
30 bool BluetoothDeviceAndroid::UpdateAdvertisedUUIDs(jobject advertised_uuids
) {
31 return Java_ChromeBluetoothDevice_updateAdvertisedUUIDs(
32 AttachCurrentThread(), j_device_
.obj(), advertised_uuids
);
36 bool BluetoothDeviceAndroid::RegisterJNI(JNIEnv
* env
) {
37 return RegisterNativesImpl(env
); // Generated in ChromeBluetoothDevice_jni.h
40 uint32
BluetoothDeviceAndroid::GetBluetoothClass() const {
41 return Java_ChromeBluetoothDevice_getBluetoothClass(AttachCurrentThread(),
45 std::string
BluetoothDeviceAndroid::GetAddress() const {
46 return ConvertJavaStringToUTF8(Java_ChromeBluetoothDevice_getAddress(
47 AttachCurrentThread(), j_device_
.obj()));
50 BluetoothDevice::VendorIDSource
BluetoothDeviceAndroid::GetVendorIDSource()
52 // Android API does not provide Vendor ID.
53 return VENDOR_ID_UNKNOWN
;
56 uint16
BluetoothDeviceAndroid::GetVendorID() const {
57 // Android API does not provide Vendor ID.
61 uint16
BluetoothDeviceAndroid::GetProductID() const {
62 // Android API does not provide Product ID.
66 uint16
BluetoothDeviceAndroid::GetDeviceID() const {
67 // Android API does not provide Device ID.
71 bool BluetoothDeviceAndroid::IsPaired() const {
72 return Java_ChromeBluetoothDevice_isPaired(AttachCurrentThread(),
76 bool BluetoothDeviceAndroid::IsConnected() const {
81 bool BluetoothDeviceAndroid::IsConnectable() const {
86 bool BluetoothDeviceAndroid::IsConnecting() const {
91 BluetoothDevice::UUIDList
BluetoothDeviceAndroid::GetUUIDs() const {
92 JNIEnv
* env
= AttachCurrentThread();
93 std::vector
<std::string
> uuid_strings
;
94 AppendJavaStringArrayToStringVector(
95 env
, Java_ChromeBluetoothDevice_getUuids(env
, j_device_
.obj()).obj(),
97 BluetoothDevice::UUIDList uuids
;
98 uuids
.reserve(uuid_strings
.size());
99 for (auto uuid_string
: uuid_strings
) {
100 uuids
.push_back(BluetoothUUID(uuid_string
));
105 int16
BluetoothDeviceAndroid::GetInquiryRSSI() const {
107 return kUnknownPower
;
110 int16
BluetoothDeviceAndroid::GetInquiryTxPower() const {
112 return kUnknownPower
;
115 bool BluetoothDeviceAndroid::ExpectingPinCode() const {
120 bool BluetoothDeviceAndroid::ExpectingPasskey() const {
125 bool BluetoothDeviceAndroid::ExpectingConfirmation() const {
130 void BluetoothDeviceAndroid::GetConnectionInfo(
131 const ConnectionInfoCallback
& callback
) {
133 callback
.Run(ConnectionInfo());
136 void BluetoothDeviceAndroid::Connect(
137 PairingDelegate
* pairing_delegate
,
138 const base::Closure
& callback
,
139 const ConnectErrorCallback
& error_callback
) {
143 void BluetoothDeviceAndroid::SetPinCode(const std::string
& pincode
) {
147 void BluetoothDeviceAndroid::SetPasskey(uint32 passkey
) {
151 void BluetoothDeviceAndroid::ConfirmPairing() {
155 void BluetoothDeviceAndroid::RejectPairing() {
159 void BluetoothDeviceAndroid::CancelPairing() {
163 void BluetoothDeviceAndroid::Disconnect(const base::Closure
& callback
,
164 const ErrorCallback
& error_callback
) {
168 void BluetoothDeviceAndroid::Forget(const ErrorCallback
& error_callback
) {
172 void BluetoothDeviceAndroid::ConnectToService(
173 const BluetoothUUID
& uuid
,
174 const ConnectToServiceCallback
& callback
,
175 const ConnectToServiceErrorCallback
& error_callback
) {
179 void BluetoothDeviceAndroid::ConnectToServiceInsecurely(
180 const BluetoothUUID
& uuid
,
181 const ConnectToServiceCallback
& callback
,
182 const ConnectToServiceErrorCallback
& error_callback
) {
186 void BluetoothDeviceAndroid::CreateGattConnection(
187 const GattConnectionCallback
& callback
,
188 const ConnectErrorCallback
& error_callback
) {
192 BluetoothDeviceAndroid::BluetoothDeviceAndroid() {
195 std::string
BluetoothDeviceAndroid::GetDeviceName() const {
196 return ConvertJavaStringToUTF8(Java_ChromeBluetoothDevice_getDeviceName(
197 AttachCurrentThread(), j_device_
.obj()));
200 } // namespace device