Added abandoning of audio focus request

Improved random color generation
This commit is contained in:
Juha Heinanen
2026-05-15 16:20:13 +03:00
parent 4a3408bc30
commit 8afc84adf3
6 changed files with 32 additions and 19 deletions

View File

@ -77,7 +77,6 @@ dependencies {
implementation(libs.kotlinx.serialization.json) implementation(libs.kotlinx.serialization.json)
implementation(libs.androidx.activity.ktx) implementation(libs.androidx.activity.ktx)
implementation(libs.androidx.fragment.ktx) implementation(libs.androidx.fragment.ktx)
implementation(libs.androidx.media)
implementation(libs.coil.compose) implementation(libs.coil.compose)
implementation(libs.androidx.navigation.compose) implementation(libs.androidx.navigation.compose)
implementation(libs.androidx.navigation.runtime.android) implementation(libs.androidx.navigation.runtime.android)

View File

@ -54,9 +54,9 @@ class Account(val accp: Long, virtualAor: String? = null) {
if (ob != "") { if (ob != "") {
outbound.add(ob) outbound.add(ob)
i++ i++
} else {
break
} }
else
break
} }
i = 0 i = 0

View File

@ -21,6 +21,7 @@ import android.database.ContentObserver
import android.graphics.ImageDecoder import android.graphics.ImageDecoder
import android.media.AudioAttributes import android.media.AudioAttributes
import android.media.AudioDeviceInfo import android.media.AudioDeviceInfo
import android.media.AudioFocusRequest
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.AudioManager.MODE_NORMAL
@ -1092,6 +1093,8 @@ class BaresipService: Service() {
if (call != null) { if (call != null) {
stopRinging() stopRinging()
stopMediaPlayer() stopMediaPlayer()
if (!Call.inCall())
abandonAudioFocus(this)
val newCall = call.newCall val newCall = call.newCall
if (newCall != null) { if (newCall != null) {
newCall.onHoldCall = null newCall.onHoldCall = null
@ -2495,6 +2498,7 @@ class BaresipService: Service() {
} }
stopRinging() stopRinging()
stopMediaPlayer() stopMediaPlayer()
abandonAudioFocus(this)
uas.value = emptyList() uas.value = emptyList()
uasStatus.value = emptyMap() uasStatus.value = emptyMap()
callHistory.clear() callHistory.clear()
@ -2587,7 +2591,7 @@ class BaresipService: Service() {
private var ns: NoiseSuppressor? = null private var ns: NoiseSuppressor? = null
private var recorderSessionId = 0 private var recorderSessionId = 0
private var btAdapter: BluetoothAdapter? = null private var btAdapter: BluetoothAdapter? = null
private var audioFocusRequest: androidx.media.AudioFocusRequestCompat? = null private var audioFocusRequest: AudioFocusRequest? = null
var rt: Ringtone? = null var rt: Ringtone? = null
@ -2630,20 +2634,16 @@ class BaresipService: Service() {
return true return true
} }
val am = ctx.getSystemService(AUDIO_SERVICE) as AudioManager val am = ctx.getSystemService(AUDIO_SERVICE) as AudioManager
val attributes = androidx.media.AudioAttributesCompat.Builder() val attributes = AudioAttributes.Builder()
.setUsage(androidx.media.AudioAttributesCompat.USAGE_VOICE_COMMUNICATION) .setUsage(AudioAttributes.USAGE_VOICE_COMMUNICATION)
.setContentType(androidx.media.AudioAttributesCompat.CONTENT_TYPE_SPEECH) .setContentType(AudioAttributes.CONTENT_TYPE_SPEECH)
.build() .build()
audioFocusRequest = audioFocusRequest =
androidx.media.AudioFocusRequestCompat.Builder(androidx.media.AudioManagerCompat.AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE) AudioFocusRequest.Builder(AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE)
.setAudioAttributes(attributes) .setAudioAttributes(attributes)
.setOnAudioFocusChangeListener { } .setOnAudioFocusChangeListener { }
.build() .build()
if (androidx.media.AudioManagerCompat.requestAudioFocus( if (am.requestAudioFocus(audioFocusRequest!!) == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
am,
audioFocusRequest!!
) == AudioManager.AUDIOFOCUS_REQUEST_GRANTED
) {
Log.d(TAG, "requestAudioFocus granted") Log.d(TAG, "requestAudioFocus granted")
} }
else { else {
@ -2653,6 +2653,18 @@ class BaresipService: Service() {
return audioFocusRequest != null return audioFocusRequest != null
} }
fun abandonAudioFocus(ctx: Context) {
if (audioFocusRequest != null) {
Log.d(TAG, "Abandoning audio focus")
val am = ctx.getSystemService(AUDIO_SERVICE) as AudioManager
if (am.abandonAudioFocusRequest(audioFocusRequest!!) == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
audioFocusRequest = null
} else {
Log.e(TAG, "Failed to abandon audio focus")
}
}
}
private fun isBluetoothScoOn(am: AudioManager): Boolean { private fun isBluetoothScoOn(am: AudioManager): Boolean {
return if (VERSION.SDK_INT < 31) return if (VERSION.SDK_INT < 31)
@Suppress("DEPRECATION") @Suppress("DEPRECATION")

View File

@ -12,6 +12,7 @@ import android.content.Intent
import android.content.pm.PackageManager import android.content.pm.PackageManager
import android.content.res.Configuration import android.content.res.Configuration
import android.graphics.Bitmap import android.graphics.Bitmap
import android.graphics.Color
import android.graphics.PorterDuff import android.graphics.PorterDuff
import android.graphics.PorterDuffXfermode import android.graphics.PorterDuffXfermode
import android.media.AudioAttributes import android.media.AudioAttributes
@ -852,9 +853,12 @@ object Utils {
} }
fun randomColor(): Int { fun randomColor(): Int {
val rnd = Random() return Color.argb(
return android.graphics.Color.argb(255, rnd.nextInt(256), rnd.nextInt(256), 255,
rnd.nextInt(256)) kotlin.random.Random.nextInt(256),
kotlin.random.Random.nextInt(256),
kotlin.random.Random.nextInt(256)
)
} }
fun requestDismissKeyguard(activity: Activity) { fun requestDismissKeyguard(activity: Activity) {

View File

@ -525,7 +525,7 @@
<string name="diverted_by_dots">Siirtäjä …</string> <string name="diverted_by_dots">Siirtäjä …</string>
<string name="diverted_by">siirtäjä</string> <string name="diverted_by">siirtäjä</string>
<string name="no_telephony_provider">Tilille \'%1$s\' ei ole konfiguroitu puhelinpalvelun <string name="no_telephony_provider">Tilille \'%1$s\' ei ole konfiguroitu puhelinpalvelun
tarjoajaa</string> tarjoajaa</string>log
<string name="no_telephone_number">Mobiilipuhelu voidaan tehdä vain puhelinnumeroon</string> <string name="no_telephone_number">Mobiilipuhelu voidaan tehdä vain puhelinnumeroon</string>
<string name="video_call">Videopuhelu</string> <string name="video_call">Videopuhelu</string>
<string name="video_request">Videopyyntö</string> <string name="video_request">Videopyyntö</string>

View File

@ -15,7 +15,6 @@ lifecycleProcess = "2.10.0"
lifecycleRuntimeCompose = "2.10.0" lifecycleRuntimeCompose = "2.10.0"
lifecycleViewmodelKtx = "2.10.0" lifecycleViewmodelKtx = "2.10.0"
material = "1.13.0" material = "1.13.0"
media = "1.7.1"
navigationCompose = "2.9.8" navigationCompose = "2.9.8"
preferenceKtx = "1.2.1" preferenceKtx = "1.2.1"
ui = "1.11.0" ui = "1.11.0"
@ -37,7 +36,6 @@ androidx-fragment-ktx = { module = "androidx.fragment:fragment-ktx", version.ref
androidx-lifecycle-process = { group = "androidx.lifecycle", name = "lifecycle-process", version.ref = "lifecycleProcess" } androidx-lifecycle-process = { group = "androidx.lifecycle", name = "lifecycle-process", version.ref = "lifecycleProcess" }
androidx-lifecycle-runtime-compose = { group = "androidx.lifecycle", name = "lifecycle-runtime-compose", version.ref = "lifecycleRuntimeCompose" } androidx-lifecycle-runtime-compose = { group = "androidx.lifecycle", name = "lifecycle-runtime-compose", version.ref = "lifecycleRuntimeCompose" }
androidx-lifecycle-viewmodel-ktx = { module = "androidx.lifecycle:lifecycle-viewmodel-ktx", version.ref = "lifecycleViewmodelKtx" } androidx-lifecycle-viewmodel-ktx = { module = "androidx.lifecycle:lifecycle-viewmodel-ktx", version.ref = "lifecycleViewmodelKtx" }
androidx-media = { module = "androidx.media:media", version.ref = "media" }
androidx-navigation-compose = { module = "androidx.navigation:navigation-compose", version.ref = "navigationCompose" } androidx-navigation-compose = { module = "androidx.navigation:navigation-compose", version.ref = "navigationCompose" }
androidx-preference-ktx = { module = "androidx.preference:preference-ktx", version.ref = "preferenceKtx" } androidx-preference-ktx = { module = "androidx.preference:preference-ktx", version.ref = "preferenceKtx" }
androidx-ui = { module = "androidx.compose.ui:ui", version.ref = "ui" } androidx-ui = { module = "androidx.compose.ui:ui", version.ref = "ui" }