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

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

Issue 2499913002: bluetooth: android: Implement RetrieveGattConnectedDevicesWithFilter
Patch Set: Comment why BluetoothDeviceWrapper is in a separate file Created 4 years, 1 month 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/BluetoothDeviceWrapper.java
diff --git a/device/bluetooth/android/java/src/org/chromium/device/bluetooth/BluetoothDeviceWrapper.java b/device/bluetooth/android/java/src/org/chromium/device/bluetooth/BluetoothDeviceWrapper.java
new file mode 100644
index 0000000000000000000000000000000000000000..39cbfcc80a9550a0a894d98c5da20321f0a8b002
--- /dev/null
+++ b/device/bluetooth/android/java/src/org/chromium/device/bluetooth/BluetoothDeviceWrapper.java
@@ -0,0 +1,77 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.device.bluetooth;
+
+import android.annotation.TargetApi;
+import android.bluetooth.BluetoothDevice;
+import android.bluetooth.BluetoothGattCharacteristic;
+import android.bluetooth.BluetoothGattDescriptor;
+import android.content.Context;
+import android.os.Build;
+import android.os.ParcelUuid;
+
+import org.chromium.base.annotations.JNINamespace;
+
+import java.util.HashMap;
+
+/**
+ * Wraps android.bluetooth.BluetoothDevice. See Wrappers.java for the rest of the wrappers.
+ * BluetoothDeviceWrapper is in its own file because jni cannot direclty use the nested class
scheib 2016/11/28 20:42:22 Wrapper.java explains what the concept of a wrappe
+ * for:
+ * @CalledByNative
+ * private DeviceAndUUIDs[] retrieveGattConnectedDevices() {
+ */
+@JNINamespace("device")
scheib 2016/11/28 20:42:22 This class needs JNINamespace because other classe
+@TargetApi(Build.VERSION_CODES.LOLLIPOP)
+class BluetoothDeviceWrapper {
scheib 2016/11/28 20:42:22 Can this still be "static class"?
+ public static final int DEVICE_CLASS_UNSPECIFIED = 0x1F00;
+
+ private final BluetoothDevice mDevice;
+ final HashMap<BluetoothGattCharacteristic, Wrappers.BluetoothGattCharacteristicWrapper>
+ mCharacteristicsToWrappers;
+ final HashMap<BluetoothGattDescriptor, Wrappers.BluetoothGattDescriptorWrapper>
+ mDescriptorsToWrappers;
+
+ public BluetoothDeviceWrapper(BluetoothDevice device) {
+ mDevice = device;
+ mCharacteristicsToWrappers = new HashMap<BluetoothGattCharacteristic,
+ Wrappers.BluetoothGattCharacteristicWrapper>();
+ mDescriptorsToWrappers =
+ new HashMap<BluetoothGattDescriptor, Wrappers.BluetoothGattDescriptorWrapper>();
+ }
+
+ public Wrappers.BluetoothGattWrapper connectGatt(
+ Context context, boolean autoConnect, Wrappers.BluetoothGattCallbackWrapper callback) {
+ return new Wrappers.BluetoothGattWrapper(
+ mDevice.connectGatt(context, autoConnect,
+ new Wrappers.ForwardBluetoothGattCallbackToWrapper(callback, this)),
+ this);
+ }
+
+ public String getAddress() {
+ return mDevice.getAddress();
+ }
+
+ public int getBluetoothClass_getDeviceClass() {
+ if (mDevice == null || mDevice.getBluetoothClass() == null) {
+ // BluetoothDevice.getBluetoothClass() returns null if adapter has been powered off.
+ // Return DEVICE_CLASS_UNSPECIFIED in these cases.
+ return DEVICE_CLASS_UNSPECIFIED;
+ }
+ return mDevice.getBluetoothClass().getDeviceClass();
+ }
+
+ public int getBondState() {
+ return mDevice.getBondState();
+ }
+
+ public String getName() {
+ return mDevice.getName();
+ }
+
+ public ParcelUuid[] getUuids() {
+ return mDevice.getUuids();
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698