Loading android/app/src/com/android/bluetooth/a2dp/A2dpStateMachine.java +8 −1 Original line number Diff line number Diff line Loading @@ -328,7 +328,14 @@ final class A2dpStateMachine extends StateMachine { + messageWhatToString(message.what)); switch (message.what) { case MESSAGE_CONNECT -> deferMessage(message); case MESSAGE_CONNECT -> { if (Flags.a2dpSmIgnoreConnectEventsInConnectingState() && !hasDeferredMessages(MESSAGE_DISCONNECT)) { Log.w(TAG, "Connecting: CONNECT ignored: " + mDevice); } else { deferMessage(message); } } case MESSAGE_CONNECT_TIMEOUT -> { Log.w(TAG, "Connecting connection timeout: " + mDevice); mA2dpNativeInterface.disconnectA2dp(mDevice); Loading android/app/tests/unit/src/com/android/bluetooth/a2dp/A2dpStateMachineTest.java +23 −0 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ import static androidx.test.espresso.intent.matcher.IntentMatchers.hasAction; import static androidx.test.espresso.intent.matcher.IntentMatchers.hasExtra; import static com.android.bluetooth.a2dp.A2dpStateMachine.MESSAGE_CONNECT; import static com.android.bluetooth.a2dp.A2dpStateMachine.MESSAGE_DISCONNECT; import static com.android.bluetooth.a2dp.A2dpStateMachine.MESSAGE_STACK_EVENT; import static com.google.common.truth.Truth.assertThat; Loading @@ -47,11 +48,14 @@ import android.bluetooth.BluetoothDevice; import android.content.Intent; import android.os.Bundle; import android.os.test.TestLooper; 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.flags.Flags; import org.hamcrest.Matcher; import org.hamcrest.core.AllOf; Loading @@ -72,6 +76,8 @@ import java.util.Arrays; public class A2dpStateMachineTest { @Rule public MockitoRule mockitoRule = MockitoJUnit.rule(); @Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule(); @Mock private A2dpService mService; @Mock private A2dpNativeInterface mNativeInterface; Loading Loading @@ -327,6 +333,23 @@ public class A2dpStateMachineTest { mStateMachine.dump(new StringBuilder()); } @Test @EnableFlags(Flags.FLAG_A2DP_SM_IGNORE_CONNECT_EVENTS_IN_CONNECTING_STATE) public void connectEventNeglectedWhileInConnectingState() { sendAndDispatchMessage(MESSAGE_CONNECT, mDevice); verifyConnectionStateIntent(STATE_CONNECTING, STATE_DISCONNECTED); assertThat(mStateMachine.getCurrentState()).isInstanceOf(A2dpStateMachine.Connecting.class); // Dispatch CONNECT event twice more sendAndDispatchMessage(MESSAGE_CONNECT, mDevice); sendAndDispatchMessage(MESSAGE_CONNECT, mDevice); sendAndDispatchMessage(MESSAGE_DISCONNECT, mDevice); verifyConnectionStateIntent(STATE_DISCONNECTED, STATE_CONNECTING); assertThat(mStateMachine.getCurrentState()) .isInstanceOf(A2dpStateMachine.Disconnected.class); assertThat(mLooper.dispatchAll()).isEqualTo(0); } private void sendAndDispatchMessage(int what, Object obj) { mStateMachine.sendMessage(what, obj); mLooper.dispatchAll(); Loading Loading
android/app/src/com/android/bluetooth/a2dp/A2dpStateMachine.java +8 −1 Original line number Diff line number Diff line Loading @@ -328,7 +328,14 @@ final class A2dpStateMachine extends StateMachine { + messageWhatToString(message.what)); switch (message.what) { case MESSAGE_CONNECT -> deferMessage(message); case MESSAGE_CONNECT -> { if (Flags.a2dpSmIgnoreConnectEventsInConnectingState() && !hasDeferredMessages(MESSAGE_DISCONNECT)) { Log.w(TAG, "Connecting: CONNECT ignored: " + mDevice); } else { deferMessage(message); } } case MESSAGE_CONNECT_TIMEOUT -> { Log.w(TAG, "Connecting connection timeout: " + mDevice); mA2dpNativeInterface.disconnectA2dp(mDevice); Loading
android/app/tests/unit/src/com/android/bluetooth/a2dp/A2dpStateMachineTest.java +23 −0 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ import static androidx.test.espresso.intent.matcher.IntentMatchers.hasAction; import static androidx.test.espresso.intent.matcher.IntentMatchers.hasExtra; import static com.android.bluetooth.a2dp.A2dpStateMachine.MESSAGE_CONNECT; import static com.android.bluetooth.a2dp.A2dpStateMachine.MESSAGE_DISCONNECT; import static com.android.bluetooth.a2dp.A2dpStateMachine.MESSAGE_STACK_EVENT; import static com.google.common.truth.Truth.assertThat; Loading @@ -47,11 +48,14 @@ import android.bluetooth.BluetoothDevice; import android.content.Intent; import android.os.Bundle; import android.os.test.TestLooper; 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.flags.Flags; import org.hamcrest.Matcher; import org.hamcrest.core.AllOf; Loading @@ -72,6 +76,8 @@ import java.util.Arrays; public class A2dpStateMachineTest { @Rule public MockitoRule mockitoRule = MockitoJUnit.rule(); @Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule(); @Mock private A2dpService mService; @Mock private A2dpNativeInterface mNativeInterface; Loading Loading @@ -327,6 +333,23 @@ public class A2dpStateMachineTest { mStateMachine.dump(new StringBuilder()); } @Test @EnableFlags(Flags.FLAG_A2DP_SM_IGNORE_CONNECT_EVENTS_IN_CONNECTING_STATE) public void connectEventNeglectedWhileInConnectingState() { sendAndDispatchMessage(MESSAGE_CONNECT, mDevice); verifyConnectionStateIntent(STATE_CONNECTING, STATE_DISCONNECTED); assertThat(mStateMachine.getCurrentState()).isInstanceOf(A2dpStateMachine.Connecting.class); // Dispatch CONNECT event twice more sendAndDispatchMessage(MESSAGE_CONNECT, mDevice); sendAndDispatchMessage(MESSAGE_CONNECT, mDevice); sendAndDispatchMessage(MESSAGE_DISCONNECT, mDevice); verifyConnectionStateIntent(STATE_DISCONNECTED, STATE_CONNECTING); assertThat(mStateMachine.getCurrentState()) .isInstanceOf(A2dpStateMachine.Disconnected.class); assertThat(mLooper.dispatchAll()).isEqualTo(0); } private void sendAndDispatchMessage(int what, Object obj) { mStateMachine.sendMessage(what, obj); mLooper.dispatchAll(); Loading