Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.device.bluetooth; | 5 package org.chromium.device.bluetooth; |
| 6 | 6 |
| 7 import android.annotation.TargetApi; | 7 import android.annotation.TargetApi; |
| 8 import android.os.Build; | 8 import android.os.Build; |
| 9 | 9 |
| 10 import org.chromium.base.Log; | 10 import org.chromium.base.Log; |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 141 private boolean setCharacteristicNotification(boolean enabled) { | 141 private boolean setCharacteristicNotification(boolean enabled) { |
| 142 return mChromeDevice.mBluetoothGatt.setCharacteristicNotification(mChara cteristic, enabled); | 142 return mChromeDevice.mBluetoothGatt.setCharacteristicNotification(mChara cteristic, enabled); |
| 143 } | 143 } |
| 144 | 144 |
| 145 // Creates objects for all descriptors. Designed only to be called by | 145 // Creates objects for all descriptors. Designed only to be called by |
| 146 // BluetoothRemoteGattCharacteristicAndroid::EnsureDescriptorsCreated. | 146 // BluetoothRemoteGattCharacteristicAndroid::EnsureDescriptorsCreated. |
| 147 @CalledByNative | 147 @CalledByNative |
| 148 private void createDescriptors() { | 148 private void createDescriptors() { |
| 149 List<Wrappers.BluetoothGattDescriptorWrapper> descriptors = | 149 List<Wrappers.BluetoothGattDescriptorWrapper> descriptors = |
| 150 mCharacteristic.getDescriptors(); | 150 mCharacteristic.getDescriptors(); |
| 151 // descriptorInstanceId ensures duplicate UUIDs have unique instance | |
| 152 // IDs. BluetoothGattDescriptor does not offer getInstanceId the way | |
| 153 // BluetoothGattCharacteristic does. | |
| 154 // | |
| 155 // TODO(crbug.com/576906) Do not reuse IDs upon onServicesDiscovered. | |
| 156 int instanceIdCounter = 0; | |
| 151 for (Wrappers.BluetoothGattDescriptorWrapper descriptor : descriptors) { | 157 for (Wrappers.BluetoothGattDescriptorWrapper descriptor : descriptors) { |
| 152 // Create an adapter unique descriptor ID. | 158 String descriptorInstanceId = mInstanceId + "/" + instanceIdCounter+ +; |
|
ortuno
2016/03/13 20:41:44
Hmm I wonder if we should include the UUID. I thin
scheib
2016/03/25 00:13:57
Done: Including the UUID.
| |
| 153 // TODO(crbug.com/576900) Unique descriptorInstanceId duplicate UUID values. | |
| 154 String descriptorInstanceId = mInstanceId + "/" + descriptor.getUuid ().toString(); | |
| 155 nativeCreateGattRemoteDescriptor(mNativeBluetoothRemoteGattCharacter isticAndroid, | 159 nativeCreateGattRemoteDescriptor(mNativeBluetoothRemoteGattCharacter isticAndroid, |
| 156 descriptorInstanceId, descriptor, mChromeDevice); | 160 descriptorInstanceId, descriptor, mChromeDevice); |
| 157 } | 161 } |
| 158 } | 162 } |
| 159 | 163 |
| 160 // ------------------------------------------------------------------------- -------------------- | 164 // ------------------------------------------------------------------------- -------------------- |
| 161 // BluetoothAdapterDevice C++ methods declared for access from java: | 165 // BluetoothAdapterDevice C++ methods declared for access from java: |
| 162 | 166 |
| 163 // Binds to BluetoothRemoteGattCharacteristicAndroid::OnChanged. | 167 // Binds to BluetoothRemoteGattCharacteristicAndroid::OnChanged. |
| 164 native void nativeOnChanged(long nativeBluetoothRemoteGattCharacteristicAndr oid, byte[] value); | 168 native void nativeOnChanged(long nativeBluetoothRemoteGattCharacteristicAndr oid, byte[] value); |
| 165 | 169 |
| 166 // Binds to BluetoothRemoteGattCharacteristicAndroid::OnRead. | 170 // Binds to BluetoothRemoteGattCharacteristicAndroid::OnRead. |
| 167 native void nativeOnRead( | 171 native void nativeOnRead( |
| 168 long nativeBluetoothRemoteGattCharacteristicAndroid, int status, byt e[] value); | 172 long nativeBluetoothRemoteGattCharacteristicAndroid, int status, byt e[] value); |
| 169 | 173 |
| 170 // Binds to BluetoothRemoteGattCharacteristicAndroid::OnWrite. | 174 // Binds to BluetoothRemoteGattCharacteristicAndroid::OnWrite. |
| 171 native void nativeOnWrite(long nativeBluetoothRemoteGattCharacteristicAndroi d, int status); | 175 native void nativeOnWrite(long nativeBluetoothRemoteGattCharacteristicAndroi d, int status); |
| 172 | 176 |
| 173 // Binds to BluetoothRemoteGattCharacteristicAndroid::CreateGattRemoteDescri ptor. | 177 // Binds to BluetoothRemoteGattCharacteristicAndroid::CreateGattRemoteDescri ptor. |
| 174 // TODO(http://crbug.com/505554): Replace 'Object' with specific type when J NI fixed. | 178 // TODO(http://crbug.com/505554): Replace 'Object' with specific type when J NI fixed. |
| 175 private native void nativeCreateGattRemoteDescriptor( | 179 private native void nativeCreateGattRemoteDescriptor( |
| 176 long nativeBluetoothRemoteGattCharacteristicAndroid, String instance Id, | 180 long nativeBluetoothRemoteGattCharacteristicAndroid, String instance Id, |
| 177 Object bluetoothGattDescriptorWrapper, Object chromeBluetoothDevice) ; | 181 Object bluetoothGattDescriptorWrapper, Object chromeBluetoothDevice) ; |
| 178 } | 182 } |
| OLD | NEW |