From f86adff1fdf6ea7626937c83825c0c6b230da55d Mon Sep 17 00:00:00 2001 From: "saerome.kim" Date: Wed, 20 Nov 2019 20:18:00 +0900 Subject: Fix crash of ua-test app. - Problem: The crash happened when reusing one after destroying the device. - Cause: Use the device handle of the device list directly without cloning. - Solution: Clone the device handle before manipulation. Change-Id: I47d640c56ca8063e2038debf1f6427beefc587a1 Signed-off-by: saerome.kim --- include/user-awareness-private.h | 18 +++++++++--------- include/user-awareness.h | 8 ++++---- packaging/capi-network-ua.spec | 2 +- src/user-awareness-device.c | 8 ++++---- src/user-awareness-event-handler.c | 4 ++-- src/user-awareness-monitors.c | 8 ++++---- src/user-awareness-service.c | 2 +- src/user-awareness-users.c | 18 +++++++++--------- test/uat-devices.c | 6 ++++-- test/uat-service.c | 12 ++++++------ test/uat-users.c | 12 ++++++------ 11 files changed, 50 insertions(+), 48 deletions(-) diff --git a/include/user-awareness-private.h b/include/user-awareness-private.h index 0cd5353..4acb15c 100644 --- a/include/user-awareness-private.h +++ b/include/user-awareness-private.h @@ -258,7 +258,7 @@ typedef struct { gboolean isadded; /**< Is the user addition completed? */ gboolean default_user; /**< Is it a default user? */ gboolean create_by_app; /**< Did app add this user information? */ - unsigned long long last_presence_timestamp; /**< timestamp of last presence */ + unsigned long long last_seen; /**< The time of last presence */ } ua_user_info_s; /** @@ -315,7 +315,7 @@ typedef struct { gboolean isadded; /**< Is the device addition completed? */ gboolean create_by_app; /**< Did app add this device information? */ gboolean discriminant; /**< Determines whether to judge PRESENCE/ABSENCE */ - unsigned long long last_presence_timestamp; /**< timestamp of last presence */ + unsigned long long last_seen; /**< The time of last presence */ ua_ble_payload_s *payload; /**< BLE payload to filter device*/ } ua_dev_info_s; @@ -357,8 +357,7 @@ void _ua_monitor_handle_scan_complete(int result); * @post */ void _ua_monitor_handle_user_presence_detected(uam_sensor_info_s *sensor_info, - char *service, char *account, - unsigned long long timestamp, char *device_id); + char *service, char *account, unsigned long long timestamp, char *device_id); /** * @brief Stops monitoring detection. @@ -371,7 +370,8 @@ void _ua_monitor_handle_user_presence_detected(uam_sensor_info_s *sensor_info, * @pre * @post */ -void _ua_monitor_handle_detection_stopped(char *svc_name, uam_cycle_state_e cycle_state); +void _ua_monitor_handle_detection_stopped(char *svc_name, + uam_cycle_state_e cycle_state); /** * @brief Changes sensor state. @@ -900,11 +900,11 @@ int _ua_intr_get_default_user(void); ua_user_h _ua_get_user_handle_by_account(const char *account); /** - * @brief set last presence timestamp in user handle. + * @brief set last presence time in user handle. * @since_tizen 5.5 * * @param[in] user_handle User handle. - * @param[in] timestamp The timestamp to be updated in user handle. + * @param[in] last_seen The lastest time which updated in user handle. * * @return not null on success, otherwise error * @@ -912,8 +912,8 @@ ua_user_h _ua_get_user_handle_by_account(const char *account); * @pre * @post */ -void _ua_set_user_last_presence_timestamp(ua_user_h user_handle, - unsigned long long timestamp); +void _ua_set_user_last_seen(ua_user_h user_handle, + unsigned long long last_seen); /** * @brief Checks whether a device exists in device list. diff --git a/include/user-awareness.h b/include/user-awareness.h index 1148c04..e3a329a 100644 --- a/include/user-awareness.h +++ b/include/user-awareness.h @@ -1525,11 +1525,11 @@ int ua_user_get_name( /** * @ingroup CAPI_NETWORK_UA_MODULE - * @brief Gets last presence timestamp info for user handle. + * @brief Gets last presence time info for user handle. * @since_tizen 5.5 * * @param[in] user_handle The user handle. - * @param[out] timestamp The last presence timestamp information for UA user. + * @param[out] last_seen The last presence time information for UA user. * * @return 0 on success, otherwise a negative error value * @retval #UA_ERROR_NONE Successful @@ -1540,7 +1540,7 @@ int ua_user_get_name( * @post * */ -int ua_user_get_last_presence(ua_user_h user_handle, unsigned long long *timestamp); +int ua_user_get_last_presence(ua_user_h user_handle, unsigned long long *last_seen); /** * @ingroup CAPI_NETWORK_UA_MODULE @@ -3017,7 +3017,7 @@ int ua_sensor_get_timestamp( /** * @ingroup CAPI_NETWORK_UA_MODULE - * @brief Gets sensor's timestamp. + * @brief Gets sensor's bitmask. * @since_tizen 5.5 * * @param[in] sensor_handle The sensor handle diff --git a/packaging/capi-network-ua.spec b/packaging/capi-network-ua.spec index b0040d0..7b1b465 100644 --- a/packaging/capi-network-ua.spec +++ b/packaging/capi-network-ua.spec @@ -1,6 +1,6 @@ Name: capi-network-ua Summary: User Awareness Framework CAPI -Version: 0.13.2 +Version: 0.13.3 Release: 1 License: Apache-2.0 Source0: %{name}-%{version}.tar.gz diff --git a/src/user-awareness-device.c b/src/user-awareness-device.c index 266223d..671fdaa 100644 --- a/src/user-awareness-device.c +++ b/src/user-awareness-device.c @@ -960,7 +960,7 @@ int ua_device_get_last_presence( UA_VALIDATE_INPUT_PARAMETER(timestamp); UA_PRINT_DEVICE_HANDLE(device_handle); - *timestamp = device->last_presence_timestamp; + *timestamp = device->last_seen; FUNC_EXIT; return UA_ERROR_NONE; @@ -1379,7 +1379,7 @@ int ua_device_clone(ua_device_h *cloned, device->type = org_device->type; device->os = org_device->os; device->discriminant = org_device->discriminant; - device->last_presence_timestamp = org_device->last_presence_timestamp; + device->last_seen = org_device->last_seen; if (!device->user) { /* Currently user info will be create and store at this point */ @@ -1504,7 +1504,7 @@ int ua_device_foreach_added( device_info->type = _to_ua_mac_type(ptr->type); device_info->os = ptr->operating_system; device_info->discriminant = ptr->discriminant; - device_info->last_presence_timestamp = ptr->last_seen; + device_info->last_seen = ptr->last_seen; ua_devices_list = g_slist_append(ua_devices_list, device_info); } else { UA_ERR("OPERATION_FAILED(0x%08x)", @@ -1616,7 +1616,7 @@ int ua_device_foreach_added_by_user( device_info->handle = (ua_device_h)device_info; device_info->type = _to_ua_mac_type(ptr->type); device_info->os = ptr->operating_system; - device_info->last_presence_timestamp = ptr->last_seen; + device_info->last_seen = ptr->last_seen; device_info->discriminant = ptr->discriminant; device_info->user = (ua_user_h)user; ua_devices_user_list = g_slist_append(ua_devices_user_list, device_info); diff --git a/src/user-awareness-event-handler.c b/src/user-awareness-event-handler.c index d57f5ed..96c7ad6 100644 --- a/src/user-awareness-event-handler.c +++ b/src/user-awareness-event-handler.c @@ -56,14 +56,14 @@ static void __ua_event_handler(int event, uam_event_data_s *event_param, ret_if(NULL == sensor_info); sensor_info->sensor_bitmask = event_data->sensor_bitmask; - sensor_info->timestamp = event_data->timestamp; + sensor_info->timestamp = event_data->last_seen; UA_INFO("sensor_info: bitmask[%u], timestamp [%llu]", sensor_info->sensor_bitmask, sensor_info->timestamp); _ua_monitor_handle_user_presence_detected( sensor_info, event_data->service, - event_data->account, event_data->timestamp, + event_data->account, event_data->last_seen, event_data->device_id); g_free(sensor_info); diff --git a/src/user-awareness-monitors.c b/src/user-awareness-monitors.c index 4aa57c6..e70e44d 100644 --- a/src/user-awareness-monitors.c +++ b/src/user-awareness-monitors.c @@ -488,7 +488,7 @@ static void __ua_monitor_send_sensor_presence_cb(ua_monitor_s *monitor, } static void __ua_sensor_presence_detected(ua_monitor_s *monitor, - ua_sensor_info_s *sensor_info, char *account, unsigned long long timestamp, + ua_sensor_info_s *sensor_info, char *account, unsigned long long last_seen, char *device_id) { FUNC_ENTRY; @@ -535,7 +535,7 @@ static void __ua_sensor_presence_detected(ua_monitor_s *monitor, device_handle); ua_user_h user_handle = _ua_get_user_handle_by_account(user_state->account); - _ua_set_user_last_presence_timestamp(user_handle, timestamp); + _ua_set_user_last_seen(user_handle, last_seen); } if (!monitor->presence_detection_started) { @@ -851,8 +851,8 @@ void _ua_monitor_handle_user_presence_detected(uam_sensor_info_s *info, if (!service || !g_strcmp0(service, monitor->service)) { /* Presence detection ongoing */ - __ua_sensor_presence_detected(monitor, sensor_info, account, - timestamp, device_id); + __ua_sensor_presence_detected(monitor, sensor_info, account, timestamp, + device_id); } } _ua_free_sensor_info(sensor_info); diff --git a/src/user-awareness-service.c b/src/user-awareness-service.c index 7be64e2..957b982 100644 --- a/src/user-awareness-service.c +++ b/src/user-awareness-service.c @@ -947,7 +947,7 @@ int ua_service_foreach_added_devices( device_info->type = _to_ua_mac_type(ptr->type); device_info->os = ptr->operating_system; device_info->discriminant = ptr->discriminant; - device_info->last_presence_timestamp = ptr->last_seen; + device_info->last_seen = ptr->last_seen; device_info->user = NULL; if (!foreach_cb(service->service_handle, device_info->handle, user_data)) { diff --git a/src/user-awareness-users.c b/src/user-awareness-users.c index ff8d25f..51c3a5d 100644 --- a/src/user-awareness-users.c +++ b/src/user-awareness-users.c @@ -295,8 +295,8 @@ ua_user_h _ua_get_user_handle_by_account(const char *account) return NULL; } -void _ua_set_user_last_presence_timestamp(ua_user_h user_handle, - unsigned long long timestamp) +void _ua_set_user_last_seen(ua_user_h user_handle, + unsigned long long last_seen) { FUNC_ENTRY; ua_user_info_s *user = (ua_user_info_s *)user_handle; @@ -307,7 +307,7 @@ void _ua_set_user_last_presence_timestamp(ua_user_h user_handle, return; } - user->last_presence_timestamp = timestamp; + user->last_seen = last_seen; FUNC_EXIT; } @@ -492,7 +492,7 @@ int ua_user_create(ua_user_h *user_handle) } user->state = UA_PRSENCE_STATE_INVALID; user->account = NULL; - user->last_presence_timestamp = 0; + user->last_seen = 0; /* Add user to list of users*/ *user_handle = (ua_user_h)user; @@ -524,7 +524,7 @@ int ua_user_clone(ua_user_h *dst, ua_user_h src) user_dst->isadded = user_src->isadded; user_dst->default_user = user_src->default_user; user_dst->create_by_app = user_src->create_by_app; - user_dst->last_presence_timestamp = user_src->last_presence_timestamp; + user_dst->last_seen = user_src->last_seen; user_dst->name = g_strdup(user_src->name); if (!user_dst->name) { @@ -786,18 +786,18 @@ int ua_user_get_name( return UA_ERROR_NONE; } -int ua_user_get_last_presence(ua_user_h user_handle, unsigned long long *timestamp) +int ua_user_get_last_presence(ua_user_h user_handle, unsigned long long *last_seen) { FUNC_ENTRY; ua_user_info_s *user = (ua_user_info_s *)user_handle; UA_VALIDATE_INPUT_PARAMETER(user_handle); - UA_VALIDATE_INPUT_PARAMETER(timestamp); + UA_VALIDATE_INPUT_PARAMETER(last_seen); UA_PRINT_USER_HANDLE(user_handle); /* update user list from uam_api */ - *timestamp = user->last_presence_timestamp; + *last_seen = user->last_seen; FUNC_EXIT; return UA_ERROR_NONE; @@ -1146,7 +1146,7 @@ int ua_user_foreach_added_devices( device_info->handle = (ua_device_h)device_info; device_info->type = _to_ua_mac_type(ptr->type); device_info->os = ptr->operating_system; - device_info->last_presence_timestamp = ptr->last_seen; + device_info->last_seen = ptr->last_seen; device_info->discriminant = ptr->discriminant; device_info->user = (ua_user_h)user; ua_devices_user_list = g_slist_append(ua_devices_user_list, device_info); diff --git a/test/uat-devices.c b/test/uat-devices.c index 99a2225..3960536 100644 --- a/test/uat-devices.c +++ b/test/uat-devices.c @@ -770,8 +770,10 @@ int uat_select_device(MManager *mm, struct menu_data *menu) GSList *next = iter->next; ua_device_h *handle = iter->data; if (handle && ++id == selected_id) { - g_device_h = handle; /* Make selected device as a current one */ - uat_update_device_info(); /* Update device info. */ + /* Make selected device as a current one */ + ua_device_clone(&g_device_h, handle); + /* Update device info. */ + uat_update_device_info(); msg("[%d] device selected", selected_id); return RET_SUCCESS; } diff --git a/test/uat-service.c b/test/uat-service.c index c08cc34..89c491a 100644 --- a/test/uat-service.c +++ b/test/uat-service.c @@ -56,7 +56,7 @@ static bool _service_foreach_added_user_cb( char *service_name = NULL; char *account = NULL; char *name = NULL; - unsigned long long timestamp = 0; + unsigned long long last_seen = 0; ret = ua_service_get_name(service_handle, &service_name); if (UA_ERROR_NONE == ret) @@ -91,9 +91,9 @@ static bool _service_foreach_added_user_cb( g_free(name); } - ret = ua_user_get_last_presence(handle, ×tamp); + ret = ua_user_get_last_presence(handle, &last_seen); if (UA_ERROR_NONE == ret) - msglr("last present at %llu", timestamp); + msglr("last present at %llu", last_seen); return true; @@ -190,7 +190,7 @@ static bool _service_foreach_added_device_cb( char *ipv4 = NULL; bool required = false; bool discriminant = false; - unsigned long long timestamp = 0; + unsigned long long last_seen = 0; char service_id = 0; char device_icon = 0; char purpose = 0; @@ -264,9 +264,9 @@ static bool _service_foreach_added_device_cb( if (UA_ERROR_NONE == ret_temp) msgb("Discriminant : %s", discriminant ? "Enabled" : "Disabled"); - ret_temp = ua_device_get_last_presence(handle, ×tamp); + ret_temp = ua_device_get_last_presence(handle, &last_seen); if (UA_ERROR_NONE == ret_temp) - msgb("Last present at : %llu", timestamp); + msgb("Last present at : %llu", last_seen); ret_temp = ua_device_get_payload_service_id(handle, &service_id); if (UA_ERROR_NONE == ret_temp) diff --git a/test/uat-users.c b/test/uat-users.c index 0f00d45..1c29b8b 100644 --- a/test/uat-users.c +++ b/test/uat-users.c @@ -99,7 +99,7 @@ static bool __foreach_registered_user_cb( ua_user_h handle = NULL; char *account = NULL; char *name = NULL; - unsigned long long timestamp = 0; + unsigned long long last_seen = 0; if (!user_handle) { msgr("user_handle is NULL"); @@ -128,9 +128,9 @@ static bool __foreach_registered_user_cb( g_free(name); } - ret = ua_user_get_last_presence(handle, ×tamp); + ret = ua_user_get_last_presence(handle, &last_seen); if (UA_ERROR_NONE == ret) - msglr("last present at %llu", timestamp); + msglr("last present at %llu", last_seen); return true; } @@ -204,7 +204,7 @@ static bool _user_foreach_added_device_cb(ua_device_h device_handle, char *wifi_bssid = NULL; char *ipv4 = NULL; bool required = false; - unsigned long long timestamp = 0; + unsigned long long last_seen = 0; bool discriminant = false; char service_id = 0; char device_icon = 0; @@ -269,9 +269,9 @@ static bool _user_foreach_added_device_cb(ua_device_h device_handle, if (UA_ERROR_NONE == ret_temp) msgc("Pairing Required : %s", required ? "YES" : "NO"); - ret_temp = ua_device_get_last_presence(handle, ×tamp); + ret_temp = ua_device_get_last_presence(handle, &last_seen); if (UA_ERROR_NONE == ret_temp) - msgc("Last present at : %llu", timestamp); + msgc("Last present at : %llu", last_seen); ret_temp = ua_device_get_payload_service_id(handle, &service_id); if (UA_ERROR_NONE == ret_temp) -- cgit v1.2.3