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

Commit 9adb37e9 authored by Sal Savage's avatar Sal Savage Committed by Gerrit Code Review
Browse files

Merge "Defer disconnect commands until post connecting state" into main

parents 4f9eaf4a e210e44f
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);
    }

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