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

Commit bb54587a authored by Sandeep Samdaria's avatar Sandeep Samdaria Committed by Gerrit Code Review
Browse files

Merge "Cache map client state machine state"

parents 1378e14b 11e6858e
Loading
Loading
Loading
Loading
+15 −20
Original line number Original line Diff line number Diff line
@@ -66,7 +66,6 @@ import com.android.bluetooth.btservice.MetricsLogger;
import com.android.bluetooth.btservice.ProfileService;
import com.android.bluetooth.btservice.ProfileService;
import com.android.bluetooth.map.BluetoothMapbMessageMime;
import com.android.bluetooth.map.BluetoothMapbMessageMime;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.IState;
import com.android.internal.util.State;
import com.android.internal.util.State;
import com.android.internal.util.StateMachine;
import com.android.internal.util.StateMachine;
import com.android.vcard.VCardConstants;
import com.android.vcard.VCardConstants;
@@ -135,6 +134,7 @@ class MceStateMachine extends StateMachine {


    // Connectivity States
    // Connectivity States
    private int mPreviousState = BluetoothProfile.STATE_DISCONNECTED;
    private int mPreviousState = BluetoothProfile.STATE_DISCONNECTED;
    private int mMostRecentState = BluetoothProfile.STATE_DISCONNECTED;
    private State mDisconnected;
    private State mDisconnected;
    private State mConnecting;
    private State mConnecting;
    private State mConnected;
    private State mConnected;
@@ -252,6 +252,9 @@ class MceStateMachine extends StateMachine {
    }
    }


    private void onConnectionStateChanged(int prevState, int state) {
    private void onConnectionStateChanged(int prevState, int state) {
        if (mMostRecentState == state) {
            return;
        }
        // mDevice == null only at setInitialState
        // mDevice == null only at setInitialState
        if (mDevice == null) {
        if (mDevice == null) {
            return;
            return;
@@ -263,6 +266,7 @@ class MceStateMachine extends StateMachine {
        if (prevState != state && state == BluetoothProfile.STATE_CONNECTED) {
        if (prevState != state && state == BluetoothProfile.STATE_CONNECTED) {
            MetricsLogger.logProfileConnectionEvent(BluetoothMetricsProto.ProfileId.MAP_CLIENT);
            MetricsLogger.logProfileConnectionEvent(BluetoothMetricsProto.ProfileId.MAP_CLIENT);
        }
        }
        setState(state);
        Intent intent = new Intent(BluetoothMapClient.ACTION_CONNECTION_STATE_CHANGED);
        Intent intent = new Intent(BluetoothMapClient.ACTION_CONNECTION_STATE_CHANGED);
        intent.putExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, prevState);
        intent.putExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, prevState);
        intent.putExtra(BluetoothProfile.EXTRA_STATE, state);
        intent.putExtra(BluetoothProfile.EXTRA_STATE, state);
@@ -273,21 +277,12 @@ class MceStateMachine extends StateMachine {
                Utils.getTempBroadcastOptions());
                Utils.getTempBroadcastOptions());
    }
    }


    public synchronized int getState() {
    private synchronized void setState(int state) {
        IState currentState = this.getCurrentState();
        mMostRecentState = state;
        if (currentState == null || currentState.getClass() == Disconnected.class) {
            return BluetoothProfile.STATE_DISCONNECTED;
        }
        if (currentState.getClass() == Connected.class) {
            return BluetoothProfile.STATE_CONNECTED;
    }
    }
        if (currentState.getClass() == Connecting.class) {

            return BluetoothProfile.STATE_CONNECTING;
    public synchronized int getState() {
        }
        return mMostRecentState;
        if (currentState.getClass() == Disconnecting.class) {
            return BluetoothProfile.STATE_DISCONNECTING;
        }
        return BluetoothProfile.STATE_DISCONNECTED;
    }
    }


    public boolean disconnect() {
    public boolean disconnect() {
@@ -306,7 +301,7 @@ class MceStateMachine extends StateMachine {
        if (contacts == null || contacts.length <= 0) {
        if (contacts == null || contacts.length <= 0) {
            return false;
            return false;
        }
        }
        if (this.getCurrentState() == mConnected) {
        if (mMostRecentState == BluetoothProfile.STATE_CONNECTED) {
            Bmessage bmsg = new Bmessage();
            Bmessage bmsg = new Bmessage();
            // Set type and status.
            // Set type and status.
            bmsg.setType(getDefaultMessageType());
            bmsg.setType(getDefaultMessageType());
@@ -368,7 +363,7 @@ class MceStateMachine extends StateMachine {
        if (DBG) {
        if (DBG) {
            Log.d(TAG, "getMessage" + handle);
            Log.d(TAG, "getMessage" + handle);
        }
        }
        if (this.getCurrentState() == mConnected) {
        if (mMostRecentState == BluetoothProfile.STATE_CONNECTED) {
            sendMessage(MSG_INBOUND_MESSAGE, handle);
            sendMessage(MSG_INBOUND_MESSAGE, handle);
            return true;
            return true;
        }
        }
@@ -379,7 +374,7 @@ class MceStateMachine extends StateMachine {
        if (DBG) {
        if (DBG) {
            Log.d(TAG, "getMessage");
            Log.d(TAG, "getMessage");
        }
        }
        if (this.getCurrentState() == mConnected) {
        if (mMostRecentState == BluetoothProfile.STATE_CONNECTED) {
            sendMessage(MSG_GET_MESSAGE_LISTING, FOLDER_INBOX);
            sendMessage(MSG_GET_MESSAGE_LISTING, FOLDER_INBOX);
            return true;
            return true;
        }
        }
@@ -387,7 +382,7 @@ class MceStateMachine extends StateMachine {
    }
    }


    synchronized int getSupportedFeatures() {
    synchronized int getSupportedFeatures() {
        if (this.getCurrentState() == mConnected && mMasClient != null) {
        if (mMostRecentState == BluetoothProfile.STATE_CONNECTED && mMasClient != null) {
            if (DBG) Log.d(TAG, "returning getSupportedFeatures from SDP record");
            if (DBG) Log.d(TAG, "returning getSupportedFeatures from SDP record");
            return mMasClient.getSdpMasRecord().getSupportedFeatures();
            return mMasClient.getSdpMasRecord().getSupportedFeatures();
        }
        }
@@ -399,7 +394,7 @@ class MceStateMachine extends StateMachine {
        if (DBG) {
        if (DBG) {
            Log.d(TAG, "setMessageStatus(" + handle + ", " + status + ")");
            Log.d(TAG, "setMessageStatus(" + handle + ", " + status + ")");
        }
        }
        if (this.getCurrentState() == mConnected) {
        if (mMostRecentState == BluetoothProfile.STATE_CONNECTED) {
            RequestSetMessageStatus.StatusIndicator statusIndicator;
            RequestSetMessageStatus.StatusIndicator statusIndicator;
            byte value;
            byte value;
            switch (status) {
            switch (status) {