Remove duplicacy in searching user device tech 26/282026/1
authorAbhay Agarwal <ay.agarwal@samsung.com>
Mon, 26 Sep 2022 08:48:55 +0000 (14:18 +0530)
committerAbhay Agarwal <ay.agarwal@samsung.com>
Mon, 26 Sep 2022 08:58:23 +0000 (14:28 +0530)
Change-Id: Ibfcad179872f31565702ec91ffbe23a41bb93fb7
Signed-off-by: Abhay Agarwal <ay.agarwal@samsung.com>
packaging/ua-manager.spec
ua-daemon/src/ua-manager-core.c

index c4138c40d6a7ffb6a3342138870114aab719d99a..63002e203eab58034025d0345295047e1481767f 100644 (file)
@@ -1,6 +1,6 @@
 Name:       ua-manager
 Summary:    User awareness manager
-Version:    0.14.12
+Version:    0.14.13
 Release:    1
 License:    Apache-2.0
 Source0:    %{name}-%{version}.tar.gz
index e74534bc01c4067876e3f4f1e65300ed02f314a3..004b7928c64790143b317243451a6140d2fd106f 100755 (executable)
@@ -3928,22 +3928,28 @@ static int __uam_core_search_user(int user_id, uam_db_user_info_t **user)
                return UAM_ERROR_INVALID_PARAMETER;
        }
 
+       UAM_DBG("Valid user_id [%d]", user_id);
+
        *user = l->data;
        return UAM_ERROR_NONE;
 }
 
 static int __uam_core_search_device(uam_device_info_s *dev_info,
-               int user_id, uam_db_user_info_t *user, uam_db_device_info_t **device)
+               uam_db_user_info_t *user, uam_db_device_info_t **device)
 {
        GSList *l = g_slist_find_custom(user->devices,
                        dev_info->device_id, __compare_device_id);
        if (NULL == l) {
-               UAM_ERR("Valid user_id [%d] but Invalid device_id [%s]",
-                               user_id, dev_info->device_id);
+               UAM_ERR("Invalid device_id [%s]", dev_info->device_id);
                return UAM_ERROR_INVALID_PARAMETER;
        }
 
        *device = l->data;
+       if (!((*device)->supported_techs & dev_info->type)) {
+               UAM_ERR("Valid device_id [%s] but Invalid tech type [%d]",
+                               dev_info->device_id, dev_info->type);
+               return UAM_ERROR_INVALID_PARAMETER;
+       }
        return UAM_ERROR_NONE;
 }
 
@@ -3961,6 +3967,23 @@ static int __uam_core_search_tech(uam_device_info_s *dev_info,
        return UAM_ERROR_NONE;
 }
 
+static int __uam_core_search_user_device_tech(int user_id,
+               uam_device_info_s *dev_info, uam_db_tech_info_t **tech)
+{
+       uam_db_user_info_t *user = NULL;
+       uam_db_device_info_t *device = NULL;
+
+       /* fetch the app_num info for the corresponding user_id */
+       _uam_core_get_app_num_from_userid(user_id, &dev_info->app_num);
+
+       retv_if(UAM_ERROR_NONE != __uam_core_search_user(user_id, &user), UAM_ERROR_INVALID_PARAMETER);
+
+       retv_if(UAM_ERROR_NONE != __uam_core_search_device(dev_info, user, &device), UAM_ERROR_INVALID_PARAMETER);
+
+       retv_if(UAM_ERROR_NONE != __uam_core_search_tech(dev_info, device, tech), UAM_ERROR_INVALID_PARAMETER);
+       return UAM_ERROR_NONE;
+}
+
 int _uam_core_handle_presence_detected(unsigned int sensor,
                int user_id, void *info, uam_ble_payload_s *payload)
 {
@@ -3968,8 +3991,6 @@ int _uam_core_handle_presence_detected(unsigned int sensor,
        int ret = UAM_ERROR_NONE;
 
        GSList *l;
-       uam_db_user_info_t *user = NULL;
-       uam_db_device_info_t *device = NULL;
        uam_db_tech_info_t *tech = NULL;
 
        uam_device_info_s *dev_info = NULL;
@@ -3996,19 +4017,9 @@ int _uam_core_handle_presence_detected(unsigned int sensor,
 
        retv_if(0 > user_id, UAM_ERROR_INVALID_PARAMETER);
 
-       /* fetch the app_num info for the corresponding user_id */
-       _uam_core_get_app_num_from_userid(user_id, &dev_info->app_num);
-
-       retv_if(UAM_ERROR_NONE != __uam_core_search_user(user_id, &user), UAM_ERROR_INVALID_PARAMETER);
+       retv_if(UAM_ERROR_NONE != __uam_core_search_user_device_tech(user_id,
+                               dev_info, &tech), UAM_ERROR_INVALID_PARAMETER);
 
-       retv_if(UAM_ERROR_NONE != __uam_core_search_device(dev_info, user_id, user, &device), UAM_ERROR_INVALID_PARAMETER);
-       if (!(device->supported_techs & dev_info->type)) {
-               UAM_ERR("Valid device_id [%s] but Invalid tech type [%d]",
-                               dev_info->device_id, dev_info->type);
-               return UAM_ERROR_INVALID_PARAMETER;
-       }
-
-       retv_if(UAM_ERROR_NONE != __uam_core_search_tech(dev_info, device, &tech), UAM_ERROR_INVALID_PARAMETER);
        tech->presence_state = UAM_PRESENCE_STATE_PRESENT;
        tech->last_seen = dev_info->last_seen;
 
@@ -4150,8 +4161,6 @@ int _uam_core_handle_location_detected(unsigned int sensor,
        FUNC_ENTRY;
        int ret = UAM_ERROR_NONE;
 
-       uam_db_user_info_t *user = NULL;
-       uam_db_device_info_t *device = NULL;
        uam_db_tech_info_t *tech = NULL;
        uam_device_info_s *dev_info = NULL;
 
@@ -4169,22 +4178,8 @@ int _uam_core_handle_location_detected(unsigned int sensor,
 
        retv_if(0 > user_id, UAM_ERROR_INVALID_PARAMETER);
 
-       /* fetch the app_num info for the corresponding user_id */
-       _uam_core_get_app_num_from_userid(user_id, &dev_info->app_num);
-
-       /* Search user */
-       retv_if(UAM_ERROR_NONE != __uam_core_search_user(user_id, &user), UAM_ERROR_INVALID_PARAMETER);
-
-       /* Search device */
-       retv_if(UAM_ERROR_NONE != __uam_core_search_device(dev_info, user_id, user, &device), UAM_ERROR_INVALID_PARAMETER);
-       if (!(device->supported_techs & dev_info->type)) {
-               UAM_ERR("Valid device_id [%s] but Invalid tech type [%d]",
-                               dev_info->device_id, dev_info->type);
-               return UAM_ERROR_INVALID_PARAMETER;
-       }
-
-       /* Search tech */
-       retv_if(UAM_ERROR_NONE != __uam_core_search_tech(dev_info, device, &tech), UAM_ERROR_INVALID_PARAMETER);
+       retv_if(UAM_ERROR_NONE != __uam_core_search_user_device_tech(user_id,
+                               dev_info, &tech), UAM_ERROR_INVALID_PARAMETER);
 
        /* Send user location event */
        __send_user_location_event(tech, sensor, dev_info);