GithubHelp home page GithubHelp logo

Android 14 breaking change about rxandroidble HOT 15 OPEN

angelix avatar angelix commented on June 4, 2024
Android 14 breaking change

from rxandroidble.

Comments (15)

e-Joe avatar e-Joe commented on June 4, 2024

Do you have some example for setMaxBatchSize(512 ?

from rxandroidble.

angelix avatar angelix commented on June 4, 2024

@e-Joe

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;
    }

from rxandroidble.

sravan-wellnesys avatar sravan-wellnesys commented on June 4, 2024

The work-around doesn't work in Android 14, using this .setMaxBatchSize(512) shows no effect for me, any solution for this yet?

from rxandroidble.

angelix avatar angelix commented on June 4, 2024

@sravan-wellnesys keep in mind that this change is for writing to BLE device. Be sure that the BLE device also respect the spec.

from rxandroidble.

sravan-wellnesys avatar sravan-wellnesys commented on June 4, 2024

@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:

packages/modules/Bluetooth/system/stack/gatt/gatt_api.cc:768 GATTC_TryMtuRequest: **:**:**:**:49:fe conn_id=0x000d 2023-12-05 17:54:21.669 15046-15098 bluetooth com.google.android.bluetooth I packages/modules/Bluetooth/system/stack/gatt/gatt_api.cc:728 GATTC_ConfigureMTU: Configuring ATT mtu size conn_id:13 mtu:517 user mtu 512 2023-12-05 17:54:21.684 15046-15098 bluetooth com.google.android.bluetooth I packages/modules/Bluetooth/system/stack/gatt/gatt_cl.cc:1113 gatt_process_mtu_rsp: Local pending MTU 512, Remote (**:**:**:**:49:fe) MTU 517 2023-12-05 17:54:21.684 15046-15098 bluetooth com.google.android.bluetooth I packages/modules/Bluetooth/system/stack/gatt/gatt_cl.cc:1133 gatt_process_mtu_rsp: MTU Exchange resulted in: 517 2023-12-05 17:54:21.684 15046-15098 bt_btm_ble com.google.android.bluetooth I packages/modules/Bluetooth/system/stack/btm/btm_ble.cc:619 BTM_SetBleDataLength: xx:xx:xx:xx:49:fe, 516

[ERROR:gatt_cl.cc(693)] value.len larger than GATT_MAX_ATTR_LEN, discard

Thanks for your time.

from rxandroidble.

angelix avatar angelix commented on June 4, 2024

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?

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:
MTU size includes the header size. The header can be from 3-5 bytes, but you should not really care about that. The crucial part is not to send more that 512 byte.

From the issue:

A deeper reason is that the Bluetooth Specification allows the maximum size of an ATT attribute to be 512 bytes and the largest command ATT_PREPARE_WRITE_REQ has 5 bytes of header. Hence 512 + 5 = 517.
The packet data itself should never exceed 512 as per the Bluetooth spec.

from rxandroidble.

sravan-wellnesys avatar sravan-wellnesys commented on June 4, 2024

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?

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: MTU size includes the header size. The header can be from 3-5 bytes, but you should not really care about that. The crucial part is not to send more that 512 byte.

From the issue:

A deeper reason is that the Bluetooth Specification allows the maximum size of an ATT attribute to be 512 bytes and the largest command ATT_PREPARE_WRITE_REQ has 5 bytes of header. Hence 512 + 5 = 517.
The packet data itself should never exceed 512 as per the Bluetooth spec.

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.

from rxandroidble.

angelix avatar angelix commented on June 4, 2024

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:

requestMTU(23) has the same effect as not calling requestMTU() at all, in that case the default MTU of 23 bytes will be used.

from rxandroidble.

sravan-wellnesys avatar sravan-wellnesys commented on June 4, 2024

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:

requestMTU(23) has the same effect as not calling requestMTU() at all, in that case the default MTU of 23 bytes will be used.

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.

from rxandroidble.

angelix avatar angelix commented on June 4, 2024

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:

requestMTU(23) has the same effect as not calling requestMTU() at all, in that case the default MTU of 23 bytes will be used.

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.
Try using a different android version and see the size of data the device is sending. If it's more than 512, you can be sure that's your issue.

from rxandroidble.

sravan-wellnesys avatar sravan-wellnesys commented on June 4, 2024

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:

requestMTU(23) has the same effect as not calling requestMTU() at all, in that case the default MTU of 23 bytes will be used.

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. Try using a different android version and see the size of data the device is sending. If it's more than 512, you can be sure that's your issue.

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?

from rxandroidble.

angelix avatar angelix commented on June 4, 2024

I think is device issue that needs a fix with firmware update, the device should not send more than 512 bytes.

from rxandroidble.

sravan-wellnesys avatar sravan-wellnesys commented on June 4, 2024

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?

from rxandroidble.

angelix avatar angelix commented on June 4, 2024

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.

from rxandroidble.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.