1/* 2 * Copyright (C) 2021-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} from "./basic"; 17 18/** 19 * Provides methods related to cellular data services. 20 * 21 * @since 7 22 * @syscap SystemCapability.Telephony.CellularData 23 */ 24declare namespace data { 25 /** 26 * Get the default cellular data card. 27 * 28 * @returns Returns default cellular data slot id. 29 */ 30 function getDefaultCellularDataSlotId(callback: AsyncCallback<number>): void; 31 function getDefaultCellularDataSlotId(): Promise<number>; 32 33 /** 34 * Get the default cellular data card. 35 * 36 * @returns Returns default cellular data slot id. 37 * @since 9 38 */ 39 function getDefaultCellularDataSlotIdSync(): number; 40 41 /** 42 * Switches cellular data services to another card, without changing the default settings. 43 * 44 * @param slotId Indicates the ID of the target card slot. 45 * The value {@code 0} indicates card 1, and the value {@code 1} indicates card 2. 46 * @permission ohos.permission.SET_TELEPHONY_STATE 47 * @throws {BusinessError} 201 - Permission denied. 48 * @throws {BusinessError} 401 - Parameter error. 49 * @throws {BusinessError} 8300001 - Invalid parameter value. 50 * @throws {BusinessError} 8300002 - Operation failed. Cannot connect to service. 51 * @throws {BusinessError} 8300003 - System internal error. 52 * @throws {BusinessError} 8300004 - Do not have sim card. 53 * @throws {BusinessError} 8300999 - Unknown error code. 54 * @throws {BusinessError} 8301001 - SIM card is not activated. 55 * @systemapi Hide this for inner system use. 56 */ 57 function setDefaultCellularDataSlotId(slotId: number, callback: AsyncCallback<void>): void; 58 function setDefaultCellularDataSlotId(slotId: number): Promise<void>; 59 60 /** 61 * Indicates that there is no uplink or downlink data. 62 * 63 * <p>It is a return value of service state query of cellular data services. 64 */ 65 function getCellularDataFlowType(callback: AsyncCallback<DataFlowType>): void; 66 function getCellularDataFlowType(): Promise<DataFlowType>; 67 68 /** 69 * Obtains the connection state of the PS domain. 70 * 71 * @param callback Returns the connection state, which can be any of the following: 72 * <ul> 73 * <li>{@code DataConnectState#DATA_STATE_UNKNOWN} 74 * <li>{@code DataConnectState#DATA_STATE_DISCONNECTED} 75 * <li>{@code DataConnectState#DATA_STATE_CONNECTING} 76 * <li>{@code DataConnectState#DATA_STATE_CONNECTED} 77 * <li>{@code DataConnectState#DATA_STATE_SUSPENDED} 78 * </ul> 79 */ 80 function getCellularDataState(callback: AsyncCallback<DataConnectState>): void; 81 function getCellularDataState(): Promise<DataConnectState>; 82 83 /** 84 * Checks whether cellular data services are enabled. 85 * 86 * @param callback Returns {@code true} if cellular data services are enabled; returns {@code false} otherwise. 87 * @permission ohos.permission.GET_NETWORK_INFO 88 * @throws {BusinessError} 201 - Permission denied. 89 * @throws {BusinessError} 401 - Parameter error. 90 * @throws {BusinessError} 8300001 - Invalid parameter value. 91 * @throws {BusinessError} 8300002 - Operation failed. Cannot connect to service. 92 * @throws {BusinessError} 8300003 - System internal error. 93 * @throws {BusinessError} 8300999 - Unknown error code. 94 */ 95 function isCellularDataEnabled(callback: AsyncCallback<boolean>): void; 96 function isCellularDataEnabled(): Promise<boolean>; 97 98 /** 99 * Enables cellular data services. 100 * 101 * @permission ohos.permission.SET_TELEPHONY_STATE 102 * @throws {BusinessError} 201 - Permission denied. 103 * @throws {BusinessError} 401 - Parameter error. 104 * @throws {BusinessError} 8300001 - Invalid parameter value. 105 * @throws {BusinessError} 8300002 - Operation failed. Cannot connect to service. 106 * @throws {BusinessError} 8300003 - System internal error. 107 * @throws {BusinessError} 8300999 - Unknown error code. 108 * @systemapi Hide this for inner system use. 109 */ 110 function enableCellularData(callback: AsyncCallback<void>): void; 111 function enableCellularData(): Promise<void>; 112 113 /** 114 * Disables cellular data services. 115 * 116 * @permission ohos.permission.SET_TELEPHONY_STATE 117 * @throws {BusinessError} 201 - Permission denied. 118 * @throws {BusinessError} 401 - Parameter error. 119 * @throws {BusinessError} 8300001 - Invalid parameter value. 120 * @throws {BusinessError} 8300002 - Operation failed. Cannot connect to service. 121 * @throws {BusinessError} 8300003 - System internal error. 122 * @throws {BusinessError} 8300999 - Unknown error code. 123 * @systemapi Hide this for inner system use. 124 */ 125 function disableCellularData(callback: AsyncCallback<void>): void; 126 function disableCellularData(): Promise<void>; 127 128 /** 129 * Checks whether roaming is enabled for cellular data services. 130 * 131 * @param slotId Indicates the ID of a card slot. 132 * The value {@code 0} indicates card 1, and the value {@code 1} indicates card 2. 133 * @param callback Returns {@code true} if roaming is enabled for cellular data services; returns {@code false} otherwise. 134 * @permission ohos.permission.GET_NETWORK_INFO 135 * @throws {BusinessError} 201 - Permission denied. 136 * @throws {BusinessError} 401 - Parameter error. 137 * @throws {BusinessError} 8300001 - Invalid parameter value. 138 * @throws {BusinessError} 8300002 - Operation failed. Cannot connect to service. 139 * @throws {BusinessError} 8300003 - System internal error. 140 * @throws {BusinessError} 8300999 - Unknown error code. 141 */ 142 function isCellularDataRoamingEnabled(slotId: number, callback: AsyncCallback<boolean>): void; 143 function isCellularDataRoamingEnabled(slotId: number): Promise<boolean>; 144 145 /** 146 * Enables cellular data roaming. 147 * 148 * @param slotId Indicates the ID of a card slot. 149 * The value {@code 0} indicates card 1, and the value {@code 1} indicates card 2. 150 * @permission ohos.permission.SET_TELEPHONY_STATE 151 * @throws {BusinessError} 201 - Permission denied. 152 * @throws {BusinessError} 401 - Parameter error. 153 * @throws {BusinessError} 8300001 - Invalid parameter value. 154 * @throws {BusinessError} 8300002 - Operation failed. Cannot connect to service. 155 * @throws {BusinessError} 8300003 - System internal error. 156 * @throws {BusinessError} 8300999 - Unknown error code. 157 * @systemapi Hide this for inner system use. 158 */ 159 function enableCellularDataRoaming(slotId: number, callback: AsyncCallback<void>): void; 160 function enableCellularDataRoaming(slotId: number): Promise<void>; 161 162 /** 163 * Disables cellular data roaming. 164 * 165 * @param slotId Indicates the ID of a card slot. 166 * The value {@code 0} indicates card 1, and the value {@code 1} indicates card 2. 167 * @permission ohos.permission.SET_TELEPHONY_STATE 168 * @throws {BusinessError} 201 - Permission denied. 169 * @throws {BusinessError} 401 - Parameter error. 170 * @throws {BusinessError} 8300001 - Invalid parameter value. 171 * @throws {BusinessError} 8300002 - Operation failed. Cannot connect to service. 172 * @throws {BusinessError} 8300003 - System internal error. 173 * @throws {BusinessError} 8300999 - Unknown error code. 174 * @systemapi Hide this for inner system use. 175 */ 176 function disableCellularDataRoaming(slotId: number, callback: AsyncCallback<void>): void; 177 function disableCellularDataRoaming(slotId: number): Promise<void>; 178 179 /** 180 * Describes the cellular data flow type. 181 */ 182 export enum DataFlowType { 183 /** 184 * Indicates that there is no uplink or downlink data. 185 */ 186 DATA_FLOW_TYPE_NONE = 0, 187 188 /** 189 * Indicates that there is only downlink data. 190 */ 191 DATA_FLOW_TYPE_DOWN = 1, 192 193 /** 194 * Indicates that there is only uplink data. 195 */ 196 DATA_FLOW_TYPE_UP = 2, 197 198 /** 199 * Indicates that there is uplink and downlink data. 200 */ 201 DATA_FLOW_TYPE_UP_DOWN = 3, 202 203 /** 204 * Indicates that there is no uplink or downlink data, and the bottom-layer link is in the dormant state. 205 */ 206 DATA_FLOW_TYPE_DORMANT = 4 207 } 208 209 /** 210 * Describes the cellular data link connection state. 211 */ 212 export enum DataConnectState { 213 /** 214 * Indicates that a cellular data link is unknown. 215 */ 216 DATA_STATE_UNKNOWN = -1, 217 218 /** 219 * Indicates that a cellular data link is disconnected. 220 */ 221 DATA_STATE_DISCONNECTED = 0, 222 223 /** 224 * Indicates that a cellular data link is being connected. 225 */ 226 DATA_STATE_CONNECTING = 1, 227 228 /** 229 * Indicates that a cellular data link is connected. 230 */ 231 DATA_STATE_CONNECTED = 2, 232 233 /** 234 * Indicates that a cellular data link is suspended. 235 */ 236 DATA_STATE_SUSPENDED = 3 237 } 238} 239 240export default data;