Update call UI to reflect mic muted state when toggled from Android Auto

This commit is contained in:
Sylvain Berfini 2024-08-08 01:36:44 +02:00
parent 57f3b0c78b
commit 6746e71197
5 changed files with 52 additions and 3 deletions

View file

@ -85,6 +85,10 @@ class CoreContext @UiThread constructor(val context: Context) : HandlerThread("C
MutableLiveData<Event<String>>()
}
val refreshMicrophoneMuteStateEvent: MutableLiveData<Event<Boolean>> by lazy {
MutableLiveData<Event<Boolean>>()
}
val showGreenToastEvent: MutableLiveData<Event<Pair<Int, Int>>> by lazy {
MutableLiveData<Event<Pair<Int, Int>>>()
}

View file

@ -23,15 +23,32 @@ import android.content.pm.ApplicationInfo
import androidx.car.app.CarAppService
import androidx.car.app.validation.HostValidator
import org.linphone.R
import org.linphone.core.tools.Log
class TelecomAndroidAutoService : CarAppService() {
companion object {
private const val TAG = "[Telecom Android Auto Service]"
}
override fun createHostValidator(): HostValidator {
val host = hostInfo
Log.e("$TAG Host is [${host?.packageName}] with UID [${host?.uid}]")
val validator = HostValidator.Builder(applicationContext)
.addAllowedHosts(R.array.hosts_allowlist_sample_copy) // androidx.car.app.R.array.hosts_allowlist_sampl
.build()
if (host != null) {
val allowed = validator.isValidHost(host)
Log.i("$TAG Host is [${if (allowed) "allowed" else "not allowed"}] in our validator")
} else {
Log.w("$TAG Host is null!")
}
return if ((applicationInfo.flags and ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
Log.w("$TAG App is in debug mode, allowing all hosts")
HostValidator.ALLOW_ALL_HOSTS_VALIDATOR
} else {
HostValidator.Builder(applicationContext)
.addAllowedHosts(R.array.hosts_allowlist_sample_copy)
.build()
validator
}
}
}

View file

@ -36,6 +36,7 @@ import org.linphone.core.Call
import org.linphone.core.CallListenerStub
import org.linphone.core.tools.Log
import org.linphone.utils.AudioUtils
import org.linphone.utils.Event
import org.linphone.utils.LinphoneUtils
class TelecomCallControlCallback(
@ -157,6 +158,7 @@ class TelecomCallControlCallback(
// This is to prevent mic not muted when joining conference if user decided to join as muted
if (muted || !LinphoneUtils.isCallOutgoing(callState, false)) {
call.microphoneMuted = muted
coreContext.refreshMicrophoneMuteStateEvent.postValue(Event(true))
} else {
Log.w("$TAG Not following unmute request because call is in state [$callState]")
}

View file

@ -295,6 +295,15 @@ class CallActivity : GenericActivity() {
hideUI(hide)
}
}
coreContext.refreshMicrophoneMuteStateEvent.observe(this) {
it.consume {
Log.i(
"$TAG Refreshing microphone mute state, probably to sync with Android Auto action"
)
callViewModel.refreshMicrophoneState()
}
}
}
override fun onStart() {

View file

@ -649,6 +649,23 @@ class CurrentCallViewModel @UiThread constructor() : GenericViewModel() {
}
}
@UiThread
fun refreshMicrophoneState() {
coreContext.postOnCoreThread {
val micMuted = if (currentCall.conference != null) {
currentCall.conference?.microphoneMuted ?: false
} else {
currentCall.microphoneMuted
}
if (currentCall.conference != null) {
currentCall.conference?.microphoneMuted = !micMuted
} else {
currentCall.microphoneMuted = !micMuted
}
isMicrophoneMuted.postValue(micMuted)
}
}
@UiThread
fun changeAudioOutputDevice() {
val routeAudioToSpeaker = isSpeakerEnabled.value != true