diff --git a/device.go b/device.go index e116bc7..6d3d83e 100644 --- a/device.go +++ b/device.go @@ -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 diff --git a/idevice.go b/idevice.go index 990e166..26c5df1 100644 --- a/idevice.go +++ b/idevice.go @@ -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) @@ -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 diff --git a/pkg/libimobiledevice/springboard.go b/pkg/libimobiledevice/springboard.go index 4ab2410..f3529c7 100644 --- a/pkg/libimobiledevice/springboard.go +++ b/pkg/libimobiledevice/springboard.go @@ -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" ) diff --git a/springboard.go b/springboard.go index b916e80..0a87042 100644 --- a/springboard.go +++ b/springboard.go @@ -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 +} diff --git a/springboard_test.go b/springboard_test.go index 973391a..9fd3ac5 100644 --- a/springboard_test.go +++ b/springboard_test.go @@ -1,6 +1,7 @@ package giDevice import ( + "fmt" "image" "image/jpeg" "image/png" @@ -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) @@ -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()) +}