Added Speaker Phone audio setting

This commit is contained in:
Juha Heinanen
2024-04-09 10:01:00 +03:00
parent 23ae74e4fe
commit ad7c1cb68b
6 changed files with 74 additions and 15 deletions

View File

@ -18,6 +18,7 @@ class AudioActivity : AppCompatActivity() {
private lateinit var opusBitRate: EditText
private lateinit var opusPacketLoss: EditText
private lateinit var aec: CheckBox
private lateinit var speakerPhone: CheckBox
private lateinit var audioDelay: EditText
private var save = false
@ -73,6 +74,9 @@ class AudioActivity : AppCompatActivity() {
}
}
speakerPhone = binding.SpeakerPhone
speakerPhone.isChecked = BaresipService.speakerPhone
val modules = Config.variables("module")
val audioModulesList = binding.AudioModulesList
@ -175,6 +179,13 @@ class AudioActivity : AppCompatActivity() {
save = true
}
if (speakerPhone.isChecked != BaresipService.speakerPhone) {
BaresipService.speakerPhone = speakerPhone.isChecked
Config.replaceVariable("speaker_phone",
if (BaresipService.speakerPhone) "yes" else "no")
save = true
}
var id = 1001
for (module in audioModules) {
val box = findViewById<CheckBox>(id++)
@ -287,6 +298,10 @@ class AudioActivity : AppCompatActivity() {
Utils.alertView(this, getString(R.string.default_call_volume),
getString(R.string.default_call_volume_help))
}
binding.SpeakerPhoneTitle.setOnClickListener {
Utils.alertView(this, getString(R.string.speaker_phone),
getString(R.string.speaker_phone_help))
}
binding.AudioModulesTitle.setOnClickListener {
Utils.alertView(this, getString(R.string.audio_modules_title),
getString(R.string.audio_modules_help))

View File

@ -682,6 +682,8 @@ class BaresipService: Service() {
break
stopMediaPlayer()
setCallVolume()
if (speakerPhone && !Utils.isSpeakerPhoneOn(am))
Utils.toggleSpeakerPhone(ContextCompat.getMainExecutor(this), am)
proximitySensing(true)
return
}
@ -728,22 +730,23 @@ class BaresipService: Service() {
ua.account.missedCalls = true
}
return
}
Log.d(TAG, "Incoming call $uap/$callp/$peerUri")
Call(callp, ua, peerUri, "in", "incoming", Utils.dtmfWatcher(callp)).add()
if (speakerPhone && !Utils.isSpeakerPhoneOn(am))
Utils.toggleSpeakerPhone(ContextCompat.getMainExecutor(this), am)
if (ua.account.answerMode == Api.ANSWERMODE_MANUAL) {
Log.d(TAG, "CurrentInterruptionFilter ${nm.currentInterruptionFilter}")
if (nm.currentInterruptionFilter <= NotificationManager.INTERRUPTION_FILTER_ALL)
startRinging()
} else {
Log.d(TAG, "Incoming call $uap/$callp/$peerUri")
Call(callp, ua, peerUri, "in", "incoming", Utils.dtmfWatcher(callp)).add()
if (ua.account.answerMode == Api.ANSWERMODE_MANUAL) {
Log.d(TAG, "CurrentInterruptionFilter ${nm.currentInterruptionFilter}")
if (nm.currentInterruptionFilter <= NotificationManager.INTERRUPTION_FILTER_ALL)
startRinging()
} else {
val newIntent = Intent(this, MainActivity::class.java)
newIntent.flags = Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP or
Intent.FLAG_ACTIVITY_NEW_TASK
newIntent.putExtra("action", "call answer")
newIntent.putExtra("callp", callp)
startActivity(newIntent)
return
}
val newIntent = Intent(this, MainActivity::class.java)
newIntent.flags = Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP or
Intent.FLAG_ACTIVITY_NEW_TASK
newIntent.putExtra("action", "call answer")
newIntent.putExtra("callp", callp)
startActivity(newIntent)
return
}
if (!Utils.isVisible()) {
val piFlags = PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
@ -1558,6 +1561,7 @@ class BaresipService: Service() {
var isConfigInitialized = false
var libraryLoaded = false
var callVolume = 0
var speakerPhone = false
var audioDelay = if (VERSION.SDK_INT < 31) 1500L else 500L
var dynDns = false
var filesPath = ""

View File

@ -137,6 +137,14 @@ object Config {
config = "${config}call_volume ${BaresipService.callVolume}\n"
}
val speakerPhone = previousVariable("speaker_phone")
if (speakerPhone != "") {
config = "${config}speaker_phone $speakerPhone\n"
BaresipService.speakerPhone = speakerPhone == "yes"
} else {
config = "${config}speaker_phone no\n"
}
val previousModules = previousVariables("module")
for (module in AudioActivity.audioModules)
if ("${module}.so" in previousModules)

View File

@ -40,6 +40,31 @@
</Spinner>
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="12dp" >
<TextView
android:id="@+id/SpeakerPhoneTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_toStartOf="@id/SpeakerPhone"
android:textSize="18sp"
android:text="@string/speaker_phone" >
</TextView>
<CheckBox
android:id="@+id/SpeakerPhone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_gravity="end"
android:checked="false" >
</CheckBox>
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"

View File

@ -356,6 +356,10 @@
</string>
<string name="audio">Audio</string>
<string name="audio_settings">Audio-asetukset</string>
<string name="speaker_phone">Kaiutin</string>
<string name="speaker_phone_help">Jos merkitty, kaiutin kytketään sutomaattisesti päälle
kun puhelu alkaa.
</string>
<string name="audio_modules_title">Audio-modulit</string>
<string name="audio_modules_help">Merkittyjen modulien tarjoamat audio-koodekit ovat tilien
käytettävissä.

View File

@ -334,6 +334,9 @@
Download folder.</string>
<string name="audio">Audio</string>
<string name="audio_settings">Audio Settings</string>
<string name="speaker_phone">Speaker Phone</string>
<string name="speaker_phone_help">If checked, speaker phone is turned automatically on
when call starts.</string>
<string name="audio_modules_title">Audio Modules</string>
<string name="audio_modules_help">Audio codecs provided by the checked modules are
available for use by the accounts.</string>