diff --git a/app/build.gradle b/app/build.gradle index cc86c892..9a2f7fad 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -8,8 +8,8 @@ android { applicationId = 'com.tutpro.baresip' minSdkVersion 21 targetSdkVersion 28 - versionCode = 55 - versionName = '7.0.0' + versionCode = 56 + versionName = '7.1.0' externalNativeBuild { cmake { cFlags '-DHAVE_INTTYPES_H' diff --git a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt index 9f2670c9..bdc0ab1b 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt @@ -25,6 +25,7 @@ import java.io.File import java.nio.charset.StandardCharsets import java.io.InputStream import java.util.* +import kotlin.math.roundToInt class BaresipService: Service() { @@ -41,6 +42,7 @@ class BaresipService: Service() { internal var filesPath = "" internal var audioFocusRequest: AudioFocusRequest? = null internal var audioFocused = false + internal var origCallVolume = 0 override fun onCreate() { @@ -159,11 +161,16 @@ class BaresipService: Service() { contents = "prefer_ipv6 no\n${contents}" write = true } + if (!contents.contains("call_volume")) { + contents = "${contents}call_volume 0\n" + write = true + } else { + callVolume = Utils.getNameValue(contents, "call_volume")[0].toInt() + } if (write) { Log.d(LOG_TAG, "Writing '$contents'") Utils.putFileContents(file, contents) } - } } } @@ -428,6 +435,13 @@ class BaresipService: Service() { am.mode = AudioManager.MODE_IN_COMMUNICATION requestAudioFocus(AudioManager.STREAM_VOICE_CALL) } + if (callVolume != 0) { + origCallVolume = am.getStreamMaxVolume(am.mode) + am.setStreamVolume(am.mode, + (callVolume * 0.1 * am.getStreamMaxVolume(am.mode)).roundToInt(), + 0) + } + Log.d(LOG_TAG, "Call volume of stream ${am.mode} is ${am.getStreamVolume(am.mode)}") } "call verified", "call secure" -> { val call = Call.find(callp) @@ -507,6 +521,11 @@ class BaresipService: Service() { } if (Call.calls().size == 0) { abandonAudioFocus() + if (origCallVolume != 0) { + am.setStreamVolume(am.mode, origCallVolume, 0) + origCallVolume = 0 + } + Log.d(LOG_TAG, "Call volume of stream ${am.mode} is ${am.getStreamVolume(am.mode)}") am.mode = AudioManager.MODE_NORMAL if (am.isSpeakerphoneOn) am.isSpeakerphoneOn = false speakerPhone = false @@ -786,6 +805,7 @@ class BaresipService: Service() { var libraryLoaded = false var isServiceClean = false var speakerPhone = false + var callVolume = 0 var uas = ArrayList() var status = ArrayList() diff --git a/app/src/main/kotlin/com/tutpro/baresip/ConfigActivity.kt b/app/src/main/kotlin/com/tutpro/baresip/ConfigActivity.kt index 0128b9cd..2404277d 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/ConfigActivity.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/ConfigActivity.kt @@ -28,6 +28,7 @@ class ConfigActivity : AppCompatActivity() { private var oldOpusBitrate = "" private var oldIceMode = "" private var oldLogLevel = "" + private var callVolume = BaresipService.callVolume private var save = false private var restart = false private var config = "" @@ -72,6 +73,27 @@ class ConfigActivity : AppCompatActivity() { oldIceMode = if (imCv.size == 0) "full" else imCv[0] iceLite.isChecked = oldIceMode == "lite" + val callVolSpinner = findViewById(R.id.VolumeSpinner) as Spinner + val volKeys = arrayListOf("None", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10") + val volVals = arrayListOf(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10) + val curVal = callVolume + val curKey = volKeys[curVal] + volKeys.removeAt(curVal) + volVals.removeAt(curVal) + volKeys.add(0, curKey) + volVals.add(0, curVal) + val callVolAdapter = ArrayAdapter(this,android.R.layout.simple_spinner_item, + volKeys) + callVolAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) + callVolSpinner.adapter = callVolAdapter + callVolSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { + override fun onItemSelected(parent: AdapterView<*>, view: View, position: Int, id: Long) { + callVolume = volVals[volKeys.indexOf(parent.selectedItem.toString())] + } + override fun onNothingSelected(parent: AdapterView<*>) { + } + } + debug = findViewById(R.id.Debug) as CheckBox val dbCv = Utils.getNameValue(config, "log_level") if (dbCv.size == 0) @@ -150,6 +172,13 @@ class ConfigActivity : AppCompatActivity() { restart = true } + if (BaresipService.callVolume != callVolume) { + BaresipService.callVolume = callVolume + config = Utils.removeLinesStartingWithName(config, "call_volume") + config += "\ncall_volume $callVolume\n" + save = true + } + var logLevelString = "2" if (debug.isChecked) logLevelString = "0" if (oldLogLevel != logLevelString) { @@ -212,6 +241,9 @@ class ConfigActivity : AppCompatActivity() { findViewById(R.id.IceLiteTitle) as TextView-> { Utils.alertView(this, "ICE Lite Mode", getString(R.string.iceLite)) } + findViewById(R.id.VolumeTitle) as TextView-> { + Utils.alertView(this, "Call Volume", getString(R.string.callVolume)) + } findViewById(R.id.DebugTitle) as TextView-> { Utils.alertView(this, "Debug", getString(R.string.debug)) } diff --git a/app/src/main/res/layout/activity_config.xml b/app/src/main/res/layout/activity_config.xml index 64fbcc87..430cefb6 100644 --- a/app/src/main/res/layout/activity_config.xml +++ b/app/src/main/res/layout/activity_config.xml @@ -13,12 +13,12 @@ android:paddingLeft="16dp" android:paddingRight="16dp" android:paddingTop="16dp" - android:paddingBottom="24dp" android:focusableInTouchMode="true" > + + + + + + + Average maximum bit rate used by Opus audio stream. Valid value are 6000-510000. Factory default is 28000. If checked, ICE Lite Mode is used. + If set, default call audio volume at scale 1-10. If checked, debug and info level log messages are available in logcat. If checked, configuration is reset to factory default. diff --git a/fastlane/metadata/android/en-US/changelogs/7.1.0.txt b/fastlane/metadata/android/en-US/changelogs/7.1.0.txt new file mode 100644 index 00000000..5fdc6738 --- /dev/null +++ b/fastlane/metadata/android/en-US/changelogs/7.1.0.txt @@ -0,0 +1 @@ +- Added 'Default Call Volume' configuration option.