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

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: Fix unit tests on Android 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
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() {
62 disconnectGatt(); 62 disconnectGatt();
scheib 2016/01/27 00:30:43 close() after disconnectGatt() as well?
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
72 @CalledByNative 72 @CalledByNative
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
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();
scheib 2016/01/27 00:30:43 Please add comments here explaining why this is ca
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