Ensure correct communication mode when SDK is < 31
This commit is contained in:
@@ -34,6 +34,7 @@ import android.net.NetworkCapabilities
|
|||||||
import android.net.NetworkRequest
|
import android.net.NetworkRequest
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.net.wifi.WifiManager
|
import android.net.wifi.WifiManager
|
||||||
|
import android.os.Build
|
||||||
import android.os.Build.VERSION
|
import android.os.Build.VERSION
|
||||||
import android.os.CountDownTimer
|
import android.os.CountDownTimer
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
@@ -786,10 +787,12 @@ class BaresipService: Service() {
|
|||||||
}
|
}
|
||||||
"call ringing" -> {
|
"call ringing" -> {
|
||||||
ConnectionService.connections[callp]?.setRinging()
|
ConnectionService.connections[callp]?.setRinging()
|
||||||
|
ensureCommunicationMode()
|
||||||
playRingBack()
|
playRingBack()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
"call progress" -> {
|
"call progress" -> {
|
||||||
|
ensureCommunicationMode()
|
||||||
if ((ev[1].toInt() and Api.SDP_RECVONLY) != 0)
|
if ((ev[1].toInt() and Api.SDP_RECVONLY) != 0)
|
||||||
stopMediaPlayer()
|
stopMediaPlayer()
|
||||||
else {
|
else {
|
||||||
@@ -866,6 +869,7 @@ class BaresipService: Service() {
|
|||||||
}
|
}
|
||||||
"call answered" -> {
|
"call answered" -> {
|
||||||
stopMediaPlayer()
|
stopMediaPlayer()
|
||||||
|
ensureCommunicationMode()
|
||||||
if (call!!.status.value == "incoming")
|
if (call!!.status.value == "incoming")
|
||||||
call.status.value = "answered"
|
call.status.value = "answered"
|
||||||
else
|
else
|
||||||
@@ -876,6 +880,7 @@ class BaresipService: Service() {
|
|||||||
}
|
}
|
||||||
"call established" -> {
|
"call established" -> {
|
||||||
ConnectionService.connections[callp]?.setActive()
|
ConnectionService.connections[callp]?.setActive()
|
||||||
|
ensureCommunicationMode()
|
||||||
nm.cancel(CALL_NOTIFICATION_ID)
|
nm.cancel(CALL_NOTIFICATION_ID)
|
||||||
Log.d(TAG, "AoR $aor call $callp established")
|
Log.d(TAG, "AoR $aor call $callp established")
|
||||||
call!!.status.value = "connected"
|
call!!.status.value = "connected"
|
||||||
@@ -1042,6 +1047,7 @@ class BaresipService: Service() {
|
|||||||
if (tone == "busy")
|
if (tone == "busy")
|
||||||
playBusy()
|
playBusy()
|
||||||
else if (!Call.inCall()) {
|
else if (!Call.inCall()) {
|
||||||
|
am.mode = AudioManager.MODE_NORMAL
|
||||||
resetCallVolume()
|
resetCallVolume()
|
||||||
proximitySensing(false)
|
proximitySensing(false)
|
||||||
}
|
}
|
||||||
@@ -1864,6 +1870,16 @@ class BaresipService: Service() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun ensureCommunicationMode() {
|
||||||
|
// On Android 11+, Telecom usually handles this.
|
||||||
|
// On Android 10 and below, we must be more aggressive.
|
||||||
|
if (VERSION.SDK_INT < 31 || am.mode != MODE_IN_COMMUNICATION) {
|
||||||
|
if (Call.inCall()) {
|
||||||
|
Log.d(TAG, "Manual Mode Guard: Setting MODE_IN_COMMUNICATION")
|
||||||
|
am.mode = MODE_IN_COMMUNICATION
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@SuppressLint("WakelockTimeout", "Wakelock")
|
@SuppressLint("WakelockTimeout", "Wakelock")
|
||||||
private fun proximitySensing(enable: Boolean) {
|
private fun proximitySensing(enable: Boolean) {
|
||||||
if (enable) {
|
if (enable) {
|
||||||
|
|||||||
Reference in New Issue
Block a user