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

Commit c4ec1f70 authored by jonerlin's avatar jonerlin Committed by Automerger Merge Worker
Browse files

HearingAid: Check the value of mConnectionState in isConnected am: 816ceadd am: 1888c327

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


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


            removeDeferredMessages(DISCONNECT);
            removeDeferredMessages(DISCONNECT);


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


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


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


    int getConnectionState() {
    int getConnectionState() {
        String currentState = getCurrentState().getName();
        return mConnectionState;
        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;
        }
    }
    }


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


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


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