[wearable] Refactored the logic for create AP object 48/105148/1
authorMilind Murhekar <m.murhekar@samsung.com>
Thu, 15 Dec 2016 15:07:22 +0000 (20:37 +0530)
committerMilind Murhekar <m.murhekar@samsung.com>
Thu, 15 Dec 2016 15:07:22 +0000 (20:37 +0530)
Description: This patch ignores the AP handle creation
if M/W fails to clone the avilable AP or fails to get the rssi
or wps_mode.

This logic avoids possible corrupted AP handle and safe gaurds
the handling of AP object creation.

This patch also fixes the possible crash, when Application
deletes the Genlist AP item during AP updation.

Change-Id: I45ab14494a23dfc12753256ac8bf308a05bceaa3
Signed-off-by: Milind Murhekar <m.murhekar@samsung.com>
packaging/wifi-efl-ug.spec
sources/wearable/src/net/wifi_manager.c
sources/wearable/src/wearable-circle/view/layout_scan.c

index 9720482..e1b3392 100644 (file)
@@ -1,7 +1,7 @@
 %define _unpackaged_files_terminate_build 0
 Name:          wifi-efl-ug
 Summary:       Wi-Fi UI Gadget for TIZEN
-Version:       1.0.221
+Version:       1.0.222
 Release:       1
 Group:         App/Network
 License:       Flora-1.1
index 7f1158b..79175ff 100755 (executable)
@@ -236,22 +236,27 @@ static wifi_config_object *_find_wifi_config_by_wifi_ap(wifi_manager_object *man
 static wifi_ap_object *_create_ap_object_by_ap_h(wifi_ap_h ap)
 {
        wifi_ap_object *ap_obj = g_new0(wifi_ap_object, 1);
-       gboolean is_create_failed = FALSE;
-       if (!ap_obj) {
+       if (!ap_obj)
                return NULL;
-       }
+
        if (WIFI_ERROR_NONE != wifi_ap_clone(&(ap_obj->ap), ap)) {
-               is_create_failed = TRUE;
-       } else if (WIFI_ERROR_NONE != wifi_ap_get_rssi(ap, &(ap_obj->rssi))) {
-               is_create_failed = TRUE;
-       } else if (WIFI_ERROR_NONE != wifi_ap_is_wps_supported(ap, &(ap_obj->wps_mode))) {
-               is_create_failed = TRUE;
+               WIFI_LOG_ERR("Failed to clone AP handle");
+               g_free(ap_obj);
+               return NULL;
+       }
+
+       if (WIFI_ERROR_NONE != wifi_ap_get_rssi(ap, &(ap_obj->rssi))) {
+               WIFI_LOG_ERR("Failed to get rssi of AP");
+               wifi_manager_ap_destroy(ap_obj);
+               return NULL;
        }
 
-       if (is_create_failed) {
+       if (WIFI_ERROR_NONE != wifi_ap_is_wps_supported(ap, &(ap_obj->wps_mode))) {
+               WIFI_LOG_ERR("Failed to get wps mode of AP");
                wifi_manager_ap_destroy(ap_obj);
                return NULL;
        }
+
        ap_obj->last_connection_error = WIFI_ERROR_NONE;
        ap_obj->is_captiveportal = FALSE;
        return ap_obj;
index 03ddf8a..8421dbe 100755 (executable)
@@ -261,6 +261,7 @@ static gboolean _ap_list_update_ap_items(layout_scan_object *self)
        guint index, old_items_count = elm_genlist_items_count(self->ap_list) - 1;
        guint new_items_count = g_list_length(self->ap_data_list);
        Elm_Genlist_Item_Class *wifi_ap_itc = _create_wifi_ap_itc(self);
+       Elm_Object_Item *ap_item = NULL;
 
        __WIFI_FUNC_ENTER__;
        WIFI_RET_VAL_IF_FAIL(wifi_ap_itc != NULL, FALSE);
@@ -268,7 +269,9 @@ static gboolean _ap_list_update_ap_items(layout_scan_object *self)
        if (new_items_count < old_items_count) {
                guint rm_index;
                for (rm_index = old_items_count; rm_index > new_items_count; rm_index--) {
-                       elm_object_item_del(elm_genlist_nth_item_get(self->ap_list, rm_index));
+                       ap_item = elm_genlist_nth_item_get(self->ap_list, rm_index);
+                       if (ap_item)
+                               elm_object_item_del(ap_item);
                }
        }
        for (index = 1; l != NULL; index++, l = l->next) {