feat: add call manager and more static intent building functions for WebRtcCallService.kt

This commit is contained in:
Harris
2021-10-26 17:12:25 +11:00
parent 40cca532c2
commit cbfabdd0a7
3 changed files with 30 additions and 12 deletions

View File

@@ -6,11 +6,16 @@ import android.content.Intent
import android.os.IBinder
import androidx.core.content.ContextCompat
import dagger.hilt.android.AndroidEntryPoint
import org.thoughtcrime.securesms.webrtc.AudioManagerCommand
import org.thoughtcrime.securesms.webrtc.CallManager
import java.util.*
import javax.inject.Inject
@AndroidEntryPoint
class WebRtcCallService: Service() {
@Inject lateinit var callManager: CallManager
companion object {
private const val ACTION_UPDATE = "UPDATE"
private const val ACTION_STOP = "STOP"
@@ -18,6 +23,7 @@ class WebRtcCallService: Service() {
private const val ACTION_LOCAL_HANGUP = "LOCAL_HANGUP"
private const val ACTION_WANTS_BLUETOOTH = "WANTS_BLUETOOTH"
private const val ACTION_CHANGE_POWER_BUTTON = "CHANGE_POWER_BUTTON"
private const val ACTION_SEND_AUDIO_COMMAND = "SEND_AUDIO_COMMAND"
private const val EXTRA_UPDATE_TYPE = "UPDATE_TYPE"
private const val EXTRA_RECIPIENT_ID = "RECIPIENT_ID"
@@ -28,30 +34,34 @@ class WebRtcCallService: Service() {
fun update(context: Context, type: Int, callId: UUID) {
val intent = Intent(context, WebRtcCallService::class.java)
intent.setAction(ACTION_UPDATE)
.setAction(ACTION_UPDATE)
.putExtra(EXTRA_RECIPIENT_ID, callId)
.putExtra(EXTRA_UPDATE_TYPE, type)
ContextCompat.startForegroundService(context, intent)
}
fun stop(context: Context) {
val intent = Intent(context, WebRtcCallService::class.java)
intent.action = ACTION_STOP
.setAction(ACTION_STOP)
ContextCompat.startForegroundService(context, intent)
}
fun denyCallIntent(context: Context): Intent {
return Intent(context, WebRtcCallService::class.java).setAction(ACTION_DENY_CALL)
}
fun denyCallIntent(context: Context) = Intent(context, WebRtcCallService::class.java).setAction(ACTION_DENY_CALL)
fun hangupIntent(context: Context): Intent {
return Intent(context, WebRtcCallService::class.java).setAction(ACTION_LOCAL_HANGUP)
}
fun hangupIntent(context: Context) = Intent(context, WebRtcCallService::class.java).setAction(ACTION_LOCAL_HANGUP)
fun sendAudioManagerCommand(context: Context, command: AudioManagerCommand) {
val intent = Intent(context, WebRtcCallService::class.java)
.setAction(ACTION_SEND_AUDIO_COMMAND)
.putExtra(EXTRA_AUDIO_COMMAND, command)
ContextCompat.startForegroundService(context, intent)
}
fun changePowerButtonReceiver(context: Context, register: Boolean) {
val intent = Intent(context, WebRtcCallService::class.java)
.setAction(ACTION_CHANGE_POWER_BUTTON)
.putExtra(EXTRA_ENABLED, register)
ContextCompat.startForegroundService(context, intent)
}
}

View File

@@ -4,6 +4,10 @@ import android.os.Parcelable
import kotlinx.android.parcel.Parcelize
@Parcelize
enum class AudioManagerCommand: Parcelable {
sealed class AudioManagerCommand: Parcelable {
@Parcelize object StartOutgoingRinger: AudioManagerCommand()
@Parcelize object SilenceIncomingRinger: AudioManagerCommand()
@Parcelize object Start: AudioManagerCommand()
@Parcelize object Stop: AudioManagerCommand()
@Parcelize object SetUserDevice: AudioManagerCommand()
}

View File

@@ -0,0 +1,4 @@
package org.thoughtcrime.securesms.webrtc
class CallManager {
}