@@ -134,6 +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
138
UNLOCK_MUTEX_AND_RETURN_IF_FAILED_RESULT (AMDeviceValidatePairing (device_info), start_session_mutex);
138
139
UNLOCK_MUTEX_AND_RETURN_IF_FAILED_RESULT (AMDeviceStartSession (device_info), start_session_mutex);
139
140
}
@@ -242,14 +243,26 @@ void get_device_properties(std::string device_identifier, json &result)
242
243
result[" deviceName" ] = get_device_property_value (device_identifier, " DeviceName" );
243
244
result[" productVersion" ] = get_device_property_value (device_identifier, kProductVersion );
244
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"
245
250
}
246
251
247
252
inline bool has_complete_status (std::map<std::string, boost::any>& dict)
248
253
{
249
254
return boost::any_cast<std::string>(dict[kStatusKey ]) == kComplete ;
250
255
}
251
256
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)
253
266
{
254
267
/*
255
268
Interface type can be one of the followings:
@@ -259,10 +272,23 @@ void on_device_found(const DevicePointer* device_ptr, std::string device_identif
259
272
2 - wifi interface type
260
273
*/
261
274
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);
266
292
}
267
293
}
268
294
@@ -275,21 +301,33 @@ void device_notification_callback(const DevicePointer* device_ptr)
275
301
{
276
302
case kADNCIMessageConnected :
277
303
{
278
- on_device_found (device_ptr, device_identifier, kDeviceFound , result);
304
+ on_device_found (device_ptr, device_identifier, result);
279
305
break ;
280
306
}
281
307
case kADNCIMessageDisconnected :
282
308
{
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 ;
288
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
+ }
289
322
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
+ }
291
329
}
292
- result[ kEventString ] = kDeviceLost ;
330
+
293
331
break ;
294
332
}
295
333
case kADNCIMessageUnknown :
@@ -299,7 +337,7 @@ void device_notification_callback(const DevicePointer* device_ptr)
299
337
}
300
338
case kADNCIMessageTrusted :
301
339
{
302
- on_device_found (device_ptr, device_identifier, kDeviceTrusted , result);
340
+ on_device_found (device_ptr, device_identifier, result);
303
341
break ;
304
342
}
305
343
}
@@ -497,14 +535,16 @@ void uninstall_application(std::string application_identifier, std::string devic
497
535
return ;
498
536
}
499
537
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 )
502
540
{
503
541
return ;
504
542
}
505
543
506
544
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 );
508
548
CFRelease (appid_cfstring);
509
549
510
550
if (result)
@@ -1137,7 +1177,7 @@ void post_notification(std::string device_identifier, PostNotificationInfo post_
1137
1177
void await_notification_response (std::string device_identifier, AwaitNotificationResponseInfo await_notification_response_info, std::string method_id)
1138
1178
{
1139
1179
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 );
1141
1181
PRINT_ERROR_AND_RETURN_IF_FAILED_RESULT (connection == nullptr , invalid_connection_error_message.c_str (), device_identifier, method_id);
1142
1182
1143
1183
ServiceInfo currentNotificationProxy = devices[device_identifier].services [kNotificationProxy ];
0 commit comments