From 4e70fcd339d94a2ce4bc0263a33aa020da68f57e Mon Sep 17 00:00:00 2001 From: Maxime NATUREL Date: Mon, 10 Oct 2022 11:41:35 +0200 Subject: [PATCH] Extracting parsing of operating system for Desktop/Web into dedicated method --- .../devices/v2/ParseDeviceUserAgentUseCase.kt | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) 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 4cc1bf5c9f..2876d7e855 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,17 +75,12 @@ class ParseDeviceUserAgentUseCase @Inject constructor() { private fun parseDesktopUserAgent(userAgent: String): DeviceExtendedInfo { val browserInfo = parseBrowserInfoFromDesktopUserAgent(userAgent) + val operatingSystem = parseOperatingSystemFromDesktopUserAgent(userAgent) - val deviceOperatingSystemSegments = userAgent.substringAfter("(").substringBefore(")").split("; ") - val deviceOperatingSystem = if (deviceOperatingSystemSegments.getOrNull(1)?.startsWith("Android").orFalse()) { - deviceOperatingSystemSegments.getOrNull(1) - } else { - deviceOperatingSystemSegments.getOrNull(0) - } return DeviceExtendedInfo( deviceType = DeviceType.DESKTOP, deviceModel = null, - deviceOperatingSystem = deviceOperatingSystem, + deviceOperatingSystem = operatingSystem, clientName = browserInfo.name, clientVersion = browserInfo.version, ) @@ -131,6 +126,15 @@ class ParseDeviceUserAgentUseCase @Inject constructor() { } } + private fun parseOperatingSystemFromDesktopUserAgent(userAgent: String): String? { + val deviceOperatingSystemSegments = userAgent.substringAfter("(").substringBefore(")").split("; ") + return if (deviceOperatingSystemSegments.getOrNull(1)?.startsWith("Android").orFalse()) { + deviceOperatingSystemSegments.getOrNull(1) + } else { + deviceOperatingSystemSegments.getOrNull(0) + } + } + private fun parseWebUserAgent(userAgent: String): DeviceExtendedInfo { return parseDesktopUserAgent(userAgent).copy( deviceType = DeviceType.WEB