Android APIs
public abstract class

Connection

extends Conferenceable
java.lang.Object
   ↳ android.telecom.Conferenceable
     ↳ android.telecom.Connection

Class Overview

Represents a phone call or connection to a remote endpoint that carries voice and/or video traffic.

Implementations create a custom subclass of Connection and return it to the framework as the return value of onCreateIncomingConnection(PhoneAccountHandle, ConnectionRequest) or onCreateOutgoingConnection(PhoneAccountHandle, ConnectionRequest). Implementations are then responsible for updating the state of the Connection, and must call destroy() to signal to the framework that the Connection is no longer used and associated resources may be recovered.

Summary

Nested Classes
class Connection.VideoProvider Provides a means of controlling the video session associated with a Connection
Constants
int CAPABILITY_CAN_PAUSE_VIDEO For video calls, indicates whether the outgoing video for the call can be paused using the STATE_PAUSED VideoState.
int CAPABILITY_CAN_UPGRADE_TO_VIDEO Call can be upgraded to a video call.
int CAPABILITY_DISCONNECT_FROM_CONFERENCE Connection is able to be individually disconnected when in a Conference.
int CAPABILITY_HOLD Connection can currently be put on hold or unheld.
int CAPABILITY_MANAGE_CONFERENCE Connection supports conference management.
int CAPABILITY_MERGE_CONFERENCE Connections within a conference can be merged.
int CAPABILITY_MUTE Connection can be muted.
int CAPABILITY_RESPOND_VIA_TEXT Connection supports responding via text option.
int CAPABILITY_SEPARATE_FROM_CONFERENCE Connection is able to be separated from its parent Conference, if any.
int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL Local device supports bidirectional video calling.
int CAPABILITY_SUPPORTS_VT_LOCAL_RX Local device supports receiving video.
int CAPABILITY_SUPPORTS_VT_LOCAL_TX Local device supports transmitting video.
int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL Remote device supports bidirectional video calling.
int CAPABILITY_SUPPORTS_VT_REMOTE_RX Remote device supports receiving video.
int CAPABILITY_SUPPORTS_VT_REMOTE_TX Remote device supports transmitting video.
int CAPABILITY_SUPPORT_HOLD Connection supports the hold feature.
int CAPABILITY_SWAP_CONFERENCE Connections within a conference can be swapped between foreground and background.
String EXTRA_CALL_SUBJECT Connection extra key used to store the subject for an incoming call.
String EXTRA_CHILD_ADDRESS Connection extra key used to store a child number associated with the current connection.
String EXTRA_LAST_FORWARDED_NUMBER Connection extra key used to store the last forwarded number associated with the current connection.
int STATE_ACTIVE A connection is active.
int STATE_DIALING An outgoing connection is in the dialing state.
int STATE_DISCONNECTED A connection has been disconnected.
int STATE_HOLDING A connection is on hold.
int STATE_INITIALIZING The connection is initializing.
int STATE_NEW The connection is new and not connected.
int STATE_RINGING An incoming connection is in the ringing state.
Public Constructors
Connection()
Create a new Connection.
Public Methods
static String capabilitiesToString(int capabilities)
static Connection createCanceledConnection()
Return a Connection which represents a canceled connection attempt.
static Connection createFailedConnection(DisconnectCause disconnectCause)
Return a Connection which represents a failed connection attempt.
final void destroy()
Tears down the Connection object.
final Uri getAddress()
final int getAddressPresentation()
final boolean getAudioModeIsVoip()
final CallAudioState getCallAudioState()
final String getCallerDisplayName()
final int getCallerDisplayNamePresentation()
final Conference getConference()
final List<Conferenceable> getConferenceables()
Returns the connections or conferences with which this connection can be conferenced.
final int getConnectionCapabilities()
Returns the connection's capabilities, as a bit mask of the CAPABILITY_* constants.
final DisconnectCause getDisconnectCause()
final Bundle getExtras()
final int getState()
final StatusHints getStatusHints()
final Connection.VideoProvider getVideoProvider()
final boolean isRingbackRequested()
Returns whether this connection is requesting that the system play a ringback tone on its behalf.
void onAbort()
Notifies this Connection of a request to abort.
void onAnswer(int videoState)
Notifies this Connection, which is in STATE_RINGING, of a request to accept.
void onAnswer()
Notifies this Connection, which is in STATE_RINGING, of a request to accept.
void onCallAudioStateChanged(CallAudioState state)
Notifies this Connection that the getCallAudioState() property has a new value.
void onDisconnect()
Notifies this Connection of a request to disconnect.
void onHold()
Notifies this Connection of a request to hold.
void onPlayDtmfTone(char c)
Notifies this Connection of a request to play a DTMF tone.
void onPostDialContinue(boolean proceed)
Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.
void onReject()
Notifies this Connection, which is in STATE_RINGING, of a request to reject.
void onSeparate()
Notifies this Connection of a request to separate from its parent conference.
void onStateChanged(int state)
Notifies this Connection of an internal state change.
void onStopDtmfTone()
Notifies this Connection of a request to stop any currently playing DTMF tones.
void onUnhold()
Notifies this Connection of a request to exit a hold state.
final void setActive()
Sets state to active (e.g., an ongoing connection where two or more parties can actively communicate).
final void setAddress(Uri address, int presentation)
Sets the value of the getAddress() property.
final void setAudioModeIsVoip(boolean isVoip)
Requests that the framework use VOIP audio mode for this connection.
final void setCallerDisplayName(String callerDisplayName, int presentation)
Sets the caller display name (CNAP).
final void setConferenceableConnections(List<Connection> conferenceableConnections)
Sets the connections with which this connection can be conferenced.
final void setConferenceables(List<Conferenceable> conferenceables)
Similar to setConferenceableConnections(java.util.List), sets a list of connections or conferences with which this connection can be conferenced.
final void setConnectionCapabilities(int connectionCapabilities)
Sets the connection's capabilities as a bit mask of the CAPABILITY_* constants.
final void setDialing()
Sets state to dialing (e.g., dialing an outbound connection).
final void setDisconnected(DisconnectCause disconnectCause)
Sets state to disconnected.
final void setExtras(Bundle extras)
Set some extras that can be associated with this Connection.
final void setInitialized()
Sets state to initialized (the Connection has been set up and is now ready to be used).
final void setInitializing()
Sets state to initializing (this Connection is not yet ready to be used).
final void setNextPostDialChar(char nextChar)
Informs listeners that this Connection has processed a character in the post-dial started state.
final void setOnHold()
Sets state to be on hold.
final void setPostDialWait(String remaining)
Informs listeners that this Connection is in a post-dial wait state.
final void setRingbackRequested(boolean ringback)
Requests that the framework play a ringback tone.
final void setRinging()
Sets state to ringing (e.g., an inbound ringing connection).
final void setStatusHints(StatusHints statusHints)
Sets the label and icon status to display in the in-call UI.
final void setVideoProvider(Connection.VideoProvider videoProvider)
Sets the video connection provider.
final void setVideoState(int videoState)
Set the video state for the connection.
static String stateToString(int state)
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final int CAPABILITY_CAN_PAUSE_VIDEO

