Skip to content

Commit

Permalink
* fixed: device deployment -- fails to pick exact device if multiple …
Browse files Browse the repository at this point in the history
…is connected (#759)

also removing duplicates if both Network and USB connection available to same device
  • Loading branch information
dkimitsa authored Nov 9, 2023
1 parent 6d8bfc9 commit d2adb2f
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -728,18 +728,16 @@ public static void main(String[] args) throws Exception {
}

if (deviceId == null) {
if (deviceId == null) {
String[] udids = IDevice.listUdids();
if (udids.length == 0) {
System.err.println("No device connected");
return;
}
if (udids.length > 1) {
System.err.println("More than 1 device connected ("
+ Arrays.asList(udids) + "). Using " + udids[0]);
}
deviceId = udids[0];
String[] udids = IDevice.listUdids();
if (udids.length == 0) {
System.err.println("No device connected");
return;
}
if (udids.length > 1) {
System.err.println("More than 1 device connected ("
+ Arrays.asList(udids) + "). Using " + udids[0]);
}
deviceId = udids[0];
}

try (IDevice device = new IDevice(deviceId)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
package org.robovm.libimobiledevice;

import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

import org.robovm.libimobiledevice.binding.*;

Expand Down Expand Up @@ -133,11 +135,11 @@ public static String[] listUdids() {
checkResult(LibIMobileDevice.idevice_get_device_list_extended(devicesOut, countOut));
IDeviceInfoArray devices = devicesOut.getValue();
int count = countOut.getValue();
String[] udids = new String[count];
Set<String> udids = new LinkedHashSet<>();
for (int i = 0; i < count; i++) {
udids[i] = devices.get(i).getUdid();
udids.add(devices.get(i).getUdid());
}
return udids;
return udids.toArray(new String[0]);
} catch (LibIMobileDeviceException e) {
if (e.getErrorCode() == IDeviceError.IDEVICE_E_NO_DEVICE.swigValue()) {
// This happens when usbmuxd isn't running
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,18 +331,16 @@ public static void main(String[] args) throws Exception {
}

if (deviceId == null) {
if (deviceId == null) {
String[] udids = IDevice.listUdids();
if (udids.length == 0) {
System.err.println("No device connected");
return;
}
if (udids.length > 1) {
System.err.println("More than 1 device connected ("
+ Arrays.asList(udids) + "). Using " + udids[0]);
}
deviceId = udids[0];
String[] udids = IDevice.listUdids();
if (udids.length == 0) {
System.err.println("No device connected");
return;
}
if (udids.length > 1) {
System.err.println("More than 1 device connected ("
+ Arrays.asList(udids) + "). Using " + udids[0]);
}
deviceId = udids[0];
}

try (IDevice device = new IDevice(deviceId)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,18 +249,16 @@ public static void main(String[] args) throws Exception {
}

if (deviceId == null) {
if (deviceId == null) {
String[] udids = IDevice.listUdids();
if (udids.length == 0) {
System.err.println("No device connected");
return;
}
if (udids.length > 1) {
System.err.println("More than 1 device connected ("
+ Arrays.asList(udids) + "). Using " + udids[0]);
}
deviceId = udids[0];
String[] udids = IDevice.listUdids();
if (udids.length == 0) {
System.err.println("No device connected");
return;
}
if (udids.length > 1) {
System.err.println("More than 1 device connected ("
+ Arrays.asList(udids) + "). Using " + udids[0]);
}
deviceId = udids[0];
}

try (IDevice device = new IDevice(deviceId)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ private IDevice waitForDevice(String deviceUdid) throws Exception{
if (udids.length == 1 && (deviceUdid == null || deviceUdid.equals(udids[0]))) {
// single device and it's a match
return new IDevice(udids[0]);
} else if (udids.length > 1 && deviceUdid != null && Arrays.asList(udids).contains(deviceUdid)) {
// multiple devices connected but specified is there
return new IDevice(deviceUdid);
}

String message;
Expand Down

0 comments on commit d2adb2f

Please sign in to comment.