From 99081f06dea25201aab4e41b8d8525ec6dd525aa Mon Sep 17 00:00:00 2001 From: Juha Heinanen Date: Thu, 1 Jul 2021 15:55:48 +0300 Subject: [PATCH] Only save/restore STREAM_VOICE_CALL volume --- .../com/tutpro/baresip/BaresipService.kt | 30 ++++++++----------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt index f48b366d..68ea584f 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt @@ -52,7 +52,7 @@ class BaresipService: Service() { internal var rtTimer: Timer? = null private var audioFocusRequest: AudioFocusRequest? = null private var audioFocusUsage = -1 - private var origVolumes = arrayOf(-1, -1, -1, -1) + private var origVolume = -1 private val btAdapter = BluetoothAdapter.getDefaultAdapter() internal var activeNetwork = "" @@ -1050,26 +1050,22 @@ class BaresipService: Service() { } private fun setCallVolume() { - if ((callVolume != 0) && (origVolumes.contentEquals(arrayOf(-1, -1, -1, -1)))) { - for (streamType in listOf(AudioManager.STREAM_VOICE_CALL, AudioManager.STREAM_RING)) { - origVolumes[streamType] = am.getStreamVolume(streamType) - am.setStreamVolume(streamType, - (callVolume * 0.1 * am.getStreamMaxVolume(streamType)).roundToInt(), - 0) - Log.d(TAG, "Orig/new call volume of stream type $streamType is " + - "${origVolumes[streamType]}/${am.getStreamVolume(streamType)}") - } + if (callVolume != 0 && origVolume == -1) { + val streamType = AudioManager.STREAM_VOICE_CALL + origVolume = am.getStreamVolume(streamType) + am.setStreamVolume(streamType, + (callVolume * 0.1 * am.getStreamMaxVolume(streamType)).roundToInt(), + 0) + Log.d(TAG, "Orig/new call volume is $origVolume/${am.getStreamVolume(streamType)}") } } private fun resetCallVolume() { - for (streamType in listOf(AudioManager.STREAM_VOICE_CALL, AudioManager.STREAM_RING)) { - if (origVolumes[streamType] != -1) { - am.setStreamVolume(streamType, origVolumes[streamType], 0) - Log.d(TAG, "Reset volume of stream type $streamType to " + - "${am.getStreamVolume(streamType)}") - origVolumes[streamType] = -1 - } + if (origVolume != -1) { + val streamType = AudioManager.STREAM_VOICE_CALL + am.setStreamVolume(streamType, origVolume, 0) + Log.d(TAG, "Reset volume to ${am.getStreamVolume(streamType)}") + origVolume = -1 } }