Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions ios/listdevices.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"fmt"
"strings"
"time"

plist "howett.net/plist"
)
Expand Down Expand Up @@ -102,9 +103,47 @@ func (muxConn *UsbMuxConnection) ListDevices() (DeviceList, error) {
if err != nil {
return DeviceList{}, fmt.Errorf("Failed getting devicelist: %v", err)
}
muxResponse := MuxResponsefromBytes(response.Payload)
if muxResponse.Number == 0xffffffff {
// get list of devices from Listen
// this is a workaround for the case where connected devices more than 34
return muxConn.ListDevicesFromListen()
}
return DeviceListfromBytes(response.Payload), nil
}

func (muxConn *UsbMuxConnection) ListDevicesFromListen() (DeviceList, error) {
attachedReceiver, err := muxConn.Listen()
if err != nil {
return DeviceList{}, fmt.Errorf("Failed to start listening: %v", err)
}
defer muxConn.Close()

deviceEntryChan := make(chan DeviceEntry)
go func() {
for {
msg, err := attachedReceiver()
if err != nil {
break
}
if msg.DeviceAttached() {
deviceEntryChan <- msg.DeviceEntry()
}
}
}()
var deviceList = DeviceList{
DeviceList: make([]DeviceEntry, 0, 40),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why was 34 a limit? and why put 40 as the new limit?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In most conditions, phone number is bellow 40 (from my experience).

}
for {
select {
case entry := <-deviceEntryChan:
deviceList.DeviceList = append(deviceList.DeviceList, entry)
case <-time.After(100 * time.Millisecond):
return deviceList, nil
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is 100ms the only way to know we have reached the last device? such absolute timing can be random when dealing with services. what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

em.. do you have some better way?

}
}
}

// ListDevices returns a DeviceList containing data about all
// currently connected iOS devices using a new UsbMuxConnection
func ListDevices() (DeviceList, error) {
Expand Down
6 changes: 5 additions & 1 deletion ios/mobileactivation/activation.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package mobileactivation

import (
"fmt"
"io"
"net/url"
"strings"
Expand Down Expand Up @@ -77,7 +78,10 @@ func Activate(device ios.DeviceEntry) error {
return err
}
log.Debugf("CreateTunnel1SessionInfoRequest resp: %v", resp)
val := resp["Value"].(map[string]interface{})
val, ok := resp["Value"].(map[string]interface{})
if !ok {
return fmt.Errorf("expected 'Value' to be a map, got nil or wrong type")
}

handshakeRequestMessage := val["HandshakeRequestMessage"].([]byte)
log.Debugf("HandshakeRequestMessage: %v", handshakeRequestMessage)
Expand Down
Loading