• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16import {AsyncCallback, Callback} from "./basic";
17import {NetHandle} from "./@ohos.net.connection";
18
19/**
20 * Provides network sharing related interfaces.
21 *
22 * @since 9
23 * @syscap SystemCapability.Communication.NetManager.NetSharing
24 */
25declare namespace sharing {
26  /**
27   * Checks whether this device allows for network sharing.
28   *
29   * @param callback Returns {@code true} indicating network sharing is supported; returns {@code false} otherwise.
30   * @permission ohos.permission.CONNECTIVITY_INTERNAL
31   * @systemapi Hide this for inner system use.
32   */
33  function isSharingSupported(callback: AsyncCallback<boolean>): void;
34  function isSharingSupported(): Promise<boolean>;
35
36  /**
37   * Return the global network sharing state.
38   *
39   * @param callback Returns {@code true} indicating network sharing is running; returns {@code false} otherwise.
40   * @permission ohos.permission.CONNECTIVITY_INTERNAL
41   * @systemapi Hide this for inner system use.
42   */
43  function isSharing(callback: AsyncCallback<boolean>): void;
44  function isSharing(): Promise<boolean>;
45
46  /**
47   * Start network sharing for given type.
48   *
49   * @param type Enumeration of shareable interface types.
50   * @param callback Returns the result.
51   * @permission ohos.permission.CONNECTIVITY_INTERNAL
52   * @systemapi Hide this for inner system use.
53   */
54  function startSharing(type: SharingIfaceType, callback: AsyncCallback<void>): void;
55  function startSharing(type: SharingIfaceType): Promise<void>;
56
57  /**
58   * Stop network sharing for given type.
59   *
60   * @param type Enumeration of shareable interface types.
61   * @param callback Returns the result.
62   * @permission ohos.permission.CONNECTIVITY_INTERNAL
63   * @systemapi Hide this for inner system use.
64   */
65  function stopSharing(type: SharingIfaceType, callback: AsyncCallback<void>): void;
66  function stopSharing(type: SharingIfaceType): Promise<void>;
67
68  /**
69   * Obtains the number of downlink data bytes of the sharing network interfaces.
70   *
71   * @param callback Returns the number of downlink data bytes of the sharing network interfaces.
72   * @permission ohos.permission.CONNECTIVITY_INTERNAL
73   * @systemapi Hide this for inner system use.
74   */
75  function getStatsRxBytes(callback: AsyncCallback<number>): void;
76  function getStatsRxBytes(): Promise<number>;
77
78  /**
79   * Obtains the number of uplink data bytes of the sharing network interfaces.
80   *
81   * @param callback Returns the number of uplink data bytes of the sharing network interfaces.
82   * @permission ohos.permission.CONNECTIVITY_INTERNAL
83   * @systemapi Hide this for inner system use.
84   */
85  function getStatsTxBytes(callback: AsyncCallback<number>): void;
86  function getStatsTxBytes(): Promise<number>;
87
88  /**
89   * Obtains the number of total data bytes of the sharing network interfaces.
90   *
91   * @param callback Returns the number of total data bytes of the sharing network interfaces.
92   * @permission ohos.permission.CONNECTIVITY_INTERNAL
93   * @systemapi Hide this for inner system use.
94   */
95  function getStatsTotalBytes(callback: AsyncCallback<number>): void;
96  function getStatsTotalBytes(): Promise<number>;
97
98  /**
99   * Obtains the names of interfaces in each sharing state.
100   *
101   * @param state Is the network sharing state.
102   * @param callback Returns an array of interface names that meet this status.
103   * @permission ohos.permission.CONNECTIVITY_INTERNAL
104   * @systemapi Hide this for inner system use.
105   */
106  function getSharingIfaces(state: SharingIfaceState, callback: AsyncCallback<Array<string>>): void;
107  function getSharingIfaces(state: SharingIfaceState): Promise<Array<string>>;
108
109  /**
110   * Obtains the network sharing state for given type.
111   *
112   * @param type Is the enumeration of shareable interface types.
113   * @param callback Returns {@code SharingIfaceState}.
114   * @permission ohos.permission.CONNECTIVITY_INTERNAL
115   * @systemapi Hide this for inner system use.
116   */
117  function getSharingState(type: SharingIfaceType, callback: AsyncCallback<SharingIfaceState>): void;
118  function getSharingState(type: SharingIfaceType): Promise<SharingIfaceState>;
119
120  /**
121   * Get a list regular expression that defines any interface that can support network sharing.
122   *
123   * @param type Is the enumeration of shareable interface types.
124   * @param callback Returns an array of regular expression strings that define which interfaces
125   *        are considered to support network sharing.
126   * @permission ohos.permission.CONNECTIVITY_INTERNAL
127   * @systemapi Hide this for inner system use.
128   */
129  function getSharableRegexes(type: SharingIfaceType, callback: AsyncCallback<Array<string>>): void;
130  function getSharableRegexes(type: SharingIfaceType): Promise<Array<string>>;
131
132  /**
133   * Register a callback for the global network sharing state change.
134   *
135   * @permission ohos.permission.CONNECTIVITY_INTERNAL
136   * @systemapi Hide this for inner system use.
137   */
138  function on(type: 'sharingStateChange', callback: Callback<boolean>): void;
139
140  /**
141   * Unregister a callback for the global network sharing state change.
142   *
143   * @permission ohos.permission.CONNECTIVITY_INTERNAL
144   * @systemapi Hide this for inner system use.
145   */
146  function off(type: 'sharingStateChange', callback?: Callback<boolean>): void;
147
148  /**
149   * Register a callback for the interface network sharing state change.
150   *
151   * @permission ohos.permission.CONNECTIVITY_INTERNAL
152   * @systemapi Hide this for inner system use.
153   */
154  function on(type: 'interfaceSharingStateChange', callback: Callback<{ type: SharingIfaceType, iface: string, state: SharingIfaceState }>): void;
155
156  /**
157   * Unregister a callback for the interface network sharing state change.
158   *
159   * @permission ohos.permission.CONNECTIVITY_INTERNAL
160   * @systemapi Hide this for inner system use.
161   */
162  function off(type: 'interfaceSharingStateChange', callback?: Callback<{ type: SharingIfaceType, iface: string, state: SharingIfaceState }>): void;
163
164  /**
165   * Register a callback for the sharing upstream network change.
166   *
167   * @permission ohos.permission.CONNECTIVITY_INTERNAL
168   * @systemapi Hide this for inner system use.
169   */
170  function on(type: 'sharingUpstreamChange', callback: Callback<NetHandle>): void;
171
172  /**
173   * Unregister a callback for the sharing upstream network change.
174   *
175   * @permission ohos.permission.CONNECTIVITY_INTERNAL
176   * @systemapi Hide this for inner system use.
177   */
178  function off(type: 'sharingUpstreamChange', callback?: Callback<NetHandle>): void;
179
180  /**
181   * @systemapi Hide this for inner system use.
182   */
183  export enum SharingIfaceState {
184    /**
185     * Indicates the names of the NICs that are serving as network sharing.
186     */
187    SHARING_NIC_SERVING = 1,
188
189    /**
190     * Indicates the names of the NICs that can serve as network sharing.
191     */
192    SHARING_NIC_CAN_SERVER = 2,
193
194    /**
195     * Indicates the names of the NICs that serving error.
196     */
197    SHARING_NIC_ERROR = 3
198  }
199
200  /**
201   * @systemapi Hide this for inner system use.
202   */
203  export enum SharingIfaceType {
204    /**
205     * Network sharing type for Wi-Fi.
206     */
207    SHARING_WIFI = 0,
208
209    /**
210     * Network sharing type for USB.
211     */
212    SHARING_USB = 1,
213
214    /**
215     * Network sharing type for BLUETOOTH.
216     */
217    SHARING_BLUETOOTH = 2
218  }
219}
220
221export default sharing;