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

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: 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
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..8214515472bcca3d27e42e7fe0089998efbdf6bf 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 ForwardBluetoothGattCallbackToWrapper(callback)));
+ }
+
public String getAddress() {
return mDevice.getAddress();
}
@@ -241,4 +249,52 @@ class Wrappers {
return mDevice.getName();
}
}
+
+ /**
+ * Wraps android.bluetooth.BluetoothGatt.
+ */
+ static class BluetoothGattWrapper {
+ private final BluetoothGatt mGatt;
+
+ BluetoothGattWrapper(BluetoothGatt gatt) {
+ mGatt = gatt;
+ }
+
+ public void disconnect() {
+ mGatt.disconnect();
+ }
+ }
+
+ /**
+ * Implements android.bluetooth.BluetoothGattCallback and forwards calls through
+ * to a provided BluetoothGattCallbackWrapper 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 ForwardBluetoothGattCallbackToWrapper extends BluetoothGattCallback {
+ final BluetoothGattCallbackWrapper mWrapperCallback;
+
+ ForwardBluetoothGattCallbackToWrapper(BluetoothGattCallbackWrapper wrapperCallback) {
+ mWrapperCallback = wrapperCallback;
+ }
+
+ @Override
+ public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
+ mWrapperCallback.onConnectionStateChange(status, newState);
+ }
+ }
+
+ /**
+ * Wrapper alternative to android.bluetooth.BluetoothGattCallback allowing clients and Fakes to
+ * work on older SDK versions without having a dependency on the class not defined there.
+ *
+ * BluetoothGatt gatt parameters are omitted from methods as each call would
+ * need to wrap them in a BluetoothGattWrapper. Client code should cache the
+ * BluetoothGattWrapper provided on the initial BluetoothDeviceWrapper.connectGatt call.
+ */
+ abstract static class BluetoothGattCallbackWrapper {
+ public abstract void onConnectionStateChange(int status, int newState);
+ }
}

Powered by Google App Engine
This is Rietveld 408576698