FileDocCategorySizeDatePackage
Connection.javaAPI DocAndroid 5.1 API50189Thu Mar 12 22:22:42 GMT 2015android.telecom

Connection

public abstract class Connection extends Object implements IConferenceable
Represents a connection to a remote endpoint that carries voice traffic.

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

hide

Fields Summary
public static final int
STATE_INITIALIZING
public static final int
STATE_NEW
public static final int
STATE_RINGING
public static final int
STATE_DIALING
public static final int
STATE_ACTIVE
public static final int
STATE_HOLDING
public static final int
STATE_DISCONNECTED
public static final int
CAPABILITY_HOLD
Connection can currently be put on hold or unheld.
public static final int
CAPABILITY_SUPPORT_HOLD
Connection supports the hold feature.
public static final int
CAPABILITY_MERGE_CONFERENCE
Connections within a conference can be merged. A {@link ConnectionService} has the option to add a {@link Conference} before the child {@link Connection}s are merged. This is how CDMA-based {@link Connection}s are implemented. For these unmerged {@link Conference}s, 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 {@link Conference}.

public static final int
CAPABILITY_SWAP_CONFERENCE
Connections within a conference can be swapped between foreground and background. See {@link #CAPABILITY_MERGE_CONFERENCE} for additional information.

This is only intended for use by a {@link Conference}.

public static final int
CAPABILITY_UNUSED
public static final int
CAPABILITY_RESPOND_VIA_TEXT
Connection supports responding via text option.
public static final int
CAPABILITY_MUTE
Connection can be muted.
public static final int
CAPABILITY_MANAGE_CONFERENCE
Connection supports conference management. This capability only applies to {@link Conference}s which can have {@link Connection}s as children.
public static final int
CAPABILITY_SUPPORTS_VT_LOCAL
Local device supports video telephony.
public static final int
CAPABILITY_SUPPORTS_VT_REMOTE
Remote device supports video telephony.
public static final int
CAPABILITY_HIGH_DEF_AUDIO
Connection is using high definition audio.
public static final int
CAPABILITY_VoWIFI
Connection is using voice over WIFI.
public static final int
CAPABILITY_SEPARATE_FROM_CONFERENCE
Connection is able to be separated from its parent {@code Conference}, if any.
public static final int
CAPABILITY_DISCONNECT_FROM_CONFERENCE
Connection is able to be individually disconnected when in a {@code Conference}.
public static final int
CAPABILITY_GENERIC_CONFERENCE
Whether the call is a generic conference, where we do not know the precise state of participants in the conference (eg. on CDMA).
private static final boolean
PII_DEBUG
private final Listener
mConnectionDeathListener
private final Conference.Listener
mConferenceDeathListener
private final Set
mListeners
ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is load factor before resizing, 1 means we only expect a single thread to access the map so make only a single shard
private final List
mConferenceables
private final List
mUnmodifiableConferenceables
private int
mState
private AudioState
mAudioState
private android.net.Uri
mAddress
private int
mAddressPresentation
private String
mCallerDisplayName
private int
mCallerDisplayNamePresentation
private boolean
mRingbackRequested
private int
mConnectionCapabilities
private VideoProvider
mVideoProvider
private boolean
mAudioModeIsVoip
private StatusHints
mStatusHints
private int
mVideoState
private DisconnectCause
mDisconnectCause
private Conference
mConference
private ConnectionService
mConnectionService
Constructors Summary
public Connection()
Create a new Connection.


             
      
Methods Summary
public voidaddCapability(int capability)
Adds the specified capability to the set of capabilities of this {@code Connection}.

param
capability The capability to add to the set.
hide

        mConnectionCapabilities |= capability;
    
public final android.telecom.ConnectionaddConnectionListener(android.telecom.Connection$Listener l)
Assign a listener to be notified of state changes.

param
l A listener.
return
This Connection.
hide

        mListeners.add(l);
        return this;
    
public static booleancan(int capabilities, int capability)
Whether the given capabilities support the specified capability.

param
capabilities A capability bit field.
param
capability The capability to check capabilities for.
return
Whether the specified capability is supported.
hide


                                       
           
        return (capabilities & capability) != 0;
    
public booleancan(int capability)
Whether the capabilities of this {@code Connection} supports the specified capability.

param
capability The capability to check capabilities for.
return
Whether the specified capability is supported.
hide

        return can(mConnectionCapabilities, capability);
    
public static java.lang.StringcapabilitiesToString(int capabilities)

        StringBuilder builder = new StringBuilder();
        builder.append("[Capabilities:");
        if (can(capabilities, CAPABILITY_HOLD)) {
            builder.append(" CAPABILITY_HOLD");
        }
        if (can(capabilities, CAPABILITY_SUPPORT_HOLD)) {
            builder.append(" CAPABILITY_SUPPORT_HOLD");
        }
        if (can(capabilities, CAPABILITY_MERGE_CONFERENCE)) {
            builder.append(" CAPABILITY_MERGE_CONFERENCE");
        }
        if (can(capabilities, CAPABILITY_SWAP_CONFERENCE)) {
            builder.append(" CAPABILITY_SWAP_CONFERENCE");
        }
        if (can(capabilities, CAPABILITY_RESPOND_VIA_TEXT)) {
            builder.append(" CAPABILITY_RESPOND_VIA_TEXT");
        }
        if (can(capabilities, CAPABILITY_MUTE)) {
            builder.append(" CAPABILITY_MUTE");
        }
        if (can(capabilities, CAPABILITY_MANAGE_CONFERENCE)) {
            builder.append(" CAPABILITY_MANAGE_CONFERENCE");
        }
        if (can(capabilities, CAPABILITY_SUPPORTS_VT_LOCAL)) {
            builder.append(" CAPABILITY_SUPPORTS_VT_LOCAL");
        }
        if (can(capabilities, CAPABILITY_SUPPORTS_VT_REMOTE)) {
            builder.append(" CAPABILITY_SUPPORTS_VT_REMOTE");
        }
        if (can(capabilities, CAPABILITY_HIGH_DEF_AUDIO)) {
            builder.append(" CAPABILITY_HIGH_DEF_AUDIO");
        }
        if (can(capabilities, CAPABILITY_VoWIFI)) {
            builder.append(" CAPABILITY_VoWIFI");
        }
        if (can(capabilities, CAPABILITY_GENERIC_CONFERENCE)) {
            builder.append(" CAPABILITY_GENERIC_CONFERENCE");
        }
        builder.append("]");
        return builder.toString();
    
public voidcheckImmutable()
Override to throw an {@link UnsupportedOperationException} if this {@code Connection} is not intended to be mutated, e.g., if it is a marker for failure. Only for framework use; this should never be un-@hide-den.

hide

private final voidclearConferenceableList()

        for (IConferenceable c : mConferenceables) {
            if (c instanceof Connection) {
                Connection connection = (Connection) c;
                connection.removeConnectionListener(mConnectionDeathListener);
            } else if (c instanceof Conference) {
                Conference conference = (Conference) c;
                conference.removeListener(mConferenceDeathListener);
            }
        }
        mConferenceables.clear();
    
public static android.telecom.ConnectioncreateCanceledConnection()
Return a {@code Connection} which represents a canceled connection attempt. The returned {@code Connection} will have state {@link #STATE_DISCONNECTED}, and cannot be moved out of that state. This connection should not be used for anything, and no other {@code Connection}s should be attempted.

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

return
A {@code Connection} which indicates that the underlying connection should be canceled.

        return new FailureSignalingConnection(new DisconnectCause(DisconnectCause.CANCELED));
    
public static android.telecom.ConnectioncreateFailedConnection(DisconnectCause disconnectCause)
Return a {@code Connection} which represents a failed connection attempt. The returned {@code Connection} will have a {@link android.telecom.DisconnectCause} and as specified, and a {@link #getState()} of {@link #STATE_DISCONNECTED}.

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

param
disconnectCause The disconnect cause, ({@see android.telecomm.DisconnectCause}).
return
A {@code Connection} which indicates failure.

        return new FailureSignalingConnection(disconnectCause);
    
public final voiddestroy()
Tears down the Connection object.

        for (Listener l : mListeners) {
            l.onDestroyed(this);
        }
    
private final voidfireConferenceChanged()

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

        for (Listener l : mListeners) {
            l.onConferenceablesChanged(this, getConferenceables());
        }
    
public final android.net.UrigetAddress()

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

        return mAddress;
    
public final intgetAddressPresentation()

return
The presentation requirements for the address. See {@link TelecomManager} for valid values.

        return mAddressPresentation;
    
public final booleangetAudioModeIsVoip()

return
True if the connection's audio mode is VOIP.

        return mAudioModeIsVoip;
    
public final AudioStategetAudioState()

return
The audio state of the connection, describing how its audio is currently being routed by the system. This is {@code null} if this Connection does not directly know about its audio state.

        return mAudioState;
    
public final intgetCallCapabilities()

hide

        return getConnectionCapabilities();
    
public final java.lang.StringgetCallerDisplayName()

return
The caller display name (CNAP).

        return mCallerDisplayName;
    
public final intgetCallerDisplayNamePresentation()

return
The presentation requirements for the handle. See {@link TelecomManager} for valid values.

        return mCallerDisplayNamePresentation;
    
public final ConferencegetConference()

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

        return mConference;
    
public final java.util.ListgetConferenceables()
Returns the connections or conferences with which this connection can be conferenced.

        return mUnmodifiableConferenceables;
    
public final intgetConnectionCapabilities()
Returns the connection's capabilities, as a bit mask of the {@code CAPABILITY_*} constants.

        return mConnectionCapabilities;
    
public final ConnectionServicegetConnectionService()

hide

        return mConnectionService;
    
public final DisconnectCausegetDisconnectCause()

return
The {@link DisconnectCause} for this connection.

        return mDisconnectCause;
    
public final intgetState()

return
The state of this Connection.

        return mState;
    
public final StatusHintsgetStatusHints()

return
The status hints for this connection.

        return mStatusHints;
    
public final android.telecom.Connection$VideoProvidergetVideoProvider()

hide

        return mVideoProvider;
    
public final intgetVideoState()
Returns the video state of the connection. Valid values: {@link VideoProfile.VideoState#AUDIO_ONLY}, {@link VideoProfile.VideoState#BIDIRECTIONAL}, {@link VideoProfile.VideoState#TX_ENABLED}, {@link VideoProfile.VideoState#RX_ENABLED}.

return
The video state of the connection.
hide

        return mVideoState;
    
public final booleanisRingbackRequested()
Returns whether this connection is requesting that the system play a ringback tone on its behalf.

        return mRingbackRequested;
    
protected voidnotifyConferenceStarted()
Notifies listeners that a conference call has been started.

        for (Listener l : mListeners) {
            l.onConferenceStarted();
        }
    
public voidonAbort()
Notifies this Connection of a request to abort.

public voidonAnswer(int videoState)
Notifies this Connection, which is in {@link #STATE_RINGING}, of a request to accept.

param
videoState The video state in which to answer the connection.
hide

public voidonAnswer()
Notifies this Connection, which is in {@link #STATE_RINGING}, of a request to accept.

        onAnswer(VideoProfile.VideoState.AUDIO_ONLY);
    
public voidonAudioStateChanged(AudioState state)
Notifies this Connection that the {@link #getAudioState()} property has a new value.

param
state The new connection audio state.

public voidonDisconnect()
Notifies this Connection of a request to disconnect.

public voidonDisconnectConferenceParticipant(android.net.Uri endpoint)
Notifies this Connection of a request to disconnect a participant of the conference managed by the connection.

param
endpoint the {@link Uri} of the participant to disconnect.
hide

public voidonHold()
Notifies this Connection of a request to hold.

public voidonPlayDtmfTone(char c)
Notifies this Connection of a request to play a DTMF tone.

param
c A DTMF character.

public voidonPostDialContinue(boolean proceed)
Notifies this Connection whether the user wishes to proceed with the post-dial DTMF codes.

public voidonReject()
Notifies this Connection, which is in {@link #STATE_RINGING}, of a request to reject.

public voidonSeparate()
Notifies this Connection of a request to separate from its parent conference.

public voidonStateChanged(int state)
Notifies this Connection of an internal state change. This method is called after the state is changed.

param
state The new state, one of the {@code STATE_*} constants.

public voidonStopDtmfTone()
Notifies this Connection of a request to stop any currently playing DTMF tones.

public voidonUnhold()
Notifies this Connection of a request to exit a hold state.

public voidremoveCapability(int capability)
Removes the specified capability from the set of capabilities of this {@code Connection}.

param
capability The capability to remove from the set.
hide

        mConnectionCapabilities &= ~capability;
    
public final android.telecom.ConnectionremoveConnectionListener(android.telecom.Connection$Listener l)
Remove a previously assigned listener that was being notified of state changes.

param
l A Listener.
return
This Connection.
hide

        if (l != null) {
            mListeners.remove(l);
        }
        return this;
    
public final voidresetConference()
Resets the conference that this connection is a part of.

hide

        if (mConference != null) {
            Log.d(this, "Conference reset");
            mConference = null;
            fireConferenceChanged();
        }
    
public final voidsetActive()
Sets state to active (e.g., an ongoing connection where two or more parties can actively communicate).

        checkImmutable();
        setRingbackRequested(false);
        setState(STATE_ACTIVE);
    
public final voidsetAddress(android.net.Uri address, int presentation)
Sets the value of the {@link #getAddress()} property.

param
address The new address.
param
presentation The presentation requirements for the address. See {@link TelecomManager} for valid values.

        checkImmutable();
        Log.d(this, "setAddress %s", address);
        mAddress = address;
        mAddressPresentation = presentation;
        for (Listener l : mListeners) {
            l.onAddressChanged(this, address, presentation);
        }
    
public final voidsetAudioModeIsVoip(boolean isVoip)
Requests that the framework use VOIP audio mode for this connection.

param
isVoip True if the audio mode is VOIP.

        checkImmutable();
        mAudioModeIsVoip = isVoip;
        for (Listener l : mListeners) {
            l.onAudioModeIsVoipChanged(this, isVoip);
        }
    
final voidsetAudioState(AudioState state)
Inform this Connection that the state of its audio output has been changed externally.

param
state The new audio state.
hide

        checkImmutable();
        Log.d(this, "setAudioState %s", state);
        mAudioState = state;
        onAudioStateChanged(state);
    
public final voidsetCallCapabilities(int connectionCapabilities)

hide

        setConnectionCapabilities(connectionCapabilities);
    
public final voidsetCallerDisplayName(java.lang.String callerDisplayName, int presentation)
Sets the caller display name (CNAP).

param
callerDisplayName The new display name.
param
presentation The presentation requirements for the handle. See {@link TelecomManager} for valid values.

        checkImmutable();
        Log.d(this, "setCallerDisplayName %s", callerDisplayName);
        mCallerDisplayName = callerDisplayName;
        mCallerDisplayNamePresentation = presentation;
        for (Listener l : mListeners) {
            l.onCallerDisplayNameChanged(this, callerDisplayName, presentation);
        }
    
public final booleansetConference(Conference conference)
Sets the conference that this connection is a part of. This will fail if the connection is already part of a conference. {@link #resetConference} to un-set the conference first.

param
conference The conference.
return
{@code true} if the conference was successfully set.
hide

        checkImmutable();
        // We check to see if it is already part of another conference.
        if (mConference == null) {
            mConference = conference;
            if (mConnectionService != null && mConnectionService.containsConference(conference)) {
                fireConferenceChanged();
            }
            return true;
        }
        return false;
    
public final voidsetConferenceableConnections(java.util.List conferenceableConnections)
Sets the connections with which this connection can be conferenced.

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

        checkImmutable();
        clearConferenceableList();
        for (Connection c : conferenceableConnections) {
            // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
            // small amount of items here.
            if (!mConferenceables.contains(c)) {
                c.addConnectionListener(mConnectionDeathListener);
                mConferenceables.add(c);
            }
        }
        fireOnConferenceableConnectionsChanged();
    
public final voidsetConferenceables(java.util.List conferenceables)
Similar to {@link #setConferenceableConnections(java.util.List)}, sets a list of connections or conferences with which this connection can be conferenced.

param
conferenceables The conferenceables.

        clearConferenceableList();
        for (IConferenceable c : conferenceables) {
            // If statement checks for duplicates in input. It makes it N^2 but we're dealing with a
            // small amount of items here.
            if (!mConferenceables.contains(c)) {
                if (c instanceof Connection) {
                    Connection connection = (Connection) c;
                    connection.addConnectionListener(mConnectionDeathListener);
                } else if (c instanceof Conference) {
                    Conference conference = (Conference) c;
                    conference.addListener(mConferenceDeathListener);
                }
                mConferenceables.add(c);
            }
        }
        fireOnConferenceableConnectionsChanged();
    
public final voidsetConnectionCapabilities(int connectionCapabilities)
Sets the connection's capabilities as a bit mask of the {@code CAPABILITY_*} constants.

param
connectionCapabilities The new connection capabilities.

        checkImmutable();
        if (mConnectionCapabilities != connectionCapabilities) {
            mConnectionCapabilities = connectionCapabilities;
            for (Listener l : mListeners) {
                l.onConnectionCapabilitiesChanged(this, mConnectionCapabilities);
            }
        }
    
public final voidsetConnectionService(ConnectionService connectionService)

        checkImmutable();
        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;
        }
    
public final voidsetDialing()
Sets state to dialing (e.g., dialing an outbound connection).

        checkImmutable();
        setState(STATE_DIALING);
    
public final voidsetDisconnected(DisconnectCause disconnectCause)
Sets state to disconnected.

param
disconnectCause The reason for the disconnection, as specified by {@link DisconnectCause}.

        checkImmutable();
        mDisconnectCause = disconnectCause;
        setState(STATE_DISCONNECTED);
        Log.d(this, "Disconnected with cause %s", disconnectCause);
        for (Listener l : mListeners) {
            l.onDisconnected(this, disconnectCause);
        }
    
public final voidsetInitialized()
Sets state to initialized (the Connection has been set up and is now ready to be used).

        checkImmutable();
        setState(STATE_NEW);
    
public final voidsetInitializing()
Sets state to initializing (this Connection is not yet ready to be used).

        checkImmutable();
        setState(STATE_INITIALIZING);
    
public final voidsetNextPostDialWaitChar(char nextChar)
Informs listeners that this {@code Connection} has processed a character in the post-dial started state. This is done when (a) the {@code Connection} is issuing a DTMF sequence; (b) it has encountered a "wait" character; and (c) it wishes to signal Telecom to play the corresponding DTMF tone locally.

param
nextChar The DTMF character that was just processed by the {@code Connection}.
hide

        checkImmutable();
        for (Listener l : mListeners) {
            l.onPostDialChar(this, nextChar);
        }
    
public final voidsetOnHold()
Sets state to be on hold.

        checkImmutable();
        setState(STATE_HOLDING);
    
public final voidsetPostDialWait(java.lang.String remaining)
Informs listeners that this {@code Connection} is in a post-dial wait state. This is done when (a) the {@code 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 {@link #onPostDialContinue(boolean)} signal.

param
remaining The DTMF character sequence remaining to be emitted once the {@link #onPostDialContinue(boolean)} is received, including any "wait" characters that remaining sequence may contain.

        checkImmutable();
        for (Listener l : mListeners) {
            l.onPostDialWait(this, remaining);
        }
    
public final voidsetRingbackRequested(boolean ringback)
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.

param
ringback Whether the ringback tone is to be played.

        checkImmutable();
        if (mRingbackRequested != ringback) {
            mRingbackRequested = ringback;
            for (Listener l : mListeners) {
                l.onRingbackRequested(this, ringback);
            }
        }
    
public final voidsetRinging()
Sets state to ringing (e.g., an inbound ringing connection).

        checkImmutable();
        setState(STATE_RINGING);
    
private voidsetState(int state)

        checkImmutable();
        if (mState == STATE_DISCONNECTED && mState != state) {
            Log.d(this, "Connection already DISCONNECTED; cannot transition out of this state.");
            return;
        }
        if (mState != state) {
            Log.d(this, "setState: %s", stateToString(state));
            mState = state;
            onStateChanged(state);
            for (Listener l : mListeners) {
                l.onStateChanged(this, state);
            }
        }
    
public final voidsetStatusHints(StatusHints statusHints)
Sets the label and icon status to display in the in-call UI.

param
statusHints The status label and icon to set.

        checkImmutable();
        mStatusHints = statusHints;
        for (Listener l : mListeners) {
            l.onStatusHintsChanged(this, statusHints);
        }
    
public final voidsetVideoProvider(android.telecom.Connection$VideoProvider videoProvider)
Sets the video connection provider.

param
videoProvider The video provider.
hide

        checkImmutable();
        mVideoProvider = videoProvider;
        for (Listener l : mListeners) {
            l.onVideoProviderChanged(this, videoProvider);
        }
    
public final voidsetVideoState(int videoState)
Set the video state for the connection. Valid values: {@link VideoProfile.VideoState#AUDIO_ONLY}, {@link VideoProfile.VideoState#BIDIRECTIONAL}, {@link VideoProfile.VideoState#TX_ENABLED}, {@link VideoProfile.VideoState#RX_ENABLED}.

param
videoState The new video state.
hide

        checkImmutable();
        Log.d(this, "setVideoState %d", videoState);
        mVideoState = videoState;
        for (Listener l : mListeners) {
            l.onVideoStateChanged(this, mVideoState);
        }
    
public static java.lang.StringstateToString(int state)

param
state An integer value of a {@code STATE_*} constant.
return
A string representation of the value.

        switch (state) {
            case STATE_INITIALIZING:
                return "STATE_INITIALIZING";
            case STATE_NEW:
                return "STATE_NEW";
            case STATE_RINGING:
                return "STATE_RINGING";
            case STATE_DIALING:
                return "STATE_DIALING";
            case STATE_ACTIVE:
                return "STATE_ACTIVE";
            case STATE_HOLDING:
                return "STATE_HOLDING";
            case STATE_DISCONNECTED:
                return "DISCONNECTED";
            default:
                Log.wtf(Connection.class, "Unknown state %d", state);
                return "UNKNOWN";
        }
    
static java.lang.StringtoLogSafePhoneNumber(java.lang.String number)

        // For unknown number, log empty string.
        if (number == null) {
            return "";
        }

        if (PII_DEBUG) {
            // When PII_DEBUG is true we emit PII.
            return number;
        }

        // Do exactly same thing as Uri#toSafeString() does, which will enable us to compare
        // sanitized phone numbers.
        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < number.length(); i++) {
            char c = number.charAt(i);
            if (c == '-" || c == '@" || c == '.") {
                builder.append(c);
            } else {
                builder.append('x");
            }
        }
        return builder.toString();
    
public final voidunsetConnectionService(ConnectionService connectionService)

hide

        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;
        }
    
protected final voidupdateConferenceParticipants(java.util.List conferenceParticipants)
Notifies listeners of a change to conference participant(s).

param
conferenceParticipants The participants.
hide

        for (Listener l : mListeners) {
            l.onConferenceParticipantsChanged(this, conferenceParticipants);
        }