Added abandoning of audio focus request
Improved random color generation
This commit is contained in:
@ -77,7 +77,6 @@ dependencies {
|
||||
implementation(libs.kotlinx.serialization.json)
|
||||
implementation(libs.androidx.activity.ktx)
|
||||
implementation(libs.androidx.fragment.ktx)
|
||||
implementation(libs.androidx.media)
|
||||
implementation(libs.coil.compose)
|
||||
implementation(libs.androidx.navigation.compose)
|
||||
implementation(libs.androidx.navigation.runtime.android)
|
||||
|
||||
@ -54,9 +54,9 @@ class Account(val accp: Long, virtualAor: String? = null) {
|
||||
if (ob != "") {
|
||||
outbound.add(ob)
|
||||
i++
|
||||
} else {
|
||||
break
|
||||
}
|
||||
else
|
||||
break
|
||||
}
|
||||
|
||||
i = 0
|
||||
|
||||
@ -21,6 +21,7 @@ import android.database.ContentObserver
|
||||
import android.graphics.ImageDecoder
|
||||
import android.media.AudioAttributes
|
||||
import android.media.AudioDeviceInfo
|
||||
import android.media.AudioFocusRequest
|
||||
import android.media.AudioManager
|
||||
import android.media.AudioManager.MODE_IN_COMMUNICATION
|
||||
import android.media.AudioManager.MODE_NORMAL
|
||||
@ -1092,6 +1093,8 @@ class BaresipService: Service() {
|
||||
if (call != null) {
|
||||
stopRinging()
|
||||
stopMediaPlayer()
|
||||
if (!Call.inCall())
|
||||
abandonAudioFocus(this)
|
||||
val newCall = call.newCall
|
||||
if (newCall != null) {
|
||||
newCall.onHoldCall = null
|
||||
@ -2495,6 +2498,7 @@ class BaresipService: Service() {
|
||||
}
|
||||
stopRinging()
|
||||
stopMediaPlayer()
|
||||
abandonAudioFocus(this)
|
||||
uas.value = emptyList()
|
||||
uasStatus.value = emptyMap()
|
||||
callHistory.clear()
|
||||
@ -2587,7 +2591,7 @@ class BaresipService: Service() {
|
||||
private var ns: NoiseSuppressor? = null
|
||||
private var recorderSessionId = 0
|
||||
private var btAdapter: BluetoothAdapter? = null
|
||||
private var audioFocusRequest: androidx.media.AudioFocusRequestCompat? = null
|
||||
private var audioFocusRequest: AudioFocusRequest? = null
|
||||
|
||||
var rt: Ringtone? = null
|
||||
|
||||
@ -2630,20 +2634,16 @@ class BaresipService: Service() {
|
||||
return true
|
||||
}
|
||||
val am = ctx.getSystemService(AUDIO_SERVICE) as AudioManager
|
||||
val attributes = androidx.media.AudioAttributesCompat.Builder()
|
||||
.setUsage(androidx.media.AudioAttributesCompat.USAGE_VOICE_COMMUNICATION)
|
||||
.setContentType(androidx.media.AudioAttributesCompat.CONTENT_TYPE_SPEECH)
|
||||
val attributes = AudioAttributes.Builder()
|
||||
.setUsage(AudioAttributes.USAGE_VOICE_COMMUNICATION)
|
||||
.setContentType(AudioAttributes.CONTENT_TYPE_SPEECH)
|
||||
.build()
|
||||
audioFocusRequest =
|
||||
androidx.media.AudioFocusRequestCompat.Builder(androidx.media.AudioManagerCompat.AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE)
|
||||
AudioFocusRequest.Builder(AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE)
|
||||
.setAudioAttributes(attributes)
|
||||
.setOnAudioFocusChangeListener { }
|
||||
.build()
|
||||
if (androidx.media.AudioManagerCompat.requestAudioFocus(
|
||||
am,
|
||||
audioFocusRequest!!
|
||||
) == AudioManager.AUDIOFOCUS_REQUEST_GRANTED
|
||||
) {
|
||||
if (am.requestAudioFocus(audioFocusRequest!!) == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
|
||||
Log.d(TAG, "requestAudioFocus granted")
|
||||
}
|
||||
else {
|
||||
@ -2653,6 +2653,18 @@ class BaresipService: Service() {
|
||||
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 {
|
||||
return if (VERSION.SDK_INT < 31)
|
||||
@Suppress("DEPRECATION")
|
||||
|
||||
@ -12,6 +12,7 @@ import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.content.res.Configuration
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.Color
|
||||
import android.graphics.PorterDuff
|
||||
import android.graphics.PorterDuffXfermode
|
||||
import android.media.AudioAttributes
|
||||
@ -852,9 +853,12 @@ object Utils {
|
||||
}
|
||||
|
||||
fun randomColor(): Int {
|
||||
val rnd = Random()
|
||||
return android.graphics.Color.argb(255, rnd.nextInt(256), rnd.nextInt(256),
|
||||
rnd.nextInt(256))
|
||||
return Color.argb(
|
||||
255,
|
||||
kotlin.random.Random.nextInt(256),
|
||||
kotlin.random.Random.nextInt(256),
|
||||
kotlin.random.Random.nextInt(256)
|
||||
)
|
||||
}
|
||||
|
||||
fun requestDismissKeyguard(activity: Activity) {
|
||||
|
||||
@ -525,7 +525,7 @@
|
||||
<string name="diverted_by_dots">Siirtäjä …</string>
|
||||
<string name="diverted_by">siirtäjä</string>
|
||||
<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="video_call">Videopuhelu</string>
|
||||
<string name="video_request">Videopyyntö</string>
|
||||
|
||||
@ -15,7 +15,6 @@ lifecycleProcess = "2.10.0"
|
||||
lifecycleRuntimeCompose = "2.10.0"
|
||||
lifecycleViewmodelKtx = "2.10.0"
|
||||
material = "1.13.0"
|
||||
media = "1.7.1"
|
||||
navigationCompose = "2.9.8"
|
||||
preferenceKtx = "1.2.1"
|
||||
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-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-media = { module = "androidx.media:media", version.ref = "media" }
|
||||
androidx-navigation-compose = { module = "androidx.navigation:navigation-compose", version.ref = "navigationCompose" }
|
||||
androidx-preference-ktx = { module = "androidx.preference:preference-ktx", version.ref = "preferenceKtx" }
|
||||
androidx-ui = { module = "androidx.compose.ui:ui", version.ref = "ui" }
|
||||
|
||||
Reference in New Issue
Block a user