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

Commit 4e7cdc6b authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "BluetoothInCallService: Use handle as the key of mClccIndexMap"

parents 9b62f5f1 d3d5c639
Loading
Loading
Loading
Loading
+20 −5
Original line number Diff line number Diff line
@@ -128,7 +128,7 @@ public class BluetoothInCallService extends InCallService {
    public final HashMap<Integer, BluetoothCall> mBluetoothCallHashMap = new HashMap<>();

    // A map from Calls to indexes used to identify calls for CLCC (C* List Current Calls).
    private final Map<BluetoothCall, Integer> mClccIndexMap = new HashMap<>();
    private final Map<String, Integer> mClccIndexMap = new HashMap<>();

    private static BluetoothInCallService sInstance = null;

@@ -582,7 +582,7 @@ public class BluetoothInCallService extends InCallService {
            mBluetoothCallHashMap.remove(call.getId());
        }

        mClccIndexMap.remove(call);
        mClccIndexMap.remove(getClccMapKey(call));
        updateHeadsetWithCallState(false /* force */);
    }

@@ -771,13 +771,28 @@ public class BluetoothInCallService extends InCallService {
        }
    }

    private String getClccMapKey(BluetoothCall call) {
        if (mCallInfo.isNullCall(call) || call.getHandle() == null) {
            return "";
        }
        Uri handle = call.getHandle();
        String key;
        if (call.hasProperty(Call.Details.PROPERTY_SELF_MANAGED)) {
            key = handle.toString() + " self managed " + call.getId();
        } else {
            key = handle.toString();
        }
        return key;
    }

    /**
     * Returns the caches index for the specified call.  If no such index exists, then an index is
     * given (smallest number starting from 1 that isn't already taken).
     */
    private int getIndexForCall(BluetoothCall call) {
        if (mClccIndexMap.containsKey(call)) {
            return mClccIndexMap.get(call);
        String key = getClccMapKey(call);
        if (mClccIndexMap.containsKey(key)) {
            return mClccIndexMap.get(key);
        }

        int i = 1;  // Indexes for bluetooth clcc are 1-based.
@@ -786,7 +801,7 @@ public class BluetoothInCallService extends InCallService {
        }

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

+31 −7
Original line number Diff line number Diff line
@@ -384,8 +384,11 @@ public class BluetoothInCallServiceTest {
        // BluetoothCall has been put into a CDMA "conference" with one BluetoothCall on hold.
        List<BluetoothCall> calls = new ArrayList<BluetoothCall>();
        BluetoothCall parentCall = createActiveCall();
        when(parentCall.getHandle()).thenReturn(Uri.parse("tel:555-0000"));
        final BluetoothCall foregroundCall = getMockCall();
        when(foregroundCall.getHandle()).thenReturn(Uri.parse("tel:555-0001"));
        final BluetoothCall heldCall = createHeldCall();
        when(heldCall.getHandle()).thenReturn(Uri.parse("tel:555-0002"));
        calls.add(parentCall);
        calls.add(foregroundCall);
        calls.add(heldCall);
@@ -399,9 +402,9 @@ public class BluetoothInCallServiceTest {
        when(foregroundCall.isIncoming()).thenReturn(false);
        when(heldCall.isIncoming()).thenReturn(true);
        when(foregroundCall.getGatewayInfo()).thenReturn(
                new GatewayInfo(null, null, Uri.parse("tel:555-0000")));
        when(heldCall.getGatewayInfo()).thenReturn(
                new GatewayInfo(null, null, Uri.parse("tel:555-0001")));
        when(heldCall.getGatewayInfo()).thenReturn(
                new GatewayInfo(null, null, Uri.parse("tel:555-0002")));
        addCallCapability(parentCall, Connection.CAPABILITY_MERGE_CONFERENCE);
        addCallCapability(parentCall, Connection.CAPABILITY_SWAP_CONFERENCE);
        removeCallCapability(parentCall, Connection.CAPABILITY_CONFERENCE_HAS_NO_CHILDREN);
@@ -422,9 +425,9 @@ public class BluetoothInCallServiceTest {
        mBluetoothInCallService.listCurrentCalls();

        verify(mMockBluetoothHeadset).clccResponse(eq(1), eq(0), eq(CALL_STATE_ACTIVE), eq(0),
                eq(false), eq("5550000"), eq(PhoneNumberUtils.TOA_Unknown));
        verify(mMockBluetoothHeadset).clccResponse(eq(2), eq(1), eq(CALL_STATE_HELD), eq(0),
                eq(false), eq("5550001"), eq(PhoneNumberUtils.TOA_Unknown));
        verify(mMockBluetoothHeadset).clccResponse(eq(2), eq(1), eq(CALL_STATE_HELD), eq(0),
                eq(false), eq("5550002"), eq(PhoneNumberUtils.TOA_Unknown));
        verify(mMockBluetoothHeadset).clccResponse(0, 0, 0, 0, false, null, 0);
    }

@@ -435,6 +438,9 @@ public class BluetoothInCallServiceTest {
        BluetoothCall parentCall = createActiveCall();
        final BluetoothCall confCall1 = getMockCall();
        final BluetoothCall confCall2 = createHeldCall();
        when(parentCall.getHandle()).thenReturn(Uri.parse("tel:555-0000"));
        when(confCall1.getHandle()).thenReturn(Uri.parse("tel:555-0001"));
        when(confCall2.getHandle()).thenReturn(Uri.parse("tel:555-0002"));
        calls.add(parentCall);
        calls.add(confCall1);
        calls.add(confCall2);
@@ -491,6 +497,7 @@ public class BluetoothInCallServiceTest {
                new GatewayInfo(null, null, Uri.parse("tel:555-0000")));
        when(waitingCall.getState()).thenReturn(Call.STATE_RINGING);
        when(waitingCall.isConference()).thenReturn(false);
        when(waitingCall.getHandle()).thenReturn(Uri.parse("tel:555-0000"));

        clearInvocations(mMockBluetoothHeadset);
        mBluetoothInCallService.listCurrentCalls();
@@ -530,6 +537,7 @@ public class BluetoothInCallServiceTest {
        when(ringingCall.getState()).thenReturn(Call.STATE_RINGING);
        when(ringingCall.isIncoming()).thenReturn(true);
        when(ringingCall.isConference()).thenReturn(false);
        when(ringingCall.getHandle()).thenReturn(Uri.parse("tel:555-0000"));
        when(ringingCall.getGatewayInfo()).thenReturn(
                new GatewayInfo(null, null, Uri.parse("tel:555-0000")));

@@ -553,6 +561,7 @@ public class BluetoothInCallServiceTest {
        when(ringingCall.getState()).thenReturn(Call.STATE_RINGING);
        when(ringingCall.isIncoming()).thenReturn(true);
        when(ringingCall.isConference()).thenReturn(false);
        when(ringingCall.getHandle()).thenReturn(Uri.parse("tel:5550000"));
        when(ringingCall.getGatewayInfo()).thenReturn(
                new GatewayInfo(null, null, Uri.parse("tel:5550000")));

@@ -570,6 +579,7 @@ public class BluetoothInCallServiceTest {
        when(newHoldingCall.getState()).thenReturn(Call.STATE_HOLDING);
        when(newHoldingCall.isIncoming()).thenReturn(true);
        when(newHoldingCall.isConference()).thenReturn(false);
        when(newHoldingCall.getHandle()).thenReturn(Uri.parse("tel:555-0001"));
        when(newHoldingCall.getGatewayInfo()).thenReturn(
                new GatewayInfo(null, null, Uri.parse("tel:555-0001")));

@@ -592,6 +602,7 @@ public class BluetoothInCallServiceTest {
        when(dialingCall.getState()).thenReturn(Call.STATE_DIALING);
        when(dialingCall.isIncoming()).thenReturn(false);
        when(dialingCall.isConference()).thenReturn(false);
        when(dialingCall.getHandle()).thenReturn(Uri.parse("tel:555-0000"));
        when(dialingCall.getGatewayInfo()).thenReturn(
                new GatewayInfo(null, null, Uri.parse("tel:555-0000")));

@@ -615,6 +626,7 @@ public class BluetoothInCallServiceTest {
        when(dialingCall.getState()).thenReturn(Call.STATE_DIALING);
        when(dialingCall.isIncoming()).thenReturn(false);
        when(dialingCall.isConference()).thenReturn(false);
        when(dialingCall.getHandle()).thenReturn(Uri.parse("tel:555-0000"));
        when(dialingCall.getGatewayInfo()).thenReturn(
                new GatewayInfo(null, null, Uri.parse("tel:555-0000")));
        BluetoothCall holdingCall = createHeldCall();
@@ -624,6 +636,7 @@ public class BluetoothInCallServiceTest {
        when(holdingCall.getState()).thenReturn(Call.STATE_HOLDING);
        when(holdingCall.isIncoming()).thenReturn(true);
        when(holdingCall.isConference()).thenReturn(false);
        when(holdingCall.getHandle()).thenReturn(Uri.parse("tel:555-0001"));
        when(holdingCall.getGatewayInfo()).thenReturn(
                new GatewayInfo(null, null, Uri.parse("tel:555-0001")));

@@ -649,13 +662,14 @@ public class BluetoothInCallServiceTest {
        when(parentCall.isConference()).thenReturn(true);
        when(parentCall.getState()).thenReturn(Call.STATE_ACTIVE);
        when(parentCall.isIncoming()).thenReturn(true);
        when(parentCall.getHandle()).thenReturn(Uri.parse("tel:555-0000"));
        when(mMockCallInfo.getBluetoothCalls()).thenReturn(calls);

        clearInvocations(mMockBluetoothHeadset);
        mBluetoothInCallService.listCurrentCalls();

        verify(mMockBluetoothHeadset).clccResponse(eq(1), eq(1), eq(CALL_STATE_ACTIVE), eq(0),
                eq(true), (String) isNull(), eq(-1));
                eq(true), eq("5550000"), eq(129));
        verify(mMockBluetoothHeadset).clccResponse(0, 0, 0, 0, false, null, 0);
    }

@@ -665,6 +679,10 @@ public class BluetoothInCallServiceTest {
        BluetoothCall parentCall = createHeldCall();
        BluetoothCall childCall1 = createActiveCall();
        BluetoothCall childCall2 = createActiveCall();
        when(parentCall.getHandle()).thenReturn(Uri.parse("tel:555-0000"));
        when(childCall1.getHandle()).thenReturn(Uri.parse("tel:555-0001"));
        when(childCall2.getHandle()).thenReturn(Uri.parse("tel:555-0002"));

        calls.add(parentCall);
        calls.add(childCall1);
        calls.add(childCall2);
@@ -690,9 +708,9 @@ public class BluetoothInCallServiceTest {
        mBluetoothInCallService.listCurrentCalls();

        verify(mMockBluetoothHeadset).clccResponse(eq(1), eq(0), eq(CALL_STATE_HELD), eq(0),
                eq(true), (String) isNull(), eq(-1));
                eq(true), eq("5550001"), eq(PhoneNumberUtils.TOA_Unknown));
        verify(mMockBluetoothHeadset).clccResponse(eq(2), eq(0), eq(CALL_STATE_HELD), eq(0),
                eq(true), (String) isNull(), eq(-1));
                eq(true), eq("5550002"), eq(PhoneNumberUtils.TOA_Unknown));
        verify(mMockBluetoothHeadset).clccResponse(0, 0, 0, 0, false, null, 0);
    }

@@ -845,11 +863,14 @@ public class BluetoothInCallServiceTest {
        // and simulate a swapConference().
        BluetoothCall parentCall = createActiveCall();
        final BluetoothCall foregroundCall = getMockCall();
        when(foregroundCall.getHandle()).thenReturn(Uri.parse("tel:555-0001"));
        final BluetoothCall heldCall = createHeldCall();
        when(heldCall.getHandle()).thenReturn(Uri.parse("tel:555-0002"));
        addCallCapability(parentCall, Connection.CAPABILITY_SWAP_CONFERENCE);
        removeCallCapability(parentCall, Connection.CAPABILITY_CONFERENCE_HAS_NO_CHILDREN);
        when(parentCall.isConference()).thenReturn(true);
        when(parentCall.wasConferencePreviouslyMerged()).thenReturn(false);
        when(heldCall.getHandle()).thenReturn(Uri.parse("tel:555-0000"));
        List<Integer> childrenIds = Arrays.asList(foregroundCall.getId(),
                heldCall.getId());
        when(parentCall.getChildrenIds()).thenReturn(childrenIds);
@@ -894,6 +915,8 @@ public class BluetoothInCallServiceTest {
        BluetoothCall parentCall = createActiveCall();
        final BluetoothCall foregroundCall = getMockCall();
        final BluetoothCall heldCall = createHeldCall();
        when(foregroundCall.getHandle()).thenReturn(Uri.parse("tel:555-0001"));
        when(heldCall.getHandle()).thenReturn(Uri.parse("tel:555-0002"));
        addCallCapability(parentCall, Connection.CAPABILITY_MERGE_CONFERENCE);
        removeCallCapability(parentCall, Connection.CAPABILITY_CONFERENCE_HAS_NO_CHILDREN);
        when(parentCall.isConference()).thenReturn(true);
@@ -912,6 +935,7 @@ public class BluetoothInCallServiceTest {
        BluetoothCall activeCall = createActiveCall();
        mBluetoothInCallService.onCallAdded(activeCall);
        doReturn(null).when(mMockCallInfo).getActiveCall();
        when(activeCall.getHandle()).thenReturn(Uri.parse("tel:555-0001"));
        mBluetoothInCallService.onCallRemoved(activeCall);

        verify(mMockBluetoothHeadset).phoneStateChanged(eq(0), eq(0), eq(CALL_STATE_IDLE),