From 9850e8e168d6e8f386d78d86d85a58448a3ef759 Mon Sep 17 00:00:00 2001 From: shamanec Date: Mon, 25 Dec 2023 19:31:31 +0200 Subject: [PATCH] Fix getting android screen size * On some devices two separate lines with screen size information is returned from adb, this should fix it for such devices --- device/android.go | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/device/android.go b/device/android.go index e77cf8e..a4c988a 100644 --- a/device/android.go +++ b/device/android.go @@ -123,11 +123,31 @@ func updateAndroidScreenSizeADB(device *LocalDevice) error { } output := outBuffer.String() - splitOutput := strings.Split(output, ": ") - screenDimensions := strings.Split(splitOutput[1], "x") + // Some devices return more than one line with device screen info + // Physical size and Override size + // Thats why we'll process the response respectively + // Specifically this was applied when caught on Samsung S20 and S9, might apply for others + lines := strings.Split(output, "\n") + // If the split lines are 2 then we have only one size returned + // and one empty line + if len(lines) == 2 { + splitOutput := strings.Split(lines[0], ": ") + screenDimensions := strings.Split(splitOutput[1], "x") + + device.Device.ScreenWidth = strings.TrimSpace(screenDimensions[0]) + device.Device.ScreenHeight = strings.TrimSpace(screenDimensions[1]) + } + + // If the split lines are 3 then we have two sizes returned + // and one empty line + // We need the second size here + if len(lines) == 3 { + splitOutput := strings.Split(lines[1], ": ") + screenDimensions := strings.Split(splitOutput[1], "x") - device.Device.ScreenWidth = strings.TrimSpace(screenDimensions[0]) - device.Device.ScreenHeight = strings.TrimSpace(screenDimensions[1]) + device.Device.ScreenWidth = strings.TrimSpace(screenDimensions[0]) + device.Device.ScreenHeight = strings.TrimSpace(screenDimensions[1]) + } return nil }