Fix logic to check features 81/165481/3
authorSeonah Moon <seonah1.moon@samsung.com>
Fri, 29 Dec 2017 07:38:01 +0000 (16:38 +0900)
committerSeonah Moon <seonah1.moon@samsung.com>
Fri, 29 Dec 2017 07:55:09 +0000 (16:55 +0900)
Change-Id: Ib2c679b020983f2f990046984006e8fa35aee5da
Signed-off-by: Seonah Moon <seonah1.moon@samsung.com>
include/util.h
packaging/net-config.spec
src/main.c
src/utils/util.c
src/wifi-firmware.c

index bf74a1a..bad5936 100755 (executable)
@@ -38,6 +38,15 @@ extern "C" {
 #define TETHERING_FEATURE "http://tizen.org/feature/network.tethering"
 #define WIFI_DIRECT_FEATURE "http://tizen.org/feature/network.wifi.direct"
 
+typedef enum {
+       NETCONFIG_SUPPORTED_FEATURE_ETHERNET = 0,
+       NETCONFIG_SUPPORTED_FEATURE_TETHERING,
+       NETCONFIG_SUPPORTED_FEATURE_WIFI_DIRECT,
+       NETCONFIG_SUPPORTED_FEATURE_MAX,
+} netconfig_supported_feature_e;
+
+bool netconfig_check_feature_supported(netconfig_supported_feature_e feature);
+
 gboolean netconfig_check_passphrase(const gchar *service, const char *passphrase);
 GKeyFile *netconfig_keyfile_load(const char *pathname);
 void netconfig_keyfile_save(GKeyFile *keyfile, const char *pathname);
@@ -99,7 +108,6 @@ gboolean __netconfig_wifi_get_aka_authdata(Wifi *wifi,
 gboolean __netconfig_wifi_get_sim_authdata(Wifi *wifi,
                GDBusMethodInvocation *context, struct wifi_authentication_data **data);
 
-bool netconfig_check_feature_supported(const char *feature);
 void netconfig_plugin_init();
 void netconfig_plugin_deinit();
 gboolean netconfig_get_headed_plugin_flag();
index bfb3fac..4ac26a5 100755 (executable)
@@ -1,6 +1,6 @@
 Name:          net-config
 Summary:       TIZEN Network Configuration service
-Version:       1.1.120
+Version:       1.1.121
 Release:       2
 Group:         System/Network
 License:       Apache-2.0
index c19c3b1..9b6db87 100755 (executable)
@@ -132,7 +132,7 @@ int main(int argc, char *argv[])
        if (TIZEN_TV && emulator_is_emulated() == FALSE)
                __netconfig_set_ether_macaddr();
 
-       if (netconfig_check_feature_supported(ETHERNET_FEATURE)) {
+       if (netconfig_check_feature_supported(NETCONFIG_SUPPORTED_FEATURE_ETHERNET)) {
                /* Register the callback to check the ethernet Plug-in /Plug-out Status */
                check_ethernet_monitor_timer = g_timeout_add(ETH_POLLING_TIME,
                                __net_ethernet_cable_status_polling_callback,
index bec7fc2..06cd08f 100755 (executable)
@@ -63,6 +63,9 @@ static void *handle_telephony;
 static struct netconfig_headed_plugin_t *headed_plugin;
 static struct netconfig_telephony_plugin_t *telephony_plugin;
 
+static bool is_feature_checked[NETCONFIG_SUPPORTED_FEATURE_MAX] = {0, };
+static bool feature_supported[NETCONFIG_SUPPORTED_FEATURE_MAX] = {0, };
+
 gboolean netconfig_check_passphrase(const gchar *service, const char *passphrase)
 {
        gsize length;
@@ -317,7 +320,7 @@ void netconfig_wifi_device_picker_service_stop(void)
 
 gboolean netconfig_is_wifi_direct_on(void)
 {
-       if (!netconfig_check_feature_supported(WIFI_DIRECT_FEATURE))
+       if (!netconfig_check_feature_supported(NETCONFIG_SUPPORTED_FEATURE_WIFI_DIRECT))
                return FALSE;
 
        int wifi_direct_state = 0;
@@ -330,7 +333,7 @@ gboolean netconfig_is_wifi_direct_on(void)
 
 gboolean netconfig_is_wifi_tethering_on(void)
 {
-       if (netconfig_check_feature_supported(TETHERING_FEATURE)) {
+       if (netconfig_check_feature_supported(NETCONFIG_SUPPORTED_FEATURE_TETHERING)) {
                int wifi_tethering_state = 0;
 
                netconfig_vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_MODE, &wifi_tethering_state);
@@ -870,7 +873,7 @@ int netconfig_del_route_ipv6(gchar *ip_addr, gchar *interface, gchar *gateway, u
 
 gboolean handle_launch_direct(Wifi *wifi, GDBusMethodInvocation *context)
 {
-       if (!netconfig_check_feature_supported(WIFI_DIRECT_FEATURE)) {
+       if (!netconfig_check_feature_supported(NETCONFIG_SUPPORTED_FEATURE_WIFI_DIRECT)) {
                wifi_complete_launch_direct(wifi, context);
                return FALSE;
        }
@@ -1274,22 +1277,6 @@ tizen_profile_t _get_tizen_profile()
        return profile;
 }
 
-bool netconfig_check_feature_supported(const char *feature)
-{
-       bool is_supported = false;
-
-       if (!system_info_get_platform_bool(feature, &is_supported)) {
-               if (is_supported != TRUE)
-                       DBG("%s is not supported", feature);
-               else
-                       DBG("%s is supported", feature);
-       } else {
-               ERR("Error - Feature getting from System Info");
-       }
-
-       return is_supported;
-}
-
 void netconfig_plugin_init()
 {
        handle_headed = dlopen(HEADED_PLUGIN_FILEPATH, RTLD_NOW);
@@ -1342,3 +1329,31 @@ gboolean netconfig_get_telephony_plugin_flag()
        return netconfig_plugin_telephony_enabled;
 }
 
+bool netconfig_check_feature_supported(netconfig_supported_feature_e feature)
+{
+       const char *key = NULL;
+
+       if (!is_feature_checked[feature]) {
+               switch (feature) {
+               case NETCONFIG_SUPPORTED_FEATURE_ETHERNET:
+                       key = ETHERNET_FEATURE;
+                       break;
+               case NETCONFIG_SUPPORTED_FEATURE_TETHERING:
+                       key = TETHERING_FEATURE;
+                       break;
+               case NETCONFIG_SUPPORTED_FEATURE_WIFI_DIRECT:
+                       key = WIFI_DIRECT_FEATURE;
+                       break;
+               default:
+                       ERR("Uknown feature");
+                       return false;
+               }
+
+               if (system_info_get_platform_bool(key, &feature_supported[feature]) < 0) {
+                       ERR("Get feature is failed");
+                       return false;
+               }
+               is_feature_checked[feature] = true;
+       }
+       return feature_supported[feature];
+}
index 34fe649..9a971af 100755 (executable)
@@ -80,7 +80,7 @@ static int __netconfig_sta_firmware_stop(void)
 
 static int __netconfig_p2p_firmware_start(void)
 {
-       if (!netconfig_check_feature_supported(WIFI_DIRECT_FEATURE))
+       if (!netconfig_check_feature_supported(NETCONFIG_SUPPORTED_FEATURE_WIFI_DIRECT))
                return -ENODEV;
 
        int rv = 0;
@@ -104,7 +104,7 @@ static int __netconfig_p2p_firmware_start(void)
 
 static int __netconfig_p2p_firmware_stop(void)
 {
-       if (!netconfig_check_feature_supported(WIFI_DIRECT_FEATURE))
+       if (!netconfig_check_feature_supported(NETCONFIG_SUPPORTED_FEATURE_WIFI_DIRECT))
                return -ENODEV;
 
        int rv = 0;
@@ -126,7 +126,7 @@ static int __netconfig_p2p_firmware_stop(void)
 
 static int __netconfig_softap_firmware_start(void)
 {
-       if (!netconfig_check_feature_supported(TETHERING_FEATURE))
+       if (!netconfig_check_feature_supported(NETCONFIG_SUPPORTED_FEATURE_TETHERING))
                return -ENODEV;
 
        int rv = 0;
@@ -147,7 +147,7 @@ static int __netconfig_softap_firmware_start(void)
 
 static int __netconfig_softap_firmware_stop(void)
 {
-       if (!netconfig_check_feature_supported(TETHERING_FEATURE))
+       if (!netconfig_check_feature_supported(NETCONFIG_SUPPORTED_FEATURE_TETHERING))
                return -ENODEV;
 
        int rv = 0;
@@ -259,8 +259,8 @@ int netconfig_wifi_firmware(enum netconfig_wifi_firmware type, gboolean enable)
 #if defined WLAN_CONCURRENT_MODE
                        if (type == NETCONFIG_WIFI_STA)
                                netconfig_interface_up(WIFI_IFNAME);
-                       else if (netconfig_check_feature_supported(WIFI_DIRECT_FEATURE)
-                                       && type == NETCONFIG_WIFI_P2P)
+                       else if (netconfig_check_feature_supported(NETCONFIG_SUPPORTED_FEATURE_WIFI_DIRECT)) &&
+                               type == NETCONFIG_WIFI_P2P)
                                netconfig_interface_up(WLAN_P2P_IFACE_NAME);
 #endif
                        return -EALREADY;