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

Commit 9b5cd43f authored by Joseph Pirozzo's avatar Joseph Pirozzo
Browse files

MAP Client disconnect state machine if MAS client disconnected

If the MAS client disconnects (Obex error or remote device terminates
connection) close the state machine safely.

Bug: 138379476
Test: atest MapClientStateMachineTest
Change-Id: I11362911fc96cb15416242456fa3cf026c085745
parent ec407574
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -474,6 +474,11 @@ final class MceStateMachine extends StateMachine {
                    }
                    break;

                case MSG_MAS_DISCONNECTED:
                    deferMessage(message);
                    transitionTo(mDisconnecting);
                    break;

                case MSG_OUTBOUND_MESSAGE:
                    mMasClient.makeRequest(
                            new RequestPushMessage(FOLDER_OUTBOX, (Bmessage) message.obj, null,
+30 −0
Original line number Diff line number Diff line
@@ -150,6 +150,36 @@ public class MapClientStateMachineTest {
        Assert.assertEquals(BluetoothProfile.STATE_CONNECTED, mMceStateMachine.getState());
    }

     /**
     * Test transition from STATE_CONNECTING --> (receive MSG_MAS_CONNECTED) --> STATE_CONNECTED
     * --> (receive MSG_MAS_DISCONNECTED) --> STATE_DISCONNECTED
     */
    @Test
    public void testStateTransitionFromConnectedWithMasDisconnected() {
        Log.i(TAG, "in testStateTransitionFromConnectedWithMasDisconnected");

        setupSdpRecordReceipt();
        Message msg = Message.obtain(mHandler, MceStateMachine.MSG_MAS_CONNECTED);
        mMceStateMachine.sendMessage(msg);

        // Wait until the message is processed and a broadcast request is sent to
        // to MapClientService to change
        // state from STATE_CONNECTING to STATE_CONNECTED
        verify(mMockMapClientService,
                timeout(ASYNC_CALL_TIMEOUT_MILLIS).times(2)).sendBroadcast(
                mIntentArgument.capture(), eq(ProfileService.BLUETOOTH_PERM));
        Assert.assertEquals(BluetoothProfile.STATE_CONNECTED, mMceStateMachine.getState());

        msg = Message.obtain(mHandler, MceStateMachine.MSG_MAS_DISCONNECTED);
        mMceStateMachine.sendMessage(msg);
        verify(mMockMapClientService,
                timeout(ASYNC_CALL_TIMEOUT_MILLIS).times(4)).sendBroadcast(
                mIntentArgument.capture(), eq(ProfileService.BLUETOOTH_PERM));

        Assert.assertEquals(BluetoothProfile.STATE_DISCONNECTED, mMceStateMachine.getState());
    }


    /**
     * Test receiving an empty event report
     */