11
11
#include < thread>
12
12
13
13
#include " CommonFunctions.h"
14
+ #include " DevicectlHelper.h"
15
+
14
16
#include " Constants.h"
15
17
#include " Declarations.h"
16
18
#include " FileHelper.h"
@@ -530,6 +532,7 @@ ServiceInfo start_debug_server(std::string device_identifier, std::string ddi,
530
532
method_id, false , false );
531
533
532
534
#ifndef _WIN32
535
+
533
536
// mount_image is not available on Windows
534
537
if (!info.socket && mount_image (device_identifier, ddi, method_id)) {
535
538
info = start_secure_service (device_identifier, kNewDebugServer , method_id,
@@ -1425,6 +1428,23 @@ bool validate_device_id_and_attrs(const json &j, std::string method_id,
1425
1428
return true ;
1426
1429
}
1427
1430
1431
+ bool check_xcode_major_version (int version, std::string device_identifier, std::string method_id){
1432
+ #ifdef _WIN32
1433
+ print_error (" Not supported on windows" , device_identifier, method_id,
1434
+ kApplicationsCustomError );
1435
+ return false ;
1436
+ #else
1437
+ if (get_xcode_major_version ()>=version){
1438
+ return true ;
1439
+ } else {
1440
+ std::string message = " Xcode version of at least " + std::to_string (version) + " is required" ;
1441
+ print_error (message.c_str (), device_identifier, method_id,
1442
+ kApplicationsCustomError );
1443
+ return false ;
1444
+ }
1445
+ #endif
1446
+ }
1447
+
1428
1448
void stop_app (std::string device_identifier, std::string application_identifier,
1429
1449
std::string ddi, std::string method_id) {
1430
1450
if (!devices.count (device_identifier)) {
@@ -1434,37 +1454,54 @@ void stop_app(std::string device_identifier, std::string application_identifier,
1434
1454
}
1435
1455
1436
1456
std::map<std::string, std::map<std::string, std::string>> map;
1437
- if (get_all_apps (device_identifier, map)) {
1438
- if (map.count (application_identifier) == 0 ) {
1439
- print_error (" Application not installed" , device_identifier, method_id,
1440
- kApplicationsCustomError );
1441
- return ;
1442
- }
1443
-
1444
- long service_count = devices[device_identifier].services .size ();
1445
- ServiceInfo gdb = start_debug_server (device_identifier, ddi, method_id);
1446
- if (!gdb.socket ) {
1447
- print_error (" Unable to start gdb server" , device_identifier, method_id,
1448
- kUnexpectedError );
1449
- return ;
1457
+ if (get_all_apps (device_identifier, map)) {
1458
+ if (map.count (application_identifier) == 0 ) {
1459
+ print_error (" Application not installed" , device_identifier, method_id,
1460
+ kApplicationsCustomError );
1461
+ return ;
1462
+ }
1463
+ if (get_product_version (device_identifier) < 17 ){
1464
+ long service_count = devices[device_identifier].services .size ();
1465
+ ServiceInfo gdb = start_debug_server (device_identifier, ddi, method_id);
1466
+ if (!gdb.socket ) {
1467
+ print_error (" Unable to start gdb server" , device_identifier, method_id,
1468
+ kUnexpectedError );
1469
+ return ;
1470
+ }
1471
+
1472
+ std::string executable = map[application_identifier][kPathPascalCase ];
1473
+ if (devices[device_identifier].services .size () == service_count ||
1474
+ stop_application (executable, gdb, application_identifier,
1475
+ devices[device_identifier].apps_cache ))
1476
+ print (json ({{kResponse , " Successfully stopped application" },
1477
+ {kId , method_id},
1478
+ {kDeviceId , device_identifier}}));
1479
+ else
1480
+ print_error (" Could not stop application" , device_identifier, method_id,
1481
+ kApplicationsCustomError );
1482
+
1483
+ detach_connection (gdb, &devices[device_identifier]);
1484
+ } else {
1485
+ if (check_xcode_major_version (15 , device_identifier, method_id)){
1486
+ std::string executable = map[application_identifier][kPathPascalCase ];
1487
+ std::string CFBundleExecutableString =map[application_identifier][" CFBundleExecutable" ];
1488
+
1489
+ std::string fullPidPath =executable + " /" + CFBundleExecutableString;
1490
+ if (devicectl_stop_application (fullPidPath, device_identifier)){
1491
+
1492
+ print (json ({{kResponse , " Successfully stopped application" },
1493
+ {kId , method_id},
1494
+ {kDeviceId , device_identifier}}));
1495
+ } else {
1496
+ print_error (" Could not stop application" , device_identifier, method_id,
1497
+ kApplicationsCustomError );
1498
+ }
1499
+ }
1500
+ }
1501
+ } else {
1502
+ print_error (" Lookup applications failed" , device_identifier, method_id,
1503
+ kApplicationsCustomError );
1450
1504
}
1451
-
1452
- std::string executable = map[application_identifier][kPathPascalCase ];
1453
- if (devices[device_identifier].services .size () == service_count ||
1454
- stop_application (executable, gdb, application_identifier,
1455
- devices[device_identifier].apps_cache ))
1456
- print (json ({{kResponse , " Successfully stopped application" },
1457
- {kId , method_id},
1458
- {kDeviceId , device_identifier}}));
1459
- else
1460
- print_error (" Could not stop application" , device_identifier, method_id,
1461
- kApplicationsCustomError );
1462
-
1463
- detach_connection (gdb, &devices[device_identifier]);
1464
- } else {
1465
- print_error (" Lookup applications failed" , device_identifier, method_id,
1466
- kApplicationsCustomError );
1467
- }
1468
1505
}
1469
1506
1470
1507
void start_app (std::string device_identifier,
@@ -1483,23 +1520,34 @@ void start_app(std::string device_identifier,
1483
1520
kApplicationsCustomError );
1484
1521
return ;
1485
1522
}
1486
-
1487
- ServiceInfo gdb = start_debug_server (device_identifier, ddi, method_id);
1488
- if (!gdb.socket ) {
1489
- return ;
1490
- }
1491
-
1492
- std::string executable = map[application_identifier][kPathPascalCase ] +
1493
- " /" +
1494
- map[application_identifier][" CFBundleExecutable" ];
1495
- if (run_application (executable, gdb, application_identifier,
1496
- &devices[device_identifier], wait_for_debugger))
1497
- print (json ({{kResponse , " Successfully started application" },
1523
+ if ( get_product_version (device_identifier) < 17 ){
1524
+ ServiceInfo gdb = start_debug_server (device_identifier, ddi, method_id);
1525
+ if (!gdb.socket ) {
1526
+ return ;
1527
+ }
1528
+
1529
+ std::string executable = map[application_identifier][kPathPascalCase ] +
1530
+ " /" +
1531
+ map[application_identifier][" CFBundleExecutable" ];
1532
+ if (run_application (executable, gdb, application_identifier,
1533
+ &devices[device_identifier], wait_for_debugger))
1534
+ print (json ({{kResponse , " Successfully started application" },
1498
1535
{kId , method_id},
1499
1536
{kDeviceId , device_identifier}}));
1500
- else
1501
- print_error (" Could not start application" , device_identifier, method_id,
1502
- kApplicationsCustomError );
1537
+ else
1538
+ print_error (" Could not start application" , device_identifier, method_id,
1539
+ kApplicationsCustomError );
1540
+ } else {
1541
+ if (check_xcode_major_version (15 , device_identifier, method_id)){
1542
+ if (devicectl_start_application (application_identifier, device_identifier, wait_for_debugger))
1543
+ print (json ({{kResponse , " Successfully started application" },
1544
+ {kId , method_id},
1545
+ {kDeviceId , device_identifier}}));
1546
+ else
1547
+ print_error (" Could not start application" , device_identifier, method_id,
1548
+ kApplicationsCustomError );
1549
+ }
1550
+ }
1503
1551
} else {
1504
1552
print_error (" Lookup applications failed" , device_identifier, method_id,
1505
1553
kApplicationsCustomError );
@@ -1576,6 +1624,7 @@ void connect_to_port(std::string device_identifier, int port,
1576
1624
}
1577
1625
}
1578
1626
1627
+
1579
1628
int main () {
1580
1629
#ifdef _WIN32
1581
1630
_setmode (_fileno (stdout), _O_BINARY);
0 commit comments