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

Side by Side Diff: device/bluetooth/bluetooth_remote_gatt_characteristic_android.cc

Issue 1502833002: bluetooth: android: Enable characteristic change notification events. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bta-check-null-
Patch Set: fix imports Created 4 years, 11 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/bluetooth_remote_gatt_characteristic_android.h" 5 #include "device/bluetooth/bluetooth_remote_gatt_characteristic_android.h"
6 6
7 #include "base/android/jni_android.h" 7 #include "base/android/jni_android.h"
8 #include "base/android/jni_array.h" 8 #include "base/android/jni_array.h"
9 #include "base/android/jni_string.h" 9 #include "base/android/jni_string.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 129
130 bool BluetoothRemoteGattCharacteristicAndroid::UpdateValue( 130 bool BluetoothRemoteGattCharacteristicAndroid::UpdateValue(
131 const std::vector<uint8_t>& value) { 131 const std::vector<uint8_t>& value) {
132 NOTIMPLEMENTED(); 132 NOTIMPLEMENTED();
133 return false; 133 return false;
134 } 134 }
135 135
136 void BluetoothRemoteGattCharacteristicAndroid::StartNotifySession( 136 void BluetoothRemoteGattCharacteristicAndroid::StartNotifySession(
137 const NotifySessionCallback& callback, 137 const NotifySessionCallback& callback,
138 const ErrorCallback& error_callback) { 138 const ErrorCallback& error_callback) {
139 // TODO(crbug.com/551634): Check characteristic properties and return a better
140 // error code if notifications aren't permitted.
141 if (Java_ChromeBluetoothRemoteGattCharacteristic_startNotifySession( 139 if (Java_ChromeBluetoothRemoteGattCharacteristic_startNotifySession(
142 AttachCurrentThread(), j_characteristic_.obj())) { 140 AttachCurrentThread(), j_characteristic_.obj())) {
141 // TODO(crbug.com/569664): Wait until descriptor write completes before
142 // reporting success via calling |callback|.
143 scoped_ptr<device::BluetoothGattNotifySession> notify_session( 143 scoped_ptr<device::BluetoothGattNotifySession> notify_session(
144 new BluetoothGattNotifySessionAndroid(instance_id_)); 144 new BluetoothGattNotifySessionAndroid(instance_id_));
145 base::MessageLoop::current()->PostTask( 145 base::MessageLoop::current()->PostTask(
146 FROM_HERE, base::Bind(callback, base::Passed(&notify_session))); 146 FROM_HERE, base::Bind(callback, base::Passed(&notify_session)));
147 } else { 147 } else {
148 base::MessageLoop::current()->PostTask( 148 base::MessageLoop::current()->PostTask(
149 FROM_HERE, 149 FROM_HERE,
150 base::Bind(error_callback, 150 base::Bind(error_callback,
151 BluetoothRemoteGattServiceAndroid::GATT_ERROR_FAILED)); 151 BluetoothRemoteGattServiceAndroid::GATT_ERROR_FAILED));
152 } 152 }
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 base::Bind(error_callback, 196 base::Bind(error_callback,
197 BluetoothRemoteGattServiceAndroid::GATT_ERROR_FAILED)); 197 BluetoothRemoteGattServiceAndroid::GATT_ERROR_FAILED));
198 return; 198 return;
199 } 199 }
200 200
201 write_pending_ = true; 201 write_pending_ = true;
202 write_callback_ = callback; 202 write_callback_ = callback;
203 write_error_callback_ = error_callback; 203 write_error_callback_ = error_callback;
204 } 204 }
205 205
206 void BluetoothRemoteGattCharacteristicAndroid::OnChanged(
207 JNIEnv* env,
208 const JavaParamRef<jobject>& jcaller,
209 const JavaParamRef<jbyteArray>& value) {
210 base::android::JavaByteArrayToByteVector(env, value, &value_);
211 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, adapter_->GetObservers(),
212 GattCharacteristicValueChanged(adapter_, this, value_));
213 }
214
206 void BluetoothRemoteGattCharacteristicAndroid::OnRead( 215 void BluetoothRemoteGattCharacteristicAndroid::OnRead(
207 JNIEnv* env, 216 JNIEnv* env,
208 const JavaParamRef<jobject>& jcaller, 217 const JavaParamRef<jobject>& jcaller,
209 int32_t status, 218 int32_t status,
210 const JavaParamRef<jbyteArray>& value) { 219 const JavaParamRef<jbyteArray>& value) {
211 read_pending_ = false; 220 read_pending_ = false;
212 221
213 // Clear callbacks before calling to avoid reentrancy issues. 222 // Clear callbacks before calling to avoid reentrancy issues.
214 ValueCallback read_callback = read_callback_; 223 ValueCallback read_callback = read_callback_;
215 ErrorCallback read_error_callback = read_error_callback_; 224 ErrorCallback read_error_callback = read_error_callback_;
216 read_callback_.Reset(); 225 read_callback_.Reset();
217 read_error_callback_.Reset(); 226 read_error_callback_.Reset();
218 227
219 if (status == 0 // android.bluetooth.BluetoothGatt.GATT_SUCCESS 228 if (status == 0 // android.bluetooth.BluetoothGatt.GATT_SUCCESS
220 && !read_callback.is_null()) { 229 && !read_callback.is_null()) {
221 base::android::JavaByteArrayToByteVector(env, value, &value_); 230 base::android::JavaByteArrayToByteVector(env, value, &value_);
222 read_callback.Run(value_); 231 read_callback.Run(value_);
232 // TODO(https://crbug.com/545682): Call GattCharacteristicValueChanged.
223 } else if (!read_error_callback.is_null()) { 233 } else if (!read_error_callback.is_null()) {
224 read_error_callback.Run( 234 read_error_callback.Run(
225 BluetoothRemoteGattServiceAndroid::GetGattErrorCode(status)); 235 BluetoothRemoteGattServiceAndroid::GetGattErrorCode(status));
226 } 236 }
227 } 237 }
228 238
229 void BluetoothRemoteGattCharacteristicAndroid::OnWrite( 239 void BluetoothRemoteGattCharacteristicAndroid::OnWrite(
230 JNIEnv* env, 240 JNIEnv* env,
231 const JavaParamRef<jobject>& jcaller, 241 const JavaParamRef<jobject>& jcaller,
232 int32_t status) { 242 int32_t status) {
233 write_pending_ = false; 243 write_pending_ = false;
234 244
235 // Clear callbacks before calling to avoid reentrancy issues. 245 // Clear callbacks before calling to avoid reentrancy issues.
236 base::Closure write_callback = write_callback_; 246 base::Closure write_callback = write_callback_;
237 ErrorCallback write_error_callback = write_error_callback_; 247 ErrorCallback write_error_callback = write_error_callback_;
238 write_callback_.Reset(); 248 write_callback_.Reset();
239 write_error_callback_.Reset(); 249 write_error_callback_.Reset();
240 250
241 if (status == 0 // android.bluetooth.BluetoothGatt.GATT_SUCCESS 251 if (status == 0 // android.bluetooth.BluetoothGatt.GATT_SUCCESS
242 && !write_callback.is_null()) { 252 && !write_callback.is_null()) {
243 write_callback.Run(); 253 write_callback.Run();
254 // TODO(https://crbug.com/545682): Call GattCharacteristicValueChanged.
244 } else if (!write_error_callback.is_null()) { 255 } else if (!write_error_callback.is_null()) {
245 write_error_callback.Run( 256 write_error_callback.Run(
246 BluetoothRemoteGattServiceAndroid::GetGattErrorCode(status)); 257 BluetoothRemoteGattServiceAndroid::GetGattErrorCode(status));
247 } 258 }
248 } 259 }
249 260
250 void BluetoothRemoteGattCharacteristicAndroid::CreateGattRemoteDescriptor( 261 void BluetoothRemoteGattCharacteristicAndroid::CreateGattRemoteDescriptor(
251 JNIEnv* env, 262 JNIEnv* env,
252 const JavaParamRef<jobject>& caller, 263 const JavaParamRef<jobject>& caller,
253 const JavaParamRef<jstring>& instanceId, 264 const JavaParamRef<jstring>& instanceId,
(...skipping 22 matching lines...) Expand all
276 void BluetoothRemoteGattCharacteristicAndroid::EnsureDescriptorsCreated() 287 void BluetoothRemoteGattCharacteristicAndroid::EnsureDescriptorsCreated()
277 const { 288 const {
278 if (!descriptors_.empty()) 289 if (!descriptors_.empty())
279 return; 290 return;
280 291
281 Java_ChromeBluetoothRemoteGattCharacteristic_createDescriptors( 292 Java_ChromeBluetoothRemoteGattCharacteristic_createDescriptors(
282 AttachCurrentThread(), j_characteristic_.obj()); 293 AttachCurrentThread(), j_characteristic_.obj());
283 } 294 }
284 295
285 } // namespace device 296 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698