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

Commit 9aee7814 authored by Łukasz Rymanowski's avatar Łukasz Rymanowski
Browse files

gtbs: Fix sending notification on CallControl point

With this patch we make sure that, there is only one notification sent
on that characteristic.
Issue was visible sometimes on failing unit tests:
org.mockito.exceptions.verification.TooManyActualInvocations:
org.mockito.exceptions.verification.TooManyActualInvocations:
mMockGattServer.notifyCharacteristicChanged(
    00:01:02:03:04:00,
    com.android.bluetooth.tbs.TbsGatt$CallControlPointCharacteristic@35269cd,
    false
);
Wanted 1 time:
-> at com.android.bluetooth.tbs.TbsGattTest.testSetCallControlPointResult(TbsGattTest.java:468)
But was 2 times:
-> at com.android.bluetooth.tbs.TbsGatt$BluetoothGattCharacteristicNotifier.notifyCharacteristicChanged(TbsGatt.java:284)
-> at com.android.bluetooth.tbs.TbsGatt$BluetoothGattCharacteristicNotifier.notifyCharacteristicChanged(TbsGatt.java:284)

	at com.android.bluetooth.tbs.TbsGattTest.testSetCallControlPointResult(TbsGattTest.java:468)

Bug: 150670922
Test: atest TbsGattTest
Sponsor: @jpawlowski
Change-Id: I22645bf2a7cb3714d76b3d9159df347d9eaddfea
parent d796637e
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -355,6 +355,10 @@ public class TbsGatt {
            return success;
        }

        public boolean setValueNoNotify(byte[] value) {
            return super.setValue(value);
        }

        public boolean clearValue(boolean notify) {
            boolean success = super.setValue(new byte[0]);
            if (success && notify && isNotifiable()) {
@@ -409,7 +413,7 @@ public class TbsGatt {
            value[1] = (byte) (callIndex);
            value[2] = (byte) (requestResult);

            super.setValue(value);
            super.setValueNoNotify(value);

            // to avoid sending control point notification before write response
            mContext.getMainThreadHandler().post(() -> mNotifier.notify(device, this));
+4 −3
Original line number Diff line number Diff line
@@ -465,8 +465,8 @@ public class TbsGattTest {
        Assert.assertTrue(Arrays.equals(characteristic.getValue(),
                new byte[] {(byte) (requestedOpcode & 0xff), (byte) (callIndex & 0xff),
                        (byte) (result & 0xff)}));
        verify(mMockGattServer).notifyCharacteristicChanged(eq(mCurrentDevice), eq(characteristic),
                eq(false));
        verify(mMockGattServer, after(2000)).notifyCharacteristicChanged(eq(mCurrentDevice),
                eq(characteristic), eq(false));
        reset(mMockGattServer);

        callIndex = 0x02;
@@ -477,7 +477,8 @@ public class TbsGattTest {
        Assert.assertTrue(Arrays.equals(characteristic.getValue(),
                new byte[] {(byte) (requestedOpcode & 0xff), (byte) (callIndex & 0xff),
                        (byte) (result & 0xff)}));
        verify(mMockGattServer, times(0)).notifyCharacteristicChanged(any(), any(), anyBoolean());
        verify(mMockGattServer, after(2000).times(0)).notifyCharacteristicChanged(any(), any(),
                anyBoolean());
    }

    @Test