Skip to content

Commit

Permalink
feat: [SpringBoard] support get the orientation of the interface
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhouYixun authored Jun 13, 2022
1 parent 7a55b76 commit e787834
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 1 deletion.
10 changes: 10 additions & 0 deletions device.go
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,16 @@ func (d *device) GetIconPNGData(bundleId string) (raw *bytes.Buffer, err error)
return
}

func (d *device) GetInterfaceOrientation() (orientation libimobiledevice.OrientationState, err error) {
if _, err = d.springBoardService(); err != nil {
return
}
if orientation, err = d.springBoard.GetInterfaceOrientation(); err != nil {
return
}
return
}

func (d *device) PcapdService() (pcapd Pcapd, err error) {
// if d.pcapd != nil {
// return d.pcapd, nil
Expand Down
4 changes: 4 additions & 0 deletions idevice.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,13 @@ type Device interface {

springBoardService() (springBoard SpringBoard, err error)
GetIconPNGData(bundleId string) (raw *bytes.Buffer, err error)
GetInterfaceOrientation() (orientation OrientationState, err error)
}

type DeviceProperties = libimobiledevice.DeviceProperties

type OrientationState = libimobiledevice.OrientationState

type Lockdown interface {
QueryType() (LockdownType, error)
GetValue(domain, key string) (v interface{}, err error)
Expand Down Expand Up @@ -226,6 +229,7 @@ type CrashReportMover interface {

type SpringBoard interface {
GetIconPNGData(bundleId string) (raw *bytes.Buffer, err error)
GetInterfaceOrientation() (orientation OrientationState, err error)
}

type InnerConn = libimobiledevice.InnerConn
Expand Down
14 changes: 14 additions & 0 deletions pkg/libimobiledevice/springboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@ type IconPNGDataResponse struct {
PNGData []byte `plist:"pngData"`
}

type InterfaceOrientationResponse struct {
Orientation OrientationState `plist:"interfaceOrientation"`
}

type OrientationState int64

const (
Unknown OrientationState = iota
Portrait
PortraitUpsideDown
LandscapeLeft
LandscapeRight
)

const (
SpringBoardServiceName = "com.apple.springboardservices"
)
Expand Down
23 changes: 23 additions & 0 deletions springboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,26 @@ func (s springboard) GetIconPNGData(bundleId string) (raw *bytes.Buffer, err err
}
return
}

func (s springboard) GetInterfaceOrientation() (orientation libimobiledevice.OrientationState, err error) {
var pkt libimobiledevice.Packet
req := map[string]interface{}{
"command": "getInterfaceOrientation",
}
if pkt, err = s.client.NewBinaryPacket(req); err != nil {
return
}
if err = s.client.SendPacket(pkt); err != nil {
return 0, err
}
var respPkt libimobiledevice.Packet
if respPkt, err = s.client.ReceivePacket(); err != nil {
return 0, err
}
var reply libimobiledevice.InterfaceOrientationResponse
if err = respPkt.Unmarshal(&reply); err != nil {
return 0, fmt.Errorf("receive packet: %w", err)
}
orientation = reply.Orientation
return
}
8 changes: 7 additions & 1 deletion springboard_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package giDevice

import (
"fmt"
"image"
"image/jpeg"
"image/png"
Expand All @@ -23,7 +24,7 @@ func setupSpringBoardSrv(t *testing.T) {
}
}

func Test_springBoard(t *testing.T) {
func Test_springBoard_GetIcon(t *testing.T) {
setupSpringBoardSrv(t)
raw, _ := springBoardSrv.GetIconPNGData("com.tencent.xin")
img, format, err := image.Decode(raw)
Expand All @@ -45,3 +46,8 @@ func Test_springBoard(t *testing.T) {
t.Fatal(err)
}
}

func Test_springBoard_GetOrient(t *testing.T) {
setupSpringBoardSrv(t)
fmt.Println(springBoardSrv.GetInterfaceOrientation())
}

0 comments on commit e787834

Please sign in to comment.