From 755b97e54d2a382b33c0adc97b8e3cb1f7e8380c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=99=E6=B3=93=E9=93=AE?= Date: Wed, 25 Sep 2024 11:29:48 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=E8=A7=A3=E9=94=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hrp/pkg/uixt/harmony_hdc_driver.go | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/hrp/pkg/uixt/harmony_hdc_driver.go b/hrp/pkg/uixt/harmony_hdc_driver.go index 7aa89d8f..76f8462f 100644 --- a/hrp/pkg/uixt/harmony_hdc_driver.go +++ b/hrp/pkg/uixt/harmony_hdc_driver.go @@ -4,6 +4,7 @@ import ( "bytes" "fmt" "os" + "regexp" "time" "code.byted.org/iesqa/ghdc" @@ -17,6 +18,13 @@ type hdcDriver struct { uiDriver *ghdc.UIDriver } +type PowerStatus string + +const ( + POWER_STATUS_SUSPEND PowerStatus = "POWER_STATUS_SUSPEND" + POWER_STATUS_ON PowerStatus = "POWER_STATUS_ON" +) + func newHarmonyDriver(device *ghdc.Device) (driver *hdcDriver, err error) { driver = new(hdcDriver) driver.device = device @@ -32,6 +40,7 @@ func newHarmonyDriver(device *ghdc.Device) (driver *hdcDriver, err error) { func (hd *hdcDriver) NewSession(capabilities Capabilities) (SessionInfo, error) { hd.Driver.session.Init() + hd.Unlock() return SessionInfo{}, errDriverNotImplemented } @@ -88,11 +97,23 @@ func (hd *hdcDriver) Homescreen() error { func (hd *hdcDriver) Unlock() (err error) { // Todo 检查是否锁屏 hdc shell hidumper -s RenderService -a screen - err = hd.uiDriver.PressPowerKey() + screenInfo, err := hd.device.RunShellCommand("hidumper", "-s", "RenderService", "-a", "screen") if err != nil { return err } - return hd.Swipe(500, 2000, 500, 500) + re := regexp.MustCompile(`powerstatus=([\w_]+)`) + match := re.FindStringSubmatch(screenInfo) + if len(match) <= 1 { + return fmt.Errorf("failed to unlock; failed to find powerstatus") + } + if match[1] == string(POWER_STATUS_SUSPEND) { + err = hd.uiDriver.PressPowerKey() + if err != nil { + return err + } + } + + return hd.Swipe(500, 1500, 500, 500) } func (hd *hdcDriver) AppLaunch(packageName string) error {