@@ -134,7 +134,7 @@ int start_session(std::string& device_identifier)
134
134
{
135
135
const DeviceInfo* device_info = devices[device_identifier].device_info ;
136
136
UNLOCK_MUTEX_AND_RETURN_IF_FAILED_RESULT (AMDeviceConnect (device_info), start_session_mutex);
137
- assert (AMDeviceIsPaired (device_info));
137
+ assert (AMDeviceIsPaired (device_info));
138
138
UNLOCK_MUTEX_AND_RETURN_IF_FAILED_RESULT (AMDeviceValidatePairing (device_info), start_session_mutex);
139
139
UNLOCK_MUTEX_AND_RETURN_IF_FAILED_RESULT (AMDeviceStartSession (device_info), start_session_mutex);
140
140
}
@@ -243,18 +243,26 @@ void get_device_properties(std::string device_identifier, json &result)
243
243
result[" deviceName" ] = get_device_property_value (device_identifier, " DeviceName" );
244
244
result[" productVersion" ] = get_device_property_value (device_identifier, kProductVersion );
245
245
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"
246
+ // available values:
247
+ // "BluetoothAddress","BoardId","CPUArchitecture","ChipID","DeviceClass",
248
+ // "DeviceColor","DeviceName","FirmwareVersion","HardwareModel",
249
+ // "ModelNumber","ProductType","ProductVersion","UniqueDeviceID","WiFiAddress"
250
250
}
251
251
252
252
inline bool has_complete_status (std::map<std::string, boost::any>& dict)
253
253
{
254
254
return boost::any_cast<std::string>(dict[kStatusKey ]) == kComplete ;
255
255
}
256
256
257
- 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)
258
266
{
259
267
/*
260
268
Interface type can be one of the followings:
@@ -265,11 +273,23 @@ void on_device_found(const DevicePointer* device_ptr, std::string device_identif
265
273
*/
266
274
int interface_type = AMDeviceGetInterfaceType (device_ptr->device_info );
267
275
if (interface_type == kUSBInterfaceType || interface_type == kWIFIInterfaceType ) {
268
- devices[device_identifier] = { device_ptr->device_info , nullptr };
269
- result[kEventString ] = eventString;
270
- result[kConnectionType ] = interface_type;
271
- get_device_properties (device_identifier, result);
272
- }
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);
292
+ }
273
293
}
274
294
275
295
void device_notification_callback (const DevicePointer* device_ptr)
@@ -281,21 +301,33 @@ void device_notification_callback(const DevicePointer* device_ptr)
281
301
{
282
302
case kADNCIMessageConnected :
283
303
{
284
- on_device_found (device_ptr, device_identifier, kDeviceFound , result);
304
+ on_device_found (device_ptr, device_identifier, result);
285
305
break ;
286
306
}
287
307
case kADNCIMessageDisconnected :
288
308
{
289
- if (devices.count (device_identifier))
290
- {
291
- if (devices[device_identifier].apps_cache .size ())
292
- {
293
- 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 ;
294
315
}
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
+ }
295
322
296
- 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
+ }
297
329
}
298
- result[ kEventString ] = kDeviceLost ;
330
+
299
331
break ;
300
332
}
301
333
case kADNCIMessageUnknown :
@@ -305,7 +337,7 @@ void device_notification_callback(const DevicePointer* device_ptr)
305
337
}
306
338
case kADNCIMessageTrusted :
307
339
{
308
- on_device_found (device_ptr, device_identifier, kDeviceTrusted , result);
340
+ on_device_found (device_ptr, device_identifier, result);
309
341
break ;
310
342
}
311
343
}
@@ -510,9 +542,9 @@ void uninstall_application(std::string application_identifier, std::string devic
510
542
}
511
543
512
544
CFStringRef appid_cfstring = create_CFString (application_identifier.c_str ());
513
- DeviceInfo* deviceInfo = devices[device_identifier].device_info ;
514
- CFDictionaryRef params = CFDictionaryCreate (NULL , {}, {}, 0 , NULL , NULL );
515
- unsigned result = AMDeviceSecureUninstallApplication (serviceInfo.connection , deviceInfo, appid_cfstring, params, 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 );
516
548
CFRelease (appid_cfstring);
517
549
518
550
if (result)
0 commit comments