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

Commit 59c19fa4 authored by Kihong Seong's avatar Kihong Seong
Browse files

Throw error when notification is larger than max attribute value

In BluetoothGattServer.notifyCharacteristicChanged(), throw
IllegalArgumentException when notification is longer than max length of
an attribute value. The max length of an attribute value is defined in
gatt_api.h as 512, and is used here. CTS test for this change is linked
with the same topic to this CL.

Bug: 296145972
Test: atest CtsBluetoothTestCases
Change-Id: I4a810c4efc19460d95de2efe9793f75ad9d61ffe
parent e986f098
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -68,6 +68,8 @@ public final class BluetoothGattServer implements BluetoothProfile {
    private List<BluetoothGattService> mServices;

    private static final int CALLBACK_REG_TIMEOUT = 10000;
    // Max length of an attribute value, defined in gatt_api.h
    private static final int GATT_MAX_ATTR_LEN = 512;

    /**
     * Bluetooth GATT interface callbacks
@@ -829,6 +831,10 @@ public final class BluetoothGattServer implements BluetoothProfile {
        if (device == null) {
            throw new IllegalArgumentException("device must not be null");
        }
        if (value.length > GATT_MAX_ATTR_LEN) {
            throw new IllegalArgumentException(
                    "notification should not be longer than max length of an attribute value");
        }
        BluetoothGattService service = characteristic.getService();
        if (service == null) {
            throw new IllegalArgumentException("Characteristic must have a non-null service");