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

Commit e6a18c06 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Ensure external calls are ended on the headset." am: 05440d82 am:...

Merge "Ensure external calls are ended on the headset." am: 05440d82 am: 06fd5298 am: e7c04fb1

Original change: https://android-review.googlesource.com/c/platform/packages/modules/Bluetooth/+/2446576



Change-Id: Ic1b2ee4699e6d0dc9dcfcf3f9e708fd9c88a345d
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 40d0fa94 e7c04fb1
Loading
Loading
Loading
Loading
+13 −7
Original line number Diff line number Diff line
@@ -269,7 +269,7 @@ public class BluetoothInCallService extends InCallService {
                return;
            }
            if (call.isExternalCall()) {
                onCallRemoved(call);
                onCallRemoved(call, false /* forceRemoveCallback */);
            } else {
                onCallAdded(call);
            }
@@ -607,13 +607,19 @@ public class BluetoothInCallService extends InCallService {
        onCallAdded(new BluetoothCall(call));
    }

    public void onCallRemoved(BluetoothCall call) {
        if (call.isExternalCall()) {
            return;
        }
    /**
     * Called when a {@code BluetoothCall} has been removed from this in-call session.
     *
     * @param call the {@code BluetoothCall} to remove
     * @param forceRemoveCallback if true, this will always unregister this {@code InCallService} as
     *                            a callback for the given {@code BluetoothCall}, when false, this
     *                            will not remove the callback when the {@code BluetoothCall} is
     *                            external so that the call can be added back if no longer external.
     */
    public void onCallRemoved(BluetoothCall call, boolean forceRemoveCallback) {
        Log.d(TAG, "onCallRemoved");
        CallStateCallback callback = getCallback(call);
        if (callback != null) {
        if (callback != null && (forceRemoveCallback || !call.isExternalCall())) {
            call.unregisterCallback(callback);
        }

@@ -637,7 +643,7 @@ public class BluetoothInCallService extends InCallService {
            Log.w(TAG, "onCallRemoved, BluetoothCall is removed before registered");
            return;
        }
        onCallRemoved(bluetoothCall);
        onCallRemoved(bluetoothCall, true /* forceRemoveCallback */);
    }

    @Override
+34 −1
Original line number Diff line number Diff line
@@ -987,12 +987,45 @@ public class BluetoothInCallServiceTest {
        mBluetoothInCallService.onCallAdded(activeCall);
        doReturn(null).when(mMockCallInfo).getActiveCall();
        when(activeCall.getHandle()).thenReturn(Uri.parse("tel:555-0001"));
        mBluetoothInCallService.onCallRemoved(activeCall);

        mBluetoothInCallService.onCallRemoved(activeCall, true /* forceRemoveCallback */);

        verify(mMockBluetoothHeadset).phoneStateChanged(eq(0), eq(0), eq(CALL_STATE_IDLE),
                eq(""), eq(128), nullable(String.class));
    }

    @Test
    public void testOnDetailsChangeExternalRemovesCall() throws Exception {
        BluetoothCall activeCall = createActiveCall();
        mBluetoothInCallService.onCallAdded(activeCall);
        doReturn(null).when(mMockCallInfo).getActiveCall();
        when(activeCall.getHandle()).thenReturn(Uri.parse("tel:555-0001"));

        when(activeCall.isExternalCall()).thenReturn(true);
        mBluetoothInCallService.getCallback(activeCall).onDetailsChanged(activeCall, null);

        verify(mMockBluetoothHeadset).phoneStateChanged(eq(0), eq(0), eq(CALL_STATE_IDLE),
                eq(""), eq(128), nullable(String.class));
    }

    @Test
    public void testOnDetailsChangeExternalAddsCall() throws Exception {
        BluetoothCall activeCall = createActiveCall();
        mBluetoothInCallService.onCallAdded(activeCall);
        when(activeCall.getHandle()).thenReturn(Uri.parse("tel:555-0001"));
        BluetoothInCallService.CallStateCallback callBack = mBluetoothInCallService.getCallback(
                activeCall);

        when(activeCall.isExternalCall()).thenReturn(true);
        callBack.onDetailsChanged(activeCall, null);

        when(activeCall.isExternalCall()).thenReturn(false);
        callBack.onDetailsChanged(activeCall, null);

        verify(mMockBluetoothHeadset).phoneStateChanged(eq(1), eq(0), eq(CALL_STATE_IDLE),
                eq(""), eq(128), nullable(String.class));
    }

    @Test
    public void testOnCallStateChangedConnectingCall() throws Exception {
        BluetoothCall activeCall = getMockCall();