|
1 | 1 | package org.fossify.phone.services |
2 | 2 |
|
3 | | -import android.app.KeyguardManager |
4 | | -import android.content.Context |
5 | 3 | import android.telecom.Call |
6 | 4 | import android.telecom.CallAudioState |
7 | 5 | 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 |
8 | 9 | import org.fossify.phone.activities.CallActivity |
9 | 10 | import org.fossify.phone.extensions.config |
10 | 11 | import org.fossify.phone.extensions.isOutgoing |
| 12 | +import org.fossify.phone.extensions.keyguardManager |
11 | 13 | import org.fossify.phone.extensions.powerManager |
12 | 14 | import org.fossify.phone.helpers.CallManager |
13 | 15 | import org.fossify.phone.helpers.CallNotificationManager |
@@ -35,17 +37,31 @@ class CallService : InCallService() { |
35 | 37 | CallManager.inCallService = this |
36 | 38 | call.registerCallback(callListener) |
37 | 39 |
|
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 | + ) { |
40 | 58 | try { |
41 | | - callNotificationManager.setupNotification(true) |
42 | 59 | 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 |
45 | 63 | callNotificationManager.setupNotification() |
46 | 64 | } |
47 | | - } else { |
48 | | - callNotificationManager.setupNotification() |
49 | 65 | } |
50 | 66 | } |
51 | 67 |
|
|
0 commit comments