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_manager_errors.h"
19 #include "telephony_log_wrapper.h"
20
21 #include "cs_call.h"
22 #include "ims_call.h"
23 #include "ott_call.h"
24 #include "common_type.h"
25 #include "call_control_manager.h"
26 #include "call_ability_report_proxy.h"
27 #include "core_service_connection.h"
28 #include "cellular_call_connection.h"
29
30 namespace OHOS {
31 namespace Telephony {
CallRequestProcess()32 CallRequestProcess::CallRequestProcess() {}
33
~CallRequestProcess()34 CallRequestProcess::~CallRequestProcess() {}
35
DialRequest()36 void CallRequestProcess::DialRequest()
37 {
38 DialParaInfo info;
39 DelayedSingleton<CallControlManager>::GetInstance()->GetDialParaInfo(info);
40 if (!info.isDialing) {
41 TELEPHONY_LOGE("the device is not dialing!");
42 return;
43 }
44 if (info.dialType == DialType::DIAL_CARRIER_TYPE) {
45 std::vector<std::u16string> fdnNumberList =
46 DelayedSingleton<CoreServiceConnection>::GetInstance()->GetFdnNumberList(info.accountId);
47 if (!fdnNumberList.empty() && !IsFdnNumber(fdnNumberList, info.number)) {
48 CallEventInfo eventInfo;
49 (void)memset_s(eventInfo.phoneNum, kMaxNumberLen, 0, kMaxNumberLen);
50 eventInfo.eventId = CallAbilityEventId::EVENT_INVALID_FDN_NUMBER;
51 (void)memcpy_s(eventInfo.phoneNum, kMaxNumberLen, info.number.c_str(), info.number.length());
52 DelayedSingleton<CallControlManager>::GetInstance()->NotifyCallEventUpdated(eventInfo);
53 TELEPHONY_LOGW("invalid fdn number!");
54 return;
55 }
56 }
57 TELEPHONY_LOGI("dialType:%{public}d", info.dialType);
58 switch (info.dialType) {
59 case DialType::DIAL_CARRIER_TYPE:
60 CarrierDialProcess(info);
61 break;
62 case DialType::DIAL_VOICE_MAIL_TYPE:
63 VoiceMailDialProcess(info);
64 break;
65 case DialType::DIAL_OTT_TYPE:
66 OttDialProcess(info);
67 break;
68 default:
69 TELEPHONY_LOGE("invalid dialType:%{public}d", info.dialType);
70 break;
71 }
72 }
73
AnswerRequest(int32_t callId,int32_t videoState)74 void CallRequestProcess::AnswerRequest(int32_t callId, int32_t videoState)
75 {
76 sptr<CallBase> call = GetOneCallObject(callId);
77 if (call == nullptr) {
78 TELEPHONY_LOGE("the call object is nullptr, callId:%{public}d", callId);
79 return;
80 }
81 int32_t ret = call->AnswerCall(videoState);
82 if (ret != TELEPHONY_SUCCESS) {
83 TELEPHONY_LOGE("AnswerCall failed!");
84 return;
85 }
86 DelayedSingleton<CallControlManager>::GetInstance()->NotifyIncomingCallAnswered(call);
87 }
88
RejectRequest(int32_t callId,bool isSendSms,std::string & content)89 void CallRequestProcess::RejectRequest(int32_t callId, bool isSendSms, std::string &content)
90 {
91 sptr<CallBase> call = GetOneCallObject(callId);
92 if (call == nullptr) {
93 TELEPHONY_LOGE("the call object is nullptr, callId:%{public}d", callId);
94 return;
95 }
96
97 int32_t ret = call->RejectCall();
98 if (ret != TELEPHONY_SUCCESS) {
99 TELEPHONY_LOGE("RejectCall failed!");
100 return;
101 }
102 TELEPHONY_LOGI("start to send reject message...");
103 DelayedSingleton<CallControlManager>::GetInstance()->NotifyIncomingCallRejected(call, isSendSms, content);
104 }
105
HangUpRequest(int32_t callId)106 void CallRequestProcess::HangUpRequest(int32_t callId)
107 {
108 sptr<CallBase> call = GetOneCallObject(callId);
109 if (call == nullptr) {
110 TELEPHONY_LOGE("the call object is nullptr, callId:%{public}d", callId);
111 return;
112 }
113 TelCallState state = call->GetTelCallState();
114 if ((state == TelCallState::CALL_STATUS_ACTIVE) &&
115 (CallObjectManager::IsCallExist(call->GetCallType(), TelCallState::CALL_STATUS_HOLDING))) {
116 TELEPHONY_LOGI("release the active call and recover the held call");
117 call->SetPolicyFlag(PolicyFlag::POLICY_FLAG_HANG_UP_ACTIVE);
118 }
119 call->HangUpCall();
120 if (state == TelCallState::CALL_STATUS_DIALING || state == TelCallState::CALL_STATUS_ALERTING) {
121 sptr<CallBase> holdCall = CallObjectManager::GetOneCallObject(CallRunningState::CALL_RUNNING_STATE_HOLD);
122 if (holdCall) {
123 TELEPHONY_LOGI("release the dialing/alerting call and recover the held call");
124 holdCall->UnHoldCall();
125 }
126 }
127 }
128
HoldRequest(int32_t callId)129 void CallRequestProcess::HoldRequest(int32_t callId)
130 {
131 sptr<CallBase> call = GetOneCallObject(callId);
132 if (call == nullptr) {
133 TELEPHONY_LOGE("the call object is nullptr, callId:%{public}d", callId);
134 return;
135 }
136 call->HoldCall();
137 }
138
UnHoldRequest(int32_t callId)139 void CallRequestProcess::UnHoldRequest(int32_t callId)
140 {
141 sptr<CallBase> call = GetOneCallObject(callId);
142 if (call == nullptr) {
143 TELEPHONY_LOGE("the call object is nullptr, callId:%{public}d", callId);
144 return;
145 }
146 call->UnHoldCall();
147 }
148
SwitchRequest(int32_t callId)149 void CallRequestProcess::SwitchRequest(int32_t callId)
150 {
151 sptr<CallBase> call = GetOneCallObject(callId);
152 if (call == nullptr) {
153 TELEPHONY_LOGE("the call object is nullptr, callId:%{public}d", callId);
154 return;
155 }
156 call->SwitchCall();
157 }
158
CombineConferenceRequest(int32_t mainCallId)159 void CallRequestProcess::CombineConferenceRequest(int32_t mainCallId)
160 {
161 sptr<CallBase> call = GetOneCallObject(mainCallId);
162 if (call == nullptr) {
163 TELEPHONY_LOGE("the call object is nullptr, mainCallId:%{public}d", mainCallId);
164 return;
165 }
166 int32_t ret = call->CombineConference();
167 if (ret != TELEPHONY_SUCCESS) {
168 TELEPHONY_LOGE("CombineConference failed");
169 }
170 }
171
SeparateConferenceRequest(int32_t callId)172 void CallRequestProcess::SeparateConferenceRequest(int32_t callId)
173 {
174 sptr<CallBase> call = GetOneCallObject(callId);
175 if (call == nullptr) {
176 TELEPHONY_LOGE("the call object is nullptr, callId:%{public}d", callId);
177 return;
178 }
179 int32_t ret = call->SeparateConference();
180 if (ret != TELEPHONY_SUCCESS) {
181 TELEPHONY_LOGE("SeparateConference failed");
182 }
183 }
184
UpdateImsCallMode(int32_t callId,ImsCallMode mode)185 int32_t CallRequestProcess::UpdateImsCallMode(int32_t callId, ImsCallMode mode)
186 {
187 int32_t ret = TELEPHONY_ERR_FAIL;
188 sptr<CallBase> call = GetOneCallObject(callId);
189 if (call == nullptr) {
190 TELEPHONY_LOGE("the call object is nullptr, callId:%{public}d", callId);
191 return ret;
192 }
193 // only netcall type support update call media mode
194 if (call->GetCallType() == CallType::TYPE_IMS) {
195 sptr<IMSCall> netCall = reinterpret_cast<IMSCall *>(call.GetRefPtr());
196 TELEPHONY_LOGI("ims call update media request");
197 ret = netCall->SendUpdateCallMediaModeRequest(mode);
198 if (ret != TELEPHONY_SUCCESS) {
199 TELEPHONY_LOGE("SendUpdateCallMediaModeRequest failed. %{public}d", ret);
200 }
201 } else {
202 TELEPHONY_LOGE("the call object not support upgrade/downgrad media, callId:%{public}d", callId);
203 }
204 return ret;
205 }
206
UpdateCallMediaModeRequest(int32_t callId,ImsCallMode mode)207 void CallRequestProcess::UpdateCallMediaModeRequest(int32_t callId, ImsCallMode mode)
208 {
209 int32_t ret = TELEPHONY_ERR_FAIL;
210 AppExecFwk::PacMap resultInfo;
211 ret = UpdateImsCallMode(callId, mode);
212 if (ret != TELEPHONY_SUCCESS) {
213 resultInfo.PutIntValue("result", ret);
214 DelayedSingleton<CallAbilityReportProxy>::GetInstance()->ReportAsyncResults(
215 CallResultReportId::UPDATE_MEDIA_MODE_REPORT_ID, resultInfo);
216 }
217 }
218
StartRttRequest(int32_t callId,std::u16string & msg)219 void CallRequestProcess::StartRttRequest(int32_t callId, std::u16string &msg)
220 {
221 sptr<CallBase> call = GetOneCallObject(callId);
222 if (call == nullptr) {
223 TELEPHONY_LOGE("the call object is nullptr, callId:%{public}d", callId);
224 return;
225 }
226 if (call->GetCallType() != CallType::TYPE_IMS) {
227 TELEPHONY_LOGE("Unsupported Network type, callId:%{public}d", callId);
228 return;
229 } else {
230 sptr<IMSCall> imsCall = reinterpret_cast<IMSCall *>(call.GetRefPtr());
231 imsCall->StartRtt(msg);
232 }
233 }
234
StopRttRequest(int32_t callId)235 void CallRequestProcess::StopRttRequest(int32_t callId)
236 {
237 sptr<CallBase> call = GetOneCallObject(callId);
238 if (call == nullptr) {
239 TELEPHONY_LOGE("the call object is nullptr, callId:%{public}d", callId);
240 return;
241 }
242 if (call->GetCallType() != CallType::TYPE_IMS) {
243 TELEPHONY_LOGE("Unsupported Network type, callId:%{public}d", callId);
244 return;
245 } else {
246 sptr<IMSCall> imsCall = reinterpret_cast<IMSCall *>(call.GetRefPtr());
247 imsCall->StopRtt();
248 }
249 }
250
JoinConference(int32_t callId,std::vector<std::string> & numberList)251 void CallRequestProcess::JoinConference(int32_t callId, std::vector<std::string> &numberList)
252 {
253 sptr<CallBase> call = GetOneCallObject(callId);
254 if (call == nullptr) {
255 TELEPHONY_LOGE("the call object is nullptr, callId:%{public}d", callId);
256 return;
257 }
258 int32_t ret =
259 DelayedSingleton<CellularCallConnection>::GetInstance()->InviteToConference(numberList, call->GetSlotId());
260 if (ret != TELEPHONY_SUCCESS) {
261 TELEPHONY_LOGE("Invite to conference failed!");
262 return;
263 }
264 }
265
CarrierDialProcess(DialParaInfo & info)266 void CallRequestProcess::CarrierDialProcess(DialParaInfo &info)
267 {
268 CellularCallInfo callInfo;
269 int32_t ret = PackCellularCallInfo(info, callInfo);
270 if (ret != TELEPHONY_SUCCESS) {
271 TELEPHONY_LOGW("PackCellularCallInfo failed!");
272 }
273 // Obtain gateway information
274 ret = DelayedSingleton<CellularCallConnection>::GetInstance()->Dial(callInfo);
275 if (ret != TELEPHONY_SUCCESS) {
276 TELEPHONY_LOGE("Dial failed!");
277 return;
278 }
279 }
280
VoiceMailDialProcess(DialParaInfo & info)281 void CallRequestProcess::VoiceMailDialProcess(DialParaInfo &info)
282 {
283 CellularCallInfo callInfo;
284 int32_t ret = PackCellularCallInfo(info, callInfo);
285 if (ret != TELEPHONY_SUCCESS) {
286 TELEPHONY_LOGW("PackCellularCallInfo failed!");
287 }
288 ret = DelayedSingleton<CellularCallConnection>::GetInstance()->Dial(callInfo);
289 if (ret != TELEPHONY_SUCCESS) {
290 TELEPHONY_LOGE("Dial VoiceMail failed!");
291 return;
292 }
293 }
294
OttDialProcess(DialParaInfo & info)295 void CallRequestProcess::OttDialProcess(DialParaInfo &info)
296 {
297 AppExecFwk::PacMap callInfo;
298 callInfo.PutStringValue("phoneNumber", info.number);
299 callInfo.PutStringValue("bundleName", info.bundleName);
300 callInfo.PutIntValue("videoState", static_cast<int32_t>(info.videoState));
301 int32_t ret = DelayedSingleton<CallAbilityReportProxy>::GetInstance()->OttCallRequest(
302 OttCallRequestId::OTT_REQUEST_DIAL, callInfo);
303 if (ret != TELEPHONY_SUCCESS) {
304 TELEPHONY_LOGE("OTT call Dial failed!");
305 return;
306 }
307 }
308
PackCellularCallInfo(DialParaInfo & info,CellularCallInfo & callInfo)309 int32_t CallRequestProcess::PackCellularCallInfo(DialParaInfo &info, CellularCallInfo &callInfo)
310 {
311 callInfo.callId = info.callId;
312 callInfo.accountId = info.accountId;
313 callInfo.callType = info.callType;
314 callInfo.videoState = static_cast<int32_t>(info.videoState);
315 callInfo.index = info.index;
316 callInfo.slotId = info.accountId;
317 if (memset_s(callInfo.phoneNum, kMaxNumberLen, 0, kMaxNumberLen) != EOK) {
318 TELEPHONY_LOGW("memset_s failed!");
319 return TELEPHONY_ERR_MEMSET_FAIL;
320 }
321 if (memcpy_s(callInfo.phoneNum, kMaxNumberLen, info.number.c_str(), info.number.length()) != EOK) {
322 TELEPHONY_LOGE("memcpy_s failed!");
323 return TELEPHONY_ERR_MEMCPY_FAIL;
324 }
325 return TELEPHONY_SUCCESS;
326 }
327
IsFdnNumber(std::vector<std::u16string> fdnNumberList,std::string phoneNumber)328 bool CallRequestProcess::IsFdnNumber(std::vector<std::u16string> fdnNumberList, std::string phoneNumber)
329 {
330 char number[kMaxNumberLen + 1] = {0};
331 int32_t j = 0;
332 for (int32_t i = 0; i < phoneNumber.length(); i++) {
333 if (i >= kMaxNumberLen) {
334 break;
335 }
336 if (*(phoneNumber.c_str() + i) != ' ') {
337 number[j++] = *(phoneNumber.c_str() + i);
338 }
339 }
340 for (std::vector<std::u16string>::iterator it = fdnNumberList.begin(); it != fdnNumberList.end(); ++it) {
341 if (strstr(number, Str16ToStr8(*it).c_str()) != nullptr) {
342 TELEPHONY_LOGI("you are allowed to dial!");
343 return true;
344 }
345 }
346 TELEPHONY_LOGW("There is no fixed number.");
347 return false;
348 }
349 } // namespace Telephony
350 } // namespace OHOS
351