• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "call_request_process.h"
17 
18 #include "call_ability_report_proxy.h"
19 #include "call_control_manager.h"
20 #include "call_dialog.h"
21 #include "call_manager_errors.h"
22 #include "call_manager_hisysevent.h"
23 #include "call_number_utils.h"
24 #include "call_request_event_handler_helper.h"
25 #include "cellular_call_connection.h"
26 #include "common_type.h"
27 #include "core_service_client.h"
28 #include "core_service_connection.h"
29 #include "cs_call.h"
30 #include "ims_call.h"
31 #include "ott_call.h"
32 #include "report_call_info_handler.h"
33 #include "telephony_log_wrapper.h"
34 #include "bluetooth_call_connection.h"
35 
36 namespace OHOS {
37 namespace Telephony {
38 bool g_flagForDsda = false;
39 constexpr int32_t INIT_INDEX = 0;
40 
CallRequestProcess()41 CallRequestProcess::CallRequestProcess() {}
42 
~CallRequestProcess()43 CallRequestProcess::~CallRequestProcess() {}
44 
DialRequest()45 int32_t CallRequestProcess::DialRequest()
46 {
47     DialParaInfo info;
48     DelayedSingleton<CallControlManager>::GetInstance()->GetDialParaInfo(info);
49     if (!info.isDialing) {
50         TELEPHONY_LOGE("the device is not dialing!");
51         CallManagerHisysevent::WriteDialCallFaultEvent(info.accountId, static_cast<int32_t>(info.callType),
52             static_cast<int32_t>(info.videoState), static_cast<int32_t>(CallErrorCode::CALL_ERROR_DEVICE_NOT_DIALING),
53             "the device is not dialing");
54         return CALL_ERR_ILLEGAL_CALL_OPERATION;
55     }
56     if (info.number.length() > static_cast<size_t>(kMaxNumberLen)) {
57         TELEPHONY_LOGE("Number out of limit!");
58         return CALL_ERR_NUMBER_OUT_OF_RANGE;
59     }
60     bool isEcc = false;
61     DelayedSingleton<CallNumberUtils>::GetInstance()->CheckNumberIsEmergency(info.number, info.accountId, isEcc);
62     if (!isEcc && info.dialType == DialType::DIAL_CARRIER_TYPE &&
63         DelayedSingleton<CoreServiceConnection>::GetInstance()->IsFdnEnabled(info.accountId)) {
64         std::vector<std::u16string> fdnNumberList =
65             DelayedSingleton<CoreServiceConnection>::GetInstance()->GetFdnNumberList(info.accountId);
66         if (fdnNumberList.empty() || !IsFdnNumber(fdnNumberList, info.number)) {
67             CallEventInfo eventInfo;
68             (void)memset_s(eventInfo.phoneNum, kMaxNumberLen, 0, kMaxNumberLen);
69             eventInfo.eventId = CallAbilityEventId::EVENT_INVALID_FDN_NUMBER;
70             (void)memcpy_s(eventInfo.phoneNum, kMaxNumberLen, info.number.c_str(), info.number.length());
71             DelayedSingleton<CallControlManager>::GetInstance()->NotifyCallEventUpdated(eventInfo);
72             CallManagerHisysevent::WriteDialCallFaultEvent(info.accountId, static_cast<int32_t>(info.callType),
73                 static_cast<int32_t>(info.videoState),
74                 static_cast<int32_t>(CallErrorCode::CALL_ERROR_INVALID_FDN_NUMBER), "invalid fdn number!");
75             DelayedSingleton<CallDialog>::GetInstance()->DialogConnectExtension("CALL_FAILED_DUE_TO_FDN");
76             return CALL_ERR_DIAL_FAILED;
77         }
78     }
79     TELEPHONY_LOGI("dialType:%{public}d", info.dialType);
80     return HandleDialRequest(info);
81 }
82 
HandleDialRequest(DialParaInfo & info)83 int32_t CallRequestProcess::HandleDialRequest(DialParaInfo &info)
84 {
85     int32_t ret = CALL_ERR_UNKNOW_DIAL_TYPE;
86     switch (info.dialType) {
87         case DialType::DIAL_CARRIER_TYPE:
88             ret = CarrierDialProcess(info);
89             break;
90         case DialType::DIAL_VOICE_MAIL_TYPE:
91             ret = VoiceMailDialProcess(info);
92             break;
93         case DialType::DIAL_OTT_TYPE:
94             ret = OttDialProcess(info);
95             break;
96         case DialType::DIAL_BLUETOOTH_TYPE:
97             ret  = BluetoothDialProcess(info);
98             break;
99         default:
100             break;
101     }
102     return ret;
103 }
104 
AnswerRequest(int32_t callId,int32_t videoState)105 void CallRequestProcess::AnswerRequest(int32_t callId, int32_t videoState)
106 {
107     sptr<CallBase> call = GetOneCallObject(callId);
108     if (call == nullptr) {
109         TELEPHONY_LOGE("the call object is nullptr, callId:%{public}d", callId);
110         return;
111     }
112     call->SetAnswerVideoState(videoState);
113     if (call->GetCallType() == CallType::TYPE_VOIP) {
114         int32_t ret = call->AnswerCall(videoState);
115         if (ret != TELEPHONY_SUCCESS) {
116             TELEPHONY_LOGE("AnswerCall failed!");
117             return;
118         }
119         DelayedSingleton<CallControlManager>::GetInstance()->NotifyIncomingCallAnswered(call);
120         return;
121     }
122     AnswerRequestForDsda(call, callId, videoState);
123 }
124 
AnswerRequestForDsda(sptr<CallBase> call,int32_t callId,int32_t videoState)125 void CallRequestProcess::AnswerRequestForDsda(sptr<CallBase> call, int32_t callId, int32_t videoState)
126 {
127     int32_t slotId = call->GetSlotId();
128     int32_t callCrsType = 2;
129     if (IsDsdsMode3()) {
130         DisconnectOtherSubIdCall(callId, slotId, videoState);
131     } else if (IsDsdsMode5()) {
132         if (NeedAnswerVTAndEndActiveVO(callId, videoState)) {
133             TELEPHONY_LOGI("Answer videoCall for Dsda");
134             DisconnectOtherCallForVideoCall(callId);
135             call->SetAutoAnswerState(true);
136             return;
137         } else if (NeedAnswerVOAndEndActiveVT(callId, videoState)) {
138             TELEPHONY_LOGI("Answer voiceCall for Dsda, but has video call");
139             DisconnectOtherCallForVideoCall(callId);
140             call->SetAutoAnswerState(true);
141             return;
142         }
143         // There is already an incoming call to the CRS.
144         int32_t otherRingCallId = GetOtherRingingCall(callId);
145         if (otherRingCallId != INVALID_CALLID) {
146             sptr<CallBase> ringingCall = GetOneCallObject(otherRingCallId);
147             if (ringingCall != nullptr && ringingCall->GetCrsType() == callCrsType) {
148                 ringingCall->HangUpCall();
149                 call->SetAutoAnswerState(true);
150                 return;
151             }
152         }
153         call->SetAutoAnswerState(true);
154         HoldOrDisconnectedCall(callId, slotId, videoState);
155     } else {
156         int32_t ret = call->AnswerCall(videoState);
157         if (ret != TELEPHONY_SUCCESS) {
158             TELEPHONY_LOGE("AnswerCall failed!");
159             return;
160         }
161         DelayedSingleton<CallControlManager>::GetInstance()->NotifyIncomingCallAnswered(call);
162     }
163 }
164 
IsDsdsMode3()165 bool CallRequestProcess::IsDsdsMode3()
166 {
167     int32_t dsdsMode = DSDS_MODE_V2;
168     DelayedRefSingleton<CoreServiceClient>::GetInstance().GetDsdsMode(dsdsMode);
169     TELEPHONY_LOGI("dsdsMode:%{public}d", dsdsMode);
170     if (dsdsMode == DSDS_MODE_V3) {
171         return true;
172     }
173     return false;
174 }
175 
IsDsdsMode5()176 bool CallRequestProcess::IsDsdsMode5()
177 {
178     int32_t dsdsMode = DSDS_MODE_V2;
179     DelayedRefSingleton<CoreServiceClient>::GetInstance().GetDsdsMode(dsdsMode);
180     TELEPHONY_LOGI("IsDsdsMode5:%{public}d", dsdsMode);
181     if (dsdsMode == static_cast<int32_t>(DsdsMode::DSDS_MODE_V5_DSDA) ||
182         dsdsMode == static_cast<int32_t>(DsdsMode::DSDS_MODE_V5_TDM)) {
183         return true;
184     }
185     return false;
186 }
187 
HasConnectingCall(bool isIncludeVoipCall)188 bool CallRequestProcess::HasConnectingCall(bool isIncludeVoipCall)
189 {
190     int32_t dialingCallNum = GetCallNum(TelCallState::CALL_STATUS_DIALING, isIncludeVoipCall);
191     int32_t alertingCallNum = GetCallNum(TelCallState::CALL_STATUS_ALERTING, isIncludeVoipCall);
192     if (dialingCallNum == 0 && alertingCallNum == 0) {
193         return false;
194     }
195     return true;
196 }
197 
HasActivedCall(bool isIncludeVoipCall)198 bool CallRequestProcess::HasActivedCall(bool isIncludeVoipCall)
199 {
200     int32_t activeCallNum = GetCallNum(TelCallState::CALL_STATUS_ACTIVE, isIncludeVoipCall);
201     int32_t holdingCallNum = GetCallNum(TelCallState::CALL_STATUS_HOLDING, isIncludeVoipCall);
202     int32_t answeredCallNum = GetCallNum(TelCallState::CALL_STATUS_ANSWERED, isIncludeVoipCall);
203     if (activeCallNum == 0 && holdingCallNum == 0 && answeredCallNum == 0) {
204         return false;
205     }
206     return true;
207 }
208 
NeedAnswerVTAndEndActiveVO(int32_t callId,int32_t videoState)209 bool CallRequestProcess::NeedAnswerVTAndEndActiveVO(int32_t callId, int32_t videoState)
210 {
211     TELEPHONY_LOGI("Enter NeedAnswerVTAndEndActiveVO");
212     sptr<CallBase> activeCall = GetOneCarrierCallObject(CallRunningState::CALL_RUNNING_STATE_ACTIVE);
213     sptr<CallBase> holdingCall = GetOneCarrierCallObject(CallRunningState::CALL_RUNNING_STATE_HOLD);
214     // if this call is existed foreground or backgroud call, don't hang up it.
215     if ((activeCall != nullptr && activeCall->GetCallID() == callId) ||
216         (holdingCall != nullptr && holdingCall->GetCallID() == callId)) {
217         return false;
218     }
219     if (HasConnectingCall(false) || HasActivedCall(false)) {
220         if (videoState != static_cast<int32_t>(VideoStateType::TYPE_VOICE)) {
221             TELEPHONY_LOGI("answer a new video call, need to hang up the exist call");
222             return true;
223         }
224     }
225     return false;
226 }
227 
NeedAnswerVOAndEndActiveVT(int32_t callId,int32_t videoState)228 bool CallRequestProcess::NeedAnswerVOAndEndActiveVT(int32_t callId, int32_t videoState)
229 {
230     if (videoState != static_cast<int32_t>(VideoStateType::TYPE_VOICE)) {
231         return false;
232     }
233     if (HasActivedCall(false)) {
234         sptr<CallBase> activeCall = GetOneCarrierCallObject(CallRunningState::CALL_RUNNING_STATE_ACTIVE);
235         sptr<CallBase> holdingCall = GetOneCarrierCallObject(CallRunningState::CALL_RUNNING_STATE_HOLD);
236         if ((activeCall != nullptr && activeCall->GetVideoStateType() != VideoStateType::TYPE_VOICE &&
237                 activeCall->GetCallID() != callId) ||
238             (holdingCall != nullptr && holdingCall->GetVideoStateType() != VideoStateType::TYPE_VOICE &&
239                 holdingCall->GetCallID() != callId)) {
240             TELEPHONY_LOGI("answer a new voice call, need to hang up the exist video call");
241             return true;
242         }
243     }
244     return false;
245 }
246 
GetOtherRingingCall(int32_t currentCallId)247 int32_t CallRequestProcess::GetOtherRingingCall(int32_t currentCallId)
248 {
249     int32_t otherRingCallId = INVALID_CALLID;
250     std::list<int32_t> callIdList;
251     GetCarrierCallList(callIdList);
252     for (int32_t otherCallId : callIdList) {
253         if (otherCallId == currentCallId) {
254             continue;
255         }
256         sptr<CallBase> call = GetOneCallObject(otherCallId);
257         if (call != nullptr && call->GetCallRunningState() == CallRunningState::CALL_RUNNING_STATE_RINGING) {
258             otherRingCallId = call->GetCallID();
259             break;
260         }
261     }
262     return otherRingCallId;
263 }
264 
HoldOrDisconnectedCall(int32_t callId,int32_t slotId,int32_t videoState)265 void CallRequestProcess::HoldOrDisconnectedCall(int32_t callId, int32_t slotId, int32_t videoState)
266 {
267     TELEPHONY_LOGI("Enter HoldOrDisconnectedCall");
268     std::list<int32_t> callIdList;
269     bool noOtherCall = true;
270     bool flagForConference = false;
271     GetCarrierCallList(callIdList);
272     IsExistCallOtherSlot(callIdList, slotId, noOtherCall);
273     if (noOtherCall) {
274         TELEPHONY_LOGI("no Other Slot Call");
275         sptr<CallBase> call = GetOneCallObject(callId);
276         if (call == nullptr) {
277             TELEPHONY_LOGE("call is nullptr");
278             return;
279         }
280         int32_t ret = call->AnswerCall(videoState);
281         call->SetAutoAnswerState(false);
282         if (ret != TELEPHONY_SUCCESS) {
283             return;
284         }
285         DelayedSingleton<CallControlManager>::GetInstance()->NotifyIncomingCallAnswered(call);
286         return;
287     }
288     sptr<CallBase> incomingCall = GetOneCallObject(callId);
289     int32_t waitingCallNum = GetCallNum(TelCallState::CALL_STATUS_WAITING);
290     int32_t activeCallNum = GetCallNum(TelCallState::CALL_STATUS_ACTIVE);
291     int32_t callNum = 4;
292     for (int32_t otherCallId : callIdList) {
293         sptr<CallBase> call = GetOneCallObject(otherCallId);
294         if (call != nullptr && incomingCall != nullptr && call != incomingCall) {
295             if (HandleDsdaIncomingCall(call, activeCallNum, slotId, videoState, incomingCall)) {
296                 continue;
297             }
298             if (call->GetSlotId() != slotId) {
299                 TELEPHONY_LOGI("exist other slot call");
300                 noOtherCall = false;
301             }
302             int32_t currentCallNum = GetCurrentCallNum();
303             if (waitingCallNum > 1 || currentCallNum == callNum) {
304                 HandleCallWaitingNumTwo(incomingCall, call, slotId, activeCallNum, flagForConference);
305             } else if (waitingCallNum == 1) {
306                 HandleCallWaitingNumOne(incomingCall, call, slotId, activeCallNum, flagForConference);
307             } else {
308                 HandleCallWaitingNumZero(incomingCall, call, slotId, activeCallNum, flagForConference);
309             }
310         }
311     }
312 }
313 
HandleDsdaIncomingCall(sptr<CallBase> call,int32_t activeCallNum,int32_t slotId,int32_t videoState,sptr<CallBase> incomingCall)314 bool CallRequestProcess::HandleDsdaIncomingCall(
315     sptr<CallBase> call, int32_t activeCallNum, int32_t slotId, int32_t videoState, sptr<CallBase> incomingCall)
316 {
317     int32_t alertingCallNum = GetCallNum(TelCallState::CALL_STATUS_ALERTING);
318     int32_t dialingCallNum = GetCallNum(TelCallState::CALL_STATUS_DIALING);
319     int32_t answeredCallNum = GetCallNum(TelCallState::CALL_STATUS_ANSWERED);
320     if ((call->GetTelCallState() == TelCallState::CALL_STATUS_DISCONNECTING ||
321             call->GetTelCallState() == TelCallState::CALL_STATUS_HOLDING) &&
322         (activeCallNum == 0 && alertingCallNum == 0 && dialingCallNum == 0 && answeredCallNum == 0)) {
323         if (call->GetSlotId() != slotId) {
324             TELEPHONY_LOGI("enter HandleDsdaIncomingCall");
325             incomingCall->AnswerCall(videoState);
326             incomingCall->SetAutoAnswerState(false);
327         }
328         return true;
329     }
330     return false;
331 }
332 
IsExistCallOtherSlot(std::list<int32_t> & list,int32_t slotId,bool & noOtherCall)333 void CallRequestProcess::IsExistCallOtherSlot(std::list<int32_t> &list, int32_t slotId, bool &noOtherCall)
334 {
335     if (list.size() > 1) {
336         for (int32_t otherCallId : list) {
337             sptr<CallBase> call = GetOneCallObject(otherCallId);
338             if (call != nullptr && call->GetSlotId() != slotId) {
339                 noOtherCall = false;
340                 break;
341             }
342         }
343     }
344 }
345 
HandleCallWaitingNumTwo(sptr<CallBase> incomingCall,sptr<CallBase> call,int32_t slotId,int32_t activeCallNum,bool & flagForConference)346 void CallRequestProcess::HandleCallWaitingNumTwo(
347     sptr<CallBase> incomingCall, sptr<CallBase> call, int32_t slotId, int32_t activeCallNum, bool &flagForConference)
348 {
349     TELEPHONY_LOGI("enter HandleCallWaitingNumTwo");
350     sptr<CallBase> holdCall = GetOneCallObject(CallRunningState::CALL_RUNNING_STATE_HOLD);
351     int32_t callNum = 3;
352     int32_t currentCallNum = GetCurrentCallNum();
353     if (currentCallNum == callNum) {
354         TELEPHONY_LOGI("enter two waitingCall process");
355         HandleCallWaitingNumOne(incomingCall, call, slotId, activeCallNum, flagForConference);
356         return;
357     }
358     if (holdCall != nullptr) {
359         TELEPHONY_LOGI("enter two holdcall hangup");
360         holdCall->HangUpCall();
361     }
362     TELEPHONY_LOGI("enter two GetTelCallState =:%{public}d", call->GetCallRunningState());
363     if (call->GetCallRunningState() == CallRunningState::CALL_RUNNING_STATE_ACTIVE && !flagForConference) {
364         if (call->GetSlotId() == slotId) {
365             TELEPHONY_LOGI("enter two activecall hold");
366             call->HoldCall();
367             flagForConference = true;
368         } else {
369             TELEPHONY_LOGI(" enter two  activecall hangup");
370             call->HangUpCall();
371         }
372     }
373 }
374 
HandleCallWaitingNumOne(sptr<CallBase> incomingCall,sptr<CallBase> call,int32_t slotId,int32_t activeCallNum,bool & flagForConference)375 void CallRequestProcess::HandleCallWaitingNumOne(
376     sptr<CallBase> incomingCall, sptr<CallBase> call, int32_t slotId, int32_t activeCallNum, bool &flagForConference)
377 {
378     TELEPHONY_LOGI("enter HandleCallWaitingNumOne");
379     sptr<CallBase> holdCall = GetOneCallObject(CallRunningState::CALL_RUNNING_STATE_HOLD);
380     TELEPHONY_LOGI("enter one GetTelCallState =:%{public}d", call->GetTelCallState());
381     int32_t callNum = 2;
382     int32_t currentCallNum = GetCurrentCallNum();
383     if (holdCall != nullptr) {
384         HandleCallWaitingNumOneNext(incomingCall, call, holdCall, slotId, flagForConference);
385     } else if (currentCallNum == callNum) {
386         TELEPHONY_LOGI("enter two call process");
387         HandleCallWaitingNumZero(incomingCall, call, slotId, activeCallNum, flagForConference);
388     } else if (call->GetCallRunningState() == CallRunningState::CALL_RUNNING_STATE_ACTIVE && !flagForConference) {
389         if (call->GetSlotId() != slotId && g_flagForDsda == true) {
390             TELEPHONY_LOGI("enter one hold call is null active call hold for Special Dsda Scenario");
391             call->HoldCall();
392             flagForConference = true;
393             g_flagForDsda = false;
394         } else if (call->GetSlotId() != slotId) {
395             TELEPHONY_LOGI("enter one hold call is null active call hangup");
396             call->HangUpCall();
397         } else {
398             TELEPHONY_LOGI("enter one hold call is null active call hold");
399             call->HoldCall();
400             flagForConference = true;
401         }
402     }
403 }
404 
HandleCallWaitingNumOneNext(sptr<CallBase> incomingCall,sptr<CallBase> call,sptr<CallBase> holdCall,int32_t slotId,bool & flagForConference)405 void CallRequestProcess::HandleCallWaitingNumOneNext(
406     sptr<CallBase> incomingCall, sptr<CallBase> call, sptr<CallBase> holdCall, int32_t slotId, bool &flagForConference)
407 {
408     TELEPHONY_LOGI("enter HandleCallWaitingNumOneNext");
409     int32_t activeCallNum = GetCallNum(TelCallState::CALL_STATUS_ACTIVE);
410     int32_t dialingCallNum = GetCallNum(TelCallState::CALL_STATUS_DIALING);
411     int32_t alertingCallNum = GetCallNum(TelCallState::CALL_STATUS_ALERTING);
412     if (call->GetTelCallState() == TelCallState ::CALL_STATUS_DIALING ||
413         call->GetTelCallState() == TelCallState ::CALL_STATUS_ALERTING) {
414         TELEPHONY_LOGI("enter one dialing call hangup");
415         call->HangUpCall();
416     } else if (activeCallNum > 0) {
417         TELEPHONY_LOGI("enter one hold call hangup");
418         holdCall->HangUpCall();
419         g_flagForDsda = true;
420     }
421     if (call->GetCallRunningState() == CallRunningState::CALL_RUNNING_STATE_ACTIVE && !flagForConference) {
422         if (CallObjectManager::IsCallExist(call->GetCallType(), TelCallState::CALL_STATUS_INCOMING) &&
423             call->GetSlotId() != slotId) {
424             TELEPHONY_LOGI("enter one active call hangup");
425             call->HangUpCall();
426         } else {
427             TELEPHONY_LOGI("enter one active call hold");
428             call->HoldCall();
429             flagForConference = true;
430         }
431     } else if (activeCallNum == 0 && incomingCall->GetAutoAnswerState() && alertingCallNum == 0 &&
432                dialingCallNum == 0) {
433         TELEPHONY_LOGI("enter one active with two incoming call");
434         incomingCall->AnswerCall(static_cast<int32_t>(incomingCall->GetVideoStateType()));
435         incomingCall->SetAutoAnswerState(false);
436     }
437 }
438 
HandleCallWaitingNumZero(sptr<CallBase> incomingCall,sptr<CallBase> call,int32_t slotId,int32_t activeCallNum,bool & flagForConference)439 void CallRequestProcess::HandleCallWaitingNumZero(
440     sptr<CallBase> incomingCall, sptr<CallBase> call, int32_t slotId, int32_t activeCallNum, bool &flagForConference)
441 {
442     TELEPHONY_LOGI("enter HandleCallWaitingNumZero");
443     sptr<CallBase> holdCall = GetOneCallObject(CallRunningState::CALL_RUNNING_STATE_HOLD);
444     if (holdCall != nullptr) {
445         TELEPHONY_LOGI("enter zero holdcall is not null");
446         if (call->GetTelCallState() == TelCallState ::CALL_STATUS_DIALING ||
447             call->GetTelCallState() == TelCallState ::CALL_STATUS_ALERTING) {
448             TELEPHONY_LOGI("enter zero dialing call hangup");
449             call->HangUpCall();
450         } else if (activeCallNum > 0) {
451             TELEPHONY_LOGI("enter zero hold call hangup");
452             holdCall->HangUpCall();
453         }
454         if (call->GetCallRunningState() == CallRunningState::CALL_RUNNING_STATE_ACTIVE && !flagForConference) {
455             TELEPHONY_LOGI("enter active call hangup");
456             call->HoldCall();
457             flagForConference = true;
458         }
459     } else {
460         TELEPHONY_LOGI("enter zero holdcall is null");
461         if (call->GetTelCallState() == TelCallState ::CALL_STATUS_DIALING ||
462             call->GetTelCallState() == TelCallState ::CALL_STATUS_ALERTING) {
463             TELEPHONY_LOGI("enter zero dialing incoming call hangup");
464             call->HangUpCall();
465         } else if (call->GetCallRunningState() == CallRunningState::CALL_RUNNING_STATE_ACTIVE && !flagForConference) {
466             sptr<IMSCall> imsCall = reinterpret_cast<IMSCall *>(call.GetRefPtr());
467             if (imsCall != nullptr && imsCall->IsVoiceModifyToVideo()) {
468                 TELEPHONY_LOGI("hangup call during voice to video when answerCall");
469                 call->HangUpCall();
470                 return;
471             }
472             TELEPHONY_LOGI("enter zero active call hold");
473             call->HoldCall();
474             flagForConference = true;
475         } else if (incomingCall->GetAutoAnswerState() &&
476                    (call->GetTelCallState() == TelCallState ::CALL_STATUS_INCOMING ||
477                        call->GetTelCallState() == TelCallState ::CALL_STATUS_WAITING)) {
478             TELEPHONY_LOGI("enter two incoming call active");
479             incomingCall->AnswerCall(static_cast<int32_t>(incomingCall->GetVideoStateType()));
480             incomingCall->SetAutoAnswerState(false);
481         }
482     }
483 }
484 
DisconnectOtherSubIdCall(int32_t callId,int32_t slotId,int32_t videoState)485 void CallRequestProcess::DisconnectOtherSubIdCall(int32_t callId, int32_t slotId, int32_t videoState)
486 {
487     sptr<CallBase> incomingCall = GetOneCallObject(callId);
488     if (incomingCall == nullptr) {
489         TELEPHONY_LOGE("the call object is nullptr, callId:%{public}d", callId);
490         return;
491     }
492     std::list<int32_t> callIdList;
493     bool noOtherCall = true;
494     GetCarrierCallList(callIdList);
495     if (callIdList.size() > 1) {
496         for (int32_t otherCallId : callIdList) {
497             sptr<CallBase> call = GetOneCallObject(otherCallId);
498             if (call != nullptr && call->GetSlotId() != slotId) {
499                 incomingCall->SetAutoAnswerState(true);
500                 TELEPHONY_LOGI("Hangup call callid:%{public}d", call->GetCallID());
501                 call->HangUpCall();
502                 noOtherCall = false;
503             }
504         }
505     }
506     if (noOtherCall == true) {
507         int32_t ret = incomingCall->AnswerCall(videoState);
508         if (ret != TELEPHONY_SUCCESS) {
509             return;
510         }
511         DelayedSingleton<CallControlManager>::GetInstance()->NotifyIncomingCallAnswered(incomingCall);
512     }
513 }
514 
DisconnectOtherCallForVideoCall(int32_t callId)515 void CallRequestProcess::DisconnectOtherCallForVideoCall(int32_t callId)
516 {
517     std::list<int32_t> callIdList;
518     GetCarrierCallList(callIdList);
519     for (int32_t otherCallId : callIdList) {
520         sptr<CallBase> call = GetOneCallObject(otherCallId);
521         if (call != nullptr && call->GetCallID() != callId &&
522             (call->GetCallRunningState() == CallRunningState::CALL_RUNNING_STATE_ACTIVE ||
523                 call->GetCallRunningState() == CallRunningState::CALL_RUNNING_STATE_DIALING ||
524                 call->GetCallRunningState() == CallRunningState::CALL_RUNNING_STATE_HOLD)) {
525             TELEPHONY_LOGI("Hangup call callid:%{public}d", call->GetCallID());
526             call->HangUpCall();
527         }
528     }
529 }
530 
RejectRequest(int32_t callId,bool isSendSms,std::string & content)531 void CallRequestProcess::RejectRequest(int32_t callId, bool isSendSms, std::string &content)
532 {
533     sptr<CallBase> call = GetOneCallObject(callId);
534     if (call == nullptr) {
535         TELEPHONY_LOGE("the call object is nullptr, callId:%{public}d", callId);
536         return;
537     }
538 
539     int32_t ret = call->RejectCall();
540     if (ret != TELEPHONY_SUCCESS) {
541         TELEPHONY_LOGE("RejectCall failed!");
542         return;
543     }
544     std::list<int32_t> callIdList;
545     GetCarrierCallList(callIdList);
546     sptr<CallBase> holdCall = CallObjectManager::GetOneCallObject(CallRunningState::CALL_RUNNING_STATE_HOLD);
547     if (holdCall) {
548         TELEPHONY_LOGI("release the incoming/waiting call but can not recover the held call");
549         holdCall->SetCanUnHoldState(false);
550     }
551     TELEPHONY_LOGI("start to send reject message...");
552     DelayedSingleton<CallControlManager>::GetInstance()->NotifyIncomingCallRejected(call, isSendSms, content);
553 }
554 
HangUpRequest(int32_t callId)555 void CallRequestProcess::HangUpRequest(int32_t callId)
556 {
557     sptr<CallBase> call = GetOneCallObject(callId);
558     if (call == nullptr) {
559         TELEPHONY_LOGE("the call object is nullptr, callId:%{public}d", callId);
560         return;
561     }
562     int32_t waitingCallNum = GetCallNum(TelCallState::CALL_STATUS_WAITING);
563     TelCallState state = call->GetTelCallState();
564     TelConferenceState confState = call->GetTelConferenceState();
565     if ((((state == TelCallState::CALL_STATUS_ACTIVE) &&
566         (CallObjectManager::IsCallExist(call->GetCallType(), TelCallState::CALL_STATUS_HOLDING))) ||
567         (confState == TelConferenceState::TEL_CONFERENCE_ACTIVE)) && waitingCallNum == 0) {
568         if (HangUpForDsdaRequest(call)) {
569             TELEPHONY_LOGI("hangup for dsda Request success");
570         } else {
571             TELEPHONY_LOGI("release the active call and recover the held call");
572             call->SetPolicyFlag(PolicyFlag::POLICY_FLAG_HANG_UP_ACTIVE);
573         }
574     } else if (confState == TelConferenceState::TEL_CONFERENCE_HOLDING && waitingCallNum == 0) {
575         TELEPHONY_LOGI("release the held call and the wait call");
576         call->SetPolicyFlag(PolicyFlag::POLICY_FLAG_HANG_UP_HOLD_WAIT);
577     } else if (((confState == TelConferenceState::TEL_CONFERENCE_HOLDING) ||
578         (confState == TelConferenceState::TEL_CONFERENCE_ACTIVE)) && waitingCallNum != 0) {
579         TELEPHONY_LOGI("conference call and holding state, hangup conference call");
580         std::vector<std::u16string> callIdList;
581         call->GetSubCallIdList(callIdList);
582         for (auto it = callIdList.begin(); it != callIdList.end(); ++it) {
583             int32_t callId = -1;
584             StrToInt(Str16ToStr8(*it), callId);
585             KickOutFromConferenceRequest(callId);
586         }
587     }
588     call->HangUpCall();
589 }
590 
HangUpForDsdaRequest(sptr<CallBase> call)591 bool CallRequestProcess::HangUpForDsdaRequest(sptr<CallBase> call)
592 {
593     int32_t dsdsMode = DSDS_MODE_V2;
594     DelayedRefSingleton<CoreServiceClient>::GetInstance().GetDsdsMode(dsdsMode);
595     bool noOtherCall = true;
596     std::list<int32_t> allCallIdList;
597     GetCarrierCallList(allCallIdList);
598     IsExistCallOtherSlot(allCallIdList, call->GetSlotId(), noOtherCall);
599     if ((dsdsMode == static_cast<int32_t>(DsdsMode::DSDS_MODE_V5_DSDA) ||
600             dsdsMode == static_cast<int32_t>(DsdsMode::DSDS_MODE_V5_TDM)) &&
601         (!noOtherCall)) {
602         TELEPHONY_LOGI("release the active call but not recover the held call for dsda");
603         std::vector<std::u16string> callIdList;
604         call->GetSubCallIdList(callIdList);
605         for (auto it = callIdList.begin(); it != callIdList.end(); ++it) {
606             int32_t callId = -1;
607             StrToInt(Str16ToStr8(*it), callId);
608             KickOutFromConferenceRequest(callId);
609         }
610         return true;
611     }
612     return false;
613 }
614 
HoldRequest(int32_t callId)615 void CallRequestProcess::HoldRequest(int32_t callId)
616 {
617     sptr<CallBase> call = GetOneCallObject(callId);
618     if (call == nullptr) {
619         TELEPHONY_LOGE("the call object is nullptr, callId:%{public}d", callId);
620         return;
621     }
622     call->HoldCall();
623 }
624 
UnHoldRequest(int32_t callId)625 void CallRequestProcess::UnHoldRequest(int32_t callId)
626 {
627     TELEPHONY_LOGI("Enter UnHoldRequest");
628     sptr<CallBase> call = GetOneCallObject(callId);
629     if (call == nullptr) {
630         TELEPHONY_LOGE("the call object is nullptr, callId:%{public}d", callId);
631         return;
632     }
633     call->SetCanUnHoldState(true);
634     bool noOtherCall = true;
635     std::list<int32_t> callIdList;
636     GetCarrierCallList(callIdList);
637     IsExistCallOtherSlot(callIdList, call->GetSlotId(), noOtherCall);
638     for (int32_t otherCallId : callIdList) {
639         sptr<CallBase> otherCall = GetOneCallObject(otherCallId);
640         if (otherCall == nullptr) {
641             TELEPHONY_LOGE("otherCall is nullptr");
642             return;
643         }
644         TelCallState state = otherCall->GetTelCallState();
645         TelConferenceState confState = otherCall->GetTelConferenceState();
646         int32_t conferenceId = ERR_ID;
647         otherCall->GetMainCallId(conferenceId);
648         TELEPHONY_LOGI("otherCall->GetTelCallState(): %{public}d ,callid:%{public}d", state, otherCallId);
649         if (IsDsdsMode5() && !noOtherCall && state == TelCallState::CALL_STATUS_ACTIVE &&
650             ((confState != TelConferenceState::TEL_CONFERENCE_IDLE && conferenceId == otherCallId) ||
651                 confState == TelConferenceState::TEL_CONFERENCE_IDLE)) {
652             if (otherCall->GetCanSwitchCallState()) {
653                 TELEPHONY_LOGI("Hold other call in other slotId for switch Dsda call");
654                 otherCall->SetCanSwitchCallState(false);
655                 otherCall->HoldCall();
656                 return;
657             } else {
658                 TELEPHONY_LOGI("Currently can not swap this call");
659                 return;
660             }
661         }
662     }
663     if (noOtherCall) {
664         call->UnHoldCall();
665     }
666 }
667 
SwitchRequest(int32_t callId)668 void CallRequestProcess::SwitchRequest(int32_t callId)
669 {
670     sptr<CallBase> call = GetOneCallObject(callId);
671     if (call == nullptr) {
672         TELEPHONY_LOGE("the call object is nullptr, callId:%{public}d", callId);
673         return;
674     }
675     call->SwitchCall();
676 }
677 
CombineConferenceRequest(int32_t mainCallId)678 void CallRequestProcess::CombineConferenceRequest(int32_t mainCallId)
679 {
680     sptr<CallBase> call = GetOneCallObject(mainCallId);
681     if (call == nullptr) {
682         TELEPHONY_LOGE("the call object is nullptr, mainCallId:%{public}d", mainCallId);
683         return;
684     }
685     int32_t ret = call->CombineConference();
686     if (ret != TELEPHONY_SUCCESS) {
687         TELEPHONY_LOGE("CombineConference failed");
688     }
689 }
690 
SeparateConferenceRequest(int32_t callId)691 void CallRequestProcess::SeparateConferenceRequest(int32_t callId)
692 {
693     sptr<CallBase> call = GetOneCallObject(callId);
694     if (call == nullptr) {
695         TELEPHONY_LOGE("the call object is nullptr, callId:%{public}d", callId);
696         return;
697     }
698     int32_t ret = call->SeparateConference();
699     if (ret != TELEPHONY_SUCCESS) {
700         TELEPHONY_LOGE("SeparateConference failed");
701     }
702 }
703 
KickOutFromConferenceRequest(int32_t callId)704 void CallRequestProcess::KickOutFromConferenceRequest(int32_t callId)
705 {
706     sptr<CallBase> call = GetOneCallObject(callId);
707     if (call == nullptr) {
708         TELEPHONY_LOGE("the call object is nullptr, callId:%{public}d", callId);
709         return;
710     }
711     int32_t ret = call->KickOutFromConference();
712     if (ret != TELEPHONY_SUCCESS) {
713         TELEPHONY_LOGE("KickOutFormConference failed");
714     }
715 }
716 
StartRttRequest(int32_t callId,std::u16string & msg)717 void CallRequestProcess::StartRttRequest(int32_t callId, std::u16string &msg)
718 {
719     sptr<CallBase> call = GetOneCallObject(callId);
720     if (call == nullptr) {
721         TELEPHONY_LOGE("the call object is nullptr, callId:%{public}d", callId);
722         return;
723     }
724     if (call->GetCallType() != CallType::TYPE_IMS) {
725         TELEPHONY_LOGE("Unsupported Network type, callId:%{public}d", callId);
726         return;
727     } else {
728         sptr<IMSCall> imsCall = reinterpret_cast<IMSCall *>(call.GetRefPtr());
729         imsCall->StartRtt(msg);
730     }
731 }
732 
StopRttRequest(int32_t callId)733 void CallRequestProcess::StopRttRequest(int32_t callId)
734 {
735     sptr<CallBase> call = GetOneCallObject(callId);
736     if (call == nullptr) {
737         TELEPHONY_LOGE("the call object is nullptr, callId:%{public}d", callId);
738         return;
739     }
740     if (call->GetCallType() != CallType::TYPE_IMS) {
741         TELEPHONY_LOGE("Unsupported Network type, callId:%{public}d", callId);
742         return;
743     } else {
744         sptr<IMSCall> imsCall = reinterpret_cast<IMSCall *>(call.GetRefPtr());
745         imsCall->StopRtt();
746     }
747 }
748 
JoinConference(int32_t callId,std::vector<std::string> & numberList)749 void CallRequestProcess::JoinConference(int32_t callId, std::vector<std::string> &numberList)
750 {
751     sptr<CallBase> call = GetOneCallObject(callId);
752     if (call == nullptr) {
753         TELEPHONY_LOGE("the call object is nullptr, callId:%{public}d", callId);
754         return;
755     }
756     int32_t ret =
757         DelayedSingleton<CellularCallConnection>::GetInstance()->InviteToConference(numberList, call->GetSlotId());
758     if (ret != TELEPHONY_SUCCESS) {
759         TELEPHONY_LOGE("Invite to conference failed!");
760         return;
761     }
762 }
763 
UpdateCallReportInfo(const DialParaInfo & info,TelCallState state)764 int32_t CallRequestProcess::UpdateCallReportInfo(const DialParaInfo &info, TelCallState state)
765 {
766     CallDetailInfo callDetatilInfo;
767     if (memset_s(&callDetatilInfo, sizeof(CallDetailInfo), 0, sizeof(CallDetailInfo)) != EOK) {
768         TELEPHONY_LOGE("memset_s callDetatilInfo fail");
769         return TELEPHONY_ERR_MEMSET_FAIL;
770     }
771     callDetatilInfo.callType = info.callType;
772     callDetatilInfo.accountId = info.accountId;
773     callDetatilInfo.index = info.index;
774     callDetatilInfo.state = state;
775     callDetatilInfo.callMode = info.videoState;
776     callDetatilInfo.originalCallType = info.originalCallType;
777     callDetatilInfo.voiceDomain = static_cast<int32_t>(info.callType);
778     callDetatilInfo.phoneOrWatch = info.phoneOrWatch;
779     if (info.number.length() > kMaxNumberLen) {
780         TELEPHONY_LOGE("numbser length out of range");
781         return CALL_ERR_NUMBER_OUT_OF_RANGE;
782     }
783     if (memcpy_s(&callDetatilInfo.phoneNum, kMaxNumberLen, info.number.c_str(), info.number.length()) != EOK) {
784         TELEPHONY_LOGE("memcpy_s number failed!");
785         return TELEPHONY_ERR_MEMCPY_FAIL;
786     }
787     return DelayedSingleton<ReportCallInfoHandler>::GetInstance()->UpdateCallReportInfo(callDetatilInfo);
788 }
789 
HandleDialFail()790 int32_t CallRequestProcess::HandleDialFail()
791 {
792     std::unique_lock<std::mutex> lock(mutex_);
793     sptr<CallBase> call = nullptr;
794     while (!isFirstDialCallAdded_) {
795         if (cv_.wait_for(lock, std::chrono::seconds(WAIT_TIME_ONE_SECOND)) == std::cv_status::timeout) {
796             TELEPHONY_LOGE("CarrierDialProcess call is not added");
797             GetDialingCall(call);
798             if (call != nullptr) {
799                 DealFailDial(call);
800             }
801             return CALL_ERR_DIAL_FAILED;
802         }
803     }
804     GetDialingCall(call);
805     if (call != nullptr) {
806         return DealFailDial(call);
807     }
808     TELEPHONY_LOGE("can not find connect call or dialing call");
809     return CALL_ERR_CALL_STATE;
810 }
811 
GetDialingCall(sptr<CallBase> & call)812 void CallRequestProcess::GetDialingCall(sptr<CallBase> &call)
813 {
814     call = GetOneCarrierCallObject(CallRunningState::CALL_RUNNING_STATE_CREATE);
815     if (call != nullptr) {
816         return;
817     }
818     call = GetOneCarrierCallObject(CallRunningState::CALL_RUNNING_STATE_CONNECTING);
819     if (call != nullptr) {
820         return;
821     }
822     call = GetOneCarrierCallObject(CallRunningState::CALL_RUNNING_STATE_DIALING);
823     return;
824 }
825 
CarrierDialProcess(DialParaInfo & info)826 int32_t CallRequestProcess::CarrierDialProcess(DialParaInfo &info)
827 {
828     auto callRequestEventHandler = DelayedSingleton<CallRequestEventHandlerHelper>::GetInstance();
829     if (callRequestEventHandler->IsDialingCallProcessing()) {
830         return CALL_ERR_CALL_COUNTS_EXCEED_LIMIT;
831     }
832     callRequestEventHandler->RestoreDialingFlag(true);
833     callRequestEventHandler->SetDialingCallProcessing();
834     std::string newPhoneNum =
835         DelayedSingleton<CallNumberUtils>::GetInstance()->RemoveSeparatorsPhoneNumber(info.number);
836     int32_t ret = HandleDialingInfo(newPhoneNum, info);
837     if (ret != TELEPHONY_SUCCESS) {
838         TELEPHONY_LOGE("HandleDialingInfo failed!");
839         callRequestEventHandler->RestoreDialingFlag(false);
840         callRequestEventHandler->RemoveEventHandlerTask();
841         needWaitHold_ = false;
842         return ret;
843     }
844     std::string tempNumber = info.number;
845     bool isMMiCode = false;
846     if (!info.isEcc) {
847         isMMiCode = DelayedSingleton<CellularCallConnection>::GetInstance()->IsMmiCode(info.accountId, newPhoneNum);
848     }
849     if (!isMMiCode) {
850         isFirstDialCallAdded_ = false;
851         info.number = newPhoneNum;
852         ret = UpdateCallReportInfo(info, TelCallState::CALL_STATUS_DIALING);
853         info.number = tempNumber;
854         if (ret != TELEPHONY_SUCCESS) {
855             TELEPHONY_LOGE("UpdateCallReportInfo failed!");
856             needWaitHold_ = false;
857             return ret;
858         }
859     } else {
860         callRequestEventHandler->RestoreDialingFlag(false);
861         callRequestEventHandler->RemoveEventHandlerTask();
862         TELEPHONY_LOGI("CarrierDialProcess: isMMiCode is true!");
863         DelayedSingleton<CallDialog>::GetInstance()->DialogProcessMMICodeExtension();
864     }
865     return HandleStartDial(isMMiCode, info);
866 }
867 
HandleDialingInfo(std::string newPhoneNum,DialParaInfo & info)868 int32_t CallRequestProcess::HandleDialingInfo(std::string newPhoneNum, DialParaInfo &info)
869 {
870     bool isEcc = false;
871     int32_t ret = HandleEccCallForDsda(newPhoneNum, info, isEcc);
872     if (ret != TELEPHONY_SUCCESS) {
873         return ret;
874     }
875     if (!isEcc) {
876         bool canDial = true;
877         IsNewCallAllowedCreate(canDial);
878         if (!canDial) {
879             CallManagerHisysevent::WriteDialCallFaultEvent(info.accountId, static_cast<int32_t>(info.callType),
880                 static_cast<int32_t>(info.videoState),
881                 static_cast<int32_t>(CallErrorCode::CALL_ERROR_CALL_COUNTS_EXCEED_LIMIT), "Already a new call");
882             return CALL_ERR_CALL_COUNTS_EXCEED_LIMIT;
883         }
884         if (IsDsdsMode5()) {
885             ret = IsDialCallForDsda(info);
886             if (ret != TELEPHONY_SUCCESS) {
887                 TELEPHONY_LOGE("IsDialCallForDsda failed!");
888                 return ret;
889             }
890         }
891     }
892     return TELEPHONY_SUCCESS;
893 }
894 
HandleStartDial(bool isMMiCode,DialParaInfo & info)895 int32_t CallRequestProcess::HandleStartDial(bool isMMiCode, DialParaInfo &info)
896 {
897     CellularCallInfo callInfo;
898     int32_t ret = PackCellularCallInfo(info, callInfo);
899     if (ret != TELEPHONY_SUCCESS) {
900         TELEPHONY_LOGW("PackCellularCallInfo failed!");
901         CallManagerHisysevent::WriteDialCallFaultEvent(info.accountId, static_cast<int32_t>(info.callType),
902             static_cast<int32_t>(info.videoState), ret, "Carrier type PackCellularCallInfo failed");
903         needWaitHold_ = false;
904         return ret;
905     }
906     if (needWaitHold_ && !isMMiCode) {
907         TELEPHONY_LOGI("waitting for call hold");
908         dialCallInfo_ = callInfo;
909         return ret;
910     }
911     ret = DelayedSingleton<CellularCallConnection>::GetInstance()->Dial(callInfo);
912     if (ret != TELEPHONY_SUCCESS) {
913         TELEPHONY_LOGE("Dial failed!");
914         if (isMMiCode) {
915             return ret;
916         }
917         int32_t handleRet = HandleDialFail();
918         if (handleRet != TELEPHONY_SUCCESS) {
919             TELEPHONY_LOGE("HandleDialFail failed!");
920             return handleRet;
921         }
922         return ret;
923     }
924     return TELEPHONY_SUCCESS;
925 }
926 
IsDialCallForDsda(DialParaInfo & info)927 int32_t CallRequestProcess::IsDialCallForDsda(DialParaInfo &info)
928 {
929     sptr<CallBase> activeCall = GetOneCarrierCallObject(CallRunningState::CALL_RUNNING_STATE_ACTIVE);
930     TELEPHONY_LOGI("Is dsdsmode5 dial call info.accountId = %{public}d", info.accountId);
931     if (activeCall != nullptr && activeCall->GetSlotId() != info.accountId) {
932         int32_t ret = activeCall->HoldCall();
933         if (ret == TELEPHONY_SUCCESS) {
934             needWaitHold_ = true;
935         }
936         return ret;
937     }
938     return TELEPHONY_SUCCESS;
939 }
940 
HandleEccCallForDsda(std::string newPhoneNum,DialParaInfo & info,bool & isEcc)941 int32_t CallRequestProcess::HandleEccCallForDsda(std::string newPhoneNum, DialParaInfo &info, bool &isEcc)
942 {
943     int32_t ret =
944         DelayedSingleton<CallNumberUtils>::GetInstance()->CheckNumberIsEmergency(newPhoneNum, info.accountId, isEcc);
945     TELEPHONY_LOGE("CheckNumberIsEmergency ret is %{public}d, isEcc: %{public}d", ret, isEcc);
946     if (isEcc) {
947         return EccDialPolicy();
948     }
949     return TELEPHONY_SUCCESS;
950 }
951 
VoiceMailDialProcess(DialParaInfo & info)952 int32_t CallRequestProcess::VoiceMailDialProcess(DialParaInfo &info)
953 {
954     return CarrierDialProcess(info);
955 }
956 
OttDialProcess(DialParaInfo & info)957 int32_t CallRequestProcess::OttDialProcess(DialParaInfo &info)
958 {
959     AppExecFwk::PacMap callInfo;
960     callInfo.PutStringValue("phoneNumber", info.number);
961     callInfo.PutStringValue("bundleName", info.bundleName);
962     callInfo.PutIntValue("videoState", static_cast<int32_t>(info.videoState));
963     int32_t ret = DelayedSingleton<CallAbilityReportProxy>::GetInstance()->OttCallRequest(
964         OttCallRequestId::OTT_REQUEST_DIAL, callInfo);
965     if (ret != TELEPHONY_SUCCESS) {
966         TELEPHONY_LOGE("OTT call Dial failed!");
967         return ret;
968     }
969     return TELEPHONY_SUCCESS;
970 }
971 
PackCellularCallInfo(DialParaInfo & info,CellularCallInfo & callInfo)972 int32_t CallRequestProcess::PackCellularCallInfo(DialParaInfo &info, CellularCallInfo &callInfo)
973 {
974     callInfo.callId = info.callId;
975     callInfo.accountId = info.accountId;
976     callInfo.callType = info.callType;
977     callInfo.videoState = static_cast<int32_t>(info.videoState);
978     callInfo.index = info.index;
979     callInfo.slotId = info.accountId;
980     if (memset_s(callInfo.phoneNum, kMaxNumberLen, 0, kMaxNumberLen) != EOK) {
981         TELEPHONY_LOGW("memset_s failed!");
982         return TELEPHONY_ERR_MEMSET_FAIL;
983     }
984     if (info.number.length() > static_cast<size_t>(kMaxNumberLen)) {
985         TELEPHONY_LOGE("Number out of limit!");
986         return CALL_ERR_NUMBER_OUT_OF_RANGE;
987     }
988     if (memcpy_s(callInfo.phoneNum, kMaxNumberLen, info.number.c_str(), info.number.length()) != EOK) {
989         TELEPHONY_LOGE("memcpy_s failed!");
990         return TELEPHONY_ERR_MEMCPY_FAIL;
991     }
992     return TELEPHONY_SUCCESS;
993 }
994 
IsFdnNumber(std::vector<std::u16string> fdnNumberList,std::string phoneNumber)995 bool CallRequestProcess::IsFdnNumber(std::vector<std::u16string> fdnNumberList, std::string phoneNumber)
996 {
997     std::string withoutSpaceNumber = phoneNumber;
998     withoutSpaceNumber.erase(std::remove(withoutSpaceNumber.begin(),
999         withoutSpaceNumber.end(), ' '), withoutSpaceNumber.end());
1000     for (const auto& fdnNumber : fdnNumberList) {
1001         if (withoutSpaceNumber.compare(Str16ToStr8(fdnNumber)) == 0) {
1002             TELEPHONY_LOGI("you are allowed to dial!");
1003             return true;
1004         }
1005     }
1006     TELEPHONY_LOGW("There is no fixed number.");
1007     return false;
1008 }
1009 
EccDialPolicy()1010 int32_t CallRequestProcess::EccDialPolicy()
1011 {
1012     std::list<int32_t> callIdList;
1013     std::list<sptr<CallBase>> hangupList;
1014     std::list<sptr<CallBase>> rejectList;
1015     GetCarrierCallList(callIdList);
1016     for (int32_t callId : callIdList) {
1017         sptr<CallBase> call = GetOneCallObject(callId);
1018         if (call == nullptr) {
1019             continue;
1020         }
1021         CallRunningState crState = call->GetCallRunningState();
1022         if (call->GetCallType() == CallType::TYPE_SATELLITE) {
1023             hangupList.emplace_back(call);
1024         } else if (crState == CallRunningState::CALL_RUNNING_STATE_CREATE ||
1025             crState == CallRunningState::CALL_RUNNING_STATE_CONNECTING ||
1026             crState == CallRunningState::CALL_RUNNING_STATE_DIALING) {
1027             if (call->GetEmergencyState()) {
1028                 hangupList.clear();
1029                 rejectList.clear();
1030                 TELEPHONY_LOGE("already has ecc call dailing!");
1031                 return CALL_ERR_CALL_COUNTS_EXCEED_LIMIT;
1032             }
1033             hangupList.emplace_back(call);
1034         } else if (crState == CallRunningState::CALL_RUNNING_STATE_RINGING) {
1035             rejectList.emplace_back(call);
1036         } else if (crState == CallRunningState::CALL_RUNNING_STATE_ACTIVE ||
1037             crState == CallRunningState::CALL_RUNNING_STATE_HOLD) {
1038             hangupList.emplace_back(call);
1039         }
1040     }
1041     for (sptr<CallBase> call : hangupList) {
1042         int32_t callId = call->GetCallID();
1043         CallRunningState crState = call->GetCallRunningState();
1044         TELEPHONY_LOGE("HangUpCall call[id:%{public}d crState:%{public}d]", callId, crState);
1045         call->HangUpCall();
1046     }
1047     for (sptr<CallBase> call : rejectList) {
1048         int32_t callId = call->GetCallID();
1049         CallRunningState crState = call->GetCallRunningState();
1050         TELEPHONY_LOGE("RejectCall call[id:%{public}d crState:%{public}d]", callId, crState);
1051         call->RejectCall();
1052     }
1053     hangupList.clear();
1054     return TELEPHONY_SUCCESS;
1055 }
1056 
BluetoothDialProcess(DialParaInfo & info)1057 int32_t CallRequestProcess::BluetoothDialProcess(DialParaInfo &info)
1058 {
1059     TELEPHONY_LOGI("CallRequestProcess BluetoothDialProcess start");
1060     bool isEcc = false;
1061     DelayedSingleton<CallNumberUtils>::GetInstance()->CheckNumberIsEmergency(info.number, info.accountId, isEcc);
1062     if (!isEcc && CallObjectManager::HasCallExist()) {
1063         TELEPHONY_LOGW("BluetoothCall Dial has Call Exist.");
1064         return CALL_ERR_CALL_COUNTS_EXCEED_LIMIT;
1065     }
1066     auto callRequestEventHandler = DelayedSingleton<CallRequestEventHandlerHelper>::GetInstance();
1067     if (callRequestEventHandler->IsDialingCallProcessing()) {
1068         TELEPHONY_LOGW("BluetoothCall Dial has Call Exist.");
1069         return CALL_ERR_CALL_COUNTS_EXCEED_LIMIT;
1070     }
1071     callRequestEventHandler->RestoreDialingFlag(true);
1072     callRequestEventHandler->SetDialingCallProcessing();
1073     int32_t ret = DelayedSingleton<BluetoothCallConnection>::GetInstance()->Dial(info);
1074     if (ret == TELEPHONY_SUCCESS) {
1075         TELEPHONY_LOGI("BluetoothCall Dial Success.");
1076         info.index = INIT_INDEX;
1077         ret = UpdateCallReportInfo(info, TelCallState::CALL_STATUS_DIALING);
1078     } else {
1079         TELEPHONY_LOGE("BluetoothCall Dial failed. errorcode=%{public}d", ret);
1080         callRequestEventHandler->RestoreDialingFlag(false);
1081         callRequestEventHandler->RemoveEventHandlerTask();
1082     }
1083     return ret;
1084 }
1085 } // namespace Telephony
1086 } // namespace OHOS
1087