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 * @throws {BusinessError} 401 - Parameter error. 217 * @throws {BusinessError} 8300001 - Invalid parameter value. 218 * @throws {BusinessError} 8300002 - Operation failed. Cannot connect to service. 219 * @throws {BusinessError} 8300003 - System internal error. 220 * @throws {BusinessError} 8300999 - Unknown error code. 221 */ 222 function on(type: 'callStateChange', callback: Callback<{ state: CallState, number: string }>): void; 223 function on(type: 'callStateChange', options: { slotId: number }, 224 callback: Callback<{ state: CallState, number: string }>): void; 225 226 /** 227 * Cancel Receives a call state change. This callback is invoked when the call state of a specified card updates 228 * and the observer is added to monitor the updates. 229 * 230 * @param type callStateChange 231 * @param callback including state Indicates the call state, and number Indicates the called number. 232 * @throws {BusinessError} 401 - Parameter error. 233 * @throws {BusinessError} 8300001 - Invalid parameter value. 234 * @throws {BusinessError} 8300002 - Operation failed. Cannot connect to service. 235 * @throws {BusinessError} 8300003 - System internal error. 236 * @throws {BusinessError} 8300999 - Unknown error code. 237 */ 238 function off(type: 'callStateChange', callback?: Callback<{ state: CallState, number: string }>): void; 239 240 /** 241 * Receives a sim state change. This callback is invoked when the sim state of a specified card updates 242 * and the observer is added to monitor the updates. 243 * 244 * @param type simStateChange 245 * @param options including slotId Indicates the ID of the target card slot. 246 * The value {@code 0} indicates card 1, and the value {@code 1} indicates card 2. 247 * @param callback including state Indicates the sim state, and reason Indicates the cause of the change. 248 * @throws {BusinessError} 401 - Parameter error. 249 * @throws {BusinessError} 8300001 - Invalid parameter value. 250 * @throws {BusinessError} 8300002 - Operation failed. Cannot connect to service. 251 * @throws {BusinessError} 8300003 - System internal error. 252 * @throws {BusinessError} 8300999 - Unknown error code. 253 * @since 7 254 */ 255 function on(type: 'simStateChange', callback: Callback<SimStateData>): void; 256 function on(type: 'simStateChange', options: { slotId: number }, callback: Callback<SimStateData>): void; 257 258 /** 259 * Receives a sim state change. This callback is invoked when the sim state of a specified card updates 260 * and the observer is delete. 261 * 262 * @param type simStateChange 263 * @param callback including state Indicates the sim state, and reason Indicates the cause of the change. 264 * @throws {BusinessError} 401 - Parameter error. 265 * @throws {BusinessError} 8300001 - Invalid parameter value. 266 * @throws {BusinessError} 8300002 - Operation failed. Cannot connect to service. 267 * @throws {BusinessError} 8300003 - System internal error. 268 * @throws {BusinessError} 8300999 - Unknown error code. 269 * @since 7 270 */ 271 function off(type: 'simStateChange', callback?: Callback<SimStateData>): void; 272 273 /** 274 * @since 7 275 */ 276 export interface SimStateData { 277 type: CardType; 278 state: SimState; 279 /** 280 * @since 8 281 */ 282 reason: LockReason; 283 } 284 285 /** 286 * @since 8 287 */ 288 export enum LockReason { 289 SIM_NONE, 290 SIM_PIN, 291 SIM_PUK, 292 SIM_PN_PIN, //Network Personalization (refer 3GPP TS 22.022 [33]) 293 SIM_PN_PUK, 294 SIM_PU_PIN, //Network Subset Personalization (refer 3GPP TS 22.022 [33]) 295 SIM_PU_PUK, 296 SIM_PP_PIN, //Service Provider Personalization (refer 3GPP TS 22.022 [33]) 297 SIM_PP_PUK, 298 SIM_PC_PIN, //Corporate Personalization (refer 3GPP TS 22.022 [33]) 299 SIM_PC_PUK, 300 SIM_SIM_PIN, //SIM/USIM Personalization (refer 3GPP TS 22.022 [33]) 301 SIM_SIM_PUK, 302 } 303} 304 305export default observer;