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 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 Loading... | |
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 Loading... | |
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 Loading... | |
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 } |
OLD | NEW |