Fix crash when using Element Call on API <= 30 (#4847)
This commit is contained in:
parent
91b925c3ee
commit
b1c33063b4
1 changed files with 19 additions and 15 deletions
|
|
@ -15,6 +15,7 @@ import android.os.Build
|
||||||
import android.os.PowerManager
|
import android.os.PowerManager
|
||||||
import android.webkit.JavascriptInterface
|
import android.webkit.JavascriptInterface
|
||||||
import android.webkit.WebView
|
import android.webkit.WebView
|
||||||
|
import androidx.annotation.RequiresApi
|
||||||
import androidx.core.content.getSystemService
|
import androidx.core.content.getSystemService
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
|
@ -66,23 +67,26 @@ class WebViewAudioManager(
|
||||||
/**
|
/**
|
||||||
* This listener tracks the current communication device and updates the WebView when it changes.
|
* This listener tracks the current communication device and updates the WebView when it changes.
|
||||||
*/
|
*/
|
||||||
private val commsDeviceChangedListener = AudioManager.OnCommunicationDeviceChangedListener { device ->
|
@get:RequiresApi(Build.VERSION_CODES.S)
|
||||||
if (device != null && device.id == expectedNewCommunicationDeviceId) {
|
private val commsDeviceChangedListener by lazy {
|
||||||
expectedNewCommunicationDeviceId = null
|
AudioManager.OnCommunicationDeviceChangedListener { device ->
|
||||||
Timber.d("Audio device changed, type: ${device.type}")
|
if (device != null && device.id == expectedNewCommunicationDeviceId) {
|
||||||
updateSelectedAudioDeviceInWebView(device.id.toString())
|
|
||||||
} else if (device != null && device.id != expectedNewCommunicationDeviceId) {
|
|
||||||
// We were expecting a device change but it didn't happen, so we should retry
|
|
||||||
val expectedDeviceId = expectedNewCommunicationDeviceId
|
|
||||||
if (expectedDeviceId != null) {
|
|
||||||
// Remove the expected id so we only retry once
|
|
||||||
expectedNewCommunicationDeviceId = null
|
expectedNewCommunicationDeviceId = null
|
||||||
audioManager.selectAudioDevice(expectedDeviceId.toString())
|
Timber.d("Audio device changed, type: ${device.type}")
|
||||||
|
updateSelectedAudioDeviceInWebView(device.id.toString())
|
||||||
|
} else if (device != null && device.id != expectedNewCommunicationDeviceId) {
|
||||||
|
// We were expecting a device change but it didn't happen, so we should retry
|
||||||
|
val expectedDeviceId = expectedNewCommunicationDeviceId
|
||||||
|
if (expectedDeviceId != null) {
|
||||||
|
// Remove the expected id so we only retry once
|
||||||
|
expectedNewCommunicationDeviceId = null
|
||||||
|
audioManager.selectAudioDevice(expectedDeviceId.toString())
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Timber.d("Audio device cleared")
|
||||||
|
expectedNewCommunicationDeviceId = null
|
||||||
|
audioManager.selectAudioDevice(null)
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
Timber.d("Audio device cleared")
|
|
||||||
expectedNewCommunicationDeviceId = null
|
|
||||||
audioManager.selectAudioDevice(null)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue