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

Commit b637664a authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "HearingAid: Check the value of mConnectionState in isConnected" am: 969443f8

Change-Id: Idf5d0cb2259e171e15122ab72ba492f43eb296a8
parents c9372066 969443f8
Loading
Loading
Loading
Loading
+7 −15
Original line number Diff line number Diff line
@@ -81,6 +81,7 @@ final class HearingAidStateMachine extends StateMachine {
    private Connecting mConnecting;
    private Disconnecting mDisconnecting;
    private Connected mConnected;
    private int mConnectionState = BluetoothProfile.STATE_DISCONNECTED;
    private int mLastConnectionState = -1;

    private HearingAidService mService;
@@ -132,6 +133,7 @@ final class HearingAidStateMachine extends StateMachine {
        public void enter() {
            Log.i(TAG, "Enter Disconnected(" + mDevice + "): " + messageWhatToString(
                    getCurrentMessage().what));
            mConnectionState = BluetoothProfile.STATE_DISCONNECTED;

            removeDeferredMessages(DISCONNECT);

@@ -239,6 +241,7 @@ final class HearingAidStateMachine extends StateMachine {
            Log.i(TAG, "Enter Connecting(" + mDevice + "): "
                    + messageWhatToString(getCurrentMessage().what));
            sendMessageDelayed(CONNECT_TIMEOUT, sConnectTimeoutMs);
            mConnectionState = BluetoothProfile.STATE_CONNECTING;
            broadcastConnectionState(BluetoothProfile.STATE_CONNECTING, mLastConnectionState);
        }

@@ -329,6 +332,7 @@ final class HearingAidStateMachine extends StateMachine {
            Log.i(TAG, "Enter Disconnecting(" + mDevice + "): "
                    + messageWhatToString(getCurrentMessage().what));
            sendMessageDelayed(CONNECT_TIMEOUT, sConnectTimeoutMs);
            mConnectionState = BluetoothProfile.STATE_DISCONNECTING;
            broadcastConnectionState(BluetoothProfile.STATE_DISCONNECTING, mLastConnectionState);
        }

@@ -426,6 +430,7 @@ final class HearingAidStateMachine extends StateMachine {
        public void enter() {
            Log.i(TAG, "Enter Connected(" + mDevice + "): "
                    + messageWhatToString(getCurrentMessage().what));
            mConnectionState = BluetoothProfile.STATE_CONNECTED;
            removeDeferredMessages(CONNECT);
            broadcastConnectionState(BluetoothProfile.STATE_CONNECTED, mLastConnectionState);
        }
@@ -496,20 +501,7 @@ final class HearingAidStateMachine extends StateMachine {
    }

    int getConnectionState() {
        String currentState = getCurrentState().getName();
        switch (currentState) {
            case "Disconnected":
                return BluetoothProfile.STATE_DISCONNECTED;
            case "Connecting":
                return BluetoothProfile.STATE_CONNECTING;
            case "Connected":
                return BluetoothProfile.STATE_CONNECTED;
            case "Disconnecting":
                return BluetoothProfile.STATE_DISCONNECTING;
            default:
                Log.e(TAG, "Bad currentState: " + currentState);
                return BluetoothProfile.STATE_DISCONNECTED;
        }
        return mConnectionState;
    }

    BluetoothDevice getDevice() {
@@ -517,7 +509,7 @@ final class HearingAidStateMachine extends StateMachine {
    }

    synchronized boolean isConnected() {
        return getCurrentState() == mConnected;
        return (getConnectionState() == BluetoothProfile.STATE_CONNECTED);
    }

    // This method does not check for error condition (newState == prevState)