Loading android/app/tests/unit/src/com/android/bluetooth/a2dp/A2dpServiceTest.java +71 −1 Original line number Diff line number Diff line Loading @@ -43,6 +43,7 @@ import android.media.BluetoothProfileConnectionInfo; import android.os.Looper; import android.os.ParcelUuid; import android.os.test.TestLooper; import android.platform.test.annotations.DisableFlags; import android.platform.test.annotations.EnableFlags; import android.platform.test.flag.junit.FlagsParameterization; import android.platform.test.flag.junit.SetFlagsRule; Loading Loading @@ -595,7 +596,8 @@ public class A2dpServiceTest { * Test that a state machine in DISCONNECTED state is removed only after the device is unbond. */ @Test public void testDeleteStateMachineUnbondEvents() { @DisableFlags(Flags.FLAG_A2DP_CLEANUP_ON_REMOVE_DEVICE) public void testDeleteDisconnectedStateMachineUnbondEvents() { // Update the device priority so okToConnect() returns true when(mDatabaseManager.getProfileConnectionPolicy(sTestDevice, BluetoothProfile.A2DP)) .thenReturn(BluetoothProfile.CONNECTION_POLICY_ALLOWED); Loading Loading @@ -639,6 +641,74 @@ public class A2dpServiceTest { assertThat(mA2dpService.getDevices()).doesNotContain(sTestDevice); } /** Test that a state machine is removed after the device is unbond. */ @Test @EnableFlags(Flags.FLAG_A2DP_CLEANUP_ON_REMOVE_DEVICE) public void testDeleteStateMachineUnbondEvents() { // Update the device priority so okToConnect() returns true when(mDatabaseManager.getProfileConnectionPolicy(sTestDevice, BluetoothProfile.A2DP)) .thenReturn(BluetoothProfile.CONNECTION_POLICY_ALLOWED); doReturn(true).when(mMockNativeInterface).connectA2dp(any(BluetoothDevice.class)); doReturn(true).when(mMockNativeInterface).disconnectA2dp(any(BluetoothDevice.class)); // A2DP stack event: CONNECTION_STATE_CONNECTING - state machine should be created generateConnectionMessageFromNative(sTestDevice, STATE_CONNECTING, STATE_DISCONNECTED); assertThat(mA2dpService.getConnectionState(sTestDevice)).isEqualTo(STATE_CONNECTING); assertThat(mA2dpService.getDevices()).contains(sTestDevice); // Device unbond - state machine is not removed mA2dpService.bondStateChanged(sTestDevice, BluetoothDevice.BOND_NONE); if (Flags.a2dpBroadcastConnectionStateWhenTurnedOff()) { // Verify that the intent CONNECTION_STATE_CHANGED is generated // for the existing connections. verifyConnectionStateIntent(sTestDevice, STATE_DISCONNECTED, STATE_CONNECTING); } assertThat(mA2dpService.getDevices()).doesNotContain(sTestDevice); // A2DP stack event: CONNECTION_STATE_CONNECTED - state machine is not removed mA2dpService.bondStateChanged(sTestDevice, BluetoothDevice.BOND_BONDED); generateConnectionMessageFromNative(sTestDevice, STATE_CONNECTING, STATE_DISCONNECTED); generateConnectionMessageFromNative(sTestDevice, STATE_CONNECTED, STATE_CONNECTING); assertThat(mA2dpService.getConnectionState(sTestDevice)).isEqualTo(STATE_CONNECTED); assertThat(mA2dpService.getDevices()).contains(sTestDevice); // Device unbond - state machine is not removed mA2dpService.bondStateChanged(sTestDevice, BluetoothDevice.BOND_NONE); if (Flags.a2dpBroadcastConnectionStateWhenTurnedOff()) { // Verify that the intent CONNECTION_STATE_CHANGED is generated // for the existing connections. verifyConnectionStateIntent(sTestDevice, STATE_DISCONNECTED, STATE_CONNECTED); } assertThat(mA2dpService.getDevices()).doesNotContain(sTestDevice); // A2DP stack event: CONNECTION_STATE_DISCONNECTING - state machine is not removed mA2dpService.bondStateChanged(sTestDevice, BluetoothDevice.BOND_BONDED); generateConnectionMessageFromNative(sTestDevice, STATE_CONNECTING, STATE_DISCONNECTED); generateConnectionMessageFromNative(sTestDevice, STATE_CONNECTED, STATE_CONNECTING); generateConnectionMessageFromNative(sTestDevice, STATE_DISCONNECTING, STATE_CONNECTED); assertThat(mA2dpService.getConnectionState(sTestDevice)).isEqualTo(STATE_DISCONNECTING); assertThat(mA2dpService.getDevices()).contains(sTestDevice); // Device unbond - state machine is not removed mA2dpService.bondStateChanged(sTestDevice, BluetoothDevice.BOND_NONE); if (Flags.a2dpBroadcastConnectionStateWhenTurnedOff()) { // Verify that the intent CONNECTION_STATE_CHANGED is generated // for the existing connections. verifyConnectionStateIntent(sTestDevice, STATE_DISCONNECTED, STATE_DISCONNECTING); } assertThat(mA2dpService.getDevices()).doesNotContain(sTestDevice); // A2DP stack event: CONNECTION_STATE_DISCONNECTED - state machine is not removed mA2dpService.bondStateChanged(sTestDevice, BluetoothDevice.BOND_BONDED); generateConnectionMessageFromNative(sTestDevice, STATE_CONNECTING, STATE_DISCONNECTED); generateConnectionMessageFromNative(sTestDevice, STATE_CONNECTED, STATE_CONNECTING); generateConnectionMessageFromNative(sTestDevice, STATE_DISCONNECTING, STATE_CONNECTED); generateConnectionMessageFromNative(sTestDevice, STATE_DISCONNECTED, STATE_DISCONNECTING); assertThat(mA2dpService.getConnectionState(sTestDevice)).isEqualTo(STATE_DISCONNECTED); assertThat(mA2dpService.getDevices()).contains(sTestDevice); // Device unbond - state machine is removed mA2dpService.bondStateChanged(sTestDevice, BluetoothDevice.BOND_NONE); dispatchAtLeastOneMessage(); assertThat(mA2dpService.getDevices()).doesNotContain(sTestDevice); } /** * Test that a CONNECTION_STATE_DISCONNECTED A2DP stack event will remove the state machine only * if the device is unbond. Loading Loading
android/app/tests/unit/src/com/android/bluetooth/a2dp/A2dpServiceTest.java +71 −1 Original line number Diff line number Diff line Loading @@ -43,6 +43,7 @@ import android.media.BluetoothProfileConnectionInfo; import android.os.Looper; import android.os.ParcelUuid; import android.os.test.TestLooper; import android.platform.test.annotations.DisableFlags; import android.platform.test.annotations.EnableFlags; import android.platform.test.flag.junit.FlagsParameterization; import android.platform.test.flag.junit.SetFlagsRule; Loading Loading @@ -595,7 +596,8 @@ public class A2dpServiceTest { * Test that a state machine in DISCONNECTED state is removed only after the device is unbond. */ @Test public void testDeleteStateMachineUnbondEvents() { @DisableFlags(Flags.FLAG_A2DP_CLEANUP_ON_REMOVE_DEVICE) public void testDeleteDisconnectedStateMachineUnbondEvents() { // Update the device priority so okToConnect() returns true when(mDatabaseManager.getProfileConnectionPolicy(sTestDevice, BluetoothProfile.A2DP)) .thenReturn(BluetoothProfile.CONNECTION_POLICY_ALLOWED); Loading Loading @@ -639,6 +641,74 @@ public class A2dpServiceTest { assertThat(mA2dpService.getDevices()).doesNotContain(sTestDevice); } /** Test that a state machine is removed after the device is unbond. */ @Test @EnableFlags(Flags.FLAG_A2DP_CLEANUP_ON_REMOVE_DEVICE) public void testDeleteStateMachineUnbondEvents() { // Update the device priority so okToConnect() returns true when(mDatabaseManager.getProfileConnectionPolicy(sTestDevice, BluetoothProfile.A2DP)) .thenReturn(BluetoothProfile.CONNECTION_POLICY_ALLOWED); doReturn(true).when(mMockNativeInterface).connectA2dp(any(BluetoothDevice.class)); doReturn(true).when(mMockNativeInterface).disconnectA2dp(any(BluetoothDevice.class)); // A2DP stack event: CONNECTION_STATE_CONNECTING - state machine should be created generateConnectionMessageFromNative(sTestDevice, STATE_CONNECTING, STATE_DISCONNECTED); assertThat(mA2dpService.getConnectionState(sTestDevice)).isEqualTo(STATE_CONNECTING); assertThat(mA2dpService.getDevices()).contains(sTestDevice); // Device unbond - state machine is not removed mA2dpService.bondStateChanged(sTestDevice, BluetoothDevice.BOND_NONE); if (Flags.a2dpBroadcastConnectionStateWhenTurnedOff()) { // Verify that the intent CONNECTION_STATE_CHANGED is generated // for the existing connections. verifyConnectionStateIntent(sTestDevice, STATE_DISCONNECTED, STATE_CONNECTING); } assertThat(mA2dpService.getDevices()).doesNotContain(sTestDevice); // A2DP stack event: CONNECTION_STATE_CONNECTED - state machine is not removed mA2dpService.bondStateChanged(sTestDevice, BluetoothDevice.BOND_BONDED); generateConnectionMessageFromNative(sTestDevice, STATE_CONNECTING, STATE_DISCONNECTED); generateConnectionMessageFromNative(sTestDevice, STATE_CONNECTED, STATE_CONNECTING); assertThat(mA2dpService.getConnectionState(sTestDevice)).isEqualTo(STATE_CONNECTED); assertThat(mA2dpService.getDevices()).contains(sTestDevice); // Device unbond - state machine is not removed mA2dpService.bondStateChanged(sTestDevice, BluetoothDevice.BOND_NONE); if (Flags.a2dpBroadcastConnectionStateWhenTurnedOff()) { // Verify that the intent CONNECTION_STATE_CHANGED is generated // for the existing connections. verifyConnectionStateIntent(sTestDevice, STATE_DISCONNECTED, STATE_CONNECTED); } assertThat(mA2dpService.getDevices()).doesNotContain(sTestDevice); // A2DP stack event: CONNECTION_STATE_DISCONNECTING - state machine is not removed mA2dpService.bondStateChanged(sTestDevice, BluetoothDevice.BOND_BONDED); generateConnectionMessageFromNative(sTestDevice, STATE_CONNECTING, STATE_DISCONNECTED); generateConnectionMessageFromNative(sTestDevice, STATE_CONNECTED, STATE_CONNECTING); generateConnectionMessageFromNative(sTestDevice, STATE_DISCONNECTING, STATE_CONNECTED); assertThat(mA2dpService.getConnectionState(sTestDevice)).isEqualTo(STATE_DISCONNECTING); assertThat(mA2dpService.getDevices()).contains(sTestDevice); // Device unbond - state machine is not removed mA2dpService.bondStateChanged(sTestDevice, BluetoothDevice.BOND_NONE); if (Flags.a2dpBroadcastConnectionStateWhenTurnedOff()) { // Verify that the intent CONNECTION_STATE_CHANGED is generated // for the existing connections. verifyConnectionStateIntent(sTestDevice, STATE_DISCONNECTED, STATE_DISCONNECTING); } assertThat(mA2dpService.getDevices()).doesNotContain(sTestDevice); // A2DP stack event: CONNECTION_STATE_DISCONNECTED - state machine is not removed mA2dpService.bondStateChanged(sTestDevice, BluetoothDevice.BOND_BONDED); generateConnectionMessageFromNative(sTestDevice, STATE_CONNECTING, STATE_DISCONNECTED); generateConnectionMessageFromNative(sTestDevice, STATE_CONNECTED, STATE_CONNECTING); generateConnectionMessageFromNative(sTestDevice, STATE_DISCONNECTING, STATE_CONNECTED); generateConnectionMessageFromNative(sTestDevice, STATE_DISCONNECTED, STATE_DISCONNECTING); assertThat(mA2dpService.getConnectionState(sTestDevice)).isEqualTo(STATE_DISCONNECTED); assertThat(mA2dpService.getDevices()).contains(sTestDevice); // Device unbond - state machine is removed mA2dpService.bondStateChanged(sTestDevice, BluetoothDevice.BOND_NONE); dispatchAtLeastOneMessage(); assertThat(mA2dpService.getDevices()).doesNotContain(sTestDevice); } /** * Test that a CONNECTION_STATE_DISCONNECTED A2DP stack event will remove the state machine only * if the device is unbond. Loading