• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2021-2023 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 type { AsyncCallback } from './@ohos.base';
17
18/**
19 * Provides methods related to cellular data services.
20 *
21 * @namespace data
22 * @syscap SystemCapability.Telephony.CellularData
23 * @since 7
24 */
25declare namespace data {
26  /**
27   * Get the default cellular data card.
28   *
29   * @param { AsyncCallback<number> } callback - Indicates the default cellular data slot id.
30   * @syscap SystemCapability.Telephony.CellularData
31   * @since 7
32   */
33  function getDefaultCellularDataSlotId(callback: AsyncCallback<number>): void;
34
35  /**
36   * Get the default cellular data card.
37   *
38   * @returns { Promise<number> } Returns the default cellular data slot id.
39   * @syscap SystemCapability.Telephony.CellularData
40   * @since 7
41   */
42  function getDefaultCellularDataSlotId(): Promise<number>;
43
44  /**
45   * Get the default cellular data card.
46   *
47   * @returns { number } Returns default cellular data slot id.
48   * @syscap SystemCapability.Telephony.CellularData
49   * @since 9
50   */
51  function getDefaultCellularDataSlotIdSync(): number;
52
53  /**
54   * Switch cellular data services to another card, without changing the default settings.
55   *
56   * @permission ohos.permission.SET_TELEPHONY_STATE
57   * @param { number } slotId - Indicates the ID of the target card slot.
58   * The value {@code 0} indicates card 1, and the value {@code 1} indicates card 2.
59   * @param { AsyncCallback<void> } callback - The callback of setDefaultCellularDataSlotId.
60   * @throws { BusinessError } 201 - Permission denied.
61   * @throws { BusinessError } 202 - Non-system applications use system APIs.
62   * @throws { BusinessError } 401 - Parameter error.
63   * @throws { BusinessError } 8300001 - Invalid parameter value.
64   * @throws { BusinessError } 8300002 - Operation failed. Cannot connect to service.
65   * @throws { BusinessError } 8300003 - System internal error.
66   * @throws { BusinessError } 8300004 - Do not have sim card.
67   * @throws { BusinessError } 8300999 - Unknown error code.
68   * @throws { BusinessError } 8301001 - SIM card is not activated.
69   * @syscap SystemCapability.Telephony.CellularData
70   * @systemapi Hide this for inner system use.
71   * @since 7
72   */
73  function setDefaultCellularDataSlotId(slotId: number, callback: AsyncCallback<void>): void;
74
75  /**
76   * Switch cellular data services to another card, without changing the default settings.
77   *
78   * @permission ohos.permission.SET_TELEPHONY_STATE
79   * @param { number } slotId - Indicates the ID of the target card slot.
80   * The value {@code 0} indicates card 1, and the value {@code 1} indicates card 2.
81   * @returns { Promise<void> } The promise returned by the setDefaultCellularDataSlotId.
82   * @throws { BusinessError } 201 - Permission denied.
83   * @throws { BusinessError } 202 - Non-system applications use system APIs.
84   * @throws { BusinessError } 401 - Parameter error.
85   * @throws { BusinessError } 8300001 - Invalid parameter value.
86   * @throws { BusinessError } 8300002 - Operation failed. Cannot connect to service.
87   * @throws { BusinessError } 8300003 - System internal error.
88   * @throws { BusinessError } 8300004 - Do not have sim card.
89   * @throws { BusinessError } 8300999 - Unknown error code.
90   * @throws { BusinessError } 8301001 - SIM card is not activated.
91   * @syscap SystemCapability.Telephony.CellularData
92   * @systemapi Hide this for inner system use.
93   * @since 7
94   */
95  function setDefaultCellularDataSlotId(slotId: number): Promise<void>;
96
97  /**
98   * Indicates that there is no uplink or downlink data.
99   *
100   * <p>It is a return value of service state query of cellular data services.
101   * @param { AsyncCallback<DataFlowType> } callback - Indicates the data flow type.
102   * @syscap SystemCapability.Telephony.CellularData
103   * @since 7
104   */
105  function getCellularDataFlowType(callback: AsyncCallback<DataFlowType>): void;
106
107  /**
108   * Indicates that there is no uplink or downlink data.
109   *
110   * <p>It is a return value of service state query of cellular data services.
111   * @returns { Promise<DataFlowType> } Returns the data flow type.
112   * @syscap SystemCapability.Telephony.CellularData
113   * @since 7
114   */
115  function getCellularDataFlowType(): Promise<DataFlowType>;
116
117  /**
118   * Obtain the connection state of the PS domain.
119   *
120   * @param { AsyncCallback<DataConnectState> } callback - Indicates the callback for getting the connection state,
121   * which can be any of the following:
122   * <ul>
123   * <li>{@code DataConnectState#DATA_STATE_UNKNOWN}
124   * <li>{@code DataConnectState#DATA_STATE_DISCONNECTED}
125   * <li>{@code DataConnectState#DATA_STATE_CONNECTING}
126   * <li>{@code DataConnectState#DATA_STATE_CONNECTED}
127   * <li>{@code DataConnectState#DATA_STATE_SUSPENDED}
128   * </ul>
129   * @syscap SystemCapability.Telephony.CellularData
130   * @since 7
131   */
132  function getCellularDataState(callback: AsyncCallback<DataConnectState>): void;
133
134  /**
135   * Obtain the connection state of the PS domain.
136   *
137   * @returns { Promise<DataConnectState> } Returns the connection state, which can be any of the following:
138   * <ul>
139   * <li>{@code DataConnectState#DATA_STATE_UNKNOWN}
140   * <li>{@code DataConnectState#DATA_STATE_DISCONNECTED}
141   * <li>{@code DataConnectState#DATA_STATE_CONNECTING}
142   * <li>{@code DataConnectState#DATA_STATE_CONNECTED}
143   * <li>{@code DataConnectState#DATA_STATE_SUSPENDED}
144   * </ul>
145   * @syscap SystemCapability.Telephony.CellularData
146   * @since 7
147   */
148  function getCellularDataState(): Promise<DataConnectState>;
149
150  /**
151   * Check whether cellular data services are enabled.
152   *
153   * @permission ohos.permission.GET_NETWORK_INFO
154   * @param { AsyncCallback<boolean> } callback - Indicates the callback for checking whether cellular data services
155   * are enabled. Returns {@code true} if cellular data services are enabled; returns {@code false} otherwise.
156   * @throws { BusinessError } 201 - Permission denied.
157   * @throws { BusinessError } 401 - Parameter error.
158   * @throws { BusinessError } 8300001 - Invalid parameter value.
159   * @throws { BusinessError } 8300002 - Operation failed. Cannot connect to service.
160   * @throws { BusinessError } 8300003 - System internal error.
161   * @throws { BusinessError } 8300999 - Unknown error code.
162   * @syscap SystemCapability.Telephony.CellularData
163   * @since 7
164   */
165  function isCellularDataEnabled(callback: AsyncCallback<boolean>): void;
166
167  /**
168   * Check whether cellular data services are enabled.
169   *
170   * @permission ohos.permission.GET_NETWORK_INFO
171   * @returns { Promise<boolean> } Returns {@code true} if cellular data services are enabled.
172   * Returns {@code false} otherwise.
173   * @throws { BusinessError } 201 - Permission denied.
174   * @throws { BusinessError } 8300002 - Operation failed. Cannot connect to service.
175   * @throws { BusinessError } 8300003 - System internal error.
176   * @throws { BusinessError } 8300999 - Unknown error code.
177   * @syscap SystemCapability.Telephony.CellularData
178   * @since 7
179   */
180  function isCellularDataEnabled(): Promise<boolean>;
181
182  /**
183   * Enable cellular data services.
184   *
185   * @permission ohos.permission.SET_TELEPHONY_STATE
186   * @param { AsyncCallback<void> } callback - The callback of enableCellularData.
187   * @throws { BusinessError } 201 - Permission denied.
188   * @throws { BusinessError } 202 - Non-system applications use system APIs.
189   * @throws { BusinessError } 401 - Parameter error.
190   * @throws { BusinessError } 8300001 - Invalid parameter value.
191   * @throws { BusinessError } 8300002 - Operation failed. Cannot connect to service.
192   * @throws { BusinessError } 8300003 - System internal error.
193   * @throws { BusinessError } 8300999 - Unknown error code.
194   * @syscap SystemCapability.Telephony.CellularData
195   * @systemapi Hide this for inner system use.
196   * @since 7
197   */
198  function enableCellularData(callback: AsyncCallback<void>): void;
199
200  /**
201   * Enable cellular data services.
202   *
203   * @permission ohos.permission.SET_TELEPHONY_STATE
204   * @returns { Promise<void> } The promise returned by the enableCellularData.
205   * @throws { BusinessError } 201 - Permission denied.
206   * @throws { BusinessError } 202 - Non-system applications use system APIs.
207   * @throws { BusinessError } 8300002 - Operation failed. Cannot connect to service.
208   * @throws { BusinessError } 8300003 - System internal error.
209   * @throws { BusinessError } 8300999 - Unknown error code.
210   * @syscap SystemCapability.Telephony.CellularData
211   * @systemapi Hide this for inner system use.
212   * @since 7
213   */
214  function enableCellularData(): Promise<void>;
215
216  /**
217   * Disable cellular data services.
218   *
219   * @permission ohos.permission.SET_TELEPHONY_STATE
220   * @param { AsyncCallback<void> } callback - The callback of disableCellularData.
221   * @throws { BusinessError } 201 - Permission denied.
222   * @throws { BusinessError } 202 - Non-system applications use system APIs.
223   * @throws { BusinessError } 401 - Parameter error.
224   * @throws { BusinessError } 8300001 - Invalid parameter value.
225   * @throws { BusinessError } 8300002 - Operation failed. Cannot connect to service.
226   * @throws { BusinessError } 8300003 - System internal error.
227   * @throws { BusinessError } 8300999 - Unknown error code.
228   * @syscap SystemCapability.Telephony.CellularData
229   * @systemapi Hide this for inner system use.
230   * @since 7
231   */
232  function disableCellularData(callback: AsyncCallback<void>): void;
233
234  /**
235   * Disable cellular data services.
236   *
237   * @permission ohos.permission.SET_TELEPHONY_STATE
238   * @returns { Promise<void> } The promise returned by the disableCellularData.
239   * @throws { BusinessError } 201 - Permission denied.
240   * @throws { BusinessError } 202 - Non-system applications use system APIs.
241   * @throws { BusinessError } 8300002 - Operation failed. Cannot connect to service.
242   * @throws { BusinessError } 8300003 - System internal error.
243   * @throws { BusinessError } 8300999 - Unknown error code.
244   * @syscap SystemCapability.Telephony.CellularData
245   * @systemapi Hide this for inner system use.
246   * @since 7
247   */
248  function disableCellularData(): Promise<void>;
249
250  /**
251   * Check whether roaming is enabled for cellular data services.
252   *
253   * @permission ohos.permission.GET_NETWORK_INFO
254   * @param { number } slotId - Indicates the ID of a card slot.
255   * The value {@code 0} indicates card 1, and the value {@code 1} indicates card 2.
256   * @param { AsyncCallback<boolean> } callback - Indicates the callback for checking whether roaming is enabled
257   * for cellular data services. Returns {@code true} if roaming is enabled for cellular data services;
258   * returns {@code false} otherwise.
259   * @throws { BusinessError } 201 - Permission denied.
260   * @throws { BusinessError } 401 - Parameter error.
261   * @throws { BusinessError } 8300001 - Invalid parameter value.
262   * @throws { BusinessError } 8300002 - Operation failed. Cannot connect to service.
263   * @throws { BusinessError } 8300003 - System internal error.
264   * @throws { BusinessError } 8300999 - Unknown error code.
265   * @syscap SystemCapability.Telephony.CellularData
266   * @since 7
267   */
268  function isCellularDataRoamingEnabled(slotId: number, callback: AsyncCallback<boolean>): void;
269
270  /**
271   * Check whether roaming is enabled for cellular data services.
272   *
273   * @permission ohos.permission.GET_NETWORK_INFO
274   * @param { number } slotId - Indicates the ID of a card slot.
275   * The value {@code 0} indicates card 1, and the value {@code 1} indicates card 2.
276   * @returns { Promise<boolean> } Returns {@code true} if roaming is enabled for cellular data services.
277   * Returns {@code false} otherwise.
278   * @throws { BusinessError } 201 - Permission denied.
279   * @throws { BusinessError } 401 - Parameter error.
280   * @throws { BusinessError } 8300001 - Invalid parameter value.
281   * @throws { BusinessError } 8300002 - Operation failed. Cannot connect to service.
282   * @throws { BusinessError } 8300003 - System internal error.
283   * @throws { BusinessError } 8300999 - Unknown error code.
284   * @syscap SystemCapability.Telephony.CellularData
285   * @since 7
286   */
287  function isCellularDataRoamingEnabled(slotId: number): Promise<boolean>;
288
289  /**
290   * Enable cellular data roaming.
291   *
292   * @permission ohos.permission.SET_TELEPHONY_STATE
293   * @param { number } slotId - Indicates the ID of a card slot.
294   * The value {@code 0} indicates card 1, and the value {@code 1} indicates card 2.
295   * @param { AsyncCallback<void> } callback - The callback of enableCellularDataRoaming.
296   * @throws { BusinessError } 201 - Permission denied.
297   * @throws { BusinessError } 202 - Non-system applications use system APIs.
298   * @throws { BusinessError } 401 - Parameter error.
299   * @throws { BusinessError } 8300001 - Invalid parameter value.
300   * @throws { BusinessError } 8300002 - Operation failed. Cannot connect to service.
301   * @throws { BusinessError } 8300003 - System internal error.
302   * @throws { BusinessError } 8300999 - Unknown error code.
303   * @syscap SystemCapability.Telephony.CellularData
304   * @systemapi Hide this for inner system use.
305   * @since 7
306   */
307  function enableCellularDataRoaming(slotId: number, callback: AsyncCallback<void>): void;
308
309  /**
310   * Enable cellular data roaming.
311   *
312   * @permission ohos.permission.SET_TELEPHONY_STATE
313   * @param { number } slotId - Indicates the ID of a card slot.
314   * The value {@code 0} indicates card 1, and the value {@code 1} indicates card 2.
315   * @returns { Promise<void> } The promise returned by the enableCellularDataRoaming.
316   * @throws { BusinessError } 201 - Permission denied.
317   * @throws { BusinessError } 202 - Non-system applications use system APIs.
318   * @throws { BusinessError } 401 - Parameter error.
319   * @throws { BusinessError } 8300001 - Invalid parameter value.
320   * @throws { BusinessError } 8300002 - Operation failed. Cannot connect to service.
321   * @throws { BusinessError } 8300003 - System internal error.
322   * @throws { BusinessError } 8300999 - Unknown error code.
323   * @syscap SystemCapability.Telephony.CellularData
324   * @systemapi Hide this for inner system use.
325   * @since 7
326   */
327  function enableCellularDataRoaming(slotId: number): Promise<void>;
328
329  /**
330   * Disable cellular data roaming.
331   *
332   * @permission ohos.permission.SET_TELEPHONY_STATE
333   * @param { number } slotId - Indicates the ID of a card slot.
334   * The value {@code 0} indicates card 1, and the value {@code 1} indicates card 2.
335   * @param { AsyncCallback<void> } callback - The callback of disableCellularDataRoaming.
336   * @throws { BusinessError } 201 - Permission denied.
337   * @throws { BusinessError } 202 - Non-system applications use system APIs.
338   * @throws { BusinessError } 401 - Parameter error.
339   * @throws { BusinessError } 8300001 - Invalid parameter value.
340   * @throws { BusinessError } 8300002 - Operation failed. Cannot connect to service.
341   * @throws { BusinessError } 8300003 - System internal error.
342   * @throws { BusinessError } 8300999 - Unknown error code.
343   * @syscap SystemCapability.Telephony.CellularData
344   * @systemapi Hide this for inner system use.
345   * @since 7
346   */
347  function disableCellularDataRoaming(slotId: number, callback: AsyncCallback<void>): void;
348
349  /**
350   * Disable cellular data roaming.
351   *
352   * @permission ohos.permission.SET_TELEPHONY_STATE
353   * @param { number } slotId - Indicates the ID of a card slot.
354   * The value {@code 0} indicates card 1, and the value {@code 1} indicates card 2.
355   * @returns { Promise<void> } The promise returned by the disableCellularDataRoaming.
356   * @throws { BusinessError } 201 - Permission denied.
357   * @throws { BusinessError } 202 - Non-system applications use system APIs.
358   * @throws { BusinessError } 401 - Parameter error.
359   * @throws { BusinessError } 8300001 - Invalid parameter value.
360   * @throws { BusinessError } 8300002 - Operation failed. Cannot connect to service.
361   * @throws { BusinessError } 8300003 - System internal error.
362   * @throws { BusinessError } 8300999 - Unknown error code.
363   * @syscap SystemCapability.Telephony.CellularData
364   * @systemapi Hide this for inner system use.
365   * @since 7
366   */
367  function disableCellularDataRoaming(slotId: number): Promise<void>;
368
369  /**
370   * Obtains the default cellular data SIM ID.
371   *
372   * @returns { number } Returns the SIM ID of the default cellular data sim and SIM ID will increase from 1.
373   * @syscap SystemCapability.Telephony.CellularData
374   * @since 10
375   */
376  function getDefaultCellularDataSimId(): number;
377
378  /**
379   * Describes the cellular data flow type.
380   *
381   * @enum { number }
382   * @syscap SystemCapability.Telephony.CellularData
383   * @since 7
384   */
385  export enum DataFlowType {
386    /**
387     * Indicates that there is no uplink or downlink data.
388     *
389     * @syscap SystemCapability.Telephony.CellularData
390     * @since 7
391     */
392    DATA_FLOW_TYPE_NONE = 0,
393
394    /**
395     * Indicates that there is only downlink data.
396     *
397     * @syscap SystemCapability.Telephony.CellularData
398     * @since 7
399     */
400    DATA_FLOW_TYPE_DOWN = 1,
401
402    /**
403     * Indicates that there is only uplink data.
404     *
405     * @syscap SystemCapability.Telephony.CellularData
406     * @since 7
407     */
408    DATA_FLOW_TYPE_UP = 2,
409
410    /**
411     * Indicates that there is uplink and downlink data.
412     *
413     * @syscap SystemCapability.Telephony.CellularData
414     * @since 7
415     */
416    DATA_FLOW_TYPE_UP_DOWN = 3,
417
418    /**
419     * Indicates that there is no uplink or downlink data, and the bottom-layer link is in the dormant state.
420     *
421     * @syscap SystemCapability.Telephony.CellularData
422     * @since 7
423     */
424    DATA_FLOW_TYPE_DORMANT = 4
425  }
426
427  /**
428   * Describes the cellular data link connection state.
429   *
430   * @enum { number }
431   * @syscap SystemCapability.Telephony.CellularData
432   * @since 7
433   */
434  export enum DataConnectState {
435    /**
436     * Indicates that a cellular data link is unknown.
437     *
438     * @syscap SystemCapability.Telephony.CellularData
439     * @since 7
440     */
441    DATA_STATE_UNKNOWN = -1,
442
443    /**
444     * Indicates that a cellular data link is disconnected.
445     *
446     * @syscap SystemCapability.Telephony.CellularData
447     * @since 7
448     */
449    DATA_STATE_DISCONNECTED = 0,
450
451    /**
452     * Indicates that a cellular data link is being connected.
453     *
454     * @syscap SystemCapability.Telephony.CellularData
455     * @since 7
456     */
457    DATA_STATE_CONNECTING = 1,
458
459    /**
460     * Indicates that a cellular data link is connected.
461     *
462     * @syscap SystemCapability.Telephony.CellularData
463     * @since 7
464     */
465    DATA_STATE_CONNECTED = 2,
466
467    /**
468     * Indicates that a cellular data link is suspended.
469     *
470     * @syscap SystemCapability.Telephony.CellularData
471     * @since 7
472     */
473    DATA_STATE_SUSPENDED = 3
474  }
475}
476
477export default data;
478