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

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

Issue 1256313002: bluetooth: android: Implement & test CreateGattConnection. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Split tests up into smaller tests Created 5 years, 3 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..890bdd82f232ab1dd8f74173f1b5c31859398e3d 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,11 +27,17 @@ import java.util.List;
final class ChromeBluetoothDevice {
private static final String TAG = "cr.Bluetooth";
- private final Wrappers.BluetoothDeviceWrapper mDevice;
+ private final long mNativeBluetoothDeviceAndroid;
+ final Wrappers.BluetoothDeviceWrapper mDevice;
private List<ParcelUuid> mUuidsFromScan;
+ Wrappers.BluetoothGattWrapper mBluetoothGatt;
+ private final BluetoothGattCallbackImpl mBluetoothGattCallbackImpl;
- private ChromeBluetoothDevice(Wrappers.BluetoothDeviceWrapper deviceWrapper) {
+ private ChromeBluetoothDevice(
+ long nativeBluetoothDeviceAndroid, Wrappers.BluetoothDeviceWrapper deviceWrapper) {
+ mNativeBluetoothDeviceAndroid = nativeBluetoothDeviceAndroid;
mDevice = deviceWrapper;
+ mBluetoothGattCallbackImpl = new BluetoothGattCallbackImpl();
Log.v(TAG, "ChromeBluetoothDevice created.");
}
@@ -41,8 +48,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 +98,46 @@ final class ChromeBluetoothDevice {
return string_array;
}
+ // Implements BluetoothDeviceAndroid::CreateGattConnectionImpl.
+ @CalledByNative
+ private void createGattConnectionImpl(Context context) {
+ Log.i(TAG, "connectGatt");
+ // autoConnect set to false as under experimentation using autoConnect failed to complete
+ // connections.
+ mBluetoothGatt =
+ mDevice.connectGatt(context, false /* autoConnect */, mBluetoothGattCallbackImpl);
+ }
+
+ // 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"
+ : "Disconnected");
+ 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 status, boolean connected);
}
« 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