Modern-Apps.git
Publicgit clone https://git.maproj.org/Modern-Apps.gitModern-Apps.git / communicate-dev / src / main / java / com / vayunmathur / communicate / data / call / InAppCallSystemBridge.kt
InAppCallSystemBridge.kt47 lines · 1.8 KiBRaw
| 1 | package com.vayunmathur.communicate.data.call |
| 2 | |
| 3 | import android.content.Context |
| 4 | |
| 5 | /** |
| 6 | * Host-installed system side of in-app calling: Telecom registration and the |
| 7 | * call foreground service live in the host app (they need the host's |
| 8 | * MainActivity, resources, and manifest-declared services), while the line |
| 9 | * call managers live here. The host's `InAppCallTelecom` installs a [Handler] |
| 10 | * at app start (sync-service `onCreate` and the telecom effects); line code |
| 11 | * calls through this bridge so it never references host telephony classes. |
| 12 | * With no handler installed (unit tests), calls are dropped, matching the |
| 13 | * previous `appContext == null` behaviour. |
| 14 | */ |
| 15 | object InAppCallSystemBridge { |
| 16 | |
| 17 | /** System operations the host performs on behalf of a line call. */ |
| 18 | interface Handler { |
| 19 | /** Mirror an incoming line call into Telecom. */ |
| 20 | fun addIncoming(context: Context, peerId: String) |
| 21 | |
| 22 | /** Mirror an outgoing line call into Telecom. */ |
| 23 | fun addOutgoing(context: Context, peerId: String) |
| 24 | |
| 25 | /** Start the host's call foreground service. */ |
| 26 | fun startForegroundService(context: Context) |
| 27 | } |
| 28 | |
| 29 | /** Installed by the host; null in unit tests and before app start. */ |
| 30 | @Volatile |
| 31 | var handler: Handler? = null |
| 32 | |
| 33 | /** Mirror an incoming call into Telecom, if the host installed a handler. */ |
| 34 | fun addIncoming(context: Context, peerId: String) { |
| 35 | handler?.addIncoming(context, peerId) |
| 36 | } |
| 37 | |
| 38 | /** Mirror an outgoing call into Telecom, if the host installed a handler. */ |
| 39 | fun addOutgoing(context: Context, peerId: String) { |
| 40 | handler?.addOutgoing(context, peerId) |
| 41 | } |
| 42 | |
| 43 | /** Start the host call foreground service, if a handler is installed. */ |
| 44 | fun startForegroundService(context: Context) { |
| 45 | handler?.startForegroundService(context) |
| 46 | } |
| 47 | } |