Get vconf value via DBus in container environment 99/266299/2 accepted/tizen/unified/20211129.120848 submit/tizen/20211117.050637 submit/tizen/20211125.124313 submit/tizen/20211126.045758
authorJaehyun Kim <jeik01.kim@samsung.com>
Wed, 10 Nov 2021 09:47:37 +0000 (18:47 +0900)
committerJaehyun Kim <jeik01.kim@samsung.com>
Wed, 10 Nov 2021 10:03:06 +0000 (19:03 +0900)
Change-Id: Ie9f082cb8285f5a62ed15f56f98e4dae0582f798
Signed-off-by: Jaehyun Kim <jeik01.kim@samsung.com>
include/net_connection_private.h
src/connection.c
src/connection_profile.c
src/libnetwork.c

index 5163a73..0e077b6 100755 (executable)
@@ -135,6 +135,10 @@ typedef struct _connection_handle_s {
        void *network_info_handle;
 } connection_handle_s;
 
+char *_connection_vconf_get_str(connection_handle_s *conn_handle, const char *key);
+int _connection_vconf_get_int(connection_handle_s *conn_handle, const char *key, int *value);
+int _connection_vconf_get_bool(connection_handle_s *conn_handle, const char *key, int *value);
+
 int _connection_libnet_init(connection_handle_s *conn_handle);
 bool _connection_libnet_deinit(connection_handle_s *conn_handle, bool is_empty);
 void _connection_set_cs_tid(int tid, connection_handle_s *conn_handle);
@@ -217,6 +221,7 @@ void _connection_lock(void);
 void _connection_unlock(void);
 
 bool _connection_check_handle_validity(connection_h connection);
+void *_connection_get_default_handle(void);
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
index 0048efb..37856ac 100755 (executable)
@@ -79,6 +79,17 @@ bool _connection_check_handle_validity(connection_h connection)
        return __connection_check_handle_validity(connection);
 }
 
