• 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 
16 #ifndef TEL_RIL_MANAGER_H
17 #define TEL_RIL_MANAGER_H
18 
19 #include <singleton.h>
20 #include <v1_2/iril.h>
21 
22 #include "hdf_service_status_listener.h"
23 #include "i_tel_ril_manager.h"
24 #include "tel_ril_call.h"
25 #include "tel_ril_data.h"
26 #include "tel_ril_handler.h"
27 #include "tel_ril_modem.h"
28 #include "tel_ril_network.h"
29 #include "tel_ril_sim.h"
30 #include "tel_ril_sms.h"
31 
32 namespace OHOS {
33 namespace Telephony {
34 class TelRilManager : public ITelRilManager, public std::enable_shared_from_this<TelRilManager> {
35 public:
36     TelRilManager();
37     ~TelRilManager() override = default;
38 
39     bool OnInit() override;
40     bool DeInit();
41 
42     int32_t RegisterCoreNotify(
43         int32_t slotId, const std::shared_ptr<AppExecFwk::EventHandler> &handler, int32_t what, int32_t *obj) override;
44     int32_t UnRegisterCoreNotify(
45         int32_t slotId, const std::shared_ptr<AppExecFwk::EventHandler> &observerCallBack, int32_t what) override;
46 
47     int32_t SetRadioState(
48         int32_t slotId, int32_t fun, int32_t rst, const AppExecFwk::InnerEvent::Pointer &response) override;
49     int32_t GetRadioState(int32_t slotId, const AppExecFwk::InnerEvent::Pointer &response) override;
50 
51     int32_t ShutDown(int32_t slotId, const AppExecFwk::InnerEvent::Pointer &response) override;
52 
53     int32_t GetCallList(int32_t slotId, const AppExecFwk::InnerEvent::Pointer &result) override;
54 
55     int32_t Dial(
56         int32_t slotId, std::string address, int32_t clirMode, const AppExecFwk::InnerEvent::Pointer &result) override;
57 
58     int32_t Reject(int32_t slotId, const AppExecFwk::InnerEvent::Pointer &result) override;
59 
60     int32_t Hangup(int32_t slotId, int32_t gsmIndex, const AppExecFwk::InnerEvent::Pointer &result) override;
61 
62     int32_t Answer(int32_t slotId, const AppExecFwk::InnerEvent::Pointer &result) override;
63 
64     int32_t HoldCall(int32_t slotId, const AppExecFwk::InnerEvent::Pointer &result) override;
65 
66     int32_t UnHoldCall(int32_t slotId, const AppExecFwk::InnerEvent::Pointer &result) override;
67 
68     int32_t SwitchCall(int32_t slotId, const AppExecFwk::InnerEvent::Pointer &result) override;
69 
70     int32_t CombineConference(int32_t slotId, int32_t callType, const AppExecFwk::InnerEvent::Pointer &result) override;
71 
72     int32_t SeparateConference(
73         int32_t slotId, int32_t callIndex, int32_t callType, const AppExecFwk::InnerEvent::Pointer &result) override;
74 
75     int32_t CallSupplement(int32_t slotId, int32_t type, const AppExecFwk::InnerEvent::Pointer &result) override;
76 
77     int32_t GetCallWaiting(int32_t slotId, const AppExecFwk::InnerEvent::Pointer &result) override;
78 
79     int32_t SetCallWaiting(
80         int32_t slotId, const int32_t activate, const AppExecFwk::InnerEvent::Pointer &result) override;
81 
82     int32_t GetCallTransferInfo(
83         int32_t slotId, const int32_t reason, const AppExecFwk::InnerEvent::Pointer &result) override;
84 
85     int32_t SetCallTransferInfo(
86         int32_t slotId, const CallTransferParam &callTransfer, const AppExecFwk::InnerEvent::Pointer &result) override;
87 
88     int32_t GetClip(int32_t slotId, const AppExecFwk::InnerEvent::Pointer &result) override;
89 
90     int32_t SetClip(int32_t slotId, const int32_t action, const AppExecFwk::InnerEvent::Pointer &result) override;
91 
92     int32_t GetClir(int32_t slotId, const AppExecFwk::InnerEvent::Pointer &result) override;
93 
94     int32_t SetClir(int32_t slotId, const int32_t action, const AppExecFwk::InnerEvent::Pointer &result) override;
95 
96     int32_t GetCallRestriction(int32_t slotId, std::string fac, const AppExecFwk::InnerEvent::Pointer &result) override;
97 
98     int32_t SetCallRestriction(int32_t slotId, const CallRestrictionParam &callRestriction,
99         const AppExecFwk::InnerEvent::Pointer &result) override;
100 
101     int32_t SetBarringPassword(int32_t slotId, const char *oldPassword, const char *newPassword,
102         const std::string &restrictionType, const AppExecFwk::InnerEvent::Pointer &response) override;
103 
104     int32_t SetVoNRSwitch(int32_t slotId, int32_t state, const AppExecFwk::InnerEvent::Pointer &result) override;
105 
106     int32_t SendDtmf(
107         int32_t slotId, const DtmfParam &dtmfParam, const AppExecFwk::InnerEvent::Pointer &result) override;
108     int32_t SendDtmf(
109         int32_t slotId, char cDTMFCode, int32_t index, const AppExecFwk::InnerEvent::Pointer &result) override;
110     int32_t StartDtmf(
111         int32_t slotId, char cDTMFCode, int32_t index, const AppExecFwk::InnerEvent::Pointer &result) override;
112     int32_t StopDtmf(int32_t slotId, int32_t index, const AppExecFwk::InnerEvent::Pointer &result) override;
113 
114     int32_t GetSignalStrength(int32_t slotId, const AppExecFwk::InnerEvent::Pointer &response) override;
115 
116     int32_t GetCsRegStatus(int32_t slotId, const AppExecFwk::InnerEvent::Pointer &response) override;
117 
118     int32_t GetPsRegStatus(int32_t slotId, const AppExecFwk::InnerEvent::Pointer &response) override;
119 
120     int32_t GetOperatorInfo(int32_t slotId, const AppExecFwk::InnerEvent::Pointer &response) override;
121 
122     int32_t GetCellInfoList(int32_t slotId, const AppExecFwk::InnerEvent::Pointer &response) override;
123 
124     int32_t GetCurrentCellInfo(int32_t slotId, const AppExecFwk::InnerEvent::Pointer &response) override;
125 
126     int32_t GetImei(int32_t slotId, const AppExecFwk::InnerEvent::Pointer &response) override;
127 
128     int32_t GetMeid(int32_t slotId, const AppExecFwk::InnerEvent::Pointer &response) override;
129 
130     int32_t GetVoiceRadioTechnology(int32_t slotId, const AppExecFwk::InnerEvent::Pointer &response) override;
131 
132     int32_t GetPhysicalChannelConfig(int32_t slotId, const AppExecFwk::InnerEvent::Pointer &response) override;
133 
134     int32_t SetLocateUpdates(
135         int32_t slotId, HRilRegNotifyMode mode, const AppExecFwk::InnerEvent::Pointer &response) override;
136 
137     /**
138      * @param slotId is the card slot index number
139      * @param newFilter is the notification filter with bits in HRilNotificationFilter
140      * @param response is the feedback info after setting notification filter
141      * @return int32_t Indicates if notification filter is set successfully
142      */
143     int32_t SetNotificationFilter(
144         int32_t slotId, int32_t newFilter, const AppExecFwk::InnerEvent::Pointer &response) override;
145 
146     /**
147      * @param slotId is the card slot index number
148      * @param deviceStateType is the device state type in HRilDeviceStateType
149      * @param deviceStateOn Indicates the specific device state is on
150      * @param response is the feedback info after setting device state
151      * @return int32_t Indicates if device state is set successfully
152      */
153     int32_t SetDeviceState(int32_t slotId, int32_t deviceStateType, bool deviceStateOn,
154         const AppExecFwk::InnerEvent::Pointer &response) override;
155 
156     int32_t GetBasebandVersion(int32_t slotId, const AppExecFwk::InnerEvent::Pointer &response) override;
157 
158     int32_t SetNrOptionMode(int32_t slotId, int32_t mode, const AppExecFwk::InnerEvent::Pointer &response) override;
159 
160     int32_t GetNrOptionMode(int32_t slotId, const AppExecFwk::InnerEvent::Pointer &response) override;
161 
162     int32_t GetRrcConnectionState(int32_t slotId, const AppExecFwk::InnerEvent::Pointer &response) override;
163 
164     int32_t GetNrSsbId(int32_t slotId, const AppExecFwk::InnerEvent::Pointer &response) override;
165 
166     int32_t SendGsmSms(
167         int32_t slotId, std::string smscPdu, std::string pdu, const AppExecFwk::InnerEvent::Pointer &response) override;
168 
169     int32_t SendCdmaSms(int32_t slotId, std::string pdu, const AppExecFwk::InnerEvent::Pointer &response) override;
170 
171     int32_t AddSimMessage(
172         int32_t slotId, const SimMessageParam &simMessage, const AppExecFwk::InnerEvent::Pointer &response) override;
173 
174     int32_t DelSimMessage(int32_t slotId, int32_t gsmIndex, const AppExecFwk::InnerEvent::Pointer &response) override;
175 
176     int32_t UpdateSimMessage(
177         int32_t slotId, const SimMessageParam &simMessage, const AppExecFwk::InnerEvent::Pointer &response) override;
178 
179     int32_t GetSmscAddr(int32_t slotId, const AppExecFwk::InnerEvent::Pointer &response) override;
180 
181     int32_t GetCdmaCBConfig(int32_t slotId, const AppExecFwk::InnerEvent::Pointer &response) override;
182 
183     int32_t SetSmscAddr(
184         int32_t slotId, int32_t tosca, std::string address, const AppExecFwk::InnerEvent::Pointer &response) override;
185 
186     int32_t SetCBConfig(
187         int32_t slotId, const CBConfigParam &cbConfig, const AppExecFwk::InnerEvent::Pointer &response) override;
188 
189     int32_t SetCdmaCBConfig(int32_t slotId, CdmaCBConfigInfoList &cdmaCBConfigInfoList,
190         const AppExecFwk::InnerEvent::Pointer &response) override;
191 
192     int32_t GetCBConfig(int32_t slotId, const AppExecFwk::InnerEvent::Pointer &result) override;
193 
194     int32_t SendSmsMoreMode(
195         int32_t slotId, std::string smscPdu, std::string pdu, const AppExecFwk::InnerEvent::Pointer &response) override;
196 
197     int32_t SendSmsAck(
198         int32_t slotId, bool success, int32_t cause, const AppExecFwk::InnerEvent::Pointer &response) override;
199     int32_t AddCdmaSimMessage(
200         int32_t slotId, int32_t status, std::string pdu, const AppExecFwk::InnerEvent::Pointer &response) override;
201     int32_t DelCdmaSimMessage(
202         int32_t slotId, int32_t cdmaIndex, const AppExecFwk::InnerEvent::Pointer &response) override;
203     int32_t UpdateCdmaSimMessage(int32_t slotId, const CdmaSimMessageParam &cdmaSimMsg,
204         const AppExecFwk::InnerEvent::Pointer &response) override;
205 
206     int32_t SetInitApnInfo(
207         int32_t slotId, const DataProfile &dataProfile, const AppExecFwk::InnerEvent::Pointer &response) override;
208     int32_t ActivatePdpContext(
209         int32_t slotId, const ActivateDataParam &activeData, const AppExecFwk::InnerEvent::Pointer &response) override;
210     int32_t DeactivatePdpContext(
211         int32_t slotId, int32_t cid, int32_t reason, const AppExecFwk::InnerEvent::Pointer &response) override;
212     int32_t GetPdpContextList(int32_t slotId, const AppExecFwk::InnerEvent::Pointer &response) override;
213     int32_t GetLinkBandwidthInfo(
214         int32_t slotId, const int32_t cid, const AppExecFwk::InnerEvent::Pointer &response) override;
215     int32_t SetLinkBandwidthReportingRule(
216         int32_t slotId, LinkBandwidthRule linkBandwidth, const AppExecFwk::InnerEvent::Pointer &response) override;
217     int32_t SetDataPermitted(
218         int32_t slotId, int32_t dataPermitted, const AppExecFwk::InnerEvent::Pointer &response) override;
219     int32_t GetLinkCapability(int32_t slotId, const AppExecFwk::InnerEvent::Pointer &response) override;
220     int32_t CleanAllConnections(int32_t slotId, const AppExecFwk::InnerEvent::Pointer &response) override;
221 
222     int32_t GetSimStatus(int32_t slotId, const AppExecFwk::InnerEvent::Pointer &result) override;
223     int32_t GetSimIO(int32_t slotId, SimIoRequestInfo data, const AppExecFwk::InnerEvent::Pointer &response) override;
224     int32_t GetImsi(int32_t slotId, const AppExecFwk::InnerEvent::Pointer &result) override;
225     int32_t GetSimLockStatus(int32_t slotId, std::string fac, const AppExecFwk::InnerEvent::Pointer &result) override;
226     int32_t SetSimLock(
227         int32_t slotId, const SimLockParam &simLock, const AppExecFwk::InnerEvent::Pointer &result) override;
228     int32_t ChangeSimPassword(
229         int32_t slotId, const SimPasswordParam &simPassword, const AppExecFwk::InnerEvent::Pointer &result) override;
230     int32_t UnlockPin(int32_t slotId, const std::string &pin, const AppExecFwk::InnerEvent::Pointer &result) override;
231     int32_t UnlockPuk(int32_t slotId, const std::string &puk, const std::string &pin,
232         const AppExecFwk::InnerEvent::Pointer &result) override;
233     int32_t UnlockPin2(int32_t slotId, const std::string &pin2, const AppExecFwk::InnerEvent::Pointer &result) override;
234     int32_t UnlockPuk2(int32_t slotId, const std::string &puk2, const std::string &pin2,
235         const AppExecFwk::InnerEvent::Pointer &result) override;
236     int32_t SetActiveSim(
237         int32_t slotId, int32_t index, int32_t enable, const AppExecFwk::InnerEvent::Pointer &result) override;
238     int32_t SendTerminalResponseCmd(
239         int32_t slotId, const std::string &strCmd, const AppExecFwk::InnerEvent::Pointer &response) override;
240     int32_t SendEnvelopeCmd(
241         int32_t slotId, const std::string &strCmd, const AppExecFwk::InnerEvent::Pointer &response) override;
242     int32_t SendCallSetupRequestResult(
243         int32_t slotId, bool accept, const AppExecFwk::InnerEvent::Pointer &response) override;
244     int32_t SimStkIsReady(int32_t slotId, const AppExecFwk::InnerEvent::Pointer &response) override;
245     int32_t UnlockSimLock(int32_t slotId, int32_t lockType, std::string password,
246         const AppExecFwk::InnerEvent::Pointer &response) override;
247     int32_t GetRadioProtocol(int32_t slotId, const AppExecFwk::InnerEvent::Pointer &response) override;
248     int32_t SetRadioProtocol(
249         int32_t slotId, RadioProtocol radioProtocol, const AppExecFwk::InnerEvent::Pointer &response) override;
250 
251     int32_t GetNetworkSearchInformation(int32_t slotId, const AppExecFwk::InnerEvent::Pointer &result) override;
252     int32_t GetNetworkSelectionMode(int32_t slotId, const AppExecFwk::InnerEvent::Pointer &result) override;
253     int32_t SetNetworkSelectionMode(int32_t slotId, int32_t automaticFlag, std::string oper,
254         const AppExecFwk::InnerEvent::Pointer &result) override;
255     int32_t SetPreferredNetwork(
256         int32_t slotId, int32_t preferredNetworkType, const AppExecFwk::InnerEvent::Pointer &response) override;
257     int32_t GetPreferredNetwork(int32_t slotId, const AppExecFwk::InnerEvent::Pointer &response) override;
258 
259     int32_t SetCallPreferenceMode(
260         int32_t slotId, const int32_t mode, const AppExecFwk::InnerEvent::Pointer &response) override;
261     int32_t GetCallPreferenceMode(int32_t slotId, const AppExecFwk::InnerEvent::Pointer &response) override;
262     int32_t SetUssd(int32_t slotId, const std::string str, const AppExecFwk::InnerEvent::Pointer &response) override;
263     int32_t GetUssd(int32_t slotId, const AppExecFwk::InnerEvent::Pointer &response) override;
264     int32_t SetMute(int32_t slotId, const int32_t mute, const AppExecFwk::InnerEvent::Pointer &response) override;
265     int32_t GetMute(int32_t slotId, const AppExecFwk::InnerEvent::Pointer &response) override;
266     int32_t GetEmergencyCallList(int32_t slotId, const AppExecFwk::InnerEvent::Pointer &response) override;
267     int32_t SetEmergencyCallList(int32_t slotId, const std::vector<EmergencyCall> &eccVec,
268         const AppExecFwk::InnerEvent::Pointer &response) override;
269     int32_t GetCallFailReason(int32_t slotId, const AppExecFwk::InnerEvent::Pointer &response) override;
270     int32_t SimOpenLogicalChannel(int32_t slotId, const std::string &appID, const int32_t p2,
271         const AppExecFwk::InnerEvent::Pointer &response) override;
272     int32_t SimCloseLogicalChannel(
273         int32_t slotId, const int32_t channelId, const AppExecFwk::InnerEvent::Pointer &response) override;
274     int32_t SimTransmitApduLogicalChannel(
275         int32_t slotId, const ApduSimIORequestInfo &reqInfo, const AppExecFwk::InnerEvent::Pointer &response) override;
276     int32_t SimTransmitApduBasicChannel(
277         int32_t slotId, const ApduSimIORequestInfo &reqInfo, const AppExecFwk::InnerEvent::Pointer &response) override;
278     int32_t SimAuthentication(int32_t slotId, const SimAuthenticationRequestInfo &reqInfo,
279         const AppExecFwk::InnerEvent::Pointer &response) override;
280     int32_t SendSimMatchedOperatorInfo(int32_t slotId, const NcfgOperatorInfo &reqInfo,
281         const AppExecFwk::InnerEvent::Pointer &response) override;
282     int32_t CloseUnFinishedUssd(int32_t slotId, const AppExecFwk::InnerEvent::Pointer &response) override;
283 
284     /**
285      * Register hdf status listener
286      *
287      * @return:True is Register HdfStatusListener success, false is fail
288      */
289     bool RegisterHdfStatusListener();
290 
291     /**
292      * UnRegister hdf status listener
293      *
294      * @return:True is UnRegister HdfStatusListener success, false is fail
295      */
296     bool UnRegisterHdfStatusListener();
297 
298     std::shared_ptr<TelRilSms> GetTelRilSms(int32_t slotId);
299     std::shared_ptr<TelRilSim> GetTelRilSim(int32_t slotId);
300     std::shared_ptr<TelRilCall> GetTelRilCall(int32_t slotId);
301     std::shared_ptr<TelRilData> GetTelRilData(int32_t slotId);
302     std::shared_ptr<TelRilNetwork> GetTelRilNetwork(int32_t slotId);
303     std::shared_ptr<TelRilModem> GetTelRilModem(int32_t slotId);
304     void SendAckAndLock(void);
305     void ReduceRunningLock();
306     void ReleaseRunningLock();
307 
308 public:
309     static const int32_t INVALID_WAKELOCK = -1;
310     static const int32_t FOR_WAKELOCK = 0;
311     static const int32_t FOR_ACK_WAKELOCK = 1;
312 
313 private:
314     void CreatTelRilHandler(void);
315     int32_t SendResponseAck(void);
316     void InitTelModule(int32_t slotId);
317     bool ConnectRilInterface();
318     bool ResetRilInterface(void);
319     void HandleRilInterfaceStatusCallback(const OHOS::HDI::ServiceManager::V1_0::ServiceStatus &status);
320     bool ReConnectRilInterface();
321     bool DisConnectRilInterface();
322 
323     std::shared_ptr<ObserverHandler> GetObserverHandler(int32_t slotId);
324 
325     /**
326      * @brief Task schedule. The function of this function is to unify the input interface.
327      * @param _result response handler
328      * @param _module Sub module identification, used to print logs.
329      *   This header file cannot use the typeid() keyword, so the module name is passed in.
330      * @param template: _obj - Object type (this)pointer.
331      * @param template: _func - Class member function address.
332      * @param template: _args - The parameter list of the class member function except the response parameter.
333      *    The number can vary.
334      * @return true/false - success/fail
335      */
336     template<typename ResponsePtr, typename ClassTypePtr, typename FuncType, typename... ParamTypes>
TaskSchedule(ResponsePtr & _result,const std::string _module,ClassTypePtr _obj,FuncType && _func,ParamTypes &&..._args)337     inline int32_t TaskSchedule(ResponsePtr &_result, const std::string _module, ClassTypePtr _obj, FuncType &&_func,
338         ParamTypes &&... _args) const
339     {
340         if (_func != nullptr && _obj != nullptr) {
341             // The reason for using native member function access here is to
342             //   remove std::unique_ptr to prevent copying.
343             // The reason for not directly using pointers to access member functions is:
344             //   _obj is a smart pointer, not a native pointer.
345             return (_obj.get()->*(_func))(std::forward<ParamTypes>(_args)..., _result);
346         } else {
347             TELEPHONY_LOGE("%{public}s - func: %{public}s", _module.c_str(), "null pointer");
348             return HRIL_ERR_NULL_POINT;
349         }
350     }
351 
352 private:
353     std::mutex mutex_;
354     std::vector<std::shared_ptr<TelRilSim>> telRilSim_;
355     std::vector<std::shared_ptr<TelRilSms>> telRilSms_;
356     std::vector<std::shared_ptr<TelRilCall>> telRilCall_;
357     std::vector<std::shared_ptr<TelRilData>> telRilData_;
358     std::vector<std::shared_ptr<TelRilModem>> telRilModem_;
359     std::vector<std::shared_ptr<TelRilNetwork>> telRilNetwork_;
360     std::vector<std::shared_ptr<ObserverHandler>> observerHandler_;
361     std::shared_ptr<TelRilHandler> handler_ = nullptr;
362     sptr<OHOS::HDI::ServiceManager::V1_0::IServiceManager> servMgr_ = nullptr;
363     sptr<HdfServiceStatusListener::IServStatListener> hdfListener_ = nullptr;
364     sptr<HDI::Ril::V1_2::IRil> rilInterface_ = nullptr;
365 };
366 } // namespace Telephony
367 } // namespace OHOS
368 #endif // TEL_RIL_MANAGER_H
369