Skip to content

Commit 0f43476

Browse files
committed
Enable proximity sensor by default
1 parent b7a551c commit 0f43476

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

features/call/impl/src/main/kotlin/io/element/android/features/call/impl/ui/ElementCallActivity.kt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import android.app.PictureInPictureParams
1212
import android.content.Intent
1313
import android.os.Build
1414
import android.os.Bundle
15+
import android.os.PowerManager
1516
import android.util.Rational
1617
import android.view.WindowManager
1718
import android.webkit.PermissionRequest
@@ -28,6 +29,7 @@ import androidx.compose.runtime.mutableStateOf
2829
import androidx.compose.runtime.rememberUpdatedState
2930
import androidx.core.app.PictureInPictureModeChangedInfo
3031
import androidx.core.content.IntentCompat
32+
import androidx.core.content.getSystemService
3133
import androidx.core.util.Consumer
3234
import androidx.lifecycle.Lifecycle
3335
import io.element.android.features.call.api.CallType
@@ -76,6 +78,12 @@ class ElementCallActivity :
7678

7779
private var eventSink: ((CallScreenEvents) -> Unit)? = null
7880

81+
private val proximitySensorWakeLock: PowerManager.WakeLock? by lazy {
82+
getSystemService<PowerManager>()
83+
?.takeIf { it.isWakeLockLevelSupported(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK) }
84+
?.newWakeLock(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK, "$packageName:ProximitySensorCallWakeLock")
85+
}
86+
7987
override fun onCreate(savedInstanceState: Bundle?) {
8088
super.onCreate(savedInstanceState)
8189

@@ -89,6 +97,13 @@ class ElementCallActivity :
8997
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
9098
)
9199

100+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
101+
setShowWhenLocked(true)
102+
} else {
103+
@Suppress("DEPRECATION")
104+
window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED)
105+
}
106+
92107
setCallType(intent)
93108
// If presenter is not created at this point, it means we have no call to display, the Activity is finishing, so return early
94109
if (!::presenter.isInitialized) {
@@ -125,6 +140,26 @@ class ElementCallActivity :
125140
}
126141
}
127142

143+
override fun onStart() {
144+
super.onStart()
145+
146+
if (proximitySensorWakeLock?.isHeld == false) {
147+
val proximitySensorEnabled = proximitySensorWakeLock?.acquire()
148+
Timber.d("Proximity sensor wake lock acquired: $proximitySensorEnabled")
149+
} else {
150+
Timber.d("Proximity sensor wakelock does not exist or is already held")
151+
}
152+
}
153+
154+
override fun onStop() {
155+
super.onStop()
156+
157+
if (proximitySensorWakeLock?.isHeld == true) {
158+
proximitySensorWakeLock?.release()
159+
Timber.d("Proximity sensor wake lock released")
160+
}
161+
}
162+
128163
private fun setCallIsActive() {
129164
audioFocus.requestAudioFocus(
130165
requester = AudioFocusRequester.ElementCall,

0 commit comments

Comments
 (0)