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

Commit 88cee458 authored by Sungsoo Lim's avatar Sungsoo Lim
Browse files

Send CLCC responses when clcc end mark arrived

If a HFP connection is made in the middle of CLSS responses, the
newly connected HF can't get the full CLCC responses. This CL saves
CLCC responses and send them together to the connected devices when
a CLCC end mark is sent.

Bug: 215674669
Tag: #refactor
Test: atest CtsBluetoothTestCases bluetooth_test_gd_unit
Change-Id: I271e87082a26373a210a4aaefdadb4390d562704
parent 33d07fae
Loading
Loading
Loading
Loading
+16 −2
Original line number Diff line number Diff line
@@ -99,6 +99,7 @@ public class HeadsetService extends ProfileService {
    private static final int[] CONNECTING_CONNECTED_STATES =
            {BluetoothProfile.STATE_CONNECTING, BluetoothProfile.STATE_CONNECTED};
    private static final int DIALING_OUT_TIMEOUT_MS = 10000;
    private static final int CLCC_END_MARK_INDEX = 0;

    // Timeout for state machine thread join, to prevent potential ANR.
    private static final int SM_THREAD_JOIN_TIMEOUT_MS = 1000;
@@ -125,6 +126,7 @@ public class HeadsetService extends ProfileService {
    private VoiceRecognitionTimeoutEvent mVoiceRecognitionTimeoutEvent;
    // Timeout when voice recognition is started by remote device
    @VisibleForTesting static int sStartVrTimeoutMs = 5000;
    private ArrayList<StateMachineTask> mPendingClccResponses = new ArrayList<>();
    private boolean mStarted;
    private boolean mCreated;
    private static HeadsetService sHeadsetService;
@@ -308,6 +310,14 @@ public class HeadsetService extends ProfileService {
        }
    }

    private void doForEachConnectedStateMachine(List<StateMachineTask> tasks) {
        synchronized (mStateMachines) {
            for (StateMachineTask task : tasks) {
                doForEachConnectedStateMachine(task);
            }
        }
    }

    void onDeviceStateChanged(HeadsetDeviceState deviceState) {
        doForEachConnectedStateMachine(
                stateMachine -> stateMachine.sendMessage(HeadsetStateMachine.DEVICE_STATE_CHANGED,
@@ -1839,10 +1849,14 @@ public class HeadsetService extends ProfileService {
    private void clccResponse(int index, int direction, int status, int mode, boolean mpty,
            String number, int type) {
        enforceCallingOrSelfPermission(MODIFY_PHONE_STATE, "Need MODIFY_PHONE_STATE permission");
        doForEachConnectedStateMachine(
                stateMachine -> stateMachine.sendMessage(HeadsetStateMachine.SEND_CCLC_RESPONSE,
        mPendingClccResponses.add(
                stateMachine -> stateMachine.sendMessage(HeadsetStateMachine.SEND_CLCC_RESPONSE,
                        new HeadsetClccResponse(index, direction, status, mode, mpty, number,
                                type)));
        if (index == CLCC_END_MARK_INDEX) {
            doForEachConnectedStateMachine(mPendingClccResponses);
            mPendingClccResponses.clear();
        }
    }

    private boolean sendVendorSpecificResultCode(BluetoothDevice device, String command,
+4 −4
Original line number Diff line number Diff line
@@ -94,7 +94,7 @@ public class HeadsetStateMachine extends StateMachine {
    static final int INTENT_CONNECTION_ACCESS_REPLY = 8;
    static final int CALL_STATE_CHANGED = 9;
    static final int DEVICE_STATE_CHANGED = 10;
    static final int SEND_CCLC_RESPONSE = 11;
    static final int SEND_CLCC_RESPONSE = 11;
    static final int SEND_VENDOR_SPECIFIC_RESULT_CODE = 12;
    static final int SEND_BSIR = 13;
    static final int DIALING_OUT_RESULT = 14;
@@ -868,7 +868,7 @@ public class HeadsetStateMachine extends StateMachine {
                    }
                    mNativeInterface.notifyDeviceStatus(mDevice, (HeadsetDeviceState) message.obj);
                    break;
                case SEND_CCLC_RESPONSE:
                case SEND_CLCC_RESPONSE:
                    processSendClccResponse((HeadsetClccResponse) message.obj);
                    break;
                case CLCC_RSP_TIMEOUT: {
@@ -2170,8 +2170,8 @@ public class HeadsetStateMachine extends StateMachine {
                return "CALL_STATE_CHANGED";
            case DEVICE_STATE_CHANGED:
                return "DEVICE_STATE_CHANGED";
            case SEND_CCLC_RESPONSE:
                return "SEND_CCLC_RESPONSE";
            case SEND_CLCC_RESPONSE:
                return "SEND_CLCC_RESPONSE";
            case SEND_VENDOR_SPECIFIC_RESULT_CODE:
                return "SEND_VENDOR_SPECIFIC_RESULT_CODE";
            case STACK_EVENT: