Reworked a bit how incoming call notification & foreground service interact to fix no incoming call activity on Samsung when in secure folder

This commit is contained in:
Sylvain Berfini 2022-06-23 10:53:26 +02:00
parent a72ee81ec6
commit 5b984de21a
2 changed files with 22 additions and 12 deletions

View file

@ -35,6 +35,7 @@ Group changes to describe their impact on the project, as follows:
- Generated avatars in dark mode
- Call state in self-managed TelecomManager service if it takes longer to be created than the call to be answered
- Show service notification sooner to prevent crash if Core creation takes too long
- Incoming call screen not being showed up to user (& screen staying off) when using app in Samsung secure folder
- One to one chat room creation process waiting indefinitely if chat room already exists
- "Blinking" in some views when presence is being received
- Trying to keep the preferred driver (OpenSLES / AAudio) when switching device

View file

@ -116,12 +116,19 @@ class NotificationsManager(private val context: Context) {
Log.i("[Notifications Manager] Call state changed [$state]")
if (corePreferences.preventInterfaceFromShowingUp) {
Log.w("[Context] We were asked to not show the call notifications")
Log.w("[Notifications Manager] We were asked to not show the call notifications")
return
}
when (call.state) {
Call.State.IncomingEarlyMedia, Call.State.IncomingReceived -> displayIncomingCallNotification(call)
Call.State.IncomingEarlyMedia, Call.State.IncomingReceived -> {
if (service != null) {
Log.i("[Notifications Manager] Service isn't null, show incoming call notification")
displayIncomingCallNotification(call, false)
} else {
Log.w("[Notifications Manager] No service found, waiting for it to start")
}
}
Call.State.End, Call.State.Error -> dismissCallNotification(call)
Call.State.Released -> {
if (LinphoneUtils.isCallLogMissed(call.callLog)) {
@ -341,7 +348,8 @@ class NotificationsManager(private val context: Context) {
val call = coreContext.core.currentCall ?: coreContext.core.calls[0]
when (call.state) {
Call.State.IncomingReceived, Call.State.IncomingEarlyMedia -> {
Log.i("[Notifications Manager] Waiting for call to be in state Connected before creating service notification")
Log.i("[Notifications Manager] Creating incoming call notification to be used as foreground service")
displayIncomingCallNotification(call, true)
}
else -> {
Log.i("[Notifications Manager] Creating call notification to be used as foreground service")
@ -373,6 +381,8 @@ class NotificationsManager(private val context: Context) {
Log.i("[Notifications Manager] Starting service as foreground using call notification [$notificationId]")
currentForegroundServiceNotificationId = notificationId
service?.startForeground(currentForegroundServiceNotificationId, callNotification)
} else {
Log.w("[Notifications Manager] Can't start foreground service using notification id [$notificationId] (current foreground service notification id is [$currentForegroundServiceNotificationId]) and service [$service]")
}
}
@ -470,12 +480,18 @@ class NotificationsManager(private val context: Context) {
}
}
private fun displayIncomingCallNotification(call: Call, useAsForeground: Boolean = false) {
fun displayIncomingCallNotification(call: Call, useAsForeground: Boolean) {
if (coreContext.declineCallDueToGsmActiveCall()) {
Log.w("[Notifications Manager] Call will be declined, do not show incoming call notification")
return
}
val notifiable = getNotifiableForCall(call)
if (notifiable.notificationId == currentForegroundServiceNotificationId) {
Log.i("[Notifications Manager] There is already a Service foreground notification for this incoming call, skipping")
return
}
try {
val showLockScreenNotification = android.provider.Settings.Secure.getInt(
context.contentResolver,
@ -487,15 +503,8 @@ class NotificationsManager(private val context: Context) {
Log.e("[Notifications Manager] Failed to get android.provider.Settings.Secure.getInt(lock_screen_show_notifications): $e")
}
val notifiable = getNotifiableForCall(call)
if (notifiable.notificationId == currentForegroundServiceNotificationId) {
Log.e("[Notifications Manager] There is already a Service foreground notification for an incoming call, cancelling it")
cancel(notifiable.notificationId)
currentForegroundServiceNotificationId = 0
}
val incomingCallNotificationIntent = Intent(context, CallActivity::class.java)
incomingCallNotificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_NO_USER_ACTION)
incomingCallNotificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_NO_USER_ACTION or Intent.FLAG_FROM_BACKGROUND)
val pendingIntent = PendingIntent.getActivity(
context,
0,