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

Commit 44c59ef2 authored by Tyler Gunn's avatar Tyler Gunn
Browse files

Correct behavior of self-managed incoming call dialog.

The dialog which is shown when there is an incoming self-managed call and
there is one or more ongoing calls in another ConnectionService needed to
have its behavior adjusted.  For incoming self-managed calls, it currently
shows whenever there is another ongoing call in another ConnectionService,
when in reality it ONLY needs to show if the other ongoing calls cannot
be held.

Adjusted the logic to check for this, as well as to check for calls in
another connectionservice based on the package, not based solely on the
targe phone account.  This matches recent changes made to simultaneous
call logic made elsewhere.

Test: Run CTS verifier test.
Bug: 131785694
Change-Id: I22084debef411e55c505931e1be981b2a53c96ca
parent e8a85b76
Loading
Loading
Loading
Loading
+19 −14
Original line number Original line Diff line number Diff line
@@ -3275,25 +3275,30 @@ public class CallsManager extends Call.ListenerBase
    }
    }


    /**
    /**
     * Given a {@link PhoneAccountHandle} determines if there are calls owned by any other
     * Given a {@link PhoneAccountHandle} determines if there are other unholdable calls owned by
     * {@link PhoneAccountHandle}.
     * another connection service.
     * @param phoneAccountHandle The {@link PhoneAccountHandle} to check.
     * @param phoneAccountHandle The {@link PhoneAccountHandle} to check.
     * @return {@code true} if there are other calls, {@code false} otherwise.
     * @return {@code true} if there are other unholdable calls, {@code false} otherwise.
     */
     */
    public boolean hasCallsForOtherPhoneAccount(PhoneAccountHandle phoneAccountHandle) {
    public boolean hasUnholdableCallsForOtherConnectionService(
        return getNumCallsForOtherPhoneAccount(phoneAccountHandle) > 0;
            PhoneAccountHandle phoneAccountHandle) {
        return getNumUnholdableCallsForOtherConnectionService(phoneAccountHandle) > 0;
    }
    }


    /**
    /**
     * Determines the number of calls present for PhoneAccounts other than the one specified.
     * Determines the number of unholdable calls present in a connection service other than the one
     * the passed phone account belonds to.
     * @param phoneAccountHandle The handle of the PhoneAccount.
     * @param phoneAccountHandle The handle of the PhoneAccount.
     * @return Number of calls owned by other PhoneAccounts.
     * @return Number of unholdable calls owned by other connection service.
     */
     */
    public int getNumCallsForOtherPhoneAccount(PhoneAccountHandle phoneAccountHandle) {
    public int getNumUnholdableCallsForOtherConnectionService(
            PhoneAccountHandle phoneAccountHandle) {
        return (int) mCalls.stream().filter(call ->
        return (int) mCalls.stream().filter(call ->
                !phoneAccountHandle.equals(call.getTargetPhoneAccount()) &&
                !phoneAccountHandle.getComponentName().equals(
                        call.getParentCall() == null &&
                        call.getTargetPhoneAccount().getComponentName())
                        !call.isExternalCall()).count();
                        && call.getParentCall() == null
                        && !call.isExternalCall()
                        && !canHold(call)).count();
    }
    }


    /**
    /**
@@ -3345,9 +3350,9 @@ public class CallsManager extends Call.ListenerBase
     * @return {@code true} if the system incoming call UI should be shown, {@code false} otherwise.
     * @return {@code true} if the system incoming call UI should be shown, {@code false} otherwise.
     */
     */
    public boolean shouldShowSystemIncomingCallUi(Call incomingCall) {
    public boolean shouldShowSystemIncomingCallUi(Call incomingCall) {
        return incomingCall.isIncoming() && incomingCall.isSelfManaged() &&
        return incomingCall.isIncoming() && incomingCall.isSelfManaged()
                hasCallsForOtherPhoneAccount(incomingCall.getTargetPhoneAccount()) &&
                && hasUnholdableCallsForOtherConnectionService(incomingCall.getTargetPhoneAccount())
                incomingCall.getHandoverSourceCall() == null;
                && incomingCall.getHandoverSourceCall() == null;
    }
    }


    private boolean makeRoomForOutgoingCall(Call call, boolean isEmergency) {
    private boolean makeRoomForOutgoingCall(Call call, boolean isEmergency) {
+8 −8
Original line number Original line Diff line number Diff line
@@ -35,15 +35,11 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.content.IntentFilter;
import android.content.pm.ApplicationInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager;
import android.location.Country;
import android.location.CountryDetector;
import android.net.Uri;
import android.net.Uri;
import android.os.Process;
import android.os.UserHandle;
import android.os.UserHandle;
import android.os.UserManager;
import android.os.UserManager;
import android.telecom.Log;
import android.telecom.Log;
import android.telecom.PhoneAccountHandle;
import android.telecom.PhoneAccountHandle;
import android.telephony.PhoneNumberUtils;


import java.io.FileNotFoundException;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.InputStream;
@@ -297,13 +293,17 @@ public class TelecomSystem {
        mIncomingCallNotifier = incomingCallNotifier;
        mIncomingCallNotifier = incomingCallNotifier;
        incomingCallNotifier.setCallsManagerProxy(new IncomingCallNotifier.CallsManagerProxy() {
        incomingCallNotifier.setCallsManagerProxy(new IncomingCallNotifier.CallsManagerProxy() {
            @Override
            @Override
            public boolean hasCallsForOtherPhoneAccount(PhoneAccountHandle phoneAccountHandle) {
            public boolean hasUnholdableCallsForOtherConnectionService(
                return mCallsManager.hasCallsForOtherPhoneAccount(phoneAccountHandle);
                    PhoneAccountHandle phoneAccountHandle) {
                return mCallsManager.hasUnholdableCallsForOtherConnectionService(
                        phoneAccountHandle);
            }
            }


            @Override
            @Override
            public int getNumCallsForOtherPhoneAccount(PhoneAccountHandle phoneAccountHandle) {
            public int getNumUnholdableCallsForOtherConnectionService(
                return mCallsManager.getNumCallsForOtherPhoneAccount(phoneAccountHandle);
                    PhoneAccountHandle phoneAccountHandle) {
                return mCallsManager.getNumUnholdableCallsForOtherConnectionService(
                        phoneAccountHandle);
            }
            }


            @Override
            @Override
+4 −4
Original line number Original line Diff line number Diff line
@@ -58,8 +58,8 @@ public class IncomingCallNotifier extends CallsManagerListenerBase {
     * Eliminates strict dependency between this class and CallsManager.
     * Eliminates strict dependency between this class and CallsManager.
     */
     */
    public interface CallsManagerProxy {
    public interface CallsManagerProxy {
        boolean hasCallsForOtherPhoneAccount(PhoneAccountHandle phoneAccountHandle);
        boolean hasUnholdableCallsForOtherConnectionService(PhoneAccountHandle phoneAccountHandle);
        int getNumCallsForOtherPhoneAccount(PhoneAccountHandle phoneAccountHandle);
        int getNumUnholdableCallsForOtherConnectionService(PhoneAccountHandle phoneAccountHandle);
        Call getActiveCall();
        Call getActiveCall();
    }
    }


@@ -137,7 +137,7 @@ public class IncomingCallNotifier extends CallsManagerListenerBase {
                .findFirst();
                .findFirst();
        Call incomingCall = incomingCallOp.orElse(null);
        Call incomingCall = incomingCallOp.orElse(null);
        if (incomingCall != null && mCallsManagerProxy != null &&
        if (incomingCall != null && mCallsManagerProxy != null &&
                !mCallsManagerProxy.hasCallsForOtherPhoneAccount(
                !mCallsManagerProxy.hasUnholdableCallsForOtherConnectionService(
                        incomingCallOp.get().getTargetPhoneAccount())) {
                        incomingCallOp.get().getTargetPhoneAccount())) {
            // If there is no calls in any other ConnectionService, we can rely on the
            // If there is no calls in any other ConnectionService, we can rely on the
            // third-party app to display its own incoming call UI.
            // third-party app to display its own incoming call UI.
@@ -210,7 +210,7 @@ public class IncomingCallNotifier extends CallsManagerListenerBase {
        boolean isOngoingVideo = ongoingCall != null ?
        boolean isOngoingVideo = ongoingCall != null ?
                VideoProfile.isVideo(ongoingCall.getVideoState()) : false;
                VideoProfile.isVideo(ongoingCall.getVideoState()) : false;
        int numOtherCalls = ongoingCall != null ?
        int numOtherCalls = ongoingCall != null ?
                mCallsManagerProxy.getNumCallsForOtherPhoneAccount(
                mCallsManagerProxy.getNumUnholdableCallsForOtherConnectionService(
                        incomingCall.getTargetPhoneAccount()) : 1;
                        incomingCall.getTargetPhoneAccount()) : 1;


        // Build the "IncomingApp call from John Smith" message.
        // Build the "IncomingApp call from John Smith" message.
+9 −9
Original line number Original line Diff line number Diff line
@@ -98,7 +98,7 @@ public class IncomingCallNotifierTest extends TelecomTestCase {
    @SmallTest
    @SmallTest
    @Test
    @Test
    public void testIncomingDuringOngoingCall() {
    public void testIncomingDuringOngoingCall() {
        when(mCallsManagerProxy.hasCallsForOtherPhoneAccount(any())).thenReturn(false);
        when(mCallsManagerProxy.hasUnholdableCallsForOtherConnectionService(any())).thenReturn(false);
        mIncomingCallNotifier.onCallAdded(mRingingCall);
        mIncomingCallNotifier.onCallAdded(mRingingCall);
        verify(mNotificationManager, never()).notify(eq(IncomingCallNotifier.NOTIFICATION_TAG),
        verify(mNotificationManager, never()).notify(eq(IncomingCallNotifier.NOTIFICATION_TAG),
                eq(IncomingCallNotifier.NOTIFICATION_INCOMING_CALL), any());
                eq(IncomingCallNotifier.NOTIFICATION_INCOMING_CALL), any());
@@ -110,8 +110,8 @@ public class IncomingCallNotifierTest extends TelecomTestCase {
    @SmallTest
    @SmallTest
    @Test
    @Test
    public void testIncomingDuringOngoingCall2() {
    public void testIncomingDuringOngoingCall2() {
        when(mCallsManagerProxy.hasCallsForOtherPhoneAccount(any())).thenReturn(false);
        when(mCallsManagerProxy.hasUnholdableCallsForOtherConnectionService(any())).thenReturn(false);
        when(mCallsManagerProxy.getNumCallsForOtherPhoneAccount(any())).thenReturn(0);
        when(mCallsManagerProxy.getNumUnholdableCallsForOtherConnectionService(any())).thenReturn(0);
        when(mCallsManagerProxy.getActiveCall()).thenReturn(mAudioCall);
        when(mCallsManagerProxy.getActiveCall()).thenReturn(mAudioCall);


        mIncomingCallNotifier.onCallAdded(mAudioCall);
        mIncomingCallNotifier.onCallAdded(mAudioCall);
@@ -126,8 +126,8 @@ public class IncomingCallNotifierTest extends TelecomTestCase {
    @SmallTest
    @SmallTest
    @Test
    @Test
    public void testCallRemoved() {
    public void testCallRemoved() {
        when(mCallsManagerProxy.hasCallsForOtherPhoneAccount(any())).thenReturn(true);
        when(mCallsManagerProxy.hasUnholdableCallsForOtherConnectionService(any())).thenReturn(true);
        when(mCallsManagerProxy.getNumCallsForOtherPhoneAccount(any())).thenReturn(1);
        when(mCallsManagerProxy.getNumUnholdableCallsForOtherConnectionService(any())).thenReturn(1);
        when(mCallsManagerProxy.getActiveCall()).thenReturn(mAudioCall);
        when(mCallsManagerProxy.getActiveCall()).thenReturn(mAudioCall);


        mIncomingCallNotifier.onCallAdded(mAudioCall);
        mIncomingCallNotifier.onCallAdded(mAudioCall);
@@ -145,8 +145,8 @@ public class IncomingCallNotifierTest extends TelecomTestCase {
    @SmallTest
    @SmallTest
    @Test
    @Test
    public void testDontShowDuringHandover1() {
    public void testDontShowDuringHandover1() {
        when(mCallsManagerProxy.hasCallsForOtherPhoneAccount(any())).thenReturn(true);
        when(mCallsManagerProxy.hasUnholdableCallsForOtherConnectionService(any())).thenReturn(true);
        when(mCallsManagerProxy.getNumCallsForOtherPhoneAccount(any())).thenReturn(1);
        when(mCallsManagerProxy.getNumUnholdableCallsForOtherConnectionService(any())).thenReturn(1);
        when(mCallsManagerProxy.getActiveCall()).thenReturn(mAudioCall);
        when(mCallsManagerProxy.getActiveCall()).thenReturn(mAudioCall);
        when(mRingingCall.getHandoverState()).thenReturn(HandoverState.HANDOVER_FROM_STARTED);
        when(mRingingCall.getHandoverState()).thenReturn(HandoverState.HANDOVER_FROM_STARTED);


@@ -164,8 +164,8 @@ public class IncomingCallNotifierTest extends TelecomTestCase {
    @SmallTest
    @SmallTest
    @Test
    @Test
    public void testDontShowDuringHandover2() {
    public void testDontShowDuringHandover2() {
        when(mCallsManagerProxy.hasCallsForOtherPhoneAccount(any())).thenReturn(true);
        when(mCallsManagerProxy.hasUnholdableCallsForOtherConnectionService(any())).thenReturn(true);
        when(mCallsManagerProxy.getNumCallsForOtherPhoneAccount(any())).thenReturn(1);
        when(mCallsManagerProxy.getNumUnholdableCallsForOtherConnectionService(any())).thenReturn(1);
        when(mCallsManagerProxy.getActiveCall()).thenReturn(mAudioCall);
        when(mCallsManagerProxy.getActiveCall()).thenReturn(mAudioCall);
        when(mRingingCall.getHandoverState()).thenReturn(HandoverState.HANDOVER_COMPLETE);
        when(mRingingCall.getHandoverState()).thenReturn(HandoverState.HANDOVER_COMPLETE);