| 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 "device/bluetooth/android/wrappers.h" | 14 #include "device/bluetooth/android/wrappers.h" |
| 14 #include "device/bluetooth/bluetooth_adapter_android.h" | 15 #include "device/bluetooth/bluetooth_adapter_android.h" |
| 15 #include "device/bluetooth/bluetooth_device_android.h" | 16 #include "device/bluetooth/bluetooth_device_android.h" |
| 16 #include "device/bluetooth/bluetooth_remote_gatt_characteristic_android.h" | 17 #include "device/bluetooth/bluetooth_remote_gatt_characteristic_android.h" |
| 17 #include "device/bluetooth/bluetooth_remote_gatt_service_android.h" | 18 #include "device/bluetooth/bluetooth_remote_gatt_service_android.h" |
| 18 #include "device/bluetooth/test/test_bluetooth_adapter_observer.h" | 19 #include "device/bluetooth/test/test_bluetooth_adapter_observer.h" |
| 19 #include "jni/Fakes_jni.h" | 20 #include "jni/Fakes_jni.h" |
| 20 | 21 |
| 21 using base::android::AttachCurrentThread; | 22 using base::android::AttachCurrentThread; |
| 22 using base::android::ScopedJavaLocalRef; | 23 using base::android::ScopedJavaLocalRef; |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 int properties) { | 150 int properties) { |
| 150 BluetoothRemoteGattServiceAndroid* service_android = | 151 BluetoothRemoteGattServiceAndroid* service_android = |
| 151 static_cast<BluetoothRemoteGattServiceAndroid*>(service); | 152 static_cast<BluetoothRemoteGattServiceAndroid*>(service); |
| 152 JNIEnv* env = base::android::AttachCurrentThread(); | 153 JNIEnv* env = base::android::AttachCurrentThread(); |
| 153 | 154 |
| 154 Java_FakeBluetoothGattService_addCharacteristic( | 155 Java_FakeBluetoothGattService_addCharacteristic( |
| 155 env, service_android->GetJavaObject().obj(), | 156 env, service_android->GetJavaObject().obj(), |
| 156 base::android::ConvertUTF8ToJavaString(env, uuid).obj(), properties); | 157 base::android::ConvertUTF8ToJavaString(env, uuid).obj(), properties); |
| 157 } | 158 } |
| 158 | 159 |
| 160 void BluetoothTestAndroid::SimulateGattNotifySessionStarted( |
| 161 BluetoothGattCharacteristic* characteristic) { |
| 162 // Android doesn't provide any sort of callback for when notifications have |
| 163 // been enabled. So, just run the message loop to process the success |
| 164 // callback. |
| 165 base::RunLoop().RunUntilIdle(); |
| 166 } |
| 167 |
| 168 void BluetoothTestAndroid:: |
| 169 SimulateGattCharacteristicSetNotifyWillFailSynchronouslyOnce( |
| 170 BluetoothGattCharacteristic* characteristic) { |
| 171 BluetoothRemoteGattCharacteristicAndroid* characteristic_android = |
| 172 static_cast<BluetoothRemoteGattCharacteristicAndroid*>(characteristic); |
| 173 JNIEnv* env = base::android::AttachCurrentThread(); |
| 174 |
| 175 Java_FakeBluetoothGattCharacteristic_setCharacteristicNotificationWillFailSync
hronouslyOnce( |
| 176 env, characteristic_android->GetJavaObject().obj()); |
| 177 } |
| 178 |
| 159 void BluetoothTestAndroid::SimulateGattCharacteristicRead( | 179 void BluetoothTestAndroid::SimulateGattCharacteristicRead( |
| 160 BluetoothGattCharacteristic* characteristic, | 180 BluetoothGattCharacteristic* characteristic, |
| 161 const std::vector<uint8>& value) { | 181 const std::vector<uint8>& value) { |
| 162 BluetoothRemoteGattCharacteristicAndroid* characteristic_android = | 182 BluetoothRemoteGattCharacteristicAndroid* characteristic_android = |
| 163 static_cast<BluetoothRemoteGattCharacteristicAndroid*>(characteristic); | 183 static_cast<BluetoothRemoteGattCharacteristicAndroid*>(characteristic); |
| 164 JNIEnv* env = base::android::AttachCurrentThread(); | 184 JNIEnv* env = base::android::AttachCurrentThread(); |
| 165 | 185 |
| 166 Java_FakeBluetoothGattCharacteristic_valueRead( | 186 Java_FakeBluetoothGattCharacteristic_valueRead( |
| 167 env, characteristic_android->GetJavaObject().obj(), | 187 env, characteristic_android->GetJavaObject().obj(), |
| 168 0, // android.bluetooth.BluetoothGatt.GATT_SUCCESS | 188 0, // android.bluetooth.BluetoothGatt.GATT_SUCCESS |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 void BluetoothTestAndroid::OnFakeBluetoothGattDisconnect(JNIEnv* env, | 254 void BluetoothTestAndroid::OnFakeBluetoothGattDisconnect(JNIEnv* env, |
| 235 jobject caller) { | 255 jobject caller) { |
| 236 gatt_disconnection_attempts_++; | 256 gatt_disconnection_attempts_++; |
| 237 } | 257 } |
| 238 | 258 |
| 239 void BluetoothTestAndroid::OnFakeBluetoothGattDiscoverServices(JNIEnv* env, | 259 void BluetoothTestAndroid::OnFakeBluetoothGattDiscoverServices(JNIEnv* env, |
| 240 jobject caller) { | 260 jobject caller) { |
| 241 gatt_discovery_attempts_++; | 261 gatt_discovery_attempts_++; |
| 242 } | 262 } |
| 243 | 263 |
| 264 void BluetoothTestAndroid::OnFakeBluetoothGattSetCharacteristicNotification( |
| 265 JNIEnv* env, |
| 266 jobject caller) { |
| 267 gatt_notify_characteristic_attempts_++; |
| 268 } |
| 269 |
| 244 void BluetoothTestAndroid::OnFakeBluetoothGattReadCharacteristic( | 270 void BluetoothTestAndroid::OnFakeBluetoothGattReadCharacteristic( |
| 245 JNIEnv* env, | 271 JNIEnv* env, |
| 246 jobject caller) { | 272 jobject caller) { |
| 247 gatt_read_characteristic_attempts_++; | 273 gatt_read_characteristic_attempts_++; |
| 248 } | 274 } |
| 249 | 275 |
| 250 void BluetoothTestAndroid::OnFakeBluetoothGattWriteCharacteristic( | 276 void BluetoothTestAndroid::OnFakeBluetoothGattWriteCharacteristic( |
| 251 JNIEnv* env, | 277 JNIEnv* env, |
| 252 jobject caller, | 278 jobject caller, |
| 253 jbyteArray value) { | 279 jbyteArray value) { |
| 254 gatt_write_characteristic_attempts_++; | 280 gatt_write_characteristic_attempts_++; |
| 255 base::android::JavaByteArrayToByteVector(env, value, &last_write_value_); | 281 base::android::JavaByteArrayToByteVector(env, value, &last_write_value_); |
| 256 } | 282 } |
| 257 | 283 |
| 258 } // namespace device | 284 } // namespace device |
| OLD | NEW |