Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (c) 2014-2026 Stream.io Inc. All rights reserved.
*
* Licensed under the Stream License;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://github.com/GetStream/stream-video-android/blob/main/LICENSE
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.getstream.video.android.core

import android.app.ActivityManager
import android.content.Context
import android.os.Build

internal class BackgroundRestrictions(private val context: Context) {

fun isRestricted(): Boolean {
val am = context.getSystemService(ActivityManager::class.java)
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
am.isBackgroundRestricted ?: false

Check warning on line 28 in stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/BackgroundRestrictions.kt

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove this useless elvis operation ?:, it always succeeds.

See more on https://sonarcloud.io/project/issues?id=GetStream_stream-video-android&issues=AZ7z0olDKoyPQ8JF9D2A&open=AZ7z0olDKoyPQ8JF9D2A&pullRequest=1732
} else {
false
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -367,10 +367,6 @@ public class DefaultStreamIntentResolver(
resolveInfo.activityInfo.name,
)
putExtra(NotificationHandler.INTENT_EXTRA_CALL_CID, callId)
putExtra(
NotificationHandler.INTENT_EXTRA_NOTIFICATION_ID,
callId.cid,
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,12 @@
const val INTENT_EXTRA_CALL_DISPLAY_NAME: String =
"io.getstream.video.android.intent-extra.call_displayname"

@Deprecated(
message = "Notification ids are managed internally and this extra is no longer " +
"populated. Read the active notification id from CallState.notificationIdFlow, or " +
"derive it with StreamCallId.getNotificationId(NotificationType).",
)
const val INTENT_EXTRA_NOTIFICATION_ID: String =

Check warning on line 78 in stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/notifications/NotificationHandler.kt

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Do not forget to remove this deprecated code someday.

See more on https://sonarcloud.io/project/issues?id=GetStream_stream-video-android&issues=AZ7z0ogtKoyPQ8JF9D19&open=AZ7z0ogtKoyPQ8JF9D19&pullRequest=1732
"io.getstream.video.android.intent-extra.notification_id"

@Deprecated(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@
payload: Map<String, Any?>,
) {
logger.d { "[onLiveCall] callId: ${callId.id}, callDisplayName: $callDisplayName" }
// TODO: Replace StreamCallId.hashCode with StreamCallId.getNotificationId(appropriateType)

Check warning on line 206 in stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/notifications/handlers/StreamDefaultNotificationHandler.kt

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Complete the task associated to this TODO comment.

See more on https://sonarcloud.io/project/issues?id=GetStream_stream-video-android&issues=AZ7zHqq6Ja-Yax3ehGgK&open=AZ7zHqq6Ja-Yax3ehGgK&pullRequest=1732
val notificationId = callId.hashCode()
val liveCallPendingIntent =
intentResolver.searchLiveCallPendingIntent(callId, notificationId, payload)
Expand Down Expand Up @@ -253,6 +254,7 @@
payload: Map<String, Any?>,
) {
logger.d { "[onNotification] callId: ${callId.id}, callDisplayName: $callDisplayName" }
// TODO: Replace StreamCallId.hashCode with StreamCallId.getNotificationId(appropriateType)

Check warning on line 257 in stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/notifications/handlers/StreamDefaultNotificationHandler.kt

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Complete the task associated to this TODO comment.

See more on https://sonarcloud.io/project/issues?id=GetStream_stream-video-android&issues=AZ7zHqq6Ja-Yax3ehGgL&open=AZ7zHqq6Ja-Yax3ehGgL&pullRequest=1732
val notificationId = callId.hashCode()
val intent = intentResolver.searchNotificationCallPendingIntent(
callId,
Expand Down Expand Up @@ -541,7 +543,7 @@
),
level = DeprecationLevel.WARNING,
)
override fun getSettingUpCallNotification(): Notification? {

Check warning on line 546 in stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/notifications/handlers/StreamDefaultNotificationHandler.kt

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Do not forget to remove this deprecated code someday.

See more on https://sonarcloud.io/project/issues?id=GetStream_stream-video-android&issues=AZ7z0okkKoyPQ8JF9D1-&open=AZ7z0okkKoyPQ8JF9D1-&pullRequest=1732
logger.d { "[getSettingUpCallNotification]" }
return buildSettingUpCallNotification()
}
Expand Down Expand Up @@ -572,7 +574,7 @@
override fun getSettingUpCallNotification(trigger: String, callId: StreamCallId): Notification? {
return when (trigger) {
/**
* TODO: This logic is duplicated with getIncomingCallNotificationInternal.

Check warning on line 577 in stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/notifications/handlers/StreamDefaultNotificationHandler.kt

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Complete the task associated to this TODO comment.

See more on https://sonarcloud.io/project/issues?id=GetStream_stream-video-android&issues=AZ7z0okkKoyPQ8JF9D1_&open=AZ7z0okkKoyPQ8JF9D1_&pullRequest=1732
* Update it soon
*/

Expand Down Expand Up @@ -745,6 +747,7 @@
logger.d {
"[getSimpleOngoingCallNotification] callId: ${callId.id}, callDisplayName: $callDisplayName, isOutgoingCall: $isOutgoingCall, remoteParticipantCount: $remoteParticipantCount"
}
// TODO: Replace StreamCallId.hashCode with StreamCallId.getNotificationId(appropriateType)

Check warning on line 750 in stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/notifications/handlers/StreamDefaultNotificationHandler.kt

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Complete the task associated to this TODO comment.

See more on https://sonarcloud.io/project/issues?id=GetStream_stream-video-android&issues=AZ7zHqq6Ja-Yax3ehGgM&open=AZ7zHqq6Ja-Yax3ehGgM&pullRequest=1732
val notificationId = callId.hashCode() // Notification ID

// Intents
Expand Down Expand Up @@ -1180,6 +1183,7 @@
},
): Notification {
logger.d { "[getMinimalMediaStyleNotification] callId: ${callId.id}" }
// TODO: Replace StreamCallId.hashCode with StreamCallId.getNotificationId(appropriateType)

Check warning on line 1186 in stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/notifications/handlers/StreamDefaultNotificationHandler.kt

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Complete the task associated to this TODO comment.

See more on https://sonarcloud.io/project/issues?id=GetStream_stream-video-android&issues=AZ7zHqq6Ja-Yax3ehGgN&open=AZ7zHqq6Ja-Yax3ehGgN&pullRequest=1732
val notificationId = callId.hashCode() // Notification ID
// Intents
val onClickIntent = intentResolver.searchOngoingCallPendingIntent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import io.getstream.video.android.core.CallLeaveReason
import io.getstream.video.android.core.UserActionCause
import io.getstream.video.android.core.notifications.NotificationHandler.Companion.ACTION_LEAVE_CALL
import io.getstream.video.android.core.notifications.NotificationHandler.Companion.INTENT_EXTRA_NOTIFICATION_ID
import io.getstream.video.android.model.StreamCallId

/**
* Used to process any pending intents that feature the [ACTION_LEAVE_CALL] action. By consuming this
Expand All @@ -39,13 +39,23 @@
override suspend fun onReceive(call: Call, context: Context, intent: Intent) {
logger.d { "[onReceive] #ringing; callId: ${call.id}, action: ${intent.action}" }

// A call has at most one notification; its id is stored at creation time in
// CallState.notificationIdFlow (the source of truth, replacing the deprecated
// INTENT_EXTRA_NOTIFICATION_ID extra).
val notificationId = call.state.notificationIdFlow.value
// TODO: remove this legacy notification id once nothing posts under StreamCallId.hashCode().

Check warning on line 46 in stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/notifications/internal/receivers/LeaveCallBroadcastReceiver.kt

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Complete the task associated to this TODO comment.

See more on https://sonarcloud.io/project/issues?id=GetStream_stream-video-android&issues=AZ7zHqmYJa-Yax3ehGgJ&open=AZ7zHqmYJa-Yax3ehGgJ&pullRequest=1732
val legacyNotificationId = StreamCallId.fromCallCid(call.cid).hashCode()

call.leave(
CallLeaveReason.UserAction(
UserActionCause.LEAVE_FROM_NOTIFICATION,
),
)
val notificationId = intent.getIntExtra(INTENT_EXTRA_NOTIFICATION_ID, 0)
logger.d { "[onReceive], notificationId: $notificationId" }
NotificationManagerCompat.from(context).cancel(notificationId)
logger.d {
"[onReceive], notificationId: $notificationId, legacyNotificationId: $legacyNotificationId"
}
val notificationManager = NotificationManagerCompat.from(context)
notificationId?.let { notificationManager.cancel(it) }
notificationManager.cancel(legacyNotificationId)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import androidx.core.app.NotificationManagerCompat
import androidx.lifecycle.lifecycleScope
import io.getstream.video.android.core.StreamVideo
import io.getstream.video.android.core.notifications.NotificationHandler.Companion.INTENT_EXTRA_CALL_CID
import io.getstream.video.android.core.notifications.NotificationHandler.Companion.INTENT_EXTRA_NOTIFICATION_ID
import io.getstream.video.android.core.notifications.NotificationType
import io.getstream.video.android.model.StreamCallId
import io.getstream.video.android.model.streamCallId
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -56,7 +56,7 @@ public abstract class AbstractNotificationActivity : ComponentActivity() {

lifecycleScope.launch {
if (hasAcceptedCall) {
dismissIncomingCallNotifications()
dismissIncomingCallNotifications(callCid)
} else {
loadCallData(callCid)
}
Expand All @@ -74,15 +74,18 @@ public abstract class AbstractNotificationActivity : ComponentActivity() {
// is Result.Success -> Unit
// is Result.Failure -> finish()
// }
dismissIncomingCallNotifications()
dismissIncomingCallNotifications(guid)
}

/**
* Dismisses any notifications that might be active with a given notification ID.
* Used to clear up the notification state if the call has been accepted or rejected.
*/
private fun dismissIncomingCallNotifications() {
val notificationId = intent.getIntExtra(INTENT_EXTRA_NOTIFICATION_ID, 0)
private fun dismissIncomingCallNotifications(callCid: StreamCallId) {
// A call has a single notification; the incoming-call notification's id comes from the
// shared generator, so derive it from the call id and cancel it. (Replaces the deprecated
// INTENT_EXTRA_NOTIFICATION_ID extra.)
val notificationId = callCid.getNotificationId(NotificationType.Incoming)
NotificationManagerCompat.from(this).cancel(notificationId)
finish()
}
Expand Down
Loading