Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1f99a327 authored by Phil Burk's avatar Phil Burk
Browse files

BluetoothMidi: request higher priority, for lower latency



Request a higher connection priority.
This will result in a Connection Interval below 15 msec
vs 45 msec for some devices.

Fix: 34710538
Test: Connect a BLE-MIDI device using the MIDI+BTLE test app. See bug.
Change-Id: I846a76a36c864f82969173a94d86b05059a786ad
Signed-off-by: default avatarPhil Burk <philburk@google.com>
parent 3a543a1b
Loading
Loading
Loading
Loading
+20 −20
Original line number Diff line number Diff line
@@ -100,8 +100,8 @@ public final class BluetoothMidiDevice {
                int newState) {
            String intentAction;
            if (newState == BluetoothProfile.STATE_CONNECTED) {
                Log.i(TAG, "Connected to GATT server.");
                Log.i(TAG, "Attempting to start service discovery:" +
                Log.d(TAG, "Connected to GATT server.");
                Log.d(TAG, "Attempting to start service discovery:" +
                        mBluetoothGatt.discoverServices());
            } else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
                Log.i(TAG, "Disconnected from GATT server.");
@@ -112,24 +112,24 @@ public final class BluetoothMidiDevice {
        @Override
        public void onServicesDiscovered(BluetoothGatt gatt, int status) {
            if (status == BluetoothGatt.GATT_SUCCESS) {
                List<BluetoothGattService> services = mBluetoothGatt.getServices();
                for (BluetoothGattService service : services) {
                    if (MIDI_SERVICE.equals(service.getUuid())) {
                BluetoothGattService service = gatt.getService(MIDI_SERVICE);
                if (service != null) {
                    Log.d(TAG, "found MIDI_SERVICE");
                        List<BluetoothGattCharacteristic> characteristics
                            = service.getCharacteristics();
                        for (BluetoothGattCharacteristic characteristic : characteristics) {
                            if (MIDI_CHARACTERISTIC.equals(characteristic.getUuid())) {
                    BluetoothGattCharacteristic characteristic
                            = service.getCharacteristic(MIDI_CHARACTERISTIC);
                    if (characteristic != null) {
                        Log.d(TAG, "found MIDI_CHARACTERISTIC");
                        mCharacteristic = characteristic;

                        // Request a lower Connection Interval for better latency.
                        boolean result = gatt.requestConnectionPriority(
                                BluetoothGatt.CONNECTION_PRIORITY_HIGH);
                        Log.d(TAG, "requestConnectionPriority(CONNECTION_PRIORITY_HIGH):"
                            + result);

                        // Specification says to read the characteristic first and then
                        // switch to receiving notifications
                        mBluetoothGatt.readCharacteristic(characteristic);
                                break;
                            }
                        }
                        break;
                    }
                }
            } else {