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 {Callback} from "./basic"; 17import radio from "./@ohos.telephony.radio"; 18import data from "./@ohos.telephony.data"; 19import call from "./@ohos.telephony.call"; 20import sim from "./@ohos.telephony.sim"; 21 22/** 23 * Monitors telephony state updates of a device, including updates of the network state, 24 * signal strength, call state, the data link connection state and others. 25 * 26 * @since 6 27 * @syscap SystemCapability.Telephony.StateRegistry 28 */ 29declare namespace observer { 30 type NetworkState = radio.NetworkState; 31 type SignalInformation = radio.SignalInformation; 32 /** 33 * @systemapi Hide this for inner system use. 34 */ 35 type CellInformation = radio.CellInformation; 36 type DataConnectState = data.DataConnectState; 37 type RatType = radio.RadioTechnology; 38 type DataFlowType = data.DataFlowType; 39 type CallState = call.CallState; 40 type CardType = sim.CardType; 41 type SimState = sim.SimState; 42 43 /** 44 * Called when the network state corresponding to a monitored {@code slotId} updates. 45 * 46 * @param type networkStateChange 47 * @param options including slotId Indicates the ID of the target card slot. 48 * The value {@code 0} indicates card 1, and the value {@code 1} indicates card 2. 49 * @param callback including an instance of the {@code NetworkState} class. 50 * @permission ohos.permission.GET_NETWORK_INFO 51 * @throws {BusinessError} 201 - Permission denied. 52 * @throws {BusinessError} 401 - Parameter error. 53 * @throws {BusinessError} 8300001 - Invalid parameter value. 54 * @throws {BusinessError} 8300002 - Operation failed. Cannot connect to service. 55 * @throws {BusinessError} 8300003 - System internal error. 56 * @throws {BusinessError} 8300999 - Unknown error code. 57 */ 58 function on(type: 'networkStateChange', callback: Callback<NetworkState>): void; 59 function on(type: 'networkStateChange', options: { slotId: number }, callback: Callback<NetworkState>): void; 60 61 /** 62 * Cancel Called when the network state corresponding to a monitored {@code slotId} updates. 63 * 64 * @param type networkStateChange 65 * @param callback including an instance of the {@code NetworkState} class. 66 * @throws {BusinessError} 401 - Parameter error. 67 * @throws {BusinessError} 8300001 - Invalid parameter value. 68 * @throws {BusinessError} 8300002 - Operation failed. Cannot connect to service. 69 * @throws {BusinessError} 8300003 - System internal error. 70 * @throws {BusinessError} 8300999 - Unknown error code. 71 */ 72 function off(type: 'networkStateChange', callback?: Callback<NetworkState>): void; 73 74 /** 75 * Called when the signal strength corresponding to a monitored {@code slotId} updates. 76 * 77 * @param type signalInfoChange 78 * @param options including slotId Indicates the ID of the target card slot. 79 * The value {@code 0} indicates card 1, and the value {@code 1} indicates card 2. 80 * @param callback including an array of instances of the classes derived from {@link SignalInformation}. 81 * @throws {BusinessError} 401 - Parameter error. 82 * @throws {BusinessError} 8300001 - Invalid parameter value. 83 * @throws {BusinessError} 8300002 - Operation failed. Cannot connect to service. 84 * @throws {BusinessError} 8300003 - System internal error. 85 * @throws {BusinessError} 8300999 - Unknown error code. 86 */ 87 function on(type: 'signalInfoChange', callback: Callback<Array<SignalInformation>>): void; 88 function on(type: 'signalInfoChange', options: { slotId: number }, 89 callback: Callback<Array<SignalInformation>>): void; 90 91 /** 92 * Cancel Called when the signal strength corresponding to a monitored {@code slotId} updates. 93 * 94 * @param type signalInfoChange 95 * @param callback including an array of instances of the classes derived from {@link SignalInformation}. 96 * @throws {BusinessError} 401 - Parameter error. 97 * @throws {BusinessError} 8300001 - Invalid parameter value. 98 * @throws {BusinessError} 8300002 - Operation failed. Cannot connect to service. 99 * @throws {BusinessError} 8300003 - System internal error. 100 * @throws {BusinessError} 8300999 - Unknown error code. 101 */ 102 function off(type: 'signalInfoChange', callback?: Callback<Array<SignalInformation>>): void; 103 104 /** 105 * Called back when the cell information corresponding to a monitored {@code slotId} updates. 106 * 107 * @param type cellInfoChange 108 * @param options including slotId Indicates the ID of the target card slot. 109 * The value {@code 0} indicates card 1, and the value {@code 1} indicates card 2. 110 * @param callback including an array of instances of the classes derived from {@link CellInformation}. 111 * @permission ohos.permission.LOCATION and ohos.permission.APPROXIMATELY_LOCATION 112 * @throws {BusinessError} 201 - Permission denied. 113 * @throws {BusinessError} 401 - Parameter error. 114 * @throws {BusinessError} 8300001 - Invalid parameter value. 115 * @throws {BusinessError} 8300002 - Operation failed. Cannot connect to service. 116 * @throws {BusinessError} 8300003 - System internal error. 117 * @throws {BusinessError} 8300999 - Unknown error code. 118 * @systemapi Hide this for inner system use. 119 * @since 8 120 */ 121 function on(type: 'cellInfoChange', callback: Callback<Array<CellInformation>>): void; 122 function on(type: 'cellInfoChange', options: { slotId: number }, 123 callback: Callback<Array<CellInformation>>): void; 124 125 /** 126 * Cancel Called back when the cell information corresponding to a monitored {@code slotId} updates. 127 * 128 * @param type cellInfoChange 129 * @param callback including an array of instances of the classes derived from {@link CellInformation}. 130 * @throws {BusinessError} 401 - Parameter error. 131 * @throws {BusinessError} 8300001 - Invalid parameter value. 132 * @throws {BusinessError} 8300002 - Operation failed. Cannot connect to service. 133 * @throws {BusinessError} 8300003 - System internal error. 134 * @throws {BusinessError} 8300999 - Unknown error code. 135 * @systemapi Hide this for inner system use. 136 * @since 8 137 */ 138 function off(type: 'cellInfoChange', callback?: Callback<Array<CellInformation>>): void; 139 140 /** 141 * Called when the cellular data link connection state updates. 142 * 143 * @param type cellularDataConnectionStateChange 144 * @param options including slotId Indicates the ID of the target card slot. 145 * The value {@code 0} indicates card 1, and the value {@code 1} indicates card 2. 146 * @param callback including state Indicates the cellular data link connection state, 147 * and networkType Indicates the radio access technology for cellular data services. 148 * @throws {BusinessError} 401 - Parameter error. 149 * @throws {BusinessError} 8300001 - Invalid parameter value. 150 * @throws {BusinessError} 8300002 - Operation failed. Cannot connect to service. 151 * @throws {BusinessError} 8300003 - System internal error. 152 * @throws {BusinessError} 8300999 - Unknown error code. 153 * @since 7 154 */ 155 function on(type: 'cellularDataConnectionStateChange', 156 callback: Callback<{ state: DataConnectState, network: RatType }>): void; 157 function on(type: 'cellularDataConnectionStateChange', options: { slotId: number }, 158 callback: Callback<{ state: DataConnectState, network: RatType }>): void; 159 160 /** 161 * Cancel Called when the cellular data link connection state updates. 162 * 163 * @param type cellularDataConnectionStateChange 164 * @param callback including state Indicates the cellular data link connection state, 165 * and networkType Indicates the radio access technology for cellular data services. 166 * @throws {BusinessError} 401 - Parameter error. 167 * @throws {BusinessError} 8300001 - Invalid parameter value. 168 * @throws {BusinessError} 8300002 - Operation failed. Cannot connect to service. 169 * @throws {BusinessError} 8300003 - System internal error. 170 * @throws {BusinessError} 8300999 - Unknown error code. 171 * @since 7 172 */ 173 function off(type: 'cellularDataConnectionStateChange', 174 callback?: Callback<{ state: DataConnectState, network: RatType }>): void; 175 176 /** 177 * Called when the uplink and downlink data flow state of cellular data services updates. 178 * 179 * @param type cellularDataFlowChange 180 * @param options including slotId Indicates the ID of the target card slot. 181 * The value {@code 0} indicates card 1, and the value {@code 1} indicates card 2. 182 * @param callback including the cellular data flow state. 183 * @throws {BusinessError} 401 - Parameter error. 184 * @throws {BusinessError} 8300001 - Invalid parameter value. 185 * @throws {BusinessError} 8300002 - Operation failed. Cannot connect to service. 186 * @throws {BusinessError} 8300003 - System internal error. 187 * @throws {BusinessError} 8300999 - Unknown error code. 188 * @since 7 189 */ 190 function on(type: 'cellularDataFlowChange', callback: Callback<DataFlowType>): void; 191 function on(type: 'cellularDataFlowChange', options: { slotId: number }, 192 callback: Callback<DataFlowType>): void; 193 194 /** 195 * Cancel Called when the uplink and downlink data flow state of cellular data services updates. 196 * 197 * @param type cellularDataFlowChange 198 * @param callback including the cellular data flow state. 199 * @throws {BusinessError} 401 - Parameter error. 200 * @throws {BusinessError} 8300001 - Invalid parameter value. 201 * @throws {BusinessError} 8300002 - Operation failed. Cannot connect to service. 202 * @throws {BusinessError} 8300003 - System internal error. 203 * @throws {BusinessError} 8300999 - Unknown error code. 204 * @since 7 205 */ 206 function off(type: 'cellularDataFlowChange', callback?: Callback<DataFlowType>): void; 207 208 /** 209 * Receives a call state change. This callback is invoked when the call state of a specified card updates 210 * and the observer is added to monitor the updates. 211 * 212 * @param type callStateChange 213 * @param options including slotId Indicates the ID of the target card slot. 214 * The value {@code 0} indicates card 1, and the value {@code 1} indicates card 2. 215 * @param callback including state Indicates the call state, and number Indicates the called number. 216 * The value of number is an empty string if the application does not have the 217 * ohos.permission.READ_CALL_LOG permission. 218 * @throws {BusinessError} 401 - Parameter error. 219 * @throws {BusinessError} 8300001 - Invalid parameter value. 220 * @throws {BusinessError} 8300002 - Operation failed. Cannot connect to service. 221 * @throws {BusinessError} 8300003 - System internal error. 222 * @throws {BusinessError} 8300999 - Unknown error code. 223 */ 224 function on(type: 'callStateChange', callback: Callback<{ state: CallState, number: string }>): void; 225 function on(type: 'callStateChange', options: { slotId: number }, 226 callback: Callback<{ state: CallState, number: string }>): void; 227 228 /** 229 * Cancel Receives a call state change. This callback is invoked when the call state of a specified card updates 230 * and the observer is added to monitor the updates. 231 * 232 * @param type callStateChange 233 * @param callback including state Indicates the call state, and number Indicates the called number. 234 * @throws {BusinessError} 401 - Parameter error. 235 * @throws {BusinessError} 8300001 - Invalid parameter value. 236 * @throws {BusinessError} 8300002 - Operation failed. Cannot connect to service. 237 * @throws {BusinessError} 8300003 - System internal error. 238 * @throws {BusinessError} 8300999 - Unknown error code. 239 */ 240 function off(type: 'callStateChange', callback?: Callback<{ state: CallState, number: string }>): void; 241 242 /** 243 * Receives a sim state change. This callback is invoked when the sim state of a specified card updates 244 * and the observer is added to monitor the updates. 245 * 246 * @param type simStateChange 247 * @param options including slotId Indicates the ID of the target card slot. 248 * The value {@code 0} indicates card 1, and the value {@code 1} indicates card 2. 249 * @param callback including state Indicates the sim state, and reason Indicates the cause of the change. 250 * @throws {BusinessError} 401 - Parameter error. 251 * @throws {BusinessError} 8300001 - Invalid parameter value. 252 * @throws {BusinessError} 8300002 - Operation failed. Cannot connect to service. 253 * @throws {BusinessError} 8300003 - System internal error. 254 * @throws {BusinessError} 8300999 - Unknown error code. 255 * @since 7 256 */ 257 function on(type: 'simStateChange', callback: Callback<SimStateData>): void; 258 function on(type: 'simStateChange', options: { slotId: number }, callback: Callback<SimStateData>): void; 259 260 /** 261 * Receives a sim state change. This callback is invoked when the sim state of a specified card updates 262 * and the observer is delete. 263 * 264 * @param type simStateChange 265 * @param callback including state Indicates the sim state, and reason Indicates the cause of the change. 266 * @throws {BusinessError} 401 - Parameter error. 267 * @throws {BusinessError} 8300001 - Invalid parameter value. 268 * @throws {BusinessError} 8300002 - Operation failed. Cannot connect to service. 269 * @throws {BusinessError} 8300003 - System internal error. 270 * @throws {BusinessError} 8300999 - Unknown error code. 271 * @since 7 272 */ 273 function off(type: 'simStateChange', callback?: Callback<SimStateData>): void; 274 275 /** 276 * @since 7 277 */ 278 export interface SimStateData { 279 type: CardType; 280 state: SimState; 281 /** 282 * @since 8 283 */ 284 reason: LockReason; 285 } 286 287 /** 288 * @since 8 289 */ 290 export enum LockReason { 291 SIM_NONE, 292 SIM_PIN, 293 SIM_PUK, 294 SIM_PN_PIN, //Network Personalization (refer 3GPP TS 22.022 [33]) 295 SIM_PN_PUK, 296 SIM_PU_PIN, //Network Subset Personalization (refer 3GPP TS 22.022 [33]) 297 SIM_PU_PUK, 298 SIM_PP_PIN, //Service Provider Personalization (refer 3GPP TS 22.022 [33]) 299 SIM_PP_PUK, 300 SIM_PC_PIN, //Corporate Personalization (refer 3GPP TS 22.022 [33]) 301 SIM_PC_PUK, 302 SIM_SIM_PIN, //SIM/USIM Personalization (refer 3GPP TS 22.022 [33]) 303 SIM_SIM_PUK, 304 } 305} 306 307export default observer;