• 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 
28 namespace OHOS {
29 namespace Telephony {
30 std::list<sptr<CallBase>> CallObjectManager::callObjectPtrList_;
31 std::mutex CallObjectManager::listMutex_;
32 int32_t CallObjectManager::callId_ = CALL_START_ID;
33 std::condition_variable CallObjectManager::cv_;
34 bool CallObjectManager::isFirstDialCallAdded_ = false;
35 bool CallObjectManager::needWaitHold_ = false;
36 CellularCallInfo CallObjectManager::dialCallInfo_;
37 
CallObjectManager()38 CallObjectManager::CallObjectManager()
39 {
40 }
41 
~CallObjectManager()42 CallObjectManager::~CallObjectManager()
43 {
44     std::list<sptr<CallBase>>::iterator it = callObjectPtrList_.begin();
45     while (it != callObjectPtrList_.end()) {
46         (*it) = nullptr;
47         callObjectPtrList_.erase(it++);
48     }
49 }
50 
AddOneCallObject(sptr<CallBase> & call)51 int32_t CallObjectManager::AddOneCallObject(sptr<CallBase> &call)
52 {
53     if (call == nullptr) {
54         return TELEPHONY_ERR_LOCAL_PTR_NULL;
55     }
56     std::lock_guard<std::mutex> lock(listMutex_);
57     std::list<sptr<CallBase>>::iterator it = callObjectPtrList_.begin();
58     for (; it != callObjectPtrList_.end(); ++it) {
59         if ((*it)->GetCallID() == call->GetCallID()) {
60             TELEPHONY_LOGE("this call has existed yet!");
61             return CALL_ERR_PHONE_CALL_ALREADY_EXISTS;
62         }
63     }
64     CallAttributeInfo info;
65     call->GetCallAttributeInfo(info);
66     int32_t state;
67     bool isVoIPCallExists = false;
68     DelayedSingleton<CallControlManager>::GetInstance()->GetVoIPCallState(state);
69     if (state == (int32_t)CallStateToApp::CALL_STATE_RINGING) {
70         isVoIPCallExists = true;
71     }
72     if (callObjectPtrList_.size() == NO_CALL_EXIST && (!isVoIPCallExists || info.isEcc)) {
73         DelayedSingleton<CallConnectAbility>::GetInstance()->ConnectAbility(info);
74     }
75     callObjectPtrList_.emplace_back(call);
76     if (callObjectPtrList_.size() == ONE_CALL_EXIST &&
77         callObjectPtrList_.front()->GetTelCallState() == TelCallState::CALL_STATUS_DIALING) {
78         isFirstDialCallAdded_ = true;
79         cv_.notify_all();
80     }
81     TELEPHONY_LOGI("AddOneCallObject success! callId:%{public}d,call list size:%{public}zu", call->GetCallID(),
82         callObjectPtrList_.size());
83     return TELEPHONY_SUCCESS;
84 }
85 
DeleteOneCallObject(int32_t callId)86 int32_t CallObjectManager::DeleteOneCallObject(int32_t callId)
87 {
88     std::lock_guard<std::mutex> lock(listMutex_);
89     std::list<sptr<CallBase>>::iterator it;
90     for (it = callObjectPtrList_.begin(); it != callObjectPtrList_.end(); ++it) {
91         if ((*it)->GetCallID() == callId) {
92             callObjectPtrList_.erase(it);
93             TELEPHONY_LOGI("DeleteOneCallObject success! call list size:%{public}zu", callObjectPtrList_.size());
94             break;
95         }
96     }
97     if (callObjectPtrList_.size() == NO_CALL_EXIST) {
98         DelayedSingleton<CallConnectAbility>::GetInstance()->DisconnectAbility();
99     }
100     return TELEPHONY_SUCCESS;
101 }
102 
DeleteOneCallObject(sptr<CallBase> & call)103 void CallObjectManager::DeleteOneCallObject(sptr<CallBase> &call)
104 {
105     if (call == nullptr) {
106         TELEPHONY_LOGE("call is null!");
107         return;
108     }
109     std::lock_guard<std::mutex> lock(listMutex_);
110     callObjectPtrList_.remove(call);
111     if (callObjectPtrList_.size() == 0) {
112         DelayedSingleton<CallConnectAbility>::GetInstance()->DisconnectAbility();
113     }
114     TELEPHONY_LOGI("DeleteOneCallObject success! callList size:%{public}zu", callObjectPtrList_.size());
115 }
116 
GetOneCallObject(int32_t callId)117 sptr<CallBase> CallObjectManager::GetOneCallObject(int32_t callId)
118 {
119     sptr<CallBase> retPtr = nullptr;
120     std::lock_guard<std::mutex> lock(listMutex_);
121     std::list<sptr<CallBase>>::iterator it = CallObjectManager::callObjectPtrList_.begin();
122     for (; it != callObjectPtrList_.end(); ++it) {
123         if ((*it)->GetCallID() == callId) {
124             retPtr = *it;
125             break;
126         }
127     }
128     return retPtr;
129 }
130 
GetOneCallObject(std::string & phoneNumber)131 sptr<CallBase> CallObjectManager::GetOneCallObject(std::string &phoneNumber)
132 {
133     if (phoneNumber.empty()) {
134         TELEPHONY_LOGE("call is null!");
135         return nullptr;
136     }
137     sptr<CallBase> retPtr = nullptr;
138     std::lock_guard<std::mutex> lock(listMutex_);
139     std::list<sptr<CallBase>>::iterator it = callObjectPtrList_.begin();
140     for (; it != callObjectPtrList_.end(); ++it) {
141         std::string networkAddress =
142             DelayedSingleton<CallNumberUtils>::GetInstance()->RemovePostDialPhoneNumber((*it)->GetAccountNumber());
143         if (networkAddress == phoneNumber) {
144             TELEPHONY_LOGI("GetOneCallObject success!");
145             retPtr = *it;
146             break;
147         }
148     }
149     return retPtr;
150 }
151 
HasNewCall()152 int32_t CallObjectManager::HasNewCall()
153 {
154     std::lock_guard<std::mutex> lock(listMutex_);
155     std::list<sptr<CallBase>>::iterator it;
156     for (it = callObjectPtrList_.begin(); it != callObjectPtrList_.end(); ++it) {
157         if ((*it)->GetCallRunningState() == CallRunningState::CALL_RUNNING_STATE_CREATE ||
158             (*it)->GetCallRunningState() == CallRunningState::CALL_RUNNING_STATE_CONNECTING ||
159             (*it)->GetCallRunningState() == CallRunningState::CALL_RUNNING_STATE_DIALING) {
160             TELEPHONY_LOGE("there is already a new call[callId:%{public}d,state:%{public}d], please redial later",
161                 (*it)->GetCallID(), (*it)->GetCallRunningState());
162             return CALL_ERR_CALL_COUNTS_EXCEED_LIMIT;
163         }
164     }
165     return TELEPHONY_SUCCESS;
166 }
167 
IsNewCallAllowedCreate(bool & enabled)168 int32_t CallObjectManager::IsNewCallAllowedCreate(bool &enabled)
169 {
170     enabled = true;
171     std::list<sptr<CallBase>>::iterator it;
172     for (it = callObjectPtrList_.begin(); it != callObjectPtrList_.end(); ++it) {
173         if ((*it)->GetCallType() != CallType::TYPE_VOIP &&
174             ((*it)->GetCallRunningState() == CallRunningState::CALL_RUNNING_STATE_CREATE ||
175             (*it)->GetCallRunningState() == CallRunningState::CALL_RUNNING_STATE_CONNECTING ||
176             (*it)->GetCallRunningState() == CallRunningState::CALL_RUNNING_STATE_DIALING ||
177             (*it)->GetCallRunningState() == CallRunningState::CALL_RUNNING_STATE_RINGING)) {
178             TELEPHONY_LOGE("there is already a new call, please redial later");
179             enabled = false;
180             return TELEPHONY_ERR_SUCCESS;
181         }
182     }
183     int32_t count = 0;
184     int32_t callNum = 2;
185     std::list<int32_t> callIdList;
186     GetCarrierCallList(callIdList);
187     for (int32_t otherCallId : callIdList) {
188         sptr<CallBase> call = GetOneCallObject(otherCallId);
189         if (call != nullptr) {
190             TelConferenceState confState = call->GetTelConferenceState();
191             int32_t conferenceId = DelayedSingleton<ImsConference>::GetInstance()->GetMainCall();
192             if (confState != TelConferenceState::TEL_CONFERENCE_IDLE && conferenceId == otherCallId) {
193                 TELEPHONY_LOGI("there is conference call");
194                 count++;
195             } else if (confState == TelConferenceState::TEL_CONFERENCE_IDLE) {
196                 count++;
197             }
198         }
199     }
200     TELEPHONY_LOGI("the count is:%{public}d", count);
201     if (count >= callNum) {
202         enabled = false;
203     }
204     return TELEPHONY_ERR_SUCCESS;
205 }
206 
GetCurrentCallNum()207 int32_t CallObjectManager::GetCurrentCallNum()
208 {
209     int32_t count = 0;
210     std::list<int32_t> callIdList;
211     GetCarrierCallList(callIdList);
212     for (int32_t otherCallId : callIdList) {
213         sptr<CallBase> call = GetOneCallObject(otherCallId);
214         if (call != nullptr) {
215             TelConferenceState confState = call->GetTelConferenceState();
216             int32_t conferenceId = DelayedSingleton<ImsConference>::GetInstance()->GetMainCall();
217             if (confState != TelConferenceState::TEL_CONFERENCE_IDLE && conferenceId == otherCallId) {
218                 TELEPHONY_LOGI("there is conference call");
219                 count++;
220             } else if (confState == TelConferenceState::TEL_CONFERENCE_IDLE) {
221                 count++;
222             }
223         }
224     }
225     TELEPHONY_LOGI("the count is %{public}d", count);
226     return count;
227 }
228 
GetCarrierCallList(std::list<int32_t> & list)229 int32_t CallObjectManager::GetCarrierCallList(std::list<int32_t> &list)
230 {
231     list.clear();
232     std::lock_guard<std::mutex> lock(listMutex_);
233     std::list<sptr<CallBase>>::iterator it;
234     for (it = callObjectPtrList_.begin(); it != callObjectPtrList_.end(); ++it) {
235         if ((*it)->GetCallType() == CallType::TYPE_CS || (*it)->GetCallType() == CallType::TYPE_IMS ||
236             (*it)->GetCallType() == CallType::TYPE_SATELLITE) {
237             list.emplace_back((*it)->GetCallID());
238         }
239     }
240     return TELEPHONY_SUCCESS;
241 }
242 
HasRingingMaximum()243 bool CallObjectManager::HasRingingMaximum()
244 {
245     int32_t ringingCount = 0;
246     std::lock_guard<std::mutex> lock(listMutex_);
247     std::list<sptr<CallBase>>::iterator it;
248     for (it = callObjectPtrList_.begin(); it != callObjectPtrList_.end(); ++it) {
249         // Count the number of calls in the ringing state
250         if ((*it)->GetCallRunningState() == CallRunningState::CALL_RUNNING_STATE_RINGING) {
251             ringingCount++;
252         }
253     }
254     if (ringingCount >= RINGING_CALL_NUMBER_LEN) {
255         return true;
256     }
257     return false;
258 }
259 
HasDialingMaximum()260 bool CallObjectManager::HasDialingMaximum()
261 {
262     int32_t dialingCount = 0;
263     std::lock_guard<std::mutex> lock(listMutex_);
264     std::list<sptr<CallBase>>::iterator it;
265     for (it = callObjectPtrList_.begin(); it != callObjectPtrList_.end(); ++it) {
266         // Count the number of calls in the active state
267         if ((*it)->GetCallRunningState() == CallRunningState::CALL_RUNNING_STATE_ACTIVE) {
268             dialingCount++;
269         }
270     }
271     if (dialingCount >= DIALING_CALL_NUMBER_LEN) {
272         return true;
273     }
274     return false;
275 }
276 
HasEmergencyCall(bool & enabled)277 int32_t CallObjectManager::HasEmergencyCall(bool &enabled)
278 {
279     enabled = false;
280     std::lock_guard<std::mutex> lock(listMutex_);
281     std::list<sptr<CallBase>>::iterator it;
282     for (it = callObjectPtrList_.begin(); it != callObjectPtrList_.end(); ++it) {
283         if ((*it)->GetEmergencyState()) {
284             enabled = true;
285         }
286     }
287     return TELEPHONY_ERR_SUCCESS;
288 }
289 
GetNewCallId()290 int32_t CallObjectManager::GetNewCallId()
291 {
292     int32_t ret = 0;
293     std::lock_guard<std::mutex> lock(listMutex_);
294     ret = ++callId_;
295     return ret;
296 }
297 
IsCallExist(int32_t callId)298 bool CallObjectManager::IsCallExist(int32_t callId)
299 {
300     std::lock_guard<std::mutex> lock(listMutex_);
301     std::list<sptr<CallBase>>::iterator it = callObjectPtrList_.begin();
302     for (; it != callObjectPtrList_.end(); ++it) {
303         if ((*it)->GetCallID() == callId) {
304             TELEPHONY_LOGW("the call is exist.");
305             return true;
306         }
307     }
308     return false;
309 }
310 
IsCallExist(std::string & phoneNumber)311 bool CallObjectManager::IsCallExist(std::string &phoneNumber)
312 {
313     if (phoneNumber.empty()) {
314         return false;
315     }
316     std::lock_guard<std::mutex> lock(listMutex_);
317     std::list<sptr<CallBase>>::iterator it = callObjectPtrList_.begin();
318     for (; it != callObjectPtrList_.end(); ++it) {
319         std::string networkAddress =
320             DelayedSingleton<CallNumberUtils>::GetInstance()->RemovePostDialPhoneNumber((*it)->GetAccountNumber());
321         if (networkAddress == phoneNumber) {
322             return true;
323         }
324     }
325     TELEPHONY_LOGI("the call is does not exist.");
326     return false;
327 }
328 
HasCallExist()329 bool CallObjectManager::HasCallExist()
330 {
331     std::lock_guard<std::mutex> lock(listMutex_);
332     if (callObjectPtrList_.empty()) {
333         TELEPHONY_LOGI("call list size:%{public}zu", callObjectPtrList_.size());
334         return false;
335     }
336     return true;
337 }
338 
GetAllCallList()339 std::list<sptr<CallBase>> CallObjectManager::GetAllCallList()
340 {
341     std::lock_guard<std::mutex> lock(listMutex_);
342     return callObjectPtrList_;
343 }
344 
HasCellularCallExist()345 bool CallObjectManager::HasCellularCallExist()
346 {
347     std::lock_guard<std::mutex> lock(listMutex_);
348     std::list<sptr<CallBase>>::iterator it;
349     for (it = callObjectPtrList_.begin(); it != callObjectPtrList_.end(); ++it) {
350         if ((*it)->GetCallType() == CallType::TYPE_CS || (*it)->GetCallType() == CallType::TYPE_IMS ||
351             (*it)->GetCallType() == CallType::TYPE_SATELLITE) {
352             return true;
353         }
354     }
355     return false;
356 }
357 
HasVoipCallExist()358 bool CallObjectManager::HasVoipCallExist()
359 {
360     std::lock_guard<std::mutex> lock(listMutex_);
361     std::list<sptr<CallBase>>::iterator it;
362     for (it = callObjectPtrList_.begin(); it != callObjectPtrList_.end(); ++it) {
363         if ((*it)->GetCallType() == CallType::TYPE_VOIP) {
364             return true;
365         }
366     }
367     return false;
368 }
369 
HasVideoCall()370 bool CallObjectManager::HasVideoCall()
371 {
372     std::lock_guard<std::mutex> lock(listMutex_);
373     std::list<sptr<CallBase>>::iterator it;
374     for (it = callObjectPtrList_.begin(); it != callObjectPtrList_.end(); ++it) {
375         if ((*it)->GetVideoStateType() == VideoStateType::TYPE_VIDEO && (*it)->GetCallType() != CallType::TYPE_VOIP) {
376             return true;
377         }
378     }
379     return false;
380 }
381 
HasRingingCall(bool & enabled)382 int32_t CallObjectManager::HasRingingCall(bool &enabled)
383 {
384     enabled = false;
385     std::lock_guard<std::mutex> lock(listMutex_);
386     std::list<sptr<CallBase>>::iterator it;
387     for (it = callObjectPtrList_.begin(); it != callObjectPtrList_.end(); ++it) {
388         // Count the number of calls in the ringing state
389         if ((*it)->GetCallRunningState() == CallRunningState::CALL_RUNNING_STATE_RINGING) {
390             enabled = true;
391             break;
392         }
393     }
394     return TELEPHONY_ERR_SUCCESS;
395 }
396 
GetCallState(int32_t callId)397 TelCallState CallObjectManager::GetCallState(int32_t callId)
398 {
399     TelCallState retState = TelCallState::CALL_STATUS_IDLE;
400     std::lock_guard<std::mutex> lock(listMutex_);
401     std::list<sptr<CallBase>>::iterator it = CallObjectManager::callObjectPtrList_.begin();
402     for (; it != callObjectPtrList_.end(); ++it) {
403         if ((*it)->GetCallID() == callId) {
404             retState = (*it)->GetTelCallState();
405             break;
406         }
407     }
408     return retState;
409 }
410 
GetOneCallObject(CallRunningState callState)411 sptr<CallBase> CallObjectManager::GetOneCallObject(CallRunningState callState)
412 {
413     std::lock_guard<std::mutex> lock(listMutex_);
414     std::list<sptr<CallBase>>::reverse_iterator it;
415     for (it = callObjectPtrList_.rbegin(); it != callObjectPtrList_.rend(); ++it) {
416         if ((*it)->GetCallRunningState() == callState) {
417             return (*it);
418         }
419     }
420     return nullptr;
421 }
422 
GetOneCallObjectByIndex(int32_t index)423 sptr<CallBase> CallObjectManager::GetOneCallObjectByIndex(int32_t index)
424 {
425     std::lock_guard<std::mutex> lock(listMutex_);
426     std::list<sptr<CallBase>>::iterator it = callObjectPtrList_.begin();
427     for (; it != callObjectPtrList_.end(); ++it) {
428         if ((*it)->GetCallIndex() == index) {
429             return (*it);
430         }
431     }
432     return nullptr;
433 }
434 
GetOneCallObjectByIndexAndSlotId(int32_t index,int32_t slotId)435 sptr<CallBase> CallObjectManager::GetOneCallObjectByIndexAndSlotId(int32_t index, int32_t slotId)
436 {
437     std::lock_guard<std::mutex> lock(listMutex_);
438     std::list<sptr<CallBase>>::iterator it = callObjectPtrList_.begin();
439     for (; it != callObjectPtrList_.end(); ++it) {
440         if ((*it)->GetCallIndex() == index) {
441             if ((*it)->GetSlotId() == slotId) {
442                 return (*it);
443             }
444         }
445     }
446     return nullptr;
447 }
448 
GetOneCallObjectByVoipCallId(std::string voipCallId)449 sptr<CallBase> CallObjectManager::GetOneCallObjectByVoipCallId(std::string voipCallId)
450 {
451     std::lock_guard<std::mutex> lock(listMutex_);
452     std::list<sptr<CallBase>>::iterator it = callObjectPtrList_.begin();
453     for (; it != callObjectPtrList_.end(); ++it) {
454         if ((*it)->GetCallType() == CallType::TYPE_VOIP) {
455             sptr<VoIPCall> voipCall = reinterpret_cast<VoIPCall *>((*it).GetRefPtr());
456             if (voipCall->GetVoipCallId() == voipCallId) {
457                 return (*it);
458             }
459         }
460     }
461     return nullptr;
462 }
463 
IsCallExist(CallType callType,TelCallState callState)464 bool CallObjectManager::IsCallExist(CallType callType, TelCallState callState)
465 {
466     std::lock_guard<std::mutex> lock(listMutex_);
467     std::list<sptr<CallBase>>::iterator it;
468     for (it = callObjectPtrList_.begin(); it != callObjectPtrList_.end(); ++it) {
469         if ((*it)->GetCallType() == callType && (*it)->GetTelCallState() == callState) {
470             return true;
471         }
472     }
473     TELEPHONY_LOGI("the call is does not exist.");
474     return false;
475 }
476 
IsCallExist(TelCallState callState)477 bool CallObjectManager::IsCallExist(TelCallState callState)
478 {
479     std::lock_guard<std::mutex> lock(listMutex_);
480     std::list<sptr<CallBase>>::iterator it;
481     for (it = callObjectPtrList_.begin(); it != callObjectPtrList_.end(); ++it) {
482         if ((*it)->GetTelCallState() == callState) {
483             return true;
484         }
485     }
486     TELEPHONY_LOGI("the call is does not exist.");
487     return false;
488 }
489 
IsCallExist(TelCallState callState,int32_t & callId)490 bool CallObjectManager::IsCallExist(TelCallState callState, int32_t &callId)
491 {
492     std::lock_guard<std::mutex> lock(listMutex_);
493     std::list<sptr<CallBase>>::iterator it;
494     for (it = callObjectPtrList_.begin(); it != callObjectPtrList_.end(); ++it) {
495         if ((*it)->GetTelCallState() == callState) {
496             callId = (*it)->GetCallID();
497             return true;
498         }
499     }
500     TELEPHONY_LOGI("the call is does not exist.");
501     return false;
502 }
503 
IsConferenceCallExist(TelConferenceState state,int32_t & callId)504 bool CallObjectManager::IsConferenceCallExist(TelConferenceState state, int32_t &callId)
505 {
506     std::lock_guard<std::mutex> lock(listMutex_);
507     std::list<sptr<CallBase>>::iterator it;
508     for (it = callObjectPtrList_.begin(); it != callObjectPtrList_.end(); ++it) {
509         if ((*it)->GetTelConferenceState() == state) {
510             callId = (*it)->GetCallID();
511             return true;
512         }
513     }
514     TELEPHONY_LOGI("the call is does not exist.");
515     return false;
516 }
517 
GetCallNum(TelCallState callState)518 int32_t CallObjectManager::GetCallNum(TelCallState callState)
519 {
520     int32_t num = 0;
521     std::lock_guard<std::mutex> lock(listMutex_);
522     std::list<sptr<CallBase>>::iterator it;
523     for (it = callObjectPtrList_.begin(); it != callObjectPtrList_.end(); ++it) {
524         if ((*it)->GetTelCallState() == callState) {
525             ++num;
526             continue;
527         }
528     }
529     TELEPHONY_LOGI("callState:%{public}d, num:%{public}d", callState, num);
530     return num;
531 }
532 
GetCallNumber(TelCallState callState)533 std::string CallObjectManager::GetCallNumber(TelCallState callState)
534 {
535     std::string number = "";
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)->GetTelCallState() == callState) {
540             number = (*it)->GetAccountNumber();
541             break;
542         }
543     }
544     return number;
545 }
546 
GetCallInfoList(int32_t slotId)547 std::vector<CallAttributeInfo> CallObjectManager::GetCallInfoList(int32_t slotId)
548 {
549     std::vector<CallAttributeInfo> callVec;
550     CallAttributeInfo info;
551     callVec.clear();
552     std::lock_guard<std::mutex> lock(listMutex_);
553     std::list<sptr<CallBase>>::iterator it;
554     for (it = callObjectPtrList_.begin(); it != callObjectPtrList_.end(); ++it) {
555         (void)memset_s(&info, sizeof(CallAttributeInfo), 0, sizeof(CallAttributeInfo));
556         (*it)->GetCallAttributeInfo(info);
557         if (info.accountId == slotId && info.callType != CallType::TYPE_OTT) {
558             callVec.emplace_back(info);
559         }
560     }
561     return callVec;
562 }
563 
GetForegroundLiveCall()564 sptr<CallBase> CallObjectManager::GetForegroundLiveCall()
565 {
566     std::lock_guard<std::mutex> lock(listMutex_);
567     sptr<CallBase> liveCall = nullptr;
568     for (std::list<sptr<CallBase>>::iterator it = callObjectPtrList_.begin(); it != callObjectPtrList_.end(); ++it) {
569         TelCallState telCallState = (*it)->GetTelCallState();
570         if (telCallState == TelCallState::CALL_STATUS_WAITING ||
571             telCallState == TelCallState::CALL_STATUS_INCOMING) {
572             liveCall = (*it);
573             break;
574         }
575         if (telCallState == TelCallState::CALL_STATUS_ALERTING ||
576             telCallState == TelCallState::CALL_STATUS_DIALING) {
577             liveCall = (*it);
578             continue;
579         }
580         if (telCallState == TelCallState::CALL_STATUS_ACTIVE) {
581             liveCall = (*it);
582             continue;
583         }
584         if (telCallState == TelCallState::CALL_STATUS_HOLDING) {
585             liveCall = (*it);
586             continue;
587         }
588     }
589     return liveCall;
590 }
591 
GetDialCallInfo()592 CellularCallInfo CallObjectManager::GetDialCallInfo()
593 {
594     return dialCallInfo_;
595 }
596 
DealFailDial(sptr<CallBase> call)597 int32_t CallObjectManager::DealFailDial(sptr<CallBase> call)
598 {
599     CallDetailInfo callDetatilInfo;
600     if (memset_s(&callDetatilInfo, sizeof(CallDetailInfo), 0, sizeof(CallDetailInfo)) != EOK) {
601         TELEPHONY_LOGE("memset_s callDetatilInfo fail");
602         return TELEPHONY_ERR_MEMSET_FAIL;
603     }
604     std::string number = call->GetAccountNumber();
605     callDetatilInfo.callType = call->GetCallType();
606     callDetatilInfo.accountId = call->GetSlotId();
607     callDetatilInfo.state = TelCallState::CALL_STATUS_DISCONNECTED;
608     callDetatilInfo.callMode = call->GetVideoStateType();
609     callDetatilInfo.voiceDomain = static_cast<int32_t>(call->GetCallType());
610     if (number.length() > kMaxNumberLen) {
611         TELEPHONY_LOGE("numbser length out of range");
612         return CALL_ERR_NUMBER_OUT_OF_RANGE;
613     }
614     if (memcpy_s(&callDetatilInfo.phoneNum, kMaxNumberLen, number.c_str(), number.length()) != EOK) {
615         TELEPHONY_LOGE("memcpy_s number failed!");
616         return TELEPHONY_ERR_MEMCPY_FAIL;
617     }
618 
619     return DelayedSingleton<ReportCallInfoHandler>::GetInstance()->UpdateCallReportInfo(callDetatilInfo);
620 }
621 
GetAllCallInfoList()622 std::vector<CallAttributeInfo> CallObjectManager::GetAllCallInfoList()
623 {
624     std::vector<CallAttributeInfo> callVec;
625     callVec.clear();
626     std::lock_guard<std::mutex> lock(listMutex_);
627     std::list<sptr<CallBase>>::iterator it;
628     for (it = callObjectPtrList_.begin(); it != callObjectPtrList_.end(); ++it) {
629         CallAttributeInfo info;
630         if ((*it) == nullptr) {
631             TELEPHONY_LOGE("call is nullptr");
632             continue;
633         }
634         (*it)->GetCallAttributeInfo(info);
635         callVec.emplace_back(info);
636     }
637     return callVec;
638 }
639 } // namespace Telephony
640 } // namespace OHOS
641