Index: device/bluetooth/test/bluetooth_test_android.cc |
diff --git a/device/bluetooth/test/bluetooth_test_android.cc b/device/bluetooth/test/bluetooth_test_android.cc |
index 1be588d51643d5559b18d5462e5313ab4ad5ba27..c215f11ede98aaa47971b179871bcea912760ac5 100644 |
--- a/device/bluetooth/test/bluetooth_test_android.cc |
+++ b/device/bluetooth/test/bluetooth_test_android.cc |
@@ -7,6 +7,7 @@ |
#include "base/logging.h" |
#include "device/bluetooth/android/wrappers.h" |
#include "device/bluetooth/bluetooth_adapter_android.h" |
+#include "device/bluetooth/bluetooth_device_android.h" |
#include "jni/Fakes_jni.h" |
using base::android::AttachCurrentThread; |
@@ -52,4 +53,53 @@ void BluetoothTestAndroid::DiscoverLowEnergyDevice(int device_ordinal) { |
AttachCurrentThread(), j_fake_bluetooth_adapter_.obj(), device_ordinal); |
} |
+void BluetoothTestAndroid::CompleteGattConnection(BluetoothDevice* device) { |
+ BluetoothDeviceAndroid* device_android = |
+ static_cast<BluetoothDeviceAndroid*>(device); |
+ |
+ Java_FakeBluetoothDevice_connectionStateChange( |
+ AttachCurrentThread(), device_android->GetJavaObject().obj(), |
+ 0, // android.bluetooth.BluetoothGatt.GATT_SUCCESS |
+ true); // connected |
+} |
+ |
+void BluetoothTestAndroid::FailGattConnection( |
+ BluetoothDevice* device, |
+ BluetoothDevice::ConnectErrorCode error) { |
+ int android_error_value = 0; |
+ switch (error) { // Constants are from android.bluetooth.BluetoothGatt. |
+ case BluetoothDevice::ERROR_FAILED: |
+ android_error_value = 0x00000101; // GATT_FAILURE |
+ break; |
+ case BluetoothDevice::ERROR_AUTH_FAILED: |
+ android_error_value = 0x00000005; // GATT_INSUFFICIENT_AUTHENTICATION |
+ break; |
+ case BluetoothDevice::ERROR_UNKNOWN: |
+ case BluetoothDevice::ERROR_INPROGRESS: |
+ case BluetoothDevice::ERROR_AUTH_CANCELED: |
+ case BluetoothDevice::ERROR_AUTH_REJECTED: |
+ case BluetoothDevice::ERROR_AUTH_TIMEOUT: |
+ case BluetoothDevice::ERROR_UNSUPPORTED_DEVICE: |
+ NOTREACHED() << "No translation for error code: " << error; |
+ } |
+ |
+ BluetoothDeviceAndroid* device_android = |
+ static_cast<BluetoothDeviceAndroid*>(device); |
+ |
+ Java_FakeBluetoothDevice_connectionStateChange( |
+ AttachCurrentThread(), device_android->GetJavaObject().obj(), |
+ android_error_value, |
+ false); // connected |
+} |
+ |
+void BluetoothTestAndroid::CompleteGattDisconnection(BluetoothDevice* device) { |
+ BluetoothDeviceAndroid* device_android = |
+ static_cast<BluetoothDeviceAndroid*>(device); |
+ |
+ Java_FakeBluetoothDevice_connectionStateChange( |
+ AttachCurrentThread(), device_android->GetJavaObject().obj(), |
+ 0, // android.bluetooth.BluetoothGatt.GATT_SUCCESS |
+ false); // disconnected |
+} |
+ |
} // namespace device |