OLD | NEW |
---|---|
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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
148 | 148 |
149 if (!hasNotify && !hasIndicate) { | 149 if (!hasNotify && !hasIndicate) { |
150 LOG(ERROR) << "Characteristic needs NOTIFY or INDICATE"; | 150 LOG(ERROR) << "Characteristic needs NOTIFY or INDICATE"; |
151 base::MessageLoop::current()->PostTask( | 151 base::MessageLoop::current()->PostTask( |
152 FROM_HERE, | 152 FROM_HERE, |
153 base::Bind(error_callback, | 153 base::Bind(error_callback, |
154 BluetoothRemoteGattServiceAndroid::GATT_ERROR_FAILED)); | 154 BluetoothRemoteGattServiceAndroid::GATT_ERROR_FAILED)); |
155 return; | 155 return; |
156 } | 156 } |
157 | 157 |
158 BluetoothGattDescriptor* descriptor = GetDescriptorForUUID( | 158 std::vector<BluetoothGattDescriptor*> ccc_descriptor = GetDescriptorsForUUID( |
159 BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid()); | 159 BluetoothGattDescriptor::ClientCharacteristicConfigurationUuid()); |
160 | 160 |
161 if (!descriptor) { | 161 if (ccc_descriptor.size() != 1u) { |
ortuno
2016/03/13 20:41:45
Hmm this would fail with GATT NOT SUPPORTED if the
scheib
2016/03/25 00:13:57
Done: Different errors returned for <1 and >1. Tes
| |
162 LOG(ERROR) | 162 LOG(ERROR) |
163 << "Could not find client characteristic configuration descriptor"; | 163 << "Could not find client characteristic configuration descriptor"; |
164 base::MessageLoop::current()->PostTask( | 164 base::MessageLoop::current()->PostTask( |
165 FROM_HERE, | 165 FROM_HERE, |
166 base::Bind(error_callback, | 166 base::Bind(error_callback, |
167 BluetoothRemoteGattServiceAndroid::GATT_ERROR_FAILED)); | 167 BluetoothRemoteGattServiceAndroid::GATT_ERROR_FAILED)); |
168 return; | 168 return; |
169 } | 169 } |
170 | 170 |
171 if (!Java_ChromeBluetoothRemoteGattCharacteristic_setCharacteristicNotificatio n( | 171 if (!Java_ChromeBluetoothRemoteGattCharacteristic_setCharacteristicNotificatio n( |
172 AttachCurrentThread(), j_characteristic_.obj(), true)) { | 172 AttachCurrentThread(), j_characteristic_.obj(), true)) { |
173 LOG(ERROR) << "Error enabling characteristic notification"; | 173 LOG(ERROR) << "Error enabling characteristic notification"; |
174 base::MessageLoop::current()->PostTask( | 174 base::MessageLoop::current()->PostTask( |
175 FROM_HERE, | 175 FROM_HERE, |
176 base::Bind(error_callback, | 176 base::Bind(error_callback, |
177 BluetoothRemoteGattServiceAndroid::GATT_ERROR_FAILED)); | 177 BluetoothRemoteGattServiceAndroid::GATT_ERROR_FAILED)); |
178 return; | 178 return; |
179 } | 179 } |
180 | 180 |
181 std::vector<uint8_t> value; | 181 std::vector<uint8_t> value; |
182 value.push_back(hasNotify ? 1 : 2); | 182 value.push_back(hasNotify ? 1 : 2); |
183 value.push_back(0); | 183 value.push_back(0); |
184 | 184 |
185 pending_start_notify_calls_.push(std::make_pair(callback, error_callback)); | 185 pending_start_notify_calls_.push(std::make_pair(callback, error_callback)); |
186 descriptor->WriteRemoteDescriptor( | 186 ccc_descriptor[0]->WriteRemoteDescriptor( |
187 value, base::Bind(&BluetoothRemoteGattCharacteristicAndroid:: | 187 value, base::Bind(&BluetoothRemoteGattCharacteristicAndroid:: |
188 OnStartNotifySessionSuccess, | 188 OnStartNotifySessionSuccess, |
189 base::Unretained(this)), | 189 base::Unretained(this)), |
190 base::Bind( | 190 base::Bind( |
191 &BluetoothRemoteGattCharacteristicAndroid::OnStartNotifySessionError, | 191 &BluetoothRemoteGattCharacteristicAndroid::OnStartNotifySessionError, |
192 base::Unretained(this))); | 192 base::Unretained(this))); |
193 } | 193 } |
194 | 194 |
195 void BluetoothRemoteGattCharacteristicAndroid::ReadRemoteCharacteristic( | 195 void BluetoothRemoteGattCharacteristicAndroid::ReadRemoteCharacteristic( |
196 const ValueCallback& callback, | 196 const ValueCallback& callback, |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
345 void BluetoothRemoteGattCharacteristicAndroid::EnsureDescriptorsCreated() | 345 void BluetoothRemoteGattCharacteristicAndroid::EnsureDescriptorsCreated() |
346 const { | 346 const { |
347 if (!descriptors_.empty()) | 347 if (!descriptors_.empty()) |
348 return; | 348 return; |
349 | 349 |
350 Java_ChromeBluetoothRemoteGattCharacteristic_createDescriptors( | 350 Java_ChromeBluetoothRemoteGattCharacteristic_createDescriptors( |
351 AttachCurrentThread(), j_characteristic_.obj()); | 351 AttachCurrentThread(), j_characteristic_.obj()); |
352 } | 352 } |
353 | 353 |
354 } // namespace device | 354 } // namespace device |
OLD | NEW |