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

Side by Side Diff: device/bluetooth/android/java/src/org/chromium/device/bluetooth/ChromeBluetoothDevice.java

Issue 1618273002: Call BluetoothGatt#close() after disconnecting (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased onto current master 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
« no previous file with comments | « no previous file | device/bluetooth/android/java/src/org/chromium/device/bluetooth/Wrappers.java » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.BluetoothDevice; 8 import android.bluetooth.BluetoothDevice;
9 import android.content.Context; 9 import android.content.Context;
10 import android.os.Build; 10 import android.os.Build;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 ChromeBluetoothRemoteGattCharacteristic>(); 51 ChromeBluetoothRemoteGattCharacteristic>();
52 mWrapperToChromeDescriptorsMap = new HashMap<Wrappers.BluetoothGattDescr iptorWrapper, 52 mWrapperToChromeDescriptorsMap = new HashMap<Wrappers.BluetoothGattDescr iptorWrapper,
53 ChromeBluetoothRemoteGattDescriptor>(); 53 ChromeBluetoothRemoteGattDescriptor>();
54 Log.v(TAG, "ChromeBluetoothDevice created."); 54 Log.v(TAG, "ChromeBluetoothDevice created.");
55 } 55 }
56 56
57 /** 57 /**
58 * Handles C++ object being destroyed. 58 * Handles C++ object being destroyed.
59 */ 59 */
60 @CalledByNative 60 @CalledByNative
61 private void onBluetoothDeviceAndroidDestruction() { 61 private void onBluetoothDeviceAndroidDestruction() {
scheib 2016/01/27 00:30:43 Should close be called in onBluetoothDeviceAndroid
tommyt 2016/01/28 12:48:22 Having spent some time today looking at the Androi
scheib 2016/01/29 04:50:39 Ok, just to be clear, I think we should get that p
62 disconnectGatt(); 62 disconnectGatt();
63 mNativeBluetoothDeviceAndroid = 0; 63 mNativeBluetoothDeviceAndroid = 0;
64 } 64 }
65 65
66 // ------------------------------------------------------------------------- -------------------- 66 // ------------------------------------------------------------------------- --------------------
67 // BluetoothDeviceAndroid methods implemented in java: 67 // BluetoothDeviceAndroid methods implemented in java:
68 68
69 // Implements BluetoothDeviceAndroid::Create. 69 // Implements BluetoothDeviceAndroid::Create.
70 // 'Object' type must be used because inner class Wrappers.BluetoothDeviceWr apper reference is 70 // 'Object' type must be used because inner class Wrappers.BluetoothDeviceWr apper reference is
71 // not handled by jni_generator.py JavaToJni. http://crbug.com/505554 71 // not handled by jni_generator.py JavaToJni. http://crbug.com/505554
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 // after a device is connected, discoverServices. crbug.com/508648 114 // after a device is connected, discoverServices. crbug.com/508648
115 return mUuidsFromScan.toArray(new String[mUuidsFromScan.size()]); 115 return mUuidsFromScan.toArray(new String[mUuidsFromScan.size()]);
116 } 116 }
117 117
118 // Implements BluetoothDeviceAndroid::CreateGattConnectionImpl. 118 // Implements BluetoothDeviceAndroid::CreateGattConnectionImpl.
119 @CalledByNative 119 @CalledByNative
120 private void createGattConnectionImpl(Context context) { 120 private void createGattConnectionImpl(Context context) {
121 Log.i(TAG, "connectGatt"); 121 Log.i(TAG, "connectGatt");
122 // autoConnect set to false as under experimentation using autoConnect f ailed to complete 122 // autoConnect set to false as under experimentation using autoConnect f ailed to complete
123 // connections. 123 // connections.
124 mBluetoothGatt = 124 mBluetoothGatt =
scheib 2016/01/27 00:30:43 If we already have a mBluetoothGatt this code will
tommyt 2016/01/28 12:48:22 If we wanted to do mBluetoothGatt.connect() instea
ortuno 2016/01/28 16:19:16 Could you give an example of when this could happe
125 mDevice.connectGatt(context, false /* autoConnect */, mBluetooth GattCallbackImpl); 125 mDevice.connectGatt(context, false /* autoConnect */, mBluetooth GattCallbackImpl);
126 } 126 }
127 127
128 // Implements BluetoothDeviceAndroid::DisconnectGatt. 128 // Implements BluetoothDeviceAndroid::DisconnectGatt.
129 @CalledByNative 129 @CalledByNative
130 private void disconnectGatt() { 130 private void disconnectGatt() {
131 Log.i(TAG, "BluetoothGatt.disconnect"); 131 Log.i(TAG, "BluetoothGatt.disconnect");
132 if (mBluetoothGatt != null) mBluetoothGatt.disconnect(); 132 if (mBluetoothGatt != null) mBluetoothGatt.disconnect();
133 } 133 }
134 134
135 // Implements BluetoothDeviceAndroid::GetDeviceName. 135 // Implements BluetoothDeviceAndroid::GetDeviceName.
136 @CalledByNative 136 @CalledByNative
137 private String getDeviceName() { 137 private String getDeviceName() {
138 return mDevice.getName(); 138 return mDevice.getName();
139 } 139 }
140 140
141 // Implements callbacks related to a GATT connection. 141 // Implements callbacks related to a GATT connection.
142 private class BluetoothGattCallbackImpl extends Wrappers.BluetoothGattCallba ckWrapper { 142 private class BluetoothGattCallbackImpl extends Wrappers.BluetoothGattCallba ckWrapper {
143 @Override 143 @Override
144 public void onConnectionStateChange(final int status, final int newState ) { 144 public void onConnectionStateChange(final int status, final int newState ) {
145 Log.i(TAG, "onConnectionStateChange status:%d newState:%s", status, 145 Log.i(TAG, "onConnectionStateChange status:%d newState:%s", status,
146 (newState == android.bluetooth.BluetoothProfile.STATE_CONNEC TED) 146 (newState == android.bluetooth.BluetoothProfile.STATE_CONNEC TED)
147 ? "Connected" 147 ? "Connected"
148 : "Disconnected"); 148 : "Disconnected");
149 if (newState == android.bluetooth.BluetoothProfile.STATE_CONNECTED) { 149 if (newState == android.bluetooth.BluetoothProfile.STATE_CONNECTED) {
150 mBluetoothGatt.discoverServices(); 150 mBluetoothGatt.discoverServices();
151 } else if (newState == android.bluetooth.BluetoothProfile.STATE_DISC ONNECTED) {
152 mBluetoothGatt.close();
151 } 153 }
152 ThreadUtils.runOnUiThread(new Runnable() { 154 ThreadUtils.runOnUiThread(new Runnable() {
153 @Override 155 @Override
154 public void run() { 156 public void run() {
155 if (mNativeBluetoothDeviceAndroid != 0) { 157 if (mNativeBluetoothDeviceAndroid != 0) {
156 nativeOnConnectionStateChange(mNativeBluetoothDeviceAndr oid, status, 158 nativeOnConnectionStateChange(mNativeBluetoothDeviceAndr oid, status,
157 newState == android.bluetooth.BluetoothProfile.S TATE_CONNECTED); 159 newState == android.bluetooth.BluetoothProfile.S TATE_CONNECTED);
158 } 160 }
159 } 161 }
160 }); 162 });
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 long nativeBluetoothDeviceAndroid, int status, boolean connected); 256 long nativeBluetoothDeviceAndroid, int status, boolean connected);
255 257
256 // Binds to BluetoothDeviceAndroid::CreateGattRemoteService. 258 // Binds to BluetoothDeviceAndroid::CreateGattRemoteService.
257 // TODO(http://crbug.com/505554): Replace 'Object' with specific type when J NI fixed. 259 // TODO(http://crbug.com/505554): Replace 'Object' with specific type when J NI fixed.
258 private native void nativeCreateGattRemoteService(long nativeBluetoothDevice Android, 260 private native void nativeCreateGattRemoteService(long nativeBluetoothDevice Android,
259 String instanceId, Object bluetoothGattServiceWrapper); 261 String instanceId, Object bluetoothGattServiceWrapper);
260 262
261 // Binds to BluetoothDeviceAndroid::GattServicesDiscovered. 263 // Binds to BluetoothDeviceAndroid::GattServicesDiscovered.
262 private native void nativeOnGattServicesDiscovered(long nativeBluetoothDevic eAndroid); 264 private native void nativeOnGattServicesDiscovered(long nativeBluetoothDevic eAndroid);
263 } 265 }
OLDNEW
« no previous file with comments | « no previous file | device/bluetooth/android/java/src/org/chromium/device/bluetooth/Wrappers.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698