package com.vayunmathur.communicate.data.call import android.content.Context /** * Host-installed system side of in-app calling: Telecom registration and the * call foreground service live in the host app (they need the host's * MainActivity, resources, and manifest-declared services), while the line * call managers live here. The host's `InAppCallTelecom` installs a [Handler] * at app start (sync-service `onCreate` and the telecom effects); line code * calls through this bridge so it never references host telephony classes. * With no handler installed (unit tests), calls are dropped, matching the * previous `appContext == null` behaviour. */ object InAppCallSystemBridge { /** System operations the host performs on behalf of a line call. */ interface Handler { /** Mirror an incoming line call into Telecom. */ fun addIncoming(context: Context, peerId: String) /** Mirror an outgoing line call into Telecom. */ fun addOutgoing(context: Context, peerId: String) /** Start the host's call foreground service. */ fun startForegroundService(context: Context) } /** Installed by the host; null in unit tests and before app start. */ @Volatile var handler: Handler? = null /** Mirror an incoming call into Telecom, if the host installed a handler. */ fun addIncoming(context: Context, peerId: String) { handler?.addIncoming(context, peerId) } /** Mirror an outgoing call into Telecom, if the host installed a handler. */ fun addOutgoing(context: Context, peerId: String) { handler?.addOutgoing(context, peerId) } /** Start the host call foreground service, if a handler is installed. */ fun startForegroundService(context: Context) { handler?.startForegroundService(context) } }