Loading android/app/src/com/android/bluetooth/telephony/BluetoothInCallService.java +13 −7 Original line number Diff line number Diff line Loading @@ -269,7 +269,7 @@ public class BluetoothInCallService extends InCallService { return; } if (call.isExternalCall()) { onCallRemoved(call); onCallRemoved(call, false /* forceRemoveCallback */); } else { onCallAdded(call); } Loading Loading @@ -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); } Loading @@ -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 Loading android/app/tests/unit/src/com/android/bluetooth/telephony/BluetoothInCallServiceTest.java +34 −1 Original line number Diff line number Diff line Loading @@ -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(); Loading Loading
android/app/src/com/android/bluetooth/telephony/BluetoothInCallService.java +13 −7 Original line number Diff line number Diff line Loading @@ -269,7 +269,7 @@ public class BluetoothInCallService extends InCallService { return; } if (call.isExternalCall()) { onCallRemoved(call); onCallRemoved(call, false /* forceRemoveCallback */); } else { onCallAdded(call); } Loading Loading @@ -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); } Loading @@ -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 Loading
android/app/tests/unit/src/com/android/bluetooth/telephony/BluetoothInCallServiceTest.java +34 −1 Original line number Diff line number Diff line Loading @@ -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(); Loading