Chromium Code Reviews| 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 "base/strings/stringprintf.h" |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 201 } | 201 } |
| 202 | 202 |
| 203 void BluetoothDeviceAndroid::OnConnectionStateChange(JNIEnv* env, | 203 void BluetoothDeviceAndroid::OnConnectionStateChange(JNIEnv* env, |
| 204 jobject jcaller, | 204 jobject jcaller, |
| 205 int32_t status, | 205 int32_t status, |
| 206 bool connected) { | 206 bool connected) { |
| 207 gatt_connected_ = connected; | 207 gatt_connected_ = connected; |
| 208 if (gatt_connected_) { | 208 if (gatt_connected_) { |
| 209 DidConnectGatt(); | 209 DidConnectGatt(); |
| 210 } else { | 210 } else { |
| 211 // TODO(scheib) Create new BluetoothDevice::ConnectErrorCode enums for | |
| 212 // android values not yet represented. http://crbug.com/531058 | |
| 213 switch (status) { // Constants are from android.bluetooth.BluetoothGatt. | 211 switch (status) { // Constants are from android.bluetooth.BluetoothGatt. |
| 212 case 0x0000008f: // GATT_CONNECTION_CONGESTED | |
| 213 return DidFailToConnectGatt(ERROR_CONNECTION_CONGESTED); | |
| 214 case 0x00000101: // GATT_FAILURE | 214 case 0x00000101: // GATT_FAILURE |
| 215 return DidFailToConnectGatt(ERROR_FAILED); | 215 return DidFailToConnectGatt(ERROR_FAILED); |
| 216 case 0x00000005: // GATT_INSUFFICIENT_AUTHENTICATION | 216 case 0x00000005: // GATT_INSUFFICIENT_AUTHENTICATION |
| 217 return DidFailToConnectGatt(ERROR_AUTH_FAILED); | 217 return DidFailToConnectGatt(ERROR_AUTH_FAILED); |
| 218 case 0x0000000f: // GATT_INSUFFICIENT_ENCRYPTION | |
| 219 return DidFailToConnectGatt(ERROR_INSUFFICIENT_ENCRYPTION); | |
| 220 case 0x0000000d: // GATT_INVALID_ATTRIBUTE_LENGTH | |
| 221 return DidFailToConnectGatt(ERROR_ATTRIBUTE_LENGTH_INVALID); | |
| 222 case 0x00000007: // GATT_INVALID_OFFSET | |
| 223 return DidFailToConnectGatt(ERROR_OFFSET_INVALID); | |
| 224 case 0x00000002: // GATT_READ_NOT_PERMITTED | |
| 225 return DidFailToConnectGatt(ERROR_READ_FAILED); | |
| 226 case 0x00000006: // GATT_REQUEST_NOT_SUPPORTED | |
| 227 return DidFailToConnectGatt(ERROR_REQUEST_NOT_SUPPORTED); | |
| 218 case 0x00000000: // GATT_SUCCESS | 228 case 0x00000000: // GATT_SUCCESS |
| 219 return DidDisconnectGatt(); | 229 return DidDisconnectGatt(); |
| 230 case 0x00000003: // GATT_WRITE_NOT_PERMITTED | |
| 231 return DidFailToConnectGatt(ERROR_WRITE_FAILED); | |
|
Kai Jiang
2015/11/29 10:40:51
ERROR_WRITE_NOT_PERMITTED
| |
| 220 default: | 232 default: |
| 221 VLOG(1) << "Unhandled status: " << status; | 233 VLOG(1) << "Unhandled status: " << status; |
| 222 return DidFailToConnectGatt(ERROR_UNKNOWN); | 234 return DidFailToConnectGatt(ERROR_UNKNOWN); |
| 223 } | 235 } |
| 224 } | 236 } |
| 225 } | 237 } |
| 226 | 238 |
| 227 void BluetoothDeviceAndroid::OnGattServicesDiscovered(JNIEnv* env, | 239 void BluetoothDeviceAndroid::OnGattServicesDiscovered(JNIEnv* env, |
| 228 jobject jcaller) { | 240 jobject jcaller) { |
| 229 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, GetAdapter()->GetObservers(), | 241 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, GetAdapter()->GetObservers(), |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 264 AttachCurrentThread(), j_device_.obj(), | 276 AttachCurrentThread(), j_device_.obj(), |
| 265 base::android::GetApplicationContext()); | 277 base::android::GetApplicationContext()); |
| 266 } | 278 } |
| 267 | 279 |
| 268 void BluetoothDeviceAndroid::DisconnectGatt() { | 280 void BluetoothDeviceAndroid::DisconnectGatt() { |
| 269 Java_ChromeBluetoothDevice_disconnectGatt(AttachCurrentThread(), | 281 Java_ChromeBluetoothDevice_disconnectGatt(AttachCurrentThread(), |
| 270 j_device_.obj()); | 282 j_device_.obj()); |
| 271 } | 283 } |
| 272 | 284 |
| 273 } // namespace device | 285 } // namespace device |
| OLD | NEW |