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

Commit 2458fdd7 authored by William Escande's avatar William Escande Committed by Gerrit Code Review
Browse files

Merge "AdapterServiceTest: Handle cleanup at shutdown" into main

parents 4dc82cbf 406c8600
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);