From ef1133ee980d2e931845d30d21cc22fb013a516a Mon Sep 17 00:00:00 2001 From: Stanislav Dmitrenko <7953703+avently@users.noreply.github.com> Date: Tue, 29 Nov 2022 18:53:47 +0300 Subject: [PATCH] android: fix full screen call notification (#1466) * android: Closing call means canceling notification too * show full screen call when screen is off OR locked * make notification non-silent and set category * remove call notification category Co-authored-by: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com> --- .../java/chat/simplex/app/model/NtfManager.kt | 19 +++++++++++++++---- .../app/views/call/IncomingCallActivity.kt | 5 ++++- .../app/views/call/IncomingCallAlertView.kt | 5 ++++- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/apps/android/app/src/main/java/chat/simplex/app/model/NtfManager.kt b/apps/android/app/src/main/java/chat/simplex/app/model/NtfManager.kt index 834f0ae19d..596a2f8cde 100644 --- a/apps/android/app/src/main/java/chat/simplex/app/model/NtfManager.kt +++ b/apps/android/app/src/main/java/chat/simplex/app/model/NtfManager.kt @@ -3,9 +3,11 @@ package chat.simplex.app.model import android.app.* import android.content.* import android.graphics.BitmapFactory +import android.hardware.display.DisplayManager import android.media.AudioAttributes import android.net.Uri import android.util.Log +import android.view.Display import androidx.core.app.NotificationCompat import androidx.core.app.NotificationManagerCompat import chat.simplex.app.* @@ -151,19 +153,28 @@ class NtfManager(val context: Context, private val appPreferences: AppPreference } fun notifyCallInvitation(invitation: RcvCallInvitation) { - if (isAppOnForeground(context)) return + val inForeground = isAppOnForeground(context) + val keyguardManager = getKeyguardManager(context) + Log.d(TAG, + "notifyCallInvitation pre-requests: device locked ${keyguardManager.isDeviceLocked}, " + + "keyguard locked ${keyguardManager.isKeyguardLocked}, " + + "callOnLockScreen ${appPreferences.callOnLockScreen.get()}, " + + "inForeground $inForeground" + ) + if (inForeground) return val contactId = invitation.contact.id Log.d(TAG, "notifyCallInvitation $contactId") - val keyguardManager = getKeyguardManager(context) val image = invitation.contact.image + val displayManager = context.getSystemService(Context.DISPLAY_SERVICE) as DisplayManager + val screenOff = displayManager.displays.all { it.state != Display.STATE_ON } var ntfBuilder = - if (keyguardManager.isDeviceLocked && appPreferences.callOnLockScreen.get() != CallOnLockScreen.DISABLE) { + if ((keyguardManager.isKeyguardLocked || screenOff) && appPreferences.callOnLockScreen.get() != CallOnLockScreen.DISABLE) { val fullScreenIntent = Intent(context, IncomingCallActivity::class.java) val fullScreenPendingIntent = PendingIntent.getActivity(context, 0, fullScreenIntent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE) NotificationCompat.Builder(context, LockScreenCallChannel) .setFullScreenIntent(fullScreenPendingIntent, true) .setVisibility(NotificationCompat.VISIBILITY_PUBLIC) - .setSilent(true) + .setSilent(false) } else { val soundUri = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + context.packageName + "/" + R.raw.ring_once) NotificationCompat.Builder(context, CallChannel) diff --git a/apps/android/app/src/main/java/chat/simplex/app/views/call/IncomingCallActivity.kt b/apps/android/app/src/main/java/chat/simplex/app/views/call/IncomingCallActivity.kt index 283b6be684..7177fde2f1 100644 --- a/apps/android/app/src/main/java/chat/simplex/app/views/call/IncomingCallActivity.kt +++ b/apps/android/app/src/main/java/chat/simplex/app/views/call/IncomingCallActivity.kt @@ -123,7 +123,10 @@ fun IncomingCallLockScreenAlert(invitation: RcvCallInvitation, chatModel: ChatMo invitation, callOnLockScreen, rejectCall = { cm.endCall(invitation = invitation) }, - ignoreCall = { chatModel.activeCallInvitation.value = null }, + ignoreCall = { + chatModel.activeCallInvitation.value = null + chatModel.controller.ntfManager.cancelCallNotification() + }, acceptCall = { cm.acceptIncomingCall(invitation = invitation) }, openApp = { SoundPlayer.shared.stop() diff --git a/apps/android/app/src/main/java/chat/simplex/app/views/call/IncomingCallAlertView.kt b/apps/android/app/src/main/java/chat/simplex/app/views/call/IncomingCallAlertView.kt index 455fc915f3..a32cce845d 100644 --- a/apps/android/app/src/main/java/chat/simplex/app/views/call/IncomingCallAlertView.kt +++ b/apps/android/app/src/main/java/chat/simplex/app/views/call/IncomingCallAlertView.kt @@ -33,7 +33,10 @@ fun IncomingCallAlertView(invitation: RcvCallInvitation, chatModel: ChatModel) { IncomingCallAlertLayout( invitation, rejectCall = { cm.endCall(invitation = invitation) }, - ignoreCall = { chatModel.activeCallInvitation.value = null }, + ignoreCall = { + chatModel.activeCallInvitation.value = null + chatModel.controller.ntfManager.cancelCallNotification() + }, acceptCall = { cm.acceptIncomingCall(invitation = invitation) } ) }