1111#include < thread>
1212
1313#include " CommonFunctions.h"
14+ #include " DevicectlHelper.h"
15+
1416#include " Constants.h"
1517#include " Declarations.h"
1618#include " FileHelper.h"
@@ -530,6 +532,7 @@ ServiceInfo start_debug_server(std::string device_identifier, std::string ddi,
530532 method_id, false , false );
531533
532534#ifndef _WIN32
535+
533536 // mount_image is not available on Windows
534537 if (!info.socket && mount_image (device_identifier, ddi, method_id)) {
535538 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,
14251428 return true ;
14261429}
14271430
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+
14281448void stop_app (std::string device_identifier, std::string application_identifier,
14291449 std::string ddi, std::string method_id) {
14301450 if (!devices.count (device_identifier)) {
@@ -1434,37 +1454,54 @@ void stop_app(std::string device_identifier, std::string application_identifier,
14341454 }
14351455
14361456 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 );
14501504 }
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- }
14681505}
14691506
14701507void start_app (std::string device_identifier,
@@ -1483,23 +1520,34 @@ void start_app(std::string device_identifier,
14831520 kApplicationsCustomError );
14841521 return ;
14851522 }
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" },
14981535 {kId , method_id},
14991536 {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+ }
15031551 } else {
15041552 print_error (" Lookup applications failed" , device_identifier, method_id,
15051553 kApplicationsCustomError );
@@ -1576,6 +1624,7 @@ void connect_to_port(std::string device_identifier, int port,
15761624 }
15771625}
15781626
1627+
15791628int main () {
15801629#ifdef _WIN32
15811630 _setmode (_fileno (stdout), _O_BINARY);
0 commit comments