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 #include "device/bluetooth/bluetooth_device_android.h" | 5 #include "device/bluetooth/bluetooth_device_android.h" |
6 | 6 |
7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
8 #include "base/android/jni_array.h" | 8 #include "base/android/jni_array.h" |
9 #include "base/android/jni_string.h" | 9 #include "base/android/jni_string.h" |
| 10 #include "base/strings/stringprintf.h" |
10 #include "device/bluetooth/bluetooth_adapter_android.h" | 11 #include "device/bluetooth/bluetooth_adapter_android.h" |
| 12 #include "device/bluetooth/bluetooth_remote_gatt_service_android.h" |
11 #include "jni/ChromeBluetoothDevice_jni.h" | 13 #include "jni/ChromeBluetoothDevice_jni.h" |
12 | 14 |
13 using base::android::AttachCurrentThread; | 15 using base::android::AttachCurrentThread; |
14 using base::android::AppendJavaStringArrayToStringVector; | 16 using base::android::AppendJavaStringArrayToStringVector; |
15 | 17 |
16 namespace device { | 18 namespace device { |
17 | 19 |
18 BluetoothDeviceAndroid* BluetoothDeviceAndroid::Create( | 20 BluetoothDeviceAndroid* BluetoothDeviceAndroid::Create( |
19 BluetoothAdapterAndroid* adapter, | 21 BluetoothAdapterAndroid* adapter, |
20 jobject bluetooth_device_wrapper) { // Java Type: bluetoothDeviceWrapper | 22 jobject bluetooth_device_wrapper) { // Java Type: bluetoothDeviceWrapper |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 return DidFailToConnectGatt(ERROR_AUTH_FAILED); | 216 return DidFailToConnectGatt(ERROR_AUTH_FAILED); |
215 case 0x00000000: // GATT_SUCCESS | 217 case 0x00000000: // GATT_SUCCESS |
216 return DidDisconnectGatt(); | 218 return DidDisconnectGatt(); |
217 default: | 219 default: |
218 VLOG(1) << "Unhandled status: " << status; | 220 VLOG(1) << "Unhandled status: " << status; |
219 return DidFailToConnectGatt(ERROR_UNKNOWN); | 221 return DidFailToConnectGatt(ERROR_UNKNOWN); |
220 } | 222 } |
221 } | 223 } |
222 } | 224 } |
223 | 225 |
| 226 void BluetoothDeviceAndroid::CreateGattRemoteService( |
| 227 JNIEnv* env, |
| 228 jobject caller, |
| 229 int32_t instanceId, |
| 230 jobject bluetooth_gatt_service_wrapper // Java Type: |
| 231 // BluetoothGattServiceWrapper |
| 232 ) { |
| 233 std::string instanceIdString = base::StringPrintf("%d", instanceId); |
| 234 |
| 235 if (gatt_services_.contains(instanceIdString)) |
| 236 return; |
| 237 |
| 238 BluetoothRemoteGattServiceAndroid* service = |
| 239 BluetoothRemoteGattServiceAndroid::Create( |
| 240 GetAdapter(), this, bluetooth_gatt_service_wrapper, instanceIdString); |
| 241 |
| 242 gatt_services_.set(instanceIdString, |
| 243 make_scoped_ptr<BluetoothGattService>(service)); |
| 244 |
| 245 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, GetAdapter()->GetObservers(), |
| 246 GattServiceAdded(adapter_, this, service)); |
| 247 } |
| 248 |
224 BluetoothDeviceAndroid::BluetoothDeviceAndroid(BluetoothAdapterAndroid* adapter) | 249 BluetoothDeviceAndroid::BluetoothDeviceAndroid(BluetoothAdapterAndroid* adapter) |
225 : BluetoothDevice(adapter) {} | 250 : BluetoothDevice(adapter) {} |
226 | 251 |
227 std::string BluetoothDeviceAndroid::GetDeviceName() const { | 252 std::string BluetoothDeviceAndroid::GetDeviceName() const { |
228 return ConvertJavaStringToUTF8(Java_ChromeBluetoothDevice_getDeviceName( | 253 return ConvertJavaStringToUTF8(Java_ChromeBluetoothDevice_getDeviceName( |
229 AttachCurrentThread(), j_device_.obj())); | 254 AttachCurrentThread(), j_device_.obj())); |
230 } | 255 } |
231 | 256 |
232 void BluetoothDeviceAndroid::CreateGattConnectionImpl() { | 257 void BluetoothDeviceAndroid::CreateGattConnectionImpl() { |
233 Java_ChromeBluetoothDevice_createGattConnectionImpl( | 258 Java_ChromeBluetoothDevice_createGattConnectionImpl( |
234 AttachCurrentThread(), j_device_.obj(), | 259 AttachCurrentThread(), j_device_.obj(), |
235 base::android::GetApplicationContext()); | 260 base::android::GetApplicationContext()); |
236 } | 261 } |
237 | 262 |
238 void BluetoothDeviceAndroid::DisconnectGatt() { | 263 void BluetoothDeviceAndroid::DisconnectGatt() { |
239 Java_ChromeBluetoothDevice_disconnectGatt(AttachCurrentThread(), | 264 Java_ChromeBluetoothDevice_disconnectGatt(AttachCurrentThread(), |
240 j_device_.obj()); | 265 j_device_.obj()); |
241 } | 266 } |
242 | 267 |
243 } // namespace device | 268 } // namespace device |
OLD | NEW |