Added in API level 23

For video calls, indicates whether the outgoing video for the call can be paused using the STATE_PAUSED VideoState.

Constant Value: 1048576 (0x00100000)

public static final int CAPABILITY_CAN_UPGRADE_TO_VIDEO

Added in API level 23

Call can be upgraded to a video call.

Constant Value: 524288 (0x00080000)

public static final int CAPABILITY_DISCONNECT_FROM_CONFERENCE

Added in API level 23

Connection is able to be individually disconnected when in a Conference.

Constant Value: 8192 (0x00002000)

public static final int CAPABILITY_HOLD

Added in API level 23

Connection can currently be put on hold or unheld. This is distinct from CAPABILITY_SUPPORT_HOLD in that although a connection may support 'hold' most times, it does not at the moment support the function. This can be true while the call is in the state STATE_DIALING, for example. During this condition, an in-call UI may display a disabled 'hold' button.

Constant Value: 1 (0x00000001)

public static final int CAPABILITY_MANAGE_CONFERENCE

Added in API level 23

Connection supports conference management. This capability only applies to Conferences which can have Connections as children.

Constant Value: 128 (0x00000080)

public static final int CAPABILITY_MERGE_CONFERENCE

Added in API level 23

Connections within a conference can be merged. A ConnectionService has the option to add a Conference before the child Connections are merged. This is how CDMA-based Connections are implemented. For these unmerged Conferences, this capability allows a merge button to be shown while the conference is in the foreground of the in-call UI.

