Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android BLE onConnectionUpdated()

I'm currently trying to determine the current BLE connection interval within an Android app targeting API 27. All documentation that I've found (including many SO questions) has said that this is currently impossible, however, when running my application in debug mode, the following console message appears:

D/BluetoothGatt: onConnectionUpdated() - Device=XX:XX:XX:XX:XX:XX interval=9 latency=0 timeout=600 status=0

Unfortunately I cannot find this callback within the docs. Am I correct in assuming that this callback isn't exposed? If so, is there any way for me to access the current connection interval?

Thanks.

like image 789
amitchone Avatar asked Oct 11 '18 09:10

amitchone


1 Answers

Below is the source code for onConnectionUpdated


            /**
             * Callback invoked when the given connection is updated
             * @hide
             */
            @Override
            public void onConnectionUpdated(String address, int interval, int latency,
                    int timeout, int status) {
                if (DBG) {
                    Log.d(TAG, "onConnectionUpdated() - Device=" + address
                            + " interval=" + interval + " latency=" + latency
                            + " timeout=" + timeout + " status=" + status);
                }
                if (!address.equals(mDevice.getAddress())) {
                    return;
                }
                runOrQueueCallback(new Runnable() {
                    @Override
                    public void run() {
                        final BluetoothGattCallback callback = mCallback;
                        if (callback != null) {
                            callback.onConnectionUpdated(BluetoothGatt.this, interval, latency,
                                    timeout, status);
                        }
                    }
                });
            }

You can file the complete source code in BluetoothGatt.java


Additionally on source code on the server is

 /**
 * Callback indicating the connection parameters were updated.
 *
 * @param device The remote device involved
 * @param interval Connection interval used on this connection, 1.25ms unit. Valid range is from
 * 6 (7.5ms) to 3200 (4000ms).
 * @param latency Slave latency for the connection in number of connection events. Valid range
 * is from 0 to 499
 * @param timeout Supervision timeout for this connection, in 10ms unit. Valid range is from 10
 * (0.1s) to 3200 (32s)
 * @param status {@link BluetoothGatt#GATT_SUCCESS} if the connection has been updated
 * successfully
 * @hide
 */
public void onConnectionUpdated(BluetoothDevice device, int interval, int latency, int timeout,
        int status) {
}

This can be found at BluetoothGattServerCallback.java

like image 150
Mahendra Gunawardena Avatar answered Oct 21 '22 09:10

Mahendra Gunawardena