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

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

Issue 1574773002: bluetooth: android: Initial basic Descriptors implementation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bta-code-cleanup-
Patch Set: addressed j again Created 4 years, 11 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 bc018c678425439a321b20012a2aab6f4e442be7..ea78782289a1b4175dd618246e4a5d075fe54241 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
@@ -11,6 +11,7 @@ import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCallback;
import android.bluetooth.BluetoothGattCharacteristic;
+import android.bluetooth.BluetoothGattDescriptor;
import android.bluetooth.BluetoothGattService;
import android.bluetooth.le.BluetoothLeScanner;
import android.bluetooth.le.ScanCallback;
@@ -251,11 +252,15 @@ class Wrappers {
private final BluetoothDevice mDevice;
private final HashMap<BluetoothGattCharacteristic, BluetoothGattCharacteristicWrapper>
mCharacteristicsToWrappers;
+ private final HashMap<BluetoothGattDescriptor, BluetoothGattDescriptorWrapper>
+ mDescriptorsToWrappers;
public BluetoothDeviceWrapper(BluetoothDevice device) {
mDevice = device;
mCharacteristicsToWrappers =
new HashMap<BluetoothGattCharacteristic, BluetoothGattCharacteristicWrapper>();
+ mDescriptorsToWrappers =
+ new HashMap<BluetoothGattDescriptor, BluetoothGattDescriptorWrapper>();
}
public BluetoothGattWrapper connectGatt(
@@ -410,7 +415,8 @@ class Wrappers {
BluetoothGattCharacteristicWrapper characteristicWrapper =
mDeviceWrapper.mCharacteristicsToWrappers.get(characteristic);
if (characteristicWrapper == null) {
- characteristicWrapper = new BluetoothGattCharacteristicWrapper(characteristic);
+ characteristicWrapper =
+ new BluetoothGattCharacteristicWrapper(characteristic, mDeviceWrapper);
mDeviceWrapper.mCharacteristicsToWrappers.put(
characteristic, characteristicWrapper);
}
@@ -432,10 +438,31 @@ class Wrappers {
* Wraps android.bluetooth.BluetoothGattCharacteristic.
*/
static class BluetoothGattCharacteristicWrapper {
- private final BluetoothGattCharacteristic mCharacteristic;
+ final BluetoothGattCharacteristic mCharacteristic;
+ final BluetoothDeviceWrapper mDeviceWrapper;
- public BluetoothGattCharacteristicWrapper(BluetoothGattCharacteristic characteristic) {
+ public BluetoothGattCharacteristicWrapper(
+ BluetoothGattCharacteristic characteristic, BluetoothDeviceWrapper deviceWrapper) {
mCharacteristic = characteristic;
+ mDeviceWrapper = deviceWrapper;
+ }
+
+ public List<BluetoothGattDescriptorWrapper> getDescriptors() {
+ List<BluetoothGattDescriptor> descriptors = mCharacteristic.getDescriptors();
+
+ ArrayList<BluetoothGattDescriptorWrapper> descriptorsWrapped =
+ new ArrayList<BluetoothGattDescriptorWrapper>(descriptors.size());
+
+ for (BluetoothGattDescriptor descriptor : descriptors) {
+ BluetoothGattDescriptorWrapper descriptorWrapper =
+ mDeviceWrapper.mDescriptorsToWrappers.get(descriptor);
+ if (descriptorWrapper == null) {
+ descriptorWrapper = new BluetoothGattDescriptorWrapper(descriptor);
+ mDeviceWrapper.mDescriptorsToWrappers.put(descriptor, descriptorWrapper);
+ }
+ descriptorsWrapped.add(descriptorWrapper);
+ }
+ return descriptorsWrapped;
}
public int getInstanceId() {
@@ -458,4 +485,19 @@ class Wrappers {
return mCharacteristic.setValue(value);
}
}
+
+ /**
+ * Wraps android.bluetooth.BluetoothGattDescriptor.
+ */
+ static class BluetoothGattDescriptorWrapper {
+ private final BluetoothGattDescriptor mDescriptor;
+
+ public BluetoothGattDescriptorWrapper(BluetoothGattDescriptor descriptor) {
+ mDescriptor = descriptor;
+ }
+
+ public UUID getUuid() {
+ return mDescriptor.getUuid();
+ }
+ }
}

Powered by Google App Engine
This is Rietveld 408576698