This is only intended for use by a Conference.

Constant Value: 4 (0x00000004)

public static final int CAPABILITY_MUTE

Added in API level 23

Connection can be muted.

Constant Value: 64 (0x00000040)

public static final int CAPABILITY_RESPOND_VIA_TEXT

Added in API level 23

Connection supports responding via text option.

Constant Value: 32 (0x00000020)

public static final int CAPABILITY_SEPARATE_FROM_CONFERENCE

Added in API level 23

Connection is able to be separated from its parent Conference, if any.

Constant Value: 4096 (0x00001000)

public static final int CAPABILITY_SUPPORTS_VT_LOCAL_BIDIRECTIONAL

Added in API level 23

Local device supports bidirectional video calling.

Constant Value: 768 (0x00000300)

public static final int CAPABILITY_SUPPORTS_VT_LOCAL_RX

Added in API level 23

Local device supports receiving video.

Constant Value: 256 (0x00000100)

public static final int CAPABILITY_SUPPORTS_VT_LOCAL_TX

Added in API level 23

Local device supports transmitting video.

Constant Value: 512 (0x00000200)

public static final int CAPABILITY_SUPPORTS_VT_REMOTE_BIDIRECTIONAL

Added in API level 23

Remote device supports bidirectional video calling.

Constant Value: 3072 (0x00000c00)

public static final int CAPABILITY_SUPPORTS_VT_REMOTE_RX

Added in API level 23

Remote device supports receiving video.

Constant Value: 1024 (0x00000400)

public static final int CAPABILITY_SUPPORTS_VT_REMOTE_TX

Added in API level 23

Remote device supports transmitting video.

Constant Value: 2048 (0x00000800)

public static final int CAPABILITY_SUPPORT_HOLD

Added in API level 23

Connection supports the hold feature.

Constant Value: 2 (0x00000002)

public static final int CAPABILITY_SWAP_CONFERENCE

Added in API level 23

Connections within a conference can be swapped between foreground and background. See CAPABILITY_MERGE_CONFERENCE for additional information.

This is only intended for use by a Conference.

Constant Value: 8 (0x00000008)

public static final String EXTRA_CALL_SUBJECT

Added in API level 23

Connection extra key used to store the subject for an incoming call. The user interface can query this extra and display its contents for incoming calls. Will only be used if the PhoneAccount supports the capability CAPABILITY_CALL_SUBJECT.

Constant Value: "android.telecom.extra.CALL_SUBJECT"

public static final String EXTRA_CHILD_ADDRESS

Added in API level 23

Connection extra key used to store a child number associated with the current connection. Used to communicate to the user interface that the connection was received via a child address (i.e. phone number) associated with the PhoneAccount's primary address.

Constant Value: "android.telecom.extra.CHILD_ADDRESS"

public static final String EXTRA_LAST_FORWARDED_NUMBER

Added in API level 23

Connection extra key used to store the last forwarded number associated with the current connection. Used to communicate to the user interface that the connection was forwarded via the specified number.

Constant Value: "android.telecom.extra.LAST_FORWARDED_NUMBER"

public static final int STATE_ACTIVE

Added in API level 23

A connection is active. Both parties are connected to the call and can actively communicate.

Constant Value: 4 (0x00000004)

public static final int STATE_DIALING

Added in API level 23

An outgoing connection is in the dialing state. In this state the other party has not yet answered the call and the user traditionally hears a ringback tone.

Constant Value: 3 (0x00000003)

public static final int STATE_DISCONNECTED

Added in API level 23

A connection has been disconnected. This is the final state once the user has been disconnected from a call either locally, remotely or by an error in the service.

Constant Value: 6 (0x00000006)

public static final int STATE_HOLDING

Added in API level 23

A connection is on hold.

Constant Value: 5 (0x00000005)

public static final int STATE_INITIALIZING

Added in API level 23

The connection is initializing. This is generally the first state for a Connection returned by a ConnectionService.

Constant Value: 0 (0x00000000)

public static final int STATE_NEW

Added in API level 23

The connection is new and not connected.

Constant Value: 1 (0x00000001)

public static final int STATE_RINGING

Added in API level 23

An incoming connection is in the ringing state. During this state, the user's ringer or vibration feature will be activated.

Constant Value: 2 (0x00000002)

Public Constructors

public Connection ()

Added in API level 23

