diff --git a/api/@ohos.net.connection.d.ts b/api/@ohos.net.connection.d.ts index 8fdc6979627bbbe8998c64d2c733e92516ed7151..f1a65d2d2b28f5ee42eb1d34365cd181b294c3d2 100644 --- a/api/@ohos.net.connection.d.ts +++ b/api/@ohos.net.connection.d.ts @@ -40,6 +40,8 @@ declare namespace connection { /** * Obtains the data network that is activated by default. * + *

To call this method, you must have the {@code ohos.permission.GET_NETWORK_INFO} permission. + * * @param callback Returns the {@link NetHandle} object; * returns {@code null} if the default network is not activated. * @permission ohos.permission.GET_NETWORK_INFO @@ -47,21 +49,11 @@ declare namespace connection { function getDefaultNet(callback: AsyncCallback): void; function getDefaultNet(): Promise; - /** - * Obtains the data network that is activated by default. - * - *

To call this method, you must have the {@code ohos.permission.GET_NETWORK_INFO} permission. - * - * @return Returns the {@link NetHandle} object; - * returns {@code null} if the default network is not activated. - * @permission ohos.permission.GET_NETWORK_INFO - * @since 9 - */ - function getDefaultNetSync(): NetHandle; - /** * Obtains the list of data networks that are activated. * + *

To invoke this method, you must have the {@code ohos.permission.GET_NETWORK_INFO} permission. + * * @param callback Returns the {@link NetHandle} object; returns {@code null} if no network is activated. * @permission ohos.permission.GET_NETWORK_INFO */ @@ -71,6 +63,8 @@ declare namespace connection { /** * Queries the connection properties of a network. * + *

This method requires the {@code ohos.permission.GET_NETWORK_INFO} permission. + * * @param netHandle Indicates the network to be queried. * @param callback Returns the {@link ConnectionProperties} object. * @permission ohos.permission.GET_NETWORK_INFO @@ -81,6 +75,8 @@ declare namespace connection { /** * Obtains {@link NetCapabilities} of a {@link NetHandle} object. * + *

To invoke this method, you must have the {@code ohos.permission.GET_NETWORK_INFO} permission. + * * @param netHandle Indicates the handle. See {@link NetHandle}. * @param callback Returns {@link NetCapabilities}; returns {@code null} if {@code handle} is invalid. * @permission ohos.permission.GET_NETWORK_INFO @@ -140,6 +136,42 @@ declare namespace connection { function getAddressesByName(host: string, callback: AsyncCallback>): void; function getAddressesByName(host: string): Promise>; + /** + * Get app routing information + * + * @param callback Returns the {@link NetHandle} object; + */ + function getAppNet(callback: AsyncCallback): void; + function getAppNet(): Promise; + + /** + * set app routing information + * + * @param netHandle Indicates the network whose state is to be reported. + * @permission ohos.permission.INTERNET + * + */ + function setAppNet(netHandle: NetHandle, callback: AsyncCallback): void; + function setAppNet(netHandle: NetHandle): Promise; + + /** + * Get default httpproxy infomation + * + * @param callback Returns the {@link HttpProxy} object; + */ + function getDefaultHttpProxy(callback: AsyncCallback): void; + function getDefaultHttpProxy(): Promise; + + /** + * Is the default net measurement + * + * @param callback return is net metered + * @permission ohos.permission.GET_NETWORK_INFO + */ + function isDefaultNetMetered(callback: AsyncCallback): void; + function isDefaultNetMetered(): Promise; + + export interface NetConnection { on(type: 'netAvailable', callback: Callback): void; @@ -174,12 +206,21 @@ declare namespace connection { export interface NetHandle { netId: number; + /** + * Binds a TCPSocket or UDPSocket to the current network. All data flows from + * the socket will use this network, without being subject to {@link setAppNet}. + * Before using this method, ensure that the socket is disconnected. + * + * @param socketParam Indicates the TCPSocket or UDPSocket object. + */ + bindSocket(socketParam: TCPSocket | UDPSocket, callback: AsyncCallback): void; + bindSocket(socketParam: TCPSocket | UDPSocket): Promise; + /** * Resolves a host name to obtain all IP addresses based on the specified NetHandle. * * @param host Indicates the host name or the domain. * @param callback Returns the NetAddress list. - * @permission ohos.permission.GET_NETWORK_INFO */ getAddressesByName(host: string, callback: AsyncCallback>): void; getAddressesByName(host: string): Promise>; @@ -189,7 +230,6 @@ declare namespace connection { * * @param host Indicates the host name or the domain. * @return Returns the first NetAddress. - * @permission ohos.permission.GET_NETWORK_INFO */ getAddressByName(host: string, callback: AsyncCallback): void; getAddressByName(host: string): Promise; @@ -240,10 +280,24 @@ declare namespace connection { */ BEARER_WIFI = 1, + /** + * Indicates that the network is based on a bluetooth network. + */ + BEARER_BLUETOOTH = 2, /** * Indicates that the network is an Ethernet network. */ BEARER_ETHERNET = 3, + + /** + * Indicates that the network is based on a VPN network. + */ + BEARER_VPN = 4, + + /** + * Indicates that the network is based on bjkbearer bluetooth network. + */ + BEARER_BJKBEARER_BLUETOOTH = 5, } export interface ConnectionProperties { @@ -268,11 +322,20 @@ declare namespace connection { prefixLength: number; } + /** + * @since 7 + */ export interface NetAddress { address: string; family?: number; // IPv4 = 1; IPv6 = 2, default is IPv4 port?: number; // [0, 65535] } + + export interface HttpProxy { + host: string; + port: number; + parsedExclusionList: Array; + } } -export default connection; \ No newline at end of file +export default connection; diff --git a/api/@ohos.net.ethernet.d.ts b/api/@ohos.net.ethernet.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..99ec8b6eafe8ac53658ba5f0346a5795f8161f00 --- /dev/null +++ b/api/@ohos.net.ethernet.d.ts @@ -0,0 +1,97 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import {AsyncCallback, Callback} from "./basic"; + +/** + * Provides interfaces to manage ethernet. + * + * @since 9 + * @syscap SystemCapability.Communication.NetManager.Extension + */ +declare namespace ethernet { + /** + * Get the specified network interface information. + * + * @param iface Indicates the network interface name. + * @permission ohos.permission.GET_NETWORK_INFO + * @systemapi Hide this for inner system use. + */ + function getIfaceConfig(iface: string, callback: AsyncCallback): void; + function getIfaceConfig(iface: string): Promise; + + /** + * Set the specified network interface parameters. + * + * @param iface Indicates the network interface name of the network parameter. + * @param ic Indicates the ic. See {@link InterfaceConfiguration}. + * @permission ohos.permission.CONNECTIVITY_INTERNAL + * @systemapi Hide this for inner system use. + */ + function setIfaceConfig(iface: string, ic: InterfaceConfiguration, callback: AsyncCallback): void; + function setIfaceConfig(iface: string, ic: InterfaceConfiguration): Promise; + + /** + * Check whether the specified network is active. + * + * @param iface Indicates the network interface name. + * @permission ohos.permission.GET_NETWORK_INFO + * @systemapi Hide this for inner system use. + */ + function isIfaceActive(iface?: string, callback: AsyncCallback): void; + function isIfaceActive(iface?: string): Promise; + + /** + * Check have network is active. + * + * @permission ohos.permission.GET_NETWORK_INFO + * @systemapi Hide this for inner system use. + */ + function haveActive(callback: AsyncCallback): void; + function haveActive(): Promise; + + /** + * Gets the names of all active network interfaces. + * + * @permission ohos.permission.GET_NETWORK_INFO + * @systemapi Hide this for inner system use. + */ + function getAllActiveIfaces(callback: AsyncCallback>): void; + function getAllActiveIfaces(): Promise>; + + /** + * @systemapi Hide this for inner system use. + */ + export interface InterfaceConfiguration { + /*See {@link IPSetMode}*/ + mode: IPSetMode; + ipAddr: string; + route: string; + gateway: string; + netMask: string; + dnsServers: string; + domain: string; + } + + /** + * @systemapi Hide this for inner system use. + */ + export enum IPSetMode { + STATIC = 0, + DHCP = 1 + } +} + +export default ethernet; \ No newline at end of file diff --git a/api/@ohos.net.http.d.ts b/api/@ohos.net.http.d.ts index b6ecab57c160bc35a91f068d04def36f56c23288..bf17f265642cf0dd03d32465e705c133bf7593ba 100644 --- a/api/@ohos.net.http.d.ts +++ b/api/@ohos.net.http.d.ts @@ -14,6 +14,7 @@ */ import {AsyncCallback, Callback} from "./basic"; +import socket, {X509Certificate} from './@ohos.net.socket' /** * Provides http related APIs. @@ -22,6 +23,9 @@ import {AsyncCallback, Callback} from "./basic"; * @syscap SystemCapability.Communication.NetStack */ declare namespace http { + type TLSSecureOptions = socket.TLSSecureOptions; + type X509Certificate = socket.X509Certificate; + /** * Creates an HTTP request task. */ @@ -37,6 +41,20 @@ declare namespace http { * extraData can be a string or an Object (API 6) or an ArrayBuffer(API 8). */ extraData?: string | Object | ArrayBuffer; + /** + * Data type to be returned. If this parameter is set, the system preferentially returns the specified type. + * + * @since 9 + */ + expectDataType?: HttpDataType; + /** + * @since 9 + */ + usingCache?: boolean; // default is true + /** + * @since 9 + */ + priority?: number; // [1, 1000], default is 1. /** * HTTP request header. */ @@ -49,6 +67,22 @@ declare namespace http { * Connection timeout interval. The default value is 60,000, in ms. */ connectTimeout?: number; // default is 60s. + /** + * @since 9 + */ + usingProtocol?: HttpProtocol; // default is automatically specified by the system. + /** + * For https. + * + * @since 9 + */ + secureOptions?: TLSSecureOptions; + /** + * For https. + * + * @since 9 + */ + checkServerIdentity?: (hostname: string, certs: Array) => Error | undefined; } export interface HttpRequest { @@ -154,11 +188,50 @@ declare namespace http { VERSION } + /** + * Supported protocols. + * + * @since 9 + */ + export enum HttpProtocol { + HTTP1_1, + HTTP2, + } + + /** + * Indicates the type of the returned data. + * + * @since 9 + */ + export enum HttpDataType { + /** + * The returned type is string. + */ + STRING, + /** + * The returned type is Object. + */ + OBJECT = 1, + /** + * The returned type is ArrayBuffer. + */ + ARRAY_BUFFER = 2, + } + export interface HttpResponse { /** * result can be a string (API 6) or an ArrayBuffer(API 8). Object is deprecated from API 8. + * If {@link HttpRequestOptions#expectDataType} is set, the system preferentially returns this parameter. */ result: string | Object | ArrayBuffer; + /** + * If the resultType is string, you can get result directly. + * If the resultType is Object, you can get result such as this: result['key']. + * If the resultType is ArrayBuffer, you can use ArrayBuffer to create the binary objects. + * + * @since 9 + */ + resultType: HttpDataType; /** * Server status code. */ @@ -172,6 +245,31 @@ declare namespace http { */ cookies: string; } + + /** + * Creates a default {@code HttpResponseCache} object to store the responses of HTTP access requests. + * + * @param cacheSize the size of cache, default is 10*1024*1024(10MB). + * @since 9 + */ + function createHttpResponseCache(cacheSize?: number): HttpResponseCache; + + /** + * @since 9 + */ + export interface HttpResponseCache { + /** + * Writes data in the cache to the file system so that all the cached data can be accessed in the next HTTP request. + */ + flush(callback: AsyncCallback): void; + flush(): Promise; + + /** + * Disables a cache and deletes the data in it. + */ + delete(callback: AsyncCallback): void; + delete(): Promise; + } } export default http; \ No newline at end of file diff --git a/api/@ohos.net.policy.d.ts b/api/@ohos.net.policy.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..ecd200f05a1855ae4abd2335b70b2c40f9513f06 --- /dev/null +++ b/api/@ohos.net.policy.d.ts @@ -0,0 +1,378 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import {AsyncCallback, Callback} from "./basic"; +import connection from "./@ohos.net.connection"; + +/** + * Provides interfaces to manage network policy rules. + * + * @since 9 + * @syscap SystemCapability.Communication.NetManager.Core + */ +declare namespace policy { + type NetBearType = connection.NetBearType; + + /** + * Control if apps can use data on background. + * + * @param isAllowed Allow apps to use data on background. + * @permission ohos.permission.CONNECTIVITY_INTERNAL + * @systemapi Hide this for inner system use. + */ + function setBackgroundPolicy(isAllowed: boolean, callback: AsyncCallback): void ; + function setBackgroundPolicy(isAllowed: boolean): Promise; + + /** + * Get the status if apps can use data on background. + * + * @param callback Returns that it's allowed or not to use data on background. + * For details, see {@link BackgroundPolicy#BACKGROUND_POLICY_DISABLE}. + * @permission ohos.permission.CONNECTIVITY_INTERNAL + * @systemapi Hide this for inner system use. + */ + function getBackgroundPolicy(callback: AsyncCallback): void; + function getBackgroundPolicy(): Promise; + + /** + * Set the policy for the specified UID. + * + * @param uid The specified UID of app. + * @param policy The policy for application. + * For details, see {@link NetUidPolicy}. + * @permission ohos.permission.CONNECTIVITY_INTERNAL + * @systemapi Hide this for inner system use. + */ + function setPolicyByUid(uid: number, policy: NetUidPolicy, callback: AsyncCallback): void; + function setPolicyByUid(uid: number, policy: NetUidPolicy): Promise; + + /** + * Query the policy of the specified UID. + * + * @param uid The specified UID of app. + * @param callback Returns the policy of the current UID of application. + * For details, see {@link NetUidPolicy}. + * @permission ohos.permission.CONNECTIVITY_INTERNAL + * @systemapi Hide this for inner system use. + */ + function getPolicyByUid(uid: number, callback: AsyncCallback): void; + function getPolicyByUid(uid: number): Promise; + + /** + * Query the application UIDs of the specified policy. + * + * @param policy the policy of the current UID of application. + * For details, see {@link NetUidPolicy}. + * @param callback Returns the UIDs of the specified policy. + * @permission ohos.permission.CONNECTIVITY_INTERNAL + * @systemapi Hide this for inner system use. + */ + function getUidsByPolicy(policy: NetUidPolicy, callback: AsyncCallback>): void; + function getUidsByPolicy(policy: NetUidPolicy): Promise>; + + /** + * Get network policies. + * + * @return See {@link NetQuotaPolicy}. + * @permission ohos.permission.CONNECTIVITY_INTERNAL + * @systemapi Hide this for inner system use. + */ + function getNetQuotaPolicies(callback: AsyncCallback>): void; + function getNetQuotaPolicies(): Promise>; + + /** + * Set network policies. + * + * @param quotaPolicies Indicates {@link NetQuotaPolicy}. + * @permission ohos.permission.CONNECTIVITY_INTERNAL + * @systemapi Hide this for inner system use. + */ + function setNetQuotaPolicies(quotaPolicies: Array, callback: AsyncCallback): void; + function setNetQuotaPolicies(quotaPolicies: Array): Promise; + + /** + * Reset the specified network management policy. + * + * @param iccid Indicates the specified sim that is valid when netType is cellular. + * @permission ohos.permission.CONNECTIVITY_INTERNAL + * @systemapi Hide this for inner system use. + */ + function restoreAllPolicies(iccid: string, callback: AsyncCallback): void; + function restoreAllPolicies(iccid: string): Promise; + + /** + * Get the status whether the specified uid app can access the metered network or non-metered network. + * + * @param uid The specified UID of application. + * @param isMetered Indicates meterd network or non-metered network. + * @param callback + * @permission ohos.permission.CONNECTIVITY_INTERNAL + * @systemapi Hide this for inner system use. + */ + function isUidNetAllowed(uid: number, isMetered: boolean, callback: AsyncCallback): void; + function isUidNetAllowed(uid: number, isMetered: boolean): Promise; + + /** + * Get the status whether the specified uid app can access the specified iface network. + * + * @param uid The specified UID of application. + * @param iface Iface name. + * @param callback + * @permission ohos.permission.CONNECTIVITY_INTERNAL + * @systemapi Hide this for inner system use. + */ + function isUidNetAllowed(uid: number, iface: string, callback: AsyncCallback): void; + function isUidNetAllowed(uid: number, iface: string): Promise; + + /** + * Set the UID into device idle allow list. + * + * @param uid The specified UID of application. + * @param isAllowed The UID is into allow list or not. + * @param callback + * @permission ohos.permission.CONNECTIVITY_INTERNAL + * @systemapi Hide this for inner system use. + */ + function setDeviceIdleAllowList(uid: number, isAllowed: boolean, callback: AsyncCallback): void; + function setDeviceIdleAllowList(uid: number, isAllowed: boolean): Promise; + + /** + * Get the allow list of in device idle mode. + * + * @param callback Returns the list of UIDs + * @permission ohos.permission.CONNECTIVITY_INTERNAL + * @systemapi Hide this for inner system use. + */ + function getDeviceIdleAllowList(callback: AsyncCallback>): void; + function getDeviceIdleAllowList(): Promise>; + + /** + * Get the background network restriction policy for the specified uid. + * + * @param uid The specified UID of application. + * @param callback {@link NetBackgroundPolicy}. + * @permission ohos.permission.CONNECTIVITY_INTERNAL + * @systemapi Hide this for inner system use. + */ + function getBackgroundPolicyByUid(uid: number, callback: AsyncCallback): void; + function getBackgroundPolicyByUid(uid: number): Promise; + + /** + * Reset network policies\rules\quota policies\firewall rules. + * + * @param iccid Specify the matched iccid of quota policy. + * @param callback + * @permission ohos.permission.CONNECTIVITY_INTERNAL + * @systemapi Hide this for inner system use. + */ + function resetPolicies(iccid: string, callback: AsyncCallback): void; + function resetPolicies(iccid: string): Promise; + + /** + * Update the limit or warning remind time of quota policy. + * + * @param iccid Specify the matched iccid of quota policy when netType is cellular. + * @param netType {@link NetBearType}. + * @permission ohos.permission.CONNECTIVITY_INTERNAL + * @systemapi Hide this for inner system use. + */ + function updateRemindPolicy(netType: NetBearType, iccid: string, remindType: RemindType, callback: AsyncCallback): void; + function updateRemindPolicy(netType: NetBearType, iccid: string, remindType: RemindType): Promise; + + /** + * Register uid policy change listener. + * + * @permission ohos.permission.CONNECTIVITY_INTERNAL + * @systemapi Hide this for inner system use. + */ + function on(type: "netUidPolicyChange", callback: Callback<{ uid: number, policy: NetUidPolicy }>): void; + + /** + * Unregister uid policy change listener. + * + * @permission ohos.permission.CONNECTIVITY_INTERNAL + * @systemapi Hide this for inner system use. + */ + function off(type: "netUidPolicyChange", callback?: Callback): void; + + /** + * Register uid rule change listener. + * + * @permission ohos.permission.CONNECTIVITY_INTERNAL + * @systemapi Hide this for inner system use. + */ + function on(type: "netUidRuleChange", callback: Callback<{ uid: number, rule: NetUidRule }>): void; + + /** + * Unregister uid rule change listener. + * + * @permission ohos.permission.CONNECTIVITY_INTERNAL + * @systemapi Hide this for inner system use. + */ + function off(type: "netUidRuleChange", callback?: Callback): void; + + /** + * Register metered ifaces change listener. + * + * @permission ohos.permission.CONNECTIVITY_INTERNAL + * @systemapi Hide this for inner system use. + */ + function on(type: "netMeteredIfacesChange", callback: Callback>): void; + + /** + * Unregister metered ifaces change listener. + * + * @permission ohos.permission.CONNECTIVITY_INTERNAL + * @systemapi Hide this for inner system use. + */ + function off(type: "netMeteredIfacesChange", callback?: Callback): void; + + /** + * Register quota policies change listener. + * + * @permission ohos.permission.CONNECTIVITY_INTERNAL + * @systemapi Hide this for inner system use. + */ + function on(type: "netQuotaPolicyChange", callback: Callback>): void; + + /** + * Unregister quota policies change listener. + * + * @permission ohos.permission.CONNECTIVITY_INTERNAL + * @systemapi Hide this for inner system use. + */ + function off(type: "netQuotaPolicyChange", callback?: Callback): void; + + /** + * Register network background policy change listener. + * + * @permission ohos.permission.CONNECTIVITY_INTERNAL + * @systemapi Hide this for inner system use. + */ + function on(type: "netBackgroundPolicyChange", callback: Callback): void; + + /** + * Unregister network background policy change listener. + * + * @permission ohos.permission.CONNECTIVITY_INTERNAL + * @systemapi Hide this for inner system use. + */ + function off(type: "netBackgroundPolicyChange", callback?: Callback): void; + + /** + * Indicate whether the application can use metered networks in background. + * + * @systemapi Hide this for inner system use. + */ + export enum NetBackgroundPolicy { + /* Default value. */ + NET_BACKGROUND_POLICY_NONE = 0, + /* Apps can use metered networks on background. */ + NET_BACKGROUND_POLICY_ENABLE = 1, + /* Apps can't use metered networks on background. */ + NET_BACKGROUND_POLICY_DISABLE = 2, + /* Only apps in allow list can use metered networks on background. */ + NET_BACKGROUND_POLICY_ALLOW_LIST = 3, + } + + /** + * Policy for net quota, includes usage period, limit and warning actions. + * + * @systemapi Hide this for inner system use. + */ + export interface NetQuotaPolicy { + /* netType see {@link NetBearType}. */ + netType: NetBearType; + /* The ID of the target card, valid when netType is BEARER_CELLULAR. */ + iccid: string; + /* To specify the identity of network, such as different WLAN. */ + ident: string; + /* The period and the start time for quota policy, defalt: "M1". */ + periodDuration: string; + /* The warning threshold of traffic, default: DATA_USAGE_UNKNOWN. */ + warningBytes: number; + /* The limit threshold of traffic, default: DATA_USAGE_UNKNOWN. */ + limitBytes: number; + /* The updated wall time that last warning remind, default: REMIND_NEVER. */ + lastWarningRemind: number; + /* The updated wall time that last limit remind, default: REMIND_NEVER. */ + lastLimitRemind: number; + /* Is meterd network or not. */ + metered: boolean; + /* The action while the used bytes reach the limit, see {@link LimitAction}. */ + limitAction: LimitAction; + } + + /** + * The action when quota policy hit the limit. + * + * @systemapi Hide this for inner system use. + */ + export enum LimitAction{ + /* Default action, do nothing. */ + LIMIT_ACTION_NONE = -1, + /* Access is disabled, when quota policy hit the limit. */ + LIMIT_ACTION_DISABLE = 0, + /* The user is billed automatically, when quota policy hit the limit. */ + LIMIT_ACTION_AUTO_BILL = 1, + } + + /** + * Rules whether an uid can access to a metered or non-metered network. + * + * @systemapi Hide this for inner system use. + */ + export enum NetUidRule { + /* Default uid rule. */ + NET_RULE_NONE = 0, + /* Allow traffic on metered networks while app is foreground. */ + NET_RULE_ALLOW_METERED_FOREGROUND = 1 << 0, + /* Allow traffic on metered network. */ + NET_RULE_ALLOW_METERED = 1 << 1, + /* Reject traffic on metered network. */ + NET_RULE_REJECT_METERED = 1 << 2, + /* Allow traffic on all network (metered or non-metered). */ + NET_RULE_ALLOW_ALL = 1 << 5, + /* Reject traffic on all network. */ + NET_RULE_REJECT_ALL = 1 << 6, + } + + /** Specify the remind type, see {@link updateRemindPolicy}. + * + * @systemapi Hide this for inner system use. + */ + export enum RemindType { + /* Warning remind. */ + REMIND_TYPE_WARNING = 1, + /* Limit remind. */ + REMIND_TYPE_LIMIT = 2, + } + + /** + * Network policy for uid. + * + * @systemapi Hide this for inner system use. + */ + export enum NetUidPolicy { + /* Default net policy. */ + NET_POLICY_NONE = 0, + /* Allow on metered networks when app in background. */ + NET_POLICY_ALLOW_METERED_BACKGROUND = 1 << 0, + /* Reject on metered networks when app in background. */ + NET_POLICY_REJECT_METERED_BACKGROUND = 1 << 1, + } +} + +export default policy; \ No newline at end of file diff --git a/api/@ohos.net.sharing.d.ts b/api/@ohos.net.sharing.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..057d8124bbd44f3dadbb6e622ff156e971189fdb --- /dev/null +++ b/api/@ohos.net.sharing.d.ts @@ -0,0 +1,221 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { AsyncCallback, Callback } from "./basic"; +import { NetHandle } from "./@ohos.net.connection"; + +/** + * Provides network sharing related interfaces. + * + * @since 9 + * @syscap SystemCapability.Communication.NetManager.Extension + */ +declare namespace sharing { + /** + * Checks whether this device allows for network sharing. + * + * @param callback Returns {@code true} indicating network sharing is supported; returns {@code false} otherwise. + * @systemapi Hide this for inner system use. Only used for system app. + * @permission ohos.permission.CONNECTIVITY_INTERNAL + */ + function isSharingSupported(callback: AsyncCallback): void; + function isSharingSupported(): Promise; + + /** + * Return the global network sharing state. + * + * @param callback Returns {@code true} indicating network sharing is running; returns {@code false} otherwise. + * @systemapi Hide this for inner system use. + * @permission ohos.permission.CONNECTIVITY_INTERNAL + */ + function isSharing(callback: AsyncCallback): void; + function isSharing(): Promise; + + /** + * Start network sharing for given type. + * + * @param type Enumeration of shareable interface types. + * @param callback Returns the result. + * @systemapi Hide this for inner system use. Only used for system app. + * @permission ohos.permission.CONNECTIVITY_INTERNAL + */ + function startSharing(type: SharingIfaceType, callback: AsyncCallback): void; + function startSharing(type: SharingIfaceType): Promise; + + /** + * Stop network sharing for given type. + * + * @param type Enumeration of shareable interface types. + * @param callback Returns the result. + * @systemapi Hide this for inner system use. Only used for system app. + * @permission ohos.permission.CONNECTIVITY_INTERNAL + */ + function stopSharing(type: SharingIfaceType, callback: AsyncCallback): void; + function stopSharing(type: SharingIfaceType): Promise; + + /** + * Obtains the number of downlink data bytes of the sharing network interfaces. + * + * @param callback Returns the number of downlink data bytes of the sharing network interfaces. + * @systemapi Hide this for inner system use. + * @permission ohos.permission.CONNECTIVITY_INTERNAL + */ + function getStatsRxBytes(callback: AsyncCallback): void; + function getStatsRxBytes(): Promise; + + /** + * Obtains the number of uplink data bytes of the sharing network interfaces. + * + * @param callback Returns the number of uplink data bytes of the sharing network interfaces. + * @systemapi Hide this for inner system use. + * @permission ohos.permission.CONNECTIVITY_INTERNAL + */ + function getStatsTxBytes(callback: AsyncCallback): void; + function getStatsTxBytes(): Promise; + + /** + * Obtains the number of total data bytes of the sharing network interfaces. + * + * @param callback Returns the number of total data bytes of the sharing network interfaces. + * @systemapi Hide this for inner system use. + * @permission ohos.permission.CONNECTIVITY_INTERNAL + */ + function getStatsTotalBytes(callback: AsyncCallback): void; + function getStatsTotalBytes(): Promise; + + /** + * Obtains the names of interfaces in each sharing state. + * + * @param state Is the network sharing state, include serving, can server and servering error states. + * @param callback Returns an array of interface names that meet this status. + * @systemapi Hide this for inner system use. + * @permission ohos.permission.CONNECTIVITY_INTERNAL + */ + function getSharingIfaces(state: SharingIfaceState, callback: AsyncCallback>): void; + function getSharingIfaces(state: SharingIfaceState): Promise>; + + /** + * Obtains the network sharing state for given type. + * + * @param type Is the enumeration of shareable interface types. + * @param callback Returns {@code SharingIfaceState}. + * @systemapi Hide this for inner system use. + * @permission ohos.permission.CONNECTIVITY_INTERNAL + */ + function getSharingState(type: SharingIfaceType, callback: AsyncCallback): void; + function getSharingState(type: SharingIfaceType): Promise; + + /** + * Get a list regular expression that defines any interface that can support network sharing. + * + * @param type Is the enumeration of shareable interface types. + * @param callback Returns an array of regular expression strings that define which interfaces + * netSpecifier are considered to support network sharing. + * @systemapi Hide this for inner system use. + * @permission ohos.permission.CONNECTIVITY_INTERNAL + */ + function getSharableRegexes(type: SharingIfaceType, callback: AsyncCallback>): void; + function getSharableRegexes(type: SharingIfaceType): Promise>; + + /** + * Register a callback for the global network sharing state change. + * + * @systemapi Hide this for inner system use. + * @permission ohos.permission.CONNECTIVITY_INTERNAL + */ + function on(type: 'sharingStateChange', callback: Callback): void; + + /** + * Unregister a callback for the global network sharing state change. + * + * @systemapi Hide this for inner system use. + * @permission ohos.permission.CONNECTIVITY_INTERNAL + */ + function off(type: 'sharingStateChange', callback?: Callback): void; + + /** + * Register a callback for the interface network sharing state change. + * + * @systemapi Hide this for inner system use. + * @permission ohos.permission.CONNECTIVITY_INTERNAL + */ + function on(type: 'interfaceSharingStateChange', callback: Callback<{ type: SharingIfaceType, iface: string, state: SharingIfaceState }>): void; + + /** + * Unregister a callback for the interface network sharing state change. + * + * @systemapi Hide this for inner system use. + * @permission ohos.permission.CONNECTIVITY_INTERNAL + */ + function off(type: 'interfaceSharingStateChange', callback?: Callback<{ type: SharingIfaceType, iface: string, state: SharingIfaceState }>): void; + + /** + * Register a callback for the sharing upstream network change. + * + * @systemapi Hide this for inner system use. + * @permission ohos.permission.CONNECTIVITY_INTERNAL + */ + function on(type: 'sharingUpstreamChange', callback: Callback): void; + + /** + * Unregister a callback for the sharing upstream network change. + * + * @systemapi Hide this for inner system use. + * @permission ohos.permission.CONNECTIVITY_INTERNAL + */ + function off(type: 'sharingUpstreamChange', callback?: Callback): void; + + /** + * @systemapi Hide this for inner system use. + */ + export enum SharingIfaceState { + /** + * Indicates the names of the NICs that are serving as network sharing. + */ + SHARING_NIC_SERVING = 1, + + /** + * Indicates the names of the NICs that can serve as network sharing. + */ + SHARING_NIC_CAN_SERVER = 2, + + /** + * Indicates the names of the NICs that serving error. + */ + SHARING_NIC_ERROR = 3 + } + + /** + * @systemapi Hide this for inner system use. + */ + export enum SharingIfaceType { + /** + * Network sharing type for Wi-Fi. + */ + SHARING_WIFI = 0, + + /** + * Network sharing type for USB. + */ + SHARING_USB = 1, + + /** + * Network sharing type for BLUETOOTH. + */ + SHARING_BLUETOOTH = 2 + } +} + +export default sharing; diff --git a/api/@ohos.net.socket.d.ts b/api/@ohos.net.socket.d.ts index fb88669e14f1127a0b3b1a7d1f2b7df8e3341610..f14dfcde4d91a7901fc45e1155c136c182869a59 100644 --- a/api/@ohos.net.socket.d.ts +++ b/api/@ohos.net.socket.d.ts @@ -35,6 +35,20 @@ declare namespace socket { */ function constructTCPSocketInstance(): TCPSocket; + /** + * Creates a TLSSocket object. + * + * @since 9 + */ + function constructTLSSocketInstance(): TLSSocket; + + /** + * Creates a Local Socket object. + * + * @since 10 + */ + function constructLocalSocketInstance(name: string, isServer?: boolean): LocalSocket; + export interface UDPSendOptions { /** * Data to send. @@ -219,7 +233,7 @@ declare namespace socket { /** * Socket linger. */ - socketLinger: {on: boolean, linger: number}; + socketLinger?: {on: boolean, linger: number}; } export interface TCPSocket { @@ -314,6 +328,138 @@ declare namespace socket { */ off(type: 'error', callback?: ErrorCallback): void; } + + /** + * @since 9 + */ + export interface TLSSocket extends TCPSocket { + // 返回表示本地证书的对象。 + getCertificate(callback: AsyncCallback): void; + getCertificate(): Promise; + + // 返回代表对等方证书的对象。 如果对端没有提供证书,则将返回空对象。 如果套接字被销毁,则返回 null。 + // needChain 如果为 true,则包含完整的证书链,否则仅包含对等方的证书。 + getRemoteCertificate(needChain: boolean, callback: AsyncCallback>): void; + getRemoteCertificate(needChain: boolean): Promise>; + + // 返回包含当前连接的协商 SSL/TLS 协议版本的字符串。 对于尚未完成握手过程的已连接套接字,将返回值 'unknown'。 服务器套接字或断开的客户端套接字将返回值 null。 + getProtocol(callback: AsyncCallback): void; + getProtocol(): Promise; + + // 返回包含协商密码套件信息的对象。如:{ "name": "AES128-SHA256", "standardName": "TLS_RSA_WITH_AES_128_CBC_SHA256", "version": "TLSv1.2"} + getCipherSuite(callback: AsyncCallback): void; + getCipherSuite(): Promise; + + // 服务器和客户端之间共享的签名算法列表,按优先级降序排列。@see https://www.openssl.org/docs/man1.1.1/man3/SSL_get_shared_sigalgs.html + getSignatureAlgorithms(callback: AsyncCallback>): void; + getSignatureAlgorithms(): Promise>; + + // 连接 + /** + * @permission ohos.permission.INTERNET + */ + connect(options: TLSConnectOptions, callback: AsyncCallback): void; + connect(options: TLSConnectOptions): Promise; + } + + /** + * @since 9 + */ + export interface TLSSecureOptions { + ca?: string | Array; + cert?: string | Array; + key?: string | Array; + passwd?: string; + protocols?: Protocol | Array; + useRemoteCipherPrefer?: boolean; // default is false, use local cipher. + signatureAlgorithms?: string; // 支持的签名算法。该列表可以包含摘要算法(SHA256、MD5 等)、公钥算法(RSA-PSS、ECDSA 等)、 + // 两者的组合(例如 'RSA+SHA384')或 TLS v1.3 方案名称(例如 rsa_pss_pss_sha512) + cipherSuite?: string; // 密码套件规范 + crl?: string | Array; // 证书吊销列表 + } + + /** + * @since 9 + */ + export interface TLSConnectOptions { + address: NetAddress; + secureOptions?: TLSSecureOptions; + checkServerIdentity?: (hostname: string, certs: Array) => Error | undefined; + ALPNProtocols?: Array; // 应用层协议协商扩展,支持HTTP,HTTP/2 + } + + /** + * @since 9 + */ + export enum Protocol { + TLSv12 = "TLSv1.2", + TLSv13 = "TLSv1.3", + } + + // X509Certificate由安全子系统提供,此处仅为示意 + export interface X509Certificate { + } + + /** + * @since 10 + */ + export interface LocalSocket { + /** + * Accepts a connection request from the client. + */ + accept(callback: AsyncCallback): void; + accept(): Promise; + + /** + * Connects the client socket to a specified address for setting up a connection with the server. + */ + connect(callback: AsyncCallback): void; + connect(): Promise; + + /** + * Closes the socket after the server and client finish communicating with each other. + */ + close(callback: AsyncCallback): void; + close(): Promise; + + /** + * Sends data over a LocalSocket connection. + * + * @param data Data to send. + */ + send(data: string | ArrayBuffer, callback: AsyncCallback): void; + send(data: string | ArrayBuffer): Promise; + + /** + * Listens for message receiving events of the LocalSocket connection. + */ + on(type: 'message', callback: Callback<{message: ArrayBuffer, remoteInfo: SocketRemoteInfo}>): void; + + /** + * Cancels listening for message receiving events of the LocalSocket connection. + */ + off(type: 'message', callback?: Callback<{message: ArrayBuffer, remoteInfo: SocketRemoteInfo}>): void; + + /** + * Listens for connection or close events of the LocalSocket connection. + */ + on(type: 'connect' | 'close', callback: Callback): void; + + /** + * Cancels listening for connection or close events of the LocalSocket connection. + */ + off(type: 'connect' | 'close', callback?: Callback): void; + + /** + * Listens for error events of the LocalSocket connection. + */ + on(type: 'error', callback: ErrorCallback): void; + + /** + * Cancels listening for error events of the LocalSocket connection. + */ + off(type: 'error', callback?: ErrorCallback): void; + } } export default socket; \ No newline at end of file diff --git a/api/@ohos.net.statistics.d.ts b/api/@ohos.net.statistics.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..584ef71bed40562a6497ea4f3a1a1a63f121f0bc --- /dev/null +++ b/api/@ohos.net.statistics.d.ts @@ -0,0 +1,157 @@ +/* + * Copyright (C) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import {AsyncCallback} from "./basic"; + +/** + * Obtains traffic statistics. + * + * @since 9 + * @syscap SystemCapability.Communication.NetManager.Core + */ +declare namespace statistics { + /** + * Queries the data traffic (including all TCP and UDP data packets) received through a specified NIC. + * + * @param nic Indicates the NIC name. + * @param callback Returns the data traffic received through the specified NIC. + */ + function getIfaceRxBytes(nic: string, callback: AsyncCallback): void; + function getIfaceRxBytes(nic: string): Promise; + + /** + * Queries the data traffic (including all TCP and UDP data packets) sent through a specified NIC. + * + * @param nic Indicates the NIC name. + * @param callback Returns the data traffic sent through the specified NIC. + */ + function getIfaceTxBytes(nic: string, callback: AsyncCallback): void; + function getIfaceTxBytes(nic: string): Promise; + + /** + * Queries the data traffic (including all TCP and UDP data packets) received through the cellular network. + * + * @param callback Returns the data traffic received through the cellular network. + */ + function getCellularRxBytes(callback: AsyncCallback): void; + function getCellularRxBytes(): Promise; + + /** + * Queries the data traffic (including all TCP and UDP data packets) sent through the cellular network. + * + * @param callback Returns the data traffic sent through the cellular network. + */ + function getCellularTxBytes(callback: AsyncCallback): void; + function getCellularTxBytes(): Promise; + + /** + * Queries the data traffic (including all TCP and UDP data packets) sent through all NICs. + * + * @param callback Returns the data traffic sent through all NICs. + */ + function getAllTxBytes(callback: AsyncCallback): void; + function getAllTxBytes(): Promise; + + /** + * Queries the data traffic (including all TCP and UDP data packets) received through all NICs. + * + * @param callback Returns the data traffic received through all NICs. + */ + function getAllRxBytes(callback: AsyncCallback): void; + function getAllRxBytes(): Promise; + + /** + * Queries the data traffic (including all TCP and UDP data packets) received by a specified application. + * This method applies only to system applications and your own applications. + * + * @param uid Indicates the process ID of the application. + * @param callback Returns the data traffic received by the specified application. + */ + function getUidRxBytes(uid: number, callback: AsyncCallback): void; + function getUidRxBytes(uid: number): Promise; + + /** + * Queries the data traffic (including all TCP and UDP data packets) sent by a specified application. + * This method applies only to system applications and your own applications. + * + * @param uid Indicates the process ID of the application. + * @param callback Returns the data traffic sent by the specified application. + */ + function getUidTxBytes(uid: number, callback: AsyncCallback): void; + function getUidTxBytes(uid: number): Promise; + + /** + * Register notifications of network traffic updates, restrictions, and warnings. + * + * @permission ohos.permission.GET_NETSTATS_SUMMARY + * @systemapi Hide this for inner system use. + */ + function on(type: 'netStatsChange', callback: Callback<{ iface: string, uid?: number }>): void; + + /** + * @systemapi Hide this for inner system use. + */ + function off(type: 'netStatsChange', callback?: Callback<{ iface: string, uid?: number }>): void; + + /** + * Get the traffic usage details of the network interface in the specified time period. + * + * @param IfaceInfo Indicates the handle. See {@link IfaceInfo}. + * @permission ohos.permission.GET_NETSTATS_SUMMARY + * @systemapi Hide this for inner system use. + */ + function getIfaceStats(ifaceInfo: IfaceInfo, callback: AsyncCallback): void; + function getIfaceStats(ifaceInfo: IfaceInfo): Promise; + + /** + * Get the traffic usage details of the specified time period of the application. + * + * @param UidStatsInfo Indicates the handle. See {@link UidStatsInfo}. + * @permission ohos.permission.GET_NETSTATS_SUMMARY + * @systemapi Hide this for inner system use. + */ + function getIfaceUidStats(uidStatsInfo: UidStatsInfo, callback: AsyncCallback): void; + function getIfaceUidStats(uidStatsInfo: UidStatsInfo): Promise; + + /** + * @systemapi Hide this for inner system use. + */ + export interface IfaceInfo { + iface: string; + startTime: number; + endTime: number; + } + + /** + * @systemapi Hide this for inner system use. + */ + export interface UidStatsInfo { + /*See {@link IfaceInfo}*/ + ifaceInfo: IfaceInfo; + uid: number; + } + + /** + * @systemapi Hide this for inner system use. + */ + export interface NetStatsInfo { + rxBytes: number; + txBytes: number; + rxPackets: number; + txPackets: number; + } +} + +export default statistics; \ No newline at end of file