1 /*
2  * Copyright (C) 2021 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 #ifndef TELEPHONY_OBSERVER_H
17 #define TELEPHONY_OBSERVER_H
18 
19 #include <cstdint>
20 #include <string>
21 #include <vector>
22 
23 #include "iremote_stub.h"
24 
25 #include "telephony_observer_broker.h"
26 
27 namespace OHOS {
28 namespace Telephony {
29 class TelephonyObserver : public IRemoteStub<TelephonyObserverBroker> {
30 public:
31     TelephonyObserver();
32     ~TelephonyObserver();
33 
34     /**
35      * @brief Called when call state is updated.
36      *
37      * @param slotId Indicates the slot identification.
38      * @param callState Indicates the call state.
39      * @param phoneNumber Indicates the phoneNumber.
40      */
41     void OnCallStateUpdated(
42         int32_t slotId, int32_t callState, const std::u16string &phoneNumber) override;
43 
44     /**
45      * @brief Called when signal info is updated.
46      *
47      * @param slotId Indicates the slot identification.
48      * @param vec Indicates the signal information lists.
49      */
50     void OnSignalInfoUpdated(
51         int32_t slotId, const std::vector<sptr<SignalInformation>> &vec) override;
52 
53     /**
54      * @brief Called when network state is updated.
55      *
56      * @param slotId Indicates the slot identification.
57      * @param networkState Indicates the NetworkState.
58      */
59     void OnNetworkStateUpdated(
60         int32_t slotId, const sptr<NetworkState> &networkState) override;
61 
62     /**
63      * @brief Called when cell info is updated.
64      *
65      * @param slotId Indicates the slot identification.
66      * @param vec Indicates the cell information list.
67      */
68     void OnCellInfoUpdated(
69         int32_t slotId, const std::vector<sptr<CellInformation>> &vec) override;
70 
71     /**
72      * @brief Called when sim state is updated.
73      *
74      * @param slotId Indicates the slot identification.
75      * @param type Indicates the type of sim card.
76      * @param state Indicates the sim state.
77      * @param reason Indicates the sim lock reason.
78      */
79     void OnSimStateUpdated(
80         int32_t slotId, CardType type, SimState state, LockReason reason) override;
81 
82     /**
83      * @brief Called when cellular data connect state is updated.
84      *
85      * @param slotId Indicates the slot identification.
86      * @param dataState Indicates the cellular data state.
87      * @param networkType Indicates the network type.
88      */
89     void OnCellularDataConnectStateUpdated(
90         int32_t slotId, int32_t dataState, int32_t networkType) override;
91 
92     /**
93      * @brief Called when cellular data flow type is updated.
94      *
95      * @param slotId Indicates the slot identification.
96      * @param dataFlowType Indicates the data flow type.
97      */
98     void OnCellularDataFlowUpdated(
99         int32_t slotId, int32_t dataFlowType) override;
100 
101     /**
102      * @brief Called when CFU(Call Forwarding Unconditional) indicator updated.
103      *
104      * @param slotId Indicates the slot identification.
105      * @param cfuResult Indicates whether support CFU, true if support, false if
106      * not.
107      */
108     virtual void OnCfuIndicatorUpdated(int32_t slotId, bool cfuResult) override;
109 
110     /**
111      * @brief Called when the voice mailbox state corresponding to the monitored slotId
112      * is updated.
113      *
114      * @param slotId Indicates the slot identification.
115      * @param voiceMailMsgResult Indicates the result of voice mail message,
116      * true if success, false if not.
117      */
118     virtual void OnVoiceMailMsgIndicatorUpdated(int32_t slotId, bool voiceMailMsgResult) override;
119     int32_t OnRemoteRequest(
120         uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override;
121     virtual void OnIccAccountUpdated() override;
122 
123 private:
124     using TelephonyObserverFunc = std::function<void(MessageParcel &data, MessageParcel &reply)>;
125 
126     void ConvertSignalInfoList(MessageParcel &data, std::vector<sptr<SignalInformation>> &signalInfos);
127     void ConvertLteNrSignalInfoList(
128         MessageParcel &data, std::vector<sptr<SignalInformation>> &signalInfos, SignalInformation::NetworkType type);
129     void ConvertCellInfoList(MessageParcel &data, std::vector<sptr<CellInformation>> &cells);
130     void OnCallStateUpdatedInner(MessageParcel &data, MessageParcel &reply);
131     void OnSignalInfoUpdatedInner(MessageParcel &data, MessageParcel &reply);
132     void OnNetworkStateUpdatedInner(MessageParcel &data, MessageParcel &reply);
133     void OnCellInfoUpdatedInner(MessageParcel &data, MessageParcel &reply);
134     void OnSimStateUpdatedInner(MessageParcel &data, MessageParcel &reply);
135     void OnCellularDataConnectStateUpdatedInner(MessageParcel &data, MessageParcel &reply);
136     void OnCellularDataFlowUpdatedInner(MessageParcel &data, MessageParcel &reply);
137     void OnCfuIndicatorUpdatedInner(MessageParcel &data, MessageParcel &reply);
138     void OnVoiceMailMsgIndicatorUpdatedInner(MessageParcel &data, MessageParcel &reply);
139     void OnIccAccountUpdatedInner(MessageParcel &data, MessageParcel &reply);
140     static constexpr int32_t CELL_NUM_MAX = 100;
141     static constexpr int32_t SIGNAL_NUM_MAX = 100;
142     std::map<uint32_t, TelephonyObserverFunc> memberFuncMap_;
143 };
144 } // namespace Telephony
145 } // namespace OHOS
146 #endif // TELEPHONY_OBSERVER_H
147