1e1c44949Sopenharmony_ci/* 2e1c44949Sopenharmony_ci * Copyright (C) 2021-2024 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_handler.h" 17e1c44949Sopenharmony_ci 18e1c44949Sopenharmony_ci#include <securec.h> 19e1c44949Sopenharmony_ci#include <string_ex.h> 20e1c44949Sopenharmony_ci 21e1c44949Sopenharmony_ci#include "call_manager_errors.h" 22e1c44949Sopenharmony_ci#include "call_manager_hisysevent.h" 23e1c44949Sopenharmony_ci#include "ffrt.h" 24e1c44949Sopenharmony_ci#include "telephony_log_wrapper.h" 25e1c44949Sopenharmony_ci 26e1c44949Sopenharmony_cinamespace OHOS { 27e1c44949Sopenharmony_cinamespace Telephony { 28e1c44949Sopenharmony_ciCallRequestHandler::CallRequestHandler() {} 29e1c44949Sopenharmony_ci 30e1c44949Sopenharmony_ciCallRequestHandler::~CallRequestHandler() {} 31e1c44949Sopenharmony_ci 32e1c44949Sopenharmony_civoid CallRequestHandler::Init() 33e1c44949Sopenharmony_ci{ 34e1c44949Sopenharmony_ci callRequestProcessPtr_ = std::make_shared<CallRequestProcess>(); 35e1c44949Sopenharmony_ci return; 36e1c44949Sopenharmony_ci} 37e1c44949Sopenharmony_ci 38e1c44949Sopenharmony_ciint32_t CallRequestHandler::DialCall() 39e1c44949Sopenharmony_ci{ 40e1c44949Sopenharmony_ci if (callRequestProcessPtr_ == nullptr) { 41e1c44949Sopenharmony_ci TELEPHONY_LOGE("callRequestProcessPtr_ is nullptr"); 42e1c44949Sopenharmony_ci return TELEPHONY_ERR_LOCAL_PTR_NULL; 43e1c44949Sopenharmony_ci } 44e1c44949Sopenharmony_ci return callRequestProcessPtr_->DialRequest(); 45e1c44949Sopenharmony_ci} 46e1c44949Sopenharmony_ci 47e1c44949Sopenharmony_ciint32_t CallRequestHandler::AnswerCall(int32_t callId, int32_t videoState) 48e1c44949Sopenharmony_ci{ 49e1c44949Sopenharmony_ci if (callRequestProcessPtr_ == nullptr) { 50e1c44949Sopenharmony_ci TELEPHONY_LOGE("callRequestProcessPtr_ is nullptr"); 51e1c44949Sopenharmony_ci return TELEPHONY_ERR_LOCAL_PTR_NULL; 52e1c44949Sopenharmony_ci } 53e1c44949Sopenharmony_ci ffrt::submit([=]() { callRequestProcessPtr_->AnswerRequest(callId, videoState); }); 54e1c44949Sopenharmony_ci return TELEPHONY_SUCCESS; 55e1c44949Sopenharmony_ci} 56e1c44949Sopenharmony_ci 57e1c44949Sopenharmony_ciint32_t CallRequestHandler::RejectCall(int32_t callId, bool isSendSms, std::string &content) 58e1c44949Sopenharmony_ci{ 59e1c44949Sopenharmony_ci if (callRequestProcessPtr_ == nullptr) { 60e1c44949Sopenharmony_ci TELEPHONY_LOGE("callRequestProcessPtr_ is nullptr"); 61e1c44949Sopenharmony_ci return TELEPHONY_ERR_LOCAL_PTR_NULL; 62e1c44949Sopenharmony_ci } 63e1c44949Sopenharmony_ci ffrt::submit([=]() { 64e1c44949Sopenharmony_ci std::string mContent = content; 65e1c44949Sopenharmony_ci callRequestProcessPtr_->RejectRequest(callId, isSendSms, mContent); 66e1c44949Sopenharmony_ci }); 67e1c44949Sopenharmony_ci return TELEPHONY_SUCCESS; 68e1c44949Sopenharmony_ci} 69e1c44949Sopenharmony_ci 70e1c44949Sopenharmony_ciint32_t CallRequestHandler::HangUpCall(int32_t callId) 71e1c44949Sopenharmony_ci{ 72e1c44949Sopenharmony_ci if (callRequestProcessPtr_ == nullptr) { 73e1c44949Sopenharmony_ci TELEPHONY_LOGE("callRequestProcessPtr_ is nullptr"); 74e1c44949Sopenharmony_ci return TELEPHONY_ERR_LOCAL_PTR_NULL; 75e1c44949Sopenharmony_ci } 76e1c44949Sopenharmony_ci ffrt::submit([=]() { callRequestProcessPtr_->HangUpRequest(callId); }); 77e1c44949Sopenharmony_ci return TELEPHONY_SUCCESS; 78e1c44949Sopenharmony_ci} 79e1c44949Sopenharmony_ci 80e1c44949Sopenharmony_ciint32_t CallRequestHandler::HoldCall(int32_t callId) 81e1c44949Sopenharmony_ci{ 82e1c44949Sopenharmony_ci if (callRequestProcessPtr_ == nullptr) { 83e1c44949Sopenharmony_ci TELEPHONY_LOGE("callRequestProcessPtr_ is nullptr"); 84e1c44949Sopenharmony_ci return TELEPHONY_ERR_LOCAL_PTR_NULL; 85e1c44949Sopenharmony_ci } 86e1c44949Sopenharmony_ci ffrt::submit([=]() { callRequestProcessPtr_->HoldRequest(callId); }); 87e1c44949Sopenharmony_ci return TELEPHONY_SUCCESS; 88e1c44949Sopenharmony_ci} 89e1c44949Sopenharmony_ci 90e1c44949Sopenharmony_ciint32_t CallRequestHandler::UnHoldCall(int32_t callId) 91e1c44949Sopenharmony_ci{ 92e1c44949Sopenharmony_ci if (callRequestProcessPtr_ == nullptr) { 93e1c44949Sopenharmony_ci TELEPHONY_LOGE("callRequestProcessPtr_ is nullptr"); 94e1c44949Sopenharmony_ci return TELEPHONY_ERR_LOCAL_PTR_NULL; 95e1c44949Sopenharmony_ci } 96e1c44949Sopenharmony_ci ffrt::submit([=]() { callRequestProcessPtr_->UnHoldRequest(callId); }); 97e1c44949Sopenharmony_ci return TELEPHONY_SUCCESS; 98e1c44949Sopenharmony_ci} 99e1c44949Sopenharmony_ci 100e1c44949Sopenharmony_ciint32_t CallRequestHandler::SwitchCall(int32_t callId) 101e1c44949Sopenharmony_ci{ 102e1c44949Sopenharmony_ci if (callRequestProcessPtr_ == nullptr) { 103e1c44949Sopenharmony_ci TELEPHONY_LOGE("callRequestProcessPtr_ is nullptr"); 104e1c44949Sopenharmony_ci return TELEPHONY_ERR_LOCAL_PTR_NULL; 105e1c44949Sopenharmony_ci } 106e1c44949Sopenharmony_ci ffrt::submit([=]() { callRequestProcessPtr_->SwitchRequest(callId); }); 107e1c44949Sopenharmony_ci return TELEPHONY_SUCCESS; 108e1c44949Sopenharmony_ci} 109e1c44949Sopenharmony_ci 110e1c44949Sopenharmony_ciint32_t CallRequestHandler::StartRtt(int32_t callId, std::u16string &msg) 111e1c44949Sopenharmony_ci{ 112e1c44949Sopenharmony_ci if (callRequestProcessPtr_ == nullptr) { 113e1c44949Sopenharmony_ci TELEPHONY_LOGE("callRequestProcessPtr_ is nullptr"); 114e1c44949Sopenharmony_ci return TELEPHONY_ERR_LOCAL_PTR_NULL; 115e1c44949Sopenharmony_ci } 116e1c44949Sopenharmony_ci ffrt::submit([=]() { 117e1c44949Sopenharmony_ci std::u16string mMsg = msg; 118e1c44949Sopenharmony_ci callRequestProcessPtr_->StartRttRequest(callId, mMsg); 119e1c44949Sopenharmony_ci }); 120e1c44949Sopenharmony_ci return TELEPHONY_SUCCESS; 121e1c44949Sopenharmony_ci} 122e1c44949Sopenharmony_ci 123e1c44949Sopenharmony_ciint32_t CallRequestHandler::StopRtt(int32_t callId) 124e1c44949Sopenharmony_ci{ 125e1c44949Sopenharmony_ci if (callRequestProcessPtr_ == nullptr) { 126e1c44949Sopenharmony_ci TELEPHONY_LOGE("callRequestProcessPtr_ is nullptr"); 127e1c44949Sopenharmony_ci return TELEPHONY_ERR_LOCAL_PTR_NULL; 128e1c44949Sopenharmony_ci } 129e1c44949Sopenharmony_ci ffrt::submit([=]() { callRequestProcessPtr_->StopRttRequest(callId); }); 130e1c44949Sopenharmony_ci return TELEPHONY_SUCCESS; 131e1c44949Sopenharmony_ci} 132e1c44949Sopenharmony_ci 133e1c44949Sopenharmony_ciint32_t CallRequestHandler::JoinConference(int32_t callId, std::vector<std::string> &numberList) 134e1c44949Sopenharmony_ci{ 135e1c44949Sopenharmony_ci if (callRequestProcessPtr_ == nullptr) { 136e1c44949Sopenharmony_ci TELEPHONY_LOGE("callRequestProcessPtr_ is nullptr"); 137e1c44949Sopenharmony_ci return TELEPHONY_ERR_LOCAL_PTR_NULL; 138e1c44949Sopenharmony_ci } 139e1c44949Sopenharmony_ci std::weak_ptr<CallRequestProcess> callRequestProcessPtr = callRequestProcessPtr_; 140e1c44949Sopenharmony_ci ffrt::submit([callId, callRequestProcessPtr, numberList]() { 141e1c44949Sopenharmony_ci std::shared_ptr<CallRequestProcess> processPtr = callRequestProcessPtr.lock(); 142e1c44949Sopenharmony_ci std::vector<std::string> mNumberList(numberList); 143e1c44949Sopenharmony_ci if (processPtr == nullptr) { 144e1c44949Sopenharmony_ci TELEPHONY_LOGE("processPtr is null"); 145e1c44949Sopenharmony_ci return; 146e1c44949Sopenharmony_ci } 147e1c44949Sopenharmony_ci processPtr->JoinConference(callId, mNumberList); 148e1c44949Sopenharmony_ci }); 149e1c44949Sopenharmony_ci return TELEPHONY_SUCCESS; 150e1c44949Sopenharmony_ci} 151e1c44949Sopenharmony_ci 152e1c44949Sopenharmony_ciint32_t CallRequestHandler::CombineConference(int32_t mainCallId) 153e1c44949Sopenharmony_ci{ 154e1c44949Sopenharmony_ci if (callRequestProcessPtr_ == nullptr) { 155e1c44949Sopenharmony_ci TELEPHONY_LOGE("callRequestProcessPtr_ is nullptr"); 156e1c44949Sopenharmony_ci return TELEPHONY_ERR_LOCAL_PTR_NULL; 157e1c44949Sopenharmony_ci } 158e1c44949Sopenharmony_ci ffrt::submit([=]() { callRequestProcessPtr_->CombineConferenceRequest(mainCallId); }); 159e1c44949Sopenharmony_ci return TELEPHONY_SUCCESS; 160e1c44949Sopenharmony_ci} 161e1c44949Sopenharmony_ci 162e1c44949Sopenharmony_ciint32_t CallRequestHandler::SeparateConference(int32_t callId) 163e1c44949Sopenharmony_ci{ 164e1c44949Sopenharmony_ci if (callRequestProcessPtr_ == nullptr) { 165e1c44949Sopenharmony_ci TELEPHONY_LOGE("callRequestProcessPtr_ is nullptr"); 166e1c44949Sopenharmony_ci return TELEPHONY_ERR_LOCAL_PTR_NULL; 167e1c44949Sopenharmony_ci } 168e1c44949Sopenharmony_ci ffrt::submit([=]() { callRequestProcessPtr_->SeparateConferenceRequest(callId); }); 169e1c44949Sopenharmony_ci return TELEPHONY_SUCCESS; 170e1c44949Sopenharmony_ci} 171e1c44949Sopenharmony_ci 172e1c44949Sopenharmony_ciint32_t CallRequestHandler::KickOutFromConference(int32_t callId) 173e1c44949Sopenharmony_ci{ 174e1c44949Sopenharmony_ci if (callRequestProcessPtr_ == nullptr) { 175e1c44949Sopenharmony_ci TELEPHONY_LOGE("callRequestProcessPtr_ is nullptr"); 176e1c44949Sopenharmony_ci return TELEPHONY_ERR_LOCAL_PTR_NULL; 177e1c44949Sopenharmony_ci } 178e1c44949Sopenharmony_ci ffrt::submit([=]() { callRequestProcessPtr_->KickOutFromConferenceRequest(callId); }); 179e1c44949Sopenharmony_ci return TELEPHONY_SUCCESS; 180e1c44949Sopenharmony_ci} 181e1c44949Sopenharmony_ci} // namespace Telephony 182e1c44949Sopenharmony_ci} // namespace OHOS 183