diff --git a/network/netmanager/include/net_connection.h b/network/netmanager/include/net_connection.h index 9446b979f44c3da41f68a5eb0c59c5b987adbed6..4ef8dad6ec7ccae90938389518730374916ae624 100644 --- a/network/netmanager/include/net_connection.h +++ b/network/netmanager/include/net_connection.h @@ -219,6 +219,99 @@ int32_t OHOS_NetConn_UnregisterDnsResolver(void); */ int32_t OH_NetConn_BindSocket(int32_t socketFd, NetConn_NetHandle *netHandle); +/** + * @brief Sets http proxy information to current application. + * + * @param httpProxy Information about the proxy that needs to be set. + * @return 0 - Success. + * 401 - Parameter error. + * @syscap SystemCapability.Communication.NetManager.Core + * @since 12 + * @version 1.0 + */ +int32_t OH_NetConn_SetAppHttpProxy(NetConn_HttpProxy *httpProxy); + +/** + * @brief Registers callback to listen for changes to the application-level http proxy. + * + * @param appHttpProxyChange Callback that need to be registered to listen for changes to the http proxy. + * @param callbackId Callback id returned after registration, associated with a registered callback. + * @return 0 - Success. + * 401 - Parameter error. + * @syscap SystemCapability.Communication.NetManager.Core + * @since 12 + * @version 1.0 + */ +int32_t OH_NetConn_RegisterAppHttpProxyCallback(OH_NetConn_AppHttpProxyChange appHttpProxyChange, uint32_t *callbackId); + +/** + * @brief Unregisters a callback function that listens for application-level proxy changes. + * + * @param callbackId Id of the callback function that needs to be deregistered. + * @syscap SystemCapability.Communication.NetManager.Core + * @since 12 + * @version 1.0 + */ +void OH_NetConn_UnregisterAppHttpProxyCallback(uint32_t callbackId); + +/** + * @brief Register callback, used to monitor specific network status. + * + * @param netSpecifier specifier information. + * @param callback The callback needed to be registered. + * @param timeout The timeout period in milliseconds. + * @param callbackId out param, corresponding to a registered callback. + * @return 0 - Success. + * 201 - Permission denied. + * 401 - Parameter error. + * 2100002 - Failed to connect to the service. + * 2100003 - System internal error. + * 2101008 - The callback already exists. + * 2101022 - The number of requests exceeded the maximum allowed. + * @permission ohos.permission.GET_NETWORK_INFO + * @syscap SystemCapability.Communication.NetManager.Core + * @since 12 + * @version 1.0 + */ +int32_t OH_NetConn_RegisterNetConnCallback(NetConn_NetSpecifier *specifier, NetConn_NetConnCallback *netConnCallback, + uint32_t timeout, uint32_t *callbackId); + +/** + * @brief Registers a callback to listen default network's status changed. + * + * @param callback The callback needed to be registered. + * @param callbackId out param, corresponding to a registered callback. + * @return 0 - Success. + * 201 - Permission denied. + * 401 - Parameter error. + * 2100002 - Failed to connect to the service. + * 2100003 - System internal error. + * 2101008 - The callback already exists. + * 2101022 - The number of requests exceeded the maximum allowed. + * @permission ohos.permission.GET_NETWORK_INFO + * @syscap SystemCapability.Communication.NetManager.Core + * @since 12 + * @version 1.0 + */ +int32_t OH_NetConn_RegisterDefaultNetConnCallback(NetConn_NetConnCallback *netConnCallback, uint32_t *callbackId); + +/** + * @brief Unregister network status callback. + * + * @param callBackId the id corresponding to a registered callback. + * @return 0 - Success. + * 201 - Permission denied. + * 401 - Parameter error. + * 2100002 - Failed to connect to the service. + * 2100003 - System internal error. + * 2101007 - The callback does not exists. + * @permission ohos.permission.GET_NETWORK_INFO + * @syscap SystemCapability.Communication.NetManager.Core + * @since 12 + * @version 1.0 + */ +int32_t OH_NetConn_UnregisterNetConnCallback(uint32_t callBackId); + #ifdef __cplusplus } #endif diff --git a/network/netmanager/include/net_connection_type.h b/network/netmanager/include/net_connection_type.h index 36f68e874b74dbb730e9e78a7b6f946d7b62145d..436698c2906cd90c5e0a78f861c0302c32e9d566 100644 --- a/network/netmanager/include/net_connection_type.h +++ b/network/netmanager/include/net_connection_type.h @@ -248,6 +248,114 @@ typedef struct NetConn_NetHandleList { */ typedef int (*OH_NetConn_CustomDnsResolver)(const char *host, const char *serv, const struct addrinfo *hint, struct addrinfo **res); + +/** + * @brief Callback for application’s http proxy information changed. + * + * @param proxy The changed proxy information, may be a null pointer. + * + * @since 12 + * @version 1.0 + */ +typedef void (*OH_NetConn_AppHttpProxyChange)(NetConn_HttpProxy *proxy); + +/** + * @brief Definition of network specifier. + * + * @since 12 + * @version 1.0 + */ +typedef struct NetConn_NetSpecifier { + /** Network capabilities. */ + NetConn_NetCapabilities caps; + /** Network identifier */ + char *bearerPrivateIdentifier; +} NetConn_NetSpecifier; + +/** + * @brief Callback for network available. + * + * @param netHandle The network handle. + * + * @since 12 + * @version 1.0 + */ +typedef void (*OH_NetConn_NetworkAvailable)(NetConn_NetHandle *netHandle); + +/** + * @brief Callback for network capabilities changed. + * + * @param netHandle The network handle. + * @param netCapabilities The network capabilities. + * + * @since 12 + * @version 1.0 + */ +typedef void (*OH_NetConn_NetCapabilitiesChange)(NetConn_NetHandle *netHandle, + NetConn_NetCapabilities *netCapabilities); + +/** + * @brief Callback for network connection properties changed. + * + * @param netHandle The network handle. + * @param connConnetionProperties The network connection properties. + * + * @since 12 + * @version 1.0 + */ +typedef void (*OH_NetConn_NetConnectionPropertiesChange)(NetConn_NetHandle *netHandle, + NetConn_ConnectionProperties *connConnetionProperties); + +/** + * @brief Callback for network lost. + * + * @param netHandle The network handle. + * + * @since 12 + * @version 1.0 + */ +typedef void (*OH_NetConn_NetLost)(NetConn_NetHandle *netHandle); + +/** + * @brief Callback for network unavailable, this function invoked while network can not be available in given timeout. + * + * @since 12 + * @version 1.0 + */ +typedef void (*OH_NetConn_NetUnavailable)(void); + +/** + * @brief Callback for network blocked status changed. + * + * @param netHandle The network handle. + * @param blocked The flag used to indicate whether the network will be blocked. + * + * @since 12 + * @version 1.0 + */ +typedef void (*OH_NetConn_NetBlockStatusChange)(NetConn_NetHandle *netHandle, bool blocked); + +/** + * @brief Defines the network connection callbacks. + * + * @since 12 + * @version 1.0 + */ +typedef struct NetConn_NetConnCallback { + /** Callback for network available */ + OH_NetConn_NetworkAvailable onNetworkAvailable; + /** Callback for network capabilities changed */ + OH_NetConn_NetCapabilitiesChange onNetCapabilitiesChange; + /** Callback for network connection properties changed */ + OH_NetConn_NetConnectionPropertiesChange onConnetionProperties; + /** Callback for network lost */ + OH_NetConn_NetLost onNetLost; + /** Callback for network unavailable, this function invoked while network can not be available in given timeout */ + OH_NetConn_NetUnavailable onNetUnavailable; + /** Callback for network blocked status changed */ + OH_NetConn_NetBlockStatusChange onNetBlockStatusChange; +} NetConn_NetConnCallback; + #ifdef __cplusplus } #endif diff --git a/network/netmanager/libnet_connection.ndk.json b/network/netmanager/libnet_connection.ndk.json index 67993dd381e6caddb618dfaad2cde7b7ba825eab..792eff18ed13c4be4641d798da6a60e14a7d1e1f 100644 --- a/network/netmanager/libnet_connection.ndk.json +++ b/network/netmanager/libnet_connection.ndk.json @@ -46,5 +46,29 @@ { "first_introduced": "12", "name": "OH_NetConn_BindSocket" + }, + { + "first_introduced": "12", + "name": "OH_NetConn_SetAppHttpProxy" + }, + { + "first_introduced": "12", + "name": "OH_NetConn_RegisterAppHttpProxyCallback" + }, + { + "first_introduced": "12", + "name": "OH_NetConn_UnregisterAppHttpProxyCallback" + }, + { + "first_introduced": "12", + "name": "OH_NetConn_RegisterNetConnCallback" + }, + { + "first_introduced": "12", + "name": "OH_NetConn_RegisterDefaultNetConnCallback" + }, + { + "first_introduced": "12", + "name": "OH_NetConn_UnregisterNetConnCallback" } -] +] \ No newline at end of file