Create a new Connection.

Public Methods

public static String capabilitiesToString (int capabilities)

Added in API level 23

public static Connection createCanceledConnection ()

Added in API level 23

Return a Connection which represents a canceled connection attempt. The returned Connection will have state STATE_DISCONNECTED, and cannot be moved out of that state. This connection should not be used for anything, and no other Connections should be attempted.

so users of this method need not maintain a reference to its return value to destroy it.

Returns
  • A Connection which indicates that the underlying connection should be canceled.

public static Connection createFailedConnection (DisconnectCause disconnectCause)

Added in API level 23

Return a Connection which represents a failed connection attempt. The returned Connection will have a DisconnectCause and as specified, and a getState() of STATE_DISCONNECTED.

The returned Connection can be assumed to destroy() itself when appropriate, so users of this method need not maintain a reference to its return value to destroy it.

Parameters
disconnectCause The disconnect cause, ().
Returns
  • A Connection which indicates failure.

public final void destroy ()

Added in API level 23

Tears down the Connection object.

public final Uri getAddress ()

Added in API level 23

Returns
  • The address (e.g., phone number) to which this Connection is currently communicating.

public final int getAddressPresentation ()

Added in API level 23

Returns
  • The presentation requirements for the address. See TelecomManager for valid values.

public final boolean getAudioModeIsVoip ()

Added in API level 23

Returns
  • True if the connection's audio mode is VOIP.

public final CallAudioState getCallAudioState ()

Added in API level 23

Returns
  • The audio state of the connection, describing how its audio is currently being routed by the system. This is null if this Connection does not directly know about its audio state.

public final String getCallerDisplayName ()

Added in API level 23

Returns
  • The caller display name (CNAP).

public final int getCallerDisplayNamePresentation ()

Added in API level 23

Returns
  • The presentation requirements for the handle. See TelecomManager for valid values.

public final Conference getConference ()

Added in API level 23

Returns
  • The conference that this connection is a part of. Null if it is not part of any conference.

public final List<Conferenceable> getConferenceables ()

Added in API level 23

Returns the connections or conferences with which this connection can be conferenced.

public final int getConnectionCapabilities ()

Added in API level 23

Returns the connection's capabilities, as a bit mask of the CAPABILITY_* constants.

public final DisconnectCause getDisconnectCause ()

Added in API level 23

Returns

public final Bundle getExtras ()

Added in API level 23

Returns
  • The extras associated with this connection.

public final int getState ()

Added in API level 23

Returns
  • The state of this Connection.

public final StatusHints getStatusHints ()

Added in API level 23

Returns
  • The status hints for this connection.

public final Connection.VideoProvider getVideoProvider ()

Added in API level 23

public final boolean isRingbackRequested ()

Added in API level 23

Returns whether this connection is requesting that the system play a ringback tone on its behalf.

public void onAbort ()

Added in API level 23

Notifies this Connection of a request to abort.

public void onAnswer (int videoState)

Added in API level 23

Notifies this Connection, which is in STATE_RINGING, of a request to accept.

Parameters
videoState The video state in which to answer the connection.

public void onAnswer ()

Added in API level 23

Notifies this Connection, which is in STATE_RINGING, of a request to accept.

public void onCallAudioStateChanged (CallAudioState state)

Added in API level 23

Notifies this Connection that the getCallAudioState() property has a new value.

Parameters
state The new connection audio state.

public void onDisconnect ()

Added in API level 23

Notifies this Connection of a request to disconnect.

public void onHold ()

Added in API level 23

Notifies this Connection of a request to hold.

public void onPlayDtmfTone (char c)

Added in API level 23

Notifies this Connection of a request to play a DTMF tone.

Parameters
c A DTMF character.

public void onPostDialContinue (boolean proceed)

Added in API level 23

Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.

public void onReject ()

Added in API level 23

Notifies this Connection, which is in STATE_RINGING, of a request to reject.

public void onSeparate ()

Added in API level 23

Notifies this Connection of a request to separate from its parent conference.

public void onStateChanged (int state)

Added in API level 23

Notifies this Connection of an internal state change. This method is called after the state is changed.

Parameters
state The new state, one of the STATE_* constants.

public void onStopDtmfTone ()

Added in API level 23

Notifies this Connection of a request to stop any currently playing DTMF tones.

public void onUnhold ()

Added in API level 23

