diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/v2/ParseDeviceUserAgentUseCase.kt b/vector/src/main/java/im/vector/app/features/settings/devices/v2/ParseDeviceUserAgentUseCase.kt index ef4391c8c1..17e66815f3 100644 --- a/vector/src/main/java/im/vector/app/features/settings/devices/v2/ParseDeviceUserAgentUseCase.kt +++ b/vector/src/main/java/im/vector/app/features/settings/devices/v2/ParseDeviceUserAgentUseCase.kt @@ -75,6 +75,7 @@ class ParseDeviceUserAgentUseCase @Inject constructor() { private fun parseDesktopUserAgent(userAgent: String): DeviceExtendedInfo { val browserSegments = userAgent.split(" ") + // TODO parse the whole version of browser val (browserName, browserVersion) = when { isFirefox(browserSegments) -> { Pair("Firefox", getBrowserVersion(browserSegments, "Firefox")) @@ -140,13 +141,11 @@ class ParseDeviceUserAgentUseCase @Inject constructor() { } private fun getBrowserVersion(browserSegments: List, browserName: String): String? { - // Chrome/104.0.3497.100 -> 104 + // e.g Chrome/104.0.3497.100 -> 104.0.3497.100 return browserSegments .find { it.startsWith(browserName) } ?.split("/") ?.getOrNull(1) - ?.split(".") - ?.firstOrNull() } private fun isEdge(browserSegments: List): Boolean { diff --git a/vector/src/test/java/im/vector/app/features/settings/devices/v2/ParseDeviceUserAgentUseCaseTest.kt b/vector/src/test/java/im/vector/app/features/settings/devices/v2/ParseDeviceUserAgentUseCaseTest.kt index 60b9f70e56..19caee1db7 100644 --- a/vector/src/test/java/im/vector/app/features/settings/devices/v2/ParseDeviceUserAgentUseCaseTest.kt +++ b/vector/src/test/java/im/vector/app/features/settings/devices/v2/ParseDeviceUserAgentUseCaseTest.kt @@ -62,8 +62,8 @@ private val A_USER_AGENT_LIST_FOR_DESKTOP = listOf( "Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) ElementNightly/2022091301 Chrome/104.0.5112.102 Electron/20.1.1 Safari/537.36", ) private val AN_EXPECTED_RESULT_LIST_FOR_DESKTOP = listOf( - DeviceExtendedInfo(DeviceType.DESKTOP, null, "Macintosh", "Electron", "20"), - DeviceExtendedInfo(DeviceType.DESKTOP, null, "Windows NT 10.0", "Electron", "20"), + DeviceExtendedInfo(DeviceType.DESKTOP, null, "Macintosh", "Electron", "20.1.1"), + DeviceExtendedInfo(DeviceType.DESKTOP, null, "Windows NT 10.0", "Electron", "20.1.1"), ) private val A_USER_AGENT_LIST_FOR_WEB = listOf( @@ -78,15 +78,15 @@ private val A_USER_AGENT_LIST_FOR_WEB = listOf( "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.246", ) private val AN_EXPECTED_RESULT_LIST_FOR_WEB = listOf( - DeviceExtendedInfo(DeviceType.WEB, null, "Macintosh", "Chrome", "104"), - DeviceExtendedInfo(DeviceType.WEB, null, "Windows NT 10.0", "Chrome", "104"), - DeviceExtendedInfo(DeviceType.WEB, null, "Macintosh", "Firefox", "39"), - DeviceExtendedInfo(DeviceType.WEB, null, "Macintosh", "Safari", "8"), - DeviceExtendedInfo(DeviceType.WEB, null, "Android 9", "Chrome", "69"), - DeviceExtendedInfo(DeviceType.WEB, null, "iPad", "Safari", "8"), - DeviceExtendedInfo(DeviceType.WEB, null, "iPhone", "Safari", "8"), - DeviceExtendedInfo(DeviceType.WEB, null, "Windows NT 6.0", "Firefox", "40"), - DeviceExtendedInfo(DeviceType.WEB, null, "Windows NT 10.0", "Edge", "12"), + DeviceExtendedInfo(DeviceType.WEB, null, "Macintosh", "Chrome", "104.0.5112.102"), + DeviceExtendedInfo(DeviceType.WEB, null, "Windows NT 10.0", "Chrome", "104.0.5112.102"), + DeviceExtendedInfo(DeviceType.WEB, null, "Macintosh", "Firefox", "39.0"), + DeviceExtendedInfo(DeviceType.WEB, null, "Macintosh", "Safari", "8.0.3"), + DeviceExtendedInfo(DeviceType.WEB, null, "Android 9", "Chrome", "69.0.3497.100"), + DeviceExtendedInfo(DeviceType.WEB, null, "iPad", "Safari", "8.0"), + DeviceExtendedInfo(DeviceType.WEB, null, "iPhone", "Safari", "8.0"), + DeviceExtendedInfo(DeviceType.WEB, null, "Windows NT 6.0", "Firefox", "40.0"), + DeviceExtendedInfo(DeviceType.WEB, null, "Windows NT 10.0", "Edge", "12.246"), ) private val AN_UNKNOWN_USER_AGENT_LIST = listOf(