Several audio related improvements
This commit is contained in:
@@ -21,6 +21,7 @@ import android.graphics.ImageDecoder
|
|||||||
import android.media.AudioAttributes
|
import android.media.AudioAttributes
|
||||||
import android.media.AudioManager
|
import android.media.AudioManager
|
||||||
import android.media.AudioManager.MODE_IN_COMMUNICATION
|
import android.media.AudioManager.MODE_IN_COMMUNICATION
|
||||||
|
import android.media.AudioManager.MODE_NORMAL
|
||||||
import android.media.MediaPlayer
|
import android.media.MediaPlayer
|
||||||
import android.media.Ringtone
|
import android.media.Ringtone
|
||||||
import android.media.RingtoneManager
|
import android.media.RingtoneManager
|
||||||
@@ -1013,8 +1014,10 @@ class BaresipService: Service() {
|
|||||||
else -> DisconnectCause.REMOTE
|
else -> DisconnectCause.REMOTE
|
||||||
}
|
}
|
||||||
connection.setDisconnected(DisconnectCause(cause))
|
connection.setDisconnected(DisconnectCause(cause))
|
||||||
|
Handler(Looper.getMainLooper()).postDelayed({
|
||||||
connection.destroy()
|
connection.destroy()
|
||||||
ConnectionService.connections.remove(callp)
|
ConnectionService.connections.remove(callp)
|
||||||
|
}, 500)
|
||||||
}
|
}
|
||||||
nm.cancel(CALL_NOTIFICATION_ID)
|
nm.cancel(CALL_NOTIFICATION_ID)
|
||||||
if (call != null) {
|
if (call != null) {
|
||||||
@@ -1046,8 +1049,8 @@ class BaresipService: Service() {
|
|||||||
val tone = ev[2]
|
val tone = ev[2]
|
||||||
if (tone == "busy")
|
if (tone == "busy")
|
||||||
playBusy()
|
playBusy()
|
||||||
else if (!Call.inCall()) {
|
else {
|
||||||
am.mode = AudioManager.MODE_NORMAL
|
ensureCommunicationMode()
|
||||||
resetCallVolume()
|
resetCallVolume()
|
||||||
proximitySensing(false)
|
proximitySensing(false)
|
||||||
}
|
}
|
||||||
@@ -1060,6 +1063,7 @@ class BaresipService: Service() {
|
|||||||
val completedElsewhere = missed && ev[2].startsWith("SIP") &&
|
val completedElsewhere = missed && ev[2].startsWith("SIP") &&
|
||||||
ev[2].contains(";cause=200")
|
ev[2].contains(";cause=200")
|
||||||
if (ua.account.callHistory) {
|
if (ua.account.callHistory) {
|
||||||
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
val history = CallHistoryNew(aor, call.peerUri, call.dir)
|
val history = CallHistoryNew(aor, call.peerUri, call.dir)
|
||||||
history.stopTime = GregorianCalendar()
|
history.stopTime = GregorianCalendar()
|
||||||
history.startTime = if (completedElsewhere) history.stopTime else call.startTime
|
history.startTime = if (completedElsewhere) history.stopTime else call.startTime
|
||||||
@@ -1068,7 +1072,6 @@ class BaresipService: Service() {
|
|||||||
history.recording = call.dumpfiles
|
history.recording = call.dumpfiles
|
||||||
}
|
}
|
||||||
history.add()
|
history.add()
|
||||||
CoroutineScope(Dispatchers.IO).launch {
|
|
||||||
if (call.startTime != null && call.dumpfiles[0] != "") {
|
if (call.startTime != null && call.dumpfiles[0] != "") {
|
||||||
delay(500)
|
delay(500)
|
||||||
val rxFile = File(call.dumpfiles[0])
|
val rxFile = File(call.dumpfiles[0])
|
||||||
@@ -1871,12 +1874,17 @@ class BaresipService: Service() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun ensureCommunicationMode() {
|
private fun ensureCommunicationMode() {
|
||||||
if (Call.inCall() && am.mode != MODE_IN_COMMUNICATION) {
|
if (Call.inCall()) {
|
||||||
|
if (am.mode != MODE_IN_COMMUNICATION) {
|
||||||
am.mode = MODE_IN_COMMUNICATION
|
am.mode = MODE_IN_COMMUNICATION
|
||||||
if (VERSION.SDK_INT < 31)
|
Log.d(TAG, "Manual Mode Guard (SDK ${VERSION.SDK_INT}): Setting MODE_IN_COMMUNICATION")
|
||||||
Log.d(TAG, "Manual Mode Guard (SDK < 31): Setting MODE_IN_COMMUNICATION")
|
}
|
||||||
else
|
} else {
|
||||||
Log.d(TAG, "Manual Mode Guard (SDK >= 31): Setting MODE_IN_COMMUNICATION")
|
if (am.mode != MODE_NORMAL) {
|
||||||
|
am.mode = MODE_NORMAL
|
||||||
|
Log.d(TAG, "Manual Mode Guard (SDK ${VERSION.SDK_INT}): Resetting to MODE_NORMAL")
|
||||||
|
}
|
||||||
|
Utils.clearCommunicationDevice(am)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -868,37 +868,28 @@ object Utils {
|
|||||||
|
|
||||||
private fun setSpeakerPhone(executor: Executor, am: AudioManager, enable: Boolean) {
|
private fun setSpeakerPhone(executor: Executor, am: AudioManager, enable: Boolean) {
|
||||||
if (Build.VERSION.SDK_INT >= 31) {
|
if (Build.VERSION.SDK_INT >= 31) {
|
||||||
|
if (!enable) {
|
||||||
|
Log.d(TAG, "Disabling speakerphone")
|
||||||
|
clearCommunicationDevice(am)
|
||||||
|
if (inCall() && am.mode == AudioManager.MODE_NORMAL) {
|
||||||
|
Log.d(TAG, "Restoring MODE_IN_COMMUNICATION")
|
||||||
|
am.mode = AudioManager.MODE_IN_COMMUNICATION
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
val current = am.communicationDevice!!.type
|
val current = am.communicationDevice!!.type
|
||||||
Log.d(TAG, "Current com dev/mode is $current/${am.mode}")
|
Log.d(TAG, "Current com dev/mode is $current/${am.mode}")
|
||||||
var speakerDevice: AudioDeviceInfo? = null
|
var speakerDevice: AudioDeviceInfo? = null
|
||||||
if (enable) {
|
|
||||||
for (device in am.availableCommunicationDevices)
|
for (device in am.availableCommunicationDevices)
|
||||||
if (device.type == AudioDeviceInfo.TYPE_BUILTIN_SPEAKER) {
|
if (device.type == AudioDeviceInfo.TYPE_BUILTIN_SPEAKER) {
|
||||||
speakerDevice = device
|
speakerDevice = device
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
for (device in am.availableCommunicationDevices)
|
|
||||||
if (device.type == AudioDeviceInfo.TYPE_BUILTIN_EARPIECE) {
|
|
||||||
speakerDevice = device
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (speakerDevice == null) {
|
if (speakerDevice == null) {
|
||||||
Log.w(TAG,"Could not find requested communication device")
|
Log.w(TAG,"Could not find requested communication device")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (current != speakerDevice.type) {
|
if (current != speakerDevice.type) {
|
||||||
if (speakerDevice.type == AudioDeviceInfo.TYPE_BUILTIN_EARPIECE) {
|
|
||||||
clearCommunicationDevice(am)
|
|
||||||
Log.d(TAG, "Setting com device to TYPE_BUILTIN_EARPIECE")
|
|
||||||
if (!am.setCommunicationDevice(speakerDevice))
|
|
||||||
Log.e(TAG, "Could not set com device")
|
|
||||||
if (inCall() && am.mode == AudioManager.MODE_NORMAL) {
|
|
||||||
Log.d(TAG, "Setting mode to communication")
|
|
||||||
am.mode = AudioManager.MODE_IN_COMMUNICATION
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Currently at API levels 31+, speakerphone needs normal mode
|
// Currently at API levels 31+, speakerphone needs normal mode
|
||||||
if (am.mode == AudioManager.MODE_NORMAL) {
|
if (am.mode == AudioManager.MODE_NORMAL) {
|
||||||
Log.d(TAG, "Setting com device to ${speakerDevice.type} in MODE_NORMAL")
|
Log.d(TAG, "Setting com device to ${speakerDevice.type} in MODE_NORMAL")
|
||||||
@@ -922,7 +913,6 @@ object Utils {
|
|||||||
Log.d(TAG, "Setting mode to NORMAL")
|
Log.d(TAG, "Setting mode to NORMAL")
|
||||||
am.mode = AudioManager.MODE_NORMAL
|
am.mode = AudioManager.MODE_NORMAL
|
||||||
}
|
}
|
||||||
}
|
|
||||||
Log.d(TAG, "New com device/mode is ${am.communicationDevice!!.type}/${am.mode}")
|
Log.d(TAG, "New com device/mode is ${am.communicationDevice!!.type}/${am.mode}")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -934,17 +924,17 @@ object Utils {
|
|||||||
|
|
||||||
fun toggleSpeakerPhone(executor: Executor, am: AudioManager) {
|
fun toggleSpeakerPhone(executor: Executor, am: AudioManager) {
|
||||||
if (Build.VERSION.SDK_INT >= 31) {
|
if (Build.VERSION.SDK_INT >= 31) {
|
||||||
if (am.communicationDevice!!.type == AudioDeviceInfo.TYPE_BUILTIN_EARPIECE)
|
if (am.communicationDevice!!.type == AudioDeviceInfo.TYPE_BUILTIN_SPEAKER)
|
||||||
setSpeakerPhone(executor, am, true)
|
|
||||||
else if (am.communicationDevice!!.type == AudioDeviceInfo.TYPE_BUILTIN_SPEAKER)
|
|
||||||
setSpeakerPhone(executor, am, false)
|
setSpeakerPhone(executor, am, false)
|
||||||
|
else
|
||||||
|
setSpeakerPhone(executor, am, true)
|
||||||
} else {
|
} else {
|
||||||
@Suppress("DEPRECATION")
|
@Suppress("DEPRECATION")
|
||||||
setSpeakerPhone(executor, am, !am.isSpeakerphoneOn)
|
setSpeakerPhone(executor, am, !am.isSpeakerphoneOn)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun clearCommunicationDevice(am: AudioManager) {
|
fun clearCommunicationDevice(am: AudioManager) {
|
||||||
if (Build.VERSION.SDK_INT >= 31) {
|
if (Build.VERSION.SDK_INT >= 31) {
|
||||||
am.clearCommunicationDevice()
|
am.clearCommunicationDevice()
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user