• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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   */
52  function on(type: 'networkStateChange', callback: Callback<NetworkState>): void;
53  function on(type: 'networkStateChange', options: { slotId: number }, callback: Callback<NetworkState>): void;
54
55  function off(type: 'networkStateChange', callback?: Callback<NetworkState>): void;
56
57  /**
58   * Called when the signal strength corresponding to a monitored {@code slotId} updates.
59   *
60   * @param type signalInfoChange
61   * @param options including slotId Indicates the ID of the target card slot.
62   *   The value {@code 0} indicates card 1, and the value {@code 1} indicates card 2.
63   * @param callback including an array of instances of the classes derived from {@link SignalInformation}.
64   */
65  function on(type: 'signalInfoChange', callback: Callback<Array<SignalInformation>>): void;
66  function on(type: 'signalInfoChange', options: { slotId: number },
67    callback: Callback<Array<SignalInformation>>): void;
68
69  function off(type: 'signalInfoChange', callback?: Callback<Array<SignalInformation>>): void;
70
71  /**
72   * Called back when the cell information corresponding to a monitored {@code slotId} updates.
73   *
74   * @param type cellInfoChange
75   * @param options including slotId Indicates the ID of the target card slot.
76   *   The value {@code 0} indicates card 1, and the value {@code 1} indicates card 2.
77   * @param callback including an array of instances of the classes derived from {@link CellInformation}.
78   * @permission ohos.permission.LOCATION
79   * @systemapi Hide this for inner system use.
80   * @since 8
81   */
82  function on(type: 'cellInfoChange', callback: Callback<Array<CellInformation>>): void;
83  function on(type: 'cellInfoChange', options: { slotId: number },
84    callback: Callback<Array<CellInformation>>): void;
85
86  /**
87   * @systemapi Hide this for inner system use.
88   * @since 8
89   */
90  function off(type: 'cellInfoChange', callback?: Callback<Array<CellInformation>>): void;
91
92  /**
93   * Called when the cellular data link connection state updates.
94   *
95   * @param type cellularDataConnectionStateChange
96   * @param options including slotId Indicates the ID of the target card slot.
97   *   The value {@code 0} indicates card 1, and the value {@code 1} indicates card 2.
98   * @param callback including state Indicates the cellular data link connection state,
99   *   and networkType Indicates the radio access technology for cellular data services.
100   * @since 7
101   */
102  function on(type: 'cellularDataConnectionStateChange',
103    callback: Callback<{ state: DataConnectState, network: RatType }>): void;
104  function on(type: 'cellularDataConnectionStateChange', options: { slotId: number },
105    callback: Callback<{ state: DataConnectState, network: RatType }>): void;
106
107  /**
108   * @since 7
109   */
110  function off(type: 'cellularDataConnectionStateChange',
111    callback?: Callback<{ state: DataConnectState, network: RatType }>): void;
112
113  /**
114   * Called when the uplink and downlink data flow state of cellular data services updates.
115   *
116   * @param type cellularDataFlowChange
117   * @param options including slotId Indicates the ID of the target card slot.
118   *   The value {@code 0} indicates card 1, and the value {@code 1} indicates card 2.
119   * @param callback including the cellular data flow state.
120   * @since 7
121   */
122  function on(type: 'cellularDataFlowChange', callback: Callback<DataFlowType>): void;
123  function on(type: 'cellularDataFlowChange', options: { slotId: number },
124    callback: Callback<DataFlowType>): void;
125
126  /**
127   * @since 7
128   */
129  function off(type: 'cellularDataFlowChange', callback?: Callback<DataFlowType>): void;
130
131  /**
132   * Receives a call state change. This callback is invoked when the call state of a specified card updates
133   * and the observer is added to monitor the updates.
134   *
135   * @param type callStateChange
136   * @param options including slotId Indicates the ID of the target card slot.
137   *   The value {@code 0} indicates card 1, and the value {@code 1} indicates card 2.
138   * @param callback including state Indicates the call state, and number Indicates the called number.
139   *   The value of number is an empty string if the application does not have
140   *     the ohos.permission.READ_CALL_LOG permission.
141   */
142  function on(type: 'callStateChange', callback: Callback<{ state: CallState, number: string }>): void;
143  function on(type: 'callStateChange', options: { slotId: number },
144    callback: Callback<{ state: CallState, number: string }>): void;
145
146  function off(type: 'callStateChange', callback?: Callback<{ state: CallState, number: string }>): void;
147
148  /**
149   * Receives a sim state change. This callback is invoked when the sim state of a specified card updates
150   * and the observer is added to monitor the updates.
151   *
152   * @param type simStateChange
153   * @param options including slotId Indicates the ID of the target card slot.
154   *   The value {@code 0} indicates card 1, and the value {@code 1} indicates card 2.
155   * @param callback including state Indicates the sim state, and reason Indicates the cause of the change.
156   *   The value of reason is an empty string if the application does not have
157   * @since 7
158   */
159  function on(type: 'simStateChange', callback: Callback<SimStateData>): void;
160  function on(type: 'simStateChange', options: { slotId: number }, callback: Callback<SimStateData>): void;
161
162  /**
163   * @since 7
164   */
165  function off(type: 'simStateChange', callback?: Callback<SimStateData>): void;
166
167  /**
168   * @since 7
169   */
170  export interface SimStateData {
171    type: CardType;
172    state: SimState;
173    /**
174     * @since 8
175     */
176    reason: LockReason;
177  }
178
179  /**
180   * @since 8
181   */
182  export enum LockReason {
183    SIM_NONE,
184    SIM_PIN,
185    SIM_PUK,
186    SIM_PN_PIN, //Network Personalization (refer 3GPP TS 22.022 [33])
187    SIM_PN_PUK,
188    SIM_PU_PIN, //network sUbset Personalization (refer 3GPP TS 22.022 [33])
189    SIM_PU_PUK,
190    SIM_PP_PIN, //service Provider Personalization (refer 3GPP TS 22.022 [33])
191    SIM_PP_PUK,
192    SIM_PC_PIN, //Corporate Personalization (refer 3GPP TS 22.022 [33])
193    SIM_PC_PUK,
194    SIM_SIM_PIN, //SIM/USIM personalisation (refer 3GPP TS 22.022 [33])
195    SIM_SIM_PUK,
196  }
197}
198
199export default observer;