-
Notifications
You must be signed in to change notification settings - Fork 583
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Android 14 breaking change #843
Comments
Do you have some example for setMaxBatchSize(512 ? |
Example from green_android @Override public int write(final byte[] bytes) { this.disposable.add(this.connection .flatMap(rxConn -> rxConn.createNewLongWriteBuilder() .setMaxBatchSize(512) .setCharacteristicUuid(IO_TX_CHAR_UUID) .setBytes(bytes) .build()) .subscribe(this::onBytesSent, this::onSendFailure) ); return bytes.length; } |
The work-around doesn't work in Android 14, using this .setMaxBatchSize(512) shows no effect for me, any solution for this yet? |
@sravan-wellnesys keep in mind that this change is for writing to BLE device. Be sure that the BLE device also respect the spec. |
Can you please explain what exactly needs to be done, as I check this https://issuetracker.google.com/issues/307234027, Android 14 is by default requesting MTU 517, So should we update our peripheral device to respond to MTU 517 or By doing what you said .setMaxBatchSize(512) and configure our peripheral device to respond to MTU 512 even if Android 14 requests MTU 517? Btw, this is what I am getting in logs:
Thanks for your time. |
Your device should respond to MTU request with the value 517, but the actual payload you send must be 512 bytes at maximum. If the device sends more that 512 bytes, from my experience, Android will silently drop the packet. On my case i had to firmware update my BLE device to send max 512 bytes, and my Android app to send max 512 bytes. Explanation: From the issue:
|
Thanks a lot for your explanation, Is there a way that I don't send a value in requestMTU?, Do Android 14 still request 517 even if I don't specify a size in request instead of the default 23 bytes. |
Just don't call requestMTU at all. From the issue:
|
Yep, I am not receiving any bytes, not using requestMTU at all like you said. No data transfer is happening. So firmware upgrade is the only solution at this point? Btw my peripheral device is using Bluetooth 4.2. |
I think so. |
I tried with Android 12, When Mtu - 512, I get 509 bytes, when Mtu size - 517, I receive 514 bytes, I thought the max was 512. So app issue or device issue? |
I think is device issue that needs a fix with firmware update, the device should not send more than 512 bytes. |
So anything more than 512 does not work for Android 14, but works for the previous versions? |
Correct, Android 14 is more strict following more strictly the version 5.2 of the Bluetooth Core. |
This is a problem that the library can fix on its side — that is fix the LongWriteOperation (which btw. does not use Prepared Write but chunks data on the application side) to send maximum of 512 bytes of data on Android 13 and above. That way people will not get caught by surprise when using LongWriteOperationBuilder's default chunk size. WDYT? |
Android 14 introduced a breaking change related to MTU negotiation.
This breaking change it may even require a firmware upgrade on the device to properly support the BLE spec in a more strict way.
On the library side, if you try to write more than 512 bytes using the
LongWriteOperationBuilder
, the write fails silently.By default the following method is used to calculate the batch size.
On Android 14 the call to
rxBleConnection.getMtu()
returns 517.517 - 3 (GATT_WRITE_MTU_OVERHEAD) = 514 which is larger than the accepted 512.
Based on this very informative issue ticket MTU Overhead should be 5.
As a work around you can use
setMaxBatchSize(512)
when creating theLongWriteOperationBuilder
to use theConstantPayloadSizeLimit
implementation instead of the defaultMtuBasedPayloadSizeLimit
.The text was updated successfully, but these errors were encountered: