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

Commit 56d6fa2c authored by William Escande's avatar William Escande Committed by Gerrit Code Review
Browse files

Revert "Clean up correct state machine"

This reverts commit 4c33e9fb.

Reason for revert: b/312448477 test breakage
```
java.lang.NullPointerException: Attempt to invoke virtual method 'android.os.Looper android.os.Handler.getLooper()' on a null object reference
	at com.android.bluetooth.mapclient.MapClientServiceTest.disconnect_doesNotCleanUpNewStateMachineOfSameDevice(MapClientServiceTest.java:264)
```

Bug: 312448477
Change-Id: Idb4265bed8412224f2c4cec4393e742cf7ee73ac
parent 4c33e9fb
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));
    }