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

Side by Side Diff: device/bluetooth/test/android/java/src/org/chromium/device/bluetooth/Fakes.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.BluetoothDevice; 9 import android.bluetooth.BluetoothDevice;
10 import android.bluetooth.le.ScanFilter; 10 import android.bluetooth.le.ScanFilter;
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 347
348 /** 348 /**
349 * Fakes android.bluetooth.BluetoothGatt. 349 * Fakes android.bluetooth.BluetoothGatt.
350 */ 350 */
351 static class FakeBluetoothGatt extends Wrappers.BluetoothGattWrapper { 351 static class FakeBluetoothGatt extends Wrappers.BluetoothGattWrapper {
352 final FakeBluetoothDevice mDevice; 352 final FakeBluetoothDevice mDevice;
353 final ArrayList<Wrappers.BluetoothGattServiceWrapper> mServices; 353 final ArrayList<Wrappers.BluetoothGattServiceWrapper> mServices;
354 boolean mReadCharacteristicWillFailSynchronouslyOnce = false; 354 boolean mReadCharacteristicWillFailSynchronouslyOnce = false;
355 boolean mSetCharacteristicNotificationWillFailSynchronouslyOnce = false; 355 boolean mSetCharacteristicNotificationWillFailSynchronouslyOnce = false;
356 boolean mWriteCharacteristicWillFailSynchronouslyOnce = false; 356 boolean mWriteCharacteristicWillFailSynchronouslyOnce = false;
357 boolean mReadDescriptorWillFailSynchronouslyOnce = false;
357 boolean mWriteDescriptorWillFailSynchronouslyOnce = false; 358 boolean mWriteDescriptorWillFailSynchronouslyOnce = false;
358 359
359 public FakeBluetoothGatt(FakeBluetoothDevice device) { 360 public FakeBluetoothGatt(FakeBluetoothDevice device) {
360 super(null, null); 361 super(null, null);
361 mDevice = device; 362 mDevice = device;
362 mServices = new ArrayList<Wrappers.BluetoothGattServiceWrapper>(); 363 mServices = new ArrayList<Wrappers.BluetoothGattServiceWrapper>();
363 } 364 }
364 365
365 @Override 366 @Override
366 public void disconnect() { 367 public void disconnect() {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 if (mWriteCharacteristicWillFailSynchronouslyOnce) { 411 if (mWriteCharacteristicWillFailSynchronouslyOnce) {
411 mWriteCharacteristicWillFailSynchronouslyOnce = false; 412 mWriteCharacteristicWillFailSynchronouslyOnce = false;
412 return false; 413 return false;
413 } 414 }
414 nativeOnFakeBluetoothGattWriteCharacteristic( 415 nativeOnFakeBluetoothGattWriteCharacteristic(
415 mDevice.mAdapter.mNativeBluetoothTestAndroid, characteristic .getValue()); 416 mDevice.mAdapter.mNativeBluetoothTestAndroid, characteristic .getValue());
416 return true; 417 return true;
417 } 418 }
418 419
419 @Override 420 @Override
421 boolean readDescriptor(Wrappers.BluetoothGattDescriptorWrapper descripto r) {
422 if (mReadDescriptorWillFailSynchronouslyOnce) {
423 mReadDescriptorWillFailSynchronouslyOnce = false;
424 return false;
425 }
426 nativeOnFakeBluetoothGattReadDescriptor(mDevice.mAdapter.mNativeBlue toothTestAndroid);
427 return true;
428 }
429
430 @Override
420 boolean writeDescriptor(Wrappers.BluetoothGattDescriptorWrapper descript or) { 431 boolean writeDescriptor(Wrappers.BluetoothGattDescriptorWrapper descript or) {
421 if (mWriteDescriptorWillFailSynchronouslyOnce) { 432 if (mWriteDescriptorWillFailSynchronouslyOnce) {
422 mWriteDescriptorWillFailSynchronouslyOnce = false; 433 mWriteDescriptorWillFailSynchronouslyOnce = false;
423 return false; 434 return false;
424 } 435 }
425 nativeOnFakeBluetoothGattWriteDescriptor( 436 nativeOnFakeBluetoothGattWriteDescriptor(
426 mDevice.mAdapter.mNativeBluetoothTestAndroid, descriptor.get Value()); 437 mDevice.mAdapter.mNativeBluetoothTestAndroid, descriptor.get Value());
427 return true; 438 return true;
428 } 439 }
429 } 440 }
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
665 } 676 }
666 } 677 }
667 678
668 /** 679 /**
669 * Fakes android.bluetooth.BluetoothGattDescriptor. 680 * Fakes android.bluetooth.BluetoothGattDescriptor.
670 */ 681 */
671 static class FakeBluetoothGattDescriptor extends Wrappers.BluetoothGattDescr iptorWrapper { 682 static class FakeBluetoothGattDescriptor extends Wrappers.BluetoothGattDescr iptorWrapper {
672 final FakeBluetoothGattCharacteristic mCharacteristic; 683 final FakeBluetoothGattCharacteristic mCharacteristic;
673 final UUID mUuid; 684 final UUID mUuid;
674 byte[] mValue; 685 byte[] mValue;
686 static FakeBluetoothGattDescriptor sRememberedDescriptor;
675 687
676 public FakeBluetoothGattDescriptor( 688 public FakeBluetoothGattDescriptor(
677 FakeBluetoothGattCharacteristic characteristic, UUID uuid) { 689 FakeBluetoothGattCharacteristic characteristic, UUID uuid) {
678 super(null); 690 super(null, null);
679 mCharacteristic = characteristic; 691 mCharacteristic = characteristic;
680 mUuid = uuid; 692 mUuid = uuid;
681 mValue = new byte[0]; 693 mValue = new byte[0];
682 } 694 }
683 695
696 // Implements BluetoothTestAndroid::RememberDescriptorForSubsequentActio n.
697 @CalledByNative("FakeBluetoothGattDescriptor")
698 private static void rememberDescriptorForSubsequentAction(
699 ChromeBluetoothRemoteGattDescriptor chromeDescriptor) {
700 sRememberedDescriptor = (FakeBluetoothGattDescriptor) chromeDescript or.mDescriptor;
701 }
702
703 // Simulate a value being read from a descriptor.
704 @CalledByNative("FakeBluetoothGattDescriptor")
705 private static void valueRead(
706 ChromeBluetoothRemoteGattDescriptor chromeDescriptor, int status , byte[] value) {
707 if (chromeDescriptor == null && sRememberedDescriptor == null)
708 throw new IllegalArgumentException("rememberDescriptor wasn't ca lled previously.");
709
710 FakeBluetoothGattDescriptor fakeDescriptor = (chromeDescriptor == nu ll)
711 ? sRememberedDescriptor
712 : (FakeBluetoothGattDescriptor) chromeDescriptor.mDescriptor ;
713
714 fakeDescriptor.mValue = value;
715 fakeDescriptor.mCharacteristic.mService.mDevice.mGattCallback.onDesc riptorRead(
716 fakeDescriptor, status);
717 }
718
719 // Simulate a value being written to a descriptor.
720 @CalledByNative("FakeBluetoothGattDescriptor")
721 private static void valueWrite(
722 ChromeBluetoothRemoteGattDescriptor chromeDescriptor, int status ) {
723 if (chromeDescriptor == null && sRememberedDescriptor == null)
724 throw new IllegalArgumentException("rememberDescriptor wasn't ca lled previously.");
725
726 FakeBluetoothGattDescriptor fakeDescriptor = (chromeDescriptor == nu ll)
727 ? sRememberedDescriptor
728 : (FakeBluetoothGattDescriptor) chromeDescriptor.mDescriptor ;
729
730 fakeDescriptor.mCharacteristic.mService.mDevice.mGattCallback.onDesc riptorWrite(
731 fakeDescriptor, status);
732 }
733
734 // Cause subsequent value read of a descriptor to fail synchronously.
735 @CalledByNative("FakeBluetoothGattDescriptor")
736 private static void setReadDescriptorWillFailSynchronouslyOnce(
737 ChromeBluetoothRemoteGattDescriptor chromeDescriptor) {
738 FakeBluetoothGattDescriptor fakeDescriptor =
739 (FakeBluetoothGattDescriptor) chromeDescriptor.mDescriptor;
740
741 fakeDescriptor.mCharacteristic.mService.mDevice.mGatt
742 .mReadDescriptorWillFailSynchronouslyOnce = true;
743 }
744
684 // Cause subsequent value write of a descriptor to fail synchronously. 745 // Cause subsequent value write of a descriptor to fail synchronously.
685 @CalledByNative("FakeBluetoothGattDescriptor") 746 @CalledByNative("FakeBluetoothGattDescriptor")
686 private static void setWriteDescriptorWillFailSynchronouslyOnce( 747 private static void setWriteDescriptorWillFailSynchronouslyOnce(
687 ChromeBluetoothRemoteGattDescriptor chromeDescriptor) { 748 ChromeBluetoothRemoteGattDescriptor chromeDescriptor) {
688 FakeBluetoothGattDescriptor fakeDescriptor = 749 FakeBluetoothGattDescriptor fakeDescriptor =
689 (FakeBluetoothGattDescriptor) chromeDescriptor.mDescriptor; 750 (FakeBluetoothGattDescriptor) chromeDescriptor.mDescriptor;
690 751
691 fakeDescriptor.mCharacteristic.mService.mDevice.mGatt 752 fakeDescriptor.mCharacteristic.mService.mDevice.mGatt
692 .mWriteDescriptorWillFailSynchronouslyOnce = true; 753 .mWriteDescriptorWillFailSynchronouslyOnce = true;
693 } 754 }
694 755
695 // --------------------------------------------------------------------- -------------------- 756 // --------------------------------------------------------------------- --------------------
696 // Wrappers.BluetoothGattDescriptorWrapper overrides: 757 // Wrappers.BluetoothGattDescriptorWrapper overrides:
697 758
698 @Override 759 @Override
760 public Wrappers.BluetoothGattCharacteristicWrapper getCharacteristic() {
761 return mCharacteristic;
762 }
763
764 @Override
699 public UUID getUuid() { 765 public UUID getUuid() {
700 return mUuid; 766 return mUuid;
701 } 767 }
702 768
703 @Override 769 @Override
704 public byte[] getValue() { 770 public byte[] getValue() {
705 return mValue; 771 return mValue;
706 } 772 }
707 773
708 @Override 774 @Override
(...skipping 25 matching lines...) Expand all
734 long nativeBluetoothTestAndroid); 800 long nativeBluetoothTestAndroid);
735 801
736 // Binds to BluetoothTestAndroid::OnFakeBluetoothGattReadCharacteristic. 802 // Binds to BluetoothTestAndroid::OnFakeBluetoothGattReadCharacteristic.
737 private static native void nativeOnFakeBluetoothGattReadCharacteristic( 803 private static native void nativeOnFakeBluetoothGattReadCharacteristic(
738 long nativeBluetoothTestAndroid); 804 long nativeBluetoothTestAndroid);
739 805
740 // Binds to BluetoothTestAndroid::OnFakeBluetoothGattWriteCharacteristic. 806 // Binds to BluetoothTestAndroid::OnFakeBluetoothGattWriteCharacteristic.
741 private static native void nativeOnFakeBluetoothGattWriteCharacteristic( 807 private static native void nativeOnFakeBluetoothGattWriteCharacteristic(
742 long nativeBluetoothTestAndroid, byte[] value); 808 long nativeBluetoothTestAndroid, byte[] value);
743 809
810 // Binds to BluetoothTestAndroid::OnFakeBluetoothGattReadDescriptor.
811 private static native void nativeOnFakeBluetoothGattReadDescriptor(
812 long nativeBluetoothTestAndroid);
813
744 // Binds to BluetoothTestAndroid::OnFakeBluetoothGattWriteDescriptor. 814 // Binds to BluetoothTestAndroid::OnFakeBluetoothGattWriteDescriptor.
745 private static native void nativeOnFakeBluetoothGattWriteDescriptor( 815 private static native void nativeOnFakeBluetoothGattWriteDescriptor(
746 long nativeBluetoothTestAndroid, byte[] value); 816 long nativeBluetoothTestAndroid, byte[] value);
747 } 817 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698