Skip to content

Commit f723a44

Browse files
committed
tools/idevicedevmodectl: Fix action success check and device reboot detection
1 parent 4cb84a7 commit f723a44

File tree

1 file changed

+25
-17
lines changed

1 file changed

+25
-17
lines changed

tools/idevicedevmodectl.c

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ static int amfi_service_send_msg(property_list_service_client_t amfi, plist_t ms
146146
plist_t reply = NULL;
147147
perr = property_list_service_receive_plist(amfi, &reply);
148148
if (perr == PROPERTY_LIST_SERVICE_E_SUCCESS) {
149-
uint8_t success = 0;
150149
plist_t val = plist_dict_get_item(reply, "Error");
151150
if (val) {
152151
const char* err = plist_get_string_ptr(val, NULL);
@@ -157,15 +156,7 @@ static int amfi_service_send_msg(property_list_service_client_t amfi, plist_t ms
157156
res = 1;
158157
}
159158
} else {
160-
val = plist_dict_get_item(reply, "success");
161-
if (val) {
162-
plist_get_bool_val(val, &success);
163-
}
164-
if (success) {
165-
res = 0;
166-
} else {
167-
res = 1;
168-
}
159+
res = plist_dict_get_item(reply, "success") ? 0 : 1;
169160
}
170161
} else {
171162
fprintf(stderr, "Could not receive reply from device: %d\n", perr);
@@ -411,13 +402,30 @@ int main(int argc, char *argv[])
411402
} else {
412403
printf("%s: Developer Mode armed, waiting for reboot...\n", udid);
413404

414-
// waiting for device to disconnect...
415-
WAIT_FOR(!device_connected, 20);
416-
417-
// waiting for device to reconnect...
418-
WAIT_FOR(device_connected, 60);
419-
420-
res = amfi_send_action(device, DEV_MODE_ENABLE);
405+
do {
406+
// waiting for device to disconnect...
407+
idevice_free(device);
408+
device = NULL;
409+
WAIT_FOR(!device_connected, 40);
410+
if (device_connected) {
411+
printf("%s: ERROR: Device didn't reboot?!\n", udid);
412+
res = 2;
413+
break;
414+
}
415+
printf("disconnected\n");
416+
417+
// waiting for device to reconnect...
418+
WAIT_FOR(device_connected, 60);
419+
if (!device_connected) {
420+
printf("%s: ERROR: Device didn't re-connect?!\n", udid);
421+
res = 2;
422+
break;
423+
}
424+
printf("connected\n");
425+
426+
idevice_new(&device, udid);
427+
res = amfi_send_action(device, DEV_MODE_ENABLE);
428+
} while (0);
421429
if (res == 0) {
422430
printf("%s: Developer Mode successfully enabled.\n", udid);
423431
} else {

0 commit comments

Comments
 (0)