1 /*
2 * Copyright (C) 2021 - 2023 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
26 namespace OHOS {
27 namespace Telephony {
CallRequestHandler()28 CallRequestHandler::CallRequestHandler() {}
29
~CallRequestHandler()30 CallRequestHandler::~CallRequestHandler() {}
31
Init()32 void CallRequestHandler::Init()
33 {
34 callRequestProcessPtr_ = std::make_shared<CallRequestProcess>();
35 return;
36 }
37
DialCall()38 int32_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
AnswerCall(int32_t callId,int32_t videoState)47 int32_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
RejectCall(int32_t callId,bool isSendSms,std::string & content)57 int32_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
HangUpCall(int32_t callId)70 int32_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
HoldCall(int32_t callId)80 int32_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
UnHoldCall(int32_t callId)90 int32_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
SwitchCall(int32_t callId)100 int32_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
StartRtt(int32_t callId,std::u16string & msg)110 int32_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
StopRtt(int32_t callId)123 int32_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
JoinConference(int32_t callId,std::vector<std::string> & numberList)133 int32_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 ffrt::submit([=]() {
140 std::vector<std::string> mNumberList(numberList);
141 callRequestProcessPtr_->JoinConference(callId, mNumberList);
142 });
143 return TELEPHONY_SUCCESS;
144 }
145
CombineConference(int32_t mainCallId)146 int32_t CallRequestHandler::CombineConference(int32_t mainCallId)
147 {
148 if (callRequestProcessPtr_ == nullptr) {
149 TELEPHONY_LOGE("callRequestProcessPtr_ is nullptr");
150 return TELEPHONY_ERR_LOCAL_PTR_NULL;
151 }
152 ffrt::submit([=]() { callRequestProcessPtr_->CombineConferenceRequest(mainCallId); });
153 return TELEPHONY_SUCCESS;
154 }
155
SeparateConference(int32_t callId)156 int32_t CallRequestHandler::SeparateConference(int32_t callId)
157 {
158 if (callRequestProcessPtr_ == nullptr) {
159 TELEPHONY_LOGE("callRequestProcessPtr_ is nullptr");
160 return TELEPHONY_ERR_LOCAL_PTR_NULL;
161 }
162 ffrt::submit([=]() { callRequestProcessPtr_->SeparateConferenceRequest(callId); });
163 return TELEPHONY_SUCCESS;
164 }
165
KickOutFromConference(int32_t callId)166 int32_t CallRequestHandler::KickOutFromConference(int32_t callId)
167 {
168 if (callRequestProcessPtr_ == nullptr) {
169 TELEPHONY_LOGE("callRequestProcessPtr_ is nullptr");
170 return TELEPHONY_ERR_LOCAL_PTR_NULL;
171 }
172 ffrt::submit([=]() { callRequestProcessPtr_->KickOutFromConferenceRequest(callId); });
173 return TELEPHONY_SUCCESS;
174 }
175
UpdateImsCallMode(int32_t callId,ImsCallMode mode)176 int32_t CallRequestHandler::UpdateImsCallMode(int32_t callId, ImsCallMode mode)
177 {
178 if (callRequestProcessPtr_ == nullptr) {
179 TELEPHONY_LOGE("callRequestProcessPtr_ is nullptr");
180 return TELEPHONY_ERR_LOCAL_PTR_NULL;
181 }
182 ffrt::submit([=]() { callRequestProcessPtr_->UpdateCallMediaModeRequest(callId, mode); });
183 return TELEPHONY_SUCCESS;
184 }
185 } // namespace Telephony
186 } // namespace OHOS
187