fix: revert gadb device ScreenCap

This commit is contained in:
lilong.129 2025-03-03 21:04:00 +08:00
parent d1af4cfe61
commit 720e5fa504
2 changed files with 22 additions and 2 deletions

View File

@ -1 +1 @@
v5.0.0+2503032054
v5.0.0+2503032117

View File

@ -722,5 +722,25 @@ func (d *Device) IsPackageRunning(packageName string) bool {
}
func (d *Device) ScreenCap() ([]byte, error) {
return d.RunShellCommandV2WithBytes("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
}
// remove temp file
defer func() {
go d.RunShellCommand("rm", tempPath)
}()
buffer := bytes.NewBuffer(nil)
err = d.Pull(tempPath, buffer)
return buffer.Bytes(), err
}