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

Commit 37b9e124 authored by Chen Chen's avatar Chen Chen
Browse files

BluetoothInCallService: Make sure non conference calls have indices starting from 1

Test: atest BluetoothInstrumentationTests
Bug: 244520986
Change-Id: I565e08c9019ce90c59e96d519417efeb65e5c39d
parent cfdb9e3e
Loading
Loading
Loading
Loading
+17 −6
Original line number Diff line number Diff line
@@ -132,6 +132,8 @@ public class BluetoothInCallService extends InCallService {

    protected boolean mOnCreateCalled = false;

    private int mMaxNumberOfCalls = 0;

    /**
     * Listens to connections and disconnections of bluetooth headsets.  We need to save the current
     * bluetooth headset so that we know where to send BluetoothCall updates.
@@ -552,6 +554,9 @@ public class BluetoothInCallService extends InCallService {
            call.registerCallback(callback);

            mBluetoothCallHashMap.put(call.getId(), call);
            if (!call.isConference()) {
                mMaxNumberOfCalls = Integer.max(mMaxNumberOfCalls, mBluetoothCallHashMap.size());
            }
            updateHeadsetWithCallState(false /* force */);

            BluetoothLeCall tbsCall = createTbsCall(call);
@@ -675,6 +680,7 @@ public class BluetoothInCallService extends InCallService {
        mCallbacks.clear();
        mBluetoothCallHashMap.clear();
        mClccIndexMap.clear();
        mMaxNumberOfCalls = 0;
    }

    private static boolean isConferenceWithNoChildren(BluetoothCall call) {
@@ -832,15 +838,20 @@ public class BluetoothInCallService extends InCallService {
        if (mClccIndexMap.containsKey(key)) {
            return mClccIndexMap.get(key);
        }

        int i = 1;  // Indexes for bluetooth clcc are 1-based.
        while (mClccIndexMap.containsValue(i)) {
            i++;
        int index = 1; // Indexes for bluetooth clcc are 1-based.
        if (call.isConference()) {
            index = mMaxNumberOfCalls + 1; // The conference call should have a higher index
            Log.i(TAG,
                  "getIndexForCall for conference call starting from "
                  + mMaxNumberOfCalls);
        }
        while (mClccIndexMap.containsValue(index)) {
            index++;
        }

        // NOTE: Indexes are removed in {@link #onCallRemoved}.
        mClccIndexMap.put(key, i);
        return i;
        mClccIndexMap.put(key, index);
        return index;
    }

    private boolean _processChld(int chld) {
+6 −4
Original line number Diff line number Diff line
@@ -665,8 +665,6 @@ public class BluetoothInCallServiceTest {
    public void testListCurrentCallsImsConference() throws Exception {
        ArrayList<BluetoothCall> calls = new ArrayList<>();
        BluetoothCall parentCall = createActiveCall();
        calls.add(parentCall);
        mBluetoothInCallService.onCallAdded(parentCall);

        addCallCapability(parentCall, Connection.CAPABILITY_CONFERENCE_HAS_NO_CHILDREN);
        when(parentCall.isConference()).thenReturn(true);
@@ -675,6 +673,9 @@ public class BluetoothInCallServiceTest {
        when(parentCall.getHandle()).thenReturn(Uri.parse("tel:555-0000"));
        when(mMockCallInfo.getBluetoothCalls()).thenReturn(calls);

        calls.add(parentCall);
        mBluetoothInCallService.onCallAdded(parentCall);

        clearInvocations(mMockBluetoothHeadset);
        mBluetoothInCallService.listCurrentCalls();

@@ -731,9 +732,7 @@ public class BluetoothInCallServiceTest {
        ArrayList<BluetoothCall> calls = new ArrayList<>();
        BluetoothCall conferenceCall = createActiveCall();
        when(conferenceCall.getHandle()).thenReturn(Uri.parse("tel:555-1234"));
        calls.add(conferenceCall);

        mBluetoothInCallService.onCallAdded(conferenceCall);
        addCallCapability(conferenceCall, Connection.CAPABILITY_MANAGE_CONFERENCE);
        when(conferenceCall.isConference()).thenReturn(true);
        when(conferenceCall.getState()).thenReturn(Call.STATE_ACTIVE);
@@ -743,6 +742,9 @@ public class BluetoothInCallServiceTest {
        when(conferenceCall.isIncoming()).thenReturn(true);
        when(mMockCallInfo.getBluetoothCalls()).thenReturn(calls);

        calls.add(conferenceCall);
        mBluetoothInCallService.onCallAdded(conferenceCall);

        clearInvocations(mMockBluetoothHeadset);
        mBluetoothInCallService.listCurrentCalls();
        verify(mMockBluetoothHeadset).clccResponse(