From da83fd7d90dde75893b518a28859ffb3010cc51e Mon Sep 17 00:00:00 2001 From: buyuxiang <347586493@qq.com> Date: Wed, 7 Jun 2023 12:04:38 +0800 Subject: [PATCH] fix adb WindowSize and print logcat --- hrp/pkg/uixt/android_adb_driver.go | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/hrp/pkg/uixt/android_adb_driver.go b/hrp/pkg/uixt/android_adb_driver.go index dbaf5c5b..3be8dfe1 100644 --- a/hrp/pkg/uixt/android_adb_driver.go +++ b/hrp/pkg/uixt/android_adb_driver.go @@ -57,17 +57,29 @@ func (ad *adbDriver) BatteryInfo() (batteryInfo BatteryInfo, err error) { func (ad *adbDriver) WindowSize() (size Size, err error) { // adb shell wm size - resp, err := ad.adbClient.RunShellCommand("wm", "size") + output, err := ad.adbClient.RunShellCommand("wm", "size") if err != nil { - return + return size, errors.Wrap(err, "get window size failed with adb") } + // output may contain both Physical and Override size // Physical size: 1080x2340 - s := strings.Trim(strings.Split(resp, ": ")[1], "\n") - ss := strings.Split(s, "x") - width, _ := strconv.Atoi(ss[0]) - height, _ := strconv.Atoi(ss[1]) - size = Size{Width: width, Height: height} + // Override size: 1080x2220 + var resolution string + sizeList := strings.Split(output, "\n") + log.Info().Msgf("window size: %v", sizeList) + for _, size := range sizeList { + if strings.Contains(size, "Physical") { + resolution = strings.Split(size, ": ")[1] + // 1080x2340 + ss := strings.Split(resolution, "x") + width, _ := strconv.Atoi(ss[0]) + height, _ := strconv.Atoi(ss[1]) + return Size{Width: width, Height: height}, nil + } + } + + err = errors.New("physical window size not found by adb") return } @@ -355,6 +367,7 @@ func (ad *adbDriver) StopCaptureLog() (result interface{}, err error) { return "", err } content := ad.logcat.logBuffer.String() + log.Info().Str("logcat content", content).Msg("display logcat content") return ConvertPoints(content), nil }