Fix a problem that ADD_DEVICE operation failed accepted/tizen/unified/20191011.101532 submit/tizen/20191011.062256
authorsaerome.kim <saerome.kim@samsung.com>
Fri, 11 Oct 2019 02:06:14 +0000 (11:06 +0900)
committersaerome.kim <saerome.kim@samsung.com>
Fri, 11 Oct 2019 05:50:57 +0000 (14:50 +0900)
- Problem: if the wrong information is entered and failed to ADD_DEVICE.
  user apps can't add devices anymore.
- Cause: When one app removes the user information  while adding the device,
  there is no way to know how the ADD_DEVICE  operation succeeded or not.
- Solution: notify the user with an error when ADD_DEVICE failed.

Signed-off-by: saerome.kim <saerome.kim@samsung.com>
packaging/ua-manager.spec
ua-daemon/src/ua-manager-core.c

index da14ea7..6c193e2 100644 (file)
@@ -1,6 +1,6 @@
 Name:       ua-manager
 Summary:    User awareness manager
-Version:    0.11.3
+Version:    0.11.4
 Release:    1
 License:    Apache-2.0
 Source0:    %{name}-%{version}.tar.gz
index e0122bc..1b2c68c 100644 (file)
@@ -30,6 +30,7 @@
 #define UAM_MAX_USERS 255
 #define USER_ACCOUNT_DEFAULT "default@default.com"
 #define USER_NAME_DEFAULT "default"
+#define USER_ACCOUNT_DEFAULT_ID 1
 
 typedef struct {
        char *name;
@@ -160,7 +161,7 @@ static void __free_user_device(gpointer data)
        FUNC_EXIT;
 }
 
