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

Commit 2d932458 authored by Tyler Gunn's avatar Tyler Gunn Committed by android-build-merger
Browse files

Merge "Add ability to set parent at the same time as adding a connection." into oc-dev

am: 60da84f0

Change-Id: I8312190ea419e8141f269468ca5fd23b694e72e5
parents 78c3a6e0 60da84f0
Loading
Loading
Loading
Loading
+41 −9
Original line number Diff line number Diff line
@@ -1870,6 +1870,23 @@ public class Call implements CreateConnectionResponse, EventManager.Loggable {
        }
    }

    /**
     * Sets this {@link Call} to has the specified {@code parentCall}.  Also sets the parent to
     * have this call as a child.
     * @param parentCall
     */
    void setParentAndChildCall(Call parentCall) {
        setParentCall(parentCall);
        setChildOf(parentCall);
    }

    /**
     * Unlike {@link #setParentAndChildCall(Call)}, only sets the parent call but does NOT set
     * the child.
     * TODO: This is only required when adding existing connections as a workaround so that we
     * can avoid sending the "onParentChanged" callback until later.
     * @param parentCall The new parent call.
     */
    void setParentCall(Call parentCall) {
        if (parentCall == this) {
            Log.e(this, new Exception(), "setting the parent to self");
@@ -1879,22 +1896,37 @@ public class Call implements CreateConnectionResponse, EventManager.Loggable {
            // nothing to do
            return;
        }
        Preconditions.checkState(parentCall == null || mParentCall == null);

        Call oldParent = mParentCall;
        if (mParentCall != null) {
            mParentCall.removeChildCall(this);
        }
        mParentCall = parentCall;
        if (mParentCall != null) {
            mParentCall.addChildCall(this);
    }

        Log.addEvent(this, LogUtils.Events.SET_PARENT, mParentCall);
    /**
     * To be called after {@link #setParentCall(Call)} to complete setting the parent by adding
     * this call as a child of another call.
     * <p>
     * Note: The fact that the {@link Listener#onParentChanged(Call)} callback is called here seems
     * counter-intuitive; it is done here so that when this method is called from
     * {@link CallsManager#createCallForExistingConnection(String, ParcelableConnection)} we can
     * delay informing InCallServices of the change in parent relationship until AFTER the call has
     * been added to Telecom.
     * @param parentCall The new parent for this call.
     */
    void setChildOf(Call parentCall) {
        if (parentCall == null) {
            return;
        }

        if (!parentCall.getChildCalls().contains(this)) {
            parentCall.addChildCall(this);

            Log.addEvent(this, LogUtils.Events.SET_PARENT, parentCall);
            for (Listener l : mListeners) {
                l.onParentChanged(this);
            }
        }
    }

    void setConferenceableCalls(List<Call> conferenceableCalls) {
        mConferenceableCalls.clear();
@@ -2011,7 +2043,7 @@ public class Call implements CreateConnectionResponse, EventManager.Loggable {
     * that the insurance policy lives in the framework side of things.
     */
    private void fixParentAfterDisconnect() {
        setParentCall(null);
        setParentAndChildCall(null);
    }

    /**
+23 −1
Original line number Diff line number Diff line
@@ -2075,7 +2075,7 @@ public class CallsManager extends Call.ListenerBase
        Trace.beginSection("removeCall");
        Log.v(this, "removeCall(%s)", call);

        call.setParentCall(null);  // need to clean up parent relationship before destroying.
        call.setParentAndChildCall(null);  // clean up parent relationship before destroying.
        call.removeListener(this);
        call.clearConnectionService();
        // TODO: clean up RTT pipes
@@ -2526,7 +2526,29 @@ public class CallsManager extends Call.ListenerBase
        if (extras != null && extras.containsKey(Connection.EXTRA_ORIGINAL_CONNECTION_ID)) {
            call.setOriginalConnectionId(extras.getString(Connection.EXTRA_ORIGINAL_CONNECTION_ID));
        }
        Log.i(this, "createCallForExistingConnection: %s", connection);
        Call parentCall = null;
        if (!TextUtils.isEmpty(connection.getParentCallId())) {
            String parentId = connection.getParentCallId();
            parentCall = mCalls
                    .stream()
                    .filter(c -> c.getId().equals(parentId))
                    .findFirst()
                    .orElse(null);
            if (parentCall != null) {
                Log.i(this, "createCallForExistingConnection: %s added as child of %s.",
                        call.getId(),
                        parentCall.getId());
                // Set JUST the parent property, which won't send an update to the Incall UI.
                call.setParentCall(parentCall);
            }
        }
        addCall(call);
        if (parentCall != null) {
            // Now, set the call as a child of the parent since it has been added to Telecom.  This
            // is where we will inform InCall.
            call.setChildOf(parentCall);
        }

        return call;
    }
+3 −3
Original line number Diff line number Diff line
@@ -329,10 +329,10 @@ public class ConnectionServiceWrapper extends ServiceBinder {
                    if (childCall != null) {
                        if (conferenceCallId == null) {
                            Log.d(this, "unsetting parent: %s", conferenceCallId);
                            childCall.setParentCall(null);
                            childCall.setParentAndChildCall(null);
                        } else {
                            Call conferenceCall = mCallIdMapper.getCall(conferenceCallId);
                            childCall.setParentCall(conferenceCall);
                            childCall.setParentAndChildCall(conferenceCall);
                        }
                    } else {
                        // Log.w(this, "setIsConferenced, unknown call id: %s", args.arg1);
@@ -445,7 +445,7 @@ public class ConnectionServiceWrapper extends ServiceBinder {
                        Call childCall = mCallIdMapper.getCall(connId);
                        Log.d(this, "found child: %s", connId);
                        if (childCall != null) {
                            childCall.setParentCall(conferenceCall);
                            childCall.setParentAndChildCall(conferenceCall);
                        }
                    }
                }