CallControlScope

public interface CallControlScope extends CoroutineScope


DSL interface to provide and receive updates about a single call session. The scope should be used to provide updates to the call state and receive updates about a call state. Example usage:

// initiate a call and control via the CallControlScope
mCallsManager.addCall(
    callAttributes,
    onAnswerLambda,
    onDisconnectLambda,
    onSetActiveLambda,
    onSetInActiveLambda
    ) { // This block represents the CallControlScope

       // UI flow sends an update to a call state, relay the update to Telecom
       disconnectCallButton.setOnClickListener {
         val wasSuccessful = disconnect(reason) // waits for telecom async. response
         // update UI
       }

       // Collect updates
       currentCallEndpoint.collect { // access the new [CallEndpoint] here }
 }

Summary

Public methods

abstract @NonNull CallControlResult
answer(int callType)

Inform Telecom that your app wants to make this incoming call active.

abstract @NonNull CallControlResult

Inform Telecom that your app wishes to disconnect the call and remove the call from telecom tracking.

abstract @NonNull Flow<@NonNull List<@NonNull CallEndpointCompat>>

Collect the set of available CallEndpointCompats reported by Telecom.

abstract @NonNull ParcelUuid
abstract @NonNull Flow<@NonNull CallEndpointCompat>

Collect the new CallEndpointCompat through which call media flows (i.e. speaker, bluetooth, etc.).

abstract @NonNull Flow<@NonNull Boolean>

Collect the current mute state of the call.

abstract @NonNull CallControlResult

Request a CallEndpointCompat change.

abstract @NonNull CallControlResult

Inform Telecom that your app wants to make this call active.

abstract @NonNull CallControlResult

Inform Telecom that your app wants to make this call inactive.

Public methods

answer

abstract @NonNull CallControlResult answer(int callType)

Inform Telecom that your app wants to make this incoming call active. For outgoing calls and calls that have been placed on hold, use setActive.

Parameters
int callType

that call is to be answered as.

Returns
@NonNull CallControlResult

Telecom will return CallControlResult.Success if your app is able to answer the call. Otherwise CallControlResult.Error will be returned with an error code indicating why answer failed (ex. another call is active and telecom cannot set this call active until the other call is held or disconnected). This means that your app cannot answer this call at this time.

disconnect

abstract @NonNull CallControlResult disconnect(@NonNull DisconnectCause disconnectCause)

Inform Telecom that your app wishes to disconnect the call and remove the call from telecom tracking.

Parameters
@NonNull DisconnectCause disconnectCause

represents the cause for disconnecting the call. The only valid codes for the android.telecom.DisconnectCause passed in are:

  • DisconnectCause#LOCAL
  • DisconnectCause#REMOTE
  • DisconnectCause#REJECTED
  • DisconnectCause#MISSED

Returns
@NonNull CallControlResult

CallControlResult.Success will be returned if Telecom is able to disconnect the call successfully. Otherwise CallControlResult.Error will be returned with an error code indicating why disconnect failed.

getAvailableEndpoints

Added in 1.0.0-alpha02
abstract @NonNull Flow<@NonNull List<@NonNull CallEndpointCompat>> getAvailableEndpoints()

Collect the set of available CallEndpointCompats reported by Telecom.

getCallId

Added in 1.0.0-alpha02
abstract @NonNull ParcelUuid getCallId()
Returns
@NonNull ParcelUuid

the 128-bit universally unique identifier Telecom assigned to this CallControlScope. This id can be helpful for debugging when dumping the telecom system.

getCurrentCallEndpoint

Added in 1.0.0-alpha02
abstract @NonNull Flow<@NonNull CallEndpointCompatgetCurrentCallEndpoint()

Collect the new CallEndpointCompat through which call media flows (i.e. speaker, bluetooth, etc.).

isMuted

Added in 1.0.0-alpha02
abstract @NonNull Flow<@NonNull BooleanisMuted()

Collect the current mute state of the call. This Flow is updated every time the mute state changes.

requestEndpointChange

abstract @NonNull CallControlResult requestEndpointChange(@NonNull CallEndpointCompat endpoint)

Request a CallEndpointCompat change. Clients should not define their own CallEndpointCompat when requesting a change. Instead, the new endpoint should be one of the valid CallEndpointCompats provided by availableEndpoints.

Parameters
@NonNull CallEndpointCompat endpoint

The CallEndpointCompat to change to.

Returns
@NonNull CallControlResult

CallControlResult.Success will be returned if Telecom is able to switch to the requested endpoint successfully. Otherwise, CallControlResult.Error will be returned with an error code indicating why disconnect failed.

setActive

abstract @NonNull CallControlResult setActive()

Inform Telecom that your app wants to make this call active. This method should be called when either an outgoing call is ready to go active or a held call is ready to go active again. For incoming calls that are ready to be answered, use answer.

Returns
@NonNull CallControlResult

Telecom will return CallControlResult.Success if your app is able to set the call active. Otherwise CallControlResult.Error will be returned (ex. another call is active and telecom cannot set this call active until the other call is held or disconnected) with an error code indicating why setActive failed.

setInactive

abstract @NonNull CallControlResult setInactive()

Inform Telecom that your app wants to make this call inactive. This the same as hold for two call endpoints but can be extended to setting a meeting to inactive.

Returns
@NonNull CallControlResult

Telecom will return CallControlResult.Success if your app is able to set the call inactive. Otherwise, CallControlResult.Error will be returned with an error code indicating why setInActive failed.