Added state validity check and update vconf only when state is changed. 27/78927/2
authorNishant Chaprana <n.chaprana@samsung.com>
Wed, 29 Jun 2016 09:13:44 +0000 (14:43 +0530)
committerNishant Chaprana <n.chaprana@samsung.com>
Mon, 18 Jul 2016 04:30:55 +0000 (10:00 +0530)
Change-Id: Iacd876937a047aab7af3668ef4c9cbb0a09319f0
Signed-off-by: Nishant Chaprana <n.chaprana@samsung.com>
packaging/wifi-direct-manager.spec
src/wifi-direct-util.c

index 3e4839b..639ae4d 100755 (executable)
@@ -1,6 +1,6 @@
 Name:          wifi-direct-manager
 Summary:       Wi-Fi Direct manger
-Version:       1.2.181
+Version:       1.2.182
 Release:       1
 Group:      Network & Connectivity/Wireless
 License:    Apache-2.0
index 7b5f7cd..05e5ffe 100755 (executable)
@@ -542,10 +542,23 @@ int wfd_util_get_wifi_direct_state()
 int wfd_util_set_wifi_direct_state(int state)
 {
        __WDS_LOG_FUNC_ENTER__;
-       int vconf_state = 0;
+       static int last_state = WIFI_DIRECT_STATE_DEACTIVATED;
+       int vconf_state = VCONFKEY_WIFI_DIRECT_DEACTIVATED;
        int res = 0;
 
-       /* TODO: check validity of state */
+       if (state < WIFI_DIRECT_STATE_DEACTIVATED ||
+           state > WIFI_DIRECT_STATE_GROUP_OWNER) {
+               WDS_LOGE("Invalid parameter");
+               __WDS_LOG_FUNC_EXIT__;
+               return -1;
+       }
+
+       if (last_state == state) {
+               WDS_LOGD("No change in state, not updating vconf [%s]",
+                        VCONFKEY_WIFI_DIRECT_STATE);
+               __WDS_LOG_FUNC_EXIT__;
+               return 0;
+       }
 
        if (state == WIFI_DIRECT_STATE_ACTIVATED)
                vconf_state = VCONFKEY_WIFI_DIRECT_ACTIVATED;
@@ -561,6 +574,7 @@ int wfd_util_set_wifi_direct_state(int state)
                WDS_LOGE("This state cannot be set as wifi_direct vconf state[%d]", state);
                return 0;
        }
+
        WDS_LOGD("Vconf key set [%s: %d]", VCONFKEY_WIFI_DIRECT_STATE, vconf_state);
 
        res = vconf_set_int(VCONFKEY_WIFI_DIRECT_STATE, vconf_state);
@@ -570,6 +584,8 @@ int wfd_util_set_wifi_direct_state(int state)
                return -1;
        }
 
+       last_state = state;
+
        __WDS_LOG_FUNC_EXIT__;
        return 0;
 }