Skip to content

An open-source remote desktop application designed for self-hosting, as an alternative to TeamViewer.

fix: android, no voice call under android 11 (#8440)

fufesoubbf7d9e08a23
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 bb8cbffb2..db222dc84 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
@@ -116,7 +116,7 @@ class AudioRecordHandle(private var context: Context, private var isVideoStart:
}
fun onVoiceCallStarted(mediaProjection: MediaProjection?): Boolean {
- if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
+ if (!isSupportVoiceCall()) {
return false
}
// No need to check if video or audio is started here.
@@ -127,8 +127,8 @@ class AudioRecordHandle(private var context: Context, private var isVideoStart:
}
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 true if not supported, because is was not started.
+ if (!isSupportVoiceCall()) {
return true
}
if (isVideoStart()) {
@@ -176,9 +176,6 @@ class AudioRecordHandle(private var context: Context, private var isVideoStart:
}
fun tryReleaseAudio() {
- if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
- return
- }
if (isAudioStart() || isVideoStart()) {
return
}
diff --git a/flutter/android/app/src/main/kotlin/com/carriez/flutter_hbb/MainActivity.kt b/flutter/android/app/src/main/kotlin/com/carriez/flutter_hbb/MainActivity.kt
index b7050d8a4..10c3d7c2d 100644
--- a/flutter/android/app/src/main/kotlin/com/carriez/flutter_hbb/MainActivity.kt
+++ b/flutter/android/app/src/main/kotlin/com/carriez/flutter_hbb/MainActivity.kt
@@ -233,6 +233,17 @@ class MainActivity : FlutterActivity() {
result.success(false)
}
}
+ GET_VALUE -> {
+ if (call.arguments is String) {
+ if (call.arguments == KEY_IS_SUPPORT_VOICE_CALL) {
+ result.success(isSupportVoiceCall())
+ } else {
+ result.error("-1", "No such key", null)
+ }
+ } else {
+ result.success(null)
+ }
+ }
"on_voice_call_started" -> {
onVoiceCallStarted()
}
diff --git a/flutter/android/app/src/main/kotlin/com/carriez/flutter_hbb/common.kt b/flutter/android/app/src/main/kotlin/com/carriez/flutter_hbb/common.kt
index 3b41a73a1..514d493b9 100644
--- a/flutter/android/app/src/main/kotlin/com/carriez/flutter_hbb/common.kt
+++ b/flutter/android/app/src/main/kotlin/com/carriez/flutter_hbb/common.kt
@@ -47,6 +47,9 @@ const val START_ACTION = "start_action"
const val GET_START_ON_BOOT_OPT = "get_start_on_boot_opt"
const val SET_START_ON_BOOT_OPT = "set_start_on_boot_opt"
const val SYNC_APP_DIR_CONFIG_PATH = "sync_app_dir"
+const val GET_VALUE = "get_value"
+
+const val KEY_IS_SUPPORT_VOICE_CALL = "KEY_IS_SUPPORT_VOICE_CALL"
const val KEY_SHARED_PREFERENCES = "KEY_SHARED_PREFERENCES"
const val KEY_START_ON_BOOT_OPT = "KEY_START_ON_BOOT_OPT"
@@ -60,6 +63,11 @@ data class Info(
var width: Int, var height: Int, var scale: Int, var dpi: Int
)
+fun isSupportVoiceCall(): Boolean {
+ // https://developer.android.com/reference/android/media/MediaRecorder.AudioSource#VOICE_COMMUNICATION
+ return Build.VERSION.SDK_INT >= Build.VERSION_CODES.R
+}
+
fun requestPermission(context: Context, type: String) {
XXPermissions.with(context)
.permission(type)
diff --git a/flutter/lib/mobile/pages/remote_page.dart b/flutter/lib/mobile/pages/remote_page.dart
index d74dc4839..4d021609a 100644
--- a/flutter/lib/mobile/pages/remote_page.dart
+++ b/flutter/lib/mobile/pages/remote_page.dart
@@ -418,17 +418,21 @@ class _RemotePageState extends State<RemotePage> {
(isWeb
? []
: <Widget>[
- IconButton(
- color: Colors.white,
- icon: isAndroid
- ? SvgPicture.asset('assets/chat.svg',
- colorFilter: ColorFilter.mode(
- Colors.white, BlendMode.srcIn))
- : Icon(Icons.message),
- onPressed: () => isAndroid
- ? showChatOptions(widget.id)
- : onPressedTextChat(widget.id),
- )
+ futureBuilder(
+ future: gFFI.invokeMethod(
+ "get_value", "KEY_IS_SUPPORT_VOICE_CALL"),
+ hasData: (isSupportVoiceCall) => IconButton(
+ color: Colors.white,
+ icon: isAndroid && isSupportVoiceCall
+ ? SvgPicture.asset('assets/chat.svg',
+ colorFilter: ColorFilter.mode(
+ Colors.white, BlendMode.srcIn))
+ : Icon(Icons.message),
+ onPressed: () =>
+ isAndroid && isSupportVoiceCall
+ ? showChatOptions(widget.id)
+ : onPressedTextChat(widget.id),
+ ))
]) +
[
IconButton(