The Telecom framework, managed primarily by TelecomService (accessible via TelecomManager), acts as the central switchboard for audio and video calls on Android. It unifies SIM-based telephony (managed by the Telephony stack) and third-party Voice over IP (VoIP) applications under a single user experience.
Call Management Through Telecom
Before Android 5.0, third-party VoIP apps had to build custom in-call UIs and manually manage audio focus, often clashing with incoming cellular calls. The Telecom framework resolves this by acting as a mediator between three main components:
- Telecom Framework: The core routing logic.
- ConnectionServices: Providers of calls (e.g., the Telephony stack for SIM calls, or a VoIP app for internet calls).
- InCallServices: The UI providers (e.g., the system Dialer app, or Android Auto).
When a VoIP app wants to place a call, it tells Telecom. Telecom then asks the system's default InCallService to display the dialing UI.
ConnectionService API
To integrate with Telecom, an application must implement a ConnectionService. This service defines how the app connects, disconnects, and manages the state of a call.
When a new call is initiated (either incoming or outgoing), Telecom binds to the app's ConnectionService and requests it to create a Connection object. This object represents the call's lifecycle.
// Simplified ConnectionService implementation
public class MyVoipConnectionService extends ConnectionService {
@Override
public Connection onCreateIncomingConnection(PhoneAccountHandle handle, ConnectionRequest request) {
MyConnection connection = new MyConnection();
connection.setInitializing();
// Ring the device, connect to backend, etc.
return connection;
}
}
PhoneAccount Registration
Telecom needs to know which apps are capable of making calls. Apps register a PhoneAccount via TelecomManager.registerPhoneAccount().
A PhoneAccount contains metadata like the app's icon, a short description, and capabilities (e.g., CAPABILITY_VIDEO_CALLING or CAPABILITY_CALL_PROVIDER). When a user attempts to make a call from the dialer, they might be prompted to choose which PhoneAccount to use if multiple are registered.
Audio Routing for Calls
Routing audio during a call is complex, involving earpieces, speakerphones, Bluetooth headsets, and wired headphones. Telecom manages this via its CallAudioRouteStateMachine.
When a call becomes active, Telecom negotiates with AudioManager to set the audio mode to MODE_IN_CALL or MODE_IN_COMMUNICATION. It then commands the routing. If a user connects a Bluetooth headset during a call, the InCallService notifies Telecom, which transitions its state machine and instructs AudioManager to route the audio stream to the Bluetooth hardware.
You can view the current state of all calls, registered PhoneAccounts, and audio routes using:
adb shell dumpsys telecom