diff --git a/app/src/main/assets/linphonerc_factory b/app/src/main/assets/linphonerc_factory index c1269d081..b2e06c9d1 100644 --- a/app/src/main/assets/linphonerc_factory +++ b/app/src/main/assets/linphonerc_factory @@ -31,6 +31,7 @@ disable_ringing=1 [audio] android_disable_audio_focus_requests=1 +android_monitor_audio_devices=0 [video] displaytype=MSAndroidTextureDisplay diff --git a/app/src/main/java/org/linphone/core/CoreContext.kt b/app/src/main/java/org/linphone/core/CoreContext.kt index f535bc946..85e00409e 100644 --- a/app/src/main/java/org/linphone/core/CoreContext.kt +++ b/app/src/main/java/org/linphone/core/CoreContext.kt @@ -111,7 +111,14 @@ class CoreContext @UiThread constructor(val context: Context) : HandlerThread("C "$TAG Added device [${device.productName}] with ID [${device.id}] and type [${device.type}]" ) } - core.reloadSoundDevices() + if (telecomManager.getCurrentlyFollowedCalls() <= 0) { + Log.i("$TAG No call found in Telecom's CallsManager, reloading sound devices") + core.reloadSoundDevices() + } else { + Log.i( + "$TAG At least one active call in Telecom's CallsManager, let it handle the added device" + ) + } } } @@ -124,7 +131,14 @@ class CoreContext @UiThread constructor(val context: Context) : HandlerThread("C "$TAG Removed device [${device.id}][${device.productName}][${device.type}]" ) } - core.reloadSoundDevices() + if (telecomManager.getCurrentlyFollowedCalls() <= 0) { + Log.i("$TAG No call found in Telecom's CallsManager, reloading sound devices") + core.reloadSoundDevices() + } else { + Log.i( + "$TAG At least one active call in Telecom's CallsManager, let it handle the removed device" + ) + } } } } @@ -242,6 +256,11 @@ class CoreContext @UiThread constructor(val context: Context) : HandlerThread("C } } + @WorkerThread + override fun onAudioDevicesListUpdated(core: Core) { + Log.i("$TAG Available audio devices list was updated") + } + @WorkerThread override fun onLastCallEnded(core: Core) { Log.i("$TAG Last call ended") diff --git a/app/src/main/java/org/linphone/telecom/TelecomCallControlCallback.kt b/app/src/main/java/org/linphone/telecom/TelecomCallControlCallback.kt index 536f6367e..c25941aa4 100644 --- a/app/src/main/java/org/linphone/telecom/TelecomCallControlCallback.kt +++ b/app/src/main/java/org/linphone/telecom/TelecomCallControlCallback.kt @@ -99,7 +99,7 @@ class TelecomCallControlCallback( callControl.availableEndpoints.onEach { list -> Log.i("$TAG New available audio endpoints list") - if (availableEndpoints.size != list.size) { + if (availableEndpoints != list) { Log.i( "$TAG List size of available audio endpoints has changed, reload sound devices in SDK" ) diff --git a/app/src/main/java/org/linphone/telecom/TelecomManager.kt b/app/src/main/java/org/linphone/telecom/TelecomManager.kt index 09e2630a5..59795b76f 100644 --- a/app/src/main/java/org/linphone/telecom/TelecomManager.kt +++ b/app/src/main/java/org/linphone/telecom/TelecomManager.kt @@ -52,8 +52,15 @@ class TelecomManager @WorkerThread constructor(context: Context) { override fun onCallCreated(core: Core, call: Call) { onCallCreated(call) } + + @WorkerThread + override fun onLastCallEnded(core: Core) { + currentlyFollowedCalls = 0 + } } + private var currentlyFollowedCalls: Int = 0 + init { callsManager.registerAppWithTelecom( CallsManager.CAPABILITY_BASELINE or @@ -65,6 +72,11 @@ class TelecomManager @WorkerThread constructor(context: Context) { ) } + @WorkerThread + fun getCurrentlyFollowedCalls(): Int { + return currentlyFollowedCalls + } + @WorkerThread fun onCallCreated(call: Call) { Log.i("$TAG Call created: $call") @@ -112,6 +124,7 @@ class TelecomManager @WorkerThread constructor(context: Context) { coreContext.postOnCoreThread { coreContext.terminateCall(call) } + currentlyFollowedCalls -= 1 }, { // onSetActive Log.i("$TAG We're asked to resume the call") @@ -140,6 +153,8 @@ class TelecomManager @WorkerThread constructor(context: Context) { // We must first call setCallback on callControlScope before using it callbacks.onCallControlCallbackSet() + currentlyFollowedCalls += 1 + Log.i("$TAG Call added to Telecom's CallsManager") } } catch (e: Exception) { Log.e("$TAG Failed to add call to Telecom's CallsManager!")