BluetoothMidi: Remove unsafe code
In ag/16192242, several functions in Bluetooth relating to characteristics were marked as unsafe and new ones were added. This CL is meant to conform with these standards and potentially remove a long standing bug. Bug: 146385555 Test: Added Identity Reply/Request code to MIDIMatrix and tested with Yamaha MD-BT01 for Android T->T, T->R, R->T Change-Id: I07311296509d4d042fc92aec327f40993d2e6f54
This commit is contained in:
parent
98e13945e0
commit
6d9c9dcb5b
@ -150,6 +150,7 @@ public final class BluetoothMidiDevice {
|
||||
@Override
|
||||
public void onCharacteristicRead(BluetoothGatt gatt,
|
||||
BluetoothGattCharacteristic characteristic,
|
||||
byte[] value,
|
||||
int status) {
|
||||
Log.d(TAG, "onCharacteristicRead " + status);
|
||||
|
||||
@ -164,8 +165,8 @@ public final class BluetoothMidiDevice {
|
||||
BluetoothGattDescriptor descriptor = characteristic.getDescriptor(
|
||||
CLIENT_CHARACTERISTIC_CONFIG);
|
||||
if (descriptor != null) {
|
||||
descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
|
||||
boolean result = mBluetoothGatt.writeDescriptor(descriptor);
|
||||
int result = mBluetoothGatt.writeDescriptor(descriptor,
|
||||
BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
|
||||
Log.d(TAG, "writeDescriptor returned " + result);
|
||||
} else {
|
||||
Log.e(TAG, "No CLIENT_CHARACTERISTIC_CONFIG for device " + mBluetoothDevice);
|
||||
@ -184,12 +185,13 @@ public final class BluetoothMidiDevice {
|
||||
|
||||
@Override
|
||||
public void onCharacteristicChanged(BluetoothGatt gatt,
|
||||
BluetoothGattCharacteristic characteristic) {
|
||||
BluetoothGattCharacteristic characteristic,
|
||||
byte[] value) {
|
||||
if (DEBUG) {
|
||||
logByteArray("Received ", characteristic.getValue(), 0,
|
||||
characteristic.getValue().length);
|
||||
logByteArray("Received BLE packet", value, 0,
|
||||
value.length);
|
||||
}
|
||||
mPacketDecoder.decodePacket(characteristic.getValue(), mOutputReceiver);
|
||||
mPacketDecoder.decodePacket(value, mOutputReceiver);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -227,17 +229,14 @@ public final class BluetoothMidiDevice {
|
||||
mCachedBuffer = new byte[count];
|
||||
}
|
||||
System.arraycopy(buffer, 0, mCachedBuffer, 0, count);
|
||||
if (!mCharacteristic.setValue(mCachedBuffer)) {
|
||||
Log.w(TAG, "could not set characteristic value");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (DEBUG) {
|
||||
logByteArray("Sent ", mCharacteristic.getValue(), 0,
|
||||
mCharacteristic.getValue().length);
|
||||
}
|
||||
|
||||
if (!mBluetoothGatt.writeCharacteristic(mCharacteristic)) {
|
||||
if (mBluetoothGatt.writeCharacteristic(mCharacteristic, mCachedBuffer,
|
||||
mCharacteristic.getWriteType()) != BluetoothGatt.GATT_SUCCESS) {
|
||||
Log.w(TAG, "could not write characteristic to Bluetooth GATT");
|
||||
return false;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user