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

Commit 8452be0e authored by Tyler Gunn's avatar Tyler Gunn
Browse files

Modify Telecom to have "one call ID to rule them all".

- Add call ID to the Telecom call class.
- Modify CallIdMapper to use Telecom call ID instead of a new sequentially
generated one.
- Remove isValidCallId and isValidConferenceId from CallIdMapper as they
are no longer required.
- Modify event logger to use telecom call ID instead of a sequential ID.

Bug: 23357902
Change-Id: I485f751d1668e96b7787c4be97aa76c1e5ec0798
parent 5d28bc0e
Loading
Loading
Loading
Loading
+16 −2
Original line number Diff line number Diff line
@@ -65,6 +65,8 @@ import java.util.concurrent.ConcurrentHashMap;
 */
@VisibleForTesting
public class Call implements CreateConnectionResponse {
    public final static String CALL_ID_UNKNOWN = "-1";

    /**
     * Listener for events on the call.
     */
@@ -320,6 +322,7 @@ public class Call implements CreateConnectionResponse {
    private final CallsManager mCallsManager;
    private final TelecomSystem.SyncRoot mLock;
    private final CallerInfoAsyncQueryFactory mCallerInfoAsyncQueryFactory;
    private final String mId;

    private boolean mWasConferencePreviouslyMerged = false;

@@ -346,6 +349,7 @@ public class Call implements CreateConnectionResponse {
     * @param isIncoming True if this is an incoming call.
     */
    public Call(
            String callId,
            Context context,
            CallsManager callsManager,
            TelecomSystem.SyncRoot lock,
@@ -358,6 +362,7 @@ public class Call implements CreateConnectionResponse {
            PhoneAccountHandle targetPhoneAccountHandle,
            boolean isIncoming,
            boolean isConference) {
        mId = callId;
        mState = isConference ? CallState.ACTIVE : CallState.NEW;
        mContext = context;
        mCallsManager = callsManager;
@@ -392,6 +397,7 @@ public class Call implements CreateConnectionResponse {
     * @param connectTimeMillis The connection time of the call.
     */
    Call(
            String callId,
            Context context,
            CallsManager callsManager,
            TelecomSystem.SyncRoot lock,
@@ -405,7 +411,7 @@ public class Call implements CreateConnectionResponse {
            boolean isIncoming,
            boolean isConference,
            long connectTimeMillis) {
        this(context, callsManager, lock, repository, contactsAsyncHelper,
        this(callId, context, callsManager, lock, repository, contactsAsyncHelper,
                callerInfoAsyncQueryFactory, handle, gatewayInfo,
                connectionManagerPhoneAccountHandle, targetPhoneAccountHandle, isIncoming,
                isConference);
@@ -438,7 +444,7 @@ public class Call implements CreateConnectionResponse {


        return String.format(Locale.US, "[%s, %s, %s, %s, %s, childs(%d), has_parent(%b), [%s]]",
                System.identityHashCode(this),
                mId,
                CallState.toString(mState),
                component,
                Log.piiHandle(mHandle),
@@ -502,6 +508,14 @@ public class Call implements CreateConnectionResponse {
            mCreateConnectionProcessor.isCallTimedOut();
    }

    /**
     * Returns the unique ID for this call as it exists in Telecom.
     * @return The call ID.
     */
    public String getId() {
        return mId;
    }

    /**
     * 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
+3 −26
Original line number Diff line number Diff line
@@ -75,12 +75,6 @@ class CallIdMapper {
    }

    private final BiMap<String, Call> mCalls = new BiMap<>();
    private final String mCallIdPrefix;
    private static int sIdCount;

    CallIdMapper(String callIdPrefix) {
        mCallIdPrefix = callIdPrefix + "@";
    }

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

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

    void removeCall(Call call) {
@@ -111,10 +105,10 @@ class CallIdMapper {
    }

    String getCallId(Call call) {
        if (call == null) {
        if (call == null || mCalls.getKey(call) == null) {
            return null;
        }
        return mCalls.getKey(call);
        return call.getId();
    }

    Call getCall(Object objId) {
@@ -122,9 +116,6 @@ class CallIdMapper {
        if (objId instanceof String) {
            callId = (String) objId;
        }
        if (!isValidCallId(callId) && !isValidConferenceId(callId)) {
            return null;
        }

        return mCalls.getValue(callId);
    }
@@ -132,18 +123,4 @@ class CallIdMapper {
    void clear() {
        mCalls.clear();
    }

    boolean isValidCallId(String callId) {
        // Note, no need for thread check, this method is thread safe.
        return callId != null && callId.startsWith(mCallIdPrefix);
    }

    boolean isValidConferenceId(String callId) {
        return callId != null;
    }

    String getNewId() {
        sIdCount++;
        return mCallIdPrefix + sIdCount;
    }
}
+23 −0
Original line number Diff line number Diff line
@@ -97,6 +97,7 @@ public class CallsManager extends Call.ListenerBase implements VideoProviderProx

    private static final int[] LIVE_CALL_STATES =
            {CallState.CONNECTING, CallState.SELECT_PHONE_ACCOUNT, CallState.DIALING, CallState.ACTIVE};
    public static final String TELECOM_CALL_ID_PREFIX = "TC@";

    /**
     * The main call repository. Keeps an instance of all live calls. New incoming and outgoing
@@ -109,6 +110,13 @@ public class CallsManager extends Call.ListenerBase implements VideoProviderProx
    private final Set<Call> mCalls = Collections.newSetFromMap(
            new ConcurrentHashMap<Call, Boolean>(8, 0.9f, 1));

    /**
     * The current telecom call ID.  Used when creating new instances of {@link Call}.  Should
     * only be accessed using the {@link #getNextCallId()} method which synchronizes on the
     * {@link #mLock} sync root.
     */
    private int mCallId = 0;

    private final ConnectionServiceRepository mConnectionServiceRepository;
    private final DtmfLocalTonePlayer mDtmfLocalTonePlayer;
    private final InCallController mInCallController;
@@ -492,6 +500,7 @@ public class CallsManager extends Call.ListenerBase implements VideoProviderProx
            handle = extras.getParcelable(TelephonyManager.EXTRA_INCOMING_NUMBER);
        }
        Call call = new Call(
                getNextCallId(),
                mContext,
                this,
                mLock,
@@ -515,6 +524,7 @@ public class CallsManager extends Call.ListenerBase implements VideoProviderProx
        Uri handle = extras.getParcelable(TelecomManager.EXTRA_UNKNOWN_CALL_HANDLE);
        Log.i(this, "addNewUnknownCall with handle: %s", Log.pii(handle));
        Call call = new Call(
                getNextCallId(),
                mContext,
                this,
                mLock,
@@ -570,6 +580,7 @@ public class CallsManager extends Call.ListenerBase implements VideoProviderProx
        // Create a call with original handle. The handle may be changed when the call is attached
        // to a connection service, but in most cases will remain the same.
        return new Call(
                getNextCallId(),
                mContext,
                this,
                mLock,
@@ -1178,6 +1189,7 @@ public class CallsManager extends Call.ListenerBase implements VideoProviderProx
    }

    Call createConferenceCall(
            String callId,
            PhoneAccountHandle phoneAccount,
            ParcelableConference parcelableConference) {

@@ -1189,6 +1201,7 @@ public class CallsManager extends Call.ListenerBase implements VideoProviderProx
                        parcelableConference.getConnectTimeMillis();

        Call call = new Call(
                callId,
                mContext,
                this,
                mLock,
@@ -1598,6 +1611,7 @@ public class CallsManager extends Call.ListenerBase implements VideoProviderProx
     */
    Call createCallForExistingConnection(String callId, ParcelableConnection connection) {
        Call call = new Call(
                getNextCallId(),
                mContext,
                this,
                mLock,
@@ -1624,6 +1638,15 @@ public class CallsManager extends Call.ListenerBase implements VideoProviderProx
        return call;
    }

    /**
     * @return A new unique telecom call Id.
     */
    private String getNextCallId() {
        synchronized(mLock) {
            return TELECOM_CALL_ID_PREFIX + (++mCallId);
        }
    }

    /**
     * Dumps the state of the {@link CallsManager}.
     *
+106 −156
Original line number Diff line number Diff line
@@ -70,11 +70,9 @@ final class ConnectionServiceWrapper extends ServiceBinder {
            try {
                synchronized (mLock) {
                    logIncoming("handleCreateConnectionComplete %s", callId);
                    if (mCallIdMapper.isValidCallId(callId)) {
                    ConnectionServiceWrapper.this
                            .handleCreateConnectionComplete(callId, request, connection);
                }
                }
            } finally {
                Binder.restoreCallingIdentity(token);
            }
@@ -86,8 +84,6 @@ final class ConnectionServiceWrapper extends ServiceBinder {
            try {
                synchronized (mLock) {
                    logIncoming("setActive %s", callId);
                    if (mCallIdMapper.isValidCallId(callId) || mCallIdMapper
                            .isValidConferenceId(callId)) {
                    Call call = mCallIdMapper.getCall(callId);
                    if (call != null) {
                        mCallsManager.markCallAsActive(call);
@@ -95,7 +91,6 @@ final class ConnectionServiceWrapper extends ServiceBinder {
                        // Log.w(this, "setActive, unknown call id: %s", msg.obj);
                    }
                }
                }
            } finally {
                Binder.restoreCallingIdentity(token);
            }
@@ -107,7 +102,6 @@ final class ConnectionServiceWrapper extends ServiceBinder {
            try {
                synchronized (mLock) {
                    logIncoming("setRinging %s", callId);
                    if (mCallIdMapper.isValidCallId(callId)) {
                    Call call = mCallIdMapper.getCall(callId);
                    if (call != null) {
                        mCallsManager.markCallAsRinging(call);
@@ -115,7 +109,6 @@ final class ConnectionServiceWrapper extends ServiceBinder {
                        // Log.w(this, "setRinging, unknown call id: %s", msg.obj);
                    }
                }
                }
            } finally {
                Binder.restoreCallingIdentity(token);
            }
@@ -127,14 +120,11 @@ final class ConnectionServiceWrapper extends ServiceBinder {
            try {
                synchronized (mLock) {
                    logIncoming("setVideoProvider %s", callId);
                    if (mCallIdMapper.isValidCallId(callId)
                            || mCallIdMapper.isValidConferenceId(callId)) {
                    Call call = mCallIdMapper.getCall(callId);
                    if (call != null) {
                        call.setVideoProvider(videoProvider);
                    }
                }
                }
            } finally {
                Binder.restoreCallingIdentity(token);
            }
@@ -146,7 +136,6 @@ final class ConnectionServiceWrapper extends ServiceBinder {
            try {
                synchronized (mLock) {
                    logIncoming("setDialing %s", callId);
                    if (mCallIdMapper.isValidCallId(callId)) {
                    Call call = mCallIdMapper.getCall(callId);
                    if (call != null) {
                        mCallsManager.markCallAsDialing(call);
@@ -154,7 +143,6 @@ final class ConnectionServiceWrapper extends ServiceBinder {
                        // Log.w(this, "setDialing, unknown call id: %s", msg.obj);
                    }
                }
                }
            } finally {
                Binder.restoreCallingIdentity(token);
            }
@@ -166,8 +154,6 @@ final class ConnectionServiceWrapper extends ServiceBinder {
            try {
                synchronized (mLock) {
                    logIncoming("setDisconnected %s %s", callId, disconnectCause);
                    if (mCallIdMapper.isValidCallId(callId) || mCallIdMapper
                            .isValidConferenceId(callId)) {
                    Call call = mCallIdMapper.getCall(callId);
                    Log.d(this, "disconnect call %s %s", disconnectCause, call);
                    if (call != null) {
@@ -176,7 +162,6 @@ final class ConnectionServiceWrapper extends ServiceBinder {
                        // Log.w(this, "setDisconnected, unknown call id: %s", args.arg1);
                    }
                }
                }
            } finally {
                Binder.restoreCallingIdentity(token);
            }
@@ -188,8 +173,6 @@ final class ConnectionServiceWrapper extends ServiceBinder {
            try {
                synchronized (mLock) {
                    logIncoming("setOnHold %s", callId);
                    if (mCallIdMapper.isValidCallId(callId) || mCallIdMapper
                            .isValidConferenceId(callId)) {
                    Call call = mCallIdMapper.getCall(callId);
                    if (call != null) {
                        mCallsManager.markCallAsOnHold(call);
@@ -197,7 +180,6 @@ final class ConnectionServiceWrapper extends ServiceBinder {
                        // Log.w(this, "setOnHold, unknown call id: %s", msg.obj);
                    }
                }
                }
            } finally {
                Binder.restoreCallingIdentity(token);
            }
@@ -209,7 +191,6 @@ final class ConnectionServiceWrapper extends ServiceBinder {
            try {
                synchronized (mLock) {
                    logIncoming("setRingbackRequested %s %b", callId, ringback);
                    if (mCallIdMapper.isValidCallId(callId)) {
                    Call call = mCallIdMapper.getCall(callId);
                    if (call != null) {
                        call.setRingbackRequested(ringback);
@@ -217,7 +198,6 @@ final class ConnectionServiceWrapper extends ServiceBinder {
                        // Log.w(this, "setRingback, unknown call id: %s", args.arg1);
                    }
                }
                }
            } finally {
                Binder.restoreCallingIdentity(token);
            }
@@ -229,8 +209,6 @@ final class ConnectionServiceWrapper extends ServiceBinder {
            try {
                synchronized (mLock) {
                    logIncoming("removeCall %s", callId);
                    if (mCallIdMapper.isValidCallId(callId) || mCallIdMapper
                            .isValidConferenceId(callId)) {
                    Call call = mCallIdMapper.getCall(callId);
                    if (call != null) {
                        if (call.isAlive()) {
@@ -241,7 +219,6 @@ final class ConnectionServiceWrapper extends ServiceBinder {
                        }
                    }
                }
                }
            } finally {
                Binder.restoreCallingIdentity(token);
            }
@@ -253,8 +230,6 @@ final class ConnectionServiceWrapper extends ServiceBinder {
            try {
                synchronized (mLock) {
                    logIncoming("setConnectionCapabilities %s %d", callId, connectionCapabilities);
                    if (mCallIdMapper.isValidCallId(callId) || mCallIdMapper
                            .isValidConferenceId(callId)) {
                    Call call = mCallIdMapper.getCall(callId);
                    if (call != null) {
                        call.setConnectionCapabilities(connectionCapabilities);
@@ -263,7 +238,6 @@ final class ConnectionServiceWrapper extends ServiceBinder {
                        // "setConnectionCapabilities, unknown call id: %s", msg.obj);
                    }
                }
                }
            } finally {
                Binder.restoreCallingIdentity(token);
            }
@@ -299,7 +273,6 @@ final class ConnectionServiceWrapper extends ServiceBinder {
            try {
                synchronized (mLock) {
                    logIncoming("setConferenceMergeFailed %s", callId);
                    if (mCallIdMapper.isValidCallId(callId)) {
                    // TODO: we should move the UI for indication a merge failure here
                    // from CallNotifier.onSuppServiceFailed(). This way the InCallUI can
                    // deliver the message anyway that they want. b/20530631.
@@ -318,8 +291,6 @@ final class ConnectionServiceWrapper extends ServiceBinder {
                        Log.w(this, "setConferenceMergeFailed, unknown call id: %s", callId);
                    }
                }

                }
            } finally {
                Binder.restoreCallingIdentity(token);
            }
@@ -358,7 +329,7 @@ final class ConnectionServiceWrapper extends ServiceBinder {
                            parcelableConference.getPhoneAccount() != null) {
                        phAcc = parcelableConference.getPhoneAccount();
                    }
                    Call conferenceCall = mCallsManager.createConferenceCall(
                    Call conferenceCall = mCallsManager.createConferenceCall(callId,
                            phAcc, parcelableConference);
                    mCallIdMapper.addCall(conferenceCall, callId);
                    conferenceCall.setConnectionService(ConnectionServiceWrapper.this);
@@ -384,7 +355,6 @@ final class ConnectionServiceWrapper extends ServiceBinder {
            try {
                synchronized (mLock) {
                    logIncoming("onPostDialWait %s %s", callId, remaining);
                    if (mCallIdMapper.isValidCallId(callId)) {
                    Call call = mCallIdMapper.getCall(callId);
                    if (call != null) {
                        call.onPostDialWait(remaining);
@@ -392,7 +362,6 @@ final class ConnectionServiceWrapper extends ServiceBinder {
                        // Log.w(this, "onPostDialWait, unknown call id: %s", args.arg1);
                    }
                }
                }
            } finally {
                Binder.restoreCallingIdentity(token);
            }
@@ -404,7 +373,6 @@ final class ConnectionServiceWrapper extends ServiceBinder {
            try {
                synchronized (mLock) {
                    logIncoming("onPostDialChar %s %s", callId, nextChar);
                    if (mCallIdMapper.isValidCallId(callId)) {
                    Call call = mCallIdMapper.getCall(callId);
                    if (call != null) {
                        call.onPostDialChar(nextChar);
@@ -412,7 +380,6 @@ final class ConnectionServiceWrapper extends ServiceBinder {
                        // Log.w(this, "onPostDialChar, unknown call id: %s", args.arg1);
                    }
                }
                }
            } finally {
                Binder.restoreCallingIdentity(token);
            }
@@ -437,14 +404,11 @@ final class ConnectionServiceWrapper extends ServiceBinder {
            try {
                synchronized (mLock) {
                    logIncoming("setVideoState %s %d", callId, videoState);
                    if (mCallIdMapper.isValidCallId(callId)
                            || mCallIdMapper.isValidConferenceId(callId)) {
                    Call call = mCallIdMapper.getCall(callId);
                    if (call != null) {
                        call.setVideoState(videoState);
                    }
                }
                }
            } finally {
                Binder.restoreCallingIdentity(token);
            }
@@ -456,13 +420,11 @@ final class ConnectionServiceWrapper extends ServiceBinder {
            try {
                synchronized (mLock) {
                    logIncoming("setIsVoipAudioMode %s %b", callId, isVoip);
                    if (mCallIdMapper.isValidCallId(callId)) {
                    Call call = mCallIdMapper.getCall(callId);
                    if (call != null) {
                        call.setIsVoipAudioMode(isVoip);
                    }
                }
                }
            } finally {
                Binder.restoreCallingIdentity(token);
            }
@@ -474,14 +436,11 @@ final class ConnectionServiceWrapper extends ServiceBinder {
            try {
                synchronized (mLock) {
                    logIncoming("setStatusHints %s %s", callId, statusHints);
                    if (mCallIdMapper.isValidCallId(callId)
                            || mCallIdMapper.isValidConferenceId(callId)) {
                    Call call = mCallIdMapper.getCall(callId);
                    if (call != null) {
                        call.setStatusHints(statusHints);
                    }
                }
                }
            } finally {
                Binder.restoreCallingIdentity(token);
            }
@@ -493,14 +452,11 @@ final class ConnectionServiceWrapper extends ServiceBinder {
            try {
                synchronized(mLock) {
                    logIncoming("setExtras %s %s", callId, extras);
                    if (mCallIdMapper.isValidCallId(callId)
                            || mCallIdMapper.isValidConferenceId(callId)) {
                    Call call = mCallIdMapper.getCall(callId);
                    if (call != null) {
                        call.setExtras(extras);
                    }
                }
                }
            } finally {
                Binder.restoreCallingIdentity(token);
            }
@@ -512,13 +468,11 @@ final class ConnectionServiceWrapper extends ServiceBinder {
            try {
                synchronized (mLock) {
                    logIncoming("setAddress %s %s %d", callId, address, presentation);
                    if (mCallIdMapper.isValidCallId(callId)) {
                    Call call = mCallIdMapper.getCall(callId);
                    if (call != null) {
                        call.setHandle(address, presentation);
                    }
                }
                }
            } finally {
                Binder.restoreCallingIdentity(token);
            }
@@ -532,13 +486,11 @@ final class ConnectionServiceWrapper extends ServiceBinder {
                synchronized (mLock) {
                    logIncoming("setCallerDisplayName %s %s %d", callId, callerDisplayName,
                            presentation);
                    if (mCallIdMapper.isValidCallId(callId)) {
                    Call call = mCallIdMapper.getCall(callId);
                    if (call != null) {
                        call.setCallerDisplayName(callerDisplayName, presentation);
                    }
                }
                }
            } finally {
                Binder.restoreCallingIdentity(token);
            }
@@ -552,8 +504,6 @@ final class ConnectionServiceWrapper extends ServiceBinder {
                synchronized (mLock) {
                    logIncoming("setConferenceableConnections %s %s", callId,
                            conferenceableCallIds);
                    if (mCallIdMapper.isValidCallId(callId) ||
                            mCallIdMapper.isValidConferenceId(callId)) {
                    Call call = mCallIdMapper.getCall(callId);
                    if (call != null) {
                        List<Call> conferenceableCalls =
@@ -567,7 +517,6 @@ final class ConnectionServiceWrapper extends ServiceBinder {
                        call.setConferenceableCalls(conferenceableCalls);
                    }
                }
                }
            } finally {
                Binder.restoreCallingIdentity(token);
            }
@@ -591,7 +540,7 @@ final class ConnectionServiceWrapper extends ServiceBinder {
    }

    private final Adapter mAdapter = new Adapter();
    private final CallIdMapper mCallIdMapper = new CallIdMapper("ConnectionService");
    private final CallIdMapper mCallIdMapper = new CallIdMapper();
    private final Map<String, CreateConnectionResponse> mPendingResponses = new HashMap<>();

    private Binder2 mBinder = new Binder2();
@@ -672,7 +621,8 @@ final class ConnectionServiceWrapper extends ServiceBinder {
                                    call.getTargetPhoneAccount(),
                                    call.getHandle(),
                                    extras,
                                    call.getVideoState()),
                                    call.getVideoState(),
                                    callId),
                            call.isIncoming(),
                            call.isUnknown());
                } catch (RemoteException e) {
+66 −94

File changed.

Preview size limit exceeded, changes collapsed.

Loading