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

Commit ceb03cc8 authored by Tyler Gunn's avatar Tyler Gunn Committed by Android (Google) Code Review
Browse files

Merge "Correct behavior of self-managed incoming call dialog." into qt-dev

parents 136e82f7 44c59ef2
Loading
Loading
Loading
Loading
+19 −14
Original line number 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
     * {@link PhoneAccountHandle}.
     * Given a {@link PhoneAccountHandle} determines if there are other unholdable calls owned by
     * another connection service.
     * @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) {
        return getNumCallsForOtherPhoneAccount(phoneAccountHandle) > 0;
    public boolean hasUnholdableCallsForOtherConnectionService(
            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.
     * @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 ->
                !phoneAccountHandle.equals(call.getTargetPhoneAccount()) &&
                        call.getParentCall() == null &&
                        !call.isExternalCall()).count();
                !phoneAccountHandle.getComponentName().equals(
                        call.getTargetPhoneAccount().getComponentName())
                        && 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.
     */
    public boolean shouldShowSystemIncomingCallUi(Call incomingCall) {
        return incomingCall.isIncoming() && incomingCall.isSelfManaged() &&
                hasCallsForOtherPhoneAccount(incomingCall.getTargetPhoneAccount()) &&
                incomingCall.getHandoverSourceCall() == null;
        return incomingCall.isIncoming() && incomingCall.isSelfManaged()
                && hasUnholdableCallsForOtherConnectionService(incomingCall.getTargetPhoneAccount())
                && incomingCall.getHandoverSourceCall() == null;
    }

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

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

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

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

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

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

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

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

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