1 /*
2 * Copyright (C) 2021-2022 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_status_manager.h"
17
18 #include <securec.h>
19
20 #include "audio_control_manager.h"
21 #include "bluetooth_call_service.h"
22 #include "call_control_manager.h"
23 #include "call_manager_errors.h"
24 #include "call_manager_hisysevent.h"
25 #include "call_number_utils.h"
26 #include "call_request_event_handler_helper.h"
27 #include "core_service_client.h"
28 #include "cs_call.h"
29 #include "datashare_predicates.h"
30 #include "hitrace_meter.h"
31 #include "ims_call.h"
32 #include "os_account_manager.h"
33 #include "ott_call.h"
34 #include "report_call_info_handler.h"
35 #include "satellite_call.h"
36 #include "satellite_call_control.h"
37 #include "settings_datashare_helper.h"
38 #include "telephony_log_wrapper.h"
39 #include "call_number_utils.h"
40 #include "voip_call.h"
41 #include "uri.h"
42 #include "ffrt.h"
43 #include "parameters.h"
44 #include "spam_call_adapter.h"
45 #include "call_superprivacy_control_manager.h"
46 #include "notification_helper.h"
47 #include "call_voice_assistant_manager.h"
48
49 namespace OHOS {
50 namespace Telephony {
51 constexpr int32_t INIT_INDEX = 0;
CallStatusManager()52 CallStatusManager::CallStatusManager()
53 {
54 (void)memset_s(&callReportInfo_, sizeof(CallDetailInfo), 0, sizeof(CallDetailInfo));
55 for (int32_t i = 0; i < SLOT_NUM; i++) {
56 (void)memset_s(&callDetailsInfo_[i], sizeof(CallDetailsInfo), 0, sizeof(CallDetailsInfo));
57 }
58 }
59
~CallStatusManager()60 CallStatusManager::~CallStatusManager()
61 {
62 UnInit();
63 }
64
Init()65 int32_t CallStatusManager::Init()
66 {
67 for (int32_t i = 0; i < SLOT_NUM; i++) {
68 callDetailsInfo_[i].callVec.clear();
69 }
70 for (int32_t i = 0; i < SLOT_NUM; i++) {
71 priorVideoState_[i] = VideoStateType::TYPE_VOICE;
72 }
73 mEventIdTransferMap_.clear();
74 mOttEventIdTransferMap_.clear();
75 InitCallBaseEvent();
76 CallIncomingFilterManagerPtr_ = (std::make_unique<CallIncomingFilterManager>()).release();
77 return TELEPHONY_SUCCESS;
78 }
79
InitCallBaseEvent()80 void CallStatusManager::InitCallBaseEvent()
81 {
82 mEventIdTransferMap_[RequestResultEventId::RESULT_DIAL_NO_CARRIER] = CallAbilityEventId::EVENT_DIAL_NO_CARRIER;
83 mEventIdTransferMap_[RequestResultEventId::RESULT_HOLD_SEND_FAILED] = CallAbilityEventId::EVENT_HOLD_CALL_FAILED;
84 mEventIdTransferMap_[RequestResultEventId::RESULT_SWAP_SEND_FAILED] = CallAbilityEventId::EVENT_SWAP_CALL_FAILED;
85 mOttEventIdTransferMap_[OttCallEventId::OTT_CALL_EVENT_FUNCTION_UNSUPPORTED] =
86 CallAbilityEventId::EVENT_OTT_FUNCTION_UNSUPPORTED;
87 mEventIdTransferMap_[RequestResultEventId::RESULT_COMBINE_SEND_FAILED] =
88 CallAbilityEventId::EVENT_COMBINE_CALL_FAILED;
89 mEventIdTransferMap_[RequestResultEventId::RESULT_SPLIT_SEND_FAILED] =
90 CallAbilityEventId::EVENT_SPLIT_CALL_FAILED;
91 }
92
UnInit()93 int32_t CallStatusManager::UnInit()
94 {
95 for (int32_t i = 0; i < SLOT_NUM; i++) {
96 callDetailsInfo_[i].callVec.clear();
97 }
98 mEventIdTransferMap_.clear();
99 mOttEventIdTransferMap_.clear();
100 return TELEPHONY_SUCCESS;
101 }
102
HandleCallReportInfo(const CallDetailInfo & info)103 int32_t CallStatusManager::HandleCallReportInfo(const CallDetailInfo &info)
104 {
105 int32_t ret = TELEPHONY_ERR_FAIL;
106 callReportInfo_ = info;
107 if (info.callType == CallType::TYPE_VOIP) {
108 ret = HandleVoipCallReportInfo(info);
109 return ret;
110 }
111 switch (info.state) {
112 case TelCallState::CALL_STATUS_ACTIVE:
113 ret = ActiveHandle(info);
114 break;
115 case TelCallState::CALL_STATUS_HOLDING:
116 ret = HoldingHandle(info);
117 break;
118 case TelCallState::CALL_STATUS_DIALING: {
119 ret = DialingHandle(info);
120 FinishAsyncTrace(HITRACE_TAG_OHOS, "DialCall", getpid());
121 DelayedSingleton<CallManagerHisysevent>::GetInstance()->JudgingDialTimeOut(
122 info.accountId, static_cast<int32_t>(info.callType), static_cast<int32_t>(info.callMode));
123 break;
124 }
125 case TelCallState::CALL_STATUS_ALERTING:
126 ret = AlertHandle(info);
127 break;
128 case TelCallState::CALL_STATUS_INCOMING: {
129 DelayedSingleton<CallControlManager>::GetInstance()->AcquireIncomingLock();
130 ret = IncomingHandle(info);
131 DelayedSingleton<CallControlManager>::GetInstance()->ReleaseIncomingLock();
132 FinishAsyncTrace(HITRACE_TAG_OHOS, "InComingCall", getpid());
133 DelayedSingleton<CallManagerHisysevent>::GetInstance()->JudgingIncomingTimeOut(
134 info.accountId, static_cast<int32_t>(info.callType), static_cast<int32_t>(info.callMode));
135 break;
136 }
137 case TelCallState::CALL_STATUS_WAITING:
138 ret = WaitingHandle(info);
139 break;
140 case TelCallState::CALL_STATUS_DISCONNECTED:
141 ret = DisconnectedHandle(info);
142 break;
143 case TelCallState::CALL_STATUS_DISCONNECTING:
144 ret = DisconnectingHandle(info);
145 break;
146 default:
147 TELEPHONY_LOGE("Invalid call state!");
148 break;
149 }
150 TELEPHONY_LOGI("Entry CallStatusManager HandleCallReportInfo");
151 HandleDsdaInfo(info.accountId);
152 DelayedSingleton<BluetoothCallService>::GetInstance()->GetCallState();
153 TELEPHONY_LOGI("End CallStatusManager HandleCallReportInfo");
154 return ret;
155 }
156
HandleDsdaInfo(int32_t slotId)157 void CallStatusManager::HandleDsdaInfo(int32_t slotId)
158 {
159 int32_t dsdsMode = DSDS_MODE_V2;
160 bool noOtherCall = true;
161 std::list<int32_t> callIdList;
162 GetCarrierCallList(callIdList);
163 int32_t currentCallNum = GetCurrentCallNum();
164 DelayedSingleton<CallRequestProcess>::GetInstance()->IsExistCallOtherSlot(callIdList, slotId, noOtherCall);
165 DelayedRefSingleton<CoreServiceClient>::GetInstance().GetDsdsMode(dsdsMode);
166 TELEPHONY_LOGI("dsdsMode:%{public}d", dsdsMode);
167 if ((dsdsMode == static_cast<int32_t>(DsdsMode::DSDS_MODE_V5_DSDA) ||
168 dsdsMode == static_cast<int32_t>(DsdsMode::DSDS_MODE_V5_TDM)) &&
169 !noOtherCall) {
170 TELEPHONY_LOGI("Handle DsdaCallInfo");
171 sptr<CallBase> holdCall = GetOneCallObject(CallRunningState::CALL_RUNNING_STATE_HOLD);
172 if (holdCall != nullptr && currentCallNum > CALL_NUMBER) {
173 holdCall->SetCanUnHoldState(false);
174 }
175 }
176 }
177
178 // handle call state changes, incoming call, outgoing call.
HandleCallsReportInfo(const CallDetailsInfo & info)179 int32_t CallStatusManager::HandleCallsReportInfo(const CallDetailsInfo &info)
180 {
181 bool flag = false;
182 TELEPHONY_LOGI("call list size:%{public}zu,slotId:%{public}d", info.callVec.size(), info.slotId);
183 int32_t curSlotId = info.slotId;
184 if (!DelayedSingleton<CallNumberUtils>::GetInstance()->IsValidSlotId(curSlotId)) {
185 TELEPHONY_LOGE("invalid slotId!");
186 return CALL_ERR_INVALID_SLOT_ID;
187 }
188 for (auto &it : info.callVec) {
189 for (const auto &it1 : callDetailsInfo_[curSlotId].callVec) {
190 if (it.index == it1.index) {
191 // call state changes
192 if (it.state != it1.state || it.mpty != it1.mpty || it.callType != it1.callType
193 || it.callMode != it1.callMode || it.state == TelCallState::CALL_STATUS_ALERTING) {
194 TELEPHONY_LOGI("handle updated call state:%{public}d", it.state);
195 HandleCallReportInfo(it);
196 }
197 flag = true;
198 break;
199 }
200 }
201 // incoming/outgoing call handle
202 if (!flag || callDetailsInfo_[curSlotId].callVec.empty()) {
203 TELEPHONY_LOGI("handle new call state:%{public}d", it.state);
204 HandleCallReportInfo(it);
205 }
206 flag = false;
207 }
208 // disconnected calls handle
209 for (auto &it2 : callDetailsInfo_[curSlotId].callVec) {
210 for (const auto &it3 : info.callVec) {
211 if (it2.index == it3.index) {
212 TELEPHONY_LOGI("state:%{public}d", it2.state);
213 flag = true;
214 break;
215 }
216 }
217 if (!flag) {
218 it2.state = TelCallState::CALL_STATUS_DISCONNECTED;
219 HandleCallReportInfo(it2);
220 }
221 flag = false;
222 }
223 callDetailsInfo_[curSlotId].callVec.clear();
224 callDetailsInfo_[curSlotId] = info;
225 auto condition = [](CallDetailInfo i) { return i.state == TelCallState::CALL_STATUS_DISCONNECTED; };
226 auto it_end = std::remove_if(callDetailsInfo_[curSlotId].callVec.begin(),
227 callDetailsInfo_[curSlotId].callVec.end(), condition);
228 callDetailsInfo_[curSlotId].callVec.erase(it_end, callDetailsInfo_[curSlotId].callVec.end());
229 TELEPHONY_LOGI("End CallStatusManager HandleCallsReportInfo slotId:%{public}d, "
230 "callDetailsInfo_ size:%{public}zu", info.slotId, callDetailsInfo_[curSlotId].callVec.size());
231 return TELEPHONY_SUCCESS;
232 }
233
HandleVoipCallReportInfo(const CallDetailInfo & info)234 int32_t CallStatusManager::HandleVoipCallReportInfo(const CallDetailInfo &info)
235 {
236 TELEPHONY_LOGI("Entry CallStatusManager HandleVoipCallReportInfo");
237 int32_t ret = TELEPHONY_ERR_FAIL;
238 switch (info.state) {
239 case TelCallState::CALL_STATUS_ACTIVE:
240 ret = ActiveVoipCallHandle(info);
241 break;
242 case TelCallState::CALL_STATUS_INCOMING: {
243 ret = IncomingVoipCallHandle(info);
244 break;
245 }
246 case TelCallState::CALL_STATUS_DISCONNECTED:
247 ret = DisconnectedVoipCallHandle(info);
248 break;
249 case TelCallState::CALL_STATUS_DIALING:
250 ret = OutgoingVoipCallHandle(info);
251 break;
252 case TelCallState::CALL_STATUS_ANSWERED:
253 ret = AnsweredVoipCallHandle(info);
254 break;
255 case TelCallState::CALL_STATUS_DISCONNECTING:
256 ret = DisconnectingVoipCallHandle(info);
257 break;
258 default:
259 TELEPHONY_LOGE("Invalid call state!");
260 break;
261 }
262 return ret;
263 }
264
HandleDisconnectedCause(const DisconnectedDetails & details)265 int32_t CallStatusManager::HandleDisconnectedCause(const DisconnectedDetails &details)
266 {
267 bool ret = DelayedSingleton<CallControlManager>::GetInstance()->NotifyCallDestroyed(details);
268 if (!ret) {
269 TELEPHONY_LOGI("NotifyCallDestroyed failed!");
270 return CALL_ERR_PHONE_CALLSTATE_NOTIFY_FAILED;
271 }
272 return TELEPHONY_SUCCESS;
273 }
274
HandleEventResultReportInfo(const CellularCallEventInfo & info)275 int32_t CallStatusManager::HandleEventResultReportInfo(const CellularCallEventInfo &info)
276 {
277 if (info.eventType != CellularCallEventType::EVENT_REQUEST_RESULT_TYPE) {
278 TELEPHONY_LOGE("unexpected type event occurs, eventId:%{public}d", info.eventId);
279 return CALL_ERR_PHONE_TYPE_UNEXPECTED;
280 }
281 TELEPHONY_LOGI("recv one Event, eventId:%{public}d", info.eventId);
282 sptr<CallBase> call = GetOneCallObject(CallRunningState::CALL_RUNNING_STATE_DIALING);
283 if (call != nullptr) {
284 int32_t ret = DealFailDial(call);
285 TELEPHONY_LOGI("DealFailDial ret:%{public}d", ret);
286 }
287 CallEventInfo eventInfo;
288 (void)memset_s(&eventInfo, sizeof(CallEventInfo), 0, sizeof(CallEventInfo));
289 if (mEventIdTransferMap_.find(info.eventId) != mEventIdTransferMap_.end()) {
290 eventInfo.eventId = mEventIdTransferMap_[info.eventId];
291 DialParaInfo dialInfo;
292 if (eventInfo.eventId == CallAbilityEventId::EVENT_DIAL_NO_CARRIER) {
293 DelayedSingleton<CallControlManager>::GetInstance()->GetDialParaInfo(dialInfo);
294 if (dialInfo.number.length() > static_cast<size_t>(kMaxNumberLen)) {
295 TELEPHONY_LOGE("Number out of limit!");
296 return CALL_ERR_NUMBER_OUT_OF_RANGE;
297 }
298 if (memcpy_s(eventInfo.phoneNum, kMaxNumberLen, dialInfo.number.c_str(), dialInfo.number.length()) != EOK) {
299 TELEPHONY_LOGE("memcpy_s failed!");
300 return TELEPHONY_ERR_MEMCPY_FAIL;
301 }
302 } else if (eventInfo.eventId == CallAbilityEventId::EVENT_COMBINE_CALL_FAILED) {
303 sptr<CallBase> activeCall = GetOneCallObject(CallRunningState::CALL_RUNNING_STATE_ACTIVE);
304 if (activeCall != nullptr) {
305 activeCall->HandleCombineConferenceFailEvent();
306 }
307 } else if (eventInfo.eventId == CallAbilityEventId::EVENT_HOLD_CALL_FAILED) {
308 needWaitHold_ = false;
309 }
310 DelayedSingleton<CallControlManager>::GetInstance()->NotifyCallEventUpdated(eventInfo);
311 } else {
312 TELEPHONY_LOGW("unknown type Event, eventid %{public}d", info.eventId);
313 }
314 return TELEPHONY_SUCCESS;
315 }
316
HandleOttEventReportInfo(const OttCallEventInfo & info)317 int32_t CallStatusManager::HandleOttEventReportInfo(const OttCallEventInfo &info)
318 {
319 TELEPHONY_LOGI("recv one Event, eventId:%{public}d", info.ottCallEventId);
320 CallEventInfo eventInfo;
321 (void)memset_s(&eventInfo, sizeof(CallEventInfo), 0, sizeof(CallEventInfo));
322 if (mOttEventIdTransferMap_.find(info.ottCallEventId) != mOttEventIdTransferMap_.end()) {
323 eventInfo.eventId = mOttEventIdTransferMap_[info.ottCallEventId];
324 if (strlen(info.bundleName) > static_cast<size_t>(kMaxNumberLen)) {
325 TELEPHONY_LOGE("Number out of limit!");
326 return CALL_ERR_NUMBER_OUT_OF_RANGE;
327 }
328 if (memcpy_s(eventInfo.bundleName, kMaxNumberLen, info.bundleName, strlen(info.bundleName)) != EOK) {
329 TELEPHONY_LOGE("memcpy_s failed!");
330 return TELEPHONY_ERR_MEMCPY_FAIL;
331 }
332 DelayedSingleton<CallControlManager>::GetInstance()->NotifyCallEventUpdated(eventInfo);
333 } else {
334 TELEPHONY_LOGW("unknown type Event, eventid %{public}d", info.ottCallEventId);
335 }
336 return TELEPHONY_SUCCESS;
337 }
338
HandleVoipEventReportInfo(const VoipCallEventInfo & info)339 int32_t CallStatusManager::HandleVoipEventReportInfo(const VoipCallEventInfo &info)
340 {
341 TELEPHONY_LOGI("recv one Event, eventId:%{public}d", info.voipCallEvent);
342 sptr<CallBase> call = GetOneCallObjectByVoipCallId(info.voipCallId, info.bundleName, info.uid);
343 if (call == nullptr) {
344 TELEPHONY_LOGE("voip call is null");
345 return TELEPHONY_ERR_LOCAL_PTR_NULL;
346 }
347 if (call->GetCallRunningState() != CallRunningState::CALL_RUNNING_STATE_ACTIVE
348 && call->GetCallRunningState() != CallRunningState::CALL_RUNNING_STATE_DIALING) {
349 return TELEPHONY_ERR_FAIL;
350 }
351 if (info.voipCallEvent == VoipCallEvent::VOIP_CALL_EVENT_MUTED) {
352 call->SetMicPhoneState(true);
353 } else if (info.voipCallEvent == VoipCallEvent::VOIP_CALL_EVENT_UNMUTED) {
354 call->SetMicPhoneState(false);
355 }
356 DelayedSingleton<AudioDeviceManager>::GetInstance()->ReportAudioDeviceInfo(call);
357 return TELEPHONY_SUCCESS;
358 }
359
IncomingHandle(const CallDetailInfo & info)360 int32_t CallStatusManager::IncomingHandle(const CallDetailInfo &info)
361 {
362 TELEPHONY_LOGI("handle incoming state");
363 sptr<CallBase> call = GetOneCallObjectByIndexAndSlotId(info.index, info.accountId);
364 if (call != nullptr) {
365 auto oldCallType = call->GetCallType();
366 auto videoState = call->GetVideoStateType();
367 if (oldCallType != info.callType || call->GetTelCallState() != info.state || videoState != info.callMode) {
368 call = RefreshCallIfNecessary(call, info);
369 if (oldCallType != info.callType || videoState != info.callMode) {
370 return UpdateCallState(call, info.state);
371 }
372 }
373 return TELEPHONY_SUCCESS;
374 }
375 int32_t ret = TELEPHONY_SUCCESS;
376 if (info.callType == CallType::TYPE_CS || info.callType == CallType::TYPE_IMS ||
377 info.callType == CallType::TYPE_SATELLITE) {
378 ret = IncomingFilterPolicy(info);
379 if (ret != TELEPHONY_SUCCESS) {
380 return ret;
381 }
382 }
383 call = CreateNewCall(info, CallDirection::CALL_DIRECTION_IN);
384 if (call == nullptr) {
385 TELEPHONY_LOGE("CreateNewCall failed!");
386 return CALL_ERR_CALL_OBJECT_IS_NULL;
387 }
388 SetContactInfo(call, std::string(info.phoneNum));
389 bool block = false;
390 if (IsRejectCall(call, info, block)) {
391 return HandleRejectCall(call, block);
392 }
393 if (info.callType != CallType::TYPE_VOIP && IsRingOnceCall(call, info)) {
394 return HandleRingOnceCall(call);
395 }
396 AddOneCallObject(call);
397 DelayedSingleton<CallControlManager>::GetInstance()->NotifyNewCallCreated(call);
398 CarrierAndVoipConflictProcess(call->GetCallID());
399 ret = UpdateCallState(call, info.state);
400 if (ret != TELEPHONY_SUCCESS) {
401 TELEPHONY_LOGE("UpdateCallState failed!");
402 return ret;
403 }
404 ret = FilterResultsDispose(call);
405 if (ret != TELEPHONY_SUCCESS) {
406 TELEPHONY_LOGE("FilterResultsDispose failed!");
407 }
408 return ret;
409 }
410
CarrierAndVoipConflictProcess(int32_t callId)411 void CallStatusManager::CarrierAndVoipConflictProcess(int32_t callId)
412 {
413 DelayedSingleton<CallControlManager>::GetInstance()->CarrierAndVoipConflictProcess(callId,
414 TelCallState::CALL_STATUS_INCOMING);
415 }
416
SetContactInfo(sptr<CallBase> & call,std::string phoneNum)417 void CallStatusManager::SetContactInfo(sptr<CallBase> &call, std::string phoneNum)
418 {
419 if (call == nullptr) {
420 TELEPHONY_LOGE("CreateVoipCall failed!");
421 return;
422 }
423 ffrt::submit([=, &call]() {
424 sptr<CallBase> callObjectPtr = call;
425 // allow list filtering
426 // Get the contact data from the database
427 ContactInfo contactInfo = {
428 .name = "",
429 .number = phoneNum,
430 .isContacterExists = false,
431 .ringtonePath = "",
432 .isSendToVoicemail = false,
433 .isEcc = false,
434 .isVoiceMail = false,
435 .isQueryComplete = true,
436 };
437 QueryCallerInfo(contactInfo, phoneNum);
438 callObjectPtr->SetCallerInfo(contactInfo);
439 CallVoiceAssistantManager::GetInstance()->UpdateContactInfo(contactInfo, callObjectPtr->GetCallID());
440 });
441 }
442
HandleRejectCall(sptr<CallBase> & call,bool isBlock)443 int32_t CallStatusManager::HandleRejectCall(sptr<CallBase> &call, bool isBlock)
444 {
445 if (call == nullptr) {
446 TELEPHONY_LOGE("call is nullptr!");
447 return TELEPHONY_ERR_LOCAL_PTR_NULL;
448 }
449 int32_t ret = call->SetTelCallState(TelCallState::CALL_STATUS_INCOMING);
450 if (ret != TELEPHONY_SUCCESS && ret != CALL_ERR_NOT_NEW_STATE) {
451 TELEPHONY_LOGE("Set CallState failed!");
452 return ret;
453 }
454 ret = call->RejectCall();
455 if (ret != TELEPHONY_SUCCESS) {
456 TELEPHONY_LOGE("RejectCall failed!");
457 return ret;
458 }
459 if (isBlock) {
460 return DelayedSingleton<CallControlManager>::GetInstance()->AddBlockLogAndNotification(call);
461 }
462 return DelayedSingleton<CallControlManager>::GetInstance()->AddCallLogAndNotification(call);
463 }
464
IncomingVoipCallHandle(const CallDetailInfo & info)465 int32_t CallStatusManager::IncomingVoipCallHandle(const CallDetailInfo &info)
466 {
467 int32_t ret = TELEPHONY_ERROR;
468 sptr<CallBase> call = GetOneCallObjectByVoipCallId(
469 info.voipCallInfo.voipCallId, info.voipCallInfo.voipBundleName, info.voipCallInfo.uid);
470 if (call != nullptr) {
471 return TELEPHONY_SUCCESS;
472 }
473 call = CreateNewCall(info, CallDirection::CALL_DIRECTION_IN);
474 if (call == nullptr) {
475 TELEPHONY_LOGE("CreateVoipCall failed!");
476 return CALL_ERR_CALL_OBJECT_IS_NULL;
477 }
478 AddOneCallObject(call);
479 DelayedSingleton<CallControlManager>::GetInstance()->NotifyNewCallCreated(call);
480 ret = UpdateCallState(call, info.state);
481 if (ret != TELEPHONY_SUCCESS) {
482 TELEPHONY_LOGE("UpdateCallState failed!");
483 return ret;
484 }
485 return ret;
486 }
487
OutgoingVoipCallHandle(const CallDetailInfo & info)488 int32_t CallStatusManager::OutgoingVoipCallHandle(const CallDetailInfo &info)
489 {
490 int32_t ret = TELEPHONY_ERROR;
491 sptr<CallBase> call = GetOneCallObjectByVoipCallId(
492 info.voipCallInfo.voipCallId, info.voipCallInfo.voipBundleName, info.voipCallInfo.uid);
493 if (call != nullptr) {
494 VideoStateType originalType = call->GetVideoStateType();
495 if (originalType != info.callMode) {
496 TELEPHONY_LOGI("change VideoStateType from %{public}d to %{public}d",
497 static_cast<int32_t>(originalType), static_cast<int32_t>(info.callMode));
498 call->SetVideoStateType(info.callMode);
499 return UpdateCallState(call, info.state);
500 }
501 return TELEPHONY_SUCCESS;
502 }
503 call = CreateNewCall(info, CallDirection::CALL_DIRECTION_OUT);
504 if (call == nullptr) {
505 TELEPHONY_LOGE("CreateVoipCall failed!");
506 return CALL_ERR_CALL_OBJECT_IS_NULL;
507 }
508 AddOneCallObject(call);
509 DelayedSingleton<CallControlManager>::GetInstance()->NotifyNewCallCreated(call);
510 ret = UpdateCallState(call, info.state);
511 if (ret != TELEPHONY_SUCCESS) {
512 TELEPHONY_LOGE("UpdateCallState failed!");
513 return ret;
514 }
515 return ret;
516 }
517
AnsweredVoipCallHandle(const CallDetailInfo & info)518 int32_t CallStatusManager::AnsweredVoipCallHandle(const CallDetailInfo &info)
519 {
520 int32_t ret = TELEPHONY_ERROR;
521 sptr<CallBase> call = GetOneCallObjectByVoipCallId(
522 info.voipCallInfo.voipCallId, info.voipCallInfo.voipBundleName, info.voipCallInfo.uid);
523 if (call == nullptr) {
524 return ret;
525 }
526 if (DelayedSingleton<CallControlManager>::GetInstance()->NotifyCallStateUpdated(
527 call, TelCallState::CALL_STATUS_INCOMING, TelCallState::CALL_STATUS_ANSWERED)) {
528 return TELEPHONY_SUCCESS;
529 } else {
530 return ret;
531 }
532 }
533
DisconnectingVoipCallHandle(const CallDetailInfo & info)534 int32_t CallStatusManager::DisconnectingVoipCallHandle(const CallDetailInfo &info)
535 {
536 sptr<CallBase> call = GetOneCallObjectByVoipCallId(
537 info.voipCallInfo.voipCallId, info.voipCallInfo.voipBundleName, info.voipCallInfo.uid);
538 if (call == nullptr) {
539 return TELEPHONY_ERROR;
540 }
541 return UpdateCallState(call, TelCallState::CALL_STATUS_DISCONNECTING);
542 }
543
QueryCallerInfo(ContactInfo & contactInfo,std::string phoneNum)544 void CallStatusManager::QueryCallerInfo(ContactInfo &contactInfo, std::string phoneNum)
545 {
546 TELEPHONY_LOGI("Entry CallStatusManager QueryCallerInfo");
547 std::shared_ptr<CallDataBaseHelper> callDataPtr = DelayedSingleton<CallDataBaseHelper>::GetInstance();
548 if (callDataPtr == nullptr) {
549 TELEPHONY_LOGE("callDataPtr is nullptr!");
550 return;
551 }
552 DataShare::DataSharePredicates predicates;
553 predicates.EqualTo(DETAIL_INFO, phoneNum);
554 predicates.And();
555 predicates.EqualTo(CONTENT_TYPE, PHONE);
556 bool ret = callDataPtr->Query(contactInfo, predicates);
557 if (!ret) {
558 TELEPHONY_LOGE("Query contact database fail!");
559 }
560 }
561
IncomingFilterPolicy(const CallDetailInfo & info)562 int32_t CallStatusManager::IncomingFilterPolicy(const CallDetailInfo &info)
563 {
564 if (CallIncomingFilterManagerPtr_ == nullptr) {
565 TELEPHONY_LOGE("CallIncomingFilterManagerPtr_ is null");
566 return TELEPHONY_ERR_LOCAL_PTR_NULL;
567 }
568 return CallIncomingFilterManagerPtr_->DoIncomingFilter(info);
569 }
570
CallFilterCompleteResult(const CallDetailInfo & info)571 void CallStatusManager::CallFilterCompleteResult(const CallDetailInfo &info)
572 {
573 int32_t ret = TELEPHONY_ERR_FAIL;
574 sptr<CallBase> call = CreateNewCall(info, CallDirection::CALL_DIRECTION_IN);
575 if (call == nullptr) {
576 TELEPHONY_LOGE("CreateNewCall failed!");
577 return;
578 }
579 AddOneCallObject(call);
580 #ifdef ABILITY_DATABASE_SUPPORT
581 // allow list filtering
582 // Get the contact data from the database
583 GetCallerInfoDate(ContactInfo);
584 SetCallerInfo(contactInfo);
585 #endif
586 DelayedSingleton<CallControlManager>::GetInstance()->NotifyNewCallCreated(call);
587 ret = UpdateCallState(call, info.state);
588 if (ret != TELEPHONY_SUCCESS) {
589 TELEPHONY_LOGE("UpdateCallState failed!");
590 return;
591 }
592 ret = FilterResultsDispose(call);
593 if (ret != TELEPHONY_SUCCESS) {
594 TELEPHONY_LOGE("FilterResultsDispose failed!");
595 return;
596 }
597 }
598
UpdateDialingCallInfo(const CallDetailInfo & info)599 int32_t CallStatusManager::UpdateDialingCallInfo(const CallDetailInfo &info)
600 {
601 sptr<CallBase> call = GetOneCallObjectByIndexAndSlotId(info.index, info.accountId);
602 if (call != nullptr) {
603 call = RefreshCallIfNecessary(call, info);
604 return TELEPHONY_SUCCESS;
605 }
606 call = GetOneCallObjectByIndex(INIT_INDEX);
607 if (call == nullptr) {
608 TELEPHONY_LOGE("call is nullptr");
609 return TELEPHONY_ERR_LOCAL_PTR_NULL;
610 }
611
612 std::string oriNum = call->GetAccountNumber();
613 call = RefreshCallIfNecessary(call, info);
614 call->SetCallIndex(info.index);
615 call->SetBundleName(info.bundleName);
616 call->SetSlotId(info.accountId);
617 call->SetTelCallState(info.state);
618 call->SetVideoStateType(info.callMode);
619 call->SetCallType(info.callType);
620 call->SetAccountNumber(oriNum);
621 return TELEPHONY_SUCCESS;
622 }
623
DialingHandle(const CallDetailInfo & info)624 int32_t CallStatusManager::DialingHandle(const CallDetailInfo &info)
625 {
626 TELEPHONY_LOGI("handle dialing state");
627 if (info.index > 0) {
628 sptr<CallBase> call = GetOneCallObjectByIndexAndSlotId(INIT_INDEX, info.accountId);
629 if (call == nullptr) {
630 call = GetOneCallObjectByIndexAndSlotId(info.index, info.accountId);
631 }
632 if (call != nullptr) {
633 TELEPHONY_LOGI("need update call info");
634 return UpdateDialingCallInfo(info);
635 }
636 }
637 sptr<CallBase> call = CreateNewCall(info, CallDirection::CALL_DIRECTION_OUT);
638 if (call == nullptr) {
639 TELEPHONY_LOGE("CreateNewCall failed!");
640 return TELEPHONY_ERR_LOCAL_PTR_NULL;
641 }
642 AddOneCallObject(call);
643 auto callRequestEventHandler = DelayedSingleton<CallRequestEventHandlerHelper>::GetInstance();
644 callRequestEventHandler->RestoreDialingFlag(false);
645 callRequestEventHandler->RemoveEventHandlerTask();
646 int32_t ret = call->DialingProcess();
647 if (ret != TELEPHONY_SUCCESS) {
648 return ret;
649 }
650 DelayedSingleton<CallControlManager>::GetInstance()->NotifyNewCallCreated(call);
651 ret = UpdateCallState(call, TelCallState::CALL_STATUS_DIALING);
652 if (ret != TELEPHONY_SUCCESS) {
653 TELEPHONY_LOGE("UpdateCallState failed, errCode:%{public}d", ret);
654 }
655 return ret;
656 }
657
ActiveHandle(const CallDetailInfo & info)658 int32_t CallStatusManager::ActiveHandle(const CallDetailInfo &info)
659 {
660 TELEPHONY_LOGI("handle active state");
661 std::string tmpStr(info.phoneNum);
662 sptr<CallBase> call = GetOneCallObjectByIndexAndSlotId(info.index, info.accountId);
663 if (call == nullptr) {
664 TELEPHONY_LOGE("Call is NULL");
665 return TELEPHONY_ERR_LOCAL_PTR_NULL;
666 }
667 call = RefreshCallIfNecessary(call, info);
668 SetOriginalCallTypeForActiveState(call);
669 // call state change active, need to judge if launching a conference
670 if (info.mpty == 1) {
671 int32_t mainCallId = ERR_ID;
672 call->LaunchConference();
673 call->GetMainCallId(mainCallId);
674 sptr<CallBase> mainCall = GetOneCallObject(mainCallId);
675 if (mainCall != nullptr) {
676 mainCall->SetTelConferenceState(TelConferenceState::TEL_CONFERENCE_ACTIVE);
677 }
678 } else if (call->ExitConference() == TELEPHONY_SUCCESS) {
679 TELEPHONY_LOGI("SubCallSeparateFromConference success!");
680 } else {
681 TELEPHONY_LOGI("SubCallSeparateFromConference fail!");
682 }
683 int32_t ret = UpdateCallState(call, TelCallState::CALL_STATUS_ACTIVE);
684 if (ret != TELEPHONY_SUCCESS) {
685 TELEPHONY_LOGE("UpdateCallState failed, errCode:%{public}d", ret);
686 return ret;
687 }
688 sptr<CallBase> holdCall = GetOneCallObject(CallRunningState::CALL_RUNNING_STATE_HOLD);
689 if (holdCall != nullptr) {
690 holdCall->SetCanSwitchCallState(true);
691 TELEPHONY_LOGI("holdcall:%{public}d can swap", holdCall->GetCallID());
692 }
693 #ifdef AUDIO_SUPPORT
694 ToSpeakerPhone(call);
695 DelayedSingleton<AudioControlManager>::GetInstance()->SetVolumeAudible();
696 #endif
697 TELEPHONY_LOGI("handle active state success");
698 return ret;
699 }
700
ActiveVoipCallHandle(const CallDetailInfo & info)701 int32_t CallStatusManager::ActiveVoipCallHandle(const CallDetailInfo &info)
702 {
703 TELEPHONY_LOGI("handle active state");
704 sptr<CallBase> call = GetOneCallObjectByVoipCallId(
705 info.voipCallInfo.voipCallId, info.voipCallInfo.voipBundleName, info.voipCallInfo.uid);
706 if (call == nullptr) {
707 TELEPHONY_LOGE("voip Call is NULL");
708 return TELEPHONY_ERR_LOCAL_PTR_NULL;
709 }
710 VideoStateType originalType = call->GetVideoStateType();
711 if (originalType != info.callMode) {
712 TELEPHONY_LOGI("change VideoStateType from %{public}d to %{public}d",
713 static_cast<int32_t>(originalType), static_cast<int32_t>(info.callMode));
714 call->SetVideoStateType(info.callMode);
715 }
716 int32_t ret = UpdateCallState(call, TelCallState::CALL_STATUS_ACTIVE);
717 if (ret != TELEPHONY_SUCCESS) {
718 TELEPHONY_LOGE("UpdateCallState failed, errCode:%{public}d", ret);
719 return ret;
720 }
721 TELEPHONY_LOGI("handle active state success");
722 return ret;
723 }
724
HoldingHandle(const CallDetailInfo & info)725 int32_t CallStatusManager::HoldingHandle(const CallDetailInfo &info)
726 {
727 TELEPHONY_LOGI("handle holding state");
728 std::string tmpStr(info.phoneNum);
729 sptr<CallBase> call = GetOneCallObjectByIndexAndSlotId(info.index, info.accountId);
730 if (call == nullptr) {
731 TELEPHONY_LOGE("Call is NULL");
732 return TELEPHONY_ERR_LOCAL_PTR_NULL;
733 }
734 // if the call is in a conference, it will exit, otherwise just set it holding
735 call = RefreshCallIfNecessary(call, info);
736 if (info.mpty == 1) {
737 int32_t ret = call->HoldConference();
738 if (ret == TELEPHONY_SUCCESS) {
739 TELEPHONY_LOGI("HoldConference success");
740 }
741 }
742 TelCallState priorState = call->GetTelCallState();
743 int32_t ret = UpdateCallState(call, TelCallState::CALL_STATUS_HOLDING);
744 if (ret != TELEPHONY_SUCCESS) {
745 TELEPHONY_LOGE("UpdateCallState failed, errCode:%{public}d", ret);
746 }
747 int32_t callId = call->GetCallID();
748 int32_t dsdsMode = DSDS_MODE_V2;
749 DelayedRefSingleton<CoreServiceClient>::GetInstance().GetDsdsMode(dsdsMode);
750 TELEPHONY_LOGE("HoldingHandle dsdsMode:%{public}d", dsdsMode);
751 bool canSwitchCallState = call->GetCanSwitchCallState();
752 if (dsdsMode == static_cast<int32_t>(DsdsMode::DSDS_MODE_V5_DSDA) ||
753 dsdsMode == static_cast<int32_t>(DsdsMode::DSDS_MODE_V5_TDM)) {
754 int32_t activeCallNum = GetCallNum(TelCallState::CALL_STATUS_ACTIVE);
755 if (needWaitHold_ && activeCallNum == 0) {
756 needWaitHold_ = false;
757 int32_t result = DelayedSingleton<CellularCallConnection>::GetInstance()->Dial(GetDialCallInfo());
758 sptr<CallBase> dialCall = GetOneCallObject(CallRunningState::CALL_RUNNING_STATE_DIALING);
759 if (result != TELEPHONY_SUCCESS && dialCall != nullptr) {
760 DealFailDial(call);
761 TELEPHONY_LOGI("Dial call fail");
762 }
763 } else {
764 TelConferenceState confState = call->GetTelConferenceState();
765 int32_t conferenceId = ERR_ID;
766 call->GetMainCallId(conferenceId);
767 if (confState != TelConferenceState::TEL_CONFERENCE_IDLE && conferenceId == callId) {
768 AutoHandleForDsda(canSwitchCallState, priorState, activeCallNum, call->GetSlotId(), false);
769 } else if (confState == TelConferenceState::TEL_CONFERENCE_IDLE) {
770 AutoHandleForDsda(canSwitchCallState, priorState, activeCallNum, call->GetSlotId(), false);
771 }
772 }
773 }
774 return ret;
775 }
776
WaitingHandle(const CallDetailInfo & info)777 int32_t CallStatusManager::WaitingHandle(const CallDetailInfo &info)
778 {
779 DelayedSingleton<CallControlManager>::GetInstance()->AcquireIncomingLock();
780 int32_t ret = IncomingHandle(info);
781 DelayedSingleton<CallControlManager>::GetInstance()->ReleaseIncomingLock();
782 return ret;
783 }
784
AlertHandle(const CallDetailInfo & info)785 int32_t CallStatusManager::AlertHandle(const CallDetailInfo &info)
786 {
787 TELEPHONY_LOGI("handle alerting state");
788 std::string tmpStr(info.phoneNum);
789 sptr<CallBase> call = GetOneCallObjectByIndexAndSlotId(info.index, info.accountId);
790 if (call == nullptr) {
791 TELEPHONY_LOGE("Call is NULL");
792 return TELEPHONY_ERR_LOCAL_PTR_NULL;
793 }
794 call = RefreshCallIfNecessary(call, info);
795 int32_t ret = UpdateCallState(call, TelCallState::CALL_STATUS_ALERTING);
796 if (ret != TELEPHONY_SUCCESS) {
797 TELEPHONY_LOGE("UpdateCallState failed, errCode:%{public}d", ret);
798 return ret;
799 }
800 #ifdef AUDIO_SUPPORT
801 ToSpeakerPhone(call);
802 TurnOffMute(call);
803 DelayedSingleton<AudioControlManager>::GetInstance()->SetVolumeAudible();
804 #endif
805 return ret;
806 }
807
DisconnectingHandle(const CallDetailInfo & info)808 int32_t CallStatusManager::DisconnectingHandle(const CallDetailInfo &info)
809 {
810 TELEPHONY_LOGI("handle disconnecting state");
811 std::string tmpStr(info.phoneNum);
812 sptr<CallBase> call = GetOneCallObjectByIndexAndSlotId(info.index, info.accountId);
813 if (call == nullptr) {
814 TELEPHONY_LOGE("Call is NULL");
815 return TELEPHONY_ERR_LOCAL_PTR_NULL;
816 }
817 call = RefreshCallIfNecessary(call, info);
818 SetOriginalCallTypeForDisconnectState(call);
819 int32_t ret = UpdateCallState(call, TelCallState::CALL_STATUS_DISCONNECTING);
820 if (ret != TELEPHONY_SUCCESS) {
821 TELEPHONY_LOGE("UpdateCallState failed, errCode:%{public}d", ret);
822 }
823 return ret;
824 }
825
DisconnectedVoipCallHandle(const CallDetailInfo & info)826 int32_t CallStatusManager::DisconnectedVoipCallHandle(const CallDetailInfo &info)
827 {
828 TELEPHONY_LOGI("handle disconnected voip call state");
829 sptr<CallBase> call = GetOneCallObjectByVoipCallId(
830 info.voipCallInfo.voipCallId, info.voipCallInfo.voipBundleName, info.voipCallInfo.uid);
831 if (call == nullptr) {
832 TELEPHONY_LOGE("voip Call is NULL");
833 return TELEPHONY_ERR_LOCAL_PTR_NULL;
834 }
835 int32_t ret = UpdateCallState(call, TelCallState::CALL_STATUS_DISCONNECTED);
836 if (ret != TELEPHONY_SUCCESS) {
837 TELEPHONY_LOGE("UpdateCallState failed, errCode:%{public}d", ret);
838 return ret;
839 }
840 DeleteOneCallObject(call->GetCallID());
841 TELEPHONY_LOGI("handle disconnected voip call state success");
842 return ret;
843 }
844
DisconnectedHandle(const CallDetailInfo & info)845 int32_t CallStatusManager::DisconnectedHandle(const CallDetailInfo &info)
846 {
847 TELEPHONY_LOGI("handle disconnected state");
848 if (timeWaitHelper_ != nullptr) {
849 TELEPHONY_LOGI("ringtone once");
850 timeWaitHelper_->NotifyAll();
851 timeWaitHelper_ = nullptr;
852 }
853 std::string tmpStr(info.phoneNum);
854 sptr<CallBase> call = GetOneCallObjectByIndexAndSlotId(info.index, info.accountId);
855 if (call == nullptr) {
856 TELEPHONY_LOGE("call is null");
857 return TELEPHONY_ERR_LOCAL_PTR_NULL;
858 }
859 call = RefreshCallIfNecessary(call, info);
860 SetOriginalCallTypeForDisconnectState(call);
861 std::vector<std::u16string> callIdList;
862 call->GetSubCallIdList(callIdList);
863 CallRunningState previousState = call->GetCallRunningState();
864 call->ExitConference();
865 TelCallState priorState = call->GetTelCallState();
866 UpdateCallState(call, TelCallState::CALL_STATUS_DISCONNECTED);
867 HandleHoldCallOrAutoAnswerCall(call, callIdList, previousState, priorState);
868 int32_t currentCallNum = CallObjectManager::GetCurrentCallNum();
869 if (currentCallNum <= 0) {
870 DelayedSingleton<CallSuperPrivacyControlManager>::GetInstance()->RestoreSuperPrivacyMode();
871 }
872 return TELEPHONY_SUCCESS;
873 }
874
HandleHoldCallOrAutoAnswerCall(const sptr<CallBase> call,std::vector<std::u16string> callIdList,CallRunningState previousState,TelCallState priorState)875 void CallStatusManager::HandleHoldCallOrAutoAnswerCall(const sptr<CallBase> call,
876 std::vector<std::u16string> callIdList, CallRunningState previousState, TelCallState priorState)
877 {
878 if (call == nullptr) {
879 TELEPHONY_LOGE("call is null");
880 return;
881 }
882 bool canUnHold = false;
883 size_t size = callIdList.size();
884 int32_t activeCallNum = GetCallNum(TelCallState::CALL_STATUS_ACTIVE);
885 int32_t waitingCallNum = GetCallNum(TelCallState::CALL_STATUS_WAITING);
886 IsCanUnHold(activeCallNum, waitingCallNum, size, canUnHold);
887 sptr<CallBase> holdCall = CallObjectManager::GetOneCallObject(CallRunningState::CALL_RUNNING_STATE_HOLD);
888 if (previousState != CallRunningState::CALL_RUNNING_STATE_HOLD &&
889 previousState != CallRunningState::CALL_RUNNING_STATE_ACTIVE &&
890 priorState == TelCallState::CALL_STATUS_DISCONNECTING) {
891 if (holdCall != nullptr && canUnHold && holdCall->GetCanUnHoldState()) {
892 if (holdCall->GetSlotId() == call->GetSlotId()) {
893 TELEPHONY_LOGI("release call and recover the held call");
894 holdCall->UnHoldCall();
895 }
896 }
897 }
898 DeleteOneCallObject(call->GetCallID());
899 int32_t dsdsMode = DSDS_MODE_V2;
900 DelayedRefSingleton<CoreServiceClient>::GetInstance().GetDsdsMode(dsdsMode);
901 if (dsdsMode == DSDS_MODE_V3) {
902 AutoAnswer(activeCallNum, waitingCallNum);
903 } else if (dsdsMode == static_cast<int32_t>(DsdsMode::DSDS_MODE_V5_DSDA) ||
904 dsdsMode == static_cast<int32_t>(DsdsMode::DSDS_MODE_V5_TDM)) {
905 bool canSwitchCallState = call->GetCanSwitchCallState();
906 AutoHandleForDsda(canSwitchCallState, priorState, activeCallNum, call->GetSlotId(), true);
907 }
908 }
909
IsCanUnHold(int32_t activeCallNum,int32_t waitingCallNum,int32_t size,bool & canUnHold)910 void CallStatusManager::IsCanUnHold(int32_t activeCallNum, int32_t waitingCallNum, int32_t size, bool &canUnHold)
911 {
912 int32_t incomingCallNum = GetCallNum(TelCallState::CALL_STATUS_INCOMING);
913 int32_t answeredCallNum = GetCallNum(TelCallState::CALL_STATUS_ANSWERED);
914 int32_t dialingCallNum = GetCallNum(TelCallState::CALL_STATUS_ALERTING);
915 if (answeredCallNum == 0 && incomingCallNum == 0 && (size == 0 || size == 1) && activeCallNum == 0 &&
916 waitingCallNum == 0 && dialingCallNum == 0) {
917 canUnHold = true;
918 }
919 TELEPHONY_LOGI("CanUnHold state: %{public}d", canUnHold);
920 }
921
AutoHandleForDsda(bool canSwitchCallState,TelCallState priorState,int32_t activeCallNum,int32_t slotId,bool continueAnswer)922 void CallStatusManager::AutoHandleForDsda(
923 bool canSwitchCallState, TelCallState priorState, int32_t activeCallNum, int32_t slotId, bool continueAnswer)
924 {
925 int32_t dialingCallNum = GetCallNum(TelCallState::CALL_STATUS_DIALING);
926 int32_t alertingCallNum = GetCallNum(TelCallState::CALL_STATUS_ALERTING);
927 std::list<int32_t> callIdList;
928 GetCarrierCallList(callIdList);
929 for (int32_t ringCallId : callIdList) {
930 sptr<CallBase> ringCall = GetOneCallObject(ringCallId);
931 if (ringCall != nullptr && ringCall->GetAutoAnswerState()) {
932 TELEPHONY_LOGI("ringCall is not nullptr");
933 int32_t videoState = static_cast<int32_t>(ringCall->GetVideoStateType());
934 if (videoState == static_cast<int32_t>(VideoStateType::TYPE_VIDEO)) {
935 TELEPHONY_LOGI("AutoAnswer VideoCall for Dsda");
936 AutoAnswerForVideoCall(activeCallNum);
937 AutoUnHoldForDsda(canSwitchCallState, priorState, activeCallNum, slotId);
938 return;
939 }
940 if (dialingCallNum == 0 && alertingCallNum == 0 && activeCallNum == 0 &&
941 ringCall->GetCallRunningState() == CallRunningState::CALL_RUNNING_STATE_RINGING) {
942 TELEPHONY_LOGI("AutoAnswer VoiceCall for Dsda");
943 AutoAnswerForVoiceCall(ringCall, slotId, continueAnswer);
944 AutoUnHoldForDsda(canSwitchCallState, priorState, activeCallNum, slotId);
945 return;
946 }
947 }
948 }
949 AutoUnHoldForDsda(canSwitchCallState, priorState, activeCallNum, slotId);
950 }
951
AutoUnHoldForDsda(bool canSwitchCallState,TelCallState priorState,int32_t activeCallNum,int32_t slotId)952 void CallStatusManager::AutoUnHoldForDsda(
953 bool canSwitchCallState, TelCallState priorState, int32_t activeCallNum, int32_t slotId)
954 {
955 int32_t dialingCallNum = GetCallNum(TelCallState::CALL_STATUS_DIALING);
956 int32_t waitingCallNum = GetCallNum(TelCallState::CALL_STATUS_WAITING);
957 int32_t callNum = 2;
958 std::list<int32_t> callIdList;
959 GetCarrierCallList(callIdList);
960 int32_t currentCallNum = GetCurrentCallNum();
961 for (int32_t otherCallId : callIdList) {
962 sptr<CallBase> otherCall = GetOneCallObject(otherCallId);
963 if (otherCall == nullptr) {
964 TELEPHONY_LOGE("otherCall is nullptr");
965 continue;
966 }
967 TelCallState state = otherCall->GetTelCallState();
968 TelConferenceState confState = otherCall->GetTelConferenceState();
969 int32_t conferenceId = ERR_ID;
970 otherCall->GetMainCallId(conferenceId);
971 if (slotId != otherCall->GetSlotId() && state == TelCallState::CALL_STATUS_HOLDING &&
972 otherCall->GetCanUnHoldState() && activeCallNum == 0 && waitingCallNum == 0 &&
973 dialingCallNum == 0 &&
974 ((confState != TelConferenceState::TEL_CONFERENCE_IDLE && conferenceId == otherCallId) ||
975 confState == TelConferenceState::TEL_CONFERENCE_IDLE)) {
976 // Actively hang up the processing unhold state or exchange call
977 if (priorState == TelCallState::CALL_STATUS_DISCONNECTING ||
978 (!canSwitchCallState && currentCallNum == callNum)) {
979 otherCall->UnHoldCall();
980 return;
981 }
982 }
983 }
984 for (int32_t otherCallId : callIdList) {
985 sptr<CallBase> holdCall = GetOneCallObject(otherCallId);
986 if (holdCall != nullptr && holdCall->GetTelCallState() == TelCallState::CALL_STATUS_HOLDING) {
987 if (currentCallNum == callNum) {
988 holdCall->SetCanUnHoldState(true);
989 }
990 }
991 }
992 }
993
AutoAnswerForVoiceCall(sptr<CallBase> ringCall,int32_t slotId,bool continueAnswer)994 void CallStatusManager::AutoAnswerForVoiceCall(sptr<CallBase> ringCall, int32_t slotId, bool continueAnswer)
995 {
996 /* Need to check whether the autoAnswer call and the holding call are on the same slotid
997 * To prevent repeated AT command delivery.
998 */
999 if (continueAnswer || slotId != ringCall->GetSlotId()) {
1000 DelayedSingleton<CallControlManager>::GetInstance()->NotifyCallStateUpdated(
1001 ringCall, TelCallState::CALL_STATUS_INCOMING, TelCallState::CALL_STATUS_ANSWERED);
1002 int ret = ringCall->AnswerCall(ringCall->GetAnswerVideoState());
1003 if (ret == TELEPHONY_SUCCESS) {
1004 DelayedSingleton<CallControlManager>::GetInstance()->NotifyIncomingCallAnswered(ringCall);
1005 }
1006 TELEPHONY_LOGI("ret = %{public}d", ret);
1007 }
1008 ringCall->SetAutoAnswerState(false);
1009 }
1010
AutoAnswerForVideoCall(int32_t activeCallNum)1011 void CallStatusManager::AutoAnswerForVideoCall(int32_t activeCallNum)
1012 {
1013 int32_t holdingCallNum = GetCallNum(TelCallState::CALL_STATUS_HOLDING);
1014 int32_t dialingCallNum = GetCallNum(TelCallState::CALL_STATUS_DIALING);
1015 int32_t alertingCallNum = GetCallNum(TelCallState::CALL_STATUS_ALERTING);
1016 if (activeCallNum == 0 && holdingCallNum == 0 && dialingCallNum == 0 && alertingCallNum == 0) {
1017 std::list<int32_t> ringCallIdList;
1018 GetCarrierCallList(ringCallIdList);
1019 for (int32_t ringingCallId : ringCallIdList) {
1020 sptr<CallBase> ringingCall = GetOneCallObject(ringingCallId);
1021 if (ringingCall == nullptr) {
1022 TELEPHONY_LOGE("ringingCall is nullptr");
1023 return;
1024 }
1025 CallRunningState ringingCallState = ringingCall->GetCallRunningState();
1026 if ((ringingCallState == CallRunningState::CALL_RUNNING_STATE_RINGING &&
1027 (ringingCall->GetAutoAnswerState()))) {
1028 ringingCall->SetAutoAnswerState(false);
1029 int ret = ringingCall->AnswerCall(ringingCall->GetAnswerVideoState());
1030 TELEPHONY_LOGI("ret = %{public}d", ret);
1031 break;
1032 }
1033 }
1034 }
1035 }
1036
AutoAnswer(int32_t activeCallNum,int32_t waitingCallNum)1037 void CallStatusManager::AutoAnswer(int32_t activeCallNum, int32_t waitingCallNum)
1038 {
1039 int32_t holdingCallNum = GetCallNum(TelCallState::CALL_STATUS_HOLDING);
1040 int32_t dialingCallNum = GetCallNum(TelCallState::CALL_STATUS_DIALING);
1041 int32_t alertingCallNum = GetCallNum(TelCallState::CALL_STATUS_ALERTING);
1042 if (activeCallNum == 0 && waitingCallNum == 0 && holdingCallNum == 0 && dialingCallNum == 0 &&
1043 alertingCallNum == 0) {
1044 std::list<int32_t> ringCallIdList;
1045 GetCarrierCallList(ringCallIdList);
1046 for (int32_t ringingCallId : ringCallIdList) {
1047 sptr<CallBase> ringingCall = GetOneCallObject(ringingCallId);
1048 if (ringingCall == nullptr) {
1049 TELEPHONY_LOGE("ringingCall is nullptr");
1050 return;
1051 }
1052 CallRunningState ringingCallState = ringingCall->GetCallRunningState();
1053 if ((ringingCallState == CallRunningState::CALL_RUNNING_STATE_RINGING &&
1054 (ringingCall->GetAutoAnswerState()))) {
1055 ringingCall->SetAutoAnswerState(false);
1056 int ret = ringingCall->AnswerCall(ringingCall->GetAnswerVideoState());
1057 TELEPHONY_LOGI("ret = %{public}d", ret);
1058 break;
1059 }
1060 }
1061 }
1062 }
1063
UpdateCallState(sptr<CallBase> & call,TelCallState nextState)1064 int32_t CallStatusManager::UpdateCallState(sptr<CallBase> &call, TelCallState nextState)
1065 {
1066 TELEPHONY_LOGI("UpdateCallState start");
1067 if (call == nullptr) {
1068 TELEPHONY_LOGE("Call is NULL");
1069 return TELEPHONY_ERR_LOCAL_PTR_NULL;
1070 }
1071 TelCallState priorState = call->GetTelCallState();
1072 VideoStateType videoState = call->GetVideoStateType();
1073 TELEPHONY_LOGI(
1074 "callIndex:%{public}d, callId:%{public}d, priorState:%{public}d, nextState:%{public}d, videoState:%{public}d",
1075 call->GetCallIndex(), call->GetCallID(), priorState, nextState, videoState);
1076 if (call->GetCallType() == CallType::TYPE_SATELLITE) {
1077 DelayedSingleton<SatelliteCallControl>::GetInstance()->
1078 HandleSatelliteCallStateUpdate(call, priorState, nextState);
1079 }
1080 if (priorState == TelCallState::CALL_STATUS_INCOMING && nextState == TelCallState::CALL_STATUS_ACTIVE) {
1081 DelayedSingleton<CallManagerHisysevent>::GetInstance()->JudgingAnswerTimeOut(
1082 call->GetSlotId(), call->GetCallID(), static_cast<int32_t>(call->GetVideoStateType()));
1083 }
1084 int32_t ret = call->SetTelCallState(nextState);
1085 UpdateOneCallObjectByCallId(call->GetCallID(), nextState);
1086 if (ret != TELEPHONY_SUCCESS && ret != CALL_ERR_NOT_NEW_STATE) {
1087 TELEPHONY_LOGE("SetTelCallState failed");
1088 return TELEPHONY_ERR_LOCAL_PTR_NULL;
1089 }
1090 if (!DelayedSingleton<CallControlManager>::GetInstance()->NotifyCallStateUpdated(call, priorState, nextState)) {
1091 TELEPHONY_LOGE(
1092 "NotifyCallStateUpdated failed! priorState:%{public}d,nextState:%{public}d", priorState, nextState);
1093 if (nextState == TelCallState::CALL_STATUS_INCOMING) {
1094 CallManagerHisysevent::WriteIncomingCallFaultEvent(call->GetSlotId(),
1095 static_cast<int32_t>(call->GetCallType()), static_cast<int32_t>(call->GetVideoStateType()), ret,
1096 "NotifyCallStateUpdated failed");
1097 }
1098 return CALL_ERR_PHONE_CALLSTATE_NOTIFY_FAILED;
1099 }
1100 SetVideoCallState(call, nextState);
1101 return TELEPHONY_SUCCESS;
1102 }
1103
SetVideoCallState(sptr<CallBase> & call,TelCallState nextState)1104 void CallStatusManager::SetVideoCallState(sptr<CallBase> &call, TelCallState nextState)
1105 {
1106 if (call == nullptr) {
1107 TELEPHONY_LOGE("Call is NULL");
1108 return;
1109 }
1110 int slotId = call->GetSlotId();
1111 bool isSlotIdValid = false;
1112 if (slotId < SLOT_NUM && slotId >= 0) {
1113 isSlotIdValid = true;
1114 }
1115 VideoStateType videoState = call->GetVideoStateType();
1116 TELEPHONY_LOGI("nextVideoState:%{public}d, priorVideoState:%{public}d, isSlotIdValid:%{public}d", videoState,
1117 priorVideoState_[slotId], isSlotIdValid);
1118 if (isSlotIdValid && (priorVideoState_[slotId] != videoState)) {
1119 DelayedSingleton<AudioControlManager>::GetInstance()->VideoStateUpdated(
1120 call, priorVideoState_[slotId], videoState);
1121 priorVideoState_[slotId] = videoState;
1122 }
1123 if (isSlotIdValid && (nextState == TelCallState::CALL_STATUS_DISCONNECTED)) {
1124 priorVideoState_[slotId] = VideoStateType::TYPE_VOICE;
1125 }
1126 }
1127
RefreshCallIfNecessary(const sptr<CallBase> & call,const CallDetailInfo & info)1128 sptr<CallBase> CallStatusManager::RefreshCallIfNecessary(const sptr<CallBase> &call, const CallDetailInfo &info)
1129 {
1130 TELEPHONY_LOGI("RefreshCallIfNecessary");
1131 if (call->GetCallType() == CallType::TYPE_IMS && call->GetVideoStateType() != info.callMode) {
1132 call->SetVideoStateType(info.callMode);
1133 sptr<IMSCall> imsCall = reinterpret_cast<IMSCall *>(call.GetRefPtr());
1134 imsCall->InitVideoCall();
1135 }
1136 if (call->GetCallType() == CallType::TYPE_IMS) {
1137 call->SetCrsType(info.crsType);
1138 }
1139 if (call->GetCallType() == info.callType) {
1140 TELEPHONY_LOGI("RefreshCallIfNecessary not need Refresh");
1141 return call;
1142 }
1143 TelCallState priorState = call->GetTelCallState();
1144 CallAttributeInfo attrInfo;
1145 (void)memset_s(&attrInfo, sizeof(CallAttributeInfo), 0, sizeof(CallAttributeInfo));
1146 call->GetCallAttributeBaseInfo(attrInfo);
1147 sptr<CallBase> newCall = CreateNewCall(info, attrInfo.callDirection);
1148 if (newCall == nullptr) {
1149 TELEPHONY_LOGE("RefreshCallIfNecessary createCallFail");
1150 return call;
1151 }
1152 AddOneCallObject(newCall);
1153 newCall->SetCallRunningState(call->GetCallRunningState());
1154 newCall->SetTelConferenceState(call->GetTelConferenceState());
1155 newCall->SetStartTime(attrInfo.startTime);
1156 newCall->SetPolicyFlag(PolicyFlag(call->GetPolicyFlag()));
1157 newCall->SetSpeakerphoneOn(call->IsSpeakerphoneOn());
1158 newCall->SetCallEndedType(call->GetCallEndedType());
1159 newCall->SetCallBeginTime(attrInfo.callBeginTime);
1160 newCall->SetCallCreateTime(attrInfo.callCreateTime);
1161 newCall->SetCallEndTime(attrInfo.callEndTime);
1162 newCall->SetRingBeginTime(attrInfo.ringBeginTime);
1163 newCall->SetRingEndTime(attrInfo.ringEndTime);
1164 newCall->SetAnswerType(attrInfo.answerType);
1165 newCall->SetMicPhoneState(call->IsMuted());
1166 DeleteOneCallObject(call->GetCallID());
1167 newCall->SetCallId(call->GetCallID());
1168 newCall->SetTelCallState(priorState);
1169 if (call->GetNumberLocation() != "default") {
1170 newCall->SetNumberLocation(call->GetNumberLocation());
1171 }
1172 NumberMarkInfo numberMarkInfo = call->GetNumberMarkInfo();
1173 if (numberMarkInfo.markType != MarkType::MARK_TYPE_NONE) {
1174 newCall->SetNumberMarkInfo(numberMarkInfo);
1175 }
1176 return newCall;
1177 }
1178
SetOriginalCallTypeForActiveState(sptr<CallBase> & call)1179 void CallStatusManager::SetOriginalCallTypeForActiveState(sptr<CallBase> &call)
1180 {
1181 if (call == nullptr) {
1182 TELEPHONY_LOGE("Call is NULL");
1183 return;
1184 }
1185 TelCallState priorState = call->GetTelCallState();
1186 VideoStateType videoState = call->GetVideoStateType();
1187 int32_t videoStateHistory = call->GetOriginalCallType();
1188 if (priorState == TelCallState::CALL_STATUS_ALERTING || priorState == TelCallState::CALL_STATUS_INCOMING ||
1189 priorState == TelCallState::CALL_STATUS_WAITING) {
1190 // outgoing/incoming video call, but accepted/answered with voice call
1191 if (videoStateHistory != static_cast<int32_t>(videoState)) {
1192 TELEPHONY_LOGD("set videoState:%{public}d as original call type", static_cast<int32_t>(videoState));
1193 call->SetOriginalCallType(static_cast<int32_t>(videoState));
1194 }
1195 } else if (priorState == TelCallState::CALL_STATUS_ACTIVE || priorState == TelCallState::CALL_STATUS_HOLDING) {
1196 int32_t videoStateCurrent =
1197 static_cast<int32_t>(static_cast<uint32_t>(videoStateHistory) | static_cast<uint32_t>(videoState));
1198 TELEPHONY_LOGD("maybe upgrade/downgrade operation, keep video record always, videoStateCurrent:%{public}d",
1199 videoStateCurrent);
1200 call->SetOriginalCallType(videoStateCurrent);
1201 }
1202 }
1203
SetOriginalCallTypeForDisconnectState(sptr<CallBase> & call)1204 void CallStatusManager::SetOriginalCallTypeForDisconnectState(sptr<CallBase> &call)
1205 {
1206 if (call == nullptr) {
1207 TELEPHONY_LOGE("Call is NULL");
1208 return;
1209 }
1210 TelCallState priorState = call->GetTelCallState();
1211 CallAttributeInfo attrInfo;
1212 (void)memset_s(&attrInfo, sizeof(CallAttributeInfo), 0, sizeof(CallAttributeInfo));
1213 call->GetCallAttributeBaseInfo(attrInfo);
1214 if (priorState == TelCallState::CALL_STATUS_DIALING || priorState == TelCallState::CALL_STATUS_ALERTING ||
1215 ((priorState == TelCallState::CALL_STATUS_INCOMING || priorState == TelCallState::CALL_STATUS_WAITING) &&
1216 attrInfo.answerType != CallAnswerType::CALL_ANSWER_REJECT)) {
1217 // outgoing/incoming video call, but canceled or missed
1218 TELEPHONY_LOGD("canceled or missed call, set voice type as original call type");
1219 call->SetOriginalCallType(static_cast<int32_t>(VideoStateType::TYPE_VOICE));
1220 }
1221 }
1222
ToSpeakerPhone(sptr<CallBase> & call)1223 int32_t CallStatusManager::ToSpeakerPhone(sptr<CallBase> &call)
1224 {
1225 int32_t ret = TELEPHONY_ERR_FAIL;
1226 if (call == nullptr) {
1227 TELEPHONY_LOGE("Call is NULL");
1228 return TELEPHONY_ERR_LOCAL_PTR_NULL;
1229 }
1230 if (call->GetCallRunningState() == CallRunningState::CALL_RUNNING_STATE_DIALING) {
1231 TELEPHONY_LOGI("Call is CALL_STATUS_DIALING");
1232 return ret;
1233 }
1234 if (call->IsSpeakerphoneOn()) {
1235 AudioDevice device = {
1236 .deviceType = AudioDeviceType::DEVICE_SPEAKER,
1237 .address = { 0 },
1238 };
1239 DelayedSingleton<AudioControlManager>::GetInstance()->SetAudioDevice(device);
1240 ret = call->SetSpeakerphoneOn(false);
1241 }
1242 return ret;
1243 }
1244
TurnOffMute(sptr<CallBase> & call)1245 int32_t CallStatusManager::TurnOffMute(sptr<CallBase> &call)
1246 {
1247 bool enabled = true;
1248 if (HasEmergencyCall(enabled) != TELEPHONY_SUCCESS) {
1249 TELEPHONY_LOGI("CallStatusManager::TurnOffMute HasEmergencyCall failed.");
1250 }
1251 if (call->GetEmergencyState() || enabled) {
1252 DelayedSingleton<AudioControlManager>::GetInstance()->SetMute(false);
1253 } else {
1254 DelayedSingleton<AudioControlManager>::GetInstance()->SetMute(true);
1255 }
1256 return TELEPHONY_SUCCESS;
1257 }
1258
CreateNewCall(const CallDetailInfo & info,CallDirection dir)1259 sptr<CallBase> CallStatusManager::CreateNewCall(const CallDetailInfo &info, CallDirection dir)
1260 {
1261 TELEPHONY_LOGI("CreateNewCall");
1262 DialParaInfo paraInfo;
1263 AppExecFwk::PacMap extras;
1264 extras.Clear();
1265 PackParaInfo(paraInfo, info, dir, extras);
1266
1267 sptr<CallBase> callPtr = CreateNewCallByCallType(paraInfo, info, dir, extras);
1268 if (callPtr == nullptr) {
1269 TELEPHONY_LOGE("CreateNewCall failed!");
1270 return nullptr;
1271 }
1272 DialScene dialScene = (DialScene)extras.GetIntValue("dialScene");
1273 if (dialScene == DialScene::CALL_EMERGENCY) {
1274 callPtr->SetIsEccContact(true);
1275 }
1276 callPtr->SetOriginalCallType(info.originalCallType);
1277 TELEPHONY_LOGD("originalCallType:%{public}d", info.originalCallType);
1278 if (info.callType == CallType::TYPE_VOIP) {
1279 return callPtr;
1280 }
1281 if (info.state == TelCallState::CALL_STATUS_INCOMING || info.state == TelCallState::CALL_STATUS_WAITING ||
1282 (info.state == TelCallState::CALL_STATUS_DIALING && info.index == 0)) {
1283 TELEPHONY_LOGI("NumberLocationUpdate start");
1284 ffrt::submit([=]() {
1285 DelayedSingleton<CallNumberUtils>::GetInstance()->NumberLocationUpdate(callPtr);
1286 if (info.state == TelCallState::CALL_STATUS_DIALING) {
1287 DelayedSingleton<CallNumberUtils>::GetInstance()->YellowPageAndMarkUpdate(callPtr);
1288 }
1289 });
1290 }
1291 time_t createTime = time(nullptr);
1292 if (createTime < 0) {
1293 createTime = 0;
1294 }
1295 callPtr->SetCallCreateTime(createTime);
1296 return callPtr;
1297 }
1298
CreateNewCallByCallType(DialParaInfo & paraInfo,const CallDetailInfo & info,CallDirection dir,AppExecFwk::PacMap & extras)1299 sptr<CallBase> CallStatusManager::CreateNewCallByCallType(
1300 DialParaInfo ¶Info, const CallDetailInfo &info, CallDirection dir, AppExecFwk::PacMap &extras)
1301 {
1302 sptr<CallBase> callPtr = nullptr;
1303 switch (info.callType) {
1304 case CallType::TYPE_CS: {
1305 if (dir == CallDirection::CALL_DIRECTION_OUT) {
1306 callPtr = (std::make_unique<CSCall>(paraInfo, extras)).release();
1307 } else {
1308 callPtr = (std::make_unique<CSCall>(paraInfo)).release();
1309 }
1310 break;
1311 }
1312 case CallType::TYPE_IMS: {
1313 if (dir == CallDirection::CALL_DIRECTION_OUT) {
1314 callPtr = (std::make_unique<IMSCall>(paraInfo, extras)).release();
1315 } else {
1316 callPtr = (std::make_unique<IMSCall>(paraInfo)).release();
1317 }
1318 if (callPtr->GetCallType() == CallType::TYPE_IMS) {
1319 sptr<IMSCall> imsCall = reinterpret_cast<IMSCall *>(callPtr.GetRefPtr());
1320 imsCall->InitVideoCall();
1321 }
1322 break;
1323 }
1324 case CallType::TYPE_OTT: {
1325 if (dir == CallDirection::CALL_DIRECTION_OUT) {
1326 callPtr = (std::make_unique<OTTCall>(paraInfo, extras)).release();
1327 } else {
1328 callPtr = (std::make_unique<OTTCall>(paraInfo)).release();
1329 }
1330 break;
1331 }
1332 case CallType::TYPE_VOIP: {
1333 callPtr = (std::make_unique<VoIPCall>(paraInfo)).release();
1334 break;
1335 }
1336 case CallType::TYPE_SATELLITE: {
1337 if (dir == CallDirection::CALL_DIRECTION_OUT) {
1338 callPtr = (std::make_unique<SatelliteCall>(paraInfo, extras)).release();
1339 } else {
1340 callPtr = (std::make_unique<SatelliteCall>(paraInfo)).release();
1341 }
1342 break;
1343 }
1344 default:
1345 return nullptr;
1346 }
1347 return callPtr;
1348 }
1349
ShouldRejectIncomingCall()1350 bool CallStatusManager::ShouldRejectIncomingCall()
1351 {
1352 bool hasEcc = false;
1353 if (HasEmergencyCall(hasEcc) == TELEPHONY_SUCCESS && hasEcc) {
1354 TELEPHONY_LOGI("HasEmergencyCall reject incoming call.");
1355 return true;
1356 }
1357 auto datashareHelper = SettingsDataShareHelper::GetInstance();
1358 std::string device_provisioned {"0"};
1359 OHOS::Uri uri(
1360 "datashare:///com.ohos.settingsdata/entry/settingsdata/SETTINGSDATA?Proxy=true&key=device_provisioned");
1361 int resp = datashareHelper->Query(uri, "device_provisioned", device_provisioned);
1362 if (resp == TELEPHONY_SUCCESS && (device_provisioned == "0" || device_provisioned.empty())) {
1363 TELEPHONY_LOGI("ShouldRejectIncomingCall: device_provisioned = 0");
1364 return true;
1365 }
1366
1367 std::string user_setup_complete {"1"};
1368 std::vector<int> activedOsAccountIds;
1369 OHOS::AccountSA::OsAccountManager::QueryActiveOsAccountIds(activedOsAccountIds);
1370 if (activedOsAccountIds.empty()) {
1371 TELEPHONY_LOGI("ShouldRejectIncomingCall: activedOsAccountIds is empty");
1372 return false;
1373 }
1374 int userId = activedOsAccountIds[0];
1375 OHOS::Uri uri_setup(
1376 "datashare:///com.ohos.settingsdata/entry/settingsdata/USER_SETTINGSDATA_SECURE_"
1377 + std::to_string(userId) + "?Proxy=true&key=user_setup_complete");
1378 int resp_userSetup = datashareHelper->Query(uri_setup, "user_setup_complete", user_setup_complete);
1379 if (resp_userSetup == TELEPHONY_SUCCESS && (user_setup_complete == "0" || user_setup_complete.empty())) {
1380 TELEPHONY_LOGI("ShouldRejectIncomingCall: user_setup_complete = 0");
1381 return true;
1382 }
1383 return false;
1384 }
1385
ShouldBlockIncomingCall(const sptr<CallBase> & call,const CallDetailInfo & info)1386 bool CallStatusManager::ShouldBlockIncomingCall(const sptr<CallBase> &call, const CallDetailInfo &info)
1387 {
1388 bool isEcc = false;
1389 DelayedSingleton<CellularCallConnection>::GetInstance()->IsEmergencyPhoneNumber(
1390 info.phoneNum, info.accountId, isEcc);
1391 if (isEcc) {
1392 TELEPHONY_LOGI("incoming phoneNumber is ecc.");
1393 return false;
1394 }
1395 std::shared_ptr<SpamCallAdapter> spamCallAdapterPtr_ = std::make_shared<SpamCallAdapter>();
1396 if (spamCallAdapterPtr_ == nullptr) {
1397 TELEPHONY_LOGE("create SpamCallAdapter object failed!");
1398 return false;
1399 }
1400 bool isSpamCall = spamCallAdapterPtr_->DetectSpamCall(std::string(info.phoneNum), info.accountId);
1401 if (!isSpamCall) {
1402 TELEPHONY_LOGE("DetectSpamCall failed!");
1403 return false;
1404 }
1405 if (spamCallAdapterPtr_->WaitForDetectResult()) {
1406 TELEPHONY_LOGI("DetectSpamCall no time out");
1407 NumberMarkInfo numberMarkInfo = {
1408 .markType = MarkType::MARK_TYPE_NONE,
1409 .markContent = "",
1410 .markCount = -1,
1411 .markSource = "",
1412 .isCloud = false,
1413 };
1414 bool isBlock = false;
1415 int32_t blockReason;
1416 spamCallAdapterPtr_->GetParseResult(isBlock, numberMarkInfo, blockReason);
1417 call->SetNumberMarkInfo(numberMarkInfo);
1418 call->SetBlockReason(blockReason);
1419 if (isBlock) {
1420 return true;
1421 }
1422 }
1423 return false;
1424 }
1425
IsRingOnceCall(const sptr<CallBase> & call,const CallDetailInfo & info)1426 bool CallStatusManager::IsRingOnceCall(const sptr<CallBase> &call, const CallDetailInfo &info)
1427 {
1428 NumberMarkInfo numberMarkInfo = call->GetNumberMarkInfo();
1429 ContactInfo contactInfo = call->GetCallerInfo();
1430 if (numberMarkInfo.markType == MarkType::MARK_TYPE_YELLOW_PAGE ||
1431 std::string(contactInfo.name) != "") {
1432 return false;
1433 }
1434 auto datashareHelper = SettingsDataShareHelper::GetInstance();
1435 std::string is_check_ring_once {"0"};
1436 std::string key = "spamshield_sim" + std::to_string(info.accountId + 1) + "_phone_switch_ring_once";
1437 OHOS::Uri uri(
1438 "datashare:///com.ohos.settingsdata/entry/settingsdata/SETTINGSDATA?Proxy=true&key=" + key);
1439 int32_t ret = datashareHelper->Query(uri, key, is_check_ring_once);
1440 if (ret != TELEPHONY_SUCCESS || is_check_ring_once == "0") {
1441 TELEPHONY_LOGI("is_check_ring_once = 0, not need check ring once call");
1442 return false;
1443 }
1444 if (timeWaitHelper_ == nullptr) {
1445 timeWaitHelper_ = std::make_unique<TimeWaitHelper>(WAIT_TIME_THREE_SECOND);
1446 }
1447 if (!timeWaitHelper_->WaitForResult()) {
1448 TELEPHONY_LOGI("is not ring once");
1449 return false;
1450 }
1451 return true;
1452 }
1453
HandleRingOnceCall(sptr<CallBase> & call)1454 int32_t CallStatusManager::HandleRingOnceCall(sptr<CallBase> &call)
1455 {
1456 if (call == nullptr) {
1457 TELEPHONY_LOGE("call is nullptr!");
1458 return TELEPHONY_ERR_LOCAL_PTR_NULL;
1459 }
1460 int32_t ret = call->SetTelCallState(TelCallState::CALL_STATUS_INCOMING);
1461 if (ret != TELEPHONY_SUCCESS && ret != CALL_ERR_NOT_NEW_STATE) {
1462 TELEPHONY_LOGE("Set CallState failed!");
1463 return ret;
1464 }
1465 return DelayedSingleton<CallControlManager>::GetInstance()->AddCallLogAndNotification(call);
1466 }
1467
PackParaInfo(DialParaInfo & paraInfo,const CallDetailInfo & info,CallDirection dir,AppExecFwk::PacMap & extras)1468 void CallStatusManager::PackParaInfo(
1469 DialParaInfo ¶Info, const CallDetailInfo &info, CallDirection dir, AppExecFwk::PacMap &extras)
1470 {
1471 paraInfo.isEcc = false;
1472 paraInfo.dialType = DialType::DIAL_CARRIER_TYPE;
1473 if (dir == CallDirection::CALL_DIRECTION_OUT) {
1474 DelayedSingleton<CallControlManager>::GetInstance()->GetDialParaInfo(paraInfo, extras);
1475 }
1476 if (info.callType == CallType::TYPE_VOIP) {
1477 paraInfo.voipCallInfo.voipCallId = info.voipCallInfo.voipCallId;
1478 paraInfo.voipCallInfo.userName = info.voipCallInfo.userName;
1479 (paraInfo.voipCallInfo.userProfile).assign(
1480 (info.voipCallInfo.userProfile).begin(), (info.voipCallInfo.userProfile).end());
1481 paraInfo.voipCallInfo.abilityName = info.voipCallInfo.abilityName;
1482 paraInfo.voipCallInfo.extensionId = info.voipCallInfo.extensionId;
1483 paraInfo.voipCallInfo.voipBundleName = info.voipCallInfo.voipBundleName;
1484 paraInfo.voipCallInfo.showBannerForIncomingCall = info.voipCallInfo.showBannerForIncomingCall;
1485 paraInfo.voipCallInfo.isConferenceCall = info.voipCallInfo.isConferenceCall;
1486 paraInfo.voipCallInfo.isVoiceAnswerSupported = info.voipCallInfo.isVoiceAnswerSupported;
1487 paraInfo.voipCallInfo.hasMicPermission = info.voipCallInfo.hasMicPermission;
1488 paraInfo.voipCallInfo.uid = info.voipCallInfo.uid;
1489 }
1490 paraInfo.number = info.phoneNum;
1491 paraInfo.callId = GetNewCallId();
1492 paraInfo.index = info.index;
1493 paraInfo.videoState = info.callMode;
1494 paraInfo.accountId = info.accountId;
1495 paraInfo.callType = info.callType;
1496 paraInfo.callState = info.state;
1497 paraInfo.bundleName = info.bundleName;
1498 paraInfo.crsType = info.crsType;
1499 paraInfo.originalCallType = info.originalCallType;
1500 }
1501
IsFocusModeOpen()1502 bool CallStatusManager::IsFocusModeOpen()
1503 {
1504 auto datashareHelper = SettingsDataShareHelper::GetInstance();
1505 std::string focusModeEnable {"0"};
1506 std::vector<int> activedOsAccountIds;
1507 OHOS::AccountSA::OsAccountManager::QueryActiveOsAccountIds(activedOsAccountIds);
1508 if (activedOsAccountIds.empty()) {
1509 TELEPHONY_LOGW("ShouldRejectIncomingCall: activedOsAccountIds is empty");
1510 return false;
1511 }
1512 int userId = activedOsAccountIds[0];
1513 OHOS::Uri uri(
1514 "datashare:///com.ohos.settingsdata/entry/settingsdata/USER_SETTINGSDATA_SECURE_"
1515 + std::to_string(userId) + "?Proxy=true&key=focus_mode_enable");
1516 int resp = datashareHelper->Query(uri, "focus_mode_enable", focusModeEnable);
1517 if (resp == TELEPHONY_SUCCESS && focusModeEnable == "1") {
1518 TELEPHONY_LOGI("IsFocusModeOpen: focus_mode_enable = 1");
1519 return true;
1520 }
1521 return false;
1522 }
1523
IsRejectCall(sptr<CallBase> & call,const CallDetailInfo & info,bool & block)1524 bool CallStatusManager::IsRejectCall(sptr<CallBase> &call, const CallDetailInfo &info, bool &block)
1525 {
1526 int32_t state;
1527 DelayedSingleton<CallControlManager>::GetInstance()->GetVoIPCallState(state);
1528 if (ShouldRejectIncomingCall() || state == (int32_t)CallStateToApp::CALL_STATE_RINGING) {
1529 CallManagerHisysevent::HiWriteBehaviorEventPhoneUE(
1530 CALL_INCOMING_REJECT_BY_SYSTEM, PNAMEID_KEY, KEY_CALL_MANAGER, PVERSIONID_KEY, "",
1531 ACTION_TYPE, REJECT_BY_OOBE);
1532 block = false;
1533 return true;
1534 }
1535 if (info.callType != CallType::TYPE_VOIP && ShouldBlockIncomingCall(call, info)) {
1536 CallManagerHisysevent::HiWriteBehaviorEventPhoneUE(
1537 CALL_INCOMING_REJECT_BY_SYSTEM, PNAMEID_KEY, KEY_CALL_MANAGER, PVERSIONID_KEY, "",
1538 ACTION_TYPE, REJECT_BY_NUM_BLOCK);
1539 block = true;
1540 return true;
1541 }
1542 if (IsFocusModeOpen()) {
1543 int ret = Notification::NotificationHelper::IsNeedSilentInDoNotDisturbMode(info.phoneNum, 0);
1544 TELEPHONY_LOGI("IsRejectCall IsNeedSilentInDoNotDisturbMode ret:%{public}d", ret);
1545 if (ret == 0) {
1546 CallManagerHisysevent::HiWriteBehaviorEventPhoneUE(
1547 CALL_INCOMING_REJECT_BY_SYSTEM, PNAMEID_KEY, KEY_CALL_MANAGER, PVERSIONID_KEY, "",
1548 ACTION_TYPE, REJECT_IN_FOCUSMODE);
1549 block = false;
1550 return true;
1551 }
1552 }
1553 return false;
1554 }
1555 } // namespace Telephony
1556 } // namespace OHOS
1557