Skip to content
Open
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
Expand Up @@ -56,6 +56,7 @@
CallService.Companion.TRIGGER_ONGOING_CALL,
CallService.Companion.TRIGGER_OUTGOING_CALL,
-> calculateServiceType(context)
CallService.Companion.TRIGGER_INCOMING_CALL -> incomingRingingServiceType()
else -> noPermissionServiceType()
}
}
Expand Down Expand Up @@ -91,6 +92,24 @@
ServiceInfo.FOREGROUND_SERVICE_TYPE_PHONE_CALL
}

/**
* Foreground-service type for the incoming-ringing window.
*
* On Android 17+, background audio (the ringtone) is muted under [ServiceInfo.FOREGROUND_SERVICE_TYPE_SHORT_SERVICE],
* so phoneCall-capable VoIP services use phoneCall instead. Other services keep [noPermissionServiceType].
*/
@SuppressLint("InlinedApi")
internal open fun incomingRingingServiceType(): Int =
// TODO: replace the hardcoded 37 with Build.VERSION_CODES.<ANDROID_17> once compileSdk /

Check warning on line 103 in stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/notifications/internal/service/permissions/ForegroundServicePermissionManager.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=AZ-NzQi5cRmzc0-YXoah&open=AZ-NzQi5cRmzc0-YXoah&pullRequest=1752
// targetSdk are raised to 37; the constant does not exist at the current compileSdk.
if (requiredForegroundTypes.contains(ServiceInfo.FOREGROUND_SERVICE_TYPE_PHONE_CALL) &&
Build.VERSION.SDK_INT >= 37
Comment on lines +103 to +106

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Replace the TODO-backed API-level literal.

SonarCloud reports this TODO as unresolved. Extract 37 into a named ANDROID_17_API_LEVEL constant and track the compileSdk upgrade separately, rather than retaining a warning in production code.

🧰 Tools
🪛 GitHub Check: SonarCloud Code Analysis

[warning] 103-103: Complete the task associated to this TODO comment.

See more on https://sonarcloud.io/project/issues?id=GetStream_stream-video-android&issues=AZ-NzQi5cRmzc0-YXoah&open=AZ-NzQi5cRmzc0-YXoah&pullRequest=1752

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/notifications/internal/service/permissions/ForegroundServicePermissionManager.kt`
around lines 103 - 106, Replace the hardcoded 37 in the API-level check within
ForegroundServicePermissionManager with a named ANDROID_17_API_LEVEL constant,
and remove the TODO comment. Use the constant in the Build.VERSION.SDK_INT
comparison while preserving the existing foreground service type condition;
track the future compileSdk upgrade separately.

Source: Linters/SAST tools

) {
ServiceInfo.FOREGROUND_SERVICE_TYPE_PHONE_CALL
} else {
noPermissionServiceType()
}

@SuppressLint("InlinedApi")
internal open fun androidQServiceType(): Int {
return if (requiredForegroundTypes.contains(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config
import org.robolectric.shadows.ShadowApplication
import org.robolectric.util.ReflectionHelpers
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFalse
Expand Down Expand Up @@ -99,6 +100,40 @@ class ForegroundServicePermissionManagerTest {
assertEquals(0, type)
}

@Test
@Config(sdk = [Build.VERSION_CODES.UPSIDE_DOWN_CAKE])
fun `incoming call keeps short service below android 17`() {
// ringingServiceType only switches to phoneCall from Android 17 up, where the
// background-audio hardening applies. Android 14/15/16 keep their existing behavior.
val type = manager.getServiceType(
context,
CallService.TRIGGER_INCOMING_CALL,
)

assertEquals(
ServiceInfo.FOREGROUND_SERVICE_TYPE_SHORT_SERVICE,
type,
)
}

@Test
fun `incoming call uses phone call service type on android 17 and above`() {
// Android 17 background-audio hardening mutes the ringtone under SHORT_SERVICE; use the
// while-in-use phoneCall type instead. Robolectric 4.11.1 caps @Config at API 34, so the
// >= 37 branch is exercised by forcing SDK_INT.
ReflectionHelpers.setStaticField(Build.VERSION::class.java, "SDK_INT", 37)

val type = manager.getServiceType(
context,
CallService.TRIGGER_INCOMING_CALL,
)

assertEquals(
ServiceInfo.FOREGROUND_SERVICE_TYPE_PHONE_CALL,
type,
)
}

@Test
@Config(sdk = [Build.VERSION_CODES.UPSIDE_DOWN_CAKE])
fun `no permission uses short service on android 14`() {
Expand Down
Loading