| 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_array.h" | 9 #include "base/android/jni_array.h" |
| 10 #include "base/android/jni_string.h" | 10 #include "base/android/jni_string.h" |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 | 203 |
| 204 void BluetoothDeviceAndroid::OnConnectionStateChange( | 204 void BluetoothDeviceAndroid::OnConnectionStateChange( |
| 205 JNIEnv* env, | 205 JNIEnv* env, |
| 206 const JavaParamRef<jobject>& jcaller, | 206 const JavaParamRef<jobject>& jcaller, |
| 207 int32_t status, | 207 int32_t status, |
| 208 bool connected) { | 208 bool connected) { |
| 209 gatt_connected_ = connected; | 209 gatt_connected_ = connected; |
| 210 if (gatt_connected_) { | 210 if (gatt_connected_) { |
| 211 DidConnectGatt(); | 211 DidConnectGatt(); |
| 212 } else { | 212 } else { |
| 213 // TODO(scheib) Create new BluetoothDevice::ConnectErrorCode enums for | |
| 214 // android values not yet represented. http://crbug.com/531058 | |
| 215 switch (status) { // Constants are from android.bluetooth.BluetoothGatt. | 213 switch (status) { // Constants are from android.bluetooth.BluetoothGatt. |
| 214 case 0x0000008f: // GATT_CONNECTION_CONGESTED |
| 215 return DidFailToConnectGatt(ERROR_CONNECTION_CONGESTED); |
| 216 case 0x00000101: // GATT_FAILURE | 216 case 0x00000101: // GATT_FAILURE |
| 217 return DidFailToConnectGatt(ERROR_FAILED); | 217 return DidFailToConnectGatt(ERROR_FAILED); |
| 218 case 0x00000005: // GATT_INSUFFICIENT_AUTHENTICATION | 218 case 0x00000005: // GATT_INSUFFICIENT_AUTHENTICATION |
| 219 return DidFailToConnectGatt(ERROR_AUTH_FAILED); | 219 return DidFailToConnectGatt(ERROR_AUTH_FAILED); |
| 220 case 0x0000000f: // GATT_INSUFFICIENT_ENCRYPTION |
| 221 return DidFailToConnectGatt(ERROR_INSUFFICIENT_ENCRYPTION); |
| 222 case 0x0000000d: // GATT_INVALID_ATTRIBUTE_LENGTH |
| 223 return DidFailToConnectGatt(ERROR_ATTRIBUTE_LENGTH_INVALID); |
| 224 case 0x00000007: // GATT_INVALID_OFFSET |
| 225 return DidFailToConnectGatt(ERROR_OFFSET_INVALID); |
| 226 case 0x00000002: // GATT_READ_NOT_PERMITTED |
| 227 return DidFailToConnectGatt(ERROR_READ_NOT_PERMITTED); |
| 228 case 0x00000006: // GATT_REQUEST_NOT_SUPPORTED |
| 229 return DidFailToConnectGatt(ERROR_REQUEST_NOT_SUPPORTED); |
| 220 case 0x00000000: // GATT_SUCCESS | 230 case 0x00000000: // GATT_SUCCESS |
| 221 return DidDisconnectGatt(); | 231 return DidDisconnectGatt(); |
| 232 case 0x00000003: // GATT_WRITE_NOT_PERMITTED |
| 233 return DidFailToConnectGatt(ERROR_WRITE_NOT_PERMITTED); |
| 222 default: | 234 default: |
| 223 VLOG(1) << "Unhandled status: " << status; | 235 VLOG(1) << "Unhandled status: " << status; |
| 224 return DidFailToConnectGatt(ERROR_UNKNOWN); | 236 return DidFailToConnectGatt(ERROR_UNKNOWN); |
| 225 } | 237 } |
| 226 } | 238 } |
| 227 } | 239 } |
| 228 | 240 |
| 229 void BluetoothDeviceAndroid::OnGattServicesDiscovered( | 241 void BluetoothDeviceAndroid::OnGattServicesDiscovered( |
| 230 JNIEnv* env, | 242 JNIEnv* env, |
| 231 const JavaParamRef<jobject>& jcaller) { | 243 const JavaParamRef<jobject>& jcaller) { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 AttachCurrentThread(), j_device_.obj(), | 280 AttachCurrentThread(), j_device_.obj(), |
| 269 base::android::GetApplicationContext()); | 281 base::android::GetApplicationContext()); |
| 270 } | 282 } |
| 271 | 283 |
| 272 void BluetoothDeviceAndroid::DisconnectGatt() { | 284 void BluetoothDeviceAndroid::DisconnectGatt() { |
| 273 Java_ChromeBluetoothDevice_disconnectGatt(AttachCurrentThread(), | 285 Java_ChromeBluetoothDevice_disconnectGatt(AttachCurrentThread(), |
| 274 j_device_.obj()); | 286 j_device_.obj()); |
| 275 } | 287 } |
| 276 | 288 |
| 277 } // namespace device | 289 } // namespace device |
| OLD | NEW |