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

Commit 6e8f3d70 authored by Brad Ebinger's avatar Brad Ebinger
Browse files

Rename Telecom Call Ids to include attempt

Telecom Call Ids will now append an attempt id (in the form of an
integer) that will be used by the CreateConnetionProcessor to name the
Telecom Call Ids that are used during the creation of a Connection to
the ConnectionService. This allows us to better identify which
Connection is calling back to Telecom to update status, disconnect,
etc. Previously, all of the attempted Connections in
CreateConnectionProcessor would be given the same name, which could lead
to multiple Connections trying to manage the same Call object in
Telecom.

Also, a supporting tests were added and a few Unit Tests were fixed.

Bug: 28799824
Change-Id: I7e23497ab671712bc8d3cc9542537ae1c4829afc
parent 4c9140c8
Loading
Loading
Loading
Loading
+27 −4
Original line number Diff line number Diff line
@@ -343,6 +343,7 @@ public class Call implements CreateConnectionResponse {
    private final CallsManager mCallsManager;
    private final TelecomSystem.SyncRoot mLock;
    private final String mId;
    private String mConnectionId;
    private Analytics.CallInfo mAnalytics;

    private boolean mWasConferencePreviouslyMerged = false;
@@ -379,6 +380,8 @@ public class Call implements CreateConnectionResponse {
     */
    private boolean mIsVideoCallingSupported = false;

    private PhoneNumberUtilsAdapter mPhoneNumberUtilsAdapter;

    /**
     * Persists the specified parameters and initializes the new instance.
     *
@@ -404,6 +407,7 @@ public class Call implements CreateConnectionResponse {
            ConnectionServiceRepository repository,
            ContactsAsyncHelper contactsAsyncHelper,
            CallerInfoAsyncQueryFactory callerInfoAsyncQueryFactory,
            PhoneNumberUtilsAdapter phoneNumberUtilsAdapter,
            Uri handle,
            GatewayInfo gatewayInfo,
            PhoneAccountHandle connectionManagerPhoneAccountHandle,
@@ -412,11 +416,13 @@ public class Call implements CreateConnectionResponse {
            boolean shouldAttachToExistingConnection,
            boolean isConference) {
        mId = callId;
        mConnectionId = callId;
        mState = isConference ? CallState.ACTIVE : CallState.NEW;
        mContext = context;
        mCallsManager = callsManager;
        mLock = lock;
        mRepository = repository;
        mPhoneNumberUtilsAdapter = phoneNumberUtilsAdapter;
        setHandle(handle);
        mPostDialDigits = handle != null
                ? PhoneNumberUtils.extractPostDialPortion(handle.getSchemeSpecificPart()) : "";
@@ -458,6 +464,7 @@ public class Call implements CreateConnectionResponse {
            ConnectionServiceRepository repository,
            ContactsAsyncHelper contactsAsyncHelper,
            CallerInfoAsyncQueryFactory callerInfoAsyncQueryFactory,
            PhoneNumberUtilsAdapter phoneNumberUtilsAdapter,
            Uri handle,
            GatewayInfo gatewayInfo,
            PhoneAccountHandle connectionManagerPhoneAccountHandle,
@@ -467,7 +474,7 @@ public class Call implements CreateConnectionResponse {
            boolean isConference,
            long connectTimeMillis) {
        this(callId, context, callsManager, lock, repository, contactsAsyncHelper,
                callerInfoAsyncQueryFactory, handle, gatewayInfo,
                callerInfoAsyncQueryFactory, phoneNumberUtilsAdapter, handle, gatewayInfo,
                connectionManagerPhoneAccountHandle, targetPhoneAccountHandle, callDirection,
                shouldAttachToExistingConnection, isConference);

@@ -594,6 +601,21 @@ public class Call implements CreateConnectionResponse {
        return mId;
    }

    /**
     * Returns the unique ID for this call (see {@link #getId}) along with an attempt indicator that
     * iterates based on attempts to establish a {@link Connection} using createConnectionProcessor.
     * @return The call ID with an appended attempt id.
     */
    public String getConnectionId() {
        if(mCreateConnectionProcessor != null) {
            mConnectionId = mId + "_" +
                    String.valueOf(mCreateConnectionProcessor.getConnectionAttempt());
            return mConnectionId;
        } else {
            return mConnectionId;
        }
    }

    /**
     * Sets the call state. Although there exists the notion of appropriate state transitions
     * (see {@link CallState}), in practice those expectations break down when cellular systems
@@ -747,8 +769,9 @@ public class Call implements CreateConnectionResponse {
            // Let's not allow resetting of the emergency flag. Once a call becomes an emergency
            // call, it will remain so for the rest of it's lifetime.
            if (!mIsEmergencyCall) {
                mIsEmergencyCall = mHandle != null && PhoneNumberUtils.isLocalEmergencyNumber(
                        mContext, mHandle.getSchemeSpecificPart());
                mIsEmergencyCall = mHandle != null &&
                        mPhoneNumberUtilsAdapter.isLocalEmergencyNumber(mContext,
                                mHandle.getSchemeSpecificPart());
            }
            startCallerInfoLookup();
            for (Listener l : mListeners) {
@@ -1671,7 +1694,7 @@ public class Call implements CreateConnectionResponse {
            return false;
        }

        if (PhoneNumberUtils.isUriNumber(getHandle().toString())) {
        if (mPhoneNumberUtilsAdapter.isUriNumber(getHandle().toString())) {
            // The incoming number is actually a URI (i.e. a SIP address),
            // not a regular PSTN phone number, and we can't send SMSes to
            // SIP addresses.
+11 −2
Original line number Diff line number Diff line
@@ -77,7 +77,16 @@ public class CallIdMapper {
        }
    }

    public interface ICallInfo {
        String getCallId(Call call);
    }

    private final BiMap<String, Call> mCalls = new BiMap<>();
    private ICallInfo mCallInfo;

    public CallIdMapper(ICallInfo callInfo) {
        mCallInfo = callInfo;
    }

    void replaceCall(Call newCall, Call callToReplace) {
        // Use the old call's ID for the new call.
@@ -93,7 +102,7 @@ public class CallIdMapper {
    }

    void addCall(Call call) {
        addCall(call, call.getId());
        addCall(call, mCallInfo.getCallId(call));
    }

    void removeCall(Call call) {
@@ -111,7 +120,7 @@ public class CallIdMapper {
        if (call == null || mCalls.getKey(call) == null) {
            return null;
        }
        return call.getId();
        return mCallInfo.getCallId(call);
    }

    Call getCall(Object objId) {
+1 −1
Original line number Diff line number Diff line
@@ -148,7 +148,7 @@ public class CallIntentProcessor {
            // process will be running throughout the duration of the phone call and should never
            // be killed.
            NewOutgoingCallIntentBroadcaster broadcaster = new NewOutgoingCallIntentBroadcaster(
                    context, callsManager, call, intent, new PhoneNumberUtilsAdapterImpl(),
                    context, callsManager, call, intent, callsManager.getPhoneNumberUtilsAdapter(),
                    isPrivilegedDialer);
            final int result = broadcaster.processIntent();
            final boolean success = result == DisconnectCause.NOT_DISCONNECTED;
+14 −1
Original line number Diff line number Diff line
@@ -189,6 +189,7 @@ public class CallsManager extends Call.ListenerBase
    private final CallerInfoLookupHelper mCallerInfoLookupHelper;
    private final DefaultDialerManagerAdapter mDefaultDialerManagerAdapter;
    private final Timeouts.Adapter mTimeoutsAdapter;
    private final PhoneNumberUtilsAdapter mPhoneNumberUtilsAdapter;
    private final Set<Call> mLocallyDisconnectingCalls = new HashSet<>();
    private final Set<Call> mPendingCallsToDisconnect = new HashSet<>();
    /* Handler tied to thread in which CallManager was initialized. */
@@ -219,9 +220,11 @@ public class CallsManager extends Call.ListenerBase
            SystemStateProvider systemStateProvider,
            DefaultDialerManagerAdapter defaultDialerAdapter,
            Timeouts.Adapter timeoutsAdapter,
            AsyncRingtonePlayer asyncRingtonePlayer) {
            AsyncRingtonePlayer asyncRingtonePlayer,
            PhoneNumberUtilsAdapter phoneNumberUtilsAdapter) {
        mContext = context;
        mLock = lock;
        mPhoneNumberUtilsAdapter = phoneNumberUtilsAdapter;
        mContactsAsyncHelper = contactsAsyncHelper;
        mCallerInfoAsyncQueryFactory = callerInfoAsyncQueryFactory;
        mPhoneAccountRegistrar = phoneAccountRegistrar;
@@ -667,6 +670,7 @@ public class CallsManager extends Call.ListenerBase
                mConnectionServiceRepository,
                mContactsAsyncHelper,
                mCallerInfoAsyncQueryFactory,
                mPhoneNumberUtilsAdapter,
                handle,
                null /* gatewayInfo */,
                null /* connectionManagerPhoneAccount */,
@@ -699,6 +703,7 @@ public class CallsManager extends Call.ListenerBase
                mConnectionServiceRepository,
                mContactsAsyncHelper,
                mCallerInfoAsyncQueryFactory,
                mPhoneNumberUtilsAdapter,
                handle,
                null /* gatewayInfo */,
                null /* connectionManagerPhoneAccount */,
@@ -771,6 +776,7 @@ public class CallsManager extends Call.ListenerBase
                    mConnectionServiceRepository,
                    mContactsAsyncHelper,
                    mCallerInfoAsyncQueryFactory,
                    mPhoneNumberUtilsAdapter,
                    handle,
                    null /* gatewayInfo */,
                    null /* connectionManagerPhoneAccount */,
@@ -1543,6 +1549,11 @@ public class CallsManager extends Call.ListenerBase
        return getFirstCallWithState(null, states);
    }

    @VisibleForTesting
    public PhoneNumberUtilsAdapter getPhoneNumberUtilsAdapter() {
        return mPhoneNumberUtilsAdapter;
    }

    /**
     * Returns the first call that it finds with the given states. The states are treated as having
     * priority order so that any call with the first state will be returned before any call with
@@ -1600,6 +1611,7 @@ public class CallsManager extends Call.ListenerBase
                mConnectionServiceRepository,
                mContactsAsyncHelper,
                mCallerInfoAsyncQueryFactory,
                mPhoneNumberUtilsAdapter,
                null /* handle */,
                null /* gatewayInfo */,
                null /* connectionManagerPhoneAccount */,
@@ -1990,6 +2002,7 @@ public class CallsManager extends Call.ListenerBase
                mConnectionServiceRepository,
                mContactsAsyncHelper,
                mCallerInfoAsyncQueryFactory,
                mPhoneNumberUtilsAdapter,
                connection.getHandle() /* handle */,
                null /* gatewayInfo */,
                null /* connectionManagerPhoneAccount */,
+29 −13
Original line number Diff line number Diff line
@@ -636,7 +636,7 @@ public class ConnectionServiceWrapper extends ServiceBinder {
    }

    private final Adapter mAdapter = new Adapter();
    private final CallIdMapper mCallIdMapper = new CallIdMapper();
    private final CallIdMapper mCallIdMapper = new CallIdMapper(Call::getConnectionId);
    private final Map<String, CreateConnectionResponse> mPendingResponses = new HashMap<>();

    private Binder2 mBinder = new Binder2();
@@ -684,6 +684,17 @@ public class ConnectionServiceWrapper extends ServiceBinder {
        }
    }

    /** See {@link IConnectionService#removeConnectionServiceAdapter}. */
    private void removeConnectionServiceAdapter(IConnectionServiceAdapter adapter) {
        if (isServiceValid("removeConnectionServiceAdapter")) {
            try {
                logOutgoing("removeConnectionServiceAdapter %s", adapter);
                mServiceInterface.removeConnectionServiceAdapter(adapter);
            } catch (RemoteException e) {
            }
        }
    }

    /**
     * Creates a new connection for a new outgoing call or to attach to an existing incoming call.
     */
@@ -1003,7 +1014,16 @@ public class ConnectionServiceWrapper extends ServiceBinder {
    /** {@inheritDoc} */
    @Override
    protected void setServiceInterface(IBinder binder) {
        if (binder == null) {
        mServiceInterface = IConnectionService.Stub.asInterface(binder);
        Log.v(this, "Adding Connection Service Adapter.");
        addConnectionServiceAdapter(mAdapter);
    }

    /** {@inheritDoc} */
    @Override
    protected void removeServiceInterface() {
        Log.v(this, "Removing Connection Service Adapter.");
        removeConnectionServiceAdapter(mAdapter);
        // We have lost our service connection. Notify the world that this service is done.
        // We must notify the adapter before CallsManager. The adapter will force any pending
        // outgoing calls to try the next service. This needs to happen before CallsManager
@@ -1011,10 +1031,6 @@ public class ConnectionServiceWrapper extends ServiceBinder {
        handleConnectionServiceDeath();
        mCallsManager.handleConnectionServiceDeath(this);
        mServiceInterface = null;
        } else {
            mServiceInterface = IConnectionService.Stub.asInterface(binder);
            addConnectionServiceAdapter(mAdapter);
        }
    }

    private void handleCreateConnectionComplete(
Loading