Use androidx.lifecycle to check if application is visible
Set audio mode to normal when no calls and main activity is not visible
This commit is contained in:
@@ -56,4 +56,5 @@ dependencies {
|
|||||||
implementation "androidx.exifinterface:exifinterface:1.3.3"
|
implementation "androidx.exifinterface:exifinterface:1.3.3"
|
||||||
implementation "androidx.core:core-ktx:1.6.0"
|
implementation "androidx.core:core-ktx:1.6.0"
|
||||||
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1'
|
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1'
|
||||||
|
implementation "androidx.lifecycle:lifecycle-extensions:2.2.0"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -745,6 +745,10 @@ class BaresipService: Service() {
|
|||||||
}
|
}
|
||||||
Log.d(TAG, "AoR $aor call $callp is closed")
|
Log.d(TAG, "AoR $aor call $callp is closed")
|
||||||
stopRinging()
|
stopRinging()
|
||||||
|
if (isMainVisible)
|
||||||
|
am.mode = AudioManager.MODE_IN_COMMUNICATION
|
||||||
|
else
|
||||||
|
am.mode = AudioManager.MODE_NORMAL
|
||||||
stopMediaPlayer()
|
stopMediaPlayer()
|
||||||
when (ev[2]) {
|
when (ev[2]) {
|
||||||
"busy" ->
|
"busy" ->
|
||||||
@@ -1385,6 +1389,7 @@ class BaresipService: Service() {
|
|||||||
var logLevel = 2
|
var logLevel = 2
|
||||||
var sipTrace = false
|
var sipTrace = false
|
||||||
var callActionUri = ""
|
var callActionUri = ""
|
||||||
|
var isMainVisible = false
|
||||||
|
|
||||||
val uas = ArrayList<UserAgent>()
|
val uas = ArrayList<UserAgent>()
|
||||||
val status = ArrayList<Int>()
|
val status = ArrayList<Int>()
|
||||||
|
|||||||
@@ -795,7 +795,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
// Keep the app in communication mode in order to avoid audio delay when the mode changes
|
// Keep the app in communication mode in order to avoid audio delay when the mode changes
|
||||||
if (am.mode != AudioManager.MODE_RINGTONE && am.mode != AudioManager.MODE_IN_COMMUNICATION)
|
if (am.mode != AudioManager.MODE_RINGTONE && am.mode != AudioManager.MODE_IN_COMMUNICATION)
|
||||||
am.mode = AudioManager.MODE_IN_COMMUNICATION
|
am.mode = AudioManager.MODE_IN_COMMUNICATION
|
||||||
visible = true
|
BaresipService.isMainVisible = true
|
||||||
when (resumeAction) {
|
when (resumeAction) {
|
||||||
"call show" ->
|
"call show" ->
|
||||||
handleServiceEvent("call incoming",
|
handleServiceEvent("call incoming",
|
||||||
@@ -849,7 +849,9 @@ class MainActivity : AppCompatActivity() {
|
|||||||
override fun onPause() {
|
override fun onPause() {
|
||||||
Log.d(TAG, "Main onPause")
|
Log.d(TAG, "Main onPause")
|
||||||
Utils.addActivity("main")
|
Utils.addActivity("main")
|
||||||
visible = false
|
if (Call.calls().size == 0)
|
||||||
|
am.mode = AudioManager.MODE_NORMAL
|
||||||
|
BaresipService.isMainVisible = false
|
||||||
saveCallUri()
|
saveCallUri()
|
||||||
super.onPause()
|
super.onPause()
|
||||||
}
|
}
|
||||||
@@ -971,7 +973,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
Api.ua_hangup(uap, callp, 486, "Busy Here")
|
Api.ua_hangup(uap, callp, 486, "Busy Here")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (visible) {
|
if (BaresipService.isMainVisible) {
|
||||||
if (aor != aorSpinner.tag)
|
if (aor != aorSpinner.tag)
|
||||||
spinToAor(aor)
|
spinToAor(aor)
|
||||||
showCall(ua)
|
showCall(ua)
|
||||||
@@ -1862,10 +1864,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
var accountRequest: ActivityResultLauncher<Intent>? = null
|
var accountRequest: ActivityResultLauncher<Intent>? = null
|
||||||
|
|
||||||
var visible = false
|
|
||||||
var activityAor = ""
|
var activityAor = ""
|
||||||
|
|
||||||
// <aor, password> of those accounts that have auth username without auth password
|
// <aor, password> of those accounts that have auth username without auth password
|
||||||
val aorPasswords = mutableMapOf<String, String>()
|
val aorPasswords = mutableMapOf<String, String>()
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package com.tutpro.baresip
|
package com.tutpro.baresip
|
||||||
|
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.app.ActivityManager
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
@@ -25,6 +24,8 @@ import androidx.annotation.RequiresApi
|
|||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.core.app.ActivityCompat
|
import androidx.core.app.ActivityCompat
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
|
import androidx.lifecycle.Lifecycle
|
||||||
|
import androidx.lifecycle.ProcessLifecycleOwner
|
||||||
import java.io.*
|
import java.io.*
|
||||||
import java.lang.reflect.Method
|
import java.lang.reflect.Method
|
||||||
import java.security.SecureRandom
|
import java.security.SecureRandom
|
||||||
@@ -295,9 +296,7 @@ object Utils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun isVisible(): Boolean {
|
fun isVisible(): Boolean {
|
||||||
val appProcessInfo = ActivityManager.RunningAppProcessInfo()
|
return ProcessLifecycleOwner.get().lifecycle.currentState.isAtLeast(Lifecycle.State.STARTED)
|
||||||
ActivityManager.getMyMemoryState(appProcessInfo)
|
|
||||||
return appProcessInfo.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isHotSpotOn(wm: WifiManager): Boolean {
|
fun isHotSpotOn(wm: WifiManager): Boolean {
|
||||||
|
|||||||
Reference in New Issue
Block a user