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_object_manager.h"
17
18 #include "call_connect_ability.h"
19 #include "call_control_manager.h"
20 #include "call_manager_errors.h"
21 #include "call_number_utils.h"
22 #include "call_wired_headset.h"
23 #include "conference_base.h"
24 #include "ims_conference.h"
25 #include "report_call_info_handler.h"
26 #include "telephony_log_wrapper.h"
27 #include "voip_call.h"
28 #include "fold_status_manager.h"
29
30 namespace OHOS {
31 namespace Telephony {
32 std::list<sptr<CallBase>> CallObjectManager::callObjectPtrList_;
33 std::map<int32_t, CallAttributeInfo> CallObjectManager::voipCallObjectList_;
34 std::mutex CallObjectManager::listMutex_;
35 int32_t CallObjectManager::callId_ = CALL_START_ID;
36 std::condition_variable CallObjectManager::cv_;
37 bool CallObjectManager::isFirstDialCallAdded_ = false;
38 bool CallObjectManager::needWaitHold_ = false;
39 CellularCallInfo CallObjectManager::dialCallInfo_;
40 constexpr int32_t CRS_TYPE = 2;
41 constexpr uint64_t DISCONNECT_DELAY_TIME = 2000000;
42 static constexpr const char *VIDEO_RING_PATH_FIX_TAIL = ".mp4";
43 constexpr int32_t VIDEO_RING_PATH_FIX_TAIL_LENGTH = 4;
44 static constexpr const char *SYSTEM_VIDEO_RING = "system_video_ring";
45 #ifdef NOT_SUPPORT_MULTICALL
46 constexpr int32_t CALL_MAX_COUNT = 2;
47 #endif
CallObjectManager()48 CallObjectManager::CallObjectManager()
49 {
50 }
51
~CallObjectManager()52 CallObjectManager::~CallObjectManager()
53 {
54 std::list<sptr<CallBase>>::iterator it = callObjectPtrList_.begin();
55 while (it != callObjectPtrList_.end()) {
56 (*it) = nullptr;
57 callObjectPtrList_.erase(it++);
58 }
59 voipCallObjectList_.clear();
60 }
61
AddOneCallObject(sptr<CallBase> & call)62 int32_t CallObjectManager::AddOneCallObject(sptr<CallBase> &call)
63 {
64 if (call == nullptr) {
65 TELEPHONY_LOGE("call is nullptr!");
66 return TELEPHONY_ERR_LOCAL_PTR_NULL;
67 }
68 std::lock_guard<std::mutex> lock(listMutex_);
69 std::list<sptr<CallBase>>::iterator it = callObjectPtrList_.begin();
70 for (; it != callObjectPtrList_.end(); ++it) {
71 if ((*it)->GetCallID() == call->GetCallID()) {
72 TELEPHONY_LOGE("this call has existed yet!");
73 return CALL_ERR_PHONE_CALL_ALREADY_EXISTS;
74 }
75 }
76 CallAttributeInfo info;
77 call->GetCallAttributeInfo(info);
78 int32_t state;
79 bool isVoIPCallExists = false;
80 DelayedSingleton<CallControlManager>::GetInstance()->GetVoIPCallState(state);
81 if (state == (int32_t)CallStateToApp::CALL_STATE_RINGING) {
82 isVoIPCallExists = true;
83 }
84 if (callObjectPtrList_.size() == NO_CALL_EXIST && (!isVoIPCallExists || info.isEcc)) {
85 DelayedSingleton<CallConnectAbility>::GetInstance()->ConnectAbility();
86 }
87 callObjectPtrList_.emplace_back(call);
88 if (callObjectPtrList_.size() == ONE_CALL_EXIST) {
89 DelayedSingleton<CallWiredHeadSet>::GetInstance()->Init();
90 if (callObjectPtrList_.front()->GetTelCallState() == TelCallState::CALL_STATUS_DIALING) {
91 isFirstDialCallAdded_ = true;
92 cv_.notify_all();
93 }
94 }
95 if (FoldStatusManager::IsSmallFoldDevice()) {
96 DelayedSingleton<FoldStatusManager>::GetInstance()->RegisterFoldableListener();
97 }
98 TELEPHONY_LOGI("AddOneCallObject success! callId:%{public}d,call list size:%{public}zu", call->GetCallID(),
99 callObjectPtrList_.size());
100 return TELEPHONY_SUCCESS;
101 }
102
AddOneVoipCallObject(CallAttributeInfo info)103 int32_t CallObjectManager::AddOneVoipCallObject(CallAttributeInfo info)
104 {
105 std::lock_guard<std::mutex> lock(listMutex_);
106 std::map<int32_t, CallAttributeInfo>::iterator it = voipCallObjectList_.find(info.callId);
107 if (it == voipCallObjectList_.end()) {
108 voipCallObjectList_[info.callId] = info;
109 TELEPHONY_LOGI("AddOneVoipCallObject success! callList size:%{public}zu", voipCallObjectList_.size());
110 return TELEPHONY_SUCCESS;
111 }
112 TELEPHONY_LOGI("AddOneVoipCallObject failed!");
113 return CALL_ERR_PHONE_CALL_ALREADY_EXISTS;
114 }
115
DeleteOneVoipCallObject(int32_t callId)116 int32_t CallObjectManager::DeleteOneVoipCallObject(int32_t callId)
117 {
118 std::unique_lock<std::mutex> lock(listMutex_);
119 std::map<int32_t, CallAttributeInfo>::iterator it = voipCallObjectList_.find(callId);
120 if (it != voipCallObjectList_.end()) {
121 voipCallObjectList_.erase(callId);
122 TELEPHONY_LOGI("DeleteOneVoipCallObject success! callList size:%{public}zu", voipCallObjectList_.size());
123 return TELEPHONY_SUCCESS;
124 }
125 TELEPHONY_LOGI("DeleteOneVoipCallObject failed!");
126 return TELEPHONY_ERROR;
127 }
128
IsVoipCallExist()129 bool CallObjectManager::IsVoipCallExist()
130 {
131 std::lock_guard<std::mutex> lock(listMutex_);
132 bool res = (voipCallObjectList_.size() != 0);
133 TELEPHONY_LOGI("has voip call exist:%{public}d", res);
134 return res;
135 }
136
IsVoipCallExist(TelCallState callState,int32_t & callId)137 bool CallObjectManager::IsVoipCallExist(TelCallState callState, int32_t &callId)
138 {
139 std::lock_guard<std::mutex> lock(listMutex_);
140 std::map<int32_t, CallAttributeInfo>::iterator it;
141 for (it = voipCallObjectList_.begin(); it != voipCallObjectList_.end(); ++it) {
142 if (it->second.callState == callState) {
143 callId = it->first;
144 return true;
145 }
146 }
147 TELEPHONY_LOGI("the voip call is does not exist");
148 return false;
149 }
150
ClearVoipList()151 void CallObjectManager::ClearVoipList()
152 {
153 if (voipCallObjectList_.size() != 0) {
154 voipCallObjectList_.clear();
155 }
156 bool res = DelayedSingleton<CallControlManager>::GetInstance()->SetVirtualCall(true);
157 TELEPHONY_LOGI("SetVirtualCall res: %{public}d.", res);
158 }
159
UpdateOneVoipCallObjectByCallId(int32_t callId,TelCallState nextCallState)160 int32_t CallObjectManager::UpdateOneVoipCallObjectByCallId(int32_t callId, TelCallState nextCallState)
161 {
162 std::lock_guard<std::mutex> lock(listMutex_);
163 std::map<int32_t, CallAttributeInfo>::iterator it = voipCallObjectList_.find(callId);
164 if (it != voipCallObjectList_.end()) {
165 it->second.callState = nextCallState;
166 return TELEPHONY_SUCCESS;
167 }
168 TELEPHONY_LOGI("UpdateOneVoipCallObjectByCallId failed!");
169 return TELEPHONY_ERROR;
170 }
171
GetVoipCallInfo()172 CallAttributeInfo CallObjectManager::GetVoipCallInfo()
173 {
174 CallAttributeInfo res;
175 std::map<int32_t, CallAttributeInfo>::iterator it = voipCallObjectList_.begin();
176 if (it != voipCallObjectList_.end()) {
177 res = it->second;
178 return res;
179 }
180 return res;
181 }
182
GetActiveVoipCallInfo()183 CallAttributeInfo CallObjectManager::GetActiveVoipCallInfo()
184 {
185 CallAttributeInfo res;
186 std::map<int32_t, CallAttributeInfo>::iterator it = voipCallObjectList_.begin();
187 for (it; it != voipCallObjectList_.end(); ++it) {
188 if (it->second.callState == TelCallState::CALL_STATUS_ACTIVE) {
189 res = it->second;
190 return res;
191 }
192 }
193 return res;
194 }
195
196
DelayedDisconnectCallConnectAbility(uint64_t time=DISCONNECT_DELAY_TIME)197 void CallObjectManager::DelayedDisconnectCallConnectAbility(uint64_t time = DISCONNECT_DELAY_TIME)
198 {
199 ffrt::submit_h(
200 []() {
201 std::lock_guard<std::mutex> lock(listMutex_);
202 TELEPHONY_LOGI("delayed disconnect callback begin");
203 auto controlManager = DelayedSingleton<CallControlManager>::GetInstance();
204 if (callObjectPtrList_.size() == NO_CALL_EXIST && controlManager->ShouldDisconnectService()) {
205 auto callConnectAbility = DelayedSingleton<CallConnectAbility>::GetInstance();
206 callConnectAbility->DisconnectAbility();
207 TELEPHONY_LOGI("delayed disconnect done");
208 }
209 },
210 {}, {}, ffrt::task_attr().delay(time));
211 }
212
DeleteOneCallObject(int32_t callId)213 int32_t CallObjectManager::DeleteOneCallObject(int32_t callId)
214 {
215 TELEPHONY_LOGI("delete one call object, callId:%{public}d", callId);
216 std::unique_lock<std::mutex> lock(listMutex_);
217 std::list<sptr<CallBase>>::iterator it;
218 for (it = callObjectPtrList_.begin(); it != callObjectPtrList_.end(); ++it) {
219 if ((*it)->GetCallID() == callId) {
220 callObjectPtrList_.erase(it);
221 TELEPHONY_LOGI("DeleteOneCallObject success! call list size:%{public}zu", callObjectPtrList_.size());
222 break;
223 }
224 }
225 if (callObjectPtrList_.size() == NO_CALL_EXIST) {
226 DelayedSingleton<CallWiredHeadSet>::GetInstance()->DeInit();
227 if (FoldStatusManager::IsSmallFoldDevice()) {
228 DelayedSingleton<FoldStatusManager>::GetInstance()->UnregisterFoldableListener();
229 }
230 if (DelayedSingleton<CallControlManager>::GetInstance()->ShouldDisconnectService()) {
231 lock.unlock();
232 DelayedDisconnectCallConnectAbility();
233 }
234 }
235 return TELEPHONY_SUCCESS;
236 }
237
DeleteOneCallObject(sptr<CallBase> & call)238 void CallObjectManager::DeleteOneCallObject(sptr<CallBase> &call)
239 {
240 if (call == nullptr) {
241 TELEPHONY_LOGE("call is null!");
242 return;
243 }
244 std::unique_lock<std::mutex> lock(listMutex_);
245 callObjectPtrList_.remove(call);
246 if (callObjectPtrList_.size() == NO_CALL_EXIST) {
247 if (FoldStatusManager::IsSmallFoldDevice()) {
248 DelayedSingleton<FoldStatusManager>::GetInstance()->UnregisterFoldableListener();
249 }
250 if (DelayedSingleton<CallControlManager>::GetInstance()->ShouldDisconnectService()) {
251 lock.unlock();
252 DelayedDisconnectCallConnectAbility();
253 }
254 }
255 TELEPHONY_LOGI("DeleteOneCallObject success! callList size:%{public}zu", callObjectPtrList_.size());
256 }
257
GetOneCallObject(int32_t callId)258 sptr<CallBase> CallObjectManager::GetOneCallObject(int32_t callId)
259 {
260 sptr<CallBase> retPtr = nullptr;
261 std::lock_guard<std::mutex> lock(listMutex_);
262 std::list<sptr<CallBase>>::iterator it = CallObjectManager::callObjectPtrList_.begin();
263 for (; it != callObjectPtrList_.end(); ++it) {
264 if ((*it)->GetCallID() == callId) {
265 retPtr = *it;
266 break;
267 }
268 }
269 return retPtr;
270 }
271
GetOneCallObject(std::string & phoneNumber)272 sptr<CallBase> CallObjectManager::GetOneCallObject(std::string &phoneNumber)
273 {
274 if (phoneNumber.empty()) {
275 TELEPHONY_LOGE("call is null!");
276 return nullptr;
277 }
278 sptr<CallBase> retPtr = nullptr;
279 std::lock_guard<std::mutex> lock(listMutex_);
280 std::list<sptr<CallBase>>::iterator it = callObjectPtrList_.begin();
281 for (; it != callObjectPtrList_.end(); ++it) {
282 std::string networkAddress =
283 DelayedSingleton<CallNumberUtils>::GetInstance()->RemovePostDialPhoneNumber((*it)->GetAccountNumber());
284 if (networkAddress == phoneNumber) {
285 TELEPHONY_LOGI("GetOneCallObject success!");
286 retPtr = *it;
287 break;
288 }
289 }
290 return retPtr;
291 }
292
HasNewCall()293 int32_t CallObjectManager::HasNewCall()
294 {
295 std::lock_guard<std::mutex> lock(listMutex_);
296 std::list<sptr<CallBase>>::iterator it;
297 for (it = callObjectPtrList_.begin(); it != callObjectPtrList_.end(); ++it) {
298 if ((*it)->GetCallType() != CallType::TYPE_VOIP &&
299 ((*it)->GetCallRunningState() == CallRunningState::CALL_RUNNING_STATE_CREATE ||
300 (*it)->GetCallRunningState() == CallRunningState::CALL_RUNNING_STATE_CONNECTING ||
301 (*it)->GetCallRunningState() == CallRunningState::CALL_RUNNING_STATE_DIALING ||
302 (*it)->GetCallType() == CallType::TYPE_SATELLITE)) {
303 TELEPHONY_LOGE("there is already a new call[callId:%{public}d,state:%{public}d], please redial later",
304 (*it)->GetCallID(), (*it)->GetCallRunningState());
305 return CALL_ERR_CALL_COUNTS_EXCEED_LIMIT;
306 }
307 }
308 return TELEPHONY_SUCCESS;
309 }
310
IsNewCallAllowedCreate(bool & enabled)311 int32_t CallObjectManager::IsNewCallAllowedCreate(bool &enabled)
312 {
313 enabled = true;
314 std::list<sptr<CallBase>>::iterator it;
315 for (it = callObjectPtrList_.begin(); it != callObjectPtrList_.end(); ++it) {
316 if ((*it)->GetCallType() != CallType::TYPE_VOIP &&
317 ((*it)->GetCallRunningState() == CallRunningState::CALL_RUNNING_STATE_CREATE ||
318 (*it)->GetCallRunningState() == CallRunningState::CALL_RUNNING_STATE_CONNECTING ||
319 (*it)->GetCallRunningState() == CallRunningState::CALL_RUNNING_STATE_DIALING ||
320 (*it)->GetCallRunningState() == CallRunningState::CALL_RUNNING_STATE_RINGING)) {
321 TELEPHONY_LOGE("there is already a new call, please redial later");
322 enabled = false;
323 return TELEPHONY_ERR_SUCCESS;
324 }
325 }
326 int32_t count = 0;
327 int32_t callNum = 2;
328 #ifdef NOT_SUPPORT_MULTICALL
329 callNum = 1;
330 #endif
331 std::list<int32_t> callIdList;
332 GetCarrierCallList(callIdList);
333 for (int32_t otherCallId : callIdList) {
334 sptr<CallBase> call = GetOneCallObject(otherCallId);
335 if (call != nullptr) {
336 TelConferenceState confState = call->GetTelConferenceState();
337 int32_t conferenceId = DelayedSingleton<ImsConference>::GetInstance()->GetMainCall();
338 if (confState != TelConferenceState::TEL_CONFERENCE_IDLE && conferenceId == otherCallId) {
339 TELEPHONY_LOGI("there is conference call");
340 count++;
341 } else if (confState == TelConferenceState::TEL_CONFERENCE_IDLE) {
342 count++;
343 }
344 }
345 }
346 TELEPHONY_LOGI("the count is:%{public}d", count);
347 if (count >= callNum) {
348 enabled = false;
349 }
350 return TELEPHONY_ERR_SUCCESS;
351 }
352
GetCurrentCallNum()353 int32_t CallObjectManager::GetCurrentCallNum()
354 {
355 int32_t count = 0;
356 std::list<int32_t> callIdList;
357 GetCarrierCallList(callIdList);
358 for (int32_t otherCallId : callIdList) {
359 sptr<CallBase> call = GetOneCallObject(otherCallId);
360 if (call != nullptr) {
361 TelConferenceState confState = call->GetTelConferenceState();
362 int32_t conferenceId = DelayedSingleton<ImsConference>::GetInstance()->GetMainCall();
363 if (confState != TelConferenceState::TEL_CONFERENCE_IDLE && conferenceId == otherCallId) {
364 TELEPHONY_LOGI("there is conference call");
365 count++;
366 } else if (confState == TelConferenceState::TEL_CONFERENCE_IDLE) {
367 count++;
368 }
369 }
370 }
371 TELEPHONY_LOGI("the count is %{public}d", count);
372 return count;
373 }
374
GetCarrierCallList(std::list<int32_t> & list)375 int32_t CallObjectManager::GetCarrierCallList(std::list<int32_t> &list)
376 {
377 list.clear();
378 std::lock_guard<std::mutex> lock(listMutex_);
379 std::list<sptr<CallBase>>::iterator it;
380 for (it = callObjectPtrList_.begin(); it != callObjectPtrList_.end(); ++it) {
381 if ((*it)->GetCallType() == CallType::TYPE_CS || (*it)->GetCallType() == CallType::TYPE_IMS ||
382 (*it)->GetCallType() == CallType::TYPE_SATELLITE ||
383 (*it)->GetCallType() == CallType::TYPE_BLUETOOTH) {
384 list.emplace_back((*it)->GetCallID());
385 }
386 }
387 return TELEPHONY_SUCCESS;
388 }
389
GetVoipCallNum()390 int32_t CallObjectManager::GetVoipCallNum()
391 {
392 int32_t count = 0;
393 std::lock_guard<std::mutex> lock(listMutex_);
394 std::list<sptr<CallBase>>::iterator it;
395 for (it = callObjectPtrList_.begin(); it != callObjectPtrList_.end(); ++it) {
396 if ((*it)->GetCallType() == CallType::TYPE_VOIP) {
397 count++;
398 }
399 }
400 return count;
401 }
402
GetVoipCallList(std::list<int32_t> & list)403 int32_t CallObjectManager::GetVoipCallList(std::list<int32_t> &list)
404 {
405 list.clear();
406 std::lock_guard<std::mutex> lock(listMutex_);
407 std::list<sptr<CallBase>>::iterator it;
408 for (it = callObjectPtrList_.begin(); it != callObjectPtrList_.end(); ++it) {
409 if ((*it)->GetCallType() == CallType::TYPE_VOIP) {
410 list.emplace_back((*it)->GetCallID());
411 }
412 }
413 return TELEPHONY_SUCCESS;
414 }
415
HasRingingMaximum()416 bool CallObjectManager::HasRingingMaximum()
417 {
418 int32_t ringingCount = 0;
419 std::lock_guard<std::mutex> lock(listMutex_);
420 std::list<sptr<CallBase>>::iterator it;
421 for (it = callObjectPtrList_.begin(); it != callObjectPtrList_.end(); ++it) {
422 // Count the number of calls in the ringing state
423 if ((*it)->GetCallRunningState() == CallRunningState::CALL_RUNNING_STATE_RINGING) {
424 ringingCount++;
425 }
426 }
427 if (ringingCount >= RINGING_CALL_NUMBER_LEN) {
428 return true;
429 }
430 return false;
431 }
432
HasDialingMaximum()433 bool CallObjectManager::HasDialingMaximum()
434 {
435 int32_t dialingCount = 0;
436 std::lock_guard<std::mutex> lock(listMutex_);
437 std::list<sptr<CallBase>>::iterator it;
438 for (it = callObjectPtrList_.begin(); it != callObjectPtrList_.end(); ++it) {
439 // Count the number of calls in the active state
440 if ((*it)->GetCallRunningState() == CallRunningState::CALL_RUNNING_STATE_ACTIVE) {
441 dialingCount++;
442 }
443 }
444 if (dialingCount >= DIALING_CALL_NUMBER_LEN) {
445 return true;
446 }
447 return false;
448 }
449
HasEmergencyCall(bool & enabled)450 int32_t CallObjectManager::HasEmergencyCall(bool &enabled)
451 {
452 enabled = false;
453 std::lock_guard<std::mutex> lock(listMutex_);
454 std::list<sptr<CallBase>>::iterator it;
455 for (it = callObjectPtrList_.begin(); it != callObjectPtrList_.end(); ++it) {
456 if ((*it)->GetEmergencyState()) {
457 enabled = true;
458 }
459 }
460 return TELEPHONY_ERR_SUCCESS;
461 }
462
GetNewCallId()463 int32_t CallObjectManager::GetNewCallId()
464 {
465 int32_t ret = 0;
466 std::lock_guard<std::mutex> lock(listMutex_);
467 ret = ++callId_;
468 return ret;
469 }
470
IsCallExist(int32_t callId)471 bool CallObjectManager::IsCallExist(int32_t callId)
472 {
473 std::lock_guard<std::mutex> lock(listMutex_);
474 std::list<sptr<CallBase>>::iterator it = callObjectPtrList_.begin();
475 for (; it != callObjectPtrList_.end(); ++it) {
476 if ((*it)->GetCallID() == callId) {
477 TELEPHONY_LOGW("the call is exist.");
478 return true;
479 }
480 }
481 return false;
482 }
483
IsCallExist(std::string & phoneNumber)484 bool CallObjectManager::IsCallExist(std::string &phoneNumber)
485 {
486 if (phoneNumber.empty()) {
487 return false;
488 }
489 std::lock_guard<std::mutex> lock(listMutex_);
490 std::list<sptr<CallBase>>::iterator it = callObjectPtrList_.begin();
491 for (; it != callObjectPtrList_.end(); ++it) {
492 std::string networkAddress =
493 DelayedSingleton<CallNumberUtils>::GetInstance()->RemovePostDialPhoneNumber((*it)->GetAccountNumber());
494 if (networkAddress == phoneNumber) {
495 return true;
496 }
497 }
498 TELEPHONY_LOGI("the call is does not exist.");
499 return false;
500 }
501
HasCallExist()502 bool CallObjectManager::HasCallExist()
503 {
504 std::lock_guard<std::mutex> lock(listMutex_);
505 if (callObjectPtrList_.empty()) {
506 TELEPHONY_LOGI("call list size:%{public}zu", callObjectPtrList_.size());
507 return false;
508 }
509 return true;
510 }
511
GetAllCallList()512 std::list<sptr<CallBase>> CallObjectManager::GetAllCallList()
513 {
514 std::lock_guard<std::mutex> lock(listMutex_);
515 return callObjectPtrList_;
516 }
517
HasCellularCallExist()518 bool CallObjectManager::HasCellularCallExist()
519 {
520 std::lock_guard<std::mutex> lock(listMutex_);
521 std::list<sptr<CallBase>>::iterator it;
522 for (it = callObjectPtrList_.begin(); it != callObjectPtrList_.end(); ++it) {
523 if ((*it)->GetCallType() == CallType::TYPE_CS || (*it)->GetCallType() == CallType::TYPE_IMS ||
524 (*it)->GetCallType() == CallType::TYPE_SATELLITE ||
525 (*it)->GetCallType() == CallType::TYPE_BLUETOOTH) {
526 if ((*it)->GetTelCallState() != TelCallState::CALL_STATUS_DISCONNECTED &&
527 (*it)->GetTelCallState() != TelCallState::CALL_STATUS_DISCONNECTING) {
528 return true;
529 }
530 }
531 }
532 return false;
533 }
534
HasVoipCallExist()535 bool CallObjectManager::HasVoipCallExist()
536 {
537 std::lock_guard<std::mutex> lock(listMutex_);
538 std::list<sptr<CallBase>>::iterator it;
539 for (it = callObjectPtrList_.begin(); it != callObjectPtrList_.end(); ++it) {
540 if ((*it)->GetCallType() == CallType::TYPE_VOIP) {
541 return true;
542 }
543 }
544 return false;
545 }
546
HasIncomingCallCrsType()547 bool CallObjectManager::HasIncomingCallCrsType()
548 {
549 std::lock_guard<std::mutex> lock(listMutex_);
550 std::list<sptr<CallBase>>::iterator it;
551 for (it = callObjectPtrList_.begin(); it != callObjectPtrList_.end(); ++it) {
552 if ((*it)->GetCallRunningState() == CallRunningState::CALL_RUNNING_STATE_RINGING &&
553 (*it)->GetCrsType() == CRS_TYPE) {
554 return true;
555 }
556 }
557 return false;
558 }
559
HasIncomingCallVideoRingType()560 bool CallObjectManager::HasIncomingCallVideoRingType()
561 {
562 std::lock_guard<std::mutex> lock(listMutex_);
563 std::list<sptr<CallBase>>::iterator it;
564 for (it = callObjectPtrList_.begin(); it != callObjectPtrList_.end(); ++it) {
565 if ((*it)->GetCallType() != CallType::TYPE_VOIP &&
566 (*it)->GetCallRunningState() == CallRunningState::CALL_RUNNING_STATE_RINGING) {
567 ContactInfo contactInfo = (*it)->GetCallerInfo();
568 if (IsVideoRing(contactInfo.personalNotificationRingtone, contactInfo.ringtonePath)) {
569 return true;
570 }
571 }
572 }
573 return false;
574 }
575
IsVideoRing(const std::string & personalNotificationRingtone,const std::string & ringtonePath)576 bool CallObjectManager::IsVideoRing(const std::string &personalNotificationRingtone, const std::string &ringtonePath)
577 {
578 if ((personalNotificationRingtone.length() > VIDEO_RING_PATH_FIX_TAIL_LENGTH &&
579 personalNotificationRingtone.substr(personalNotificationRingtone.length() - VIDEO_RING_PATH_FIX_TAIL_LENGTH,
580 VIDEO_RING_PATH_FIX_TAIL_LENGTH) == VIDEO_RING_PATH_FIX_TAIL) || ringtonePath == SYSTEM_VIDEO_RING) {
581 TELEPHONY_LOGI("Is video ring.");
582 return true;
583 }
584 return false;
585 }
586
HasVideoCall()587 bool CallObjectManager::HasVideoCall()
588 {
589 std::lock_guard<std::mutex> lock(listMutex_);
590 std::list<sptr<CallBase>>::iterator it;
591 for (it = callObjectPtrList_.begin(); it != callObjectPtrList_.end(); ++it) {
592 if ((*it)->GetVideoStateType() == VideoStateType::TYPE_VIDEO && (*it)->GetCallType() != CallType::TYPE_VOIP) {
593 return true;
594 }
595 }
596 return false;
597 }
598
HasSatelliteCallExist()599 bool CallObjectManager::HasSatelliteCallExist()
600 {
601 std::lock_guard<std::mutex> lock(listMutex_);
602 std::list<sptr<CallBase>>::iterator it;
603 for (it = callObjectPtrList_.begin(); it != callObjectPtrList_.end(); ++it) {
604 if ((*it)->GetCallType() == CallType::TYPE_SATELLITE) {
605 return true;
606 }
607 }
608 return false;
609 }
610
GetSatelliteCallList(std::list<int32_t> & list)611 int32_t CallObjectManager::GetSatelliteCallList(std::list<int32_t> &list)
612 {
613 list.clear();
614 std::lock_guard<std::mutex> lock(listMutex_);
615 std::list<sptr<CallBase>>::iterator it;
616 for (it = callObjectPtrList_.begin(); it != callObjectPtrList_.end(); ++it) {
617 if ((*it)->GetCallType() == CallType::TYPE_SATELLITE) {
618 list.emplace_back((*it)->GetCallID());
619 }
620 }
621 return TELEPHONY_SUCCESS;
622 }
623
HasRingingCall(bool & hasRingingCall)624 int32_t CallObjectManager::HasRingingCall(bool &hasRingingCall)
625 {
626 hasRingingCall = false;
627 std::lock_guard<std::mutex> lock(listMutex_);
628 std::list<sptr<CallBase>>::iterator it;
629 for (it = callObjectPtrList_.begin(); it != callObjectPtrList_.end(); ++it) {
630 // Count the number of calls in the ringing state
631 if ((*it)->GetCallRunningState() == CallRunningState::CALL_RUNNING_STATE_RINGING) {
632 hasRingingCall = true;
633 break;
634 }
635 }
636 return TELEPHONY_ERR_SUCCESS;
637 }
638
HasHoldCall(bool & hasHoldCall)639 int32_t CallObjectManager::HasHoldCall(bool &hasHoldCall)
640 {
641 hasHoldCall = false;
642 std::lock_guard<std::mutex> lock(listMutex_);
643 std::list<sptr<CallBase>>::iterator it;
644 for (it = callObjectPtrList_.begin(); it != callObjectPtrList_.end(); ++it) {
645 // Count the number of calls in the hold state
646 if ((*it)->GetCallRunningState() == CallRunningState::CALL_RUNNING_STATE_HOLD) {
647 hasHoldCall = true;
648 break;
649 }
650 }
651 return TELEPHONY_ERR_SUCCESS;
652 }
653
GetCallState(int32_t callId)654 TelCallState CallObjectManager::GetCallState(int32_t callId)
655 {
656 TelCallState retState = TelCallState::CALL_STATUS_IDLE;
657 std::lock_guard<std::mutex> lock(listMutex_);
658 std::list<sptr<CallBase>>::iterator it = CallObjectManager::callObjectPtrList_.begin();
659 for (; it != callObjectPtrList_.end(); ++it) {
660 if ((*it)->GetCallID() == callId) {
661 retState = (*it)->GetTelCallState();
662 break;
663 }
664 }
665 return retState;
666 }
667
GetOneCallObject(CallRunningState callState)668 sptr<CallBase> CallObjectManager::GetOneCallObject(CallRunningState callState)
669 {
670 std::lock_guard<std::mutex> lock(listMutex_);
671 std::list<sptr<CallBase>>::reverse_iterator it;
672 for (it = callObjectPtrList_.rbegin(); it != callObjectPtrList_.rend(); ++it) {
673 if ((*it)->GetCallRunningState() == callState) {
674 return (*it);
675 }
676 }
677 return nullptr;
678 }
679
GetOneCarrierCallObject(CallRunningState callState)680 sptr<CallBase> CallObjectManager::GetOneCarrierCallObject(CallRunningState callState)
681 {
682 std::lock_guard<std::mutex> lock(listMutex_);
683 std::list<sptr<CallBase>>::reverse_iterator it;
684 for (it = callObjectPtrList_.rbegin(); it!= callObjectPtrList_.rend(); ++it) {
685 if ((*it)->GetCallRunningState() == callState && (*it)->GetCallType() != CallType::TYPE_VOIP) {
686 return (*it);
687 }
688 }
689 return nullptr;
690 }
691
GetOneCallObjectByIndex(int32_t index)692 sptr<CallBase> CallObjectManager::GetOneCallObjectByIndex(int32_t index)
693 {
694 std::lock_guard<std::mutex> lock(listMutex_);
695 std::list<sptr<CallBase>>::iterator it = callObjectPtrList_.begin();
696 for (; it != callObjectPtrList_.end(); ++it) {
697 if ((*it)->GetCallIndex() == index && (*it)->GetCallType() != CallType::TYPE_VOIP) {
698 return (*it);
699 }
700 }
701 return nullptr;
702 }
703
GetOneCallObjectByIndexAndSlotId(int32_t index,int32_t slotId)704 sptr<CallBase> CallObjectManager::GetOneCallObjectByIndexAndSlotId(int32_t index, int32_t slotId)
705 {
706 std::lock_guard<std::mutex> lock(listMutex_);
707 std::list<sptr<CallBase>>::iterator it = callObjectPtrList_.begin();
708 for (; it != callObjectPtrList_.end(); ++it) {
709 if ((*it)->GetCallIndex() == index) {
710 if ((*it)->GetSlotId() == slotId && (*it)->GetCallType() != CallType::TYPE_VOIP) {
711 return (*it);
712 }
713 }
714 }
715 return nullptr;
716 }
717
GetOneCallObjectByIndexSlotIdAndCallType(int32_t index,int32_t slotId,CallType callType)718 sptr<CallBase> CallObjectManager::GetOneCallObjectByIndexSlotIdAndCallType(int32_t index, int32_t slotId,
719 CallType callType)
720 {
721 std::lock_guard<std::mutex> lock(listMutex_);
722 if (callType == CallType::TYPE_BLUETOOTH) {
723 std::list<sptr<CallBase>>::iterator it = callObjectPtrList_.begin();
724 for (; it != callObjectPtrList_.end(); ++it) {
725 if ((*it)->GetCallType() == CallType::TYPE_BLUETOOTH && (*it)->GetCallIndex() == index &&
726 ((*it)->GetSlotId() == slotId || (*it)->GetPhoneOrWatchDial() ==
727 static_cast<int32_t>(PhoneOrWatchDial::WATCH_DIAL))) {
728 return (*it);
729 }
730 }
731 } else {
732 std::list<sptr<CallBase>>::iterator it = callObjectPtrList_.begin();
733 for (; it != callObjectPtrList_.end(); ++it) {
734 if ((*it)->GetCallType() != CallType::TYPE_BLUETOOTH && (*it)->GetCallIndex() == index &&
735 (*it)->GetSlotId() == slotId && (*it)->GetCallType() != CallType::TYPE_VOIP) {
736 return (*it);
737 }
738 }
739 }
740 return nullptr;
741 }
742
GetOneCallObjectByVoipCallId(std::string voipCallId,std::string bundleName,int32_t uid)743 sptr<CallBase> CallObjectManager::GetOneCallObjectByVoipCallId(
744 std::string voipCallId, std::string bundleName, int32_t uid)
745 {
746 std::lock_guard<std::mutex> lock(listMutex_);
747 std::list<sptr<CallBase>>::iterator it = callObjectPtrList_.begin();
748 for (; it != callObjectPtrList_.end(); ++it) {
749 if ((*it)->GetCallType() == CallType::TYPE_VOIP) {
750 sptr<VoIPCall> voipCall = reinterpret_cast<VoIPCall *>((*it).GetRefPtr());
751 if (voipCall->GetVoipCallId() == voipCallId && voipCall->GetVoipBundleName() == bundleName &&
752 voipCall->GetVoipUid() == uid) {
753 return (*it);
754 }
755 }
756 }
757 return nullptr;
758 }
759
IsCallExist(CallType callType,TelCallState callState)760 bool CallObjectManager::IsCallExist(CallType callType, TelCallState callState)
761 {
762 std::lock_guard<std::mutex> lock(listMutex_);
763 std::list<sptr<CallBase>>::iterator it;
764 for (it = callObjectPtrList_.begin(); it != callObjectPtrList_.end(); ++it) {
765 if ((*it)->GetCallType() == callType && (*it)->GetTelCallState() == callState) {
766 return true;
767 }
768 }
769 TELEPHONY_LOGI("the call is does not exist.");
770 return false;
771 }
772
IsCallExist(TelCallState callState)773 bool CallObjectManager::IsCallExist(TelCallState callState)
774 {
775 std::lock_guard<std::mutex> lock(listMutex_);
776 std::list<sptr<CallBase>>::iterator it;
777 for (it = callObjectPtrList_.begin(); it != callObjectPtrList_.end(); ++it) {
778 if ((*it)->GetTelCallState() == callState) {
779 return true;
780 }
781 }
782 TELEPHONY_LOGI("the call is does not exist.");
783 return false;
784 }
785
IsCallExist(TelCallState callState,int32_t & callId)786 bool CallObjectManager::IsCallExist(TelCallState callState, int32_t &callId)
787 {
788 std::lock_guard<std::mutex> lock(listMutex_);
789 std::list<sptr<CallBase>>::iterator it;
790 for (it = callObjectPtrList_.begin(); it != callObjectPtrList_.end(); ++it) {
791 if ((*it)->GetTelCallState() == callState) {
792 callId = (*it)->GetCallID();
793 return true;
794 }
795 }
796 TELEPHONY_LOGI("the call is does not exist.");
797 return false;
798 }
799
IsConferenceCallExist(TelConferenceState state,int32_t & callId)800 bool CallObjectManager::IsConferenceCallExist(TelConferenceState state, int32_t &callId)
801 {
802 std::lock_guard<std::mutex> lock(listMutex_);
803 std::list<sptr<CallBase>>::iterator it;
804 for (it = callObjectPtrList_.begin(); it != callObjectPtrList_.end(); ++it) {
805 if ((*it)->GetTelConferenceState() == state) {
806 callId = (*it)->GetCallID();
807 return true;
808 }
809 }
810 TELEPHONY_LOGI("the call is does not exist.");
811 return false;
812 }
813
HasActivedCallExist(int32_t & callId,bool isIncludeCallServiceKitCall)814 bool CallObjectManager::HasActivedCallExist(int32_t &callId, bool isIncludeCallServiceKitCall)
815 {
816 std::lock_guard<std::mutex> lock(listMutex_);
817 std::list<sptr<CallBase>>::iterator it;
818 for (it = callObjectPtrList_.begin(); it != callObjectPtrList_.end(); ++it) {
819 if ((*it)->GetTelCallState() == TelCallState::CALL_STATUS_ACTIVE &&
820 (isIncludeCallServiceKitCall || (*it)->GetCallType() != CallType::TYPE_VOIP)) {
821 callId = (*it)->GetCallID();
822 return true;
823 }
824 }
825 CallAttributeInfo res = GetActiveVoipCallInfo();
826 if (res.callId >= VOIP_CALL_MINIMUM) {
827 callId = res.callId;
828 return true;
829 }
830 TELEPHONY_LOGI("the call is does not exist.");
831 return false;
832 }
833
GetCallNum(TelCallState callState,bool isIncludeVoipCall)834 int32_t CallObjectManager::GetCallNum(TelCallState callState, bool isIncludeVoipCall)
835 {
836 int32_t num = 0;
837 std::lock_guard<std::mutex> lock(listMutex_);
838 std::list<sptr<CallBase>>::iterator it;
839 for (it = callObjectPtrList_.begin(); it != callObjectPtrList_.end(); ++it) {
840 if ((*it)->GetTelCallState() == callState) {
841 if (!isIncludeVoipCall && (*it)->GetCallType() == CallType::TYPE_VOIP) {
842 continue;
843 } else {
844 ++num;
845 }
846 }
847 }
848 TELEPHONY_LOGI("callState:%{public}d, num:%{public}d", callState, num);
849 return num;
850 }
851
GetCallNumber(TelCallState callState,bool isIncludeVoipCall)852 std::string CallObjectManager::GetCallNumber(TelCallState callState, bool isIncludeVoipCall)
853 {
854 std::string number = "";
855 std::lock_guard<std::mutex> lock(listMutex_);
856 std::list<sptr<CallBase>>::iterator it;
857 for (it = callObjectPtrList_.begin(); it != callObjectPtrList_.end(); ++it) {
858 if ((*it)->GetTelCallState() == callState) {
859 if (!isIncludeVoipCall && (*it)->GetCallType() == CallType::TYPE_VOIP) {
860 continue;
861 } else {
862 number = (*it)->GetAccountNumber();
863 break;
864 }
865 }
866 }
867 return number;
868 }
869
GetCallInfoList(int32_t slotId,bool isIncludeVoipCall)870 std::vector<CallAttributeInfo> CallObjectManager::GetCallInfoList(int32_t slotId, bool isIncludeVoipCall)
871 {
872 std::vector<CallAttributeInfo> callVec;
873 CallAttributeInfo info;
874 callVec.clear();
875 std::lock_guard<std::mutex> lock(listMutex_);
876 std::list<sptr<CallBase>>::iterator it;
877 for (it = callObjectPtrList_.begin(); it != callObjectPtrList_.end(); ++it) {
878 (void)memset_s(&info, sizeof(CallAttributeInfo), 0, sizeof(CallAttributeInfo));
879 (*it)->GetCallAttributeInfo(info);
880 if (info.accountId == slotId && info.callType != CallType::TYPE_OTT &&
881 (isIncludeVoipCall || info.callType != CallType::TYPE_VOIP)) {
882 callVec.emplace_back(info);
883 }
884 }
885 std::vector<CallAttributeInfo> voipCallVec = GetVoipCallInfoList();
886 for (CallAttributeInfo voipCall : voipCallVec) {
887 callVec.emplace_back(voipCall);
888 }
889 TELEPHONY_LOGI("call list size is %{public}u", static_cast<uint32_t>(callVec.size()));
890 return callVec;
891 }
892
GetVoipCallInfoList()893 std::vector<CallAttributeInfo> CallObjectManager::GetVoipCallInfoList()
894 {
895 std::vector<CallAttributeInfo> callVec;
896 int32_t voipState = DelayedSingleton<CallControlManager>::GetInstance()->GetMeetimeCallState();
897 TELEPHONY_LOGI("voip state is :%{public}d", voipState);
898 if (voipState == (int32_t)TelCallState::CALL_STATUS_INCOMING ||
899 voipState == (int32_t)TelCallState::CALL_STATUS_IDLE ||
900 voipState == (int32_t)TelCallState::CALL_STATUS_ALERTING) {
901 std::map<int32_t, CallAttributeInfo>::iterator it = voipCallObjectList_.begin();
902 for (; it != voipCallObjectList_.end(); ++it) {
903 callVec.emplace_back(it->second);
904 }
905 }
906 return callVec;
907 }
908
UpdateOneCallObjectByCallId(int32_t callId,TelCallState nextCallState)909 void CallObjectManager::UpdateOneCallObjectByCallId(int32_t callId, TelCallState nextCallState)
910 {
911 std::lock_guard<std::mutex> lock(listMutex_);
912 std::list<sptr<CallBase>>::iterator it = callObjectPtrList_.begin();
913 for (; it != callObjectPtrList_.end(); ++it) {
914 if ((*it)->GetCallID() == callId) {
915 (*it)->SetTelCallState(nextCallState);
916 }
917 }
918 }
919
GetForegroundCall(bool isIncludeVoipCall)920 sptr<CallBase> CallObjectManager::GetForegroundCall(bool isIncludeVoipCall)
921 {
922 std::lock_guard<std::mutex> lock(listMutex_);
923 sptr<CallBase> liveCall = nullptr;
924 for (std::list<sptr<CallBase>>::iterator it = callObjectPtrList_.begin(); it != callObjectPtrList_.end(); ++it) {
925 if (!isIncludeVoipCall && (*it)->GetCallType() == CallType::TYPE_VOIP) {
926 continue;
927 }
928 TelCallState telCallState = (*it)->GetTelCallState();
929 if (telCallState == TelCallState::CALL_STATUS_WAITING ||
930 telCallState == TelCallState::CALL_STATUS_INCOMING) {
931 liveCall = (*it);
932 break;
933 }
934 if (telCallState == TelCallState::CALL_STATUS_ALERTING ||
935 telCallState == TelCallState::CALL_STATUS_DIALING) {
936 liveCall = (*it);
937 continue;
938 }
939 if (telCallState == TelCallState::CALL_STATUS_ACTIVE) {
940 liveCall = (*it);
941 continue;
942 }
943 if (telCallState == TelCallState::CALL_STATUS_HOLDING) {
944 liveCall = (*it);
945 continue;
946 }
947 }
948 return liveCall;
949 }
950
GetForegroundLiveCall(bool isIncludeVoipCall)951 sptr<CallBase> CallObjectManager::GetForegroundLiveCall(bool isIncludeVoipCall)
952 {
953 std::lock_guard<std::mutex> lock(listMutex_);
954 sptr<CallBase> liveCall = nullptr;
955 for (std::list<sptr<CallBase>>::iterator it = callObjectPtrList_.begin(); it != callObjectPtrList_.end(); ++it) {
956 if (!isIncludeVoipCall && (*it)->GetCallType() == CallType::TYPE_VOIP) {
957 continue;
958 }
959 TelCallState telCallState = (*it)->GetTelCallState();
960 if (telCallState == TelCallState::CALL_STATUS_ACTIVE) {
961 liveCall = (*it);
962 break;
963 }
964 if (telCallState == TelCallState::CALL_STATUS_ALERTING ||
965 telCallState == TelCallState::CALL_STATUS_DIALING) {
966 liveCall = (*it);
967 break;
968 }
969 }
970 return liveCall;
971 }
972
GetIncomingCall(bool isIncludeVoipCall)973 sptr<CallBase> CallObjectManager::GetIncomingCall(bool isIncludeVoipCall)
974 {
975 std::lock_guard<std::mutex> lock(listMutex_);
976 sptr<CallBase> call = nullptr;
977 for (std::list<sptr<CallBase>>::iterator it = callObjectPtrList_.begin(); it != callObjectPtrList_.end(); ++it) {
978 if (!isIncludeVoipCall && (*it)->GetCallType() == CallType::TYPE_VOIP) {
979 continue;
980 }
981 TelCallState callState = (*it)->GetTelCallState();
982 if (callState == TelCallState::CALL_STATUS_INCOMING || callState == TelCallState::CALL_STATUS_WAITING) {
983 call = (*it);
984 break;
985 }
986 }
987 return call;
988 }
989
GetAudioLiveCall()990 sptr<CallBase> CallObjectManager::GetAudioLiveCall()
991 {
992 sptr<CallBase> call = GetForegroundLiveCall(false);
993 if (call == nullptr) {
994 call = GetForegroundLiveCall();
995 }
996 if (call == nullptr) {
997 call = GetIncomingCall(false);
998 }
999 return call;
1000 }
1001
GetDialCallInfo()1002 CellularCallInfo CallObjectManager::GetDialCallInfo()
1003 {
1004 return dialCallInfo_;
1005 }
1006
DealFailDial(sptr<CallBase> call)1007 int32_t CallObjectManager::DealFailDial(sptr<CallBase> call)
1008 {
1009 TELEPHONY_LOGI("DealFailDial");
1010 CallDetailInfo callDetatilInfo;
1011 if (memset_s(&callDetatilInfo, sizeof(CallDetailInfo), 0, sizeof(CallDetailInfo)) != EOK) {
1012 TELEPHONY_LOGE("memset_s callDetatilInfo fail");
1013 return TELEPHONY_ERR_MEMSET_FAIL;
1014 }
1015 std::string number = call->GetAccountNumber();
1016 callDetatilInfo.callType = call->GetCallType();
1017 callDetatilInfo.accountId = call->GetSlotId();
1018 callDetatilInfo.state = TelCallState::CALL_STATUS_DISCONNECTED;
1019 callDetatilInfo.callMode = call->GetVideoStateType();
1020 callDetatilInfo.voiceDomain = static_cast<int32_t>(call->GetCallType());
1021 if (number.length() > kMaxNumberLen) {
1022 TELEPHONY_LOGE("numbser length out of range");
1023 return CALL_ERR_NUMBER_OUT_OF_RANGE;
1024 }
1025 if (memcpy_s(&callDetatilInfo.phoneNum, kMaxNumberLen, number.c_str(), number.length()) != EOK) {
1026 TELEPHONY_LOGE("memcpy_s number failed!");
1027 return TELEPHONY_ERR_MEMCPY_FAIL;
1028 }
1029
1030 return DelayedSingleton<ReportCallInfoHandler>::GetInstance()->UpdateCallReportInfo(callDetatilInfo);
1031 }
1032
GetAllCallInfoList(bool isIncludeVoipCall)1033 std::vector<CallAttributeInfo> CallObjectManager::GetAllCallInfoList(bool isIncludeVoipCall)
1034 {
1035 std::vector<CallAttributeInfo> callVec;
1036 callVec.clear();
1037 std::lock_guard<std::mutex> lock(listMutex_);
1038 std::list<sptr<CallBase>>::iterator it;
1039 for (it = callObjectPtrList_.begin(); it != callObjectPtrList_.end(); ++it) {
1040 CallAttributeInfo info;
1041 if ((*it) == nullptr) {
1042 TELEPHONY_LOGE("call is nullptr");
1043 continue;
1044 }
1045 (*it)->GetCallAttributeInfo(info);
1046 if (isIncludeVoipCall || info.callType != CallType::TYPE_VOIP) {
1047 callVec.emplace_back(info);
1048 }
1049 }
1050 std::vector<CallAttributeInfo> voipCallVec = GetVoipCallInfoList();
1051 for (CallAttributeInfo voipCall : voipCallVec) {
1052 callVec.emplace_back(voipCall);
1053 }
1054 return callVec;
1055 }
1056
GetCallNumByRunningState(CallRunningState callState)1057 int32_t CallObjectManager::GetCallNumByRunningState(CallRunningState callState)
1058 {
1059 int32_t count = 0;
1060 std::lock_guard<std::mutex> lock(listMutex_);
1061 std::list<sptr<CallBase>>::iterator it;
1062 for (it = callObjectPtrList_.begin(); it != callObjectPtrList_.end(); ++it) {
1063 if ((*it)->GetCallRunningState() == callState) {
1064 count++;
1065 continue;
1066 }
1067 }
1068 TELEPHONY_LOGI("callState:%{public}d, count:%{public}d", callState, count);
1069 return count;
1070 }
1071
GetForegroundLiveCallByCallId(int32_t callId)1072 sptr<CallBase> CallObjectManager::GetForegroundLiveCallByCallId(int32_t callId)
1073 {
1074 std::lock_guard<std::mutex> lock(listMutex_);
1075 sptr<CallBase> liveCall = nullptr;
1076 for (std::list<sptr<CallBase>>::iterator it = callObjectPtrList_.begin(); it != callObjectPtrList_.end(); ++it) {
1077 TelCallState telCallState = (*it)->GetTelCallState();
1078 if (telCallState == TelCallState::CALL_STATUS_ACTIVE && (*it)->GetCallID() == callId) {
1079 liveCall = (*it);
1080 break;
1081 }
1082 if ((telCallState == TelCallState::CALL_STATUS_ALERTING ||
1083 telCallState == TelCallState::CALL_STATUS_DIALING) && (*it)->GetCallID() == callId) {
1084 liveCall = (*it);
1085 break;
1086 }
1087 if ((telCallState == TelCallState::CALL_STATUS_WAITING ||
1088 telCallState == TelCallState::CALL_STATUS_INCOMING) && (*it)->GetCallID() == callId) {
1089 liveCall = (*it);
1090 continue;
1091 }
1092 }
1093 return liveCall;
1094 }
1095
IsNeedSilentInDoNotDisturbMode()1096 bool CallObjectManager::IsNeedSilentInDoNotDisturbMode()
1097 {
1098 sptr<CallBase> foregroundCall = CallObjectManager::GetForegroundCall(false);
1099 if (foregroundCall == nullptr) {
1100 TELEPHONY_LOGE("call object nullptr");
1101 return false;
1102 }
1103 TelCallState telCallState = foregroundCall->GetTelCallState();
1104 if (telCallState == TelCallState::CALL_STATUS_INCOMING) {
1105 AAFwk::WantParams params = foregroundCall->GetExtraParams();
1106 int value = params.GetIntParam("IsNeedSilentInDoNotDisturbMode", 0);
1107 TELEPHONY_LOGI("CallObjectManager::IsNeedSilentInDoNotDisturbMode: %{public}d", value);
1108 if (value == 1) {
1109 return true;
1110 }
1111 }
1112 return false;
1113 }
1114 #ifdef NOT_SUPPORT_MULTICALL
IsTwoCallBtCallAndESIM()1115 bool CallObjectManager::IsTwoCallBtCallAndESIM()
1116 {
1117 std::lock_guard<std::mutex> lock(listMutex_);
1118 if (callObjectPtrList_.size() != CALL_MAX_COUNT) {
1119 return false;
1120 }
1121 std::string numberEsim;
1122 std::string numberBtCall;
1123 bool hasEsim = false;
1124 bool hasBtCall = false;
1125 std::list<sptr<CallBase>>::iterator it;
1126 for (it = callObjectPtrList_.begin(); it != callObjectPtrList_.end(); ++it) {
1127 if ((*it)->GetCallType() == CallType::TYPE_CS || (*it)->GetCallType() == CallType::TYPE_IMS) {
1128 hasEsim = true;
1129 numberEsim = (*it)->GetAccountNumber();
1130 }
1131 if ((*it)->GetCallType() == CallType::TYPE_BLUETOOTH) {
1132 hasBtCall = true;
1133 numberBtCall = (*it)->GetAccountNumber();
1134 }
1135 }
1136 if (hasEsim && hasBtCall) {
1137 if (!numberEsim.empty() && (numberEsim == numberBtCall)) {
1138 return false;
1139 }
1140 return true;
1141 }
1142 return false;
1143 }
1144
IsTwoCallBtCall()1145 bool CallObjectManager::IsTwoCallBtCall()
1146 {
1147 std::lock_guard<std::mutex> lock(listMutex_);
1148 if (callObjectPtrList_.size() != CALL_MAX_COUNT) {
1149 return false;
1150 }
1151 std::list<sptr<CallBase>>::iterator it;
1152 for (it = callObjectPtrList_.begin(); it != callObjectPtrList_.end(); ++it) {
1153 if ((*it)->GetCallType() != CallType::TYPE_BLUETOOTH) {
1154 return false;
1155 }
1156 }
1157 return true;
1158 }
1159
IsTwoCallESIMCall()1160 bool CallObjectManager::IsTwoCallESIMCall()
1161 {
1162 std::lock_guard<std::mutex> lock(listMutex_);
1163 if (callObjectPtrList_.size() != CALL_MAX_COUNT) {
1164 return false;
1165 }
1166 std::list<sptr<CallBase>>::iterator it;
1167 for (it = callObjectPtrList_.begin(); it != callObjectPtrList_.end(); ++it) {
1168 if ((*it)->GetCallType() != CallType::TYPE_CS || (*it)->GetCallType() != CallType::TYPE_IMS) {
1169 return false;
1170 }
1171 }
1172 return true;
1173 }
1174
IsOneNumberDualTerminal()1175 bool CallObjectManager::IsOneNumberDualTerminal()
1176 {
1177 std::lock_guard<std::mutex> lock(listMutex_);
1178 if (callObjectPtrList_.size() != CALL_MAX_COUNT) {
1179 return false;
1180 }
1181 std::string numberEsim;
1182 std::string numberBtCall;
1183 bool hasEsim = false;
1184 bool hasBtCall = false;
1185 std::list<sptr<CallBase>>::iterator it;
1186 for (it = callObjectPtrList_.begin(); it != callObjectPtrList_.end(); ++it) {
1187 if ((*it)->GetCallType() == CallType::TYPE_CS || (*it)->GetCallType() == CallType::TYPE_IMS) {
1188 hasEsim = true;
1189 numberEsim = (*it)->GetAccountNumber();
1190 }
1191 if ((*it)->GetCallType() == CallType::TYPE_BLUETOOTH) {
1192 hasBtCall = true;
1193 numberBtCall = (*it)->GetAccountNumber();
1194 }
1195 }
1196 if (hasEsim && hasBtCall) {
1197 if (!numberEsim.empty() && (numberEsim == numberBtCall)) {
1198 return true;
1199 }
1200 }
1201 return false;
1202 }
1203 #endif
1204 } // namespace Telephony
1205 } // namespace OHOS
1206