From 74cc5abd09f56ac6d8294a4e3c8ff35fb6883a8e Mon Sep 17 00:00:00 2001 From: fufesou <13586388+fufesou@users.noreply.github.com> Date: Fri, 21 Jun 2024 16:43:54 +0800 Subject: [PATCH] fix: android prompt "Failed to stop voice call" on conn ended (#8434) * fix: android prompt "Failed to stop voice call" on conn ended Signed-off-by: fufesou * Remove invalid comment Signed-off-by: fufesou * Better control of voice call status Signed-off-by: fufesou * Better voice call status control Signed-off-by: fufesou * better end conn for voice call Signed-off-by: fufesou --------- Signed-off-by: fufesou --- .../com/carriez/flutter_hbb/AudioRecordHandle.kt | 14 +++++--------- flutter/lib/mobile/pages/remote_page.dart | 9 ++++----- flutter/lib/models/chat_model.dart | 2 ++ 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/flutter/android/app/src/main/kotlin/com/carriez/flutter_hbb/AudioRecordHandle.kt b/flutter/android/app/src/main/kotlin/com/carriez/flutter_hbb/AudioRecordHandle.kt index 122a5a92b..bb8cbffb2 100644 --- a/flutter/android/app/src/main/kotlin/com/carriez/flutter_hbb/AudioRecordHandle.kt +++ b/flutter/android/app/src/main/kotlin/com/carriez/flutter_hbb/AudioRecordHandle.kt @@ -119,21 +119,17 @@ class AudioRecordHandle(private var context: Context, private var isVideoStart: if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) { return false } - if (isVideoStart() || isAudioStart()) { - if (!switchToVoiceCall(mediaProjection)) { - return false - } - } else { - if (!switchToVoiceCall(mediaProjection)) { - return false - } + // No need to check if video or audio is started here. + if (!switchToVoiceCall(mediaProjection)) { + return false } return true } fun onVoiceCallClosed(mediaProjection: MediaProjection?): Boolean { + // Return true if `Build.VERSION.SDK_INT < Build.VERSION_CODES.R`, because is was not started. if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) { - return false + return true } if (isVideoStart()) { switchOutVoiceCall(mediaProjection) diff --git a/flutter/lib/mobile/pages/remote_page.dart b/flutter/lib/mobile/pages/remote_page.dart index 3d89cd85f..d74dc4839 100644 --- a/flutter/lib/mobile/pages/remote_page.dart +++ b/flutter/lib/mobile/pages/remote_page.dart @@ -105,11 +105,10 @@ class _RemotePageState extends State { } await keyboardSubscription.cancel(); removeSharedStates(widget.id); - if (isAndroid) { - // Only one client is considered here for now. - // TODO: take into account the case where there are multiple clients - gFFI.invokeMethod("on_voice_call_closed"); - } + // `on_voice_call_closed` should be called when the connection is ended. + // The inner logic of `on_voice_call_closed` will check if the voice call is active. + // Only one client is considered here for now. + gFFI.chatModel.onVoiceCallClosed("End connetion"); } // to-do: It should be better to use transparent color instead of the bgColor. diff --git a/flutter/lib/models/chat_model.dart b/flutter/lib/models/chat_model.dart index 289124104..778c94357 100644 --- a/flutter/lib/models/chat_model.dart +++ b/flutter/lib/models/chat_model.dart @@ -535,6 +535,8 @@ class ChatModel with ChangeNotifier { void onVoiceCallClosed(String reason) { _voiceCallStatus.value = VoiceCallStatus.notStarted; if (isAndroid) { + // We can always invoke "on_voice_call_closed" + // no matter if the `_voiceCallStatus` was `VoiceCallStatus.notStarted` or not. parent.target?.invokeMethod("on_voice_call_closed"); } }