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

Commit 933cfc73 authored by Tyler Gunn's avatar Tyler Gunn
Browse files

Change semantics of onCallCreated to be onStartCreateConnection.

onCallCreated encapsulated other things which happen prior to the call
being added to the CallAnomalyWatchDog.  For outgoing calls in particular,
this includes the NewOutgoingCallBroadcast being sent and the
CallRedirectionService being run.  Repurposed this call back to instead
happen just before CreateConnetionPRocessor runs and the ConnetionService
is asked to start creating a new connection.

Also renamed onCallCreatedButNeverAdded to onCreateConnectionFailed for
symmetry.

This will clear up the anomalies we're seeing which are a result of the
slow NewOutgoingCallBroadcast.  The CallRedirectionService already has its
own timeout so we don't need CallAnomalyWatchdog to enforce one, and the
NOCB is going to be none blocking in the future we can ignore those cases
for now.

Test: Run Telecom unit tests
Fixes: 270068100
Change-Id: I47c8d2b0da2aa1027ba2b6d734cbd4080c80c4a5
parent ed96db50
Loading
Loading
Loading
Loading
+9 −7
Original line number Diff line number Diff line
@@ -153,8 +153,12 @@ public class CallAnomalyWatchdog extends CallsManagerListenerBase implements Cal
        mClockProxy = clockProxy;
    }

    /**
     * Start tracking a call that we're waiting for a ConnectionService to create.
     * @param call the call.
     */
    @Override
    public void onCallCreated(Call call) {
    public void onStartCreateConnection(Call call) {
        maybeTrackCall(call);
        call.addListener(this);
    }
@@ -165,15 +169,13 @@ public class CallAnomalyWatchdog extends CallsManagerListenerBase implements Cal
    }

    /**
     * Override of {@link CallsManagerListenerBase} to track when calls are created but
     * intentionally not added to mCalls. These calls should no longer be tracked by the
     * CallAnomalyWatchdog.
     * Override of {@link CallsManagerListenerBase} to track when calls have failed to be created by
     * a ConnectionService.  These calls should no longer be tracked by the CallAnomalyWatchdog.
     * @param call the call
     */

    @Override
    public void onCallCreatedButNeverAdded(Call call) {
        Log.i(this, "onCallCreatedButNeverAdded: call=%s", call.toString());
    public void onCreateConnectionFailed(Call call) {
        Log.i(this, "onCreateConnectionFailed: call=%s", call.toString());
        stopTrackingCall(call);
    }

+17 −22
Original line number Diff line number Diff line
@@ -61,7 +61,6 @@ import android.media.MediaPlayer;
import android.media.ToneGenerator;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Binder;
import android.os.Bundle;
import android.os.Handler;
import android.os.HandlerThread;
@@ -109,7 +108,6 @@ import android.util.Pair;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.view.accessibility.AccessibilityManager;
import android.widget.Button;

import com.android.internal.annotations.VisibleForTesting;
@@ -176,14 +174,13 @@ public class CallsManager extends Call.ListenerBase
    @VisibleForTesting
    public interface CallsManagerListener {
        /**
         * Informs listeners when a {@link Call} is newly created but not yet added to
         * {@link #mCalls}.  This is where the call has not yet been created by the underlying
         * {@link ConnectionService}.
         * Informs listeners when a {@link Call} is newly created, but not yet returned by a
         * {@link android.telecom.ConnectionService} implementation.
         * @param call the call.
         */
        default void onCallCreated(Call call) {}
        default void onStartCreateConnection(Call call) {}
        void onCallAdded(Call call);
        void onCallCreatedButNeverAdded(Call call);
        void onCreateConnectionFailed(Call call);
        void onCallRemoved(Call call);
        void onCallStateChanged(Call call, int oldState, int newState);
        void onConnectionServiceChanged(
@@ -1397,7 +1394,6 @@ public class CallsManager extends Call.ListenerBase
                isConference, /* isConference */
                mClockProxy,
                mToastFactory);
        notifyCallCreated(call);

        // set properties for transactional call
        if (extras.containsKey(TelecomManager.TRANSACTION_CALL_ID_KEY)) {
@@ -1565,6 +1561,7 @@ public class CallsManager extends Call.ListenerBase
            call.setIsCreateConnectionComplete(true);
            addCall(call);
        } else {
            notifyStartCreateConnection(call);
            call.startCreateConnection(mPhoneAccountRegistrar);
        }
        return call;
@@ -1591,12 +1588,11 @@ public class CallsManager extends Call.ListenerBase
                false, /* isConference */
                mClockProxy,
                mToastFactory);
        notifyCallCreated(call);

        call.initAnalytics();

        setIntentExtrasAndStartTime(call, extras);
        call.addListener(this);
        notifyStartCreateConnection(call);
        call.startCreateConnection(mPhoneAccountRegistrar);
    }

