- Set volume controls to apply to current audio stream (may not always work)
- Audio focus implementation changes
This commit is contained in:
@@ -330,20 +330,18 @@ class BaresipService: Service() {
|
|||||||
else
|
else
|
||||||
status[account_index] = R.drawable.dot_green
|
status[account_index] = R.drawable.dot_green
|
||||||
updateStatusNotification()
|
updateStatusNotification()
|
||||||
if (!Utils.isVisible())
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
"registering failed" -> {
|
"registering failed" -> {
|
||||||
status[account_index] = R.drawable.dot_red
|
status[account_index] = R.drawable.dot_red
|
||||||
updateStatusNotification()
|
updateStatusNotification()
|
||||||
if (!Utils.isVisible())
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
"unregistering" -> {
|
"unregistering" -> {
|
||||||
status[account_index] = R.drawable.dot_yellow
|
status[account_index] = R.drawable.dot_yellow
|
||||||
updateStatusNotification()
|
updateStatusNotification()
|
||||||
if (!Utils.isVisible())
|
}
|
||||||
return
|
"call ringing" -> {
|
||||||
|
am.mode = AudioManager.MODE_IN_COMMUNICATION
|
||||||
|
requestAudioFocus(AudioManager.STREAM_VOICE_CALL)
|
||||||
}
|
}
|
||||||
"call incoming" -> {
|
"call incoming" -> {
|
||||||
val peerUri = Api.call_peeruri(callp)
|
val peerUri = Api.call_peeruri(callp)
|
||||||
@@ -412,12 +410,12 @@ class BaresipService: Service() {
|
|||||||
CallHistory.add(CallHistory(aor, call.peerURI, call.dir, true))
|
CallHistory.add(CallHistory(aor, call.peerURI, call.dir, true))
|
||||||
CallHistory.save(filesPath)
|
CallHistory.save(filesPath)
|
||||||
call.hasHistory = true
|
call.hasHistory = true
|
||||||
stopRinging()
|
if (call.dir == "in")
|
||||||
am.mode = AudioManager.MODE_IN_COMMUNICATION
|
stopRinging()
|
||||||
requestAudioFocus(AudioManager.STREAM_VOICE_CALL)
|
if (!isAudioFocused()) {
|
||||||
am.isSpeakerphoneOn = false
|
am.mode = AudioManager.MODE_IN_COMMUNICATION
|
||||||
if (!Utils.isVisible())
|
requestAudioFocus(AudioManager.STREAM_VOICE_CALL)
|
||||||
return
|
}
|
||||||
}
|
}
|
||||||
"call verified", "call secure" -> {
|
"call verified", "call secure" -> {
|
||||||
val call = Call.find(callp)
|
val call = Call.find(callp)
|
||||||
@@ -431,8 +429,6 @@ class BaresipService: Service() {
|
|||||||
call.security = R.drawable.box_green
|
call.security = R.drawable.box_green
|
||||||
call.zid = ev[1]
|
call.zid = ev[1]
|
||||||
}
|
}
|
||||||
if (!Utils.isVisible())
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
"call transfer" -> {
|
"call transfer" -> {
|
||||||
val call = Call.find(callp)
|
val call = Call.find(callp)
|
||||||
@@ -489,7 +485,8 @@ class BaresipService: Service() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
Log.d(LOG_TAG, "AoR $aor call $callp is closed")
|
Log.d(LOG_TAG, "AoR $aor call $callp is closed")
|
||||||
stopRinging()
|
if (call.status == "incoming")
|
||||||
|
stopRinging()
|
||||||
calls.remove(call)
|
calls.remove(call)
|
||||||
if (!call.hasHistory) {
|
if (!call.hasHistory) {
|
||||||
CallHistory.add(CallHistory(aor, call.peerURI, call.dir, false))
|
CallHistory.add(CallHistory(aor, call.peerURI, call.dir, false))
|
||||||
@@ -497,16 +494,11 @@ class BaresipService: Service() {
|
|||||||
if (call.dir == "in") ua.account.missedCalls = true
|
if (call.dir == "in") ua.account.missedCalls = true
|
||||||
}
|
}
|
||||||
if (Call.calls().size == 0) {
|
if (Call.calls().size == 0) {
|
||||||
|
abandonAudioFocus()
|
||||||
am.mode = AudioManager.MODE_NORMAL
|
am.mode = AudioManager.MODE_NORMAL
|
||||||
if (am.isSpeakerphoneOn) am.isSpeakerphoneOn = false
|
if (am.isSpeakerphoneOn) am.isSpeakerphoneOn = false
|
||||||
if (audioFocused) abandonAudioFocus()
|
speakerPhone = false
|
||||||
}
|
}
|
||||||
if (speakerPhone) {
|
|
||||||
am.isSpeakerphoneOn = !am.isSpeakerphoneOn
|
|
||||||
speakerPhone = am.isSpeakerphoneOn
|
|
||||||
}
|
|
||||||
if (!Utils.isVisible())
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
"transfer failed" -> {
|
"transfer failed" -> {
|
||||||
Log.d(LOG_TAG, "AoR $aor hanging up call $callp with ${ev[1]}")
|
Log.d(LOG_TAG, "AoR $aor hanging up call $callp with ${ev[1]}")
|
||||||
@@ -516,6 +508,8 @@ class BaresipService: Service() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!Utils.isVisible())
|
||||||
|
return
|
||||||
if (newEvent == null) newEvent = event
|
if (newEvent == null) newEvent = event
|
||||||
val intent = Intent("service event")
|
val intent = Intent("service event")
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or
|
||||||
@@ -695,6 +689,13 @@ class BaresipService: Service() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun isAudioFocused(): Boolean {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
|
||||||
|
return audioFocusRequest != null
|
||||||
|
else
|
||||||
|
return audioFocused
|
||||||
|
}
|
||||||
|
|
||||||
private fun abandonAudioFocus() {
|
private fun abandonAudioFocus() {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
if (audioFocusRequest != null) {
|
if (audioFocusRequest != null) {
|
||||||
@@ -728,8 +729,8 @@ class BaresipService: Service() {
|
|||||||
rtTimer!!.cancel()
|
rtTimer!!.cancel()
|
||||||
rtTimer = null
|
rtTimer = null
|
||||||
if (rt.isPlaying) rt.stop()
|
if (rt.isPlaying) rt.stop()
|
||||||
abandonAudioFocus()
|
|
||||||
}
|
}
|
||||||
|
abandonAudioFocus()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun cleanService() {
|
private fun cleanService() {
|
||||||
@@ -772,6 +773,7 @@ class BaresipService: Service() {
|
|||||||
var disconnected = false
|
var disconnected = false
|
||||||
var libraryLoaded = false
|
var libraryLoaded = false
|
||||||
var isServiceClean = false
|
var isServiceClean = false
|
||||||
|
var speakerPhone = false
|
||||||
|
|
||||||
var uas = ArrayList<UserAgent>()
|
var uas = ArrayList<UserAgent>()
|
||||||
var status = ArrayList<Int>()
|
var status = ArrayList<Int>()
|
||||||
@@ -781,8 +783,6 @@ class BaresipService: Service() {
|
|||||||
var contacts = ArrayList<Contact>()
|
var contacts = ArrayList<Contact>()
|
||||||
var chatTexts: MutableMap<String, String> = mutableMapOf<String, String>()
|
var chatTexts: MutableMap<String, String> = mutableMapOf<String, String>()
|
||||||
|
|
||||||
var speakerPhone = false
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import android.util.Log
|
|||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
|
import android.media.AudioManager
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.CountDownTimer
|
import android.os.CountDownTimer
|
||||||
import android.support.v4.content.LocalBroadcastManager
|
import android.support.v4.content.LocalBroadcastManager
|
||||||
@@ -568,6 +569,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
Toast.LENGTH_LONG).show()
|
Toast.LENGTH_LONG).show()
|
||||||
}
|
}
|
||||||
"call ringing" -> {
|
"call ringing" -> {
|
||||||
|
setVolumeControlStream(AudioManager.STREAM_VOICE_CALL)
|
||||||
}
|
}
|
||||||
"call rejected" -> {
|
"call rejected" -> {
|
||||||
if (ua == UserAgent.uas()[aorSpinner.selectedItemPosition]) {
|
if (ua == UserAgent.uas()[aorSpinner.selectedItemPosition]) {
|
||||||
@@ -590,6 +592,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
Log.e("Baresip", "Incoming call $callp not found")
|
Log.e("Baresip", "Incoming call $callp not found")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
setVolumeControlStream(AudioManager.STREAM_RING)
|
||||||
if ((aorSpinner.selectedItemPosition == -1) ||
|
if ((aorSpinner.selectedItemPosition == -1) ||
|
||||||
(ua != UserAgent.uas()[aorSpinner.selectedItemPosition])) {
|
(ua != UserAgent.uas()[aorSpinner.selectedItemPosition])) {
|
||||||
aorSpinner.setSelection(account_index)
|
aorSpinner.setSelection(account_index)
|
||||||
@@ -622,6 +625,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
Log.e("Baresip", "Established call $callp not found")
|
Log.e("Baresip", "Established call $callp not found")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
setVolumeControlStream(AudioManager.STREAM_VOICE_CALL)
|
||||||
if (ua == UserAgent.uas()[aorSpinner.selectedItemPosition]) {
|
if (ua == UserAgent.uas()[aorSpinner.selectedItemPosition]) {
|
||||||
if (call.dir == "in")
|
if (call.dir == "in")
|
||||||
callTitle.text = "Incoming call from ..."
|
callTitle.text = "Incoming call from ..."
|
||||||
|
|||||||
Reference in New Issue
Block a user