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

Commit e210e44f authored by Sal Savage's avatar Sal Savage
Browse files

Defer disconnect commands until post connecting state

If a device receives a disconnect event while connecting, that event is
currently dropped and the device won't end up disconnecting as a result
of the request.

To fix this, we'll defer the request until we exit the connecting state.
Either we end up disconnecting (connection fails) and the disconnect is
redundant, or we end up in connected where the request is properly
processed

Tag: #stability
Bug: 298209581
Test: atest BluetoothInstrumentationTests
Change-Id: I66bc568b0649dd8259d3cdfa1a7979c53851ba12
parent aedd0dfa
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -218,6 +218,10 @@ public class A2dpSinkStateMachine extends StateMachine {
                case CONNECT_TIMEOUT:
                    transitionTo(mDisconnected);
                    return true;
                case DISCONNECT:
                    Log.d(TAG, "Received disconnect message while connecting. deferred");
                    deferMessage(message);
                    return true;
            }
            return false;
        }
+8 −1
Original line number Diff line number Diff line
@@ -269,12 +269,19 @@ public class A2dpSinkStateMachineTest {
    }

    @Test
    public void testDisconnectInConnecting() {
    public void testDisconnectInConnecting_disconnectDeferredAndProcessed() {
        testConnectInDisconnected();
        assertThat(mStateMachine.getState()).isEqualTo(BluetoothProfile.STATE_CONNECTING);
        mStateMachine.disconnect();
        TestUtils.waitForLooperToFinishScheduledTask(mStateMachine.getHandler().getLooper());
        assertThat(mStateMachine.getState()).isEqualTo(BluetoothProfile.STATE_CONNECTING);

        // send connected, disconnect should get processed
        sendConnectionEvent(BluetoothProfile.STATE_CONNECTED);
        TestUtils.waitForLooperToFinishScheduledTask(mStateMachine.getHandler().getLooper());
        verify(mNativeInterface, times(1)).disconnectA2dpSink(mDevice);
        verify(mService, timeout(TIMEOUT_MS).times(1)).removeStateMachine(mStateMachine);
        assertThat(mStateMachine.getState()).isEqualTo(BluetoothProfile.STATE_DISCONNECTED);
    }

    /**********************************************************************************************