Notifies this Connection of a request to exit a hold state.

public final void setActive ()

Added in API level 23

Sets state to active (e.g., an ongoing connection where two or more parties can actively communicate).

public final void setAddress (Uri address, int presentation)

Added in API level 23

Sets the value of the getAddress() property.

Parameters
address The new address.
presentation The presentation requirements for the address. See TelecomManager for valid values.

public final void setAudioModeIsVoip (boolean isVoip)

Added in API level 23

Requests that the framework use VOIP audio mode for this connection.

Parameters
isVoip True if the audio mode is VOIP.

public final void setCallerDisplayName (String callerDisplayName, int presentation)

Added in API level 23

Sets the caller display name (CNAP).

Parameters
callerDisplayName The new display name.
presentation The presentation requirements for the handle. See TelecomManager for valid values.

public final void setConferenceableConnections (List<Connection> conferenceableConnections)

Added in API level 23

Sets the connections with which this connection can be conferenced.

Parameters
conferenceableConnections The set of connections this connection can conference with.

public final void setConferenceables (List<Conferenceable> conferenceables)

Added in API level 23

Similar to setConferenceableConnections(java.util.List), sets a list of connections or conferences with which this connection can be conferenced.

Parameters
conferenceables The conferenceables.

public final void setConnectionCapabilities (int connectionCapabilities)

Added in API level 23

Sets the connection's capabilities as a bit mask of the CAPABILITY_* constants.

Parameters
connectionCapabilities The new connection capabilities.

public final void setDialing ()

Added in API level 23

Sets state to dialing (e.g., dialing an outbound connection).

public final void setDisconnected (DisconnectCause disconnectCause)

Added in API level 23

Sets state to disconnected.

Parameters
disconnectCause The reason for the disconnection, as specified by DisconnectCause.

public final void setExtras (Bundle extras)

Added in API level 23

Set some extras that can be associated with this Connection. No assumptions should be made as to how an In-Call UI or service will handle these extras. Keys should be fully qualified (e.g., com.example.MY_EXTRA) to avoid conflicts.

Parameters
extras The extras associated with this Connection.

public final void setInitialized ()

Added in API level 23

Sets state to initialized (the Connection has been set up and is now ready to be used).

public final void setInitializing ()

Added in API level 23

Sets state to initializing (this Connection is not yet ready to be used).

public final void setNextPostDialChar (char nextChar)

Added in API level 23

Informs listeners that this Connection has processed a character in the post-dial started state. This is done when (a) the Connection is issuing a DTMF sequence; and (b) it wishes to signal Telecom to play the corresponding DTMF tone locally.

Parameters
nextChar The DTMF character that was just processed by the Connection.

public final void setOnHold ()

Added in API level 23

Sets state to be on hold.

public final void setPostDialWait (String remaining)

Added in API level 23

Informs listeners that this Connection is in a post-dial wait state. This is done when (a) the Connection is issuing a DTMF sequence; (b) it has encountered a "wait" character; and (c) it wishes to inform the In-Call app that it is waiting for the end-user to send an onPostDialContinue(boolean) signal.

Parameters
remaining The DTMF character sequence remaining to be emitted once the onPostDialContinue(boolean) is received, including any "wait" characters that remaining sequence may contain.

public final void setRingbackRequested (boolean ringback)

Added in API level 23

Requests that the framework play a ringback tone. This is to be invoked by implementations that do not play a ringback tone themselves in the connection's audio stream.

Parameters
ringback Whether the ringback tone is to be played.

public final void setRinging ()

Added in API level 23

Sets state to ringing (e.g., an inbound ringing connection).

public final void setStatusHints (StatusHints statusHints)

Added in API level 23

Sets the label and icon status to display in the in-call UI.

Parameters
statusHints The status label and icon to set.

public final void setVideoProvider (Connection.VideoProvider videoProvider)

Added in API level 23

Sets the video connection provider.

Parameters
videoProvider The video provider.

public final void setVideoState (int videoState)

Added in API level 23

Set the video state for the connection. Valid values: STATE_AUDIO_ONLY, STATE_BIDIRECTIONAL, STATE_TX_ENABLED, STATE_RX_ENABLED.

Parameters
videoState The new video state.

public static String stateToString (int state)

Added in API level 23

Parameters
state An integer value of a STATE_* constant.
Returns
  • A string representation of the value.