From 768e8756175e5aadfd32654723586025b3787beb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A5=A5=E5=88=A9=E5=A5=A5=E5=97=B7=E5=97=B7=E5=8F=AB?= Date: Thu, 8 Dec 2022 00:36:55 +0800 Subject: [PATCH] add PowerSource --- device.go | 13 ++++++++++++ device_test.go | 9 ++++++++ diagnosticsrelay.go | 27 +++++++++++++++++++++++- idevice.go | 2 ++ pkg/libimobiledevice/diagnosticsrelay.go | 4 ++++ 5 files changed, 54 insertions(+), 1 deletion(-) diff --git a/device.go b/device.go index d6b3856..4816d7e 100644 --- a/device.go +++ b/device.go @@ -657,6 +657,19 @@ func (d *device) Reboot() (err error) { return } +func (d *device) PowerSource() (powerInfo interface{}, err error) { + if _, err = d.lockdownService(); err != nil { + return + } + if d.diagnosticsRelay, err = d.lockdown.DiagnosticsRelayService(); err != nil { + return + } + if powerInfo, err = d.diagnosticsRelay.PowerSource(); err != nil { + return + } + return +} + func (d *device) Shutdown() (err error) { if _, err = d.lockdownService(); err != nil { return diff --git a/device_test.go b/device_test.go index 03c4fe6..6dc77b8 100644 --- a/device_test.go +++ b/device_test.go @@ -155,6 +155,15 @@ func Test_device_Shutdown(t *testing.T) { dev.Shutdown() } +func Test_device_PowerInfo(t *testing.T) { + setupDevice(t) + data, err := dev.PowerSource() + if err != nil { + panic(err) + } + log.Println(data) +} + func Test_device_InstallationProxyBrowse(t *testing.T) { setupDevice(t) diff --git a/diagnosticsrelay.go b/diagnosticsrelay.go index 336cb27..0c80f0d 100644 --- a/diagnosticsrelay.go +++ b/diagnosticsrelay.go @@ -1,6 +1,8 @@ package giDevice -import "github.com/SonicCloudOrg/sonic-gidevice/pkg/libimobiledevice" +import ( + "github.com/SonicCloudOrg/sonic-gidevice/pkg/libimobiledevice" +) func newDiagnosticsRelay(client *libimobiledevice.DiagnosticsRelayClient) *diagnostics { return &diagnostics{ @@ -37,3 +39,26 @@ func (d *diagnostics) Shutdown() (err error) { } return } + +func (d *diagnostics) PowerSource() (powerInfo interface{}, err error) { + var data map[string]string + data["Request"] = "IORegistry" + data["EntryClass"] = "IOPMPowerSource" + data["Label"] = "org.cloud.sonic.gidevice" + var pkt libimobiledevice.Packet + if pkt, err = d.client.NewXmlPacket( + d.client.NewBasicRequest("Shutdown"), + ); err != nil { + return nil, err + } + if err = d.client.SendPacket(pkt); err != nil { + return nil, err + } + if pkt, err = d.client.ReceivePacket(); err != nil { + return nil, err + } + if err = pkt.Unmarshal(powerInfo); err != nil { + return nil, err + } + return +} diff --git a/idevice.go b/idevice.go index 3da5147..7f07dcf 100644 --- a/idevice.go +++ b/idevice.go @@ -67,6 +67,7 @@ type Device interface { Reboot() error Shutdown() error + PowerSource() (powerInfo interface{}, err error) crashReportMoverService() (crashReportMover CrashReportMover, err error) MoveCrashReport(hostDir string, opts ...CrashReportMoverOption) (err error) @@ -234,6 +235,7 @@ type Perfd interface { type DiagnosticsRelay interface { Reboot() error Shutdown() error + PowerSource() (powerInfo interface{}, err error) } type WebInspector interface { diff --git a/pkg/libimobiledevice/diagnosticsrelay.go b/pkg/libimobiledevice/diagnosticsrelay.go index f38b416..0ff0f3b 100644 --- a/pkg/libimobiledevice/diagnosticsrelay.go +++ b/pkg/libimobiledevice/diagnosticsrelay.go @@ -37,3 +37,7 @@ func (c *DiagnosticsRelayClient) NewXmlPacket(req interface{}) (Packet, error) { func (c *DiagnosticsRelayClient) SendPacket(pkt Packet) (err error) { return c.client.SendPacket(pkt) } + +func (c *DiagnosticsRelayClient) ReceivePacket() (respPkt Packet, err error) { + return c.client.ReceivePacket() +}