@@ -1719,8 +1715,6 @@ public class CallsManager extends Call.ListenerBase
            }

            call.initAnalytics(callingPackage, creationLogs.toString());
            // Let listeners know that we just created a new call but haven't added it yet.
            notifyCallCreated(call);

            // Ensure new calls related to self-managed calls/connections are set as such.  This
            // will be overridden when the actual connection is returned in startCreateConnection,
@@ -1959,7 +1953,7 @@ public class CallsManager extends Call.ListenerBase
                                Log.i(CallsManager.this, "Aborting call since there are no"
                                        + " available accounts.");
                                showErrorMessage(R.string.cant_call_due_to_no_supported_service);
                                mListeners.forEach(l -> l.onCallCreatedButNeverAdded(callToPlace));
                                mListeners.forEach(l -> l.onCreateConnectionFailed(callToPlace));
                                if (callToPlace.isEmergencyCall()){
                                    mAnomalyReporter.reportAnomaly(
                                            EMERGENCY_CALL_ABORTED_NO_PHONE_ACCOUNTS_ERROR_UUID,
@@ -2671,6 +2665,7 @@ public class CallsManager extends Call.ListenerBase
                    disconnectSelfManagedCalls("place emerg call" /* reason */);
                }
                try {
                    notifyStartCreateConnection(call);
                    call.startCreateConnection(mPhoneAccountRegistrar);
                } catch (Exception exception) {
                    // If an exceptions is thrown while creating the connection, prompt the user to
@@ -3560,7 +3555,7 @@ public class CallsManager extends Call.ListenerBase
                        EMERGENCY_CALL_DISCONNECTED_BEFORE_BEING_ADDED_ERROR_UUID,
                        EMERGENCY_CALL_DISCONNECTED_BEFORE_BEING_ADDED_ERROR_MSG);
            }
            mListeners.forEach(l -> l.onCallCreatedButNeverAdded(call));
            mListeners.forEach(l -> l.onCreateConnectionFailed(call));
        }

        // If a call diagnostic service is in use, we will log the original telephony-provided
@@ -5524,7 +5519,7 @@ public class CallsManager extends Call.ListenerBase
            call.setConnectionService(service);
            service.createConnectionFailed(call);
            if (!mCalls.contains(call)){
                mListeners.forEach(l -> l.onCallCreatedButNeverAdded(call));
                mListeners.forEach(l -> l.onCreateConnectionFailed(call));
            }
        }
    }
