Add new API to check whether metered or non metered
[platform/core/api/connection.git] / src / connection.c
index 348a3a2..2b74071 100755 (executable)
@@ -667,6 +667,26 @@ EXPORT_API int connection_get_mac_address(connection_h connection, connection_ty
 }
 
 
+EXPORT_API int connection_is_metered_network(connection_h connection, bool* is_metered)
+{
+       CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE);
+
+       if (is_metered == NULL || !(__connection_check_handle_validity(connection))) {
+               CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
+               return CONNECTION_ERROR_INVALID_PARAMETER;
+       }
+
+       int rv = _connection_libnet_get_metered_state(is_metered);
+       if (rv != CONNECTION_ERROR_NONE) {
+               CONNECTION_LOG(CONNECTION_ERROR, "Fail to get metered state[%d]", rv); //LCOV_EXCL_LINE
+               return rv; //LCOV_EXCL_LINE
+       }
+
+       CONNECTION_LOG(CONNECTION_INFO, "metered state: %s", is_metered ? "true" : "false");
+       return CONNECTION_ERROR_NONE;
+}
+
+
 EXPORT_API int connection_get_cellular_state(connection_h connection, connection_cellular_state_e* state)
 {
        int rv = 0;
@@ -1208,6 +1228,54 @@ EXPORT_API int connection_remove_route_ipv6(connection_h connection, const char
        return _connection_libnet_remove_route_ipv6(interface_name, host_address, gateway);
 }
 
+EXPORT_API int connection_add_route_entry(connection_h connection,
+               connection_address_family_e address_family,     const char *interface_name,
+               const char *host_address, const char *gateway)
+{
+       CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, ETHERNET_FEATURE);
+
+       if (!(__connection_check_handle_validity(connection)) ||
+               (address_family != CONNECTION_ADDRESS_FAMILY_IPV4 &&
+            address_family != CONNECTION_ADDRESS_FAMILY_IPV6) ||
+           interface_name == NULL || host_address == NULL) {
+               CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
+               return CONNECTION_ERROR_INVALID_PARAMETER;
+       }
+
+       if (address_family == CONNECTION_ADDRESS_FAMILY_IPV4)
+               return _connection_libnet_add_route_entry(CONNECTION_ADDRESS_FAMILY_IPV4,
+                                                               interface_name, host_address, gateway);
+       else
+               return _connection_libnet_add_route_entry(CONNECTION_ADDRESS_FAMILY_IPV6,
+                                                               interface_name, host_address, gateway);
+
+       return CONNECTION_ERROR_NONE;
+}
+
+EXPORT_API int connection_remove_route_entry(connection_h connection,
+               connection_address_family_e address_family,     const char *interface_name,
+               const char *host_address, const char *gateway)
+{
+       CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, ETHERNET_FEATURE);
+
+       if (!(__connection_check_handle_validity(connection)) ||
+               (address_family != CONNECTION_ADDRESS_FAMILY_IPV4 &&
+            address_family != CONNECTION_ADDRESS_FAMILY_IPV6) ||
+           interface_name == NULL || host_address == NULL) {
+               CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
+               return CONNECTION_ERROR_INVALID_PARAMETER;
+       }
+
+       if (address_family == CONNECTION_ADDRESS_FAMILY_IPV4)
+               return _connection_libnet_remove_route_entry(CONNECTION_ADDRESS_FAMILY_IPV4,
+                                                               interface_name, host_address, gateway);
+       else
+               return _connection_libnet_remove_route_entry(CONNECTION_ADDRESS_FAMILY_IPV6,
+                                                               interface_name, host_address, gateway);
+
+       return CONNECTION_ERROR_NONE;
+}
+
 static int __get_cellular_statistic(connection_statistics_type_e statistics_type, long long *llsize)
 {
        int rv = VCONF_OK, rv1 = VCONF_OK;