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

Side by Side Diff: device/bluetooth/android/java/src/org/chromium/device/bluetooth/Wrappers.java

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 package org.chromium.device.bluetooth; 5 package org.chromium.device.bluetooth;
6 6
7 import android.Manifest; 7 import android.Manifest;
8 import android.annotation.TargetApi; 8 import android.annotation.TargetApi;
9 import android.bluetooth.BluetoothAdapter; 9 import android.bluetooth.BluetoothAdapter;
10 import android.bluetooth.BluetoothDevice; 10 import android.bluetooth.BluetoothDevice;
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 347
348 boolean setCharacteristicNotification( 348 boolean setCharacteristicNotification(
349 BluetoothGattCharacteristicWrapper characteristic, boolean enabl e) { 349 BluetoothGattCharacteristicWrapper characteristic, boolean enabl e) {
350 return mGatt.setCharacteristicNotification(characteristic.mCharacter istic, enable); 350 return mGatt.setCharacteristicNotification(characteristic.mCharacter istic, enable);
351 } 351 }
352 352
353 boolean writeCharacteristic(BluetoothGattCharacteristicWrapper character istic) { 353 boolean writeCharacteristic(BluetoothGattCharacteristicWrapper character istic) {
354 return mGatt.writeCharacteristic(characteristic.mCharacteristic); 354 return mGatt.writeCharacteristic(characteristic.mCharacteristic);
355 } 355 }
356 356
357 boolean readDescriptor(BluetoothGattDescriptorWrapper descriptor) {
358 return mGatt.readDescriptor(descriptor.mDescriptor);
359 }
360
357 boolean writeDescriptor(BluetoothGattDescriptorWrapper descriptor) { 361 boolean writeDescriptor(BluetoothGattDescriptorWrapper descriptor) {
358 return mGatt.writeDescriptor(descriptor.mDescriptor); 362 return mGatt.writeDescriptor(descriptor.mDescriptor);
359 } 363 }
360 } 364 }
361 365
362 /** 366 /**
363 * Implements android.bluetooth.BluetoothGattCallback and forwards calls thr ough 367 * Implements android.bluetooth.BluetoothGattCallback and forwards calls thr ough
364 * to a provided BluetoothGattCallbackWrapper instance. 368 * to a provided BluetoothGattCallbackWrapper instance.
365 * 369 *
366 * This class is required so that Fakes can use BluetoothGattCallbackWrapper 370 * This class is required so that Fakes can use BluetoothGattCallbackWrapper
(...skipping 26 matching lines...) Expand all
393 } 397 }
394 398
395 @Override 399 @Override
396 public void onCharacteristicWrite( 400 public void onCharacteristicWrite(
397 BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) { 401 BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
398 mWrapperCallback.onCharacteristicWrite( 402 mWrapperCallback.onCharacteristicWrite(
399 mDeviceWrapper.mCharacteristicsToWrappers.get(characteristic ), status); 403 mDeviceWrapper.mCharacteristicsToWrappers.get(characteristic ), status);
400 } 404 }
401 405
402 @Override 406 @Override
407 public void onDescriptorRead(
408 BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int stat us) {
409 mWrapperCallback.onDescriptorRead(
410 mDeviceWrapper.mDescriptorsToWrappers.get(descriptor), statu s);
411 }
412
413 @Override
414 public void onDescriptorWrite(
415 BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int stat us) {
416 mWrapperCallback.onDescriptorWrite(
417 mDeviceWrapper.mDescriptorsToWrappers.get(descriptor), statu s);
418 }
419
420 @Override
403 public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) { 421 public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
404 mWrapperCallback.onConnectionStateChange(status, newState); 422 mWrapperCallback.onConnectionStateChange(status, newState);
405 } 423 }
406 424
407 @Override 425 @Override
408 public void onServicesDiscovered(BluetoothGatt gatt, int status) { 426 public void onServicesDiscovered(BluetoothGatt gatt, int status) {
409 mWrapperCallback.onServicesDiscovered(status); 427 mWrapperCallback.onServicesDiscovered(status);
410 } 428 }
411 } 429 }
412 430
413 /** 431 /**
414 * Wrapper alternative to android.bluetooth.BluetoothGattCallback allowing c lients and Fakes to 432 * Wrapper alternative to android.bluetooth.BluetoothGattCallback allowing c lients and Fakes to
415 * work on older SDK versions without having a dependency on the class not d efined there. 433 * work on older SDK versions without having a dependency on the class not d efined there.
416 * 434 *
417 * BluetoothGatt gatt parameters are omitted from methods as each call would 435 * BluetoothGatt gatt parameters are omitted from methods as each call would
418 * need to look up the correct BluetoothGattWrapper instance. 436 * need to look up the correct BluetoothGattWrapper instance.
419 * Client code should cache the BluetoothGattWrapper provided if 437 * Client code should cache the BluetoothGattWrapper provided if
420 * necessary from the initial BluetoothDeviceWrapper.connectGatt 438 * necessary from the initial BluetoothDeviceWrapper.connectGatt
421 * call. 439 * call.
422 */ 440 */
423 abstract static class BluetoothGattCallbackWrapper { 441 abstract static class BluetoothGattCallbackWrapper {
424 public abstract void onCharacteristicChanged( 442 public abstract void onCharacteristicChanged(
425 BluetoothGattCharacteristicWrapper characteristic); 443 BluetoothGattCharacteristicWrapper characteristic);
426 public abstract void onCharacteristicRead( 444 public abstract void onCharacteristicRead(
427 BluetoothGattCharacteristicWrapper characteristic, int status); 445 BluetoothGattCharacteristicWrapper characteristic, int status);
428 public abstract void onCharacteristicWrite( 446 public abstract void onCharacteristicWrite(
429 BluetoothGattCharacteristicWrapper characteristic, int status); 447 BluetoothGattCharacteristicWrapper characteristic, int status);
448 public abstract void onDescriptorRead(
449 BluetoothGattDescriptorWrapper descriptor, int status);
450 public abstract void onDescriptorWrite(
451 BluetoothGattDescriptorWrapper descriptor, int status);
430 public abstract void onConnectionStateChange(int status, int newState); 452 public abstract void onConnectionStateChange(int status, int newState);
431 public abstract void onServicesDiscovered(int status); 453 public abstract void onServicesDiscovered(int status);
432 } 454 }
433 455
434 /** 456 /**
435 * Wraps android.bluetooth.BluetoothGattService. 457 * Wraps android.bluetooth.BluetoothGattService.
436 */ 458 */
437 static class BluetoothGattServiceWrapper { 459 static class BluetoothGattServiceWrapper {
438 private final BluetoothGattService mService; 460 private final BluetoothGattService mService;
439 private final BluetoothDeviceWrapper mDeviceWrapper; 461 private final BluetoothDeviceWrapper mDeviceWrapper;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
487 public BluetoothGattDescriptorWrapper getDescriptor(UUID uuid) { 509 public BluetoothGattDescriptorWrapper getDescriptor(UUID uuid) {
488 BluetoothGattDescriptor descriptor = mCharacteristic.getDescriptor(u uid); 510 BluetoothGattDescriptor descriptor = mCharacteristic.getDescriptor(u uid);
489 if (descriptor == null) { 511 if (descriptor == null) {
490 return null; 512 return null;
491 } 513 }
492 514
493 BluetoothGattDescriptorWrapper descriptorWrapper = 515 BluetoothGattDescriptorWrapper descriptorWrapper =
494 mDeviceWrapper.mDescriptorsToWrappers.get(descriptor); 516 mDeviceWrapper.mDescriptorsToWrappers.get(descriptor);
495 517
496 if (descriptorWrapper == null) { 518 if (descriptorWrapper == null) {
497 descriptorWrapper = new BluetoothGattDescriptorWrapper(descripto r); 519 descriptorWrapper = new BluetoothGattDescriptorWrapper(descripto r, mDeviceWrapper);
498 mDeviceWrapper.mDescriptorsToWrappers.put(descriptor, descriptor Wrapper); 520 mDeviceWrapper.mDescriptorsToWrappers.put(descriptor, descriptor Wrapper);
499 } 521 }
500 return descriptorWrapper; 522 return descriptorWrapper;
501 } 523 }
502 524
503 public List<BluetoothGattDescriptorWrapper> getDescriptors() { 525 public List<BluetoothGattDescriptorWrapper> getDescriptors() {
504 List<BluetoothGattDescriptor> descriptors = mCharacteristic.getDescr iptors(); 526 List<BluetoothGattDescriptor> descriptors = mCharacteristic.getDescr iptors();
505 527
506 ArrayList<BluetoothGattDescriptorWrapper> descriptorsWrapped = 528 ArrayList<BluetoothGattDescriptorWrapper> descriptorsWrapped =
507 new ArrayList<BluetoothGattDescriptorWrapper>(descriptors.si ze()); 529 new ArrayList<BluetoothGattDescriptorWrapper>(descriptors.si ze());
508 530
509 for (BluetoothGattDescriptor descriptor : descriptors) { 531 for (BluetoothGattDescriptor descriptor : descriptors) {
510 BluetoothGattDescriptorWrapper descriptorWrapper = 532 BluetoothGattDescriptorWrapper descriptorWrapper =
511 mDeviceWrapper.mDescriptorsToWrappers.get(descriptor); 533 mDeviceWrapper.mDescriptorsToWrappers.get(descriptor);
512 if (descriptorWrapper == null) { 534 if (descriptorWrapper == null) {
513 descriptorWrapper = new BluetoothGattDescriptorWrapper(descr iptor); 535 descriptorWrapper =
536 new BluetoothGattDescriptorWrapper(descriptor, mDevi ceWrapper);
514 mDeviceWrapper.mDescriptorsToWrappers.put(descriptor, descri ptorWrapper); 537 mDeviceWrapper.mDescriptorsToWrappers.put(descriptor, descri ptorWrapper);
515 } 538 }
516 descriptorsWrapped.add(descriptorWrapper); 539 descriptorsWrapped.add(descriptorWrapper);
517 } 540 }
518 return descriptorsWrapped; 541 return descriptorsWrapped;
519 } 542 }
520 543
521 public int getInstanceId() { 544 public int getInstanceId() {
522 return mCharacteristic.getInstanceId(); 545 return mCharacteristic.getInstanceId();
523 } 546 }
(...skipping 13 matching lines...) Expand all
537 public boolean setValue(byte[] value) { 560 public boolean setValue(byte[] value) {
538 return mCharacteristic.setValue(value); 561 return mCharacteristic.setValue(value);
539 } 562 }
540 } 563 }
541 564
542 /** 565 /**
543 * Wraps android.bluetooth.BluetoothGattDescriptor. 566 * Wraps android.bluetooth.BluetoothGattDescriptor.
544 */ 567 */
545 static class BluetoothGattDescriptorWrapper { 568 static class BluetoothGattDescriptorWrapper {
546 private final BluetoothGattDescriptor mDescriptor; 569 private final BluetoothGattDescriptor mDescriptor;
570 final BluetoothDeviceWrapper mDeviceWrapper;
547 571
548 public BluetoothGattDescriptorWrapper(BluetoothGattDescriptor descriptor ) { 572 public BluetoothGattDescriptorWrapper(
573 BluetoothGattDescriptor descriptor, BluetoothDeviceWrapper devic eWrapper) {
549 mDescriptor = descriptor; 574 mDescriptor = descriptor;
575 mDeviceWrapper = deviceWrapper;
576 }
577
578 public BluetoothGattCharacteristicWrapper getCharacteristic() {
579 return mDeviceWrapper.mCharacteristicsToWrappers.get(mDescriptor.get Characteristic());
550 } 580 }
551 581
552 public UUID getUuid() { 582 public UUID getUuid() {
553 return mDescriptor.getUuid(); 583 return mDescriptor.getUuid();
554 } 584 }
555 585
556 public byte[] getValue() { 586 public byte[] getValue() {
557 return mDescriptor.getValue(); 587 return mDescriptor.getValue();
558 } 588 }
559 589
560 public boolean setValue(byte[] value) { 590 public boolean setValue(byte[] value) {
561 return mDescriptor.setValue(value); 591 return mDescriptor.setValue(value);
562 } 592 }
563 } 593 }
564 } 594 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698