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_STATE_REGISTRY_CLIENT_H
17 #define TELEPHONY_STATE_REGISTRY_CLIENT_H
18 
19 #include <cstdint>
20 #include <iremote_object.h>
21 #include <singleton.h>
22 
23 #include "i_telephony_state_notify.h"
24 
25 namespace OHOS {
26 namespace Telephony {
27 class TelephonyStateRegistryClient : public DelayedRefSingleton<TelephonyStateRegistryClient> {
28     DECLARE_DELAYED_REF_SINGLETON(TelephonyStateRegistryClient);
29 
30 public:
31     /**
32      * @brief Update cellular data connect state
33      *
34      * @param slotId sim slot id
35      * @param dataState cellular data link state
36      * @param networkState network state
37      * @return int32_t TELEPHONY_SUCCESS on success, others on failure.
38      */
39     int32_t UpdateCellularDataConnectState(int32_t slotId, int32_t dataState, int32_t networkState);
40     /**
41      * @brief Update call state
42      *
43      * @param callStatus call status
44      * @param number call number
45      * @return int32_t TELEPHONY_SUCCESS on success, others on failure.
46      */
47     int32_t UpdateCallState(int32_t callStatus, const std::u16string &number);
48     /**
49      * @brief Update call state for slotId
50      *
51      * @param slotId sim slot id
52      * @param callStatus call status
53      * @param number incoming number
54      * @return int32_t TELEPHONY_SUCCESS on success, others on failure.
55      */
56     int32_t UpdateCallStateForSlotId(
57         int32_t slotId, int32_t callStatus, const std::u16string &number);
58     /**
59      * @brief Update signal information
60      *
61      * @param slotId sim slot id
62      * @param vec networkType search signal information
63      * @return int32_t TELEPHONY_SUCCESS on success, others on failure.
64      */
65     int32_t UpdateSignalInfo(int32_t slotId, const std::vector<sptr<SignalInformation>> &vec);
66     /**
67      * @brief Update cell information
68      *
69      * @param slotId sim slot id
70      * @param vec cell info
71      * @return int32_t TELEPHONY_NO_ERROR on success, others on failure.
72      */
73     int32_t UpdateCellInfo(int32_t slotId, const std::vector<sptr<CellInformation>> &vec);
74     /**
75      * @brief Update network state
76      *
77      * @param slotId sim slot id
78      * @param networkStatus network status
79      * @return int32_t TELEPHONY_SUCCESS on success, others on failure.
80      */
81     int32_t UpdateNetworkState(int32_t slotId, const sptr<NetworkState> &networkState);
82     /**
83      * @brief Update sim state
84      *
85      * @param slotId sim slot id
86      * @param CardType sim card type
87      * @param state sim state
88      * @param reason Indicates the reason of update sim state
89      * @return int32_t TELEPHONY_SUCCESS on success, others on failure.
90      */
91     int32_t UpdateSimState(int32_t slotId, CardType type, SimState state, LockReason reason);
92     /**
93      * @brief Update cellular data flow
94      *
95      * @param slotId sim slot id
96      * @param dataFlowType cellular data flow state
97      * @return int32_t TELEPHONY_SUCCESS on success, others on failure.
98      */
99     int32_t UpdateCellularDataFlow(int32_t slotId, int32_t flowType);
100     /**
101      * @brief Update call forward unconditionally indicator
102      *
103      * @param slotId sim slot id
104      * @param cfuResult set the result of call forwarding
105      * @return int32_t TELEPHONY_SUCCESS on success, others on failure.
106      */
107     int32_t UpdateCfuIndicator(int32_t slotId, bool cfuResult);
108     /**
109      * @brief Update voice mail message indicator
110      *
111      * @param slotId sim slot id
112      * @param voiceMailMsgResult voice mail message indicator
113      * @return int32_t TELEPHONY_SUCCESS on success, others on failure.
114      */
115     int32_t UpdateVoiceMailMsgIndicator(int32_t slotId, bool voiceMailMsgResult);
116     int32_t UpdateIccAccount();
117     sptr<ITelephonyStateNotify> GetProxy();
118 
119 private:
120     class StateRegistryDeathRecipient : public IRemoteObject::DeathRecipient {
121     public:
StateRegistryDeathRecipient(TelephonyStateRegistryClient & client)122         explicit StateRegistryDeathRecipient(TelephonyStateRegistryClient &client) : client_(client) {}
123         ~StateRegistryDeathRecipient() override = default;
OnRemoteDied(const wptr<IRemoteObject> & remote)124         void OnRemoteDied(const wptr<IRemoteObject> &remote) override
125         {
126             client_.OnRemoteDied(remote);
127         }
128 
129     private:
130         TelephonyStateRegistryClient &client_;
131     };
132 
133     void OnRemoteDied(const wptr<IRemoteObject> &remote);
134 
135 private:
136     std::mutex mutexProxy_;
137     sptr<ITelephonyStateNotify> proxy_ {nullptr};
138     sptr<IRemoteObject::DeathRecipient> deathRecipient_ {nullptr};
139 };
140 } // namespace Telephony
141 } // namespace OHOS
142 #endif // TELEPHONY_STATE_REGISTRY_CLIENT_H
143