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