| 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/test/bluetooth_test_android.h" | 5 #include "device/bluetooth/test/bluetooth_test_android.h" |
| 6 | 6 |
| 7 #include <iterator> | 7 #include <iterator> |
| 8 #include <sstream> | 8 #include <sstream> |
| 9 | 9 |
| 10 #include "base/android/jni_array.h" | 10 #include "base/android/jni_array.h" |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 static_cast<BluetoothDeviceAndroid*>(device); | 77 static_cast<BluetoothDeviceAndroid*>(device); |
| 78 | 78 |
| 79 Java_FakeBluetoothDevice_connectionStateChange( | 79 Java_FakeBluetoothDevice_connectionStateChange( |
| 80 AttachCurrentThread(), device_android->GetJavaObject().obj(), | 80 AttachCurrentThread(), device_android->GetJavaObject().obj(), |
| 81 0, // android.bluetooth.BluetoothGatt.GATT_SUCCESS | 81 0, // android.bluetooth.BluetoothGatt.GATT_SUCCESS |
| 82 true); // connected | 82 true); // connected |
| 83 } | 83 } |
| 84 | 84 |
| 85 void BluetoothTestAndroid::SimulateGattConnectionError( | 85 void BluetoothTestAndroid::SimulateGattConnectionError( |
| 86 BluetoothDevice* device, | 86 BluetoothDevice* device, |
| 87 BluetoothDevice::ConnectErrorCode error) { | 87 BluetoothDevice::ConnectErrorCode) { |
| 88 int android_error_value = 0; | |
| 89 switch (error) { // Constants are from android.bluetooth.BluetoothGatt. | |
| 90 case BluetoothDevice::ERROR_ATTRIBUTE_LENGTH_INVALID: | |
| 91 android_error_value = 0x0000000d; // GATT_INVALID_ATTRIBUTE_LENGTH | |
| 92 break; | |
| 93 case BluetoothDevice::ERROR_AUTH_FAILED: | |
| 94 android_error_value = 0x00000005; // GATT_INSUFFICIENT_AUTHENTICATION | |
| 95 break; | |
| 96 case BluetoothDevice::ERROR_CONNECTION_CONGESTED: | |
| 97 android_error_value = 0x0000008f; // GATT_CONNECTION_CONGESTED | |
| 98 break; | |
| 99 case BluetoothDevice::ERROR_FAILED: | |
| 100 android_error_value = 0x00000101; // GATT_FAILURE | |
| 101 break; | |
| 102 case BluetoothDevice::ERROR_INSUFFICIENT_ENCRYPTION: | |
| 103 android_error_value = 0x0000000f; // GATT_INSUFFICIENT_ENCRYPTION | |
| 104 break; | |
| 105 case BluetoothDevice::ERROR_OFFSET_INVALID: | |
| 106 android_error_value = 0x00000007; // GATT_INVALID_OFFSET | |
| 107 break; | |
| 108 case BluetoothDevice::ERROR_READ_NOT_PERMITTED: | |
| 109 android_error_value = 0x00000002; // GATT_READ_NOT_PERMITTED | |
| 110 break; | |
| 111 case BluetoothDevice::ERROR_REQUEST_NOT_SUPPORTED: | |
| 112 android_error_value = 0x00000006; // GATT_REQUEST_NOT_SUPPORTED | |
| 113 break; | |
| 114 case BluetoothDevice::ERROR_WRITE_NOT_PERMITTED: | |
| 115 android_error_value = 0x00000003; // GATT_WRITE_NOT_PERMITTED | |
| 116 break; | |
| 117 case BluetoothDevice::ERROR_AUTH_CANCELED: | |
| 118 case BluetoothDevice::ERROR_AUTH_REJECTED: | |
| 119 case BluetoothDevice::ERROR_AUTH_TIMEOUT: | |
| 120 case BluetoothDevice::ERROR_INPROGRESS: | |
| 121 case BluetoothDevice::ERROR_UNKNOWN: | |
| 122 case BluetoothDevice::ERROR_UNSUPPORTED_DEVICE: | |
| 123 case BluetoothDevice::NUM_CONNECT_ERROR_CODES: | |
| 124 NOTREACHED() << "No translation for error code: " << error; | |
| 125 } | |
| 126 | |
| 127 BluetoothDeviceAndroid* device_android = | 88 BluetoothDeviceAndroid* device_android = |
| 128 static_cast<BluetoothDeviceAndroid*>(device); | 89 static_cast<BluetoothDeviceAndroid*>(device); |
| 129 | 90 |
| 130 Java_FakeBluetoothDevice_connectionStateChange( | 91 Java_FakeBluetoothDevice_connectionStateChange( |
| 131 AttachCurrentThread(), device_android->GetJavaObject().obj(), | 92 AttachCurrentThread(), device_android->GetJavaObject().obj(), |
| 132 android_error_value, | 93 // TODO(ortuno): Add all types of errors Android can produce. For now we |
| 94 // just return a timeout error. |
| 95 // http://crbug.com/578191 |
| 96 0x08, // Connection Timeout from Bluetooth Spec. |
| 133 false); // connected | 97 false); // connected |
| 134 } | 98 } |
| 135 | 99 |
| 136 void BluetoothTestAndroid::SimulateGattDisconnection(BluetoothDevice* device) { | 100 void BluetoothTestAndroid::SimulateGattDisconnection(BluetoothDevice* device) { |
| 137 BluetoothDeviceAndroid* device_android = | 101 BluetoothDeviceAndroid* device_android = |
| 138 static_cast<BluetoothDeviceAndroid*>(device); | 102 static_cast<BluetoothDeviceAndroid*>(device); |
| 139 | 103 |
| 140 Java_FakeBluetoothDevice_connectionStateChange( | 104 Java_FakeBluetoothDevice_connectionStateChange( |
| 141 AttachCurrentThread(), device_android->GetJavaObject().obj(), | 105 AttachCurrentThread(), device_android->GetJavaObject().obj(), |
| 142 0, // android.bluetooth.BluetoothGatt.GATT_SUCCESS | 106 0x13, // Connection terminate by peer user from Bluetooth Spec. |
| 143 false); // disconnected | 107 false); // disconnected |
| 144 } | 108 } |
| 145 | 109 |
| 146 void BluetoothTestAndroid::SimulateGattServicesDiscovered( | 110 void BluetoothTestAndroid::SimulateGattServicesDiscovered( |
| 147 BluetoothDevice* device, | 111 BluetoothDevice* device, |
| 148 const std::vector<std::string>& uuids) { | 112 const std::vector<std::string>& uuids) { |
| 149 BluetoothDeviceAndroid* device_android = | 113 BluetoothDeviceAndroid* device_android = |
| 150 static_cast<BluetoothDeviceAndroid*>(device); | 114 static_cast<BluetoothDeviceAndroid*>(device); |
| 151 JNIEnv* env = base::android::AttachCurrentThread(); | 115 JNIEnv* env = base::android::AttachCurrentThread(); |
| 152 | 116 |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 | 326 |
| 363 void BluetoothTestAndroid::OnFakeBluetoothGattWriteDescriptor( | 327 void BluetoothTestAndroid::OnFakeBluetoothGattWriteDescriptor( |
| 364 JNIEnv* env, | 328 JNIEnv* env, |
| 365 const JavaParamRef<jobject>& caller, | 329 const JavaParamRef<jobject>& caller, |
| 366 const JavaParamRef<jbyteArray>& value) { | 330 const JavaParamRef<jbyteArray>& value) { |
| 367 gatt_write_descriptor_attempts_++; | 331 gatt_write_descriptor_attempts_++; |
| 368 base::android::JavaByteArrayToByteVector(env, value, &last_write_value_); | 332 base::android::JavaByteArrayToByteVector(env, value, &last_write_value_); |
| 369 } | 333 } |
| 370 | 334 |
| 371 } // namespace device | 335 } // namespace device |
| OLD | NEW |