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

Side by Side Diff: device/bluetooth/android/java/src/org/chromium/device/bluetooth/ChromeBluetoothRemoteGattCharacteristic.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 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.annotation.TargetApi; 7 import android.annotation.TargetApi;
8 import android.bluetooth.BluetoothGattCharacteristic; 8 import android.bluetooth.BluetoothGattCharacteristic;
9 import android.bluetooth.BluetoothGattDescriptor; 9 import android.bluetooth.BluetoothGattDescriptor;
10 import android.os.Build; 10 import android.os.Build;
(...skipping 14 matching lines...) Expand all
25 */ 25 */
26 @JNINamespace("device") 26 @JNINamespace("device")
27 @TargetApi(Build.VERSION_CODES.LOLLIPOP) 27 @TargetApi(Build.VERSION_CODES.LOLLIPOP)
28 final class ChromeBluetoothRemoteGattCharacteristic { 28 final class ChromeBluetoothRemoteGattCharacteristic {
29 private static final String TAG = "Bluetooth"; 29 private static final String TAG = "Bluetooth";
30 30
31 private long mNativeBluetoothRemoteGattCharacteristicAndroid; 31 private long mNativeBluetoothRemoteGattCharacteristicAndroid;
32 final Wrappers.BluetoothGattCharacteristicWrapper mCharacteristic; 32 final Wrappers.BluetoothGattCharacteristicWrapper mCharacteristic;
33 final String mInstanceId; 33 final String mInstanceId;
34 final ChromeBluetoothDevice mChromeDevice; 34 final ChromeBluetoothDevice mChromeDevice;
35 private boolean mPendingOnStartNotifySession = false;
35 36
36 private ChromeBluetoothRemoteGattCharacteristic( 37 private ChromeBluetoothRemoteGattCharacteristic(
37 long nativeBluetoothRemoteGattCharacteristicAndroid, 38 long nativeBluetoothRemoteGattCharacteristicAndroid,
38 Wrappers.BluetoothGattCharacteristicWrapper characteristicWrapper, S tring instanceId, 39 Wrappers.BluetoothGattCharacteristicWrapper characteristicWrapper, S tring instanceId,
39 ChromeBluetoothDevice chromeDevice) { 40 ChromeBluetoothDevice chromeDevice) {
40 mNativeBluetoothRemoteGattCharacteristicAndroid = 41 mNativeBluetoothRemoteGattCharacteristicAndroid =
41 nativeBluetoothRemoteGattCharacteristicAndroid; 42 nativeBluetoothRemoteGattCharacteristicAndroid;
42 mCharacteristic = characteristicWrapper; 43 mCharacteristic = characteristicWrapper;
43 mInstanceId = instanceId; 44 mInstanceId = instanceId;
44 mChromeDevice = chromeDevice; 45 mChromeDevice = chromeDevice;
(...skipping 17 matching lines...) Expand all
62 } 63 }
63 64
64 void onCharacteristicChanged() { 65 void onCharacteristicChanged() {
65 Log.i(TAG, "onCharacteristicChanged"); 66 Log.i(TAG, "onCharacteristicChanged");
66 if (mNativeBluetoothRemoteGattCharacteristicAndroid != 0) { 67 if (mNativeBluetoothRemoteGattCharacteristicAndroid != 0) {
67 nativeOnChanged( 68 nativeOnChanged(
68 mNativeBluetoothRemoteGattCharacteristicAndroid, mCharacteri stic.getValue()); 69 mNativeBluetoothRemoteGattCharacteristicAndroid, mCharacteri stic.getValue());
69 } 70 }
70 } 71 }
71 72
73 boolean onStartNotifySession(int status) {
74 if (!mPendingOnStartNotifySession) {
75 return false;
76 }
77
78 mPendingOnStartNotifySession = false;
79
80 Log.i(TAG, "onStartNotifySession status:%d==%s", status,
81 status == android.bluetooth.BluetoothGatt.GATT_SUCCESS ? "OK" : "Error");
82 if (mNativeBluetoothRemoteGattCharacteristicAndroid != 0) {
83 nativeOnStartNotifySession(mNativeBluetoothRemoteGattCharacteristicA ndroid, status);
84 }
85
86 return true;
87 }
88
72 void onCharacteristicRead(int status) { 89 void onCharacteristicRead(int status) {
73 Log.i(TAG, "onCharacteristicRead status:%d==%s", status, 90 Log.i(TAG, "onCharacteristicRead status:%d==%s", status,
74 status == android.bluetooth.BluetoothGatt.GATT_SUCCESS ? "OK" : "Error"); 91 status == android.bluetooth.BluetoothGatt.GATT_SUCCESS ? "OK" : "Error");
75 if (mNativeBluetoothRemoteGattCharacteristicAndroid != 0) { 92 if (mNativeBluetoothRemoteGattCharacteristicAndroid != 0) {
76 nativeOnRead(mNativeBluetoothRemoteGattCharacteristicAndroid, status , 93 nativeOnRead(mNativeBluetoothRemoteGattCharacteristicAndroid, status ,
77 mCharacteristic.getValue()); 94 mCharacteristic.getValue());
78 } 95 }
79 } 96 }
80 97
81 void onCharacteristicWrite(int status) { 98 void onCharacteristicWrite(int status) {
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 return false; 167 return false;
151 } 168 }
152 Log.v(TAG, hasNotify ? "startNotifySession NOTIFY." : "startNotifySessio n INDICATE."); 169 Log.v(TAG, hasNotify ? "startNotifySession NOTIFY." : "startNotifySessio n INDICATE.");
153 170
154 if (!mChromeDevice.mBluetoothGatt.writeDescriptor( 171 if (!mChromeDevice.mBluetoothGatt.writeDescriptor(
155 clientCharacteristicConfigurationDescriptor)) { 172 clientCharacteristicConfigurationDescriptor)) {
156 Log.i(TAG, "startNotifySession writeDescriptor failed!"); 173 Log.i(TAG, "startNotifySession writeDescriptor failed!");
157 return false; 174 return false;
158 } 175 }
159 176
177 mPendingOnStartNotifySession = true;
178
160 return true; 179 return true;
161 } 180 }
162 181
163 // Implements BluetoothRemoteGattCharacteristicAndroid::ReadRemoteCharacteri stic. 182 // Implements BluetoothRemoteGattCharacteristicAndroid::ReadRemoteCharacteri stic.
164 @CalledByNative 183 @CalledByNative
165 private boolean readRemoteCharacteristic() { 184 private boolean readRemoteCharacteristic() {
166 if (!mChromeDevice.mBluetoothGatt.readCharacteristic(mCharacteristic)) { 185 if (!mChromeDevice.mBluetoothGatt.readCharacteristic(mCharacteristic)) {
167 Log.i(TAG, "readRemoteCharacteristic readCharacteristic failed."); 186 Log.i(TAG, "readRemoteCharacteristic readCharacteristic failed.");
168 return false; 187 return false;
169 } 188 }
(...skipping 28 matching lines...) Expand all
198 descriptorInstanceId, descriptor, mChromeDevice); 217 descriptorInstanceId, descriptor, mChromeDevice);
199 } 218 }
200 } 219 }
201 220
202 // ------------------------------------------------------------------------- -------------------- 221 // ------------------------------------------------------------------------- --------------------
203 // BluetoothAdapterDevice C++ methods declared for access from java: 222 // BluetoothAdapterDevice C++ methods declared for access from java:
204 223
205 // Binds to BluetoothRemoteGattCharacteristicAndroid::OnChanged. 224 // Binds to BluetoothRemoteGattCharacteristicAndroid::OnChanged.
206 native void nativeOnChanged(long nativeBluetoothRemoteGattCharacteristicAndr oid, byte[] value); 225 native void nativeOnChanged(long nativeBluetoothRemoteGattCharacteristicAndr oid, byte[] value);
207 226
227 // Binds to BluetoothRemoteGattCharacteristicAndroid::OnStartNotifySession.
228 native void nativeOnStartNotifySession(
229 long nativeBluetoothRemoteGattCharacteristicAndroid, int status);
230
208 // Binds to BluetoothRemoteGattCharacteristicAndroid::OnRead. 231 // Binds to BluetoothRemoteGattCharacteristicAndroid::OnRead.
209 native void nativeOnRead( 232 native void nativeOnRead(
210 long nativeBluetoothRemoteGattCharacteristicAndroid, int status, byt e[] value); 233 long nativeBluetoothRemoteGattCharacteristicAndroid, int status, byt e[] value);
211 234
212 // Binds to BluetoothRemoteGattCharacteristicAndroid::OnWrite. 235 // Binds to BluetoothRemoteGattCharacteristicAndroid::OnWrite.
213 native void nativeOnWrite(long nativeBluetoothRemoteGattCharacteristicAndroi d, int status); 236 native void nativeOnWrite(long nativeBluetoothRemoteGattCharacteristicAndroi d, int status);
214 237
215 // Binds to BluetoothRemoteGattCharacteristicAndroid::CreateGattRemoteDescri ptor. 238 // Binds to BluetoothRemoteGattCharacteristicAndroid::CreateGattRemoteDescri ptor.
216 // TODO(http://crbug.com/505554): Replace 'Object' with specific type when J NI fixed. 239 // TODO(http://crbug.com/505554): Replace 'Object' with specific type when J NI fixed.
217 private native void nativeCreateGattRemoteDescriptor( 240 private native void nativeCreateGattRemoteDescriptor(
218 long nativeBluetoothRemoteGattCharacteristicAndroid, String instance Id, 241 long nativeBluetoothRemoteGattCharacteristicAndroid, String instance Id,
219 Object bluetoothGattDescriptorWrapper, Object chromeBluetoothDevice) ; 242 Object bluetoothGattDescriptorWrapper, Object chromeBluetoothDevice) ;
220 } 243 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698