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/context_utils.h" | 7 #include "base/android/context_utils.h" |
8 #include "base/android/jni_android.h" | 8 #include "base/android/jni_android.h" |
9 #include "base/android/jni_string.h" | 9 #include "base/android/jni_string.h" |
10 #include "base/metrics/sparse_histogram.h" | 10 #include "base/metrics/sparse_histogram.h" |
11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
12 #include "device/bluetooth/bluetooth_adapter_android.h" | 12 #include "device/bluetooth/bluetooth_adapter_android.h" |
13 #include "device/bluetooth/bluetooth_remote_gatt_service_android.h" | 13 #include "device/bluetooth/bluetooth_remote_gatt_service_android.h" |
14 #include "jni/ChromeBluetoothDevice_jni.h" | 14 #include "jni/ChromeBluetoothDevice_jni.h" |
15 | 15 |
16 using base::android::AttachCurrentThread; | 16 using base::android::AttachCurrentThread; |
17 using base::android::JavaParamRef; | 17 using base::android::JavaParamRef; |
| 18 using base::android::JavaRef; |
18 | 19 |
19 namespace device { | 20 namespace device { |
20 namespace { | 21 namespace { |
21 void RecordConnectionSuccessResult(int32_t status) { | 22 void RecordConnectionSuccessResult(int32_t status) { |
22 UMA_HISTOGRAM_SPARSE_SLOWLY("Bluetooth.Android.GATTConnection.Success.Result", | 23 UMA_HISTOGRAM_SPARSE_SLOWLY("Bluetooth.Android.GATTConnection.Success.Result", |
23 status); | 24 status); |
24 } | 25 } |
25 void RecordConnectionFailureResult(int32_t status) { | 26 void RecordConnectionFailureResult(int32_t status) { |
26 UMA_HISTOGRAM_SPARSE_SLOWLY("Bluetooth.Android.GATTConnection.Failure.Result", | 27 UMA_HISTOGRAM_SPARSE_SLOWLY("Bluetooth.Android.GATTConnection.Failure.Result", |
27 status); | 28 status); |
28 } | 29 } |
29 void RecordConnectionTerminatedResult(int32_t status) { | 30 void RecordConnectionTerminatedResult(int32_t status) { |
30 UMA_HISTOGRAM_SPARSE_SLOWLY( | 31 UMA_HISTOGRAM_SPARSE_SLOWLY( |
31 "Bluetooth.Android.GATTConnection.Disconnected.Result", status); | 32 "Bluetooth.Android.GATTConnection.Disconnected.Result", status); |
32 } | 33 } |
33 } // namespace | 34 } // namespace |
34 | 35 |
35 BluetoothDeviceAndroid* BluetoothDeviceAndroid::Create( | 36 BluetoothDeviceAndroid* BluetoothDeviceAndroid::Create( |
36 BluetoothAdapterAndroid* adapter, | 37 BluetoothAdapterAndroid* adapter, |
37 jobject bluetooth_device_wrapper) { // Java Type: bluetoothDeviceWrapper | 38 const JavaRef<jobject>& |
| 39 bluetooth_device_wrapper) { // Java Type: bluetoothDeviceWrapper |
38 BluetoothDeviceAndroid* device = new BluetoothDeviceAndroid(adapter); | 40 BluetoothDeviceAndroid* device = new BluetoothDeviceAndroid(adapter); |
39 | 41 |
40 device->j_device_.Reset(Java_ChromeBluetoothDevice_create( | 42 device->j_device_.Reset(Java_ChromeBluetoothDevice_create( |
41 AttachCurrentThread(), reinterpret_cast<intptr_t>(device), | 43 AttachCurrentThread(), reinterpret_cast<intptr_t>(device), |
42 bluetooth_device_wrapper)); | 44 bluetooth_device_wrapper)); |
43 | 45 |
44 return device; | 46 return device; |
45 } | 47 } |
46 | 48 |
47 BluetoothDeviceAndroid::~BluetoothDeviceAndroid() { | 49 BluetoothDeviceAndroid::~BluetoothDeviceAndroid() { |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 base::android::ConvertJavaStringToUTF8(env, instance_id); | 247 base::android::ConvertJavaStringToUTF8(env, instance_id); |
246 | 248 |
247 if (gatt_services_.contains(instance_id_string)) | 249 if (gatt_services_.contains(instance_id_string)) |
248 return; | 250 return; |
249 | 251 |
250 BluetoothDevice::GattServiceMap::iterator service_iterator = | 252 BluetoothDevice::GattServiceMap::iterator service_iterator = |
251 gatt_services_.set( | 253 gatt_services_.set( |
252 instance_id_string, | 254 instance_id_string, |
253 BluetoothRemoteGattServiceAndroid::Create( | 255 BluetoothRemoteGattServiceAndroid::Create( |
254 GetAndroidAdapter(), this, bluetooth_gatt_service_wrapper, | 256 GetAndroidAdapter(), this, bluetooth_gatt_service_wrapper, |
255 instance_id_string, j_device_.obj())); | 257 instance_id_string, j_device_)); |
256 | 258 |
257 adapter_->NotifyGattServiceAdded(service_iterator->second); | 259 adapter_->NotifyGattServiceAdded(service_iterator->second); |
258 } | 260 } |
259 | 261 |
260 BluetoothDeviceAndroid::BluetoothDeviceAndroid(BluetoothAdapterAndroid* adapter) | 262 BluetoothDeviceAndroid::BluetoothDeviceAndroid(BluetoothAdapterAndroid* adapter) |
261 : BluetoothDevice(adapter) {} | 263 : BluetoothDevice(adapter) {} |
262 | 264 |
263 void BluetoothDeviceAndroid::CreateGattConnectionImpl() { | 265 void BluetoothDeviceAndroid::CreateGattConnectionImpl() { |
264 Java_ChromeBluetoothDevice_createGattConnectionImpl( | 266 Java_ChromeBluetoothDevice_createGattConnectionImpl( |
265 AttachCurrentThread(), j_device_, base::android::GetApplicationContext()); | 267 AttachCurrentThread(), j_device_, base::android::GetApplicationContext()); |
266 } | 268 } |
267 | 269 |
268 void BluetoothDeviceAndroid::DisconnectGatt() { | 270 void BluetoothDeviceAndroid::DisconnectGatt() { |
269 Java_ChromeBluetoothDevice_disconnectGatt(AttachCurrentThread(), j_device_); | 271 Java_ChromeBluetoothDevice_disconnectGatt(AttachCurrentThread(), j_device_); |
270 } | 272 } |
271 | 273 |
272 } // namespace device | 274 } // namespace device |
OLD | NEW |