| 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" |
| 11 #include "base/android/jni_string.h" | 11 #include "base/android/jni_string.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
| 14 #include "device/bluetooth/android/wrappers.h" | 14 #include "device/bluetooth/android/wrappers.h" |
| 15 #include "device/bluetooth/bluetooth_adapter_android.h" | 15 #include "device/bluetooth/bluetooth_adapter_android.h" |
| 16 #include "device/bluetooth/bluetooth_device_android.h" | 16 #include "device/bluetooth/bluetooth_device_android.h" |
| 17 #include "device/bluetooth/bluetooth_remote_gatt_characteristic_android.h" | 17 #include "device/bluetooth/bluetooth_remote_gatt_characteristic_android.h" |
| 18 #include "device/bluetooth/bluetooth_remote_gatt_descriptor_android.h" |
| 18 #include "device/bluetooth/bluetooth_remote_gatt_service_android.h" | 19 #include "device/bluetooth/bluetooth_remote_gatt_service_android.h" |
| 19 #include "device/bluetooth/test/test_bluetooth_adapter_observer.h" | 20 #include "device/bluetooth/test/test_bluetooth_adapter_observer.h" |
| 20 #include "jni/Fakes_jni.h" | 21 #include "jni/Fakes_jni.h" |
| 21 | 22 |
| 22 using base::android::AttachCurrentThread; | 23 using base::android::AttachCurrentThread; |
| 23 using base::android::ScopedJavaLocalRef; | 24 using base::android::ScopedJavaLocalRef; |
| 24 | 25 |
| 25 namespace device { | 26 namespace device { |
| 26 | 27 |
| 27 BluetoothTestAndroid::BluetoothTestAndroid() { | 28 BluetoothTestAndroid::BluetoothTestAndroid() { |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 void BluetoothTestAndroid:: | 258 void BluetoothTestAndroid:: |
| 258 SimulateGattCharacteristicWriteWillFailSynchronouslyOnce( | 259 SimulateGattCharacteristicWriteWillFailSynchronouslyOnce( |
| 259 BluetoothGattCharacteristic* characteristic) { | 260 BluetoothGattCharacteristic* characteristic) { |
| 260 BluetoothRemoteGattCharacteristicAndroid* characteristic_android = | 261 BluetoothRemoteGattCharacteristicAndroid* characteristic_android = |
| 261 static_cast<BluetoothRemoteGattCharacteristicAndroid*>(characteristic); | 262 static_cast<BluetoothRemoteGattCharacteristicAndroid*>(characteristic); |
| 262 Java_FakeBluetoothGattCharacteristic_setWriteCharacteristicWillFailSynchronous
lyOnce( | 263 Java_FakeBluetoothGattCharacteristic_setWriteCharacteristicWillFailSynchronous
lyOnce( |
| 263 base::android::AttachCurrentThread(), | 264 base::android::AttachCurrentThread(), |
| 264 characteristic_android->GetJavaObject().obj()); | 265 characteristic_android->GetJavaObject().obj()); |
| 265 } | 266 } |
| 266 | 267 |
| 268 void BluetoothTestAndroid::SimulateGattDescriptor( |
| 269 BluetoothGattCharacteristic* characteristic, |
| 270 const std::string& uuid) { |
| 271 BluetoothRemoteGattCharacteristicAndroid* characteristic_android = |
| 272 static_cast<BluetoothRemoteGattCharacteristicAndroid*>(characteristic); |
| 273 JNIEnv* env = base::android::AttachCurrentThread(); |
| 274 |
| 275 Java_FakeBluetoothGattCharacteristic_addDescriptor( |
| 276 env, characteristic_android->GetJavaObject().obj(), |
| 277 base::android::ConvertUTF8ToJavaString(env, uuid).obj()); |
| 278 } |
| 279 |
| 267 void BluetoothTestAndroid::OnFakeBluetoothDeviceConnectGattCalled( | 280 void BluetoothTestAndroid::OnFakeBluetoothDeviceConnectGattCalled( |
| 268 JNIEnv* env, | 281 JNIEnv* env, |
| 269 const JavaParamRef<jobject>& caller) { | 282 const JavaParamRef<jobject>& caller) { |
| 270 gatt_connection_attempts_++; | 283 gatt_connection_attempts_++; |
| 271 } | 284 } |
| 272 | 285 |
| 273 void BluetoothTestAndroid::OnFakeBluetoothGattDisconnect( | 286 void BluetoothTestAndroid::OnFakeBluetoothGattDisconnect( |
| 274 JNIEnv* env, | 287 JNIEnv* env, |
| 275 const JavaParamRef<jobject>& caller) { | 288 const JavaParamRef<jobject>& caller) { |
| 276 gatt_disconnection_attempts_++; | 289 gatt_disconnection_attempts_++; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 296 | 309 |
| 297 void BluetoothTestAndroid::OnFakeBluetoothGattWriteCharacteristic( | 310 void BluetoothTestAndroid::OnFakeBluetoothGattWriteCharacteristic( |
| 298 JNIEnv* env, | 311 JNIEnv* env, |
| 299 const JavaParamRef<jobject>& caller, | 312 const JavaParamRef<jobject>& caller, |
| 300 const JavaParamRef<jbyteArray>& value) { | 313 const JavaParamRef<jbyteArray>& value) { |
| 301 gatt_write_characteristic_attempts_++; | 314 gatt_write_characteristic_attempts_++; |
| 302 base::android::JavaByteArrayToByteVector(env, value, &last_write_value_); | 315 base::android::JavaByteArrayToByteVector(env, value, &last_write_value_); |
| 303 } | 316 } |
| 304 | 317 |
| 305 } // namespace device | 318 } // namespace device |
| OLD | NEW |