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 6e1d20ea2e..a25c4d39cb 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 @@ -135,38 +135,14 @@ class ParseDeviceUserAgentUseCase @Inject constructor() { val secondSegment = deviceOperatingSystemSegments.getOrNull(1).orEmpty() return when { - firstSegment.startsWith(OPERATING_SYSTEM_MAC_KEYWORD) -> { - // e.g. (Macintosh; Intel Mac OS X 10_15_7) => macOS 10.15.7 - val version = secondSegment - .substringAfterLast(" ") - .replace("_", ".") - if (version.isEmpty()) { - OPERATING_SYSTEM_MAC - } else { - "$OPERATING_SYSTEM_MAC $version" - } - } - firstSegment.startsWith(OPERATING_SYSTEM_WINDOWS_KEYWORD) -> { - // e.g. (Windows NT 10.0; Win64; x64) => Windows 10.0 - firstSegment.replace("NT ", "") - } - firstSegment.startsWith(DEVICE_IPAD_KEYWORD) || firstSegment.startsWith(DEVICE_IPHONE_KEYWORD) -> { - // e.g. (iPad; CPU OS 8_4_1 like Mac OS X) => macOS 8.4.1 - val version = secondSegment - .split(" ") - .find { it.contains("_") } - ?.replace("_", ".") - .orEmpty() - if (version.isEmpty()) { - OPERATING_SYSTEM_IOS - } else { - "$OPERATING_SYSTEM_IOS $version" - } - } - secondSegment.startsWith(OPERATING_SYSTEM_ANDROID_KEYWORD) -> { - // e.g. (Linux; Android 9; SM-G973U Build/PPR1.180610.011) => Android 9 - secondSegment - } + // e.g. (Macintosh; Intel Mac OS X 10_15_7) => macOS + firstSegment.startsWith(OPERATING_SYSTEM_MAC_KEYWORD) -> OPERATING_SYSTEM_MAC + // e.g. (Windows NT 10.0; Win64; x64) => Windows + firstSegment.startsWith(OPERATING_SYSTEM_WINDOWS_KEYWORD) -> OPERATING_SYSTEM_WINDOWS_KEYWORD + // e.g. (iPad; CPU OS 8_4_1 like Mac OS X) => iOS + firstSegment.startsWith(DEVICE_IPAD_KEYWORD) || firstSegment.startsWith(DEVICE_IPHONE_KEYWORD) -> OPERATING_SYSTEM_IOS + // e.g. (Linux; Android 9; SM-G973U Build/PPR1.180610.011) => Android + secondSegment.startsWith(OPERATING_SYSTEM_ANDROID_KEYWORD) -> OPERATING_SYSTEM_ANDROID_KEYWORD else -> null } } 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 d6ac925603..20c4a8fa3d 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, "macOS 10.15.7", "Electron", "20.1.1"), - DeviceExtendedInfo(DeviceType.DESKTOP, null, "Windows 10.0", "Electron", "20.1.1"), + DeviceExtendedInfo(DeviceType.DESKTOP, null, "macOS", "Electron", "20.1.1"), + DeviceExtendedInfo(DeviceType.DESKTOP, null, "Windows", "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, "macOS 10.15.7", "Chrome", "104.0.5112.102"), - DeviceExtendedInfo(DeviceType.WEB, null, "Windows 10.0", "Chrome", "104.0.5112.102"), - DeviceExtendedInfo(DeviceType.WEB, null, "macOS 10.10", "Firefox", "39.0"), - DeviceExtendedInfo(DeviceType.WEB, null, "macOS 10.10.2", "Safari", "8.0.3"), - DeviceExtendedInfo(DeviceType.WEB, null, "Android 9", "Chrome", "69.0.3497.100"), - DeviceExtendedInfo(DeviceType.WEB, null, "iOS 8.4.1", "Safari", "8.0"), - DeviceExtendedInfo(DeviceType.WEB, null, "iOS 8.4.1", "Safari", "8.0"), - DeviceExtendedInfo(DeviceType.WEB, null, "Windows 6.0", "Firefox", "40.0"), - DeviceExtendedInfo(DeviceType.WEB, null, "Windows 10.0", "Edge", "12.246"), + DeviceExtendedInfo(DeviceType.WEB, null, "macOS", "Chrome", "104.0.5112.102"), + DeviceExtendedInfo(DeviceType.WEB, null, "Windows", "Chrome", "104.0.5112.102"), + DeviceExtendedInfo(DeviceType.WEB, null, "macOS", "Firefox", "39.0"), + DeviceExtendedInfo(DeviceType.WEB, null, "macOS", "Safari", "8.0.3"), + DeviceExtendedInfo(DeviceType.WEB, null, "Android", "Chrome", "69.0.3497.100"), + DeviceExtendedInfo(DeviceType.WEB, null, "iOS", "Safari", "8.0"), + DeviceExtendedInfo(DeviceType.WEB, null, "iOS", "Safari", "8.0"), + DeviceExtendedInfo(DeviceType.WEB, null, "Windows", "Firefox", "40.0"), + DeviceExtendedInfo(DeviceType.WEB, null, "Windows", "Edge", "12.246"), ) private val AN_UNKNOWN_USER_AGENT_LIST = listOf(