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

Commit 006b2c20 authored by Grzegorz Kolodziejczyk (xWF)'s avatar Grzegorz Kolodziejczyk (xWF) Committed by Gerrit Code Review
Browse files

Merge changes I97231165,Ia99be2f3 into main

* changes:
  le_audio: ignore connect events in connecting state
  flags: leaudio_sm_ignore_connect_events_in_connecting_state
parents 8bf8784b ca8aac2c
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -50,6 +50,7 @@ import android.os.Message;
import android.util.Log;

import com.android.bluetooth.btservice.ProfileService;
import com.android.bluetooth.flags.Flags;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.State;
import com.android.internal.util.StateMachine;
@@ -276,7 +277,12 @@ final class LeAudioStateMachine extends StateMachine {

            switch (message.what) {
                case CONNECT:
                    if (Flags.leaudioSmIgnoreConnectEventsInConnectingState()
                            && !hasDeferredMessages(DISCONNECT)) {
                        Log.w(TAG, "Connecting: CONNECT ignored: " + mDevice);
                    } else {
                        deferMessage(message);
                    }
                    break;
                case CONNECT_TIMEOUT:
                    Log.w(TAG, "Connecting connection timeout: " + mDevice);
+44 −0
Original line number Diff line number Diff line
@@ -17,6 +17,9 @@

package com.android.bluetooth.le_audio;

import static com.android.bluetooth.le_audio.LeAudioStateMachine.CONNECT;
import static com.android.bluetooth.le_audio.LeAudioStateMachine.DISCONNECT;

import static com.google.common.truth.Truth.assertThat;

import static org.mockito.Mockito.after;
@@ -34,12 +37,15 @@ import android.bluetooth.BluetoothProfile;
import android.content.Intent;
import android.os.Bundle;
import android.os.HandlerThread;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.flag.junit.SetFlagsRule;

import androidx.test.filters.MediumTest;
import androidx.test.runner.AndroidJUnit4;

import com.android.bluetooth.TestUtils;
import com.android.bluetooth.btservice.AdapterService;
import com.android.bluetooth.flags.Flags;

import org.junit.After;
import org.junit.Before;
@@ -60,6 +66,7 @@ public class LeAudioStateMachineTest {
    private static final int TIMEOUT_MS = 1000;

    @Rule public MockitoRule mockitoRule = MockitoJUnit.rule();
    @Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();

    @Mock private AdapterService mAdapterService;
    @Mock private LeAudioService mLeAudioService;
@@ -232,4 +239,41 @@ public class LeAudioStateMachineTest {
        assertThat(mLeAudioStateMachine.getCurrentState())
                .isInstanceOf(LeAudioStateMachine.Disconnected.class);
    }

    private void sendAndDispatchMessage(int what, Object obj) {
        mLeAudioStateMachine.sendMessage(what, obj);
        TestUtils.waitForLooperToFinishScheduledTask(mHandlerThread.getLooper());
    }

    @Test
    @EnableFlags(Flags.FLAG_LEAUDIO_SM_IGNORE_CONNECT_EVENTS_IN_CONNECTING_STATE)
    public void connectEventNeglectedWhileInConnectingState() {
        allowConnection(true);
        doReturn(true).when(mLeAudioNativeInterface).connectLeAudio(any(BluetoothDevice.class));
        doReturn(true).when(mLeAudioNativeInterface).disconnectLeAudio(any(BluetoothDevice.class));

        sendAndDispatchMessage(CONNECT, mTestDevice);
        // Verify that one connection state change is notified
        verify(mLeAudioService, timeout(TIMEOUT_MS))
                .notifyConnectionStateChanged(
                        any(),
                        eq(BluetoothProfile.STATE_CONNECTING),
                        eq(BluetoothProfile.STATE_DISCONNECTED));
        assertThat(mLeAudioStateMachine.getCurrentState())
                .isInstanceOf(LeAudioStateMachine.Connecting.class);

        // Dispatch CONNECT event twice more
        sendAndDispatchMessage(CONNECT, mTestDevice);
        sendAndDispatchMessage(CONNECT, mTestDevice);
        sendAndDispatchMessage(DISCONNECT, mTestDevice);
        // Verify that one connection state change is notified
        verify(mLeAudioService, timeout(TIMEOUT_MS))
                .notifyConnectionStateChanged(
                        any(),
                        eq(BluetoothProfile.STATE_DISCONNECTED),
                        eq(BluetoothProfile.STATE_CONNECTING));
        assertThat(mLeAudioStateMachine.getCurrentState())
                .isInstanceOf(LeAudioStateMachine.Disconnected.class);
        TestUtils.waitForLooperToFinishScheduledTask(mHandlerThread.getLooper());
    }
}
+10 −0
Original line number Diff line number Diff line
@@ -441,3 +441,13 @@ flag {
        purpose: PURPOSE_BUGFIX
    }
}

flag {
    name: "leaudio_sm_ignore_connect_events_in_connecting_state"
    namespace: "bluetooth"
    description: "When received CONNECT event in Connecting state, with no prior DISCONNECT - ignore the event"
    bug: "384460395"
    metadata {
        purpose: PURPOSE_BUGFIX
    }
}