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

Commit 823fd3c7 authored by Santos Cordon's avatar Santos Cordon
Browse files

Update conference call APIs.

Clean up conference call APIs to use a distinct type separate from
Connection.  Also allow the addition of Conference calls at any point
using addConference() API method.

Bug:16844332
Bug:16449372
Change-Id: I34e45fde1aa43559f5f4e29b990929c188b16875
parent b511c4c1
Loading
Loading
Loading
Loading
+23 −6
Original line number Diff line number Diff line
@@ -28838,6 +28838,25 @@ package android.telecomm {
    field public static final android.os.Parcelable.Creator CREATOR;
  }
  public abstract class Conference {
    ctor public Conference(android.telecomm.PhoneAccountHandle);
    method public boolean addConnection(android.telecomm.Connection);
    method public void destroy();
    method public final int getCapabilities();
    method public final java.util.List<android.telecomm.Connection> getConnections();
    method public final android.telecomm.PhoneAccountHandle getPhoneAccount();
    method public final int getState();
    method public void onDisconnect();
    method public void onHold();
    method public void onSeparate(android.telecomm.Connection);
    method public void onUnhold();
    method public void removeConnection(android.telecomm.Connection);
    method public final void setActive();
    method public final void setCapabilities(int);
    method public final void setDisconnected(int, java.lang.String);
    method public final void setOnHold();
  }
  public abstract class Connection {
    ctor public Connection();
    method public static android.telecomm.Connection createCanceledConnection();
@@ -28848,22 +28867,19 @@ package android.telecomm {
    method public final int getCallCapabilities();
    method public final java.lang.String getCallerDisplayName();
    method public final int getCallerDisplayNamePresentation();
    method public final java.util.List<android.telecomm.Connection> getChildConnections();
    method public final android.telecomm.Conference getConference();
    method public final java.util.List<android.telecomm.Connection> getConferenceableConnections();
    method public final int getFailureCode();
    method public final java.lang.String getFailureMessage();
    method public final android.net.Uri getHandle();
    method public final int getHandlePresentation();
    method public final android.telecomm.Connection getParentConnection();
    method public final int getState();
    method public final android.telecomm.StatusHints getStatusHints();
    method public final android.telecomm.Connection.VideoProvider getVideoProvider();
    method public final int getVideoState();
    method public final boolean isConferenceConnection();
    method public final boolean isRequestingRingback();
    method public void onAbort();
    method public void onAnswer(int);
    method public void onChildrenChanged(java.util.List<android.telecomm.Connection>);
    method public void onConferenceWith(android.telecomm.Connection);
    method public void onDisconnect();
    method public void onHold();
@@ -28882,6 +28898,7 @@ package android.telecomm {
    method public final void setCallerDisplayName(java.lang.String, int);
    method public final void setCanceled();
    method public final void setConferenceableConnections(java.util.List<android.telecomm.Connection>);
    method public final void setConnectionService(android.telecomm.ConnectionService);
    method public final void setDialing();
    method public final void setDisconnected(int, java.lang.String);
    method public final void setFailed(int, java.lang.String);
@@ -28889,7 +28906,6 @@ package android.telecomm {
    method public final void setInitialized();
    method public final void setInitializing();
    method public final void setOnHold();
    method public final void setParentConnection(android.telecomm.Connection);
    method public final void setPostDialWait(java.lang.String);
    method public final void setRequestingRingback(boolean);
    method public final void setRinging();
@@ -28952,13 +28968,14 @@ package android.telecomm {
  public abstract class ConnectionService extends android.app.Service {
    ctor public ConnectionService();
    method public final void addConference(android.telecomm.Conference);
    method public final android.telecomm.RemoteConnection createRemoteIncomingConnection(android.telecomm.PhoneAccountHandle, android.telecomm.ConnectionRequest);
    method public final android.telecomm.RemoteConnection createRemoteOutgoingConnection(android.telecomm.PhoneAccountHandle, android.telecomm.ConnectionRequest);
    method public final java.util.Collection<android.telecomm.Connection> getAllConnections();
    method public final android.os.IBinder onBind(android.content.Intent);
    method public void onConference(android.telecomm.Connection, android.telecomm.Connection);
    method public void onConnectionAdded(android.telecomm.Connection);
    method public void onConnectionRemoved(android.telecomm.Connection);
    method public void onCreateConferenceConnection(java.lang.String, android.telecomm.Connection, android.telecomm.Response<java.lang.String, android.telecomm.Connection>);
    method public android.telecomm.Connection onCreateIncomingConnection(android.telecomm.PhoneAccountHandle, android.telecomm.ConnectionRequest);
    method public android.telecomm.Connection onCreateOutgoingConnection(android.telecomm.PhoneAccountHandle, android.telecomm.ConnectionRequest);
    field public static final java.lang.String SERVICE_INTERFACE = "android.telecomm.ConnectionService";
+38 −10
Original line number Diff line number Diff line
@@ -363,6 +363,7 @@ public final class Call {
    private final Phone mPhone;
    private final String mTelecommCallId;
    private final InCallAdapter mInCallAdapter;
    private final List<String> mChildrenIds = new ArrayList<>();
    private final List<Call> mChildren = new ArrayList<>();
    private final List<Call> mUnmodifiableChildren = Collections.unmodifiableList(mChildren);
    private final List<Listener> mListeners = new CopyOnWriteArrayList<>();
@@ -370,7 +371,8 @@ public final class Call {
    private final List<Call> mUnmodifiableConferenceableCalls =
            Collections.unmodifiableList(mConferenceableCalls);

    private Call mParent = null;
    private boolean mChildrenCached;
    private String mParentId = null;
    private int mState;
    private List<String> mCannedTextResponses = null;
    private String mRemainingPostDialSequence;
@@ -513,7 +515,10 @@ public final class Call {
     * child of any conference {@code Call}s.
     */
    public Call getParent() {
        return mParent;
        if (mParentId != null) {
            return mPhone.internalGetCallByTelecommId(mParentId);
        }
        return null;
    }

    /**
@@ -523,6 +528,21 @@ public final class Call {
     * {@code List} otherwise.
     */
    public List<Call> getChildren() {
        if (!mChildrenCached) {
            mChildrenCached = true;
            mChildren.clear();

            for(String id : mChildrenIds) {
                Call call = mPhone.internalGetCallByTelecommId(id);
                if (call == null) {
                    // At least one child was still not found, so do not save true for "cached"
                    mChildrenCached = false;
                } else {
                    mChildren.add(call);
                }
            }
        }

        return mUnmodifiableChildren;
    }

@@ -648,16 +668,18 @@ public final class Call {
            mState = state;
        }

        if (parcelableCall.getParentCallId() != null) {
            mParent = mPhone.internalGetCallByTelecommId(parcelableCall.getParentCallId());
        String parentId = parcelableCall.getParentCallId();
        boolean parentChanged = !Objects.equals(mParentId, parentId);
        if (parentChanged) {
            mParentId = parentId;
        }

        mChildren.clear();
        if (parcelableCall.getChildCallIds() != null) {
            for (int i = 0; i < parcelableCall.getChildCallIds().size(); i++) {
                mChildren.add(mPhone.internalGetCallByTelecommId(
                        parcelableCall.getChildCallIds().get(i)));
            }
        List<String> childCallIds = parcelableCall.getChildCallIds();
        boolean childrenChanged = !Objects.equals(childCallIds, mChildrenIds);
        if (childrenChanged) {
            mChildrenIds.clear();
            mChildrenIds.addAll(parcelableCall.getChildCallIds());
            mChildrenCached = false;
        }

        List<String> conferenceableCallIds = parcelableCall.getConferenceableCallIds();
@@ -689,6 +711,12 @@ public final class Call {
        if (videoCallChanged) {
            fireVideoCallChanged(mVideoCall);
        }
        if (parentChanged) {
            fireParentChanged(getParent());
        }
        if (childrenChanged) {
            fireChildrenChanged(getChildren());
        }

        // If we have transitioned to DISCONNECTED, that means we need to notify clients and
        // remove ourselves from the Phone. Note that we do this after completing all state updates
+238 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2014 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.telecomm;

import android.telephony.DisconnectCause;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CopyOnWriteArraySet;

/**
 * Represents a conference call which can contain any number of {@link Connection} objects.
 */
public abstract class Conference {

    /** @hide */
    public abstract static class Listener {
        public void onStateChanged(Conference conference, int oldState, int newState) {}
        public void onDisconnected(Conference conference, int cause, String message) {}
        public void onConnectionAdded(Conference conference, Connection connection) {}
        public void onConnectionRemoved(Conference conference, Connection connection) {}
        public void onDestroyed(Conference conference) {}
        public void onCapabilitiesChanged(Conference conference, int capabilities) {}
    }

    private final Set<Listener> mListeners = new CopyOnWriteArraySet<>();
    private final List<Connection> mChildConnections = new CopyOnWriteArrayList<>();
    private final List<Connection> mUnmodifiableChildConnection =
            Collections.unmodifiableList(mChildConnections);

    private PhoneAccountHandle mPhoneAccount;
    private int mState = Connection.STATE_NEW;
    private int mDisconnectCause = DisconnectCause.NOT_VALID;
    private int mCapabilities;
    private String mDisconnectMessage;

    public Conference(PhoneAccountHandle phoneAccount) {
        mPhoneAccount = phoneAccount;
    }

    public final PhoneAccountHandle getPhoneAccount() {
        return mPhoneAccount;
    }

    public final List<Connection> getConnections() {
        return mUnmodifiableChildConnection;
    }

    public final int getState() {
        return mState;
    }

    public final int getCapabilities() {
        return mCapabilities;
    }

    /**
     * Invoked when the Conference and all it's {@link Connection}s should be disconnected.
     */
    public void onDisconnect() {}

    /**
     * Invoked when the specified {@link Connection} should be separated from the conference call.
     *
     * @param connection The connection to separate.
     */
    public void onSeparate(Connection connection) {}

    /**
     * Invoked when the conference should be put on hold.
     */
    public void onHold() {}

    /**
     * Invoked when the conference should be moved from hold to active.
     */
    public void onUnhold() {}

    /**
     * Sets state to be on hold.
     */
    public final void setOnHold() {
        setState(Connection.STATE_HOLDING);
    }

    /**
     * Sets state to be active.
     */
    public final void setActive() {
        setState(Connection.STATE_ACTIVE);
    }

    /**
     * Sets state to disconnected.
     *
     * @param cause The reason for the disconnection, any of
     *         {@link android.telephony.DisconnectCause}.
     * @param message Optional call-service-provided message about the disconnect.
     */
    public final void setDisconnected(int cause, String message) {
        mDisconnectCause = cause;
        mDisconnectMessage = message;
        setState(Connection.STATE_DISCONNECTED);
        for (Listener l : mListeners) {
            l.onDisconnected(this, mDisconnectCause, mDisconnectMessage);
        }
    }

    /**
     * Sets the cabilities of a conference.
     */
    public final void setCapabilities(int capabilities) {
        if (capabilities != mCapabilities) {
            mCapabilities = capabilities;

            for (Listener l : mListeners) {
                l.onCapabilitiesChanged(this, mCapabilities);
            }
        }
    }

    /**
     * Adds the specified connection as a child of this conference.
     *
     * @param connection The connection to add.
     * @return True if the connection was successfully added.
     */
    public boolean addConnection(Connection connection) {
        if (connection != null && !mChildConnections.contains(connection)) {
            if (connection.setConference(this)) {
                mChildConnections.add(connection);
                for (Listener l : mListeners) {
                    l.onConnectionAdded(this, connection);
                }
                return true;
            }
        }
        return false;
    }

    /**
     * Removes the specified connection as a child of this conference.
     *
     * @param connection The connection to remove.
     * @return True if the connection was successfully removed.
     */
    public void removeConnection(Connection connection) {
        if (connection != null && mChildConnections.remove(connection)) {
            connection.resetConference();
            for (Listener l : mListeners) {
                l.onConnectionRemoved(this, connection);
            }
        }
    }

    /**
     * Tears down the conference object and any of it's current connections.
     */
    public void destroy() {
        Log.d(this, "destroying conference : %s", this);
        // Tear down the children.
        for (Connection connection : new ArrayList<>(mChildConnections)) {
            Log.d(this, "removing connection %s", connection);
            removeConnection(connection);
        }

        // If not yet disconnected, set the conference call as disconnected first.
        if (mState != Connection.STATE_DISCONNECTED) {
            Log.d(this, "setting to disconnected");
            setDisconnected(DisconnectCause.LOCAL, null);
        }

        // ...and notify.
        for (Listener l : mListeners) {
            l.onDestroyed(this);
        }
    }

    /**
     * Add a listener to be notified of a state change.
     *
     * @param listener The new listener.
     * @return This conference.
     * @hide
     */
    public final Conference addListener(Listener listener) {
        mListeners.add(listener);
        return this;
    }

    /**
     * Removes the specified listener.
     *
     * @param listener The listener to remove.
     * @return This conference.
     * @hide
     */
    public final Conference removeListener(Listener listener) {
        mListeners.remove(listener);
        return this;
    }

    private void setState(int newState) {
        if (newState != Connection.STATE_ACTIVE &&
                newState != Connection.STATE_HOLDING &&
                newState != Connection.STATE_DISCONNECTED) {
            Log.w(this, "Unsupported state transition for Conference call.",
                    Connection.stateToString(newState));
            return;
        }

        if (mState != newState) {
            int oldState = mState;
            mState = newState;
            for (Listener l : mListeners) {
                l.onStateChanged(this, oldState, newState);
            }
        }
    }
}
+71 −57
Original line number Diff line number Diff line
@@ -74,7 +74,6 @@ public abstract class Connection {
        public void onRequestingRingback(Connection c, boolean ringback) {}
        public void onDestroyed(Connection c) {}
        public void onCallCapabilitiesChanged(Connection c, int callCapabilities) {}
        public void onParentConnectionChanged(Connection c, Connection parent) {}
        public void onVideoProviderChanged(
                Connection c, VideoProvider videoProvider) {}
        public void onAudioModeIsVoipChanged(Connection c, boolean isVoip) {}
@@ -82,6 +81,7 @@ public abstract class Connection {
        public void onStartActivityFromInCall(Connection c, PendingIntent intent) {}
        public void onConferenceableConnectionsChanged(
                Connection c, List<Connection> conferenceableConnections) {}
        public void onConferenceChanged(Connection c, Conference conference) {}
    }

    public static abstract class VideoProvider {
@@ -455,9 +455,6 @@ public abstract class Connection {
     */
    private final Set<Listener> mListeners = Collections.newSetFromMap(
            new ConcurrentHashMap<Listener, Boolean>(8, 0.9f, 1));
    private final List<Connection> mChildConnections = new ArrayList<>();
    private final List<Connection> mUnmodifiableChildConnections =
            Collections.unmodifiableList(mChildConnections);
    private final List<Connection> mConferenceableConnections = new ArrayList<>();
    private final List<Connection> mUnmodifiableConferenceableConnections =
            Collections.unmodifiableList(mConferenceableConnections);
@@ -470,7 +467,6 @@ public abstract class Connection {
    private int mCallerDisplayNamePresentation;
    private boolean mRequestingRingback = false;
    private int mCallCapabilities;
    private Connection mParentConnection;
    private VideoProvider mVideoProvider;
    private boolean mAudioModeIsVoip;
    private StatusHints mStatusHints;
@@ -478,6 +474,8 @@ public abstract class Connection {
    private int mFailureCode;
    private String mFailureMessage;
    private boolean mIsCanceled;
    private Conference mConference;
    private ConnectionService mConnectionService;

    /**
     * Create a new Connection.
@@ -543,18 +541,19 @@ public abstract class Connection {
    }

    /**
     * Returns whether this connection is requesting that the system play a ringback tone
     * on its behalf.
     * @return The conference that this connection is a part of.  Null if it is not part of any
     *         conference.
     */
    public final boolean isRequestingRingback() {
        return mRequestingRingback;
    public final Conference getConference() {
        return mConference;
    }

    /**
     * Returns whether this connection is a conference connection (has child connections).
     * Returns whether this connection is requesting that the system play a ringback tone
     * on its behalf.
     */
    public final boolean isConferenceConnection() {
        return !mChildConnections.isEmpty();
    public final boolean isRequestingRingback() {
        return mRequestingRingback;
    }

    /**
@@ -655,34 +654,6 @@ public abstract class Connection {
        }
    }

    /**
     * TODO: Needs documentation.
     */
    public final void setParentConnection(Connection parentConnection) {
        Log.d(this, "parenting %s to %s", this, parentConnection);
        if (mParentConnection != parentConnection) {
            if (mParentConnection != null) {
                mParentConnection.removeChild(this);
            }
            mParentConnection = parentConnection;
            if (mParentConnection != null) {
                mParentConnection.addChild(this);
                // do something if the child connections goes down to ZERO.
            }
            for (Listener l : mListeners) {
                l.onParentConnectionChanged(this, mParentConnection);
            }
        }
    }

    public final Connection getParentConnection() {
        return mParentConnection;
    }

    public final List<Connection> getChildConnections() {
        return mUnmodifiableChildConnections;
    }

    /**
     * Returns the connection's {@link PhoneCapabilities}
     */
@@ -936,6 +907,60 @@ public abstract class Connection {
        return mUnmodifiableConferenceableConnections;
    }

    /*
     * @hide
     */
    public final void setConnectionService(ConnectionService connectionService) {
        if (mConnectionService != null) {
            Log.e(this, new Exception(), "Trying to set ConnectionService on a connection " +
                    "which is already associated with another ConnectionService.");
        } else {
            mConnectionService = connectionService;
        }
    }

    /**
     * @hide
     */
    public final void unsetConnectionService(ConnectionService connectionService) {
        if (mConnectionService != connectionService) {
            Log.e(this, new Exception(), "Trying to remove ConnectionService from a Connection " +
                    "that does not belong to the ConnectionService.");
        } else {
            mConnectionService = null;
        }
    }

    /**
     * Sets the conference that this connection is a part of. This will fail if the connection is
     * already part of a conference call. {@link #resetConference} to un-set the conference first.
     *
     * @param conference The conference.
     * @return {@code true} if the conference was successfully set.
     * @hide
     */
    public final boolean setConference(Conference conference) {
        // We check to see if it is already part of another conference.
        if (mConference == null && mConnectionService != null &&
                mConnectionService.containsConference(conference)) {
            mConference = conference;
            fireConferenceChanged();
            return true;
        }
        return false;
    }

    /**
     * Resets the conference that this connection is a part of.
     * @hide
     */
    public final void resetConference() {
        if (mConference != null) {
            mConference = null;
            fireConferenceChanged();
        }
    }

    /**
     * Launches an activity for this connection on top of the in-call UI.
     *
@@ -1021,11 +1046,6 @@ public abstract class Connection {
     */
    public void onPostDialContinue(boolean proceed) {}

    /**
     * TODO: Needs documentation.
     */
    public void onChildrenChanged(List<Connection> children) {}

    /**
     * Called when the phone account UI was clicked.
     */
@@ -1073,18 +1093,6 @@ public abstract class Connection {
        return sNullConnection;
    }

    private void addChild(Connection connection) {
        Log.d(this, "adding child %s", connection);
        mChildConnections.add(connection);
        onChildrenChanged(mChildConnections);
    }

    private void removeChild(Connection connection) {
        Log.d(this, "removing child %s", connection);
        mChildConnections.remove(connection);
        onChildrenChanged(mChildConnections);
    }

    private void setState(int state) {
        if (mState == STATE_FAILED || mState == STATE_CANCELED) {
            Log.d(this, "Connection already %s; cannot transition out of this state.",
@@ -1139,6 +1147,12 @@ public abstract class Connection {
        }
    }

    private final void fireConferenceChanged() {
        for (Listener l : mListeners) {
            l.onConferenceChanged(this, mConference);
        }
    }

    private final void clearConferenceableList() {
        for (Connection c : mConferenceableConnections) {
            c.removeConnectionListener(mConnectionDeathListener);
+161 −56

File changed.

Preview size limit exceeded, changes collapsed.

Loading