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

Commit 1a763454 authored by Jakub Tyszkowski's avatar Jakub Tyszkowski Committed by Jakub Tyszkowski (xWF)
Browse files

Tbs: Fix restoring CCC values when not initialised

There's no point restoring CCC descriptor values of the not
yet initialized GATT service. Register the callback after creating the
GATT service.

Bug: 353756651
Test: atest GoogleBluetoothInstrumentationTests
Flag: Exempt; fix covered with unit test
Change-Id: Id469f388fb8bb4f3945d14866fb7578385355db7
parent 472ac7e7
Loading
Loading
Loading
Loading
+8 −5
Original line number Diff line number Diff line
@@ -249,9 +249,6 @@ public class TbsGatt {
                        AdapterService.getAdapterService(),
                        "AdapterService shouldn't be null when creating TbsGatt");

        mAdapterService.registerBluetoothStateCallback(
                mContext.getMainExecutor(), mBluetoothStateChangeCallback);

        mBearerProviderNameCharacteristic =
                new GattCharacteristic(
                        UUID_BEARER_PROVIDER_NAME,
@@ -377,9 +374,15 @@ public class TbsGatt {
        mEventLogger =
                new BluetoothEventLogger(
                        LOG_NB_EVENTS, TAG + " instance (CCID= " + ccid + ") event log");
        mEventLogger.add("Initializing");
        if (!mBluetoothGattServer.addService(gattService)) {
            mEventLogger.add("Initialization failed");
            return false;
        }

        return mBluetoothGattServer.addService(gattService);
        mEventLogger.add("Initialized");
        mAdapterService.registerBluetoothStateCallback(
                mContext.getMainExecutor(), mBluetoothStateChangeCallback);
        return true;
    }

    public void cleanup() {
+1 −0
Original line number Diff line number Diff line
@@ -137,6 +137,7 @@ public class TbsGattTest {
                        mMockTbsGattCallback));
        Assert.assertNotNull(mMockGattServer);

        verify(mAdapterService, times(1)).registerBluetoothStateCallback(any(), any());
        verify(mMockGattServer).addService(mGattServiceCaptor.capture());
        doReturn(mGattServiceCaptor.getValue()).when(mMockGattServer).getService(any(UUID.class));
        Assert.assertNotNull(mMockGattServer);