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

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

Issue 1256313002: bluetooth: android: Implement & test CreateGattConnection. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updated patchset dependency Created 5 years, 4 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
Index: device/bluetooth/android/java/src/org/chromium/device/bluetooth/Wrappers.java
diff --git a/device/bluetooth/android/java/src/org/chromium/device/bluetooth/Wrappers.java b/device/bluetooth/android/java/src/org/chromium/device/bluetooth/Wrappers.java
index 928d3baf654aacc92ecf66f3e9d4d6ec2579572a..ad8487b135351794974e60a77dc37d90582a6683 100644
--- a/device/bluetooth/android/java/src/org/chromium/device/bluetooth/Wrappers.java
+++ b/device/bluetooth/android/java/src/org/chromium/device/bluetooth/Wrappers.java
@@ -8,6 +8,8 @@ import android.Manifest;
import android.annotation.TargetApi;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
+import android.bluetooth.BluetoothGatt;
+import android.bluetooth.BluetoothGattCallback;
import android.bluetooth.le.BluetoothLeScanner;
import android.bluetooth.le.ScanCallback;
import android.bluetooth.le.ScanFilter;
@@ -225,6 +227,12 @@ class Wrappers {
mDevice = device;
}
+ public BluetoothGattWrapper connectGatt(
+ Context context, boolean autoConnect, BluetoothGattCallbackWrapper callback) {
+ return new BluetoothGattWrapper(mDevice.connectGatt(
+ context, autoConnect, new BluetoothGattCallbackWrapperCaller(callback)));
+ }
+
public String getAddress() {
return mDevice.getAddress();
}
@@ -241,4 +249,57 @@ class Wrappers {
return mDevice.getName();
}
}
+
+ /**
+ * Wraps android.bluetooth.BluetoothGatt.
+ */
+ static class BluetoothGattWrapper {
+ private final BluetoothGatt mGatt;
+
+ BluetoothGattWrapper(BluetoothGatt gatt) {
+ mGatt = gatt;
+ }
+
+ public boolean connect() {
+ return mGatt.connect();
+ }
+
+ public void disconnect() {
+ mGatt.disconnect();
+ }
+ }
+
+ /**
+ * Implements android.bluetooth.BluetoothGattCallback and passes calls through
+ * to a provided BluetoothGattCallback instance.
+ *
+ * This class is required so that Fakes can use BluetoothGattCallbackWrapper
+ * without it extending from BluetoothGattCallback. Fakes must function even on
+ * Android versions where BluetoothGattCallback class is not defined.
+ */
+ static class BluetoothGattCallbackWrapperCaller extends BluetoothGattCallback {
Jeffrey Yasskin 2015/08/20 21:35:13 "CallbackWrapperCaller" is awkward. Maybe ForwardB
scheib 2015/09/13 02:41:01 Done.
+ final BluetoothGattCallbackWrapper mWrapperCallback;
+
+ BluetoothGattCallbackWrapperCaller(BluetoothGattCallbackWrapper wrapperCallback) {
+ mWrapperCallback = wrapperCallback;
+ }
+
+ @Override
+ public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
+ mWrapperCallback.onConnectionStateChange(status, newState);
+ }
+ }
+
+ /**
+ * Wraps android.bluetooth.BluetoothGattCallback, being called by
+ * BluetoothGattCallbackWrapperCaller.
Jeffrey Yasskin 2015/08/20 21:35:13 The "being called by" clause doesn't make a lot of
scheib 2015/09/13 02:41:01 Done.
+ *
+ * BluetoothGatt gatt parameters are omitted from methods as each call would
+ * need to wrapp them in a BluetoothGattWrapper. That would be superfluous given
Jeffrey Yasskin 2015/08/20 21:35:14 sp: wrapp
Jeffrey Yasskin 2015/08/20 21:35:14 BluetoothGattCallback passes the BluetoothGatt obj
scheib 2015/09/13 02:41:01 Done.
scheib 2015/09/13 02:41:01 Done.
+ * that the required initial call to BluetoothDeviceWrapper.connectGatt will
+ * return a BluetoothGattWrapper.
+ */
+ abstract static class BluetoothGattCallbackWrapper {
+ public abstract void onConnectionStateChange(int status, int newState);
+ }
}

Powered by Google App Engine
This is Rietveld 408576698