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

Commit c6dbbcad authored by Sanket Agarwal's avatar Sanket Agarwal Committed by Gerrit Code Review
Browse files

Merge changes If009c2e0,Ib2097456,I032efd2d

* changes:
  Remove hashcode() override for Connection
  Handle the case of disconnecting -> active for PTS
  Cleanup state while transitioning to disconnected.
parents bc4e9af5 54d153c5
Loading
Loading
Loading
Loading
+3 −4
Original line number Diff line number Diff line
@@ -107,7 +107,7 @@ final class HeadsetClientStateMachine extends StateMachine {
    static final int TERMINATE_SPECIFIC_CALL = 53;

    // Timeouts.
    static final int CONNECTING_TIMEOUT_MS = 5000;
    static final int CONNECTING_TIMEOUT_MS = 10000;  // 10s

    static final int MAX_HFP_SCO_VOICE_CALL_VOLUME = 15; // HFP 1.5 spec.
    static final int MIN_HFP_SCO_VOICE_CALL_VOLUME = 1; // HFP 1.5 spec.
@@ -920,6 +920,8 @@ final class HeadsetClientStateMachine extends StateMachine {
            mVoiceRecognitionActive = HeadsetClientHalConstants.VR_STATE_STOPPED;
            mInBandRingtone = HeadsetClientHalConstants.IN_BAND_RING_NOT_PROVIDED;

            mCurrentDevice = null;

            mCalls.clear();
            mCallsUpdate.clear();

@@ -1113,7 +1115,6 @@ final class HeadsetClientStateMachine extends StateMachine {
                case HeadsetClientHalConstants.CONNECTION_STATE_DISCONNECTED:
                    broadcastConnectionState(mCurrentDevice, BluetoothProfile.STATE_DISCONNECTED,
                            BluetoothProfile.STATE_CONNECTING);
                    mCurrentDevice = null;
                    transitionTo(mDisconnected);
                    break;

@@ -1667,7 +1668,6 @@ final class HeadsetClientStateMachine extends StateMachine {
                        broadcastConnectionState(mCurrentDevice,
                                BluetoothProfile.STATE_DISCONNECTED,
                                BluetoothProfile.STATE_CONNECTED);
                        mCurrentDevice = null;
                        transitionTo(mDisconnected);
                    } else {
                        Log.e(TAG, "Disconnected from unknown device: " + device);
@@ -1851,7 +1851,6 @@ final class HeadsetClientStateMachine extends StateMachine {
                        broadcastConnectionState(mCurrentDevice,
                                BluetoothProfile.STATE_DISCONNECTED,
                                BluetoothProfile.STATE_CONNECTED);
                        mCurrentDevice = null;
                        transitionTo(mDisconnected);
                    } else {
                        Log.e(TAG, "Disconnected from unknown device: " + device);
+14 −12
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ public class HfpClientConnection extends Connection {

    private BluetoothHeadsetClientCall mCurrentCall;
    private boolean mClosed;
    private boolean mClosing = false;
    private boolean mLocalDisconnect;
    private boolean mClientHasEcc;
    private boolean mAdded;
@@ -168,13 +169,14 @@ public class HfpClientConnection extends Connection {
        }
    }

    private void close(int cause) {
    public synchronized void close(int cause) {
        if (DBG) {
            Log.d(TAG, "Closing " + mClosed);
            Log.d(TAG, "Closing call " + mCurrentCall + "state: " + mClosed);
        }
        if (mClosed) {
            return;
        }
        Log.d(TAG, "Setting " + mCurrentCall + " to disconnected " + getTelecomCallId());
        setDisconnected(new DisconnectCause(cause));

        mClosed = true;
@@ -183,8 +185,12 @@ public class HfpClientConnection extends Connection {
        destroy();
    }

    public synchronized boolean isClosing() {
        return mClosing;
    }

    @Override
    public void onPlayDtmfTone(char c) {
    public synchronized void onPlayDtmfTone(char c) {
        if (DBG) {
            Log.d(TAG, "onPlayDtmfTone " + c + " " + mCurrentCall);
        }
@@ -202,6 +208,7 @@ public class HfpClientConnection extends Connection {
        if (!mClosed) {
            mHeadsetProfile.terminateCall(mDevice, mCurrentCall);
            mLocalDisconnect = true;
            mClosing = true;
        }
    }

@@ -214,7 +221,7 @@ public class HfpClientConnection extends Connection {
    }

    @Override
    public void onHold() {
    public synchronized void onHold() {
        if (DBG) {
            Log.d(TAG, "onHold " + mCurrentCall);
        }
@@ -224,7 +231,7 @@ public class HfpClientConnection extends Connection {
    }

    @Override
    public void onUnhold() {
    public synchronized void onUnhold() {
        if (getConnectionService().getAllConnections().size() > 1) {
            Log.w(TAG, "Ignoring unhold; call hold on the foreground call");
            return;
@@ -238,7 +245,7 @@ public class HfpClientConnection extends Connection {
    }

    @Override
    public void onAnswer() {
    public synchronized void onAnswer() {
        if (DBG) {
            Log.d(TAG, "onAnswer " + mCurrentCall);
        }
@@ -248,7 +255,7 @@ public class HfpClientConnection extends Connection {
    }

    @Override
    public void onReject() {
    public synchronized void onReject() {
        if (DBG) {
            Log.d(TAG, "onReject " + mCurrentCall);
        }
@@ -266,11 +273,6 @@ public class HfpClientConnection extends Connection {
        return getAddress() == otherAddr || otherAddr != null && otherAddr.equals(getAddress());
    }

    @Override
    public int hashCode() {
        return getAddress() == null ? 0 : getAddress().hashCode();
    }

    @Override
    public String toString() {
        return "HfpClientConnection{" + getAddress() + "," + stateToString(getState()) + "," +
+23 −0
Original line number Diff line number Diff line
@@ -232,6 +232,17 @@ public class HfpClientConnectionService extends ConnectionService {
        }
        HfpClientConnection connection = findConnectionKey(call.getUUID());

        // We need to have special handling for calls that mysteriously convert from
        // DISCONNECTING -> ACTIVE/INCOMING state. This can happen for PTS (b/31159015).
        // We terminate the previous call and create a new one here.
        if (connection != null && isDisconnectingToActive(connection, call)) {
            connection.close(DisconnectCause.ERROR);
            synchronized (this) {
                mConnections.remove(call.getUUID());
            }
            connection = null;
        }

        if (connection != null) {
            connection.updateCall(call);
            connection.handleCallChanged();
@@ -569,4 +580,16 @@ public class HfpClientConnectionService extends ConnectionService {
        }
        return account;
    }

    private boolean isDisconnectingToActive(HfpClientConnection prevConn,
            BluetoothHeadsetClientCall newCall) {
        if (DBG) {
            Log.d(TAG, "prevConn " + prevConn.isClosing() + " new call " + newCall.getState());
        }
        if (prevConn.isClosing() &&
                newCall.getState() != BluetoothHeadsetClientCall.CALL_STATE_TERMINATED) {
            return true;
        }
        return false;
    }
}