@@ -5549,18 +5544,18 @@ public class CallsManager extends Call.ListenerBase
            call.setConnectionService(service);
            service.createConferenceFailed(call);
            if (!mCalls.contains(call)){
                mListeners.forEach(l -> l.onCallCreatedButNeverAdded(call));
                mListeners.forEach(l -> l.onCreateConnectionFailed(call));
            }
        }
    }

    /**
     * Notify interested parties that a new call has been created, but not yet added to
     * CallsManager.
     * Notify interested parties that a new call is about to be handed off to a ConnectionService to
     * be created.
     * @param theCall the new call.
     */
    private void notifyCallCreated(final Call theCall) {
        mListeners.forEach(l -> l.onCallCreated(theCall));
    private void notifyStartCreateConnection(final Call theCall) {
        mListeners.forEach(l -> l.onStartCreateConnection(theCall));
    }

    /**
@@ -5725,7 +5720,7 @@ public class CallsManager extends Call.ListenerBase
                // Disconnect all self-managed calls to make priority for emergency call.
                disconnectSelfManagedCalls("emergency call");
            }

            notifyStartCreateConnection(call);
            call.startCreateConnection(mPhoneAccountRegistrar);
        }

@@ -5902,7 +5897,7 @@ public class CallsManager extends Call.ListenerBase
        extras.putBoolean(TelecomManager.EXTRA_IS_HANDOVER_CONNECTION, true);
        extras.putParcelable(TelecomManager.EXTRA_HANDOVER_FROM_PHONE_ACCOUNT,
                fromCall.getTargetPhoneAccount());

        notifyStartCreateConnection(call);
        call.startCreateConnection(mPhoneAccountRegistrar);
    }

+1 −1
Original line number Diff line number Diff line
@@ -35,7 +35,7 @@ public abstract class CallsManagerListenerBase implements CallsManager.CallsMana
    }

    @Override
    public void onCallCreatedButNeverAdded(Call call) {
    public void onCreateConnectionFailed(Call call) {
    }

    @Override
+6 −6
Original line number Diff line number Diff line
@@ -767,7 +767,7 @@ public class CallAnomalyWatchdogTest extends TelecomTestCase {
        Call call = getCall();
        call.setState(CallState.NEW, "foo");
        call.setIsCreateConnectionComplete(false);
        mCallAnomalyWatchdog.onCallCreated(call);
        mCallAnomalyWatchdog.onStartCreateConnection(call);

        //The connection fails before being added to CallsManager for a known reason:
        call.handleCreateConnectionFailure(new DisconnectCause(DisconnectCause.CANCELED));
@@ -795,7 +795,7 @@ public class CallAnomalyWatchdogTest extends TelecomTestCase {
        call.setCallDirection(Call.CALL_DIRECTION_OUTGOING);
        call.setState(CallState.NEW, "foo");
        call.setIsCreateConnectionComplete(false);
        mCallAnomalyWatchdog.onCallCreated(call);
        mCallAnomalyWatchdog.onStartCreateConnection(call);

        //The connection fails before being added to CallsManager for a known reason.
        call.handleCreateConnectionFailure(new DisconnectCause(DisconnectCause.CANCELED));
@@ -814,8 +814,8 @@ public class CallAnomalyWatchdogTest extends TelecomTestCase {
    /**
     * Emulate the case where a new incoming call is created but the connection fails for a known
     * reason before being added to CallsManager and CallsManager notifies the watchdog by invoking
     * onCallCreatedButNeverAdded(). In this case, the watchdog should stop tracking
     * the call and not trigger an anomaly report.
     * {@link CallsManager.CallsManagerListener#onCreateConnectionFailed(Call)}.
     * In this case, the watchdog should stop tracking the call and not trigger an anomaly report.
     */
    @Test
    public void testCallCreatedButNotAddedPreventsAnomalyReport() {
@@ -823,10 +823,10 @@ public class CallAnomalyWatchdogTest extends TelecomTestCase {
        Call call = getCall();
        call.setState(CallState.NEW, "foo");
        call.setIsCreateConnectionComplete(false);
        mCallAnomalyWatchdog.onCallCreated(call);
        mCallAnomalyWatchdog.onStartCreateConnection(call);

        //Telecom cancels the connection before adding it to CallsManager:
        mCallAnomalyWatchdog.onCallCreatedButNeverAdded(call);
        mCallAnomalyWatchdog.onCreateConnectionFailed(call);

        // Move the clock forward:
        when(mMockClockProxy.elapsedRealtime()).
+5 −7
Original line number Diff line number Diff line
@@ -135,10 +135,8 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;

@@ -2016,13 +2014,13 @@ public class CallsManagerTest extends TelecomTestCase {
        incomingCall.handleCreateConnectionFailure(new DisconnectCause(DisconnectCause.CANCELED));

        //Ensure the listener is notified properly:
        verify(listener).onCallCreatedButNeverAdded(incomingCall);
        verify(listener).onCreateConnectionFailed(incomingCall);
    }

    /**
     * Emulate the case where a new incoming call is created but the connection fails for a known
     * reason after being added to CallsManager. Since the call was added to CallsManager, the
     * listeners should not be notified via onCallCreatedButNeverAdded().
     * listeners should not be notified via onCreateConnectionFailed().
     */
    @Test
    public void testIncomingCallCreatedAndAddedDoNotNotifyListener() {
@@ -2037,8 +2035,8 @@ public class CallsManagerTest extends TelecomTestCase {
        //The connection fails after being added to CallsManager for a known reason:
        incomingCall.handleCreateConnectionFailure(new DisconnectCause(DisconnectCause.CANCELED));

        //Since the call was added to CallsManager, onCallCreatedButNeverAdded shouldn't be invoked:
        verify(listener, never()).onCallCreatedButNeverAdded(incomingCall);
        //Since the call was added to CallsManager, onCreateConnectionFailed shouldn't be invoked:
        verify(listener, never()).onCreateConnectionFailed(incomingCall);
    }

    /**
@@ -2069,7 +2067,7 @@ public class CallsManagerTest extends TelecomTestCase {
        Call result = callFuture.get(TEST_TIMEOUT, TimeUnit.MILLISECONDS);

        //Ensure the listener is notified properly:
        verify(listener).onCallCreatedButNeverAdded(any());
        verify(listener).onCreateConnectionFailed(any());
        assertNull(result);
    }