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

Commit 5b37d960 authored by Joseph Pirozzo's avatar Joseph Pirozzo Committed by Sanket Agarwal
Browse files

MAP MCE disconnecting automatically

Disconnect commands were getting queued even if bluetooth wasn't
connected.  This would cause the disconnect command to get processed
immediately after the connection succeeded.  Updated logic to defer all
commands while "Connecting" or "Disconnecting" throw out any disconnect
commands at the head of the queue while "Disconnected" and generate
implied disconnect commands when a connect command arived while already
Connected.

Bug: 32080718
Change-Id: Ib02c74c753e88cf4876835ee8e5e0c8f2a6ebc34
(cherry picked from commit bb6d28b7e9c6cf7e57712e687daed388b069a014)
parent 7465dd56
Loading
Loading
Loading
Loading
+13 −9
Original line number Diff line number Diff line
@@ -31,11 +31,12 @@
 * Disconnected + CONNECT -> Connecting
 * Connecting + CONNECTED -> Connected
 * Connecting + TIMEOUT -> Disconnecting
 * Connecting + DISCONNECT -> Disconnecting
 * Connecting + DISCONNECT/CONNECT -> Defer Message
 * Connected + DISCONNECT -> Disconnecting
 * Connected + CONNECT -> Disconnecting + Defer Message
 * Disconnecting + DISCONNECTED -> (Safe) Disconnected
 * Disconnecting + TIMEOUT -> (Force)
 * Disconnected Disconnecting + CONNECT : Defer Message
 * Disconnecting + TIMEOUT -> (Force) Disconnected
 * Disconnecting + DISCONNECT/CONNECT : Defer Message
 */
package com.android.bluetooth.mapclient;

@@ -295,10 +296,6 @@ final class MceStateMachine extends StateMachine {
                    transitionTo(mConnecting);
                    break;

                case MSG_DISCONNECT:
                    deferMessage(message);
                    break;

                default:
                    Log.w(TAG, "Unexpected message: " + message.what + " from state:" +
                        this.getName());
@@ -371,6 +368,7 @@ final class MceStateMachine extends StateMachine {
        @Override
        public void exit() {
            mPreviousState = BluetoothProfile.STATE_CONNECTING;
            removeMessages(MSG_CONNECTING_TIMEOUT);
        }
    }

@@ -393,7 +391,9 @@ final class MceStateMachine extends StateMachine {
        public boolean processMessage(Message message) {
            switch (message.what) {
                case MSG_DISCONNECT:
                    if (mDevice.equals(message.obj)) {
                        transitionTo(mDisconnecting);
                    }
                    break;

                case MSG_OUTBOUND_MESSAGE:
@@ -438,7 +438,10 @@ final class MceStateMachine extends StateMachine {
                    break;

                case MSG_CONNECT:
                    if (!mDevice.equals(message.obj)) {
                        deferMessage(message);
                        transitionTo(mDisconnecting);
                    }
                    break;

                default:
@@ -591,6 +594,7 @@ final class MceStateMachine extends StateMachine {
        @Override
        public void exit() {
            mPreviousState = BluetoothProfile.STATE_DISCONNECTING;
            removeMessages(MSG_DISCONNECTING_TIMEOUT);
        }
    }