Fix crash of ua-test app. accepted/tizen/unified/20191125.135545 accepted/tizen/unified/20191125.135550 accepted/tizen/unified/20191126.124638 submit/tizen/20191122.014017 submit/tizen/20191126.004258
authorsaerome.kim <saerome.kim@samsung.com>
Wed, 20 Nov 2019 11:18:00 +0000 (20:18 +0900)
committersaerome.kim <saerome.kim@samsung.com>
Thu, 21 Nov 2019 05:41:11 +0000 (14:41 +0900)
- 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 <saerome.kim@samsung.com>
include/user-awareness-private.h
include/user-awareness.h
packaging/capi-network-ua.spec
src/user-awareness-device.c
src/user-awareness-event-handler.c
src/user-awareness-monitors.c
src/user-awareness-service.c
src/user-awareness-users.c
test/uat-devices.c
test/uat-service.c
test/uat-users.c

index 0cd5353874d93ebb10e958195aa4aa82d76e99d6..4acb15c1e6105e8a703912e92a0f75900a700fd2 100644 (file)
@@ -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.
index 1148c045ca5ca8865ff435d825240c7badb0d233..e3a329a55b129409c55971d9a16b6117e0c41330 100644 (file)
@@ -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
index b0040d0fc40cf1ba703582b7e9b33de53924689a..7b1b4654fca990aba13591288e52d1336ad10869 100644 (file)
@@ -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
index 266223d7ff51ea2034ef6e24465fb74f4884996f..671fdaaabadb598d89791d4a2e509a3372fcb308 100644 (file)
@@ -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);
index d57f5ed71e8c8607d05807024c8e1312718e12fc..96c7ad61b293d998e255fc4d549b709f95f2e232 100644 (file)
@@ -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);
 
index 4aa57c61aeb2bb8a6f4d158bc4c50546365e2418..e70e44d4f17a3ea9018cd0079de85a6798187867 100644 (file)
@@ -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);
index 7be64e2df59b001bf83f20215562cf4675b8ee40..957b98258e2b749bd8f18e802d81984a13caa2a6 100644 (file)
@@ -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)) {
index ff8d25f7288d33295727955d2704c91419c9ebf9..51c3a5d0434a3c04da1d96bc9162ea68d8bd2c6d 100644 (file)
@@ -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);
index 99a22251d8dca02d042e61976d9874fc27e4f558..3960536793c4de57f35a636f88d6fd854751dc16 100644 (file)
@@ -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;
                }
index c08cc348c5d0d426a7fbdae24ab85edd0049e5d3..89c491a93bd6ce2498282407af81d3fefe8dfedd 100644 (file)
@@ -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, &timestamp);
+       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, &timestamp);
+       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)
index 0f00d45d9fe48e3598bbfbb03b30548a1b62b4a9..1c29b8bcc1961fe22e25e9629727a6333a3a6011 100644 (file)
@@ -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, &timestamp);
+       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, &timestamp);
+       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)