Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(153)

Side by Side Diff: device/bluetooth/test/bluetooth_test_android.cc

Issue 1712593002: bluetooth: android: Confirm the notify session after the descriptor has been written. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address Vincent's comments Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 BluetoothRemoteGattCharacteristicAndroid* characteristic_android = 169 BluetoothRemoteGattCharacteristicAndroid* characteristic_android =
170 static_cast<BluetoothRemoteGattCharacteristicAndroid*>(characteristic); 170 static_cast<BluetoothRemoteGattCharacteristicAndroid*>(characteristic);
171 171
172 Java_FakeBluetoothGattCharacteristic_rememberCharacteristicForSubsequentAction ( 172 Java_FakeBluetoothGattCharacteristic_rememberCharacteristicForSubsequentAction (
173 base::android::AttachCurrentThread(), 173 base::android::AttachCurrentThread(),
174 characteristic_android->GetJavaObject().obj()); 174 characteristic_android->GetJavaObject().obj());
175 } 175 }
176 176
177 void BluetoothTestAndroid::SimulateGattNotifySessionStarted( 177 void BluetoothTestAndroid::SimulateGattNotifySessionStarted(
178 BluetoothGattCharacteristic* characteristic) { 178 BluetoothGattCharacteristic* characteristic) {
179 // Android doesn't provide any sort of callback for when notifications have 179 BluetoothGattDescriptor* descriptor = characteristic->GetDescriptorForUUID(
180 // been enabled. So, just run the message loop to process the success 180 BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid());
181 // callback. 181 BluetoothRemoteGattDescriptorAndroid* descriptor_android =
182 base::RunLoop().RunUntilIdle(); 182 static_cast<BluetoothRemoteGattDescriptorAndroid*>(descriptor);
183 Java_FakeBluetoothGattDescriptor_valueWrite(
184 base::android::AttachCurrentThread(),
185 descriptor_android ? descriptor_android->GetJavaObject().obj() : nullptr,
186 0); // android.bluetooth.BluetoothGatt.GATT_SUCCESS
183 } 187 }
184 188
185 void BluetoothTestAndroid:: 189 void BluetoothTestAndroid::
186 SimulateGattCharacteristicSetNotifyWillFailSynchronouslyOnce( 190 SimulateGattCharacteristicSetNotifyWillFailSynchronouslyOnce(
187 BluetoothGattCharacteristic* characteristic) { 191 BluetoothGattCharacteristic* characteristic) {
188 BluetoothRemoteGattCharacteristicAndroid* characteristic_android = 192 BluetoothRemoteGattCharacteristicAndroid* characteristic_android =
189 static_cast<BluetoothRemoteGattCharacteristicAndroid*>(characteristic); 193 static_cast<BluetoothRemoteGattCharacteristicAndroid*>(characteristic);
190 JNIEnv* env = base::android::AttachCurrentThread(); 194 JNIEnv* env = base::android::AttachCurrentThread();
191 195
192 Java_FakeBluetoothGattCharacteristic_setCharacteristicNotificationWillFailSync hronouslyOnce( 196 Java_FakeBluetoothGattCharacteristic_setCharacteristicNotificationWillFailSync hronouslyOnce(
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 const std::string& uuid) { 288 const std::string& uuid) {
285 BluetoothRemoteGattCharacteristicAndroid* characteristic_android = 289 BluetoothRemoteGattCharacteristicAndroid* characteristic_android =
286 static_cast<BluetoothRemoteGattCharacteristicAndroid*>(characteristic); 290 static_cast<BluetoothRemoteGattCharacteristicAndroid*>(characteristic);
287 JNIEnv* env = base::android::AttachCurrentThread(); 291 JNIEnv* env = base::android::AttachCurrentThread();
288 292
289 Java_FakeBluetoothGattCharacteristic_addDescriptor( 293 Java_FakeBluetoothGattCharacteristic_addDescriptor(
290 env, characteristic_android->GetJavaObject().obj(), 294 env, characteristic_android->GetJavaObject().obj(),
291 base::android::ConvertUTF8ToJavaString(env, uuid).obj()); 295 base::android::ConvertUTF8ToJavaString(env, uuid).obj());
292 } 296 }
293 297
298 void BluetoothTestAndroid::RememberDescriptorForSubsequentAction(
299 BluetoothGattDescriptor* descriptor) {
300 BluetoothRemoteGattDescriptorAndroid* descriptor_android =
301 static_cast<BluetoothRemoteGattDescriptorAndroid*>(descriptor);
302
303 Java_FakeBluetoothGattDescriptor_rememberDescriptorForSubsequentAction(
304 base::android::AttachCurrentThread(),
305 descriptor_android->GetJavaObject().obj());
306 }
307
308 void BluetoothTestAndroid::SimulateGattDescriptorRead(
309 BluetoothGattDescriptor* descriptor,
310 const std::vector<uint8_t>& value) {
311 BluetoothRemoteGattDescriptorAndroid* descriptor_android =
312 static_cast<BluetoothRemoteGattDescriptorAndroid*>(descriptor);
313 JNIEnv* env = base::android::AttachCurrentThread();
314
315 Java_FakeBluetoothGattDescriptor_valueRead(
316 env,
317 descriptor_android ? descriptor_android->GetJavaObject().obj() : nullptr,
318 0, // android.bluetooth.BluetoothGatt.GATT_SUCCESS
319 base::android::ToJavaByteArray(env, value).obj());
320 }
321
322 void BluetoothTestAndroid::SimulateGattDescriptorReadError(
323 BluetoothGattDescriptor* descriptor,
324 BluetoothGattService::GattErrorCode error_code) {
325 BluetoothRemoteGattDescriptorAndroid* descriptor_android =
326 static_cast<BluetoothRemoteGattDescriptorAndroid*>(descriptor);
327 JNIEnv* env = base::android::AttachCurrentThread();
328 std::vector<uint8_t> empty_value;
329
330 Java_FakeBluetoothGattDescriptor_valueRead(
331 env, descriptor_android->GetJavaObject().obj(),
332 BluetoothRemoteGattServiceAndroid::GetAndroidErrorCode(error_code),
333 base::android::ToJavaByteArray(env, empty_value).obj());
334 }
335
336 void BluetoothTestAndroid::SimulateGattDescriptorReadWillFailSynchronouslyOnce(
337 BluetoothGattDescriptor* descriptor) {
338 BluetoothRemoteGattDescriptorAndroid* descriptor_android =
339 static_cast<BluetoothRemoteGattDescriptorAndroid*>(descriptor);
340 JNIEnv* env = base::android::AttachCurrentThread();
341
342 Java_FakeBluetoothGattDescriptor_setReadDescriptorWillFailSynchronouslyOnce(
343 env, descriptor_android->GetJavaObject().obj());
344 }
345
346 void BluetoothTestAndroid::SimulateGattDescriptorWrite(
347 BluetoothGattDescriptor* descriptor) {
348 BluetoothRemoteGattDescriptorAndroid* descriptor_android =
349 static_cast<BluetoothRemoteGattDescriptorAndroid*>(descriptor);
350 Java_FakeBluetoothGattDescriptor_valueWrite(
351 base::android::AttachCurrentThread(),
352 descriptor_android ? descriptor_android->GetJavaObject().obj() : nullptr,
353 0); // android.bluetooth.BluetoothGatt.GATT_SUCCESS
354 }
355
356 void BluetoothTestAndroid::SimulateGattDescriptorWriteError(
357 BluetoothGattDescriptor* descriptor,
358 BluetoothGattService::GattErrorCode error_code) {
359 BluetoothRemoteGattDescriptorAndroid* descriptor_android =
360 static_cast<BluetoothRemoteGattDescriptorAndroid*>(descriptor);
361 Java_FakeBluetoothGattDescriptor_valueWrite(
362 base::android::AttachCurrentThread(),
363 descriptor_android->GetJavaObject().obj(),
364 BluetoothRemoteGattServiceAndroid::GetAndroidErrorCode(error_code));
365 }
366
294 void BluetoothTestAndroid::SimulateGattDescriptorWriteWillFailSynchronouslyOnce( 367 void BluetoothTestAndroid::SimulateGattDescriptorWriteWillFailSynchronouslyOnce(
295 BluetoothGattDescriptor* descriptor) { 368 BluetoothGattDescriptor* descriptor) {
296 BluetoothRemoteGattDescriptorAndroid* descriptor_android = 369 BluetoothRemoteGattDescriptorAndroid* descriptor_android =
297 static_cast<BluetoothRemoteGattDescriptorAndroid*>(descriptor); 370 static_cast<BluetoothRemoteGattDescriptorAndroid*>(descriptor);
298 Java_FakeBluetoothGattDescriptor_setWriteDescriptorWillFailSynchronouslyOnce( 371 Java_FakeBluetoothGattDescriptor_setWriteDescriptorWillFailSynchronouslyOnce(
299 base::android::AttachCurrentThread(), 372 base::android::AttachCurrentThread(),
300 descriptor_android->GetJavaObject().obj()); 373 descriptor_android->GetJavaObject().obj());
301 } 374 }
302 375
303 void BluetoothTestAndroid::OnFakeBluetoothDeviceConnectGattCalled( 376 void BluetoothTestAndroid::OnFakeBluetoothDeviceConnectGattCalled(
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 } 414 }
342 415
343 void BluetoothTestAndroid::OnFakeBluetoothGattWriteCharacteristic( 416 void BluetoothTestAndroid::OnFakeBluetoothGattWriteCharacteristic(
344 JNIEnv* env, 417 JNIEnv* env,
345 const JavaParamRef<jobject>& caller, 418 const JavaParamRef<jobject>& caller,
346 const JavaParamRef<jbyteArray>& value) { 419 const JavaParamRef<jbyteArray>& value) {
347 gatt_write_characteristic_attempts_++; 420 gatt_write_characteristic_attempts_++;
348 base::android::JavaByteArrayToByteVector(env, value, &last_write_value_); 421 base::android::JavaByteArrayToByteVector(env, value, &last_write_value_);
349 } 422 }
350 423
424 void BluetoothTestAndroid::OnFakeBluetoothGattReadDescriptor(
425 JNIEnv* env,
426 const JavaParamRef<jobject>& caller) {
427 gatt_read_descriptor_attempts_++;
428 }
429
351 void BluetoothTestAndroid::OnFakeBluetoothGattWriteDescriptor( 430 void BluetoothTestAndroid::OnFakeBluetoothGattWriteDescriptor(
352 JNIEnv* env, 431 JNIEnv* env,
353 const JavaParamRef<jobject>& caller, 432 const JavaParamRef<jobject>& caller,
354 const JavaParamRef<jbyteArray>& value) { 433 const JavaParamRef<jbyteArray>& value) {
355 gatt_write_descriptor_attempts_++; 434 gatt_write_descriptor_attempts_++;
356 base::android::JavaByteArrayToByteVector(env, value, &last_write_value_); 435 base::android::JavaByteArrayToByteVector(env, value, &last_write_value_);
357 } 436 }
358 437
359 } // namespace device 438 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698