Skip to content

Commit

Permalink
add PowerSource
Browse files Browse the repository at this point in the history
  • Loading branch information
aoliaoaoaojiao committed Dec 7, 2022
1 parent d0e5002 commit 768e875
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 1 deletion.
13 changes: 13 additions & 0 deletions device.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions device_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
27 changes: 26 additions & 1 deletion diagnosticsrelay.go
Original file line number Diff line number Diff line change
@@ -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{
Expand Down Expand Up @@ -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
}
2 changes: 2 additions & 0 deletions idevice.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -234,6 +235,7 @@ type Perfd interface {
type DiagnosticsRelay interface {
Reboot() error
Shutdown() error
PowerSource() (powerInfo interface{}, err error)
}

type WebInspector interface {
Expand Down
4 changes: 4 additions & 0 deletions pkg/libimobiledevice/diagnosticsrelay.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

0 comments on commit 768e875

Please sign in to comment.