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