Telecom Connection onHold and onUnhold aren't getting called

56 views Asked by At

onHold and onUnhold functions won't get triggered when I receive a GSM call and pick it up while I'm on an active call through my app. onDisconnect callback gets triggered when I answer the GSM call. Am I missing something in my implementation?

So, I've integrated the telecom subsystem into my app. I've also set the capabilities for the connection and included CAPABILITY_SUPPORT_HOLD, like shown below,

class VoiceConnectionService : ConnectionService() {

   var activeConnection: Connection? = null

   override fun onCreateIncomingConnection(
        connectionManagerPhoneAccount: PhoneAccountHandle,
        request: ConnectionRequest
    ): Connection? {
        val incomingCallConnection = createConnection(request)
        incomingCallConnection?.setRinging()
        return incomingCallConnection
    }

    private fun createConnection(request: ConnectionRequest): Connection? {
        activeConnection = TelecomConnection()

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            (activeConnection as TelecomTwilioConnection).connectionProperties = Connection.PROPERTY_SELF_MANAGED
        }
        (activeConnection as TelecomTwilioConnection).connectionCapabilities = Connection.CAPABILITY_MUTE
        (activeConnection as TelecomTwilioConnection).connectionCapabilities = Connection.CAPABILITY_SUPPORT_HOLD
        return activeConnection
    }
}

But the callback functions in TelecomConnection class won't get triggered when I'm on an active call through this app and then I receive a GSM call and if I answer it, onHold and onUnhold won't get called.

class TelecomConnection : Connection() {

   override onHold() { }
   override onUnhold() { }
}
<service android:name=".twilio.telecom.VoiceConnectionService"
            android:label="VoiceConnectionService"
            android:permission="android.permission.BIND_TELECOM_CONNECTION_SERVICE"
            android:exported="false">
            <intent-filter>
                <action android:name="android.telecom.ConnectionService" />
            </intent-filter>
        </service>
1

There are 1 answers

0
Jitendra Reddy On BEST ANSWER

I was able to get it working by adding the capabilities in the following way,

var capabilities: Int = (activeConnection as TelecomTwilioConnection).connectionCapabilities or Connection.CAPABILITY_MUTE
        capabilities = capabilities or Connection.CAPABILITY_HOLD
        capabilities = capabilities or Connection.CAPABILITY_SUPPORT_HOLD
        (activeConnection as TelecomTwilioConnection).connectionCapabilities = capabilities