refactor: in-call check from floret-kit's ring module (calendula#171)

This commit is contained in:
makiolaj committed 2026-11-13 17:35:11 +01:00
1 parent 3200afd97b
commit 3a36b26686
2 files changed
+3 -10

No files matched your search

@@ -5,12 +5,12 @@ import android.app.Application
import android.app.KeyguardManager
import android.content.Context
import android.content.Intent
import android.media.AudioManager
import android.os.Bundle
import android.os.PowerManager
import android.provider.Settings
import de.jeanlucmakiola.clockula.domain.alarm.DirectLaunchFacts
import de.jeanlucmakiola.clockula.domain.alarm.DirectLaunchPolicy
import de.jeanlucmakiola.floret.ring.isInCall
/**
* Opens a ring screen directly where a full-screen intent would only show a
@@ -66,7 +66,7 @@ object ForegroundRingScreen {
screenShowing = screenShowing,
overOtherApps = overOtherApps,
canDrawOverlays = Settings.canDrawOverlays(context),
inCall = inCall(context),
inCall = context.isInCall(),
)
if (!DirectLaunchPolicy.opensDirectly(facts)) return
// A refused start costs nothing: the notification is up either way.
@@ -80,11 +80,4 @@ object ForegroundRingScreen {
private fun phoneInUse(context: Context): Boolean =
context.getSystemService(PowerManager::class.java).isInteractive &&
!context.getSystemService(KeyguardManager::class.java).isKeyguardLocked
/** The audio mode, which needs no phone permission, unlike the telecom APIs. */
private fun inCall(context: Context): Boolean =
when (context.getSystemService(AudioManager::class.java).mode) {
AudioManager.MODE_IN_CALL, AudioManager.MODE_IN_COMMUNICATION, AudioManager.MODE_RINGTONE -> true
else -> false
}
}