Get vconf value via DBus in container environment 68/266268/5
authorJaehyun Kim <jeik01.kim@samsung.com>
Wed, 10 Nov 2021 05:59:15 +0000 (14:59 +0900)
committerJaehyun Kim <jeik01.kim@samsung.com>
Thu, 11 Nov 2021 08:33:05 +0000 (17:33 +0900)
Change-Id: I35e19ed16c1558f5eb05ae000f330af04d1805e0
Signed-off-by: Jaehyun Kim <jeik01.kim@samsung.com>
src/network_dbus.c
src/network_dbus.h
src/network_interface.c
src/network_internal.c
src/network_internal.h
src/wifi_internal.c

index 82a4079..1dc54b9 100644 (file)
@@ -821,24 +821,33 @@ GVariant *_net_invoke_dbus_method(network_info_s *network_info,
        GDBusConnection *connection = NULL;
        gboolean created = FALSE;
 
-       if (network_info == NULL || network_info->connection == NULL) {
+       if ((network_info == NULL || network_info->connection == NULL) &&
+                       access(CONTAINER_FILE, F_OK) == 0) {
+
+               connection = g_dbus_connection_new_for_address_sync(
+                               DBUS_HOST_SYSTEM_BUS_ADDRESS,
+                               G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT | G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION,
+                               NULL, NULL, &error);
+               created = TRUE;
+       } else if (network_info == NULL || network_info->connection == NULL) {
                connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
-               /* LCOV_EXCL_START */
-               if (connection == NULL) {
-                       if (error != NULL) {
-                               WIFI_LOG(WIFI_ERROR,
-                                               "Failed to connect to the D-BUS daemon [%s]", error->message);
-                               g_error_free(error);
-                       }
-                       return NULL;
-               }
-               /* LCOV_EXCL_STOP */
                created = TRUE;
        } else {
                connection = network_info->connection;
                created = FALSE;
        }
 
+       /* LCOV_EXCL_START */
+       if (connection == NULL) {
+               if (error != NULL) {
+                       WIFI_LOG(WIFI_ERROR,
+                                       "Failed to connect to the D-BUS daemon [%s]", error->message);
+                       g_error_free(error);
+               }
+               return NULL;
+       }
+       /* LCOV_EXCL_STOP */
+
        reply = g_dbus_connection_call_sync(connection,
                        dest,
                        path,
@@ -863,6 +872,8 @@ GVariant *_net_invoke_dbus_method(network_info_s *network_info,
                        *dbus_error = NET_ERR_UNKNOWN; //LCOV_EXCL_LINE
                }
 
+               if (created)
+                       g_object_unref(connection);
                __NETWORK_FUNC_EXIT__;
                return NULL;
        }
@@ -4328,3 +4339,35 @@ int _net_dbus_get_country_code(network_info_s *network_info, char **country)
        __NETWORK_FUNC_EXIT__;
        return Error;
 }
+
+int _net_dbus_get_vconf_value(network_info_s *network_info,
+               const char *key, const char *type, int *ret, int *int_value, char **str_value)
+{
+       __NETWORK_FUNC_ENTER__;
+
+       net_err_e ret_error = NET_ERR_NONE;
+       GVariant *message = NULL;
+       GVariant *params = NULL;
+
+       params = g_variant_new("(ss)", key, type);
+       message = _net_invoke_dbus_method(network_info,
+                       NETCONFIG_SERVICE, NETCONFIG_NETWORK_PATH,
+                       NETCONFIG_NETWORK_INTERFACE, "RequestVconfValue",
+                       params, &ret_error);
+
+       if (message == NULL) {
+               WIFI_LOG(WIFI_ERROR, "Failed to get vconf value, key: %s", key);
+               __NETWORK_FUNC_EXIT__;
+               return ret_error;
+       }
+
+       g_variant_get(message, "(iis)", ret, int_value, str_value);
+
+       WIFI_LOG(WIFI_INFO, "Vconf key: %s, type: %s, ret: %d, int_value: %d, str_value: %s",
+                       key, type, *ret, *int_value, *str_value);
+
+       g_variant_unref(message);
+
+       __NETWORK_FUNC_EXIT__;
+       return ret_error;
+}
index 7ff7012..dd317d6 100644 (file)
@@ -229,6 +229,8 @@ int _net_dbus_get_random_mac_lifetime(network_info_s *network_info, unsigned int
 
 int _net_dbus_set_country_code(network_info_s *network_info, const char *country);
 int _net_dbus_get_country_code(network_info_s *network_info, char **country);
+int _net_dbus_get_vconf_value(network_info_s *network_info,
+               const char *key, const char *type, int *ret, int *int_value, char **str_value);
 
 #ifdef __cplusplus
 }
index 4e46898..87ae1c4 100644 (file)
@@ -2099,7 +2099,7 @@ int net_wifi_power_on(network_info_s *network_info, gboolean wifi_picker_test)
        }
 
        /* TODO */
