-
Notifications
You must be signed in to change notification settings - Fork 226
Use in-call volume and mode for EC #4481
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
b570a0b
e5ec2c4
d2dbae8
4645d6f
c19acb7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright 2025 New Vector Ltd. | ||
* | ||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial | ||
* Please see LICENSE files in the repository root for full details. | ||
*/ | ||
|
||
package io.element.android.libraries.androidutils.compat | ||
|
||
import android.media.AudioDeviceInfo | ||
import android.media.AudioManager | ||
import android.os.Build | ||
|
||
fun AudioManager.enableExternalAudioDevice() { | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { | ||
// The list of device types that are considered as communication devices, sorted by likelihood of it being used for communication. | ||
val wantedDeviceTypes = listOf( | ||
Check warning on line 17 in libraries/androidutils/src/main/kotlin/io/element/android/libraries/androidutils/compat/AudioManager.kt
|
||
// Paired bluetooth device with microphone | ||
AudioDeviceInfo.TYPE_BLUETOOTH_SCO, | ||
Check warning on line 19 in libraries/androidutils/src/main/kotlin/io/element/android/libraries/androidutils/compat/AudioManager.kt
|
||
// USB devices which can play or record audio | ||
AudioDeviceInfo.TYPE_USB_HEADSET, | ||
AudioDeviceInfo.TYPE_USB_DEVICE, | ||
AudioDeviceInfo.TYPE_USB_ACCESSORY, | ||
Check warning on line 23 in libraries/androidutils/src/main/kotlin/io/element/android/libraries/androidutils/compat/AudioManager.kt
|
||
// Wired audio devices | ||
AudioDeviceInfo.TYPE_WIRED_HEADSET, | ||
AudioDeviceInfo.TYPE_WIRED_HEADPHONES, | ||
Check warning on line 26 in libraries/androidutils/src/main/kotlin/io/element/android/libraries/androidutils/compat/AudioManager.kt
|
||
// The built-in speaker of the device | ||
AudioDeviceInfo.TYPE_BUILTIN_SPEAKER, | ||
Check warning on line 28 in libraries/androidutils/src/main/kotlin/io/element/android/libraries/androidutils/compat/AudioManager.kt
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For Video Call, I guess TYPE_BUILTIN_SPEAKER should have a higher priority than TYPE_BUILTIN_EARPIECE, no? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, nice catch. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Once we have the "EC stop audio output"/"EC start/continue audio output" widget actions it should be easy to switch from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can't say without having tested it first. In theory it should be. |
||
// The built-in earpiece of the device | ||
AudioDeviceInfo.TYPE_BUILTIN_EARPIECE, | ||
Check warning on line 30 in libraries/androidutils/src/main/kotlin/io/element/android/libraries/androidutils/compat/AudioManager.kt
|
||
) | ||
val devices = availableCommunicationDevices | ||
Check warning on line 32 in libraries/androidutils/src/main/kotlin/io/element/android/libraries/androidutils/compat/AudioManager.kt
|
||
val selectedDevice = devices.find { | ||
wantedDeviceTypes.contains(it.type) | ||
Check warning on line 34 in libraries/androidutils/src/main/kotlin/io/element/android/libraries/androidutils/compat/AudioManager.kt
|
||
} | ||
selectedDevice?.let { setCommunicationDevice(it) } | ||
} else { | ||
// If we don't have access to the new APIs, use the deprecated ones | ||
@Suppress("DEPRECATION") | ||
isSpeakerphoneOn = true | ||
} | ||
} | ||
|
||
fun AudioManager.disableExternalAudioDevice() { | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { | ||
clearCommunicationDevice() | ||
Check warning on line 46 in libraries/androidutils/src/main/kotlin/io/element/android/libraries/androidutils/compat/AudioManager.kt
|
||
} else { | ||
// If we don't have access to the new APIs, use the deprecated ones | ||
@Suppress("DEPRECATION") | ||
isSpeakerphoneOn = false | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe store the previous mode and restore it here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From what I saw in some issues (this is poorly documented, AFAICT) the app can be 'blacklisted' if it doesn't play any audio in the 6s after enabling this mode or doesn't return to the
MODE_NORMAL
when it's done playing.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, thanks.