Merge "Remove DEPRECATED connection_set_ethernet_cable_state_chaged_cb() call" into... accepted/tizen_5.5_unified_mobile_hotfix tizen_5.5_mobile_hotfix tizen_5.5_tv accepted/tizen/5.5/unified/20191031.030104 accepted/tizen/5.5/unified/mobile/hotfix/20201027.064104 accepted/tizen/unified/20191011.015511 submit/tizen/20191010.060003 submit/tizen_5.5/20191031.000002 submit/tizen_5.5_mobile_hotfix/20201026.185102 tizen_5.5.m2_release
authorJaehyun Kim <jeik01.kim@samsung.com>
Thu, 10 Oct 2019 05:58:32 +0000 (05:58 +0000)
committerGerrit Code Review <gerrit@review.ap-northeast-2.compute.internal>
Thu, 10 Oct 2019 05:58:32 +0000 (05:58 +0000)
include/connection_profile.h
include/net_connection.h
include/net_connection_private.h
src/connection.c
src/connection_profile.c
src/libnetwork.c
test/connection_test.c

index 2bb50b0..34c216d 100755 (executable)
@@ -84,7 +84,7 @@ typedef enum {
        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 */
@@ -234,6 +234,15 @@ typedef enum {
        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.
@@ -400,6 +409,20 @@ int connection_profile_refresh(connection_profile_h profile);
 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.
index 90fd750..f9d6070 100755 (executable)
@@ -62,7 +62,7 @@ typedef enum {
        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;
 
 
@@ -183,6 +183,21 @@ typedef enum {
        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,
@@ -198,11 +213,6 @@ typedef enum {
        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,
@@ -228,16 +238,6 @@ typedef enum {
        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,
@@ -367,8 +367,8 @@ typedef void(*connection_set_default_cb)(connection_error_e result, void* user_d
  * @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);
 
@@ -521,6 +521,46 @@ int connection_get_wifi_state(connection_h connection, connection_wifi_state_e*
  */
 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.
@@ -558,7 +598,7 @@ typedef void(*connection_ethernet_cable_state_chaged_cb)
  * @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,
@@ -577,7 +617,7 @@ int connection_set_ethernet_cable_state_chaged_cb(connection_h connection,
  * @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
@@ -601,7 +641,7 @@ typedef void(*connection_ethernet_cable_state_changed_cb)(
 /**
  * @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,
@@ -619,7 +659,7 @@ int connection_set_ethernet_cable_state_changed_cb(connection_h connection,
 /**
  * @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
index 1e73281..1af2a6e 100755 (executable)
@@ -116,6 +116,7 @@ typedef struct _connection_handle_s {
        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;
@@ -124,6 +125,7 @@ typedef struct _connection_handle_s {
        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;
index 61b87cb..b90606f 100755 (executable)
@@ -100,6 +100,13 @@ static void __connection_set_proxy_changed_callback(connection_handle_s *conn_ha
        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)
 {
@@ -193,6 +200,7 @@ EXPORT_API int connection_destroy(connection_h connection)
        __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);
 
@@ -838,6 +846,43 @@ EXPORT_API int connection_unset_proxy_address_changed_cb(connection_h 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;
index 4955d48..b63afdd 100755 (executable)
@@ -547,6 +547,29 @@ EXPORT_API int connection_profile_get_state(connection_profile_h profile, connec
        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)
 {
index f40966f..2d60d7c 100755 (executable)
@@ -370,6 +370,42 @@ static void __libnet_evt_cb(net_event_info_t *event_cb, void *user_data)
                                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;
index 5ea1d4e..7236b33 100755 (executable)
@@ -92,6 +92,14 @@ static const char *test_print_state(connection_profile_state_e state)
        }
 }
 
+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) {
@@ -257,6 +265,11 @@ static void test_proxy_changed_callback(const char* ipv4_address, const char* ip
                        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;
@@ -1034,6 +1047,7 @@ int test_register_client(void)
                connection_set_proxy_address_changed_cb(connection, test_proxy_changed_callback, NULL);
                connection_set_ethernet_cable_state_changed_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;
@@ -1628,6 +1642,7 @@ int test_get_profile_info(void)
        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;
@@ -1656,6 +1671,11 @@ int test_get_profile_info(void)
        } 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;