fix: screencap compatibility for shell v1 and v2

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

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
}