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