Index: device/bluetooth/android/java/src/org/chromium/device/bluetooth/ChromeBluetoothDevice.java |
diff --git a/device/bluetooth/android/java/src/org/chromium/device/bluetooth/ChromeBluetoothDevice.java b/device/bluetooth/android/java/src/org/chromium/device/bluetooth/ChromeBluetoothDevice.java |
index 3536bf8e4118069655ade0e82b5a9f46fe21b0ce..bc76234b15d58707aefb61df26f65ac30c40ee60 100644 |
--- a/device/bluetooth/android/java/src/org/chromium/device/bluetooth/ChromeBluetoothDevice.java |
+++ b/device/bluetooth/android/java/src/org/chromium/device/bluetooth/ChromeBluetoothDevice.java |
@@ -6,6 +6,7 @@ package org.chromium.device.bluetooth; |
import android.annotation.TargetApi; |
import android.bluetooth.BluetoothDevice; |
+import android.content.Context; |
import android.os.Build; |
import android.os.ParcelUuid; |
@@ -26,10 +27,14 @@ import java.util.List; |
final class ChromeBluetoothDevice { |
private static final String TAG = "cr.Bluetooth"; |
- private final Wrappers.BluetoothDeviceWrapper mDevice; |
+ private long mNativeBluetoothDeviceAndroid; |
+ final Wrappers.BluetoothDeviceWrapper mDevice; |
private List<ParcelUuid> mUuidsFromScan; |
+ Wrappers.BluetoothGattWrapper mBluetoothGatt; |
- private ChromeBluetoothDevice(Wrappers.BluetoothDeviceWrapper deviceWrapper) { |
+ private ChromeBluetoothDevice( |
+ long nativeBluetoothDeviceAndroid, Wrappers.BluetoothDeviceWrapper deviceWrapper) { |
+ mNativeBluetoothDeviceAndroid = nativeBluetoothDeviceAndroid; |
mDevice = deviceWrapper; |
Log.v(TAG, "ChromeBluetoothDevice created."); |
} |
@@ -41,8 +46,10 @@ final class ChromeBluetoothDevice { |
// 'Object' type must be used because inner class Wrappers.BluetoothDeviceWrapper reference is |
// not handled by jni_generator.py JavaToJni. http://crbug.com/505554 |
@CalledByNative |
- private static ChromeBluetoothDevice create(Object deviceWrapper) { |
- return new ChromeBluetoothDevice((Wrappers.BluetoothDeviceWrapper) deviceWrapper); |
+ private static ChromeBluetoothDevice create( |
+ long nativeBluetoothDeviceAndroid, Object deviceWrapper) { |
+ return new ChromeBluetoothDevice( |
+ nativeBluetoothDeviceAndroid, (Wrappers.BluetoothDeviceWrapper) deviceWrapper); |
} |
// Implements BluetoothDeviceAndroid::UpdateAdvertisedUUIDs. |
@@ -89,9 +96,49 @@ final class ChromeBluetoothDevice { |
return string_array; |
} |
+ // Implements BluetoothDeviceAndroid::CreateGattConnectionImpl. |
+ @CalledByNative |
+ private boolean createGattConnectionImpl(Context context) { |
+ if (mBluetoothGatt == null) { |
+ Log.i(TAG, "connectGatt"); |
Jeffrey Yasskin
2015/08/20 21:35:13
Do we still need all this logging?
scheib
2015/09/13 02:41:01
I've reduced some and filed crbug.com/529510 to re
|
+ mBluetoothGatt = mDevice.connectGatt( |
+ context, false /* autoConnect */, new BluetoothGattCallbackImpl()); |
+ } |
+ boolean connectResult = mBluetoothGatt.connect(); |
Jeffrey Yasskin
2015/08/20 21:35:13
Calling .connect() appears to ask Android to conne
scheib
2015/09/13 02:41:01
So, autoconnect=true isn't working on devices I'm
|
+ Log.i(TAG, "BluetoothGatt.connect returned %b", connectResult); |
+ return connectResult; |
+ } |
+ |
+ // Implements BluetoothDeviceAndroid::DisconnectGatt. |
+ @CalledByNative |
+ private void disconnectGatt() { |
+ Log.i(TAG, "BluetoothGatt.disconnect"); |
+ mBluetoothGatt.disconnect(); |
+ } |
+ |
// Implements BluetoothDeviceAndroid::GetDeviceName. |
@CalledByNative |
private String getDeviceName() { |
return mDevice.getName(); |
} |
+ |
+ // Implements callbacks related to a GATT connection. |
+ private class BluetoothGattCallbackImpl extends Wrappers.BluetoothGattCallbackWrapper { |
+ @Override |
+ public void onConnectionStateChange(int status, int newState) { |
+ Log.i(TAG, "onConnectionStateChange status:%d newState:%s", status, |
+ (newState == android.bluetooth.BluetoothProfile.STATE_CONNECTED) |
+ ? "Connected" |
+ : "Dissconnected"); |
Jeffrey Yasskin
2015/08/20 21:35:13
sp: Dissconnected
scheib
2015/09/13 02:41:01
Done.
|
+ nativeOnConnectionStateChange(mNativeBluetoothDeviceAndroid, status, |
+ newState == android.bluetooth.BluetoothProfile.STATE_CONNECTED); |
+ } |
+ } |
+ |
+ // --------------------------------------------------------------------------------------------- |
+ // BluetoothAdapterDevice C++ methods declared for access from java: |
+ |
+ // Binds to BluetoothDeviceAndroid::OnConnectionStateChange. |
+ private native void nativeOnConnectionStateChange( |
+ long nativeBluetoothDeviceAndroid, int success, boolean connected); |
Jeffrey Yasskin
2015/08/20 21:35:13
s/success/status/
scheib
2015/09/13 02:41:01
Done.
|
} |