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

Commit 1826699e authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Revert "Clean up correct state machine"" into main

parents d2429f6b 56d6fa2c
Loading
Loading
Loading
Loading
+3 −8
Original line number Diff line number Diff line
@@ -367,10 +367,9 @@ public class MapClientService extends ProfileService {
     * cleanupDevice removes the associated state machine from the instance map
     *
     * @param device BluetoothDevice address of remote device
     * @param sm the state machine to clean up or null for cleaning up any state machine.
     */
    @VisibleForTesting
    public void cleanupDevice(BluetoothDevice device, MceStateMachine sm) {
    public void cleanupDevice(BluetoothDevice device) {
        if (DBG) {
            StringBuilder sb = new StringBuilder();
            dump(sb);
@@ -380,12 +379,8 @@ public class MapClientService extends ProfileService {
        synchronized (mMapInstanceMap) {
            MceStateMachine stateMachine = mMapInstanceMap.get(device);
            if (stateMachine != null) {
                if (sm == null || stateMachine == sm) {
                mMapInstanceMap.remove(device);
                stateMachine.doQuit();
                } else {
                    Log.w(TAG, "Trying to clean up wrong state machine");
                }
            }
        }
        if (DBG) {
+1 −1
Original line number Diff line number Diff line
@@ -250,7 +250,7 @@ class MceStateMachine extends StateMachine {
    @Override
    protected void onQuitting() {
        if (mService != null) {
            mService.cleanupDevice(mDevice, this);
            mService.cleanupDevice(mDevice);
        }
    }

+2 −26
Original line number Diff line number Diff line
@@ -71,7 +71,6 @@ public class MapClientServiceTest {
        doReturn(true, false).when(mAdapterService).isStartedProfile(anyString());
        TestUtils.startService(mServiceRule, MapClientService.class);
        mService = MapClientService.getMapClientService();

        assertThat(mService).isNotNull();
        // Try getting the Bluetooth adapter
        mAdapter = BluetoothAdapter.getDefaultAdapter();
@@ -238,32 +237,9 @@ public class MapClientServiceTest {
        MceStateMachine sm = mock(MceStateMachine.class);
        mService.getInstanceMap().put(mRemoteDevice, sm);

        mService.cleanupDevice(mRemoteDevice, sm);
        assertThat(mService.getInstanceMap()).doesNotContainKey(mRemoteDevice);
    }

    @Test
    public void disconnect_doesNotCleanUpNewStateMachineOfSameDevice() {
        int connectionPolicy = BluetoothProfile.CONNECTION_POLICY_ALLOWED;
        when(mDatabaseManager.getProfileConnectionPolicy(
                        mRemoteDevice, BluetoothProfile.MAP_CLIENT))
                .thenReturn(connectionPolicy);
        mService.cleanupDevice(mRemoteDevice);

        mService.connect(mRemoteDevice);
        MceStateMachine connectedSm = mService.getInstanceMap().get(mRemoteDevice);
        assertThat(connectedSm).isNotNull();

        connectedSm.sendMessage(MceStateMachine.MSG_MAS_SDP_DONE, mock(SdpMasRecord.class));
        connectedSm.sendMessage(MceStateMachine.MSG_MAS_CONNECTED);
        TestUtils.waitForLooperToFinishScheduledTask(connectedSm.getHandler().getLooper());

        mService.disconnect(mRemoteDevice);
        assertThat(mService.getInstanceMap()).containsKey(mRemoteDevice);
        MceStateMachine sm = mock(MceStateMachine.class);
        mService.getInstanceMap().put(mRemoteDevice, sm);
        TestUtils.waitForLooperToFinishScheduledTask(connectedSm.getHandler().getLooper());

        assertThat(mService.getInstanceMap()).containsKey(mRemoteDevice);
        assertThat(mService.getInstanceMap()).doesNotContainKey(mRemoteDevice);
    }

    @Test
+1 −1
Original line number Diff line number Diff line
@@ -129,7 +129,7 @@ public class MapClientTest {
        TestUtils.waitForLooperToFinishScheduledTask(sm.getHandler().getLooper());

        Assert.assertEquals(BluetoothProfile.STATE_CONNECTING, sm.getState());
        mService.cleanupDevice(device, sm);
        mService.cleanupDevice(device);
        Assert.assertNull(mService.getInstanceMap().get(device));
    }