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