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

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

Issue 1565773002: Clear the BLE services list on disconnect. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add a unittest 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_device_android.h" 5 #include "device/bluetooth/bluetooth_device_android.h"
6 6
7 #include "base/android/context_utils.h" 7 #include "base/android/context_utils.h"
8 #include "base/android/jni_android.h" 8 #include "base/android/jni_android.h"
9 #include "base/android/jni_array.h" 9 #include "base/android/jni_array.h"
10 #include "base/android/jni_string.h" 10 #include "base/android/jni_string.h"
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 203
204 void BluetoothDeviceAndroid::OnConnectionStateChange( 204 void BluetoothDeviceAndroid::OnConnectionStateChange(
205 JNIEnv* env, 205 JNIEnv* env,
206 const JavaParamRef<jobject>& jcaller, 206 const JavaParamRef<jobject>& jcaller,
207 int32_t status, 207 int32_t status,
208 bool connected) { 208 bool connected) {
209 gatt_connected_ = connected; 209 gatt_connected_ = connected;
210 if (gatt_connected_) { 210 if (gatt_connected_) {
211 DidConnectGatt(); 211 DidConnectGatt();
212 } else { 212 } else {
213 gatt_services_.clear();
214 SetGattServicesDiscoveryComplete(false);
215
213 // TODO(scheib) Create new BluetoothDevice::ConnectErrorCode enums for 216 // TODO(scheib) Create new BluetoothDevice::ConnectErrorCode enums for
214 // android values not yet represented. http://crbug.com/531058 217 // android values not yet represented. http://crbug.com/531058
215 switch (status) { // Constants are from android.bluetooth.BluetoothGatt. 218 switch (status) { // Constants are from android.bluetooth.BluetoothGatt.
216 case 0x00000101: // GATT_FAILURE 219 case 0x00000101: // GATT_FAILURE
217 return DidFailToConnectGatt(ERROR_FAILED); 220 return DidFailToConnectGatt(ERROR_FAILED);
218 case 0x00000005: // GATT_INSUFFICIENT_AUTHENTICATION 221 case 0x00000005: // GATT_INSUFFICIENT_AUTHENTICATION
219 return DidFailToConnectGatt(ERROR_AUTH_FAILED); 222 return DidFailToConnectGatt(ERROR_AUTH_FAILED);
220 case 0x00000000: // GATT_SUCCESS 223 case 0x00000000: // GATT_SUCCESS
221 return DidDisconnectGatt(); 224 return DidDisconnectGatt();
222 default: 225 default:
223 VLOG(1) << "Unhandled status: " << status; 226 VLOG(1) << "Unhandled status: " << status;
224 return DidFailToConnectGatt(ERROR_UNKNOWN); 227 return DidFailToConnectGatt(ERROR_UNKNOWN);
225 } 228 }
226 } 229 }
227 } 230 }
228 231
229 void BluetoothDeviceAndroid::OnGattServicesDiscovered( 232 void BluetoothDeviceAndroid::OnGattServicesDiscovered(
230 JNIEnv* env, 233 JNIEnv* env,
231 const JavaParamRef<jobject>& jcaller) { 234 const JavaParamRef<jobject>& jcaller) {
235 SetGattServicesDiscoveryComplete(true);
232 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, GetAdapter()->GetObservers(), 236 FOR_EACH_OBSERVER(BluetoothAdapter::Observer, GetAdapter()->GetObservers(),
233 GattServicesDiscovered(GetAdapter(), this)); 237 GattServicesDiscovered(GetAdapter(), this));
234 } 238 }
235 239
236 void BluetoothDeviceAndroid::CreateGattRemoteService( 240 void BluetoothDeviceAndroid::CreateGattRemoteService(
237 JNIEnv* env, 241 JNIEnv* env,
238 const JavaParamRef<jobject>& caller, 242 const JavaParamRef<jobject>& caller,
239 const JavaParamRef<jstring>& instanceId, 243 const JavaParamRef<jstring>& instanceId,
240 const JavaParamRef<jobject>& 244 const JavaParamRef<jobject>&
241 bluetooth_gatt_service_wrapper) { // BluetoothGattServiceWrapper 245 bluetooth_gatt_service_wrapper) { // BluetoothGattServiceWrapper
(...skipping 26 matching lines...) Expand all
268 AttachCurrentThread(), j_device_.obj(), 272 AttachCurrentThread(), j_device_.obj(),
269 base::android::GetApplicationContext()); 273 base::android::GetApplicationContext());
270 } 274 }
271 275
272 void BluetoothDeviceAndroid::DisconnectGatt() { 276 void BluetoothDeviceAndroid::DisconnectGatt() {
273 Java_ChromeBluetoothDevice_disconnectGatt(AttachCurrentThread(), 277 Java_ChromeBluetoothDevice_disconnectGatt(AttachCurrentThread(),
274 j_device_.obj()); 278 j_device_.obj());
275 } 279 }
276 280
277 } // namespace device 281 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698