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