mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-01-17 03:18:06 +00:00
Fixed proximity sensor not turned ON when call is answered from notification
This commit is contained in:
parent
d1b8ecb8b8
commit
dd0ca8f67d
2 changed files with 44 additions and 28 deletions
|
|
@ -22,6 +22,7 @@ package org.linphone.core
|
|||
import android.annotation.SuppressLint
|
||||
import android.app.Application
|
||||
import android.content.Context
|
||||
import android.content.Context.POWER_SERVICE
|
||||
import android.content.Intent
|
||||
import android.media.AudioDeviceCallback
|
||||
import android.media.AudioDeviceInfo
|
||||
|
|
@ -29,6 +30,7 @@ import android.media.AudioManager
|
|||
import android.os.Handler
|
||||
import android.os.HandlerThread
|
||||
import android.os.Looper
|
||||
import android.os.PowerManager
|
||||
import android.provider.Settings
|
||||
import android.provider.Settings.SettingNotFoundException
|
||||
import androidx.annotation.AnyThread
|
||||
|
|
@ -130,6 +132,8 @@ class CoreContext
|
|||
|
||||
private var keepAliveServiceStarted = false
|
||||
|
||||
private lateinit var proximityWakeLock: PowerManager.WakeLock
|
||||
|
||||
@SuppressLint("HandlerLeak")
|
||||
private lateinit var coreThread: Handler
|
||||
|
||||
|
|
@ -356,6 +360,15 @@ class CoreContext
|
|||
call.startRecording()
|
||||
}
|
||||
}
|
||||
|
||||
if (core.isInBackground) {
|
||||
// App is in background which means user likely answered the call from the notification
|
||||
// In this case start proximity sensor, otherwise CallActivity will handle it
|
||||
postOnMainThread {
|
||||
Log.i("$TAG App is in background, start proximity sensor")
|
||||
enableProximitySensor(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Call.State.Error -> {
|
||||
|
|
@ -406,6 +419,11 @@ class CoreContext
|
|||
core.videoDevice = frontFacing
|
||||
}
|
||||
}
|
||||
|
||||
postOnMainThread {
|
||||
Log.i("$TAG Releasing proximity sensor if it was enabled")
|
||||
enableProximitySensor(false)
|
||||
}
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
|
|
@ -669,6 +687,16 @@ class CoreContext
|
|||
Log.w("$TAG Keep alive service is enabled but auto start isn't and app is not in foreground, not starting it")
|
||||
}
|
||||
}
|
||||
|
||||
val powerManager = context.getSystemService(POWER_SERVICE) as PowerManager
|
||||
if (!powerManager.isWakeLockLevelSupported(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK)) {
|
||||
Log.w("$TAG PROXIMITY_SCREEN_OFF_WAKE_LOCK isn't supported on this device!")
|
||||
} else {
|
||||
proximityWakeLock = powerManager.newWakeLock(
|
||||
PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK,
|
||||
"${context.packageName};proximity_sensor"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
|
|
@ -1188,4 +1216,17 @@ class CoreContext
|
|||
fun updateCrashlyticsEnabledSetting(enabled: Boolean) {
|
||||
crashlyticsEnabled = enabled
|
||||
}
|
||||
|
||||
@UiThread
|
||||
fun enableProximitySensor(enable: Boolean) {
|
||||
if (::proximityWakeLock.isInitialized) {
|
||||
if (enable && !proximityWakeLock.isHeld) {
|
||||
Log.i("$TAG Acquiring proximity sensor wake lock for 2 hours")
|
||||
proximityWakeLock.acquire(7200 * 1000L) // 2 hours
|
||||
} else if (!enable && proximityWakeLock.isHeld) {
|
||||
Log.i("$TAG Releasing proximity sensor wake lock")
|
||||
proximityWakeLock.release(PowerManager.RELEASE_FLAG_WAIT_FOR_NO_PROXIMITY)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@ import android.content.pm.PackageManager
|
|||
import android.content.res.Resources
|
||||
import android.graphics.Color
|
||||
import android.os.Bundle
|
||||
import android.os.PowerManager
|
||||
import androidx.activity.SystemBarStyle
|
||||
import androidx.activity.enableEdgeToEdge
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
|
|
@ -80,8 +79,6 @@ class CallActivity : GenericActivity() {
|
|||
private lateinit var callsViewModel: CallsViewModel
|
||||
private lateinit var callViewModel: CurrentCallViewModel
|
||||
|
||||
private lateinit var proximityWakeLock: PowerManager.WakeLock
|
||||
|
||||
private var bottomSheetDialog: BottomSheetDialogFragment? = null
|
||||
|
||||
private var isPipSupported = false
|
||||
|
|
@ -150,16 +147,6 @@ class CallActivity : GenericActivity() {
|
|||
WindowInsetsCompat.CONSUMED
|
||||
}
|
||||
|
||||
val powerManager = getSystemService(POWER_SERVICE) as PowerManager
|
||||
if (!powerManager.isWakeLockLevelSupported(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK)) {
|
||||
Log.w("$TAG PROXIMITY_SCREEN_OFF_WAKE_LOCK isn't supported on this device!")
|
||||
}
|
||||
|
||||
proximityWakeLock = powerManager.newWakeLock(
|
||||
PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK,
|
||||
"$packageName;proximity_sensor"
|
||||
)
|
||||
|
||||
lifecycleScope.launch(Dispatchers.Main) {
|
||||
WindowInfoTracker
|
||||
.getOrCreate(this@CallActivity)
|
||||
|
|
@ -269,7 +256,7 @@ class CallActivity : GenericActivity() {
|
|||
|
||||
callViewModel.proximitySensorEnabled.observe(this) { enabled ->
|
||||
Log.i("$TAG ${if (enabled) "Enabling" else "Disabling"} proximity sensor")
|
||||
enableProximitySensor(enabled)
|
||||
coreContext.enableProximitySensor(enabled)
|
||||
}
|
||||
|
||||
callsViewModel.showIncomingCallEvent.observe(this) {
|
||||
|
|
@ -374,7 +361,7 @@ class CallActivity : GenericActivity() {
|
|||
}
|
||||
|
||||
override fun onPause() {
|
||||
enableProximitySensor(false)
|
||||
coreContext.enableProximitySensor(false)
|
||||
|
||||
super.onPause()
|
||||
|
||||
|
|
@ -383,7 +370,7 @@ class CallActivity : GenericActivity() {
|
|||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
enableProximitySensor(false)
|
||||
coreContext.enableProximitySensor(false)
|
||||
|
||||
super.onDestroy()
|
||||
|
||||
|
|
@ -545,16 +532,4 @@ class CallActivity : GenericActivity() {
|
|||
modalBottomSheet.show(supportFragmentManager, ConferenceLayoutMenuDialogFragment.TAG)
|
||||
bottomSheetDialog = modalBottomSheet
|
||||
}
|
||||
|
||||
private fun enableProximitySensor(enable: Boolean) {
|
||||
if (enable && !proximityWakeLock.isHeld) {
|
||||
Log.i("$TAG Acquiring PROXIMITY_SCREEN_OFF_WAKE_LOCK for 2 hours")
|
||||
proximityWakeLock.acquire(7200 * 1000L) // 2 heures
|
||||
} else if (!enable && proximityWakeLock.isHeld) {
|
||||
Log.i(
|
||||
"$TAG Asking to release PROXIMITY_SCREEN_OFF_WAKE_LOCK (next time sensor detects no proximity)"
|
||||
)
|
||||
proximityWakeLock.release(PowerManager.RELEASE_FLAG_WAIT_FOR_NO_PROXIMITY)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue