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