Skip to content

Commit a081f63

Browse files
committed
fix: rework when full-screen intent is used
1 parent b11a7e5 commit a081f63

File tree

2 files changed

+34
-11
lines changed

2 files changed

+34
-11
lines changed

app/src/main/kotlin/org/fossify/phone/extensions/Context.kt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package org.fossify.phone.extensions
22

33
import android.annotation.SuppressLint
4+
import android.app.KeyguardManager
45
import android.content.Context
6+
import android.content.Context.KEYGUARD_SERVICE
57
import android.content.Intent
68
import android.media.AudioManager
79
import android.net.Uri
@@ -14,9 +16,14 @@ import org.fossify.phone.models.SIMAccount
1416

1517
val Context.config: Config get() = Config.newInstance(applicationContext)
1618

17-
val Context.audioManager: AudioManager get() = getSystemService(Context.AUDIO_SERVICE) as AudioManager
19+
val Context.audioManager: AudioManager
20+
get() = getSystemService(Context.AUDIO_SERVICE) as AudioManager
1821

19-
val Context.powerManager: PowerManager get() = getSystemService(Context.POWER_SERVICE) as PowerManager
22+
val Context.powerManager: PowerManager
23+
get() = getSystemService(Context.POWER_SERVICE) as PowerManager
24+
25+
val Context.keyguardManager: KeyguardManager
26+
get() = getSystemService(KEYGUARD_SERVICE) as KeyguardManager
2027

2128
@SuppressLint("MissingPermission")
2229
fun Context.getAvailableSIMCardLabels(): List<SIMAccount> {

app/src/main/kotlin/org/fossify/phone/services/CallService.kt

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
package org.fossify.phone.services
22

3-
import android.app.KeyguardManager
4-
import android.content.Context
53
import android.telecom.Call
64
import android.telecom.CallAudioState
75
import android.telecom.InCallService
6+
import org.fossify.commons.extensions.canUseFullScreenIntent
7+
import org.fossify.commons.extensions.hasPermission
8+
import org.fossify.commons.helpers.PERMISSION_POST_NOTIFICATIONS
89
import org.fossify.phone.activities.CallActivity
910
import org.fossify.phone.extensions.config
1011
import org.fossify.phone.extensions.isOutgoing
12+
import org.fossify.phone.extensions.keyguardManager
1113
import org.fossify.phone.extensions.powerManager
1214
import org.fossify.phone.helpers.CallManager
1315
import org.fossify.phone.helpers.CallNotificationManager
@@ -35,17 +37,31 @@ class CallService : InCallService() {
3537
CallManager.inCallService = this
3638
call.registerCallback(callListener)
3739

38-
val isScreenLocked = (getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager).isDeviceLocked
39-
if (!powerManager.isInteractive || call.isOutgoing() || isScreenLocked || config.alwaysShowFullscreen) {
40+
// Incoming/Outgoing (locked): high priority (FSI)
41+
// Incoming (unlocked): if user opted in, low priority ➜ manual activity start, otherwise high priority (FSI)
42+
// Outgoing (unlocked): low priority ➜ manual activity start
43+
val isIncoming = !call.isOutgoing()
44+
val isDeviceLocked = !powerManager.isInteractive || keyguardManager.isDeviceLocked
45+
val lowPriority = when {
46+
isIncoming && isDeviceLocked -> false
47+
!isIncoming && isDeviceLocked -> false
48+
isIncoming && !isDeviceLocked -> config.alwaysShowFullscreen
49+
else -> true
50+
}
51+
52+
callNotificationManager.setupNotification(lowPriority)
53+
if (
54+
lowPriority
55+
|| !hasPermission(PERMISSION_POST_NOTIFICATIONS)
56+
|| !canUseFullScreenIntent()
57+
) {
4058
try {
41-
callNotificationManager.setupNotification(true)
4259
startActivity(CallActivity.getStartIntent(this))
43-
} catch (e: Exception) {
44-
// seems like startActivity can throw AndroidRuntimeException and ActivityNotFoundException, not yet sure when and why, lets show a notification
60+
} catch (_: Exception) {
61+
// seems like startActivity can throw AndroidRuntimeException and
62+
// ActivityNotFoundException, not yet sure when and why, lets show a notification
4563
callNotificationManager.setupNotification()
4664
}
47-
} else {
48-
callNotificationManager.setupNotification()
4965
}
5066
}
5167

0 commit comments

Comments
 (0)