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