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

Commit 406c8600 authored by William Escande's avatar William Escande
Browse files

AdapterServiceTest: Handle cleanup at shutdown

Test: atest AdapterServiceTest
Bug: 339548431
Flag: com.android.bluetooth.flags.explicit_kill_from_system_server
Change-Id: I889300a2f343e97191732219baa2ded30cc8f8e3
parent d550e9d1
Loading
Loading
Loading
Loading
+38 −2
Original line number Diff line number Diff line
@@ -548,6 +548,12 @@ public class AdapterServiceTest {
        verify(nativeInterface).disable();
        adapter.stateChangeCallback(AbstractionLayer.BT_STATE_OFF);
        TestUtils.syncHandler(looper, AdapterState.BLE_STOPPED);
        if (Flags.explicitKillFromSystemServer()) {
            // When reaching the OFF state, the cleanup is called that will destroy the state
            // machine of the adapterService. Destroying state machine send a -1 event on the
            // handler
            TestUtils.syncHandler(looper, -1);
        }
        verifyStateChange(callback, STATE_BLE_TURNING_OFF, STATE_OFF);

        assertThat(adapter.getState()).isEqualTo(STATE_OFF);
@@ -640,6 +646,12 @@ public class AdapterServiceTest {
        assertThat(mAdapterService.getBluetoothGatt()).isNull();

        syncHandler(AdapterState.BLE_STOPPED);
        if (Flags.explicitKillFromSystemServer()) {
            // When reaching the OFF state, the cleanup is called that will destroy the state
            // machine of the adapterService. Destroying state machine send a -1 event on the
            // handler
            syncHandler(-1);
        }
        syncHandler(MESSAGE_PROFILE_SERVICE_STATE_CHANGED);
        syncHandler(MESSAGE_PROFILE_SERVICE_UNREGISTERED);

@@ -674,6 +686,12 @@ public class AdapterServiceTest {

        mLooper.moveTimeForward(120_000); // Skip time so the timeout fires
        syncHandler(AdapterState.BLE_STOP_TIMEOUT);
        if (Flags.explicitKillFromSystemServer()) {
            // When reaching the OFF state, the cleanup is called that will destroy the state
            // machine of the adapterService. Destroying state machine send a -1 event on the
            // handler
            syncHandler(-1);
        }
        verifyStateChange(STATE_BLE_TURNING_OFF, STATE_OFF);

        assertThat(mAdapterService.getState()).isEqualTo(STATE_OFF);
@@ -723,12 +741,18 @@ public class AdapterServiceTest {
        assertThat(mAdapterService.getBluetoothGatt()).isNull();

        mAdapterService.stopBle();
        TestUtils.syncHandler(mLooper, AdapterState.BLE_TURN_OFF);
        syncHandler(AdapterState.BLE_TURN_OFF);
        verifyStateChange(callback, STATE_BLE_ON, STATE_BLE_TURNING_OFF);

        verify(mNativeInterface).disable();
        mAdapterService.stateChangeCallback(AbstractionLayer.BT_STATE_OFF);
        TestUtils.syncHandler(mLooper, AdapterState.BLE_STOPPED);
        syncHandler(AdapterState.BLE_STOPPED);
        if (Flags.explicitKillFromSystemServer()) {
            // When reaching the OFF state, the cleanup is called that will destroy the state
            // machine of the adapterService. Destroying state machine send a -1 event on the
            // handler
            syncHandler(-1);
        }
        verifyStateChange(callback, STATE_BLE_TURNING_OFF, STATE_OFF);

        assertThat(mAdapterService.getState()).isEqualTo(STATE_OFF);
@@ -875,6 +899,12 @@ public class AdapterServiceTest {
        // TODO(b/280518177): The only timeout to fire here should be the BREDR
        mLooper.moveTimeForward(120_000); // Skip time so the timeout fires
        syncHandler(AdapterState.BLE_STOP_TIMEOUT);
        if (Flags.explicitKillFromSystemServer()) {
            // When reaching the OFF state, the cleanup is called that will destroy the state
            // machine of the adapterService. Destroying state machine send a -1 event on the
            // handler
            syncHandler(-1);
        }
        verifyStateChange(STATE_BLE_TURNING_OFF, STATE_OFF);

        assertThat(mAdapterService.getState()).isEqualTo(STATE_OFF);
@@ -918,6 +948,12 @@ public class AdapterServiceTest {

        mAdapterService.stateChangeCallback(AbstractionLayer.BT_STATE_OFF);
        syncHandler(AdapterState.BLE_STOPPED);
        if (Flags.explicitKillFromSystemServer()) {
            // When reaching the OFF state, the cleanup is called that will destroy the state
            // machine of the adapterService. Destroying state machine send a -1 event on the
            // handler
            syncHandler(-1);
        }

        verifyStateChange(STATE_BLE_TURNING_OFF, STATE_OFF);
        assertThat(mAdapterService.getState()).isEqualTo(STATE_OFF);