Re: [web-bluetooth] API which provides the negotiated MTU is required (#383)

Last time I checked, Android will automatically send the onMtuChanged callback immediately after onConnectionStateChange (when indicating connected), if there is already an established MTU. This can for example happen when another app on the phone is already connected and the MTU exchange has already taken place. The documentation for onMtuChanged indeeds hints this can happen.

In this case, to be able to distinguish this automatic callback from a manual one triggered as a response to requestMtu, and to not accidentally executing more than one request in parallel (which Android doesn't like), a flow that works is to do the following:

1. After onConnectionStateChange indicates the connection is complete, start a service discovery.
2. Now, either onMtuChanged will be called first or onServicesDiscovered will be called first.
3. If onMtuChanged is called first, note down this MTU value and use it for the rest of the connection.
4. If onServicesDiscovered is called first, only in this case send requestMtu. First when onMtuChanged has been called, Android's Bluetooth stack will start to request other GATT operations. (Sending requests while an MTU request is pending will fail).

-- 
GitHub Notification of comment by Emill
Please view or discuss this issue at https://github.com/WebBluetoothCG/web-bluetooth/issues/383#issuecomment-960997255 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Thursday, 4 November 2021 14:01:58 UTC