-       if (vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_MODE, &hotspot_state) != 0) {
+       if (_net_vconf_get_int(network_info, VCONFKEY_MOBILE_HOTSPOT_MODE, &hotspot_state) != 0) {
                WIFI_LOG(WIFI_ERROR, "Failed to get vconf key of hotspot mode"); //LCOV_EXCL_LINE
                __NETWORK_FUNC_EXIT__; //LCOV_EXCL_LINE
                return NET_ERR_INVALID_OPERATION; //LCOV_EXCL_LINE
index 43da9a6..1d7f6ec 100644 (file)
@@ -20,6 +20,8 @@
 #include "network_internal.h"
 #include "network_dbus.h"
 
+static gboolean in_container = FALSE;
+
 //LCOV_EXCL_START
 static char *__convert_eap_type_to_string(gchar eap_type)
 {
@@ -96,6 +98,76 @@ static char *__convert_eap_keymgmt_type_to_string(gchar eap_keymgmt)
        }
 }
 
+char *_net_vconf_get_str(network_info_s *network_info, const char *key)
+{
+       int ret = 0;
+       int int_value = 0;
+       char *str_value = NULL;
+
+       if (!in_container) {
+               str_value = vconf_get_str(key);
+               if (!str_value)
+                       WIFI_LOG(WIFI_ERROR, "Failed to get vconfkey [%s] value", key);
+
+               return str_value;
+       }
+
+       if (_net_dbus_get_vconf_value(network_info, key, "string", &ret, &int_value, &str_value) != NET_ERR_NONE)
+               return NULL;
+
+       return str_value;
+}
+
+int _net_vconf_get_int(network_info_s *network_info, const char *key, int *value)
+{
+       int ret = 0;
+       int int_value = 0;
+       char *str_value = NULL;
+
+       if (!in_container) {
+               ret = vconf_get_int(key, value);
+               if (ret != VCONF_OK)
+                       WIFI_LOG(WIFI_ERROR, "Failed to get vconfkey [%s] value", key);
+
+               return ret;
+       }
+
+       if (_net_dbus_get_vconf_value(network_info, key, "int", &ret, &int_value, &str_value) != NET_ERR_NONE)
+               return VCONF_ERROR;
+
+       *value = int_value;
+
+       if (str_value)
+               g_free(str_value);
+
+       return ret;
+}
+
+int _net_vconf_get_bool(network_info_s *network_info, const char *key, int *value)
+{
+       int ret = 0;
+       int int_value = 0;
+       char *str_value = NULL;
+
+       if (!in_container) {
+               ret = vconf_get_bool(key, value);
+               if (ret != VCONF_OK)
+                       WIFI_LOG(WIFI_ERROR, "Failed to get vconfkey [%s] value", key);
+
+               return ret;
+       }
+
+       if (_net_dbus_get_vconf_value(network_info, key, "bool", &ret, &int_value, &str_value) != NET_ERR_NONE)
+               return VCONF_ERROR;
+
+       *value = int_value;
+
+       if (str_value)
+               g_free(str_value);
+
+       return ret;
+}
+
 char* _net_print_error(net_err_e error)
 {
        switch (error) {
@@ -404,6 +476,9 @@ int _net_dbus_create_gdbus_call(network_info_s *network_info)
                                DBUS_HOST_SYSTEM_BUS_ADDRESS,
                                G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT | G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION,
                                NULL, NULL, &error);
+
+               if (!in_container)
+                       in_container = TRUE;
        } else
                network_info->connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
 
index 5176b7a..455d07e 100644 (file)
@@ -140,6 +140,11 @@ typedef enum {
 
 int _net_get_tech_state(network_info_s *network_info,
                GVariant *iter, network_tech_state_info_s* tech_state);
+
+char *_net_vconf_get_str(network_info_s *network_info, const char *key);
+int _net_vconf_get_int(network_info_s *network_info, const char *key, int *value);
+int _net_vconf_get_bool(network_info_s *network_info, const char *key, int *value);
+
 char* _net_print_error(net_err_e error);
 int _net_open_connection_with_wifi_info(network_info_s *network_info,
                const net_wifi_connection_info_s* wifi_info);
index 5fdfe3a..30f037a 100644 (file)
@@ -1739,7 +1739,7 @@ int _wifi_get_mac_address(wifi_manager_h wifi, char **mac_address)
                *mac_address = g_strdup(buf);
                fclose(fp);
        } else {
-               *mac_address = vconf_get_str(VCONFKEY_WIFI_BSSID_ADDRESS);
+               *mac_address = _net_vconf_get_str(wifi_handle->network_info, VCONFKEY_WIFI_BSSID_ADDRESS);
 
                if (*mac_address == NULL) {
                        WIFI_LOG(WIFI_ERROR, "Failed to get vconf" //LCOV_EXCL_LINE
@@ -2148,7 +2148,7 @@ int _wifi_bssid_scan_request(wifi_manager_h wifi,
        int activated = -1;
        int flight_mode = -1;
 
-       if (vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &flight_mode) != 0) {
+       if (_net_vconf_get_bool(wifi_handle->network_info, VCONFKEY_TELEPHONY_FLIGHT_MODE, &flight_mode) != 0) {
                WIFI_LOG(WIFI_ERROR, "Failed to get vconf key of flight mode"); //LCOV_EXCL_LINE
                return WIFI_MANAGER_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
        }
@@ -2257,7 +2257,7 @@ int _wifi_netlink_scan_request(wifi_manager_h wifi, wifi_manager_netlink_scan_h
        /** When softap mode is enabled wifi device is in deactivated state,
          so to search APs wifi_manager_netlink_scan() API is used.
          When wifi device is in activated state use wifi_manager_scan() API instead. */
-       if (vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_MODE, &is_on) != 0) {
+       if (_net_vconf_get_int(wifi_handle->network_info, VCONFKEY_MOBILE_HOTSPOT_MODE, &is_on) != 0) {
                WIFI_LOG(WIFI_ERROR, "Failed to get vconf key of hotspot mode");
                return WIFI_MANAGER_ERROR_OPERATION_FAILED;
        }