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; | |
10 import android.os.Build; | 9 import android.os.Build; |
11 | 10 |
12 import org.chromium.base.Log; | 11 import org.chromium.base.Log; |
13 import org.chromium.base.annotations.CalledByNative; | 12 import org.chromium.base.annotations.CalledByNative; |
14 import org.chromium.base.annotations.JNINamespace; | 13 import org.chromium.base.annotations.JNINamespace; |
15 import org.chromium.base.metrics.RecordHistogram; | 14 import org.chromium.base.metrics.RecordHistogram; |
16 | 15 |
17 import java.util.HashMap; | 16 import java.util.HashMap; |
18 | 17 |
19 /** | 18 /** |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
93 } | 92 } |
94 | 93 |
95 // Implements BluetoothDeviceAndroid::IsPaired. | 94 // Implements BluetoothDeviceAndroid::IsPaired. |
96 @CalledByNative | 95 @CalledByNative |
97 private boolean isPaired() { | 96 private boolean isPaired() { |
98 return mDevice.getBondState() == BluetoothDevice.BOND_BONDED; | 97 return mDevice.getBondState() == BluetoothDevice.BOND_BONDED; |
99 } | 98 } |
100 | 99 |
101 // Implements BluetoothDeviceAndroid::CreateGattConnectionImpl. | 100 // Implements BluetoothDeviceAndroid::CreateGattConnectionImpl. |
102 @CalledByNative | 101 @CalledByNative |
103 private void createGattConnectionImpl(Context context) { | 102 private void createGattConnectionImpl() { |
104 Log.i(TAG, "connectGatt"); | 103 Log.i(TAG, "connectGatt"); |
105 | 104 |
106 if (mBluetoothGatt != null) mBluetoothGatt.close(); | 105 if (mBluetoothGatt != null) mBluetoothGatt.close(); |
107 | 106 |
108 // autoConnect set to false as under experimentation using autoConnect f ailed to complete | 107 // autoConnect set to false as under experimentation using autoConnect f ailed to complete |
109 // connections. | 108 // connections. |
110 mBluetoothGatt = | 109 mBluetoothGatt = mDevice.connectGatt(false /* autoConnect */, mBluetooth GattCallbackImpl, |
scheib
2017/05/10 20:40:20
mDevice.connectGatt(ContextUtils.getApplicationCon
Peter Wen
2017/05/11 14:01:34
Done.
| |
111 mDevice.connectGatt(context, false /* autoConnect */, mBluetooth GattCallbackImpl, | 110 // Prefer LE for dual-mode devices due to lower energy consumpti on. |
112 // Prefer LE for dual-mode devices due to lower energy c onsumption. | 111 BluetoothDevice.TRANSPORT_LE); |
113 BluetoothDevice.TRANSPORT_LE); | |
114 } | 112 } |
115 | 113 |
116 // Implements BluetoothDeviceAndroid::DisconnectGatt. | 114 // Implements BluetoothDeviceAndroid::DisconnectGatt. |
117 @CalledByNative | 115 @CalledByNative |
118 private void disconnectGatt() { | 116 private void disconnectGatt() { |
119 Log.i(TAG, "BluetoothGatt.disconnect"); | 117 Log.i(TAG, "BluetoothGatt.disconnect"); |
120 if (mBluetoothGatt != null) mBluetoothGatt.disconnect(); | 118 if (mBluetoothGatt != null) mBluetoothGatt.disconnect(); |
121 } | 119 } |
122 | 120 |
123 // Implements callbacks related to a GATT connection. | 121 // Implements callbacks related to a GATT connection. |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
313 long nativeBluetoothDeviceAndroid, int status, boolean connected); | 311 long nativeBluetoothDeviceAndroid, int status, boolean connected); |
314 | 312 |
315 // Binds to BluetoothDeviceAndroid::CreateGattRemoteService. | 313 // Binds to BluetoothDeviceAndroid::CreateGattRemoteService. |
316 // TODO(http://crbug.com/505554): Replace 'Object' with specific type when J NI fixed. | 314 // TODO(http://crbug.com/505554): Replace 'Object' with specific type when J NI fixed. |
317 private native void nativeCreateGattRemoteService(long nativeBluetoothDevice Android, | 315 private native void nativeCreateGattRemoteService(long nativeBluetoothDevice Android, |
318 String instanceId, Object bluetoothGattServiceWrapper); | 316 String instanceId, Object bluetoothGattServiceWrapper); |
319 | 317 |
320 // Binds to BluetoothDeviceAndroid::GattServicesDiscovered. | 318 // Binds to BluetoothDeviceAndroid::GattServicesDiscovered. |
321 private native void nativeOnGattServicesDiscovered(long nativeBluetoothDevic eAndroid); | 319 private native void nativeOnGattServicesDiscovered(long nativeBluetoothDevic eAndroid); |
322 } | 320 } |
OLD | NEW |