-static void __send_device_event(int event, const uam_device_info_s *dev_info)
+static void __send_device_event(int err, int event, const uam_device_info_s *dev_info)
 {
        FUNC_ENTRY;
        GVariant *param;
@@ -168,7 +169,7 @@ static void __send_device_event(int event, const uam_device_info_s *dev_info)
        UAM_INFO_C("Send %s to applications", _uam_manager_event_to_str(event));
        /* Send device event to application */
        param = g_variant_new("(iiisss)",
-                       UAM_ERROR_NONE,
+                       err,
                        dev_info->operating_system,
                        dev_info->type,
                        dev_info->mac,
@@ -315,7 +316,7 @@ static void __remove_user_device(gpointer data)
                                        _uam_manager_error_to_str(ret));
 
                /* Send device removed event to application */
-               __send_device_event(UAM_EVENT_DEVICE_REMOVED, &dev_info);
+               __send_device_event(UAM_ERROR_NONE, UAM_EVENT_DEVICE_REMOVED, &dev_info);
 
                /* Remove device from database */
                if (UAM_ERROR_NONE != _uam_device_db_delete_device_info(
@@ -982,7 +983,7 @@ static int __uam_remove_device(int user_id, uam_db_device_info_t *device,
        }
 
        /* Send device removed event to application */
-       __send_device_event(UAM_EVENT_DEVICE_REMOVED, dev_info);
+       __send_device_event(ret, UAM_EVENT_DEVICE_REMOVED, dev_info);
 
        /* Remove device from database */
        if (UAM_ERROR_NONE != _uam_device_db_delete_device_info(
@@ -2394,8 +2395,10 @@ int _uam_core_handle_device_added(int status,
 {
        FUNC_ENTRY;
        GSList *l;
-       uam_db_user_info_t *user = NULL;
        int ret = UAM_ERROR_NONE;
+       uam_db_user_info_t *user = NULL;
+       GSList *svc_list = NULL;
+       long long timestamp;
 
        /* Send reply over dbus for add device API */
        l = _uam_manager_get_request_list();
@@ -2430,94 +2433,88 @@ int _uam_core_handle_device_added(int status,
                break;
        }
 
-       if (UAM_ERROR_NONE == status) {
-               GSList *svc_list = NULL;
-               long long timestamp;
-
-               if (0 > user_id) {
-
-                       l = g_slist_find_custom(users,
-                                       USER_ACCOUNT_DEFAULT, __compare_user_account);
-                       if (NULL == l) {
-                               ret = _uam_core_add_user(
-                                               USER_ACCOUNT_DEFAULT, USER_NAME_DEFAULT);
-                               if (UAM_ERROR_NONE != ret) {
-                                       UAM_ERR("_uam_core_add_user failed with %s",
-                                                       _uam_manager_error_to_str(ret));
-                                       return ret;
-                               }
-                       }
-                       l = g_slist_find_custom(users, USER_ACCOUNT_DEFAULT, __compare_user_account);
-                       if (!l) {
-                               UAM_ERR("_uam_core_add_user failed because user is null");
-                               ret = UAM_ERROR_NOT_FOUND;
-                               return ret;
-                       }
+       if (UAM_ERROR_NONE != status) {
+               __send_device_event(status, UAM_EVENT_DEVICE_ADDED, dev_info);
+               return status;
+       }
 
-                       user = l->data;
-                       user_id = user->user_id;
-               } else {
-                       l = g_slist_find_custom(users, &user_id, __compare_user_id);
-                       if (NULL == l) {
-                               UAM_ERR("Invalid user Id: %d", user_id);
-                               ret = UAM_ERROR_NOT_FOUND;
+       if (0 > user_id) {
+               l = g_slist_find_custom(users,
+                               USER_ACCOUNT_DEFAULT, __compare_user_account);
+               if (NULL == l) {
+                       ret = _uam_core_add_user(
+                                       USER_ACCOUNT_DEFAULT, USER_NAME_DEFAULT);
+                       if (UAM_ERROR_NONE != ret) {
+                               UAM_ERR("_uam_core_add_user failed with %s",
+                                               _uam_manager_error_to_str(ret));
+                               __send_device_event(ret, UAM_EVENT_DEVICE_ADDED, dev_info);
                                return ret;
                        }
-                       user = l->data;
                }
+               user_id = USER_ACCOUNT_DEFAULT_ID;
+       }
+       l = g_slist_find_custom(users, &user_id, __compare_user_id);
+       if (NULL == l) {
+               UAM_ERR("Invalid user Id: %d", user_id);
+               ret = UAM_ERROR_NOT_FOUND;
+               __send_device_event(ret, UAM_EVENT_DEVICE_ADDED, dev_info);
+               return ret;
+       }
+       user = l->data;
 
-               /* Get default service and add it to device's service list by default */
-               l = g_slist_find_custom(services, UAM_SERVICE_DEFAULT, __compare_svc_name);
-               if (!l) {
-                       uam_db_service_info_t *service = g_new0(uam_db_service_info_t, 1);
-                       service->name = g_strdup(UAM_SERVICE_DEFAULT);
-                       service->cycle = UAM_DETECTION_CYCLE_DEFAULT;
-                       services = g_slist_append(services, service);
-                       svc_list = g_slist_append(svc_list, service);
-               } else {
-                       uam_db_service_info_t *service = l->data;
-                       svc_list = g_slist_append(svc_list, service);
-               }
+       /* Get default service and add it to device's service list by default */
+       l = g_slist_find_custom(services, UAM_SERVICE_DEFAULT, __compare_svc_name);
+       if (!l) {
+               uam_db_service_info_t *service = g_new0(uam_db_service_info_t, 1);
+               service->name = g_strdup(UAM_SERVICE_DEFAULT);
+               service->cycle = UAM_DETECTION_CYCLE_DEFAULT;
+               services = g_slist_append(services, service);
+               svc_list = g_slist_append(svc_list, service);
+       } else {
+               uam_db_service_info_t *service = l->data;
+               svc_list = g_slist_append(svc_list, service);
+       }
 
-               timestamp = time(NULL);
-               __uam_core_add_dev_to_list(user, dev_info,
-                               UAM_PRESENCE_STATE_PRESENT, timestamp, svc_list);
+       timestamp = time(NULL);
+       __uam_core_add_dev_to_list(user, dev_info,
+                       UAM_PRESENCE_STATE_PRESENT, timestamp, svc_list);
 
-               /* Add device to database */
-               ret = _uam_device_db_insert_device_info(user->user_id,
-                                       dev_info, UAM_PRESENCE_STATE_PRESENT, timestamp);
-               if (UAM_ERROR_NONE != ret) {
-                       UAM_WARN("Device addition to persistent DB failed");
-                       return ret;
-               }
+       /* Add device to database */
+       ret = _uam_device_db_insert_device_info(user->user_id,
+                               dev_info, UAM_PRESENCE_STATE_PRESENT, timestamp);
+       if (UAM_ERROR_NONE != ret) {
+               UAM_WARN("Device addition to persistent DB failed");
+               return ret;
+       }
 
-               /* Insert device service info to db */
-               ret =  _uam_db_insert_device_service_info(
-                                       dev_info->device_id, dev_info->type, dev_info->mac,
-                                       UAM_SERVICE_DEFAULT, UAM_DETECTION_CYCLE_DEFAULT,
-                                       dev_info->discriminant);
-               if (UAM_ERROR_NONE != ret) {
-                       UAM_WARN("Device service addition to persistent DB failed");
-                       return ret;
-               }
+       /* Insert device service info to db */
+       ret =  _uam_db_insert_device_service_info(
+                               dev_info->device_id, dev_info->type, dev_info->mac,
+                               UAM_SERVICE_DEFAULT, UAM_DETECTION_CYCLE_DEFAULT,
+                               dev_info->discriminant);
+       if (UAM_ERROR_NONE != ret) {
+               UAM_WARN("Device service addition to persistent DB failed");
+               __send_device_event(ret, UAM_EVENT_DEVICE_ADDED, dev_info);
+               return ret;
+       }
 
-               ret = _uam_core_update_svc_dev_info(
-                                       dev_info->device_id, dev_info->type,
-                                       UAM_SERVICE_DEFAULT, dev_info->discriminant);
-               if (UAM_ERROR_NONE != ret) {
-                       UAM_WARN("Device service mappiing update failed");
-                       return ret;
-               }
+       ret = _uam_core_update_svc_dev_info(
+                               dev_info->device_id, dev_info->type,
+                               UAM_SERVICE_DEFAULT, dev_info->discriminant);
+       if (UAM_ERROR_NONE != ret) {
+               UAM_WARN("Device service mappiing update failed");
+               __send_device_event(ret, UAM_EVENT_DEVICE_ADDED, dev_info);
+               return ret;
+       }
 
-               /* Send device added event to application */
-               __send_device_event(UAM_EVENT_DEVICE_ADDED, dev_info);
+       /* Send device added event to application */
+       __send_device_event(ret, UAM_EVENT_DEVICE_ADDED, dev_info);
 
-               /* Set/update registered device list to plugins */
-               ret = _uam_pm_set_registered_devices(devices);
-               if (UAM_ERROR_NONE != ret) {
-                       UAM_ERR("_uam_pm_set_registered_devices failed");
-                       return ret;
-               }
+       /* Set/update registered device list to plugins */
+       ret = _uam_pm_set_registered_devices(devices);
+       if (UAM_ERROR_NONE != ret) {
+               UAM_ERR("_uam_pm_set_registered_devices failed");
+               return ret;
        }
 
        _uam_cloud_send_device_added(status, (user ? user->account : NULL), dev_info);