• 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_base.h"
17 
18 #include <securec.h>
19 
20 #include "audio_control_manager.h"
21 #include "bluetooth_call_manager.h"
22 #include "call_manager_errors.h"
23 #include "cellular_call_connection.h"
24 #include "common_type.h"
25 #include "ffrt.h"
26 #include "telephony_log_wrapper.h"
27 #include "voip_call.h"
28 #include "voip_call_connection.h"
29 #include "call_manager_info.h"
30 #include "antifraud_service.h"
31 
32 namespace OHOS {
33 namespace Telephony {
34 static const int MILLI_TO_BASE = 1000;
35 
CallBase(DialParaInfo & info)36 CallBase::CallBase(DialParaInfo &info)
37     : callId_(info.callId), callType_(info.callType), videoState_(info.videoState), accountNumber_(info.number),
38       bundleName_(info.bundleName), callRunningState_(CallRunningState::CALL_RUNNING_STATE_CREATE),
39       conferenceState_(TelConferenceState::TEL_CONFERENCE_IDLE), startTime_(0),
40       direction_(CallDirection::CALL_DIRECTION_IN), policyFlag_(0), callState_(info.callState), autoAnswerState_(false),
41       canUnHoldState_(true), canSwitchCallState_(true), answerVideoState_(0), isSpeakerphoneOn_(false),
42       callEndedType_(CallEndedType::UNKNOWN), callBeginTime_(0), callCreateTime_(0), callEndTime_(0), ringBeginTime_(0),
43       ringEndTime_(0), answerType_(CallAnswerType::CALL_ANSWER_MISSED), accountId_(info.accountId),
44       crsType_(info.crsType), originalCallType_(info.originalCallType), isMuted_(false), numberLocation_("default"),
45       blockReason_(0), isEccContact_(false), celiaCallType_(-1), extraParams_(info.extraParams), isAnswered_(false),
46       detectDetails_(""), phoneOrWatch_(info.phoneOrWatch)
47 {
48     (void)memset_s(&contactInfo_, sizeof(ContactInfo), 0, sizeof(ContactInfo));
49     (void)memset_s(&numberMarkInfo_, sizeof(NumberMarkInfo), 0, sizeof(NumberMarkInfo));
50     numberMarkInfo_.markType = MarkType::MARK_TYPE_DEFAULT;
51 }
52 
CallBase(DialParaInfo & info,AppExecFwk::PacMap & extras)53 CallBase::CallBase(DialParaInfo &info, AppExecFwk::PacMap &extras)
54     : callId_(info.callId), callType_(info.callType), videoState_(info.videoState), accountNumber_(info.number),
55       bundleName_(info.bundleName), callRunningState_(CallRunningState::CALL_RUNNING_STATE_CREATE),
56       conferenceState_(TelConferenceState::TEL_CONFERENCE_IDLE), startTime_(0),
57       direction_(CallDirection::CALL_DIRECTION_OUT), policyFlag_(0), callState_(info.callState),
58       autoAnswerState_(false), canUnHoldState_(true), canSwitchCallState_(true), answerVideoState_(0),
59       isSpeakerphoneOn_(false), callEndedType_(CallEndedType::UNKNOWN), callBeginTime_(0), callCreateTime_(0),
60       callEndTime_(0), ringBeginTime_(0), ringEndTime_(0), answerType_(CallAnswerType::CALL_ANSWER_MISSED),
61       accountId_(info.accountId), crsType_(info.crsType), originalCallType_(info.originalCallType), isMuted_(false),
62       numberLocation_("default"), blockReason_(0), isEccContact_(false), celiaCallType_(-1),
63       extraParams_(info.extraParams), isAnswered_(false), detectDetails_(""), phoneOrWatch_(info.phoneOrWatch)
64 {
65     (void)memset_s(&contactInfo_, sizeof(ContactInfo), 0, sizeof(ContactInfo));
66     (void)memset_s(&numberMarkInfo_, sizeof(NumberMarkInfo), 0, sizeof(NumberMarkInfo));
67     numberMarkInfo_.markType = MarkType::MARK_TYPE_DEFAULT;
68 }
69 
~CallBase()70 CallBase::~CallBase() {}
71 
DialCallBase()72 int32_t CallBase::DialCallBase()
73 {
74     std::lock_guard<std::mutex> lock(mutex_);
75     callRunningState_ = CallRunningState::CALL_RUNNING_STATE_CONNECTING;
76     TELEPHONY_LOGI("start to set audio");
77     // Set audio, set hands-free
78     ffrt::submit([=]() { HangUpVoipCall(); });
79     return TELEPHONY_SUCCESS;
80 }
81 
HangUpVoipCall()82 void CallBase::HangUpVoipCall()
83 {
84     std::vector<CallAttributeInfo> callAttributeInfo = CallObjectManager::GetAllCallInfoList();
85     std::vector<CallAttributeInfo>::iterator it = callAttributeInfo.begin();
86     while (it != callAttributeInfo.end()) {
87         CallAttributeInfo callinfo = (*it);
88         TelCallState callState = callinfo.callState;
89         ++it;
90         if (callinfo.callType == CallType::TYPE_VOIP) {
91             sptr<CallBase> tempCall = CallObjectManager::GetOneCallObject(callinfo.callId);
92             if (tempCall == nullptr) {
93                 TELEPHONY_LOGE("the call object is nullptr, callId:%{public}d", callinfo.callId);
94                 continue;
95             }
96             sptr<VoIPCall> call = static_cast<VoIPCall *>(static_cast<void *>(tempCall.GetRefPtr()));
97             if (call == nullptr) {
98                 TELEPHONY_LOGE("the call object is nullptr, callId:%{public}d", callinfo.callId);
99                 continue;
100             }
101             TelCallState voipCallState = call->GetTelCallState();
102             if (voipCallState == TelCallState::CALL_STATUS_ACTIVE) {
103                 TELEPHONY_LOGI("the voip call with callId %{public}d is active, no need to hangup", call->GetCallID());
104             } else if (voipCallState == TelCallState::CALL_STATUS_INCOMING) {
105                 call->RejectCall();
106             } else {
107                 call->HangUpCall(ErrorReason::CELLULAR_CALL_EXISTS);
108             }
109         }
110     }
111 }
112 
IncomingCallBase()113 int32_t CallBase::IncomingCallBase()
114 {
115     std::lock_guard<std::mutex> lock(mutex_);
116     callRunningState_ = CallRunningState::CALL_RUNNING_STATE_RINGING;
117     return TELEPHONY_SUCCESS;
118 }
119 
AnswerCallBase()120 int32_t CallBase::AnswerCallBase()
121 {
122     if (!IsCurrentRinging()) {
123         TELEPHONY_LOGW("the device is currently not ringing");
124         return CALL_ERR_PHONE_ANSWER_IS_BUSY;
125     }
126     return TELEPHONY_SUCCESS;
127 }
128 
RejectCallBase()129 int32_t CallBase::RejectCallBase()
130 {
131     answerType_ = CallAnswerType::CALL_ANSWER_REJECT;
132     return TELEPHONY_SUCCESS;
133 }
134 
GetExtraParams()135 AAFwk::WantParams CallBase::GetExtraParams()
136 {
137     std::lock_guard<std::mutex> lock(mutex_);
138     return extraParams_;
139 }
140 
SetExtraParams(AAFwk::WantParams extraParams)141 void CallBase::SetExtraParams(AAFwk::WantParams extraParams)
142 {
143     std::lock_guard<std::mutex> lock(mutex_);
144     extraParams_ = extraParams;
145 }
146 
GetCallAttributeBaseInfo(CallAttributeInfo & info)147 void CallBase::GetCallAttributeBaseInfo(CallAttributeInfo &info)
148 {
149     std::lock_guard<std::mutex> lock(mutex_);
150     (void)memset_s(info.accountNumber, kMaxNumberLen, 0, kMaxNumberLen);
151     if (accountNumber_.length() > static_cast<size_t>(kMaxNumberLen)) {
152         TELEPHONY_LOGE("Number out of limit!");
153         return;
154     }
155     if (memcpy_s(info.accountNumber, kMaxNumberLen, accountNumber_.c_str(), accountNumber_.length()) == 0) {
156         info.speakerphoneOn = isSpeakerphoneOn_;
157         info.videoState = videoState_;
158         info.startTime = startTime_;
159         info.callType = callType_;
160         info.callId = callId_;
161         info.callState = callState_;
162         info.conferenceState = conferenceState_;
163         info.callBeginTime = callBeginTime_;
164         info.callCreateTime = callCreateTime_;
165         info.callEndTime = callEndTime_;
166         info.ringBeginTime = ringBeginTime_;
167         info.ringEndTime = ringEndTime_;
168         info.callDirection = direction_;
169         info.answerType = answerType_;
170         info.accountId = accountId_;
171         info.crsType = crsType_;
172         info.originalCallType = originalCallType_;
173         info.isEccContact = isEccContact_;
174         info.celiaCallType = celiaCallType_;
175         info.extraParamsString = AAFwk::WantParamWrapper(extraParams_).ToString();
176         AAFwk::WantParams object = AAFwk::WantParamWrapper::ParseWantParamsWithBrackets(info.extraParamsString);
177         info.name = object.GetStringParam("name");
178         info.namePresentation = object.GetIntParam("namePresentation", 0);
179         info.antiFraudState = object.GetIntParam("antiFraudState", 0);
180         info.phoneOrWatch = phoneOrWatch_;
181         if (memset_s(info.numberLocation, kMaxNumberLen, 0, kMaxNumberLen) != EOK) {
182             TELEPHONY_LOGE("memset_s numberLocation fail");
183             return;
184         }
185         if (memcpy_s(info.numberLocation, kMaxNumberLen, numberLocation_.c_str(), numberLocation_.length()) != EOK) {
186             TELEPHONY_LOGE("memcpy_s numberLocation fail");
187             return;
188         }
189         if (memcpy_s(info.contactName, kMaxNumberLen, contactInfo_.name.c_str(), contactInfo_.name.length()) != EOK) {
190             TELEPHONY_LOGE("memcpy_s contact name fail");
191         }
192         info.numberMarkInfo = numberMarkInfo_;
193         if (info.antiFraudState == static_cast<int32_t>(AntiFraudState::ANTIFRAUD_STATE_RISK)) {
194             info.numberMarkInfo.markType = MarkType::MARK_TYPE_FRAUD_RISK;
195             TELEPHONY_LOGI("mark fraud risk success");
196         }
197         info.blockReason = blockReason_;
198         if (bundleName_.length() > static_cast<size_t>(kMaxBundleNameLen)) {
199             TELEPHONY_LOGE("Number out of limit!");
200             return;
201         }
202         errno_t result = memcpy_s(info.bundleName, kMaxBundleNameLen, bundleName_.c_str(), bundleName_.length());
203         if (result != EOK) {
204             TELEPHONY_LOGE("memcpy_s failed!");
205         }
206         if (memcpy_s(info.detectDetails, sizeof(info.detectDetails), detectDetails_.c_str(), detectDetails_.length())
207             != EOK) {
208             TELEPHONY_LOGE("memcpy_s detectDetails fail");
209         }
210     }
211 }
212 
GetCallID()213 int32_t CallBase::GetCallID()
214 {
215     std::lock_guard<std::mutex> lock(mutex_);
216     return callId_;
217 }
218 
GetCallType()219 CallType CallBase::GetCallType()
220 {
221     return callType_;
222 }
223 
GetCallRunningState()224 CallRunningState CallBase::GetCallRunningState()
225 {
226     std::lock_guard<std::mutex> lock(mutex_);
227     return callRunningState_;
228 }
229 
230 // transfer from external call state to callmanager local state
SetTelCallState(TelCallState nextState)231 int32_t CallBase::SetTelCallState(TelCallState nextState)
232 {
233     std::lock_guard<std::mutex> lock(mutex_);
234     if (callRunningState_ != CallRunningState::CALL_RUNNING_STATE_CREATE && callState_ == nextState &&
235         nextState != TelCallState::CALL_STATUS_DIALING) {
236         TELEPHONY_LOGI("Call state duplication %{public}d", nextState);
237         return CALL_ERR_NOT_NEW_STATE;
238     }
239     callState_ = nextState;
240     switch (nextState) {
241         case TelCallState::CALL_STATUS_DIALING:
242             StateChangesToDialing();
243             break;
244         case TelCallState::CALL_STATUS_INCOMING:
245             StateChangesToIncoming();
246             break;
247         case TelCallState::CALL_STATUS_WAITING:
248             StateChangesToWaiting();
249             break;
250         case TelCallState::CALL_STATUS_ACTIVE:
251             StateChangesToActive();
252             break;
253         case TelCallState::CALL_STATUS_HOLDING:
254             StateChangesToHolding();
255             break;
256         case TelCallState::CALL_STATUS_DISCONNECTED:
257             StateChangesToDisconnected();
258             break;
259         case TelCallState::CALL_STATUS_DISCONNECTING:
260             StateChangesToDisconnecting();
261             break;
262         case TelCallState::CALL_STATUS_ALERTING:
263             StateChangesToAlerting();
264             break;
265         default:
266             break;
267     }
268     return TELEPHONY_SUCCESS;
269 }
270 
StateChangesToDialing()271 void CallBase::StateChangesToDialing()
272 {
273     callRunningState_ = CallRunningState::CALL_RUNNING_STATE_DIALING;
274 }
275 
StateChangesToIncoming()276 void CallBase::StateChangesToIncoming()
277 {
278     callRunningState_ = CallRunningState::CALL_RUNNING_STATE_RINGING;
279     ringBeginTime_ = time(nullptr);
280 }
281 
StateChangesToWaiting()282 void CallBase::StateChangesToWaiting()
283 {
284     callRunningState_ = CallRunningState::CALL_RUNNING_STATE_RINGING;
285     ringBeginTime_ = time(nullptr);
286 }
287 
StateChangesToActive()288 void CallBase::StateChangesToActive()
289 {
290     callRunningState_ = CallRunningState::CALL_RUNNING_STATE_ACTIVE;
291     if (callBeginTime_ == 0) {
292         callBeginTime_ = ringEndTime_ = time(nullptr);
293         if (callType_ == CallType::TYPE_VOIP) {
294             struct timeval tv;
295             gettimeofday(&tv, nullptr);
296             startTime_ = tv.tv_sec * MILLI_TO_BASE + tv.tv_usec / MILLI_TO_BASE;
297         } else {
298             startTime_ = callBeginTime_;
299         }
300         answerType_ = CallAnswerType::CALL_ANSWER_ACTIVED;
301     }
302 }
303 
StateChangesToHolding()304 void CallBase::StateChangesToHolding()
305 {
306     callRunningState_ = CallRunningState::CALL_RUNNING_STATE_HOLD;
307     if (conferenceState_ == TelConferenceState::TEL_CONFERENCE_ACTIVE) {
308         conferenceState_ = TelConferenceState::TEL_CONFERENCE_DISCONNECTED;
309     }
310 }
311 
StateChangesToDisconnected()312 void CallBase::StateChangesToDisconnected()
313 {
314     callRunningState_ = CallRunningState::CALL_RUNNING_STATE_ENDED;
315     if (conferenceState_ == TelConferenceState::TEL_CONFERENCE_DISCONNECTING ||
316         conferenceState_ == TelConferenceState::TEL_CONFERENCE_ACTIVE) {
317         conferenceState_ = TelConferenceState::TEL_CONFERENCE_DISCONNECTED;
318     }
319     callEndTime_ = time(nullptr);
320     if (ringEndTime_ == 0) {
321         ringEndTime_ = time(nullptr);
322     }
323 }
324 
StateChangesToDisconnecting()325 void CallBase::StateChangesToDisconnecting()
326 {
327     callRunningState_ = CallRunningState::CALL_RUNNING_STATE_ENDING;
328     if (conferenceState_ == TelConferenceState::TEL_CONFERENCE_ACTIVE) {
329         conferenceState_ = TelConferenceState::TEL_CONFERENCE_DISCONNECTING;
330     }
331     if (ringEndTime_ == 0) {
332         ringEndTime_ = time(nullptr);
333     }
334 }
335 
StateChangesToAlerting()336 void CallBase::StateChangesToAlerting()
337 {
338     callRunningState_ = CallRunningState::CALL_RUNNING_STATE_DIALING;
339     ringBeginTime_ = time(nullptr);
340 }
341 
GetTelCallState()342 TelCallState CallBase::GetTelCallState()
343 {
344     std::lock_guard<std::mutex> lock(mutex_);
345     return callState_;
346 }
347 
SetAutoAnswerState(bool flag)348 void CallBase::SetAutoAnswerState(bool flag)
349 {
350     std::lock_guard<std::mutex> lock(mutex_);
351     autoAnswerState_ = flag;
352     TELEPHONY_LOGI("NeedAutoAnswer:%{public}d", autoAnswerState_);
353 }
354 
GetAutoAnswerState()355 bool CallBase::GetAutoAnswerState()
356 {
357     std::lock_guard<std::mutex> lock(mutex_);
358     return autoAnswerState_;
359 }
360 
SetAnswerVideoState(int32_t videoState)361 void CallBase::SetAnswerVideoState(int32_t videoState)
362 {
363     std::lock_guard<std::mutex> lock(mutex_);
364     answerVideoState_ = videoState;
365     TELEPHONY_LOGI("set answer video state :%{public}d", answerVideoState_);
366 }
367 
GetAnswerVideoState()368 int32_t CallBase::GetAnswerVideoState()
369 {
370     std::lock_guard<std::mutex> lock(mutex_);
371     return answerVideoState_;
372 }
373 
SetCanUnHoldState(bool flag)374 void CallBase::SetCanUnHoldState(bool flag)
375 {
376     std::lock_guard<std::mutex> lock(mutex_);
377     canUnHoldState_ = flag;
378     TELEPHONY_LOGI("CanUnHoldState:%{public}d", canUnHoldState_);
379 }
380 
GetCanUnHoldState()381 bool CallBase::GetCanUnHoldState()
382 {
383     std::lock_guard<std::mutex> lock(mutex_);
384     TELEPHONY_LOGI("CanUnHoldState:%{public}d", canUnHoldState_);
385     return canUnHoldState_;
386 }
387 
SetCanSwitchCallState(bool flag)388 void CallBase::SetCanSwitchCallState(bool flag)
389 {
390     std::lock_guard<std::mutex> lock(mutex_);
391     canSwitchCallState_ = flag;
392     TELEPHONY_LOGI("CanSwitchCallState:%{public}d", canSwitchCallState_);
393 }
394 
GetCanSwitchCallState()395 bool CallBase::GetCanSwitchCallState()
396 {
397     std::lock_guard<std::mutex> lock(mutex_);
398     TELEPHONY_LOGI("CanSwitchCallState:%{public}d", canSwitchCallState_);
399     return canSwitchCallState_;
400 }
401 
SetTelConferenceState(TelConferenceState state)402 void CallBase::SetTelConferenceState(TelConferenceState state)
403 {
404     std::lock_guard<std::mutex> lock(mutex_);
405     conferenceState_ = state;
406     TELEPHONY_LOGI("SetTelConferenceState, callId:%{public}d, state:%{public}d", callId_, state);
407 }
408 
GetTelConferenceState()409 TelConferenceState CallBase::GetTelConferenceState()
410 {
411     std::lock_guard<std::mutex> lock(mutex_);
412     return conferenceState_;
413 }
414 
GetVideoStateType()415 VideoStateType CallBase::GetVideoStateType()
416 {
417     std::lock_guard<std::mutex> lock(mutex_);
418     return videoState_;
419 }
420 
SetVideoStateType(VideoStateType mediaType)421 void CallBase::SetVideoStateType(VideoStateType mediaType)
422 {
423     std::lock_guard<std::mutex> lock(mutex_);
424     videoState_ = mediaType;
425 }
426 
GetCrsType()427 int32_t CallBase::GetCrsType()
428 {
429     std::lock_guard<std::mutex> lock(mutex_);
430     return crsType_;
431 }
432 
SetCrsType(int32_t crsType)433 void CallBase::SetCrsType(int32_t crsType)
434 {
435     std::lock_guard<std::mutex> lock(mutex_);
436     crsType_ = crsType;
437 }
438 
GetOriginalCallType()439 int32_t CallBase::GetOriginalCallType()
440 {
441     std::lock_guard<std::mutex> lock(mutex_);
442     return originalCallType_;
443 }
444 
SetOriginalCallType(int32_t originalCallType)445 void CallBase::SetOriginalCallType(int32_t originalCallType)
446 {
447     std::lock_guard<std::mutex> lock(mutex_);
448     originalCallType_ = originalCallType;
449 }
450 
SetIsEccContact(bool isEccContact)451 void CallBase::SetIsEccContact(bool isEccContact)
452 {
453     std::lock_guard<std::mutex> lock(mutex_);
454     isEccContact_ = isEccContact;
455 }
456 
SetNumberLocation(std::string numberLocation)457 void CallBase::SetNumberLocation(std::string numberLocation)
458 {
459     std::lock_guard<std::mutex> lock(mutex_);
460     numberLocation_ = numberLocation;
461 }
462 
GetAccountId()463 int32_t CallBase::GetAccountId()
464 {
465     return accountId_;
466 }
467 
GetNumberLocation()468 std::string CallBase::GetNumberLocation()
469 {
470     std::lock_guard<std::mutex> lock(mutex_);
471     return numberLocation_;
472 }
473 
SetPolicyFlag(PolicyFlag flag)474 void CallBase::SetPolicyFlag(PolicyFlag flag)
475 {
476     std::lock_guard<std::mutex> lock(mutex_);
477     policyFlag_ |= flag;
478 }
479 
GetPolicyFlag()480 uint64_t CallBase::GetPolicyFlag()
481 {
482     std::lock_guard<std::mutex> lock(mutex_);
483     return policyFlag_;
484 }
485 
GetCallerInfo()486 ContactInfo CallBase::GetCallerInfo()
487 {
488     std::lock_guard<std::mutex> lock(mutex_);
489     return contactInfo_;
490 }
491 
SetCallerInfo(const ContactInfo & info)492 void CallBase::SetCallerInfo(const ContactInfo &info)
493 {
494     std::lock_guard<std::mutex> lock(mutex_);
495     contactInfo_ = info;
496 }
497 
GetNumberMarkInfo()498 NumberMarkInfo CallBase::GetNumberMarkInfo()
499 {
500     std::lock_guard<std::mutex> lock(mutex_);
501     return numberMarkInfo_;
502 }
503 
SetNumberMarkInfo(const NumberMarkInfo & numberMarkInfo)504 void CallBase::SetNumberMarkInfo(const NumberMarkInfo &numberMarkInfo)
505 {
506     std::lock_guard<std::mutex> lock(mutex_);
507     numberMarkInfo_ = numberMarkInfo;
508 }
509 
SetBlockReason(const int32_t & blockReason)510 void CallBase::SetBlockReason(const int32_t &blockReason)
511 {
512     std::lock_guard<std::mutex> lock(mutex_);
513     blockReason_ = blockReason;
514 }
515 
SetDetectDetails(std::string detectDetails)516 void CallBase::SetDetectDetails(std::string detectDetails)
517 {
518     std::lock_guard<std::mutex> lock(mutex_);
519     detectDetails_ = detectDetails;
520 }
521 
GetDetectDetails()522 std::string CallBase::GetDetectDetails()
523 {
524     std::lock_guard<std::mutex> lock(mutex_);
525     return detectDetails_;
526 }
527 
SetCallRunningState(CallRunningState callRunningState)528 void CallBase::SetCallRunningState(CallRunningState callRunningState)
529 {
530     std::lock_guard<std::mutex> lock(mutex_);
531     callRunningState_ = callRunningState;
532 }
533 
SetStartTime(int64_t startTime)534 void CallBase::SetStartTime(int64_t startTime)
535 {
536     std::lock_guard<std::mutex> lock(mutex_);
537     startTime_ = startTime;
538 }
539 
SetCallBeginTime(time_t callBeginTime)540 void CallBase::SetCallBeginTime(time_t callBeginTime)
541 {
542     std::lock_guard<std::mutex> lock(mutex_);
543     callBeginTime_ = callBeginTime;
544 }
545 
SetCallCreateTime(time_t callCreateTime)546 void CallBase::SetCallCreateTime(time_t callCreateTime)
547 {
548     std::lock_guard<std::mutex> lock(mutex_);
549     callCreateTime_ = callCreateTime;
550 }
551 
SetCallEndTime(time_t callEndTime)552 void CallBase::SetCallEndTime(time_t callEndTime)
553 {
554     std::lock_guard<std::mutex> lock(mutex_);
555     callEndTime_ = callEndTime;
556 }
557 
SetRingBeginTime(time_t ringBeginTime)558 void CallBase::SetRingBeginTime(time_t ringBeginTime)
559 {
560     std::lock_guard<std::mutex> lock(mutex_);
561     ringBeginTime_ = ringBeginTime;
562 }
563 
SetRingEndTime(time_t ringEndTime)564 void CallBase::SetRingEndTime(time_t ringEndTime)
565 {
566     std::lock_guard<std::mutex> lock(mutex_);
567     ringEndTime_ = ringEndTime;
568 }
569 
SetAnswerType(CallAnswerType answerType)570 void CallBase::SetAnswerType(CallAnswerType answerType)
571 {
572     std::lock_guard<std::mutex> lock(mutex_);
573     answerType_ = answerType;
574 }
575 
GetAnswerType()576 CallAnswerType CallBase::GetAnswerType()
577 {
578     std::lock_guard<std::mutex> lock(mutex_);
579     return answerType_;
580 }
581 
GetCallEndedType()582 CallEndedType CallBase::GetCallEndedType()
583 {
584     std::lock_guard<std::mutex> lock(mutex_);
585     return callEndedType_;
586 }
587 
SetCallEndedType(CallEndedType callEndedType)588 int32_t CallBase::SetCallEndedType(CallEndedType callEndedType)
589 {
590     std::lock_guard<std::mutex> lock(mutex_);
591     callEndedType_ = callEndedType;
592     return TELEPHONY_SUCCESS;
593 }
594 
SetCallId(int32_t callId)595 void CallBase::SetCallId(int32_t callId)
596 {
597     std::lock_guard<std::mutex> lock(mutex_);
598     callId_ = callId;
599 }
600 
SetCeliaCallType(int32_t celiaCallType)601 void CallBase::SetCeliaCallType(int32_t celiaCallType)
602 {
603     std::lock_guard<std::mutex> lock(mutex_);
604     celiaCallType_ = celiaCallType;
605 }
606 
GetCeliaCallType()607 int32_t CallBase::GetCeliaCallType()
608 {
609     std::lock_guard<std::mutex> lock(mutex_);
610     return celiaCallType_;
611 }
612 
CheckVoicemailNumber(std::string phoneNumber)613 bool CallBase::CheckVoicemailNumber(std::string phoneNumber)
614 {
615     return false;
616 }
617 
IsSpeakerphoneEnabled()618 bool CallBase::IsSpeakerphoneEnabled()
619 {
620     std::shared_ptr<BluetoothCallManager> bluetoothCallManager = std::make_shared<BluetoothCallManager>();
621     // Gets whether the device can be started from the configuration
622     if (bluetoothCallManager->IsBtAvailble()) {
623         return false;
624     }
625     return true;
626 }
627 
IsCurrentRinging()628 bool CallBase::IsCurrentRinging()
629 {
630     std::lock_guard<std::mutex> lock(mutex_);
631     return (callRunningState_ == CallRunningState::CALL_RUNNING_STATE_RINGING) ? true : false;
632 }
633 
GetAccountNumber()634 std::string CallBase::GetAccountNumber()
635 {
636     return accountNumber_;
637 }
638 
SetAccountNumber(const std::string accountNumber)639 void CallBase::SetAccountNumber(const std::string accountNumber)
640 {
641     accountNumber_ = accountNumber;
642 }
643 
IsAnsweredCall()644 bool CallBase::IsAnsweredCall()
645 {
646     std::lock_guard<std::mutex> lock(mutex_);
647     return isAnswered_;
648 }
649 
SetAnsweredCall(bool isAnswered)650 void CallBase::SetAnsweredCall(bool isAnswered)
651 {
652     std::lock_guard<std::mutex> lock(mutex_);
653     isAnswered_ = isAnswered;
654 }
655 
SetSpeakerphoneOn(bool speakerphoneOn)656 int32_t CallBase::SetSpeakerphoneOn(bool speakerphoneOn)
657 {
658     isSpeakerphoneOn_ = speakerphoneOn;
659     return TELEPHONY_SUCCESS;
660 }
661 
IsSpeakerphoneOn()662 bool CallBase::IsSpeakerphoneOn()
663 {
664     return isSpeakerphoneOn_;
665 }
666 
IsAliveState()667 bool CallBase::IsAliveState()
668 {
669     return !(callState_ == TelCallState::CALL_STATUS_IDLE || callState_ == TelCallState::CALL_STATUS_DISCONNECTED ||
670         callState_ == TelCallState::CALL_STATUS_DISCONNECTING);
671 }
672 
SetBundleName(const char * bundleName)673 void CallBase::SetBundleName(const char *bundleName)
674 {
675     bundleName_ = bundleName;
676 }
677 
SetCallType(CallType callType)678 void CallBase::SetCallType(CallType callType)
679 {
680     callType_ = callType;
681 }
682 
SetMicPhoneState(bool isMuted)683 int32_t CallBase::SetMicPhoneState(bool isMuted)
684 {
685     isMuted_ = isMuted;
686     return TELEPHONY_SUCCESS;
687 }
688 
IsMuted()689 bool CallBase::IsMuted()
690 {
691     return isMuted_;
692 }
693 
SetCallDirection(CallDirection direction)694 void CallBase::SetCallDirection(CallDirection direction)
695 {
696     direction_ = direction;
697 }
698 
GetCallDirection()699 CallDirection CallBase::GetCallDirection()
700 {
701     return direction_;
702 }
703 
SetPhoneOrWatchDial(int32_t phoneOrWatch)704 void CallBase::SetPhoneOrWatchDial(int32_t phoneOrWatch)
705 {
706     phoneOrWatch_ = phoneOrWatch;
707 }
708 } // namespace Telephony
709 } // namespace OHOS
710