CONNECTION_CELLULAR_SERVICE_TYPE_UNKNOWN = 0, /**< Unknown */
CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET = 1, /**< Internet */
CONNECTION_CELLULAR_SERVICE_TYPE_MMS = 2, /**< MMS */
- CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_INTERNET = 3, /**< Prepaid internet */
+ CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_INTERNET = 3, /**< Prepaid Internet */
CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_MMS = 4, /**< Prepaid MMS */
CONNECTION_CELLULAR_SERVICE_TYPE_TETHERING = 5, /**< Tethering */
CONNECTION_CELLULAR_SERVICE_TYPE_APPLICATION = 6, /**< Specific application */
CONNECTION_PROFILE_TYPE_BT = 3, /**< Bluetooth type */
} connection_profile_type_e;
+/**
+ * @brief Enumeration for Internet connection state.
+ * @since_tizen 5.5
+ */
+typedef enum {
+ CONNECTION_INTERNET_STATE_OFFLINE = 0, /**< Internet connection is unavailable */
+ CONNECTION_INTERNET_STATE_ONLINE = 1, /**< Internet connection is available */
+} connection_internet_state_e;
+
/**
* @brief Creates a profile handle.
int connection_profile_get_state(connection_profile_h profile,
connection_profile_state_e *state);
+/**
+ * @brief Gets the Internet connection state.
+ * @since_tizen 5.5
+ * @param[in] profile The profile handle
+ * @param[out] state The Internet connection state of the profile
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #CONNECTION_ERROR_NONE Successful
+ * @retval #CONNECTION_ERROR_NOT_INITIALIZED Not initialized
+ * @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #CONNECTION_ERROR_OPERATION_FAILED Operation failed
+*/
+int connection_profile_get_internet_state(connection_profile_h profile,
+ connection_internet_state_e *state);
/**
* @brief Gets the IP config type.
CONNECTION_TYPE_CELLULAR = 2, /**< Cellular type */
CONNECTION_TYPE_ETHERNET = 3, /**< Ethernet type */
CONNECTION_TYPE_BT = 4, /**< Bluetooth type */
- CONNECTION_TYPE_NET_PROXY, /**< Proxy type for internet connection (Since 3.0) */
+ CONNECTION_TYPE_NET_PROXY, /**< Proxy type for Internet connection (Since 3.0) */
} connection_type_e;
CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED = TIZEN_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED,
/**
+ * Now inprogress
+ */
+ CONNECTION_ERROR_NOW_IN_PROGRESS = TIZEN_ERROR_NOW_IN_PROGRESS,
+
+ /**
+ * Permission denied
+ */
+ CONNECTION_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED,
+
+ /**
+ * Not supported
+ */
+ CONNECTION_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED,
+
+ /**
* Operation failed
*/
CONNECTION_ERROR_OPERATION_FAILED = TIZEN_ERROR_CONNECTION|0x0401,
CONNECTION_ERROR_NO_CONNECTION = TIZEN_ERROR_CONNECTION|0x0403,
/**
- * Now inprogress
- */
- CONNECTION_ERROR_NOW_IN_PROGRESS = TIZEN_ERROR_NOW_IN_PROGRESS,
-
- /**
* Already exists
*/
CONNECTION_ERROR_ALREADY_EXISTS = TIZEN_ERROR_CONNECTION|0x0404,
CONNECTION_ERROR_NO_REPLY = TIZEN_ERROR_CONNECTION|0x0408,
/**
- * Permission denied
- */
- CONNECTION_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED,
-
- /**
- * Not supported
- */
- CONNECTION_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED,
-
- /**
* Already initialized (Since 5.0)
*/
CONNECTION_ERROR_ALREADY_INITIALIZED = TIZEN_ERROR_CONNECTION|0x0409,
/**
- * Not initialized (Sinece 5.0)
+ * Not initialized (Since 5.0)
*/
CONNECTION_ERROR_NOT_INITIALIZED = TIZEN_ERROR_CONNECTION|0x040A,
* @param[in] user_data The user data passed from the foreach function
* @return @c true to continue with the next iteration of the loop, \n
* @c false to break out of the loop
- * @pre connection_foreach_ipv6_addresses() will invoke this callback.
- * @see connection_foreach_ipv6_addresses()
+ * @pre connection_foreach_ipv6_address() will invoke this callback.
+ * @see connection_foreach_ipv6_address()
*/
typedef bool(*connection_ipv6_address_cb)(char *ipv6_address, void *user_data);
*/
int connection_get_ethernet_state(connection_h connection, connection_ethernet_state_e* state);
+/**
+ * @brief Called when the Internet state of the current connection is changed.
+ * @since_tizen 5.5
+ * @param[in] state The Internet state of current connection
+ * @param[in] user_data The user data passed to callback registration function
+ */
+typedef void(*connection_internet_state_changed_cb)(
+ connection_internet_state_e state, void* user_data);
+
+/**
+ * @brief Sets the callback that is called when the Internet availability over the current connection is changed.
+ * @since_tizen 5.5
+ * @param[in] connection The connection handle
+ * @param[in] callback The callback function to be called
+ * @param[in] user_data The user data passed to the callback function
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #CONNECTION_ERROR_NONE Successful
+ * @retval #CONNECTION_ERROR_NOT_INITIALIZED Not initialized
+ * @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #CONNECTION_ERROR_OPERATION_FAILED Operation failed
+ * @retval #CONNECTION_ERROR_NOT_SUPPORTED Not supported
+ */
+int connection_set_internet_state_changed_cb(connection_h connection,
+ connection_internet_state_changed_cb callback, void *user_data);
+
+
+/**
+ * @brief Unsets the callback that is called when the Internet state of the current connection is changed.
+ * @since_tizen 5.5
+ * @param[in] connection The connection handle
+ * @return @c 0 on success,
+ * otherwise a negative error value
+ * @retval #CONNECTION_ERROR_NONE Successful
+ * @retval #CONNECTION_ERROR_NOT_INITIALIZED Not initialized
+ * @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #CONNECTION_ERROR_OPERATION_FAILED Operation failed
+ * @retval #CONNECTION_ERROR_NOT_SUPPORTED Not supported
+ */
+int connection_unset_internet_state_changed_cb(connection_h connection);
/**
* @brief Checks for ethernet cable is attached or not.
* @deprecated Deprecated since 4.0. Use connection_set_ethernet_cable_state_changed_cb() instead.
* @brief Sets callback for ethernet cable is plugged [in/out] event.
* @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif
- * @param[in] connection The handle of connection
+ * @param[in] connection The connection handle
* @param[in] callback The callback function to be called
* @param[in] user_data The user data passed to the callback function
* @return @c 0 on success,
* @deprecated Deprecated since 4.0. Use connection_unset_ethernet_cable_state_changed_cb() instead.
* @brief Unsets callback for ethernet cable is plugged [in/out] event.
* @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif
- * @param[in] connection The handle of connection
+ * @param[in] connection The connection handle
* @return @c 0 on success,
* otherwise a negative error value
* @retval #CONNECTION_ERROR_NONE Successful
/**
* @brief Sets callback for ethernet cable is plugged [in/out] event.
* @since_tizen 4.0
- * @param[in] connection The handle of connection
+ * @param[in] connection The connection handle
* @param[in] callback The callback function to be called
* @param[in] user_data The user data passed to the callback function
* @return @c 0 on success,
/**
* @brief Unsets callback for ethernet cable is plugged [in/out] event.
* @since_tizen 4.0
- * @param[in] connection The handle of connection
+ * @param[in] connection The connection handle
* @return @c 0 on success,
* otherwise a negative error value
* @retval #CONNECTION_ERROR_NONE Successful
connection_type_changed_cb type_changed_callback;
connection_address_changed_cb ip_changed_callback;
connection_address_changed_cb proxy_changed_callback;
+ connection_internet_state_changed_cb internet_state_changed_callback;
connection_ethernet_cable_state_changed_cb ethernet_cable_state_changed_callback;
connection_set_default_cb set_default_callback;
connection_opened_cb opened_callback;
void *type_changed_user_data;
void *ip_changed_user_data;
void *proxy_changed_user_data;
+ void *internet_state_changed_user_data;
void *ethernet_cable_state_changed_user_data;
void *set_default_user_data;
void *opened_user_data;
conn_handle->proxy_changed_callback = callback;
}
+static void __connection_set_internet_state_changed_callback(connection_handle_s *conn_handle,
+ void *callback, void *user_data)
+{
+ conn_handle->internet_state_changed_user_data = user_data;
+ conn_handle->internet_state_changed_callback = callback;
+}
+
static void __connection_set_ethernet_cable_state_changed_cb(connection_handle_s *conn_handle,
void *callback, void *user_data)
{
__connection_set_type_changed_callback(connection, NULL, NULL);
__connection_set_ip_changed_callback(connection, NULL, NULL);
__connection_set_proxy_changed_callback(connection, NULL, NULL);
+ __connection_set_internet_state_changed_callback(connection, NULL, NULL);
__connection_set_ethernet_cable_state_changed_cb(connection, NULL, NULL);
_connection_libnet_deinit(connection);
return CONNECTION_ERROR_NONE;
}
+EXPORT_API int connection_set_internet_state_changed_cb(connection_h connection,
+ connection_internet_state_changed_cb callback, void *user_data)
+{
+ CONN_LOCK;
+
+ CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
+
+ if (callback == NULL || !(__connection_check_handle_validity(connection))) {
+ CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
+ CONN_UNLOCK;
+ return CONNECTION_ERROR_INVALID_PARAMETER;
+ }
+
+ __connection_set_internet_state_changed_callback(connection, callback, user_data);
+
+ CONN_UNLOCK;
+ return CONNECTION_ERROR_NONE;
+}
+
+EXPORT_API int connection_unset_internet_state_changed_cb(connection_h connection)
+{
+ CONN_LOCK;
+
+ CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
+
+ if (!(__connection_check_handle_validity(connection))) {
+ CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
+ CONN_UNLOCK;
+ return CONNECTION_ERROR_INVALID_PARAMETER;
+ }
+
+ __connection_set_internet_state_changed_callback(connection, NULL, NULL);
+
+ CONN_UNLOCK;
+ return CONNECTION_ERROR_NONE;
+}
+
EXPORT_API int connection_add_profile(connection_h connection, connection_profile_h profile)
{
int rv = 0;
return CONNECTION_ERROR_NONE;
}
+EXPORT_API int connection_profile_get_internet_state(connection_profile_h profile,
+ connection_internet_state_e *state)
+{
+ CONN_LOCK;
+
+ CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE);
+
+ if (!(_connection_libnet_check_profile_validity(profile)) || state == NULL) {
+ CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter");
+ CONN_UNLOCK;
+ return CONNECTION_ERROR_INVALID_PARAMETER;
+ }
+
+ net_profile_info_t *profile_info = profile;
+ if (profile_info->ProfileState == NET_STATE_TYPE_ONLINE)
+ *state = CONNECTION_INTERNET_STATE_ONLINE;
+ else
+ *state = CONNECTION_INTERNET_STATE_OFFLINE;
+
+ CONN_UNLOCK;
+ return CONNECTION_ERROR_NONE;
+}
+
EXPORT_API int connection_profile_get_ip_config_type(connection_profile_h profile,
connection_address_family_e address_family, connection_ip_config_type_e *type)
{
conn_handle->proxy_changed_user_data);
}
break;
+ case NET_EVENT_INTERNET_ONLINE_IND:
+ case NET_EVENT_INTERNET_OFFLINE_IND:
+ CONNECTION_LOG(CONNECTION_INFO, "Got Internet State Changed Indication: %s",
+ event_cb->Event == NET_EVENT_INTERNET_ONLINE_IND ? "Online" : "Offline");
+ net_device_t *device_type = (net_device_t *) event_cb->Data;
+
+ if (conn_handle->internet_state_changed_callback) {
+ net_profile_info_t active_profile;
+ int rv;
+
+ rv = net_get_active_net_info(conn_handle->network_info_handle, &active_profile);
+
+ if (rv == NET_ERR_NO_SERVICE && event_cb->Event == NET_EVENT_INTERNET_OFFLINE_IND) {
+ conn_handle->internet_state_changed_callback(CONNECTION_INTERNET_STATE_OFFLINE,
+ conn_handle->internet_state_changed_user_data); //LCOV_EXCL_LINE
+ break;
+ } else if (rv == NET_ERR_ACCESS_DENIED) {
+ CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); //LCOV_EXCL_LINE
+ break;
+ } else if (rv != NET_ERR_NONE) {
+ CONNECTION_LOG(CONNECTION_ERROR, "Unable to get Default profile handle"); //LCOV_EXCL_LINE
+ break; //LCOV_EXCL_LINE
+ }
+
+ if (event_cb->Event == NET_EVENT_INTERNET_ONLINE_IND) {
+ if (active_profile.ProfileState == NET_STATE_TYPE_ONLINE &&
+ active_profile.profile_type == *device_type)
+ conn_handle->internet_state_changed_callback(CONNECTION_INTERNET_STATE_ONLINE,
+ conn_handle->internet_state_changed_user_data);
+ } else {
+ if (active_profile.ProfileState != NET_STATE_TYPE_ONLINE)
+ conn_handle->internet_state_changed_callback(CONNECTION_INTERNET_STATE_OFFLINE,
+ conn_handle->internet_state_changed_user_data);
+ }
+ }
+ break;
default:
break;
}
}
+static const char *test_print_internet_state(connection_internet_state_e state)
+{
+ if (state == CONNECTION_INTERNET_STATE_ONLINE)
+ return "Online";
+
+ return "Offline";
+}
+
static const char *test_print_connection_type(connection_type_e type)
{
switch (type) {
ipv4_address, (ipv6_address ? ipv6_address : "NULL"));
}
+static void test_internet_state_changed_callback(connection_internet_state_e state, void* user_data)
+{
+ printf("Internet state changed callback, state : %d\n", state);
+}
+
static void test_profile_state_callback(connection_profile_state_e state, void* user_data)
{
char *profile_name;
connection_set_proxy_address_changed_cb(connection, test_proxy_changed_callback, NULL);
connection_set_ethernet_cable_state_chaged_cb(connection,
test_get_ethernet_cable_state_callback, NULL);
+ connection_set_internet_state_changed_cb(connection, test_internet_state_changed_callback, NULL);
} else {
printf("Client registration failed [%s]\n", test_print_error(err));
return -1;
connection_profile_type_e prof_type;
connection_profile_state_e profile_state;
connection_profile_state_e profile_ipv6_state;
+ connection_internet_state_e internet_state;
connection_profile_h profile;
char *profile_name = NULL;
int address_family = 0;
} else
printf("Profile IPv6 State : %s\n", test_print_state(profile_ipv6_state));
+ if (connection_profile_get_internet_state(profile, &internet_state) != CONNECTION_ERROR_NONE) {
+ printf("Fail to get Internet state\n");
+ return -1;
+ } else
+ printf("Internet State : %s\n", test_print_internet_state(internet_state));
if (connection_profile_get_type(profile, &prof_type) != CONNECTION_ERROR_NONE)
return -1;