1/* 2 * Copyright (C) 2021-2024 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 - Service connection failed. 71 * @throws { BusinessError } 8300003 - System internal error. 72 * @throws { BusinessError } 8300004 - No SIM card found. 73 * @throws { BusinessError } 8300999 - Unknown error. 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 - Service connection failed. 94 * @throws { BusinessError } 8300003 - System internal error. 95 * @throws { BusinessError } 8300004 - No SIM card found. 96 * @throws { BusinessError } 8300999 - Unknown error. 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 - Service connection failed. 168 * @throws { BusinessError } 8300003 - System internal error. 169 * @throws { BusinessError } 8300999 - Unknown error. 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 - Service connection failed. 183 * @throws { BusinessError } 8300003 - System internal error. 184 * @throws { BusinessError } 8300999 - Unknown error. 185 * @syscap SystemCapability.Telephony.CellularData 186 * @since 7 187 */ 188 function isCellularDataEnabled(): Promise<boolean>; 189 190 /** 191 * Check whether cellular data services are enabled. 192 * 193 * @permission ohos.permission.GET_NETWORK_INFO 194 * @returns { boolean } Returns {@code true} if cellular data services are enabled. 195 * Returns {@code false} otherwise. 196 * @throws { BusinessError } 201 - Permission denied. 197 * @throws { BusinessError } 8300002 - Operation failed. Cannot connect to service. 198 * @throws { BusinessError } 8300003 - System internal error. 199 * @throws { BusinessError } 8300999 - Unknown error code. 200 * @syscap SystemCapability.Telephony.CellularData 201 * @since 12 202 */ 203 function isCellularDataEnabledSync(): boolean; 204 205 /** 206 * Enable cellular data services. 207 * 208 * @permission ohos.permission.SET_TELEPHONY_STATE 209 * @param { AsyncCallback<void> } callback - The callback of enableCellularData. 210 * @throws { BusinessError } 201 - Permission denied. 211 * @throws { BusinessError } 202 - Non-system applications use system APIs. 212 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 213 * 2. Incorrect parameter types. 214 * @throws { BusinessError } 8300001 - Invalid parameter value. 215 * @throws { BusinessError } 8300002 - Service connection failed. 216 * @throws { BusinessError } 8300003 - System internal error. 217 * @throws { BusinessError } 8300999 - Unknown error. 218 * @syscap SystemCapability.Telephony.CellularData 219 * @systemapi Hide this for inner system use. 220 * @since 7 221 */ 222 function enableCellularData(callback: AsyncCallback<void>): void; 223 224 /** 225 * Enable cellular data services. 226 * 227 * @permission ohos.permission.SET_TELEPHONY_STATE 228 * @returns { Promise<void> } The promise returned by the enableCellularData. 229 * @throws { BusinessError } 201 - Permission denied. 230 * @throws { BusinessError } 202 - Non-system applications use system APIs. 231 * @throws { BusinessError } 8300002 - Service connection failed. 232 * @throws { BusinessError } 8300003 - System internal error. 233 * @throws { BusinessError } 8300999 - Unknown error. 234 * @syscap SystemCapability.Telephony.CellularData 235 * @systemapi Hide this for inner system use. 236 * @since 7 237 */ 238 function enableCellularData(): Promise<void>; 239 240 /** 241 * Disable cellular data services. 242 * 243 * @permission ohos.permission.SET_TELEPHONY_STATE 244 * @param { AsyncCallback<void> } callback - The callback of disableCellularData. 245 * @throws { BusinessError } 201 - Permission denied. 246 * @throws { BusinessError } 202 - Non-system applications use system APIs. 247 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 248 * 2. Incorrect parameter types. 249 * @throws { BusinessError } 8300001 - Invalid parameter value. 250 * @throws { BusinessError } 8300002 - Service connection failed. 251 * @throws { BusinessError } 8300003 - System internal error. 252 * @throws { BusinessError } 8300999 - Unknown error. 253 * @syscap SystemCapability.Telephony.CellularData 254 * @systemapi Hide this for inner system use. 255 * @since 7 256 */ 257 function disableCellularData(callback: AsyncCallback<void>): void; 258 259 /** 260 * Disable cellular data services. 261 * 262 * @permission ohos.permission.SET_TELEPHONY_STATE 263 * @returns { Promise<void> } The promise returned by the disableCellularData. 264 * @throws { BusinessError } 201 - Permission denied. 265 * @throws { BusinessError } 202 - Non-system applications use system APIs. 266 * @throws { BusinessError } 8300002 - Service connection failed. 267 * @throws { BusinessError } 8300003 - System internal error. 268 * @throws { BusinessError } 8300999 - Unknown error. 269 * @syscap SystemCapability.Telephony.CellularData 270 * @systemapi Hide this for inner system use. 271 * @since 7 272 */ 273 function disableCellularData(): Promise<void>; 274 275 /** 276 * Check whether roaming is enabled for cellular data services. 277 * 278 * @permission ohos.permission.GET_NETWORK_INFO 279 * @param { number } slotId - Indicates the ID of a card slot. 280 * The value {@code 0} indicates card 1, and the value {@code 1} indicates card 2. 281 * @param { AsyncCallback<boolean> } callback - Indicates the callback for checking whether roaming is enabled 282 * for cellular data services. Returns {@code true} if roaming is enabled for cellular data services; 283 * returns {@code false} otherwise. 284 * @throws { BusinessError } 201 - Permission denied. 285 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 286 * 2. Incorrect parameter types. 287 * @throws { BusinessError } 8300001 - Invalid parameter value. 288 * @throws { BusinessError } 8300002 - Service connection failed. 289 * @throws { BusinessError } 8300003 - System internal error. 290 * @throws { BusinessError } 8300999 - Unknown error. 291 * @syscap SystemCapability.Telephony.CellularData 292 * @since 7 293 */ 294 function isCellularDataRoamingEnabled(slotId: number, callback: AsyncCallback<boolean>): void; 295 296 /** 297 * Check whether roaming is enabled for cellular data services. 298 * 299 * @permission ohos.permission.GET_NETWORK_INFO 300 * @param { number } slotId - Indicates the ID of a card slot. 301 * The value {@code 0} indicates card 1, and the value {@code 1} indicates card 2. 302 * @returns { Promise<boolean> } Returns {@code true} if roaming is enabled for cellular data services. 303 * Returns {@code false} otherwise. 304 * @throws { BusinessError } 201 - Permission denied. 305 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 306 * 2. Incorrect parameter types. 307 * @throws { BusinessError } 8300001 - Invalid parameter value. 308 * @throws { BusinessError } 8300002 - Service connection failed. 309 * @throws { BusinessError } 8300003 - System internal error. 310 * @throws { BusinessError } 8300999 - Unknown error. 311 * @syscap SystemCapability.Telephony.CellularData 312 * @since 7 313 */ 314 function isCellularDataRoamingEnabled(slotId: number): Promise<boolean>; 315 316 /** 317 * Check whether roaming is enabled for cellular data services. 318 * 319 * @permission ohos.permission.GET_NETWORK_INFO 320 * @param { number } slotId - Indicates the ID of a card slot. 321 * The value {@code 0} indicates card 1, and the value {@code 1} indicates card 2. 322 * @returns { boolean } Returns {@code true} if roaming is enabled for cellular data services. 323 * Returns {@code false} otherwise. 324 * @throws { BusinessError } 201 - Permission denied. 325 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 326 * 2. Incorrect parameters types; 327 * @throws { BusinessError } 8300001 - Invalid parameter value. 328 * @throws { BusinessError } 8300002 - Operation failed. Cannot connect to service. 329 * @throws { BusinessError } 8300003 - System internal error. 330 * @throws { BusinessError } 8300999 - Unknown error code. 331 * @syscap SystemCapability.Telephony.CellularData 332 * @since 12 333 */ 334 function isCellularDataRoamingEnabledSync(slotId: number): boolean; 335 336 /** 337 * Enable cellular data roaming. 338 * 339 * @permission ohos.permission.SET_TELEPHONY_STATE 340 * @param { number } slotId - Indicates the ID of a card slot. 341 * The value {@code 0} indicates card 1, and the value {@code 1} indicates card 2. 342 * @param { AsyncCallback<void> } callback - The callback of enableCellularDataRoaming. 343 * @throws { BusinessError } 201 - Permission denied. 344 * @throws { BusinessError } 202 - Non-system applications use system APIs. 345 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 346 * 2. Incorrect parameter types. 347 * @throws { BusinessError } 8300001 - Invalid parameter value. 348 * @throws { BusinessError } 8300002 - Service connection failed. 349 * @throws { BusinessError } 8300003 - System internal error. 350 * @throws { BusinessError } 8300999 - Unknown error. 351 * @syscap SystemCapability.Telephony.CellularData 352 * @systemapi Hide this for inner system use. 353 * @since 7 354 */ 355 function enableCellularDataRoaming(slotId: number, callback: AsyncCallback<void>): void; 356 357 /** 358 * Enable cellular data roaming. 359 * 360 * @permission ohos.permission.SET_TELEPHONY_STATE 361 * @param { number } slotId - Indicates the ID of a card slot. 362 * The value {@code 0} indicates card 1, and the value {@code 1} indicates card 2. 363 * @returns { Promise<void> } The promise returned by the enableCellularDataRoaming. 364 * @throws { BusinessError } 201 - Permission denied. 365 * @throws { BusinessError } 202 - Non-system applications use system APIs. 366 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 367 * 2. Incorrect parameter types. 368 * @throws { BusinessError } 8300001 - Invalid parameter value. 369 * @throws { BusinessError } 8300002 - Service connection failed. 370 * @throws { BusinessError } 8300003 - System internal error. 371 * @throws { BusinessError } 8300999 - Unknown error. 372 * @syscap SystemCapability.Telephony.CellularData 373 * @systemapi Hide this for inner system use. 374 * @since 7 375 */ 376 function enableCellularDataRoaming(slotId: number): Promise<void>; 377 378 /** 379 * Disable cellular data roaming. 380 * 381 * @permission ohos.permission.SET_TELEPHONY_STATE 382 * @param { number } slotId - Indicates the ID of a card slot. 383 * The value {@code 0} indicates card 1, and the value {@code 1} indicates card 2. 384 * @param { AsyncCallback<void> } callback - The callback of disableCellularDataRoaming. 385 * @throws { BusinessError } 201 - Permission denied. 386 * @throws { BusinessError } 202 - Non-system applications use system APIs. 387 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 388 * 2. Incorrect parameter types. 389 * @throws { BusinessError } 8300001 - Invalid parameter value. 390 * @throws { BusinessError } 8300002 - Service connection failed. 391 * @throws { BusinessError } 8300003 - System internal error. 392 * @throws { BusinessError } 8300999 - Unknown error. 393 * @syscap SystemCapability.Telephony.CellularData 394 * @systemapi Hide this for inner system use. 395 * @since 7 396 */ 397 function disableCellularDataRoaming(slotId: number, callback: AsyncCallback<void>): void; 398 399 /** 400 * Disable cellular data roaming. 401 * 402 * @permission ohos.permission.SET_TELEPHONY_STATE 403 * @param { number } slotId - Indicates the ID of a card slot. 404 * The value {@code 0} indicates card 1, and the value {@code 1} indicates card 2. 405 * @returns { Promise<void> } The promise returned by the disableCellularDataRoaming. 406 * @throws { BusinessError } 201 - Permission denied. 407 * @throws { BusinessError } 202 - Non-system applications use system APIs. 408 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 409 * 2. Incorrect parameter types. 410 * @throws { BusinessError } 8300001 - Invalid parameter value. 411 * @throws { BusinessError } 8300002 - Service connection failed. 412 * @throws { BusinessError } 8300003 - System internal error. 413 * @throws { BusinessError } 8300999 - Unknown error. 414 * @syscap SystemCapability.Telephony.CellularData 415 * @systemapi Hide this for inner system use. 416 * @since 7 417 */ 418 function disableCellularDataRoaming(slotId: number): Promise<void>; 419 420 /** 421 * Obtains the default cellular data SIM ID. 422 * 423 * @returns { number } Returns the SIM ID of the default cellular data sim and SIM ID will increase from 1. 424 * @syscap SystemCapability.Telephony.CellularData 425 * @since 10 426 */ 427 function getDefaultCellularDataSimId(): number; 428 429 /** 430 * Describes the cellular data flow type. 431 * 432 * @enum { number } 433 * @syscap SystemCapability.Telephony.CellularData 434 * @since 7 435 */ 436 export enum DataFlowType { 437 /** 438 * Indicates that there is no uplink or downlink data. 439 * 440 * @syscap SystemCapability.Telephony.CellularData 441 * @since 7 442 */ 443 DATA_FLOW_TYPE_NONE = 0, 444 445 /** 446 * Indicates that there is only downlink data. 447 * 448 * @syscap SystemCapability.Telephony.CellularData 449 * @since 7 450 */ 451 DATA_FLOW_TYPE_DOWN = 1, 452 453 /** 454 * Indicates that there is only uplink data. 455 * 456 * @syscap SystemCapability.Telephony.CellularData 457 * @since 7 458 */ 459 DATA_FLOW_TYPE_UP = 2, 460 461 /** 462 * Indicates that there is uplink and downlink data. 463 * 464 * @syscap SystemCapability.Telephony.CellularData 465 * @since 7 466 */ 467 DATA_FLOW_TYPE_UP_DOWN = 3, 468 469 /** 470 * Indicates that there is no uplink or downlink data, and the bottom-layer link is in the dormant state. 471 * 472 * @syscap SystemCapability.Telephony.CellularData 473 * @since 7 474 */ 475 DATA_FLOW_TYPE_DORMANT = 4 476 } 477 478 /** 479 * Describes the cellular data link connection state. 480 * 481 * @enum { number } 482 * @syscap SystemCapability.Telephony.CellularData 483 * @since 7 484 */ 485 export enum DataConnectState { 486 /** 487 * Indicates that a cellular data link is unknown. 488 * 489 * @syscap SystemCapability.Telephony.CellularData 490 * @since 7 491 */ 492 DATA_STATE_UNKNOWN = -1, 493 494 /** 495 * Indicates that a cellular data link is disconnected. 496 * 497 * @syscap SystemCapability.Telephony.CellularData 498 * @since 7 499 */ 500 DATA_STATE_DISCONNECTED = 0, 501 502 /** 503 * Indicates that a cellular data link is being connected. 504 * 505 * @syscap SystemCapability.Telephony.CellularData 506 * @since 7 507 */ 508 DATA_STATE_CONNECTING = 1, 509 510 /** 511 * Indicates that a cellular data link is connected. 512 * 513 * @syscap SystemCapability.Telephony.CellularData 514 * @since 7 515 */ 516 DATA_STATE_CONNECTED = 2, 517 518 /** 519 * Indicates that a cellular data link is suspended. 520 * 521 * @syscap SystemCapability.Telephony.CellularData 522 * @since 7 523 */ 524 DATA_STATE_SUSPENDED = 3 525 } 526} 527 528export default data; 529