Skip to content

Commit

Permalink
Add support for userspace reboot
Browse files Browse the repository at this point in the history
the default stays a full reboot
  • Loading branch information
dmissmann committed Dec 19, 2023
1 parent 0c3b53b commit be91343
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions ios/appservice/appservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/google/uuid"
"howett.net/plist"
"io"
"net"
"path"
"syscall"
)
Expand All @@ -18,6 +19,11 @@ type Connection struct {
deviceId string
}

const (
RebootFull = "full"
RebootUserspace = "userspace"
)

func New(deviceEntry ios.DeviceEntry) (*Connection, error) {
xpcConn, err := ios.ConnectToXpcServiceTunnelIface(deviceEntry, "com.apple.coredevice.appservice")
if err != nil {
Expand Down Expand Up @@ -112,8 +118,13 @@ func (c *Connection) KillProcess(pid int) error {
return nil
}

// Reboot performs a full reboot of the device
func (c *Connection) Reboot() error {
err := c.conn.Send(buildRebootPayload(c.deviceId))
return c.RebootWithStyle(RebootFull)
}

func (c *Connection) RebootWithStyle(style string) error {
err := c.conn.Send(buildRebootPayload(c.deviceId, style))
if err != nil {
return err
}
Expand All @@ -122,6 +133,10 @@ func (c *Connection) Reboot() error {
if errors.Is(err, io.EOF) {
return nil
}
var opErr *net.OpError
if errors.As(err, &opErr) && opErr.Timeout() {
return nil
}
return err
}
return getError(m)
Expand Down Expand Up @@ -161,10 +176,10 @@ func buildListProcessesPayload(deviceId string) map[string]interface{} {
return buildRequest(deviceId, "com.apple.coredevice.feature.listprocesses", nil)
}

func buildRebootPayload(deviceId string) map[string]interface{} {
func buildRebootPayload(deviceId string, style string) map[string]interface{} {
return buildRequest(deviceId, "com.apple.coredevice.feature.rebootdevice", map[string]interface{}{
"rebootStyle": map[string]interface{}{
"full": map[string]interface{}{},
style: map[string]interface{}{},
},
})
}
Expand Down

0 comments on commit be91343

Please sign in to comment.