From 90cf68fd4c4455f2e7abca7ac1a6c1b53df14cc7 Mon Sep 17 00:00:00 2001 From: Mario Danic Date: Mon, 28 Oct 2019 13:35:11 +0100 Subject: [PATCH] Improve call detection Signed-off-by: Mario Danic --- .../nextcloud/talk/utils/DoNotDisturbUtils.kt | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/utils/DoNotDisturbUtils.kt b/app/src/main/java/com/nextcloud/talk/utils/DoNotDisturbUtils.kt index 967962ded..3ec484415 100644 --- a/app/src/main/java/com/nextcloud/talk/utils/DoNotDisturbUtils.kt +++ b/app/src/main/java/com/nextcloud/talk/utils/DoNotDisturbUtils.kt @@ -25,6 +25,7 @@ import android.content.Context import android.media.AudioManager import android.os.Build import android.os.Vibrator +import android.telephony.TelephonyManager import com.nextcloud.talk.application.NextcloudTalkApplication object DoNotDisturbUtils { @@ -62,6 +63,15 @@ object DoNotDisturbUtils { return false } + fun areWeInTelephonyCall(context: Context): Boolean { + val telephonyManager = context.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager + if (telephonyManager.callState != TelephonyManager.CALL_STATE_IDLE) { + return true + } + + return false + } + fun shouldPlaySound(importantConversation: Boolean): Boolean { val context = NextcloudTalkApplication.sharedApplication?.applicationContext @@ -86,7 +96,7 @@ object DoNotDisturbUtils { shouldPlaySound = true } - if (audioManager.mode == AudioManager.MODE_IN_CALL) { + if (areWeInTelephonyCall(context)) { shouldPlaySound = false } @@ -101,9 +111,7 @@ object DoNotDisturbUtils { fun shouldVibrate(vibrate: Boolean): Boolean { val context = NextcloudTalkApplication.sharedApplication?.applicationContext - val audioManager = context?.getSystemService(Context.AUDIO_SERVICE) as AudioManager - - if (audioManager.mode == AudioManager.MODE_IN_CALL) { + if (areWeInTelephonyCall(context!!)) { return false }