#define __NET_CONNECTION_INTF_H__
-#include "connection_profile.h"
+#include <connection_profile.h>
#ifdef __cplusplus
*/
typedef void(*connection_set_default_cb)(connection_error_e result, void* user_data);
-/* @brief Called with an IPv6 address.
+/**
+ * @brief Called with an IPv6 address.
* @since_tizen 4.0
* @remarks If @a ipv6_address is needed outside the callback, a copy should be made. \n
* @a ipv6_address will be freed automatically after the execution of this callback.
/**
+ * @brief Gets if the current connection is metered.
+ * @since_tizen 4.0
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/network.get
+ * @param[in] connection The connection handle
+ * @param[out] is_metered The value indicating whether it is metered
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #CONNECTION_ERROR_NONE Successful
+ * @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #CONNECTION_ERROR_OPERATION_FAILED Operation failed
+ * @retval #CONNECTION_ERROR_PERMISSION_DENIED Permission denied
+ * @retval #CONNECTION_ERROR_NOT_SUPPORTED Not supported
+ */
+int connection_is_metered_network(connection_h connection, bool* is_metered);
+
+
+/**
* @brief Gets the state of cellular connection.
* @details The returned state is for the cellular connection state.
* @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
* @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter
* @retval #CONNECTION_ERROR_OPERATION_FAILED Operation failed
* @retval #CONNECTION_ERROR_PERMISSION_DENIED Permission denied
- * @retval #CONNECTION_ERROR_NOT_SUPPORTED Not supported
+ * @retval #CONNECTION_ERROR_NOT_SUPPORTED Not supported
*/
int connection_get_wifi_state(connection_h connection, connection_wifi_state_e* state);
* @param[in] profile_iterator The iterator of profile
* @return @c true if next element exists,
* otherwise @c false if next element doesn't exist
+ * @exception #CONNECTION_ERROR_NONE Successful
+ * @exception #CONNECTION_ERROR_NOT_SUPPORTED Not supported
+ * @see get_last_result()
*/
bool connection_profile_iterator_has_next(connection_profile_iterator_h profile_iterator);
connection_address_family_e address_family, const char *interface_name,
const char *host_address, const char *gateway);
-/*
+/**
* @brief Gets all IPv6 addresses assigned to the network interface.
* @since_tizen 4.0
* @param[in] connection The connection handle
* @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
* @privlevel public
* @privilege %http://tizen.org/privilege/network.set
- * @remarks This API needs both privileges.
* @param[in] connection The connection handle
* @param[in] connection_type The type of connection \n
* Only CONNECTION_TYPE_WIFI and CONNECTION_TYPE_CELLULAR are supported
}
+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;
}
//LCOV_EXCL_STOP
+int _connection_libnet_get_metered_state(bool* is_metered)
+{
+ int rv = 0;
+ int status = 0;
+
+ rv = net_get_metered_state(&status);
+ if (rv == NET_ERR_ACCESS_DENIED) {
+ CONNECTION_LOG(CONNECTION_ERROR, "Access denied");
+ return CONNECTION_ERROR_PERMISSION_DENIED;
+ } else if (rv != NET_ERR_NONE) {
+ CONNECTION_LOG(CONNECTION_ERROR, "Failed to get metered state[%d]", rv);
+ return CONNECTION_ERROR_OPERATION_FAILED;
+ }
+
+ if (status == 1)
+ *is_metered = true;
+ else
+ *is_metered = false;
+ return CONNECTION_ERROR_NONE;
+}
+
int _connection_libnet_get_wifi_state(connection_wifi_state_e *state)
{
int rv;
return 1;
}
+int test_is_metered_network(void)
+{
+ int rv = 0;
+ bool metered_state;
+
+ rv = connection_is_metered_network(connection, &metered_state);
+
+ if (rv != CONNECTION_ERROR_NONE) {
+ printf("Fail to get metered state [%s]\n", test_print_error(rv));
+ return -1;
+ }
+
+ printf("Retval = [%s] metered state [%s]\n",
+ test_print_error(rv), metered_state ? "TRUE" : "FALSE");
+
+ return 1;
+}
int main(int argc, char **argv)
{
printf("D - Add new route entry\n");
printf("E - Remove route entry\n");
printf("F - Get all IPv6 address\n");
+ printf("G - Get metered state\n");
printf(LOG_RED "0 - Exit \n" LOG_END);
printf("ENTER - Show options menu.......\n");
}
case 'F':
rv = test_foreach_ipv6_address();
break;
+ case 'G':
+ rv = test_is_metered_network();
+ break;
}
if (rv == 1)