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 #include "cellular_call_connection_ims.h"
17
18 #include "cellular_call_hisysevent.h"
19 #include "cellular_call_service.h"
20 #include "ims_call_client.h"
21 #include "radio_event.h"
22 #include "securec.h"
23 #include "standardize_utils.h"
24
25 namespace OHOS {
26 namespace Telephony {
DialRequest(int32_t slotId,const ImsDialInfoStruct & dialRequest)27 int32_t CellularCallConnectionIMS::DialRequest(int32_t slotId, const ImsDialInfoStruct &dialRequest)
28 {
29 TELEPHONY_LOGI("call ims service");
30 ImsCallInfo callInfo;
31 if (memset_s(&callInfo, sizeof(callInfo), 0, sizeof(callInfo)) != EOK) {
32 TELEPHONY_LOGE("return, memset_s error.");
33 CellularCallHiSysEvent::WriteDialCallFaultEvent(
34 slotId, INVALID_PARAMETER, dialRequest.videoState, TELEPHONY_ERR_MEMSET_FAIL, "memset_s error");
35 return TELEPHONY_ERR_MEMSET_FAIL;
36 }
37 UpdateCallNumber(dialRequest.phoneNum);
38 size_t cpyLen = strlen(phoneNumber_.c_str()) + 1;
39 if (cpyLen > static_cast<size_t>(kMaxNumberLength)) {
40 phoneNumber_.clear();
41 return TELEPHONY_ERR_STRCPY_FAIL;
42 }
43 if (strcpy_s(callInfo.phoneNum, cpyLen, phoneNumber_.c_str()) != EOK) {
44 TELEPHONY_LOGE("return, strcpy_s fail.");
45 phoneNumber_.clear();
46 CellularCallHiSysEvent::WriteDialCallFaultEvent(
47 slotId, INVALID_PARAMETER, dialRequest.videoState, TELEPHONY_ERR_STRCPY_FAIL, "strcpy_s fail");
48 return TELEPHONY_ERR_STRCPY_FAIL;
49 }
50 phoneNumber_.clear();
51 callInfo.videoState = dialRequest.videoState;
52 callInfo.slotId = slotId;
53 if (DelayedSingleton<ImsCallClient>::GetInstance() == nullptr) {
54 TELEPHONY_LOGE("return, ImsCallClient is nullptr.");
55 CellularCallHiSysEvent::WriteDialCallFaultEvent(slotId, INVALID_PARAMETER, dialRequest.videoState,
56 CALL_ERR_RESOURCE_UNAVAILABLE, "ims vendor service does not exist");
57 return CALL_ERR_RESOURCE_UNAVAILABLE;
58 }
59 return DelayedSingleton<ImsCallClient>::GetInstance()->Dial(callInfo, dialRequest.clirMode);
60 }
61
HangUpRequest(int32_t slotId,const std::string & phoneNum,int32_t index)62 int32_t CellularCallConnectionIMS::HangUpRequest(int32_t slotId, const std::string &phoneNum, int32_t index)
63 {
64 if (moduleUtils_.NeedCallImsService()) {
65 TELEPHONY_LOGI("call ims service");
66 ImsCallInfo callInfo;
67 if (memset_s(&callInfo, sizeof(callInfo), 0, sizeof(callInfo)) != EOK) {
68 TELEPHONY_LOGE("return, memset_s error.");
69 return TELEPHONY_ERR_MEMSET_FAIL;
70 }
71 if (static_cast<int32_t>(phoneNum.length() + 1) > kMaxNumberLength) {
72 return TELEPHONY_ERR_STRCPY_FAIL;
73 }
74 if (strcpy_s(callInfo.phoneNum, strlen(phoneNum.c_str()) + 1, phoneNum.c_str()) != EOK) {
75 TELEPHONY_LOGE("return, strcpy_s fail.");
76 return TELEPHONY_ERR_STRCPY_FAIL;
77 }
78 callInfo.slotId = slotId;
79 callInfo.index = index;
80 if (DelayedSingleton<ImsCallClient>::GetInstance() == nullptr) {
81 TELEPHONY_LOGE("return, ImsCallClient is nullptr.");
82 return CALL_ERR_RESOURCE_UNAVAILABLE;
83 }
84 return DelayedSingleton<ImsCallClient>::GetInstance()->HangUp(callInfo);
85 }
86 TELEPHONY_LOGE("ims vendor service does not exist.");
87 CellularCallHiSysEvent::WriteHangUpFaultEvent(slotId, INVALID_PARAMETER,
88 static_cast<int32_t>(CallErrorCode::CALL_ERROR_IMS_SERVICE_NOT_EXIST),
89 "HangUpRequest ims vendor service does not exist");
90 return TELEPHONY_ERROR;
91 }
92
AnswerRequest(int32_t slotId,const std::string & phoneNum,int32_t videoState,int32_t index)93 int32_t CellularCallConnectionIMS::AnswerRequest(
94 int32_t slotId, const std::string &phoneNum, int32_t videoState, int32_t index)
95 {
96 if (moduleUtils_.NeedCallImsService()) {
97 TELEPHONY_LOGI("call ims service");
98 ImsCallInfo callInfo;
99 if (memset_s(&callInfo, sizeof(callInfo), 0, sizeof(callInfo)) != EOK) {
100 TELEPHONY_LOGE("return, memset_s error.");
101 return TELEPHONY_ERR_MEMSET_FAIL;
102 }
103 if (static_cast<int32_t>(phoneNum.length() + 1) > kMaxNumberLength) {
104 return TELEPHONY_ERR_STRCPY_FAIL;
105 }
106 if (strcpy_s(callInfo.phoneNum, strlen(phoneNum.c_str()) + 1, phoneNum.c_str()) != EOK) {
107 TELEPHONY_LOGE("return, strcpy_s fail.");
108 return TELEPHONY_ERR_STRCPY_FAIL;
109 }
110 callInfo.videoState = videoState;
111 callInfo.slotId = slotId;
112 callInfo.index = index;
113 if (DelayedSingleton<ImsCallClient>::GetInstance() == nullptr) {
114 TELEPHONY_LOGE("return, ImsCallClient is nullptr.");
115 return CALL_ERR_RESOURCE_UNAVAILABLE;
116 }
117 return DelayedSingleton<ImsCallClient>::GetInstance()->Answer(callInfo);
118 }
119 TELEPHONY_LOGE("ims vendor service does not exist.");
120 CellularCallHiSysEvent::WriteAnswerCallFaultEvent(slotId, INVALID_PARAMETER, INVALID_PARAMETER,
121 static_cast<int32_t>(CallErrorCode::CALL_ERROR_IMS_SERVICE_NOT_EXIST), "ims vendor service does not exist");
122 return TELEPHONY_ERROR;
123 }
124
RejectRequest(int32_t slotId,const std::string & phoneNum,int32_t index)125 int32_t CellularCallConnectionIMS::RejectRequest(int32_t slotId, const std::string &phoneNum, int32_t index)
126 {
127 if (moduleUtils_.NeedCallImsService()) {
128 TELEPHONY_LOGI("call ims service");
129 ImsCallInfo callInfo;
130 if (memset_s(&callInfo, sizeof(callInfo), 0, sizeof(callInfo)) != EOK) {
131 TELEPHONY_LOGE("return, memset_s error.");
132 return TELEPHONY_ERR_MEMSET_FAIL;
133 }
134 if (static_cast<int32_t>(phoneNum.length() + 1) > kMaxNumberLength) {
135 return TELEPHONY_ERR_STRCPY_FAIL;
136 }
137 if (strcpy_s(callInfo.phoneNum, strlen(phoneNum.c_str()) + 1, phoneNum.c_str()) != EOK) {
138 TELEPHONY_LOGE("return, strcpy_s fail.");
139 return TELEPHONY_ERR_STRCPY_FAIL;
140 }
141 callInfo.slotId = slotId;
142 callInfo.index = index;
143 if (DelayedSingleton<ImsCallClient>::GetInstance() == nullptr) {
144 TELEPHONY_LOGE("return, ImsCallClient is nullptr.");
145 return CALL_ERR_RESOURCE_UNAVAILABLE;
146 }
147 return DelayedSingleton<ImsCallClient>::GetInstance()->Reject(callInfo);
148 }
149 TELEPHONY_LOGE("ims vendor service does not exist.");
150 CellularCallHiSysEvent::WriteHangUpFaultEvent(slotId, INVALID_PARAMETER,
151 static_cast<int32_t>(CallErrorCode::CALL_ERROR_IMS_SERVICE_NOT_EXIST),
152 "RejectRequest ims vendor service does not exist");
153 return TELEPHONY_ERROR;
154 }
155
HoldCallRequest(int32_t slotId)156 int32_t CellularCallConnectionIMS::HoldCallRequest(int32_t slotId)
157 {
158 if (moduleUtils_.NeedCallImsService()) {
159 TELEPHONY_LOGI("call ims service");
160 if (DelayedSingleton<ImsCallClient>::GetInstance() == nullptr) {
161 TELEPHONY_LOGE("return, ImsCallClient is nullptr.");
162 return CALL_ERR_RESOURCE_UNAVAILABLE;
163 }
164 int32_t callType = static_cast<int32_t>(GetCallReportInfo().callMode);
165 return DelayedSingleton<ImsCallClient>::GetInstance()->HoldCall(slotId, callType);
166 }
167 TELEPHONY_LOGE("ims vendor service does not exist.");
168 return TELEPHONY_ERROR;
169 }
170
UnHoldCallRequest(int32_t slotId)171 int32_t CellularCallConnectionIMS::UnHoldCallRequest(int32_t slotId)
172 {
173 if (moduleUtils_.NeedCallImsService()) {
174 TELEPHONY_LOGI("call ims service");
175 if (DelayedSingleton<ImsCallClient>::GetInstance() == nullptr) {
176 TELEPHONY_LOGE("return, ImsCallClient is nullptr.");
177 return CALL_ERR_RESOURCE_UNAVAILABLE;
178 }
179 int32_t callType = static_cast<int32_t>(GetCallReportInfo().callMode);
180 return DelayedSingleton<ImsCallClient>::GetInstance()->UnHoldCall(slotId, callType);
181 }
182 TELEPHONY_LOGE("ims vendor service does not exist.");
183 return TELEPHONY_ERROR;
184 }
185
SwitchCallRequest(int32_t slotId)186 int32_t CellularCallConnectionIMS::SwitchCallRequest(int32_t slotId)
187 {
188 if (moduleUtils_.NeedCallImsService()) {
189 TELEPHONY_LOGI("call ims service");
190 if (DelayedSingleton<ImsCallClient>::GetInstance() == nullptr) {
191 TELEPHONY_LOGE("return, ImsCallClient is nullptr.");
192 return CALL_ERR_RESOURCE_UNAVAILABLE;
193 }
194 int32_t callType = static_cast<int32_t>(GetCallReportInfo().callMode);
195 return DelayedSingleton<ImsCallClient>::GetInstance()->SwitchCall(slotId, callType);
196 }
197 TELEPHONY_LOGE("ims vendor service does not exist.");
198 return TELEPHONY_ERROR;
199 }
200
CombineConferenceRequest(int32_t slotId,int32_t voiceCall)201 int32_t CellularCallConnectionIMS::CombineConferenceRequest(int32_t slotId, int32_t voiceCall)
202 {
203 if (moduleUtils_.NeedCallImsService()) {
204 TELEPHONY_LOGI("call ims service");
205 if (DelayedSingleton<ImsCallClient>::GetInstance() == nullptr) {
206 TELEPHONY_LOGE("return, ImsCallClient is nullptr.");
207 return CALL_ERR_RESOURCE_UNAVAILABLE;
208 }
209 return DelayedSingleton<ImsCallClient>::GetInstance()->CombineConference(slotId);
210 }
211 TELEPHONY_LOGE("ims vendor service does not exist.");
212 return TELEPHONY_ERROR;
213 }
214
InviteToConferenceRequest(int32_t slotId,const std::vector<std::string> & numberList)215 int32_t CellularCallConnectionIMS::InviteToConferenceRequest(
216 int32_t slotId, const std::vector<std::string> &numberList)
217 {
218 if (moduleUtils_.NeedCallImsService()) {
219 TELEPHONY_LOGI("call ims service");
220 if (DelayedSingleton<ImsCallClient>::GetInstance() == nullptr) {
221 TELEPHONY_LOGE("return, ImsCallClient is nullptr.");
222 return CALL_ERR_RESOURCE_UNAVAILABLE;
223 }
224 return DelayedSingleton<ImsCallClient>::GetInstance()->InviteToConference(slotId, numberList);
225 }
226 TELEPHONY_LOGE("ims vendor service does not exist.");
227 return TELEPHONY_ERROR;
228 }
229
KickOutFromConferenceRequest(int32_t slotId,int32_t index)230 int32_t CellularCallConnectionIMS::KickOutFromConferenceRequest(int32_t slotId, int32_t index)
231 {
232 if (moduleUtils_.NeedCallImsService()) {
233 TELEPHONY_LOGI("call ims service");
234 if (DelayedSingleton<ImsCallClient>::GetInstance() == nullptr) {
235 TELEPHONY_LOGE("return, ImsCallClient is nullptr.");
236 return CALL_ERR_RESOURCE_UNAVAILABLE;
237 }
238 return DelayedSingleton<ImsCallClient>::GetInstance()->KickOutFromConference(slotId, index);
239 }
240 TELEPHONY_LOGE("ims vendor service does not exist.");
241 return TELEPHONY_ERROR;
242 }
243
CallSupplementRequest(int32_t slotId,CallSupplementType type)244 int32_t CellularCallConnectionIMS::CallSupplementRequest(int32_t slotId, CallSupplementType type)
245 {
246 TELEPHONY_LOGD("start");
247 if (DelayedSingleton<CellularCallService>::GetInstance() == nullptr) {
248 TELEPHONY_LOGE("return, error type: GetInstance() is nullptr.");
249 return CALL_ERR_RESOURCE_UNAVAILABLE;
250 }
251 auto handle = DelayedSingleton<CellularCallService>::GetInstance()->GetHandler(slotId);
252 if (handle == nullptr) {
253 TELEPHONY_LOGE("return, error type: handle is nullptr.");
254 return CALL_ERR_RESOURCE_UNAVAILABLE;
255 }
256 CoreManagerInner::GetInstance().CallSupplement(slotId, RadioEvent::RADIO_CALL_SUPPLEMENT, type, handle);
257 return TELEPHONY_SUCCESS;
258 }
259
UpdateCallMediaModeRequest(const CellularCallInfo & callInfo,ImsCallMode mode)260 int32_t CellularCallConnectionIMS::UpdateCallMediaModeRequest(const CellularCallInfo &callInfo, ImsCallMode mode)
261 {
262 if (moduleUtils_.NeedCallImsService()) {
263 TELEPHONY_LOGD("call ims service");
264 ImsCallInfo imsCallInfo;
265 if (memset_s(&imsCallInfo, sizeof(imsCallInfo), 0, sizeof(imsCallInfo)) != EOK) {
266 TELEPHONY_LOGE("return, memset_s error.");
267 return TELEPHONY_ERR_MEMSET_FAIL;
268 }
269 if (static_cast<int32_t>(strlen(callInfo.phoneNum) + 1) > kMaxNumberLength) {
270 return TELEPHONY_ERR_STRCPY_FAIL;
271 }
272 errno_t result = strcpy_s(imsCallInfo.phoneNum, strlen(callInfo.phoneNum) + 1,
273 callInfo.phoneNum);
274 if (result != EOK) {
275 TELEPHONY_LOGE("return, strcpy_s fail.");
276 return TELEPHONY_ERR_STRCPY_FAIL;
277 }
278 imsCallInfo.slotId = callInfo.slotId;
279 imsCallInfo.index = callInfo.index;
280 if (DelayedSingleton<ImsCallClient>::GetInstance() == nullptr) {
281 TELEPHONY_LOGE("return, ImsCallClient is nullptr.");
282 return CALL_ERR_RESOURCE_UNAVAILABLE;
283 }
284 return DelayedSingleton<ImsCallClient>::GetInstance()->UpdateImsCallMode(imsCallInfo, mode);
285 }
286 TELEPHONY_LOGE("ims vendor service does not exist.");
287 return TELEPHONY_ERROR;
288 }
289
GetImsCallsDataRequest(int32_t slotId,int64_t lastCallsDataFlag)290 int32_t CellularCallConnectionIMS::GetImsCallsDataRequest(int32_t slotId, int64_t lastCallsDataFlag)
291 {
292 if (moduleUtils_.NeedCallImsService()) {
293 TELEPHONY_LOGI("call ims service");
294 if (DelayedSingleton<ImsCallClient>::GetInstance() == nullptr) {
295 TELEPHONY_LOGE("return, ImsCallClient is nullptr.");
296 return CALL_ERR_RESOURCE_UNAVAILABLE;
297 }
298 return DelayedSingleton<ImsCallClient>::GetInstance()->GetImsCallsDataRequest(slotId, lastCallsDataFlag);
299 }
300 TELEPHONY_LOGE("ims vendor service does not exist.");
301 return TELEPHONY_ERROR;
302 }
303
SendDtmfRequest(int32_t slotId,char cDtmfCode,int32_t index) const304 int32_t CellularCallConnectionIMS::SendDtmfRequest(int32_t slotId, char cDtmfCode, int32_t index) const
305 {
306 if (moduleUtils_.NeedCallImsService()) {
307 TELEPHONY_LOGD("call ims service");
308 if (DelayedSingleton<ImsCallClient>::GetInstance() == nullptr) {
309 TELEPHONY_LOGE("return, ImsCallClient is nullptr.");
310 return CALL_ERR_RESOURCE_UNAVAILABLE;
311 }
312 return DelayedSingleton<ImsCallClient>::GetInstance()->SendDtmf(slotId, cDtmfCode, index);
313 }
314 TELEPHONY_LOGE("ims vendor service does not exist.");
315 return TELEPHONY_ERROR;
316 }
317
StartDtmfRequest(int32_t slotId,char cDtmfCode,int32_t index) const318 int32_t CellularCallConnectionIMS::StartDtmfRequest(int32_t slotId, char cDtmfCode, int32_t index) const
319 {
320 if (moduleUtils_.NeedCallImsService()) {
321 TELEPHONY_LOGI("call ims service");
322 if (DelayedSingleton<ImsCallClient>::GetInstance() == nullptr) {
323 TELEPHONY_LOGE("return, ImsCallClient is nullptr.");
324 return CALL_ERR_RESOURCE_UNAVAILABLE;
325 }
326 return DelayedSingleton<ImsCallClient>::GetInstance()->StartDtmf(slotId, cDtmfCode, index);
327 }
328 TELEPHONY_LOGE("ims vendor service does not exist.");
329 return TELEPHONY_ERROR;
330 }
331
StopDtmfRequest(int32_t slotId,int32_t index) const332 int32_t CellularCallConnectionIMS::StopDtmfRequest(int32_t slotId, int32_t index) const
333 {
334 if (moduleUtils_.NeedCallImsService()) {
335 TELEPHONY_LOGI("call ims service");
336 if (DelayedSingleton<ImsCallClient>::GetInstance() == nullptr) {
337 TELEPHONY_LOGE("return, ImsCallClient is nullptr.");
338 return CALL_ERR_RESOURCE_UNAVAILABLE;
339 }
340 return DelayedSingleton<ImsCallClient>::GetInstance()->StopDtmf(slotId, index);
341 }
342 TELEPHONY_LOGE("ims vendor service does not exist.");
343 return TELEPHONY_ERROR;
344 }
345
StartRttRequest(int32_t slotId,const std::string & msg)346 int32_t CellularCallConnectionIMS::StartRttRequest(int32_t slotId, const std::string &msg)
347 {
348 if (moduleUtils_.NeedCallImsService()) {
349 TELEPHONY_LOGI("call ims service");
350 if (DelayedSingleton<ImsCallClient>::GetInstance() == nullptr) {
351 TELEPHONY_LOGE("return, ImsCallClient is nullptr.");
352 return CALL_ERR_RESOURCE_UNAVAILABLE;
353 }
354 return DelayedSingleton<ImsCallClient>::GetInstance()->StartRtt(slotId, msg);
355 }
356 TELEPHONY_LOGE("ims vendor service does not exist.");
357 return TELEPHONY_ERROR;
358 }
359
StopRttRequest(int32_t slotId)360 int32_t CellularCallConnectionIMS::StopRttRequest(int32_t slotId)
361 {
362 if (moduleUtils_.NeedCallImsService()) {
363 TELEPHONY_LOGI("call ims service");
364 if (DelayedSingleton<ImsCallClient>::GetInstance() == nullptr) {
365 TELEPHONY_LOGE("return, ImsCallClient is nullptr.");
366 return CALL_ERR_RESOURCE_UNAVAILABLE;
367 }
368 return DelayedSingleton<ImsCallClient>::GetInstance()->StopRtt(slotId);
369 }
370 TELEPHONY_LOGE("ims vendor service does not exist.");
371 return TELEPHONY_ERROR;
372 }
373
GetCallFailReasonRequest(int32_t slotId) const374 int32_t CellularCallConnectionIMS::GetCallFailReasonRequest(int32_t slotId) const
375 {
376 if (moduleUtils_.NeedCallImsService()) {
377 TELEPHONY_LOGD("call ims service");
378 if (DelayedSingleton<ImsCallClient>::GetInstance() == nullptr) {
379 TELEPHONY_LOGE("return, ImsCallClient is nullptr.");
380 return CALL_ERR_RESOURCE_UNAVAILABLE;
381 }
382 return DelayedSingleton<ImsCallClient>::GetInstance()->GetLastCallFailReason(slotId);
383 }
384 TELEPHONY_LOGE("ims vendor service does not exist.");
385 return TELEPHONY_ERROR;
386 }
387
ProcessPostDialCallChar(int32_t slotId,char c)388 int32_t CellularCallConnectionIMS::ProcessPostDialCallChar(int32_t slotId, char c)
389 {
390 if (StandardizeUtils::IsDtmfKey(c)) {
391 SendDtmfRequest(slotId, c, GetIndex());
392 } else if (StandardizeUtils::IsPauseKey(c)) {
393 SetPostDialCallState(PostDialCallState::POST_DIAL_CALL_PAUSE);
394 auto handle = DelayedSingleton<CellularCallService>::GetInstance()->GetHandler(slotId);
395 if (handle == nullptr) {
396 TELEPHONY_LOGE("SendDtmfRequest return, error type: handle is nullptr.");
397 return CALL_ERR_RESOURCE_UNAVAILABLE;
398 }
399 std::shared_ptr<PostDialData> postDial = std::make_shared<PostDialData>();
400 postDial->callId = GetIndex();
401 postDial->isIms = true;
402 handle->SendEvent(EVENT_EXECUTE_POST_DIAL, postDial, PAUSE_DELAY_TIME);
403 } else if (StandardizeUtils::IsWaitKey(c)) {
404 SetPostDialCallState(PostDialCallState::POST_DIAL_CALL_DELAY);
405 }
406 return TELEPHONY_SUCCESS;
407 }
408 } // namespace Telephony
409 } // namespace OHOS
410