@@ -134,6 +134,7 @@ int start_session(std::string& device_identifier)
134134 {
135135 const DeviceInfo* device_info = devices[device_identifier].device_info ;
136136 UNLOCK_MUTEX_AND_RETURN_IF_FAILED_RESULT (AMDeviceConnect (device_info), start_session_mutex);
137+ assert (AMDeviceIsPaired (device_info));
137138 UNLOCK_MUTEX_AND_RETURN_IF_FAILED_RESULT (AMDeviceValidatePairing (device_info), start_session_mutex);
138139 UNLOCK_MUTEX_AND_RETURN_IF_FAILED_RESULT (AMDeviceStartSession (device_info), start_session_mutex);
139140 }
@@ -242,14 +243,26 @@ void get_device_properties(std::string device_identifier, json &result)
242243 result[" deviceName" ] = get_device_property_value (device_identifier, " DeviceName" );
243244 result[" productVersion" ] = get_device_property_value (device_identifier, kProductVersion );
244245 result[" deviceColor" ] = get_device_property_value (device_identifier, " DeviceColor" );
246+ // available values:
247+ // "BluetoothAddress","BoardId","CPUArchitecture","ChipID","DeviceClass",
248+ // "DeviceColor","DeviceName","FirmwareVersion","HardwareModel",
249+ // "ModelNumber","ProductType","ProductVersion","UniqueDeviceID","WiFiAddress"
245250}
246251
247252inline bool has_complete_status (std::map<std::string, boost::any>& dict)
248253{
249254 return boost::any_cast<std::string>(dict[kStatusKey ]) == kComplete ;
250255}
251256
252- void on_device_found (const DevicePointer* device_ptr, std::string device_identifier, std::string eventString, json &result)
257+
258+ void update_device_result (std::string device_identifier, json &result)
259+ {
260+ result[kIsUSBConnected ] = devices[device_identifier].isUSBConnected ;
261+ result[kIsWiFiConnected ] = devices[device_identifier].isWiFiConnected ;
262+ get_device_properties (device_identifier, result);
263+ }
264+
265+ void on_device_found (const DevicePointer* device_ptr, std::string device_identifier, json &result)
253266{
254267 /*
255268 Interface type can be one of the followings:
@@ -259,10 +272,23 @@ void on_device_found(const DevicePointer* device_ptr, std::string device_identif
259272 2 - wifi interface type
260273 */
261274 int interface_type = AMDeviceGetInterfaceType (device_ptr->device_info );
262- if (interface_type == kUSBInterfaceType ) {
263- devices[device_identifier] = { device_ptr->device_info , nullptr };
264- result[kEventString ] = eventString;
265- get_device_properties (device_identifier, result);
275+ if (interface_type == kUSBInterfaceType || interface_type == kWIFIInterfaceType ) {
276+ if (devices.count (device_identifier)) {
277+ devices[device_identifier].device_info = device_ptr->device_info ;
278+ result[kEventString ] = kDeviceUpdated ;
279+ } else {
280+ devices[device_identifier] = { device_ptr->device_info , nullptr };
281+ result[kEventString ] = kDeviceFound ;
282+ }
283+
284+
285+ if (interface_type == kUSBInterfaceType ) {
286+ devices[device_identifier].isUSBConnected = 1 ;
287+ } else {
288+ devices[device_identifier].isWiFiConnected = 1 ;
289+ }
290+
291+ update_device_result (device_identifier, result);
266292 }
267293}
268294
@@ -275,21 +301,33 @@ void device_notification_callback(const DevicePointer* device_ptr)
275301 {
276302 case kADNCIMessageConnected :
277303 {
278- on_device_found (device_ptr, device_identifier, kDeviceFound , result);
304+ on_device_found (device_ptr, device_identifier, result);
279305 break ;
280306 }
281307 case kADNCIMessageDisconnected :
282308 {
283- if (devices.count (device_identifier))
284- {
285- if (devices[device_identifier].apps_cache .size ())
286- {
287- cleanup_file_resources (device_identifier);
309+ if (devices.count (device_identifier)) {
310+ int interface_type = AMDeviceGetInterfaceType (device_ptr->device_info );
311+ if (interface_type == kUSBInterfaceType ) {
312+ devices[device_identifier].isUSBConnected = 0 ;
313+ } else if (interface_type == kWIFIInterfaceType ) {
314+ devices[device_identifier].isWiFiConnected = 0 ;
288315 }
316+
317+ if (!devices[device_identifier].isUSBConnected && !devices[device_identifier].isWiFiConnected ) {
318+ if (devices[device_identifier].apps_cache .size ())
319+ {
320+ cleanup_file_resources (device_identifier);
321+ }
289322
290- devices.erase (device_identifier);
323+ devices.erase (device_identifier);
324+ result[kEventString ] = kDeviceLost ;
325+ } else {
326+ result[kEventString ] = kDeviceUpdated ;
327+ update_device_result (device_identifier, result);
328+ }
291329 }
292- result[ kEventString ] = kDeviceLost ;
330+
293331 break ;
294332 }
295333 case kADNCIMessageUnknown :
@@ -299,7 +337,7 @@ void device_notification_callback(const DevicePointer* device_ptr)
299337 }
300338 case kADNCIMessageTrusted :
301339 {
302- on_device_found (device_ptr, device_identifier, kDeviceTrusted , result);
340+ on_device_found (device_ptr, device_identifier, result);
303341 break ;
304342 }
305343 }
@@ -497,14 +535,16 @@ void uninstall_application(std::string application_identifier, std::string devic
497535 return ;
498536 }
499537
500- HANDLE socket = start_secure_service (device_identifier, kInstallationProxy , method_id, true , false ). socket ;
501- if (!socket)
538+ ServiceInfo serviceInfo = start_secure_service (device_identifier, kInstallationProxy , method_id, true , false );
539+ if (!serviceInfo. socket )
502540 {
503541 return ;
504542 }
505543
506544 CFStringRef appid_cfstring = create_CFString (application_identifier.c_str ());
507- unsigned result = AMDeviceUninstallApplication (socket, appid_cfstring, NULL , [] {}, NULL );
545+ DeviceInfo* deviceInfo = devices[device_identifier].device_info ;
546+ CFDictionaryRef params = CFDictionaryCreate (NULL , {}, {}, 0 , NULL , NULL );
547+ unsigned result = AMDeviceSecureUninstallApplication (serviceInfo.connection , deviceInfo, appid_cfstring, params, NULL );
508548 CFRelease (appid_cfstring);
509549
510550 if (result)
@@ -1137,7 +1177,7 @@ void post_notification(std::string device_identifier, PostNotificationInfo post_
11371177void await_notification_response (std::string device_identifier, AwaitNotificationResponseInfo await_notification_response_info, std::string method_id)
11381178{
11391179 ServiceConnRef connection = serviceConnections[(int )await_notification_response_info.socket ];
1140- std::string invalid_connection_error_message = " Invalid connectionId : " + std::to_string (await_notification_response_info.socket );
1180+ std::string invalid_connection_error_message = " Invalid socket : " + std::to_string (await_notification_response_info.socket );
11411181 PRINT_ERROR_AND_RETURN_IF_FAILED_RESULT (connection == nullptr , invalid_connection_error_message.c_str (), device_identifier, method_id);
11421182
11431183 ServiceInfo currentNotificationProxy = devices[device_identifier].services [kNotificationProxy ];
0 commit comments