From ef784709af5863b2023a5b2722b19006e929e467 Mon Sep 17 00:00:00 2001 From: "lilong.129" Date: Thu, 13 Apr 2023 22:48:40 +0800 Subject: [PATCH] faet: add ScreenCap for gadb --- hrp/pkg/gadb/client_test.go | 2 +- hrp/pkg/gadb/device.go | 4 ++++ hrp/pkg/uixt/android_adb_driver.go | 4 +--- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/hrp/pkg/gadb/client_test.go b/hrp/pkg/gadb/client_test.go index dff28e38..56dd1a94 100644 --- a/hrp/pkg/gadb/client_test.go +++ b/hrp/pkg/gadb/client_test.go @@ -140,7 +140,7 @@ func TestScreenCap(t *testing.T) { t.Error(err) } d := dl[0] - res, err := d.RunShellCommandV2WithBytes("screencap", "-p") + res, err := d.ScreenCap() if err != nil { t.Error(err) } diff --git a/hrp/pkg/gadb/device.go b/hrp/pkg/gadb/device.go index b9911272..4b296396 100644 --- a/hrp/pkg/gadb/device.go +++ b/hrp/pkg/gadb/device.go @@ -571,3 +571,7 @@ func (d *Device) Uninstall(packageName string, keepData ...bool) (string, error) args = append(args, packageName) return d.RunShellCommandV2("pm", args...) } + +func (d *Device) ScreenCap() ([]byte, error) { + return d.RunShellCommandV2WithBytes("screencap", "-p") +} diff --git a/hrp/pkg/uixt/android_adb_driver.go b/hrp/pkg/uixt/android_adb_driver.go index e9a35b38..fbf89eb2 100644 --- a/hrp/pkg/uixt/android_adb_driver.go +++ b/hrp/pkg/uixt/android_adb_driver.go @@ -280,9 +280,7 @@ func (ad *adbDriver) SetRotation(rotation Rotation) (err error) { func (ad *adbDriver) Screenshot() (raw *bytes.Buffer, err error) { // adb shell screencap -p - resp, err := ad.adbClient.RunShellCommandWithBytes( - "screencap", "-p", - ) + resp, err := ad.adbClient.ScreenCap() if err == nil { return bytes.NewBuffer(resp), nil }