fix: screencap compatibility for shell v1 and v2

This commit is contained in:
lilong.129
2023-04-14 23:50:40 +08:00
parent c787b73e99
commit 524b277308
3 changed files with 18 additions and 2 deletions

View File

@@ -13,6 +13,7 @@
- fix: stop logcat only when enabled
- fix: do not fail case when kill logcat error
- fix: take screenshot after each step
- fix: screencap compatibility for shell v1 and v2
## v4.3.2 (2022-12-26)

View File

@@ -1 +1 @@
v4.3.3.2304142149
v4.3.3.2304142356

View File

@@ -572,5 +572,20 @@ func (d *Device) Uninstall(packageName string, keepData ...bool) (string, error)
}
func (d *Device) ScreenCap() ([]byte, error) {
return d.RunShellCommandWithBytes("screencap", "-p")
if d.HasFeature(FeatShellV2) {
return d.RunShellCommandV2WithBytes("screencap", "-p")
}
// for shell v1, screenshot buffer maybe truncated
// thus we firstly save it to local file and then pull it
tempPath := fmt.Sprintf("/data/local/tmp/screenshot_%d.png",
time.Now().Unix())
_, err := d.RunShellCommandWithBytes("screencap", "-p", tempPath)
if err != nil {
return nil, err
}
buffer := bytes.NewBuffer(nil)
err = d.Pull(tempPath, buffer)
return buffer.Bytes(), err
}