diff --git a/features/call/src/main/kotlin/io/element/android/features/call/CallIntentDataParser.kt b/features/call/src/main/kotlin/io/element/android/features/call/CallIntentDataParser.kt index cac211cdc1..9237087e2b 100644 --- a/features/call/src/main/kotlin/io/element/android/features/call/CallIntentDataParser.kt +++ b/features/call/src/main/kotlin/io/element/android/features/call/CallIntentDataParser.kt @@ -18,8 +18,9 @@ package io.element.android.features.call import android.net.Uri import java.net.URLDecoder +import javax.inject.Inject -object CallIntentDataParser { +class CallIntentDataParser @Inject constructor() { private val validHttpSchemes = sequenceOf("http", "https") diff --git a/features/call/src/main/kotlin/io/element/android/features/call/ElementCallActivity.kt b/features/call/src/main/kotlin/io/element/android/features/call/ElementCallActivity.kt index 69ef3963cb..481634a4ca 100644 --- a/features/call/src/main/kotlin/io/element/android/features/call/ElementCallActivity.kt +++ b/features/call/src/main/kotlin/io/element/android/features/call/ElementCallActivity.kt @@ -39,6 +39,7 @@ import javax.inject.Inject class ElementCallActivity : ComponentActivity() { @Inject lateinit var userAgentProvider: UserAgentProvider + @Inject lateinit var callIntentDataParser: CallIntentDataParser private lateinit var audioManager: AudioManager @@ -129,7 +130,7 @@ class ElementCallActivity : ComponentActivity() { finishAndRemoveTask() } - private fun parseUrl(url: String?): String? = CallIntentDataParser.parse(url) + private fun parseUrl(url: String?): String? = callIntentDataParser.parse(url) private fun registerPermissionResultLauncher(): ActivityResultLauncher> { return registerForActivityResult( diff --git a/features/call/src/test/kotlin/io/element/android/features/call/CallIntentDataParserTests.kt b/features/call/src/test/kotlin/io/element/android/features/call/CallIntentDataParserTests.kt index da41692b40..93ae34a9c9 100644 --- a/features/call/src/test/kotlin/io/element/android/features/call/CallIntentDataParserTests.kt +++ b/features/call/src/test/kotlin/io/element/android/features/call/CallIntentDataParserTests.kt @@ -25,28 +25,30 @@ import java.net.URLEncoder @RunWith(RobolectricTestRunner::class) class CallIntentDataParserTests { + private val callIntentDataParser = CallIntentDataParser() + @Test fun `a null data returns null`() { val url: String? = null - assertThat(CallIntentDataParser.parse(url)).isNull() + assertThat(callIntentDataParser.parse(url)).isNull() } @Test fun `empty data returns null`() { val url = "" - assertThat(CallIntentDataParser.parse(url)).isNull() + assertThat(callIntentDataParser.parse(url)).isNull() } @Test fun `invalid data returns null`() { val url = "!" - assertThat(CallIntentDataParser.parse(url)).isNull() + assertThat(callIntentDataParser.parse(url)).isNull() } @Test fun `data with no scheme returns null`() { val url = "test" - assertThat(CallIntentDataParser.parse(url)).isNull() + assertThat(callIntentDataParser.parse(url)).isNull() } @Test @@ -55,10 +57,10 @@ class CallIntentDataParserTests { val httpCallUrl = "http://call.element.io/some-actual-call?with=parameters" val httpsBaseUrl = "https://call.element.io" val httpsCallUrl = "https://call.element.io/some-actual-call?with=parameters" - assertThat(CallIntentDataParser.parse(httpBaseUrl)).isEqualTo(httpBaseUrl) - assertThat(CallIntentDataParser.parse(httpCallUrl)).isEqualTo(httpCallUrl) - assertThat(CallIntentDataParser.parse(httpsBaseUrl)).isEqualTo(httpsBaseUrl) - assertThat(CallIntentDataParser.parse(httpsCallUrl)).isEqualTo(httpsCallUrl) + assertThat(callIntentDataParser.parse(httpBaseUrl)).isEqualTo(httpBaseUrl) + assertThat(callIntentDataParser.parse(httpCallUrl)).isEqualTo(httpCallUrl) + assertThat(callIntentDataParser.parse(httpsBaseUrl)).isEqualTo(httpsBaseUrl) + assertThat(callIntentDataParser.parse(httpsCallUrl)).isEqualTo(httpsCallUrl) } @Test @@ -67,10 +69,10 @@ class CallIntentDataParserTests { val httpsBaseUrl = "https://app.element.io" val httpInvalidUrl = "http://" val httpsInvalidUrl = "http://" - assertThat(CallIntentDataParser.parse(httpBaseUrl)).isNull() - assertThat(CallIntentDataParser.parse(httpsBaseUrl)).isNull() - assertThat(CallIntentDataParser.parse(httpInvalidUrl)).isNull() - assertThat(CallIntentDataParser.parse(httpsInvalidUrl)).isNull() + assertThat(callIntentDataParser.parse(httpBaseUrl)).isNull() + assertThat(callIntentDataParser.parse(httpsBaseUrl)).isNull() + assertThat(callIntentDataParser.parse(httpInvalidUrl)).isNull() + assertThat(callIntentDataParser.parse(httpsInvalidUrl)).isNull() } @Test @@ -78,7 +80,7 @@ class CallIntentDataParserTests { val embeddedUrl = "http://call.element.io/some-actual-call?with=parameters" val encodedUrl = URLEncoder.encode(embeddedUrl, "utf-8") val url = "element://call?url=$encodedUrl" - assertThat(CallIntentDataParser.parse(url)).isEqualTo(embeddedUrl) + assertThat(callIntentDataParser.parse(url)).isEqualTo(embeddedUrl) } @Test @@ -86,7 +88,7 @@ class CallIntentDataParserTests { val embeddedUrl = "http://call.element.io/some-actual-call?with=parameters" val encodedUrl = URLEncoder.encode(embeddedUrl, "utf-8") val url = "element://call?no-url=$encodedUrl" - assertThat(CallIntentDataParser.parse(url)).isNull() + assertThat(callIntentDataParser.parse(url)).isNull() } @Test @@ -94,12 +96,12 @@ class CallIntentDataParserTests { val embeddedUrl = "http://call.element.io/some-actual-call?with=parameters" val encodedUrl = URLEncoder.encode(embeddedUrl, "utf-8") val url = "element://no-call?url=$encodedUrl" - assertThat(CallIntentDataParser.parse(url)).isNull() + assertThat(callIntentDataParser.parse(url)).isNull() } @Test fun `element scheme with no data returns null`() { val url = "element://call?url=" - assertThat(CallIntentDataParser.parse(url)).isNull() + assertThat(callIntentDataParser.parse(url)).isNull() } }