+void *_connection_get_default_handle(void)
+{
+       GSList *list = NULL;
+
+       for (list = conn_handle_list; list; list = list->next)
+               if (list->data)
+                       return list->data;
+
+       return NULL;
+}
+
 static void __connection_set_type_changed_callback(connection_handle_s *conn_handle,
                        void *callback, void *user_data)
 {
@@ -268,7 +279,7 @@ EXPORT_API int connection_get_type(connection_h connection, connection_type_e* t
                return CONNECTION_ERROR_INVALID_PARAMETER;
        }
 
-       rv = vconf_get_int(VCONFKEY_NETWORK_STATUS, &status);
+       rv = _connection_vconf_get_int(connection, VCONFKEY_NETWORK_STATUS, &status);
        if (rv != VCONF_OK) {
                CONNECTION_LOG(CONNECTION_ERROR, "vconf_get_int Failed = %d", status); //LCOV_EXCL_LINE
                CONN_UNLOCK; //LCOV_EXCL_LINE
@@ -298,10 +309,10 @@ EXPORT_API int connection_get_ip_address(connection_h connection,
 
        switch (address_family) {
        case CONNECTION_ADDRESS_FAMILY_IPV4:
-               *ip_address = vconf_get_str(VCONFKEY_NETWORK_IP);
+               *ip_address = _connection_vconf_get_str(connection, VCONFKEY_NETWORK_IP);
                break;
        case CONNECTION_ADDRESS_FAMILY_IPV6:
-               *ip_address = vconf_get_str(VCONFKEY_NETWORK_IP6);
+               *ip_address = _connection_vconf_get_str(connection, VCONFKEY_NETWORK_IP6);
                break;
        default:
                CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
@@ -335,7 +346,7 @@ EXPORT_API int connection_get_proxy(connection_h connection,
        switch (address_family) {
        case CONNECTION_ADDRESS_FAMILY_IPV4:
        case CONNECTION_ADDRESS_FAMILY_IPV6:
-               *proxy = vconf_get_str(VCONFKEY_NETWORK_PROXY);
+               *proxy = _connection_vconf_get_str(connection, VCONFKEY_NETWORK_PROXY);
                break;
        default:
                CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
@@ -391,7 +402,7 @@ EXPORT_API int connection_get_mac_address(connection_h connection, connection_ty
                        *mac_addr = g_strdup(buf);
                        fclose(fp);
                } else {
-                       *mac_addr = vconf_get_str(VCONFKEY_WIFI_BSSID_ADDRESS);
+                       *mac_addr = _connection_vconf_get_str(connection, VCONFKEY_WIFI_BSSID_ADDRESS);
 
                        if (*mac_addr == NULL) {
                                CONNECTION_LOG(CONNECTION_ERROR, "Failed to get vconf from %s", VCONFKEY_WIFI_BSSID_ADDRESS); //LCOV_EXCL_LINE
@@ -496,7 +507,7 @@ EXPORT_API int connection_get_cellular_state(connection_h connection, connection
                return CONNECTION_ERROR_INVALID_PARAMETER;
        }
 
-       rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_STATE, &status);
+       rv = _connection_vconf_get_int(connection, VCONFKEY_NETWORK_CELLULAR_STATE, &status);
        if (rv != VCONF_OK) {
                CONNECTION_LOG(CONNECTION_ERROR, "Failed to get cellular state"); //LCOV_EXCL_LINE
                CONN_UNLOCK; //LCOV_EXCL_LINE
@@ -508,7 +519,7 @@ EXPORT_API int connection_get_cellular_state(connection_h connection, connection
 
        if (*state == CONNECTION_CELLULAR_STATE_AVAILABLE) {
 #if defined TIZEN_DUALSIM_ENABLE
-               rv = vconf_get_int(VCONF_TELEPHONY_DEFAULT_DATA_SERVICE, &sim_id);
+               rv = _connection_vconf_get_int(connection, VCONF_TELEPHONY_DEFAULT_DATA_SERVICE, &sim_id);
                if (rv != VCONF_OK) {
                        CONNECTION_LOG(CONNECTION_ERROR,
                                        "Failed to get default subscriber id", sim_id);
@@ -519,12 +530,12 @@ EXPORT_API int connection_get_cellular_state(connection_h connection, connection
                switch (sim_id) {
                case CONNECTION_CELLULAR_SUBSCRIBER_1:
 #endif
-                       rv = vconf_get_int(VCONFKEY_DNET_STATE, &cellular_state);
+                       rv = _connection_vconf_get_int(connection, VCONFKEY_DNET_STATE, &cellular_state);
 #if defined TIZEN_DUALSIM_ENABLE
                        break;
 
                case CONNECTION_CELLULAR_SUBSCRIBER_2:
-                       rv = vconf_get_int(VCONFKEY_DNET_STATE2, &cellular_state);
+                       rv = _connection_vconf_get_int(connection, VCONFKEY_DNET_STATE2, &cellular_state);
                        break;
 
                default:
@@ -1423,7 +1434,8 @@ EXPORT_API int connection_remove_route_entry(connection_h connection,
        }
 }
 
-static int __get_cellular_statistic(connection_statistics_type_e statistics_type, long long *llsize)
+static int __get_cellular_statistic(connection_handle_s *conn_handle,
+               connection_statistics_type_e statistics_type, long long *llsize)
 {
        int rv = VCONF_OK, rv1 = VCONF_OK;
        int last_size = 0, size = 0;
@@ -1447,7 +1459,7 @@ static int __get_cellular_statistic(connection_statistics_type_e statistics_type
        }
 
 #if defined TIZEN_DUALSIM_ENABLE
-       rv = vconf_get_int(VCONF_TELEPHONY_DEFAULT_DATA_SERVICE, &sim_id);
+       rv = _connection_vconf_get_int(conn_handle, VCONF_TELEPHONY_DEFAULT_DATA_SERVICE, &sim_id);
        if (rv != VCONF_OK) {
                CONNECTION_LOG(CONNECTION_ERROR, "Failed to get default subscriber id");
                *llsize = 0;
@@ -1459,18 +1471,18 @@ static int __get_cellular_statistic(connection_statistics_type_e statistics_type
 #endif
                switch (statistics_type) {
                case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
-                       rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT, &last_size);
+                       rv = _connection_vconf_get_int(conn_handle, VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT, &last_size);
                        break;
                case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
-                       rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV, &last_size);
+                       rv = _connection_vconf_get_int(conn_handle, VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV, &last_size);
                        break;
                case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
-                       rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT, &last_size);
-                       rv1 = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_SNT, &size);
+                       rv = _connection_vconf_get_int(conn_handle, VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT, &last_size);
+                       rv1 = _connection_vconf_get_int(conn_handle, VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_SNT, &size);
                        break;
                case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
-                       rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV, &last_size);
-                       rv1 = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_RCV, &size);
+                       rv = _connection_vconf_get_int(conn_handle, VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV, &last_size);
+                       rv1 = _connection_vconf_get_int(conn_handle, VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_RCV, &size);
                        break;
                }
 #if defined TIZEN_DUALSIM_ENABLE
@@ -1478,18 +1490,18 @@ static int __get_cellular_statistic(connection_statistics_type_e statistics_type
        case 1:
                switch (statistics_type) {
                case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
-                       rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT2, &last_size);
+                       rv = _connection_vconf_get_int(conn_handle, VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT2, &last_size);
                        break;
                case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA:
-                       rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV2, &last_size);
+                       rv = _connection_vconf_get_int(conn_handle, VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV2, &last_size);
                        break;
                case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA:
-                       rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT2, &last_size);
-                       rv1 = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_SNT2, &size);
+                       rv = _connection_vconf_get_int(conn_handle, VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT2, &last_size);
+                       rv1 = _connection_vconf_get_int(conn_handle, VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_SNT2, &size);
                        break;
                case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA:
-                       rv = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV2, &last_size);
-                       rv1 = vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_RCV2, &size);
+                       rv = _connection_vconf_get_int(conn_handle, VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV2, &last_size);
+                       rv1 = _connection_vconf_get_int(conn_handle, VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_RCV2, &size);
                        break;
                }
                break;
@@ -1531,7 +1543,7 @@ static int __get_statistic(connection_handle_s *conn_handle, connection_type_e c
        }
 
        if (connection_type == CONNECTION_TYPE_CELLULAR)
-               return __get_cellular_statistic(statistics_type, llsize);
+               return __get_cellular_statistic(conn_handle, statistics_type, llsize);
        else if (connection_type == CONNECTION_TYPE_WIFI) {
                switch (statistics_type) {
                case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA:
index 11c6ecf..fb778df 100755 (executable)
@@ -218,7 +218,8 @@ static void __profile_init_cellular_profile(net_profile_info_t *profile_info, co
        profile_info->profile_info.pdp.net_info.proxy_method = NET_PROXY_TYPE_DIRECT;
        g_strlcpy(profile_info->profile_info.pdp.keyword, keyword, NET_PDP_APN_LEN_MAX);
 
-       if (vconf_get_int(VCONF_TELEPHONY_DEFAULT_DATA_SERVICE,
+       if (_connection_vconf_get_int(_connection_get_default_handle(),
+                                       VCONF_TELEPHONY_DEFAULT_DATA_SERVICE,
                                        &default_subscriber_id) != 0)
                CONNECTION_LOG(CONNECTION_ERROR, //LCOV_EXCL_LINE
                                                "Failed to get VCONF_TELEPHONY_DEFAULT_DATA_SERVICE");
@@ -259,7 +260,7 @@ static char *__profile_get_ethernet_proxy(void)
 {
        char *proxy;
 
-       proxy = vconf_get_str(VCONFKEY_NETWORK_PROXY);
+       proxy = _connection_vconf_get_str(_connection_get_default_handle(), VCONFKEY_NETWORK_PROXY);
 
        if (proxy == NULL) {
                CONNECTION_LOG(CONNECTION_ERROR, "Fail to get system proxy");
index 81aaf10..6ae47e0 100755 (executable)
 #include <vconf/vconf.h>
 #include <system_info.h>
 #include <arpa/inet.h>
+#include <unistd.h>
 
 #include "net_connection_private.h"
 
+#define CONTAINER_FILE "/run/systemd/container"
+
 static GSList *prof_handle_list = NULL;
 static GHashTable *profile_cb_table = NULL;
 static pthread_mutex_t g_conn_thread_mutex = PTHREAD_MUTEX_INITIALIZER;
 static __thread int g_conn_thread_mutex_ref = 0;
+static gboolean in_container = FALSE;
 
 struct _profile_cb_s {
        connection_profile_state_changed_cb callback;
@@ -136,6 +140,79 @@ static const char *__libnet_convert_cp_state_to_string(connection_profile_state_
        }
 }
 
+char *_connection_vconf_get_str(connection_handle_s *conn_handle, 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)
+                       CONNECTION_LOG(CONNECTION_ERROR, "Failed to get vconfkey [%s] value", key);
+
+               return str_value;
+       }
+
+       if (conn_handle && net_get_vconf_value(conn_handle->network_info_handle,
+                       key, "string", &ret, &int_value, &str_value) != NET_ERR_NONE)
+               return NULL;
+
+       return str_value;
+}
+
+int _connection_vconf_get_int(connection_handle_s *conn_handle, 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)
+                       CONNECTION_LOG(CONNECTION_ERROR, "Failed to get vconfkey [%s] value", key);
+
+               return ret;
+       }
+
+       if (conn_handle && net_get_vconf_value(conn_handle->network_info_handle,
+                       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 _connection_vconf_get_bool(connection_handle_s *conn_handle, 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)
+                       CONNECTION_LOG(CONNECTION_ERROR, "Failed to get vconfkey [%s] value", key);
+
+               return ret;
+       }
+
+       if (conn_handle && net_get_vconf_value(conn_handle->network_info_handle,
+                       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;
+}
+
 static void __libnet_state_changed_cb(char *profile_name, connection_profile_state_e state)
 {
        struct _profile_cb_s *cb_info;
@@ -341,7 +418,7 @@ static void __libnet_evt_cb(net_event_info_t *event_cb, void *user_data)
                        char *addr = (char *)event_cb->data;
 
                        ipv4_addr = g_strdup(addr);
-                       ipv6_addr = vconf_get_str(VCONFKEY_NETWORK_IP6);
+                       ipv6_addr = _connection_vconf_get_str(conn_handle, VCONFKEY_NETWORK_IP6);
                        if (ipv6_addr == NULL)
                                CONNECTION_LOG(CONNECTION_ERROR, //LCOV_EXCL_LINE
                                                "vconf_get_str(VCONFKEY_NETWORK_IP6) failed");
@@ -361,7 +438,7 @@ static void __libnet_evt_cb(net_event_info_t *event_cb, void *user_data)
                        char *addr = (char *)event_cb->data;
 
                        ipv6_addr = g_strdup(addr);
-                       ipv4_addr = vconf_get_str(VCONFKEY_NETWORK_IP);
+                       ipv4_addr = _connection_vconf_get_str(conn_handle, VCONFKEY_NETWORK_IP);
                        if (ipv4_addr == NULL)
                                CONNECTION_LOG(CONNECTION_ERROR, //LCOV_EXCL_LINE
                                                "vconf_get_str(VCONFKEY_NETWORK_IP) failed");
@@ -497,6 +574,9 @@ int _connection_libnet_init(connection_handle_s *conn_handle)
        if (profile_cb_table == NULL)
                profile_cb_table = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
 
+       if (!in_container && access(CONTAINER_FILE, F_OK) == 0)
+               in_container = TRUE;
+
        return NET_ERR_NONE;
 }
 
@@ -923,7 +1003,7 @@ int _connection_libnet_get_cellular_service_profile(connection_handle_s *conn_ha
        }
 
 #if defined TIZEN_DUALSIM_ENABLE
-       if (vconf_get_int(VCONF_TELEPHONY_DEFAULT_DATA_SERVICE,
+       if (_connection_vconf_get_int(conn_handle, VCONF_TELEPHONY_DEFAULT_DATA_SERVICE,
                                                &default_subscriber_id) != 0) {
                CONNECTION_LOG(CONNECTION_ERROR,
                                                "Failed to get VCONF_TELEPHONY_DEFAULT_DATA_SERVICE");