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

Side by Side Diff: device/bluetooth/android/java/src/org/chromium/device/bluetooth/ChromeBluetoothRemoteGattDescriptor.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: Added the comment that Gio requested Created 4 years, 10 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 org.chromium.base.Log; 7 import org.chromium.base.Log;
8 import org.chromium.base.annotations.CalledByNative; 8 import org.chromium.base.annotations.CalledByNative;
9 import org.chromium.base.annotations.JNINamespace; 9 import org.chromium.base.annotations.JNINamespace;
10 10
11 /** 11 /**
12 * Exposes android.bluetooth.BluetoothGattDescriptor as necessary 12 * Exposes android.bluetooth.BluetoothGattDescriptor as necessary
13 * for C++ device::BluetoothRemoteGattDescriptorAndroid. 13 * for C++ device::BluetoothRemoteGattDescriptorAndroid.
14 * 14 *
15 * Lifetime is controlled by device::BluetoothRemoteGattDescriptorAndroid. 15 * Lifetime is controlled by device::BluetoothRemoteGattDescriptorAndroid.
16 */ 16 */
17 @JNINamespace("device") 17 @JNINamespace("device")
18 final class ChromeBluetoothRemoteGattDescriptor { 18 final class ChromeBluetoothRemoteGattDescriptor {
19 private static final String TAG = "Bluetooth"; 19 private static final String TAG = "Bluetooth";
20 20
21 // TODO(scheib): Will need c++ pointer eventually: 21 private long mNativeBluetoothRemoteGattDescriptorAndroid;
22 // private long mNativeBluetoothRemoteGattDescriptorAndroid;
23 final Wrappers.BluetoothGattDescriptorWrapper mDescriptor; 22 final Wrappers.BluetoothGattDescriptorWrapper mDescriptor;
24 final ChromeBluetoothDevice mChromeDevice; 23 final ChromeBluetoothDevice mChromeDevice;
25 24
26 private ChromeBluetoothRemoteGattDescriptor( 25 private ChromeBluetoothRemoteGattDescriptor(long nativeBluetoothRemoteGattDe scriptorAndroid,
27 // TODO(scheib): Will need c++ pointer eventually:
28 // long nativeBluetoothRemoteGattDescriptorAndroid,
29 Wrappers.BluetoothGattDescriptorWrapper descriptorWrapper, 26 Wrappers.BluetoothGattDescriptorWrapper descriptorWrapper,
30 ChromeBluetoothDevice chromeDevice) { 27 ChromeBluetoothDevice chromeDevice) {
31 // TODO(scheib): Will need c++ pointer eventually: 28 mNativeBluetoothRemoteGattDescriptorAndroid = nativeBluetoothRemoteGattD escriptorAndroid;
32 // mNativeBluetoothRemoteGattDescriptorAndroid =
33 // nativeBluetoothRemoteGattDescriptorAndroid;
34 mDescriptor = descriptorWrapper; 29 mDescriptor = descriptorWrapper;
35 mChromeDevice = chromeDevice; 30 mChromeDevice = chromeDevice;
36 31
37 mChromeDevice.mWrapperToChromeDescriptorsMap.put(descriptorWrapper, this ); 32 mChromeDevice.mWrapperToChromeDescriptorsMap.put(descriptorWrapper, this );
38 33
39 Log.v(TAG, "ChromeBluetoothRemoteGattDescriptor created."); 34 Log.v(TAG, "ChromeBluetoothRemoteGattDescriptor created.");
40 } 35 }
41 36
42 /** 37 /**
43 * Handles C++ object being destroyed. 38 * Handles C++ object being destroyed.
44 */ 39 */
45 @CalledByNative 40 @CalledByNative
46 private void onBluetoothRemoteGattDescriptorAndroidDestruction() { 41 private void onBluetoothRemoteGattDescriptorAndroidDestruction() {
47 Log.v(TAG, "ChromeBluetoothRemoteGattDescriptor Destroyed."); 42 Log.v(TAG, "ChromeBluetoothRemoteGattDescriptor Destroyed.");
48 // TODO(scheib): Will need c++ pointer eventually: 43 mNativeBluetoothRemoteGattDescriptorAndroid = 0;
49 // mNativeBluetoothRemoteGattDescriptorAndroid = 0;
50 mChromeDevice.mWrapperToChromeDescriptorsMap.remove(mDescriptor); 44 mChromeDevice.mWrapperToChromeDescriptorsMap.remove(mDescriptor);
51 } 45 }
52 46
47 void onDescriptorRead(int status) {
48 Log.i(TAG, "onDescriptorRead status:%d==%s", status,
49 status == android.bluetooth.BluetoothGatt.GATT_SUCCESS ? "OK" : "Error");
50 if (mNativeBluetoothRemoteGattDescriptorAndroid != 0) {
51 nativeOnRead(
52 mNativeBluetoothRemoteGattDescriptorAndroid, status, mDescri ptor.getValue());
53 }
54 }
55
56 void onDescriptorWrite(int status) {
57 Log.i(TAG, "onDescriptorWrite status:%d==%s", status,
58 status == android.bluetooth.BluetoothGatt.GATT_SUCCESS ? "OK" : "Error");
59 if (mNativeBluetoothRemoteGattDescriptorAndroid != 0) {
60 nativeOnWrite(mNativeBluetoothRemoteGattDescriptorAndroid, status);
61 }
62 }
63
53 // ------------------------------------------------------------------------- -------------------- 64 // ------------------------------------------------------------------------- --------------------
54 // BluetoothRemoteGattDescriptorAndroid methods implemented in java: 65 // BluetoothRemoteGattDescriptorAndroid methods implemented in java:
55 66
56 // Implements BluetoothRemoteGattDescriptorAndroid::Create. 67 // Implements BluetoothRemoteGattDescriptorAndroid::Create.
57 // TODO(http://crbug.com/505554): Replace 'Object' with specific type when J NI fixed. 68 // TODO(http://crbug.com/505554): Replace 'Object' with specific type when J NI fixed.
58 @CalledByNative 69 @CalledByNative
59 private static ChromeBluetoothRemoteGattDescriptor create( 70 private static ChromeBluetoothRemoteGattDescriptor create(
60 // TODO(scheib): Will need c++ pointer eventually: 71 long nativeBluetoothRemoteGattDescriptorAndroid, Object bluetoothGat tDescriptorWrapper,
61 // long nativeBluetoothRemoteGattDescriptorAndroid, 72 ChromeBluetoothDevice chromeDevice) {
62 Object bluetoothGattDescriptorWrapper, ChromeBluetoothDevice chromeD evice) { 73 return new ChromeBluetoothRemoteGattDescriptor(nativeBluetoothRemoteGatt DescriptorAndroid,
63 return new ChromeBluetoothRemoteGattDescriptor(
64 // TODO(scheib): Will need c++ pointer eventually:
65 // nativeBluetoothRemoteGattDescriptorAndroid,
66 (Wrappers.BluetoothGattDescriptorWrapper) bluetoothGattDescripto rWrapper, 74 (Wrappers.BluetoothGattDescriptorWrapper) bluetoothGattDescripto rWrapper,
67 chromeDevice); 75 chromeDevice);
68 } 76 }
69 77
70 // Implements BluetoothRemoteGattDescriptorAndroid::GetUUID. 78 // Implements BluetoothRemoteGattDescriptorAndroid::GetUUID.
71 @CalledByNative 79 @CalledByNative
72 private String getUUID() { 80 private String getUUID() {
73 return mDescriptor.getUuid().toString(); 81 return mDescriptor.getUuid().toString();
74 } 82 }
83
84 // Implements BluetoothRemoteGattDescriptorAndroid::ReadRemoteDescriptor.
85 @CalledByNative
86 private boolean readRemoteDescriptor() {
87 if (!mChromeDevice.mBluetoothGatt.readDescriptor(mDescriptor)) {
88 Log.i(TAG, "readRemoteDescriptor readDescriptor failed.");
89 return false;
90 }
91 return true;
92 }
93
94 // Implements BluetoothRemoteGattDescriptorAndroid::WriteRemoteDescriptor.
95 @CalledByNative
96 private boolean writeRemoteDescriptor(byte[] value) {
97 if (!mDescriptor.setValue(value)) {
98 Log.i(TAG, "writeRemoteDescriptor setValue failed.");
99 return false;
100 }
101 if (!mChromeDevice.mBluetoothGatt.writeDescriptor(mDescriptor)) {
102 Log.i(TAG, "writeRemoteDescriptor writeDescriptor failed.");
103 return false;
104 }
105 return true;
106 }
107
scheib 2016/02/26 04:27:01 Add a comment section divider: // ----------------
tommyt 2016/03/01 14:45:14 Done.
108 // Binds to BluetoothRemoteGattDescriptorAndroid::OnRead.
109 native void nativeOnRead(
110 long nativeBluetoothRemoteGattDescriptorAndroid, int status, byte[] value);
111
112 // Binds to BluetoothRemoteGattDescriptorAndroid::OnWrite.
113 native void nativeOnWrite(long nativeBluetoothRemoteGattDescriptorAndroid, i nt status);
75 } 114 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698