1 /*
2 * Copyright (C) 2021-2022 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_control_manager.h"
17
18 #include <securec.h>
19 #include <string_ex.h>
20
21 #include "audio_control_manager.h"
22 #include "bluetooth_call_manager.h"
23 #include "call_ability_report_proxy.h"
24 #include "call_manager_errors.h"
25 #include "call_manager_hisysevent.h"
26 #include "call_number_utils.h"
27 #include "call_records_manager.h"
28 #include "call_state_report_proxy.h"
29 #include "cellular_call_connection.h"
30 #include "common_type.h"
31 #include "ims_call.h"
32 #include "iservice_registry.h"
33 #include "reject_call_sms.h"
34 #include "telephony_log_wrapper.h"
35 #include "video_control_manager.h"
36
37 namespace OHOS {
38 namespace Telephony {
39 using namespace OHOS::EventFwk;
CallControlManager()40 CallControlManager::CallControlManager()
41 : callStateListenerPtr_(nullptr), callRequestHandlerServicePtr_(nullptr), incomingCallWakeup_(nullptr),
42 missedCallNotification_(nullptr), callSettingManagerPtr_(nullptr)
43 {
44 dialSrcInfo_.callId = ERR_ID;
45 dialSrcInfo_.number = "";
46 extras_.Clear();
47 dialSrcInfo_.isDialing = false;
48 }
49
~CallControlManager()50 CallControlManager::~CallControlManager()
51 {
52 if (statusChangeListener_ != nullptr) {
53 auto samgrProxy = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
54 if (samgrProxy != nullptr) {
55 samgrProxy->UnSubscribeSystemAbility(COMMON_EVENT_SERVICE_ID, statusChangeListener_);
56 statusChangeListener_ = nullptr;
57 }
58 }
59 }
60
Init()61 bool CallControlManager::Init()
62 {
63 callStateListenerPtr_ = std::make_unique<CallStateListener>();
64 if (callStateListenerPtr_ == nullptr) {
65 TELEPHONY_LOGE("callStateListenerPtr_ is null");
66 return false;
67 }
68 callRequestHandlerServicePtr_ = std::make_unique<CallRequestHandlerService>();
69 if (callRequestHandlerServicePtr_ == nullptr) {
70 TELEPHONY_LOGE("callRequestHandlerServicePtr_ is null");
71 return false;
72 }
73 callRequestHandlerServicePtr_->Start();
74 incomingCallWakeup_ = std::make_shared<IncomingCallWakeup>();
75 if (incomingCallWakeup_ == nullptr) {
76 TELEPHONY_LOGE("incomingCallWakeup_ is null");
77 return false;
78 }
79 missedCallNotification_ = std::make_shared<MissedCallNotification>();
80 if (missedCallNotification_ == nullptr) {
81 TELEPHONY_LOGE("missedCallNotification_ is null");
82 return false;
83 }
84 callSettingManagerPtr_ = std::make_unique<CallSettingManager>();
85 if (callSettingManagerPtr_ == nullptr) {
86 TELEPHONY_LOGE("callSettingManagerPtr_ is nullptr!");
87 return false;
88 }
89 if (BroadcastSubscriber() != TELEPHONY_SUCCESS) {
90 TELEPHONY_LOGE("BroadcastSubscriber failed!");
91 return false;
92 }
93 DelayedSingleton<AudioControlManager>::GetInstance()->Init();
94 CallStateObserve();
95 return true;
96 }
97
DialCall(std::u16string & number,AppExecFwk::PacMap & extras)98 int32_t CallControlManager::DialCall(std::u16string &number, AppExecFwk::PacMap &extras)
99 {
100 sptr<CallBase> callObjectPtr = nullptr;
101 std::string accountNumber(Str16ToStr8(number));
102 int32_t ret = NumberLegalityCheck(accountNumber);
103 if (ret != TELEPHONY_SUCCESS) {
104 TELEPHONY_LOGE("Invalid number!");
105 return ret;
106 }
107 bool isEcc = false;
108 ret = DelayedSingleton<CallNumberUtils>::GetInstance()->CheckNumberIsEmergency(
109 accountNumber, extras.GetIntValue("accountId"), isEcc);
110 if (ret != TELEPHONY_SUCCESS) {
111 TELEPHONY_LOGE("check number is emergency result:%{public}d", ret);
112 return ret;
113 }
114 if (isEcc) {
115 extras.PutIntValue("dialScene", (int32_t)DialScene::CALL_EMERGENCY);
116 } else {
117 extras.PutIntValue("dialScene", (int32_t)DialScene::CALL_NORMAL);
118 }
119 ret = DialPolicy(number, extras, isEcc);
120 if (ret != TELEPHONY_SUCCESS) {
121 TELEPHONY_LOGE("dial policy result:%{public}d", ret);
122 return ret;
123 }
124 // temporarily save dial information
125 {
126 std::lock_guard<std::mutex> lock(mutex_);
127 dialSrcInfo_.callId = ERR_ID;
128 dialSrcInfo_.number = accountNumber;
129 dialSrcInfo_.isDialing = true;
130 dialSrcInfo_.isEcc = isEcc;
131 dialSrcInfo_.callType = (CallType)extras.GetIntValue("callType");
132 dialSrcInfo_.accountId = extras.GetIntValue("accountId");
133 dialSrcInfo_.dialType = (DialType)extras.GetIntValue("dialType");
134 dialSrcInfo_.videoState = (VideoStateType)extras.GetIntValue("videoState");
135 dialSrcInfo_.bundleName = extras.GetStringValue("bundleName");
136 extras_.Clear();
137 extras_ = extras;
138 }
139 if (callRequestHandlerServicePtr_ == nullptr) {
140 TELEPHONY_LOGE("callRequestHandlerServicePtr_ is nullptr!");
141 return TELEPHONY_ERR_LOCAL_PTR_NULL;
142 }
143 ret = callRequestHandlerServicePtr_->DialCall();
144 if (ret != TELEPHONY_SUCCESS) {
145 TELEPHONY_LOGE("DialCall failed!");
146 return ret;
147 }
148 return TELEPHONY_SUCCESS;
149 }
150
AnswerCall(int32_t callId,int32_t videoState)151 int32_t CallControlManager::AnswerCall(int32_t callId, int32_t videoState)
152 {
153 if (callId == INVALID_CALLID) {
154 sptr<CallBase> call = GetOneCallObject(CallRunningState::CALL_RUNNING_STATE_RINGING);
155 if (call == nullptr) {
156 TELEPHONY_LOGE("call is nullptr");
157 CallManagerHisysevent::WriteAnswerCallFaultEvent(
158 INVALID_PARAMETER, callId, videoState, TELEPHONY_ERR_LOCAL_PTR_NULL, "call is nullptr");
159 return TELEPHONY_ERROR;
160 }
161 callId = call->GetCallID();
162 }
163
164 int32_t ret = AnswerCallPolicy(callId, videoState);
165 if (ret != TELEPHONY_SUCCESS) {
166 TELEPHONY_LOGE("AnswerCallPolicy failed!");
167 CallManagerHisysevent::WriteAnswerCallFaultEvent(
168 INVALID_PARAMETER, callId, videoState, ret, "AnswerCallPolicy failed");
169 return ret;
170 }
171 if (callRequestHandlerServicePtr_ == nullptr) {
172 TELEPHONY_LOGE("callRequestHandlerServicePtr_ is nullptr!");
173 return TELEPHONY_ERR_LOCAL_PTR_NULL;
174 }
175 ret = callRequestHandlerServicePtr_->AnswerCall(callId, videoState);
176 if (ret != TELEPHONY_SUCCESS) {
177 TELEPHONY_LOGE("AnswerCall failed!");
178 return ret;
179 }
180 return TELEPHONY_SUCCESS;
181 }
182
RejectCall(int32_t callId,bool rejectWithMessage,std::u16string textMessage)183 int32_t CallControlManager::RejectCall(int32_t callId, bool rejectWithMessage, std::u16string textMessage)
184 {
185 if (callRequestHandlerServicePtr_ == nullptr) {
186 TELEPHONY_LOGE("callRequestHandlerServicePtr_ is nullptr!");
187 return TELEPHONY_ERR_LOCAL_PTR_NULL;
188 }
189
190 if (callId == INVALID_CALLID) {
191 sptr<CallBase> call = GetOneCallObject(CallRunningState::CALL_RUNNING_STATE_RINGING);
192 if (call == nullptr) {
193 TELEPHONY_LOGE("call is nullptr");
194 CallManagerHisysevent::WriteHangUpFaultEvent(
195 INVALID_PARAMETER, callId, TELEPHONY_ERR_LOCAL_PTR_NULL, "Reject call is nullptr");
196 return TELEPHONY_ERROR;
197 }
198 callId = call->GetCallID();
199 }
200
201 int32_t ret = RejectCallPolicy(callId);
202 if (ret != TELEPHONY_SUCCESS) {
203 TELEPHONY_LOGE("RejectCallPolicy failed!");
204 CallManagerHisysevent::WriteHangUpFaultEvent(INVALID_PARAMETER, callId, ret, "Reject RejectCallPolicy failed");
205 return ret;
206 }
207 std::string messageStr(Str16ToStr8(textMessage));
208 ret = callRequestHandlerServicePtr_->RejectCall(callId, rejectWithMessage, messageStr);
209 if (ret != TELEPHONY_SUCCESS) {
210 TELEPHONY_LOGE("RejectCall failed!");
211 return ret;
212 }
213 return TELEPHONY_SUCCESS;
214 }
215
HangUpCall(int32_t callId)216 int32_t CallControlManager::HangUpCall(int32_t callId)
217 {
218 if (callId == INVALID_CALLID) {
219 std::vector<CallRunningState> callRunningStateVec;
220 callRunningStateVec.push_back(CallRunningState::CALL_RUNNING_STATE_ACTIVE);
221 callRunningStateVec.push_back(CallRunningState::CALL_RUNNING_STATE_DIALING);
222 callRunningStateVec.push_back(CallRunningState::CALL_RUNNING_STATE_CONNECTING);
223
224 for (auto &state : callRunningStateVec) {
225 sptr<CallBase> call = GetOneCallObject(state);
226 if (call != nullptr) {
227 callId = call->GetCallID();
228 break;
229 }
230 }
231
232 if (callId == INVALID_CALLID) {
233 TELEPHONY_LOGE("callId is INVALID_CALLID!");
234 CallManagerHisysevent::WriteHangUpFaultEvent(
235 INVALID_PARAMETER, callId, TELEPHONY_ERR_LOCAL_PTR_NULL, "HangUp callId is INVALID_CALLID");
236 return TELEPHONY_ERROR;
237 }
238 }
239
240 if (callRequestHandlerServicePtr_ == nullptr) {
241 TELEPHONY_LOGE("callRequestHandlerServicePtr_ is nullptr!");
242 return TELEPHONY_ERR_LOCAL_PTR_NULL;
243 }
244 int32_t ret = HangUpPolicy(callId);
245 if (ret != TELEPHONY_SUCCESS) {
246 TELEPHONY_LOGE("HangUpPolicy failed!");
247 CallManagerHisysevent::WriteHangUpFaultEvent(INVALID_PARAMETER, callId, ret, "HangUp HangUpPolicy failed");
248 return ret;
249 }
250 ret = callRequestHandlerServicePtr_->HangUpCall(callId);
251 if (ret != TELEPHONY_SUCCESS) {
252 TELEPHONY_LOGE("HangUpCall failed!");
253 return ret;
254 }
255 return TELEPHONY_SUCCESS;
256 }
257
GetCallState()258 int32_t CallControlManager::GetCallState()
259 {
260 CallStateToApp callState = CallStateToApp::CALL_STATE_UNKNOWN;
261 if (!HasCallExist()) {
262 callState = CallStateToApp::CALL_STATE_IDLE;
263 } else {
264 callState = CallStateToApp::CALL_STATE_OFFHOOK;
265 bool enabled = false;
266 if ((HasRingingCall(enabled) == TELEPHONY_SUCCESS) && enabled) {
267 callState = CallStateToApp::CALL_STATE_RINGING;
268 }
269 }
270 return static_cast<int32_t>(callState);
271 }
272
HoldCall(int32_t callId)273 int32_t CallControlManager::HoldCall(int32_t callId)
274 {
275 int32_t ret = HoldCallPolicy(callId);
276 if (ret != TELEPHONY_SUCCESS) {
277 TELEPHONY_LOGE("HoldCall failed!");
278 return ret;
279 }
280 if (callRequestHandlerServicePtr_ == nullptr) {
281 TELEPHONY_LOGE("callRequestHandlerServicePtr_ is nullptr!");
282 return TELEPHONY_ERR_LOCAL_PTR_NULL;
283 }
284 ret = callRequestHandlerServicePtr_->HoldCall(callId);
285 if (ret != TELEPHONY_SUCCESS) {
286 TELEPHONY_LOGE("HoldCall failed!");
287 return ret;
288 }
289 return TELEPHONY_SUCCESS;
290 }
291
UnHoldCall(const int32_t callId)292 int32_t CallControlManager::UnHoldCall(const int32_t callId)
293 {
294 int32_t ret = UnHoldCallPolicy(callId);
295 if (ret != TELEPHONY_SUCCESS) {
296 TELEPHONY_LOGE("UnHoldCall failed!");
297 return ret;
298 }
299 if (callRequestHandlerServicePtr_ == nullptr) {
300 TELEPHONY_LOGE("callRequestHandlerServicePtr_ is nullptr!");
301 return TELEPHONY_ERR_LOCAL_PTR_NULL;
302 }
303 ret = callRequestHandlerServicePtr_->UnHoldCall(callId);
304 if (ret != TELEPHONY_SUCCESS) {
305 TELEPHONY_LOGE("UnHoldCall failed!");
306 return ret;
307 }
308 return TELEPHONY_SUCCESS;
309 }
310
311 // swap two calls state, turn active call into holding, and turn holding call into active
SwitchCall(int32_t callId)312 int32_t CallControlManager::SwitchCall(int32_t callId)
313 {
314 int32_t ret = SwitchCallPolicy(callId);
315 if (ret != TELEPHONY_SUCCESS) {
316 TELEPHONY_LOGE("SwitchCall failed!");
317 return ret;
318 }
319 if (callRequestHandlerServicePtr_ == nullptr) {
320 TELEPHONY_LOGE("callRequestHandlerServicePtr_ is nullptr!");
321 return TELEPHONY_ERR_LOCAL_PTR_NULL;
322 }
323 ret = callRequestHandlerServicePtr_->SwitchCall(callId);
324 if (ret != TELEPHONY_SUCCESS) {
325 TELEPHONY_LOGE("SwitchCall failed!");
326 return ret;
327 }
328 return TELEPHONY_SUCCESS;
329 }
330
HasCall()331 bool CallControlManager::HasCall()
332 {
333 return HasCallExist();
334 }
335
IsNewCallAllowed(bool & enabled)336 int32_t CallControlManager::IsNewCallAllowed(bool &enabled)
337 {
338 return IsNewCallAllowedCreate(enabled);
339 }
340
IsRinging(bool & enabled)341 int32_t CallControlManager::IsRinging(bool &enabled)
342 {
343 return HasRingingCall(enabled);
344 }
345
HasEmergency(bool & enabled)346 int32_t CallControlManager::HasEmergency(bool &enabled)
347 {
348 return HasEmergencyCall(enabled);
349 }
350
NotifyNewCallCreated(sptr<CallBase> & callObjectPtr)351 bool CallControlManager::NotifyNewCallCreated(sptr<CallBase> &callObjectPtr)
352 {
353 if (callObjectPtr == nullptr) {
354 TELEPHONY_LOGE("callObjectPtr is null!");
355 return false;
356 }
357 if (callStateListenerPtr_ != nullptr) {
358 callStateListenerPtr_->NewCallCreated(callObjectPtr);
359 }
360 return true;
361 }
362
NotifyCallDestroyed(const DisconnectedDetails & details)363 bool CallControlManager::NotifyCallDestroyed(const DisconnectedDetails &details)
364 {
365 if (callStateListenerPtr_ != nullptr) {
366 callStateListenerPtr_->CallDestroyed(details);
367 return true;
368 }
369 return false;
370 }
371
NotifyCallStateUpdated(sptr<CallBase> & callObjectPtr,TelCallState priorState,TelCallState nextState)372 bool CallControlManager::NotifyCallStateUpdated(
373 sptr<CallBase> &callObjectPtr, TelCallState priorState, TelCallState nextState)
374 {
375 if (callObjectPtr == nullptr) {
376 TELEPHONY_LOGE("callObjectPtr is null!");
377 return false;
378 }
379 if (callStateListenerPtr_ != nullptr) {
380 callStateListenerPtr_->CallStateUpdated(callObjectPtr, priorState, nextState);
381 TELEPHONY_LOGI("NotifyCallStateUpdated priorState:%{public}d,nextState:%{public}d", priorState, nextState);
382 return true;
383 }
384 return false;
385 }
386
NotifyIncomingCallAnswered(sptr<CallBase> & callObjectPtr)387 bool CallControlManager::NotifyIncomingCallAnswered(sptr<CallBase> &callObjectPtr)
388 {
389 if (callObjectPtr == nullptr) {
390 TELEPHONY_LOGE("callObjectPtr is null!");
391 return false;
392 }
393 if (callStateListenerPtr_ != nullptr) {
394 callStateListenerPtr_->IncomingCallActivated(callObjectPtr);
395 return true;
396 }
397 return false;
398 }
399
NotifyIncomingCallRejected(sptr<CallBase> & callObjectPtr,bool isSendSms,std::string content)400 bool CallControlManager::NotifyIncomingCallRejected(
401 sptr<CallBase> &callObjectPtr, bool isSendSms, std::string content)
402 {
403 if (callObjectPtr == nullptr) {
404 TELEPHONY_LOGE("callObjectPtr is null!");
405 return false;
406 }
407 if (callStateListenerPtr_ != nullptr) {
408 callStateListenerPtr_->IncomingCallHungUp(callObjectPtr, isSendSms, content);
409 return true;
410 }
411 return false;
412 }
413
NotifyCallEventUpdated(CallEventInfo & info)414 bool CallControlManager::NotifyCallEventUpdated(CallEventInfo &info)
415 {
416 if (callStateListenerPtr_ != nullptr) {
417 callStateListenerPtr_->CallEventUpdated(info);
418 return true;
419 }
420 return false;
421 }
422
StartDtmf(int32_t callId,char str)423 int32_t CallControlManager::StartDtmf(int32_t callId, char str)
424 {
425 sptr<CallBase> call = GetOneCallObject(callId);
426 if (call == nullptr) {
427 return TELEPHONY_ERR_ARGUMENT_INVALID;
428 }
429 if (!call->IsAliveState()) {
430 return CALL_ERR_CALL_STATE_MISMATCH_OPERATION;
431 }
432
433 int32_t ret = call->StartDtmf(str);
434 if (ret != TELEPHONY_SUCCESS) {
435 TELEPHONY_LOGE("StartDtmf failed, return:%{public}d", ret);
436 }
437 return ret;
438 }
439
StopDtmf(int32_t callId)440 int32_t CallControlManager::StopDtmf(int32_t callId)
441 {
442 sptr<CallBase> call = GetOneCallObject(callId);
443 if (call == nullptr) {
444 return TELEPHONY_ERR_ARGUMENT_INVALID;
445 }
446 if (!call->IsAliveState()) {
447 return CALL_ERR_CALL_STATE_MISMATCH_OPERATION;
448 }
449
450 int32_t ret = call->StopDtmf();
451 if (ret != TELEPHONY_SUCCESS) {
452 TELEPHONY_LOGE("StopDtmf failed, return:%{public}d", ret);
453 }
454 return ret;
455 }
456
GetCallWaiting(int32_t slotId)457 int32_t CallControlManager::GetCallWaiting(int32_t slotId)
458 {
459 int32_t ret = CallPolicy::GetCallWaitingPolicy(slotId);
460 if (ret != TELEPHONY_SUCCESS) {
461 TELEPHONY_LOGE("GetCallWaiting failed!");
462 return ret;
463 }
464 if (callSettingManagerPtr_ != nullptr) {
465 return callSettingManagerPtr_->GetCallWaiting(slotId);
466 } else {
467 TELEPHONY_LOGE("callSettingManagerPtr_ is nullptr!");
468 return TELEPHONY_ERR_LOCAL_PTR_NULL;
469 }
470 }
471
SetCallWaiting(int32_t slotId,bool activate)472 int32_t CallControlManager::SetCallWaiting(int32_t slotId, bool activate)
473 {
474 int32_t ret = CallPolicy::SetCallWaitingPolicy(slotId);
475 if (ret != TELEPHONY_SUCCESS) {
476 TELEPHONY_LOGE("SetCallWaiting failed!");
477 return ret;
478 }
479 if (callSettingManagerPtr_ != nullptr) {
480 return callSettingManagerPtr_->SetCallWaiting(slotId, activate);
481 } else {
482 TELEPHONY_LOGE("callSettingManagerPtr_ is nullptr!");
483 return TELEPHONY_ERR_LOCAL_PTR_NULL;
484 }
485 }
486
GetCallRestriction(int32_t slotId,CallRestrictionType type)487 int32_t CallControlManager::GetCallRestriction(int32_t slotId, CallRestrictionType type)
488 {
489 int32_t ret = CallPolicy::GetCallRestrictionPolicy(slotId);
490 if (ret != TELEPHONY_SUCCESS) {
491 TELEPHONY_LOGE("GetCallRestriction failed!");
492 return ret;
493 }
494 if (callSettingManagerPtr_ != nullptr) {
495 return callSettingManagerPtr_->GetCallRestriction(slotId, type);
496 } else {
497 TELEPHONY_LOGE("callSettingManagerPtr_ is nullptr!");
498 return TELEPHONY_ERR_LOCAL_PTR_NULL;
499 }
500 }
501
SetCallRestriction(int32_t slotId,CallRestrictionInfo & info)502 int32_t CallControlManager::SetCallRestriction(int32_t slotId, CallRestrictionInfo &info)
503 {
504 int32_t ret = CallPolicy::SetCallRestrictionPolicy(slotId);
505 if (ret != TELEPHONY_SUCCESS) {
506 TELEPHONY_LOGE("SetCallRestriction failed!");
507 return ret;
508 }
509 if (callSettingManagerPtr_ != nullptr) {
510 return callSettingManagerPtr_->SetCallRestriction(slotId, info);
511 } else {
512 TELEPHONY_LOGE("callSettingManagerPtr_ is nullptr!");
513 return TELEPHONY_ERR_LOCAL_PTR_NULL;
514 }
515 }
516
GetCallTransferInfo(int32_t slotId,CallTransferType type)517 int32_t CallControlManager::GetCallTransferInfo(int32_t slotId, CallTransferType type)
518 {
519 int32_t ret = CallPolicy::GetCallTransferInfoPolicy(slotId);
520 if (ret != TELEPHONY_SUCCESS) {
521 TELEPHONY_LOGE("GetCallTransferInfo failed!");
522 return ret;
523 }
524 if (callSettingManagerPtr_ != nullptr) {
525 return callSettingManagerPtr_->GetCallTransferInfo(slotId, type);
526 } else {
527 TELEPHONY_LOGE("callSettingManagerPtr_ is nullptr!");
528 return TELEPHONY_ERR_LOCAL_PTR_NULL;
529 }
530 }
531
SetCallTransferInfo(int32_t slotId,CallTransferInfo & info)532 int32_t CallControlManager::SetCallTransferInfo(int32_t slotId, CallTransferInfo &info)
533 {
534 int32_t ret = CallPolicy::SetCallTransferInfoPolicy(slotId);
535 if (ret != TELEPHONY_SUCCESS) {
536 TELEPHONY_LOGE("SetCallTransferInfo failed!");
537 return ret;
538 }
539 if (callSettingManagerPtr_ != nullptr) {
540 return callSettingManagerPtr_->SetCallTransferInfo(slotId, info);
541 } else {
542 TELEPHONY_LOGE("callSettingManagerPtr_ is nullptr!");
543 return TELEPHONY_ERR_LOCAL_PTR_NULL;
544 }
545 }
546
SetCallPreferenceMode(int32_t slotId,int32_t mode)547 int32_t CallControlManager::SetCallPreferenceMode(int32_t slotId, int32_t mode)
548 {
549 int32_t ret = CallPolicy::SetCallPreferenceModePolicy(slotId);
550 if (ret != TELEPHONY_SUCCESS) {
551 TELEPHONY_LOGE("SetCallPreferenceMode failed!");
552 return ret;
553 }
554 if (callSettingManagerPtr_ != nullptr) {
555 return callSettingManagerPtr_->SetCallPreferenceMode(slotId, mode);
556 } else {
557 TELEPHONY_LOGE("callSettingManagerPtr_ is nullptr!");
558 return TELEPHONY_ERR_LOCAL_PTR_NULL;
559 }
560 }
561
562 /**
563 * start a telephone conference by merging three-way calls,steps as follows:
564 * 1.A call B: A<---->B,set holding
565 * 2.A call C: A<---->C, active
566 * 3.A initial merge request by CombineConference
567 * @param mainCallId:active call id
568 */
CombineConference(int32_t mainCallId)569 int32_t CallControlManager::CombineConference(int32_t mainCallId)
570 {
571 sptr<CallBase> mainCall = GetOneCallObject(mainCallId);
572 if (mainCall == nullptr) {
573 TELEPHONY_LOGE("GetOneCallObject failed, mainCallId:%{public}d", mainCallId);
574 return TELEPHONY_ERR_ARGUMENT_INVALID;
575 }
576 if (mainCall->GetTelCallState() != TelCallState::CALL_STATUS_ACTIVE) {
577 TELEPHONY_LOGE("mainCall state should be active ");
578 return CALL_ERR_CALL_STATE_MISMATCH_OPERATION;
579 }
580 if (!CallObjectManager::IsCallExist(mainCall->GetCallType(), TelCallState::CALL_STATUS_HOLDING)) {
581 TELEPHONY_LOGE("callType:%{public}d,callState:CALL_STATUS_HOLDING is not exist!", mainCall->GetCallType());
582 return CALL_ERR_CALL_STATE_MISMATCH_OPERATION;
583 }
584 int32_t ret = mainCall->CanCombineConference();
585 if (ret != TELEPHONY_SUCCESS) {
586 TELEPHONY_LOGE("CanCombineConference failed");
587 return ret;
588 }
589 if (callRequestHandlerServicePtr_ == nullptr) {
590 TELEPHONY_LOGE("callRequestHandlerServicePtr_ is nullptr!");
591 return TELEPHONY_ERR_LOCAL_PTR_NULL;
592 }
593 ret = callRequestHandlerServicePtr_->CombineConference(mainCallId);
594 if (ret != TELEPHONY_SUCCESS) {
595 TELEPHONY_LOGE("CombineConference failed!");
596 }
597 return ret;
598 }
599
SeparateConference(int32_t callId)600 int32_t CallControlManager::SeparateConference(int32_t callId)
601 {
602 sptr<CallBase> call = GetOneCallObject(callId);
603 if (call == nullptr) {
604 TELEPHONY_LOGE("GetOneCallObject failed, callId:%{public}d", callId);
605 return TELEPHONY_ERR_ARGUMENT_INVALID;
606 }
607 int32_t ret = call->CanSeparateConference();
608 if (ret != TELEPHONY_SUCCESS) {
609 TELEPHONY_LOGE("CanSeparateConference failed");
610 return ret;
611 }
612 if (callRequestHandlerServicePtr_ == nullptr) {
613 TELEPHONY_LOGE("callRequestHandlerServicePtr_ is nullptr!");
614 return TELEPHONY_ERR_LOCAL_PTR_NULL;
615 }
616 ret = callRequestHandlerServicePtr_->SeparateConference(callId);
617 if (ret != TELEPHONY_SUCCESS) {
618 TELEPHONY_LOGE("CombineConference failed!");
619 return ret;
620 }
621 return TELEPHONY_SUCCESS;
622 }
623
GetMainCallId(int32_t callId,int32_t & mainCallId)624 int32_t CallControlManager::GetMainCallId(int32_t callId, int32_t &mainCallId)
625 {
626 sptr<CallBase> call = GetOneCallObject(callId);
627 if (call == nullptr) {
628 TELEPHONY_LOGE("GetMainCallId failed! callId:%{public}d", callId);
629 return TELEPHONY_ERR_ARGUMENT_INVALID;
630 }
631 return call->GetMainCallId(mainCallId);
632 }
633
GetSubCallIdList(int32_t callId,std::vector<std::u16string> & callIdList)634 int32_t CallControlManager::GetSubCallIdList(int32_t callId, std::vector<std::u16string> &callIdList)
635 {
636 sptr<CallBase> call = GetOneCallObject(callId);
637 if (call == nullptr) {
638 TELEPHONY_LOGE("GetSubCallIdList failed! callId:%{public}d", callId);
639 return TELEPHONY_ERR_ARGUMENT_INVALID;
640 }
641 return call->GetSubCallIdList(callIdList);
642 }
643
GetCallIdListForConference(int32_t callId,std::vector<std::u16string> & callIdList)644 int32_t CallControlManager::GetCallIdListForConference(int32_t callId, std::vector<std::u16string> &callIdList)
645 {
646 sptr<CallBase> call = GetOneCallObject(callId);
647 if (call == nullptr) {
648 TELEPHONY_LOGE("GetCallIdListForConference failed! callId:%{public}d", callId);
649 return TELEPHONY_ERR_ARGUMENT_INVALID;
650 }
651 return call->GetCallIdListForConference(callIdList);
652 }
653
GetImsConfig(int32_t slotId,ImsConfigItem item)654 int32_t CallControlManager::GetImsConfig(int32_t slotId, ImsConfigItem item)
655 {
656 int32_t ret = CallPolicy::GetImsConfigPolicy(slotId);
657 if (ret != TELEPHONY_SUCCESS) {
658 TELEPHONY_LOGE("GetImsConfig failed!");
659 return ret;
660 }
661 if (callSettingManagerPtr_ != nullptr) {
662 return callSettingManagerPtr_->GetImsConfig(slotId, item);
663 } else {
664 TELEPHONY_LOGE("callSettingManagerPtr_ is nullptr!");
665 return TELEPHONY_ERR_LOCAL_PTR_NULL;
666 }
667 }
668
SetImsConfig(int32_t slotId,ImsConfigItem item,std::u16string & value)669 int32_t CallControlManager::SetImsConfig(int32_t slotId, ImsConfigItem item, std::u16string &value)
670 {
671 int32_t ret = CallPolicy::SetImsConfigPolicy(slotId);
672 if (ret != TELEPHONY_SUCCESS) {
673 TELEPHONY_LOGE("SetImsConfig failed!");
674 return ret;
675 }
676 if (callSettingManagerPtr_ != nullptr) {
677 return callSettingManagerPtr_->SetImsConfig(slotId, item, value);
678 } else {
679 TELEPHONY_LOGE("callSettingManagerPtr_ is nullptr!");
680 return TELEPHONY_ERR_LOCAL_PTR_NULL;
681 }
682 }
683
GetImsFeatureValue(int32_t slotId,FeatureType type)684 int32_t CallControlManager::GetImsFeatureValue(int32_t slotId, FeatureType type)
685 {
686 int32_t ret = CallPolicy::GetImsFeatureValuePolicy(slotId);
687 if (ret != TELEPHONY_SUCCESS) {
688 TELEPHONY_LOGE("GetImsFeatureValue failed!");
689 return ret;
690 }
691 if (callSettingManagerPtr_ != nullptr) {
692 return callSettingManagerPtr_->GetImsFeatureValue(slotId, type);
693 } else {
694 TELEPHONY_LOGE("callSettingManagerPtr_ is nullptr!");
695 return TELEPHONY_ERR_LOCAL_PTR_NULL;
696 }
697 }
698
SetImsFeatureValue(int32_t slotId,FeatureType type,int32_t value)699 int32_t CallControlManager::SetImsFeatureValue(int32_t slotId, FeatureType type, int32_t value)
700 {
701 int32_t ret = CallPolicy::SetImsFeatureValuePolicy(slotId);
702 if (ret != TELEPHONY_SUCCESS) {
703 TELEPHONY_LOGE("SetImsFeatureValue failed!");
704 return ret;
705 }
706 if (callSettingManagerPtr_ != nullptr) {
707 return callSettingManagerPtr_->SetImsFeatureValue(slotId, type, value);
708 } else {
709 TELEPHONY_LOGE("callSettingManagerPtr_ is nullptr!");
710 return TELEPHONY_ERR_LOCAL_PTR_NULL;
711 }
712 }
713
EnableImsSwitch(int32_t slotId)714 int32_t CallControlManager::EnableImsSwitch(int32_t slotId)
715 {
716 int32_t ret = CallPolicy::EnableVoLtePolicy(slotId);
717 if (ret != TELEPHONY_SUCCESS) {
718 TELEPHONY_LOGE("EnableImsSwitch failed!");
719 return ret;
720 }
721 if (callSettingManagerPtr_ != nullptr) {
722 return callSettingManagerPtr_->EnableImsSwitch(slotId);
723 } else {
724 TELEPHONY_LOGE("callSettingManagerPtr_ is nullptr!");
725 return TELEPHONY_ERR_LOCAL_PTR_NULL;
726 }
727 }
728
DisableImsSwitch(int32_t slotId)729 int32_t CallControlManager::DisableImsSwitch(int32_t slotId)
730 {
731 int32_t ret = CallPolicy::DisableVoLtePolicy(slotId);
732 if (ret != TELEPHONY_SUCCESS) {
733 TELEPHONY_LOGE("DisableImsSwitch failed!");
734 return ret;
735 }
736 if (callSettingManagerPtr_ != nullptr) {
737 return callSettingManagerPtr_->DisableImsSwitch(slotId);
738 } else {
739 TELEPHONY_LOGE("callSettingManagerPtr_ is nullptr!");
740 return TELEPHONY_ERR_LOCAL_PTR_NULL;
741 }
742 }
743
IsImsSwitchEnabled(int32_t slotId,bool & enabled)744 int32_t CallControlManager::IsImsSwitchEnabled(int32_t slotId, bool &enabled)
745 {
746 int32_t ret = CallPolicy::IsVoLteEnabledPolicy(slotId);
747 if (ret != TELEPHONY_SUCCESS) {
748 TELEPHONY_LOGE("IsImsSwitchEnabled failed!");
749 return ret;
750 }
751 if (callSettingManagerPtr_ != nullptr) {
752 return callSettingManagerPtr_->IsImsSwitchEnabled(slotId, enabled);
753 } else {
754 TELEPHONY_LOGE("callSettingManagerPtr_ is nullptr!");
755 return TELEPHONY_ERR_LOCAL_PTR_NULL;
756 }
757 }
758
UpdateImsCallMode(int32_t callId,ImsCallMode mode)759 int32_t CallControlManager::UpdateImsCallMode(int32_t callId, ImsCallMode mode)
760 {
761 int32_t ret = TELEPHONY_ERR_FAIL;
762 ret = UpdateCallMediaModePolicy(callId, mode);
763 if (ret != TELEPHONY_SUCCESS) {
764 TELEPHONY_LOGE("check prerequisites failed !");
765 return ret;
766 }
767 if (callRequestHandlerServicePtr_ == nullptr) {
768 TELEPHONY_LOGE("callRequestHandlerServicePtr_ is nullptr!");
769 return TELEPHONY_ERR_LOCAL_PTR_NULL;
770 }
771 ret = callRequestHandlerServicePtr_->UpdateImsCallMode(callId, mode);
772 if (ret != TELEPHONY_SUCCESS) {
773 TELEPHONY_LOGE("UpdateImsCallMode failed!");
774 return ret;
775 }
776 return TELEPHONY_SUCCESS;
777 }
778
StartRtt(int32_t callId,std::u16string & msg)779 int32_t CallControlManager::StartRtt(int32_t callId, std::u16string &msg)
780 {
781 int32_t ret = CallPolicy::StartRttPolicy(callId);
782 if (ret != TELEPHONY_SUCCESS) {
783 TELEPHONY_LOGE("NO IMS call,can not StartRtt!");
784 return ret;
785 }
786 if (callRequestHandlerServicePtr_ == nullptr) {
787 TELEPHONY_LOGE("callRequestHandlerServicePtr_ is nullptr!");
788 return TELEPHONY_ERR_LOCAL_PTR_NULL;
789 }
790 ret = callRequestHandlerServicePtr_->StartRtt(callId, msg);
791 if (ret != TELEPHONY_SUCCESS) {
792 TELEPHONY_LOGE("StartRtt failed!");
793 return ret;
794 }
795 return TELEPHONY_SUCCESS;
796 }
797
StopRtt(int32_t callId)798 int32_t CallControlManager::StopRtt(int32_t callId)
799 {
800 int32_t ret = CallPolicy::StopRttPolicy(callId);
801 if (ret != TELEPHONY_SUCCESS) {
802 TELEPHONY_LOGE("NO IMS call,no need StopRtt!");
803 return ret;
804 }
805 if (callRequestHandlerServicePtr_ == nullptr) {
806 TELEPHONY_LOGE("callRequestHandlerServicePtr_ is nullptr!");
807 return TELEPHONY_ERR_LOCAL_PTR_NULL;
808 }
809 ret = callRequestHandlerServicePtr_->StopRtt(callId);
810 if (ret != TELEPHONY_SUCCESS) {
811 TELEPHONY_LOGE("StopRtt failed!");
812 return ret;
813 }
814 return TELEPHONY_SUCCESS;
815 }
816
JoinConference(int32_t callId,std::vector<std::u16string> & numberList)817 int32_t CallControlManager::JoinConference(int32_t callId, std::vector<std::u16string> &numberList)
818 {
819 if (callRequestHandlerServicePtr_ == nullptr) {
820 TELEPHONY_LOGE("callRequestHandlerServicePtr_ is nullptr!");
821 return TELEPHONY_ERR_LOCAL_PTR_NULL;
822 }
823 std::vector<std::string> phoneNumberList(numberList.size());
824 for (size_t index = 0; index < numberList.size(); ++index) {
825 phoneNumberList[index] = Str16ToStr8(numberList[index]);
826 }
827 int32_t ret = CallPolicy::InviteToConferencePolicy(callId, phoneNumberList);
828 if (ret != TELEPHONY_SUCCESS) {
829 TELEPHONY_LOGE("check InviteToConference Policy failed!");
830 return ret;
831 }
832 ret = callRequestHandlerServicePtr_->JoinConference(callId, phoneNumberList);
833 if (ret != TELEPHONY_SUCCESS) {
834 TELEPHONY_LOGE("JoinConference failed!");
835 return ret;
836 }
837 return TELEPHONY_SUCCESS;
838 }
839
SetMuted(bool isMute)840 int32_t CallControlManager::SetMuted(bool isMute)
841 {
842 sptr<CallBase> call = CallObjectManager::GetOneCallObject(CallRunningState::CALL_RUNNING_STATE_ACTIVE);
843 if (call == nullptr) {
844 return CALL_ERR_AUDIO_SETTING_MUTE_FAILED;
845 }
846
847 if (call->GetCallType() == CallType::TYPE_IMS
848 || call->GetCallType() == CallType::TYPE_CS) {
849 TELEPHONY_LOGI("SetMute by ims or cs");
850 call->SetMute(isMute, call->GetSlotId());
851 }
852
853 return DelayedSingleton<AudioControlManager>::GetInstance()->SetMute(isMute);
854 }
855
MuteRinger()856 int32_t CallControlManager::MuteRinger()
857 {
858 return DelayedSingleton<AudioControlManager>::GetInstance()->MuteRinger();
859 }
860
SetAudioDevice(AudioDevice deviceType,const std::string & bluetoothAddress)861 int32_t CallControlManager::SetAudioDevice(AudioDevice deviceType, const std::string &bluetoothAddress)
862 {
863 if (deviceType == AudioDevice::DEVICE_BLUETOOTH_SCO &&
864 DelayedSingleton<AudioDeviceManager>::GetInstance()->ConnectBtScoWithAddress(bluetoothAddress)) {
865 return TELEPHONY_SUCCESS;
866 }
867 return DelayedSingleton<AudioControlManager>::GetInstance()->SetAudioDevice(deviceType);
868 }
869
ControlCamera(std::u16string cameraId,int32_t callingUid,int32_t callingPid)870 int32_t CallControlManager::ControlCamera(std::u16string cameraId, int32_t callingUid, int32_t callingPid)
871 {
872 return DelayedSingleton<VideoControlManager>::GetInstance()->ControlCamera(cameraId, callingUid, callingPid);
873 }
874
SetPreviewWindow(VideoWindow & window)875 int32_t CallControlManager::SetPreviewWindow(VideoWindow &window)
876 {
877 return DelayedSingleton<VideoControlManager>::GetInstance()->SetPreviewWindow(window);
878 }
879
SetDisplayWindow(VideoWindow & window)880 int32_t CallControlManager::SetDisplayWindow(VideoWindow &window)
881 {
882 return DelayedSingleton<VideoControlManager>::GetInstance()->SetDisplayWindow(window);
883 }
884
SetCameraZoom(float zoomRatio)885 int32_t CallControlManager::SetCameraZoom(float zoomRatio)
886 {
887 return DelayedSingleton<VideoControlManager>::GetInstance()->SetCameraZoom(zoomRatio);
888 }
889
SetPausePicture(std::u16string path)890 int32_t CallControlManager::SetPausePicture(std::u16string path)
891 {
892 return DelayedSingleton<VideoControlManager>::GetInstance()->SetPausePicture(path);
893 }
894
SetDeviceDirection(int32_t rotation)895 int32_t CallControlManager::SetDeviceDirection(int32_t rotation)
896 {
897 return DelayedSingleton<VideoControlManager>::GetInstance()->SetDeviceDirection(rotation);
898 }
899
IsEmergencyPhoneNumber(std::u16string & number,int32_t slotId,bool & enabled)900 int32_t CallControlManager::IsEmergencyPhoneNumber(std::u16string &number, int32_t slotId, bool &enabled)
901 {
902 if (IsValidSlotId(slotId)) {
903 return CALL_ERR_INVALID_SLOT_ID;
904 }
905 return DelayedSingleton<CallNumberUtils>::GetInstance()->CheckNumberIsEmergency(
906 Str16ToStr8(number), slotId, enabled);
907 }
908
FormatPhoneNumber(std::u16string & number,std::u16string & countryCode,std::u16string & formatNumber)909 int32_t CallControlManager::FormatPhoneNumber(
910 std::u16string &number, std::u16string &countryCode, std::u16string &formatNumber)
911 {
912 std::string tmpStr("");
913 int32_t ret = DelayedSingleton<CallNumberUtils>::GetInstance()->FormatPhoneNumber(
914 Str16ToStr8(number), Str16ToStr8(countryCode), tmpStr);
915 formatNumber = Str8ToStr16(tmpStr);
916 return ret;
917 }
918
FormatPhoneNumberToE164(std::u16string & number,std::u16string & countryCode,std::u16string & formatNumber)919 int32_t CallControlManager::FormatPhoneNumberToE164(
920 std::u16string &number, std::u16string &countryCode, std::u16string &formatNumber)
921 {
922 std::string tmpStr("");
923 int32_t ret = DelayedSingleton<CallNumberUtils>::GetInstance()->FormatPhoneNumberToE164(
924 Str16ToStr8(number), Str16ToStr8(countryCode), tmpStr);
925 formatNumber = Str8ToStr16(tmpStr);
926 return ret;
927 }
928
GetDialParaInfo(DialParaInfo & info)929 void CallControlManager::GetDialParaInfo(DialParaInfo &info)
930 {
931 std::lock_guard<std::mutex> lock(mutex_);
932 info = dialSrcInfo_;
933 }
934
GetDialParaInfo(DialParaInfo & info,AppExecFwk::PacMap & extras)935 void CallControlManager::GetDialParaInfo(DialParaInfo &info, AppExecFwk::PacMap &extras)
936 {
937 std::lock_guard<std::mutex> lock(mutex_);
938 info = dialSrcInfo_;
939 extras = extras_;
940 }
941
CallStateObserve()942 void CallControlManager::CallStateObserve()
943 {
944 if (callStateListenerPtr_ == nullptr) {
945 TELEPHONY_LOGE("callStateListenerPtr_ is null");
946 return;
947 }
948 std::shared_ptr<RejectCallSms> hangUpSmsPtr = std::make_shared<RejectCallSms>();
949 if (hangUpSmsPtr == nullptr) {
950 TELEPHONY_LOGE("hangUpSmsPtr is null");
951 return;
952 }
953 std::shared_ptr<CallStateReportProxy> callStateReportPtr = std::make_shared<CallStateReportProxy>();
954 if (callStateReportPtr == nullptr) {
955 TELEPHONY_LOGE("CallStateReportProxy is nullptr!");
956 return;
957 }
958 callStateListenerPtr_->AddOneObserver(DelayedSingleton<CallAbilityReportProxy>::GetInstance());
959 callStateListenerPtr_->AddOneObserver(callStateReportPtr);
960 callStateListenerPtr_->AddOneObserver(DelayedSingleton<AudioControlManager>::GetInstance());
961 callStateListenerPtr_->AddOneObserver(hangUpSmsPtr);
962 callStateListenerPtr_->AddOneObserver(missedCallNotification_);
963 callStateListenerPtr_->AddOneObserver(incomingCallWakeup_);
964 callStateListenerPtr_->AddOneObserver(DelayedSingleton<CallRecordsManager>::GetInstance());
965 }
966
NumberLegalityCheck(std::string & number)967 int32_t CallControlManager::NumberLegalityCheck(std::string &number)
968 {
969 if (number.empty()) {
970 TELEPHONY_LOGE("phone number is NULL!");
971 return CALL_ERR_PHONE_NUMBER_EMPTY;
972 }
973 if (number.length() > kMaxNumberLen) {
974 TELEPHONY_LOGE(
975 "the number length exceeds limit,len:%{public}zu,maxLen:%{public}d", number.length(), kMaxNumberLen);
976 return CALL_ERR_NUMBER_OUT_OF_RANGE;
977 }
978 return TELEPHONY_SUCCESS;
979 }
980
SystemAbilityListener(std::shared_ptr<CallBroadcastSubscriber> subscriberPtr)981 CallControlManager::SystemAbilityListener::SystemAbilityListener(std::shared_ptr<CallBroadcastSubscriber> subscriberPtr)
982 : subscriberPtr_(subscriberPtr)
983 {}
984
OnAddSystemAbility(int32_t systemAbilityId,const std::string & deviceId)985 void CallControlManager::SystemAbilityListener::OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId)
986 {
987 if (systemAbilityId != COMMON_EVENT_SERVICE_ID) {
988 TELEPHONY_LOGE("systemAbilityId is not COMMON_EVENT_SERVICE_ID");
989 return;
990 }
991
992 if (subscriberPtr_ == nullptr) {
993 TELEPHONY_LOGE("CallControlManager::OnAddSystemAbility subscriberPtr is nullptr");
994 return;
995 }
996
997 bool subscribeResult = EventFwk::CommonEventManager::SubscribeCommonEvent(subscriberPtr_);
998 TELEPHONY_LOGI("CallControlManager::OnAddSystemAbility subscribeResult = %{public}d", subscribeResult);
999 }
1000
OnRemoveSystemAbility(int32_t systemAbilityId,const std::string & deviceId)1001 void CallControlManager::SystemAbilityListener::OnRemoveSystemAbility(
1002 int32_t systemAbilityId, const std::string &deviceId)
1003 {
1004 if (systemAbilityId != COMMON_EVENT_SERVICE_ID) {
1005 TELEPHONY_LOGE("systemAbilityId is not COMMON_EVENT_SERVICE_ID");
1006 return;
1007 }
1008
1009 if (subscriberPtr_ == nullptr) {
1010 TELEPHONY_LOGE("CallControlManager::OnRemoveSystemAbility subscriberPtr is nullptr");
1011 return;
1012 }
1013
1014 bool subscribeResult = EventFwk::CommonEventManager::UnSubscribeCommonEvent(subscriberPtr_);
1015 TELEPHONY_LOGI("CallControlManager::OnRemoveSystemAbility subscribeResult = %{public}d", subscribeResult);
1016 }
1017
BroadcastSubscriber()1018 int32_t CallControlManager::BroadcastSubscriber()
1019 {
1020 EventFwk::MatchingSkills matchingSkills;
1021 matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_SIM_STATE_CHANGED);
1022 EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills);
1023 std::shared_ptr<CallBroadcastSubscriber> subscriberPtr = std::make_shared<CallBroadcastSubscriber>(subscriberInfo);
1024 if (subscriberPtr == nullptr) {
1025 TELEPHONY_LOGE("CallControlManager::BroadcastSubscriber subscriberPtr is nullptr");
1026 return TELEPHONY_ERROR;
1027 }
1028 // if SubscribeCommonEvent fail, register statusChangeListener to SubscribeCommonEvent again
1029 auto samgrProxy = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
1030 if (samgrProxy == nullptr) {
1031 TELEPHONY_LOGE("samgrProxy is nullptr");
1032 return TELEPHONY_ERROR;
1033 }
1034
1035 statusChangeListener_ = new (std::nothrow) SystemAbilityListener(subscriberPtr);
1036 if (statusChangeListener_ == nullptr) {
1037 TELEPHONY_LOGE("statusChangeListener_ is nullptr");
1038 return TELEPHONY_ERROR;
1039 }
1040
1041 int32_t ret = samgrProxy->SubscribeSystemAbility(COMMON_EVENT_SERVICE_ID, statusChangeListener_);
1042 TELEPHONY_LOGI("CallControlManager::BroadcastSubscriber ret: %{public}d", ret);
1043 return TELEPHONY_SUCCESS;
1044 }
1045
1046 #ifdef ABILITY_MEDIA_SUPPORT
onButtonDealing(HeadsetButtonService::ButtonEvent type)1047 bool CallControlManager::onButtonDealing(HeadsetButtonService::ButtonEvent type)
1048 {
1049 bool isRingState = false;
1050 sptr<CallBase> call = nullptr;
1051
1052 if (GetOneCallObject(CallRunningState::CALL_RUNNING_STATE_RINGING) != nullptr) {
1053 call = GetOneCallObject(CallRunningState::CALL_RUNNING_STATE_RINGING);
1054 isRingState = true;
1055 } else if (GetOneCallObject(CallRunningState::CALL_RUNNING_STATE_DIALING) != nullptr) {
1056 call = GetOneCallObject(CallRunningState::CALL_RUNNING_STATE_DIALING);
1057 } else if (GetOneCallObject(CallRunningState::CALL_RUNNING_STATE_ACTIVE) != nullptr) {
1058 call = GetOneCallObject(CallRunningState::CALL_RUNNING_STATE_ACTIVE);
1059 } else if (GetOneCallObject(CallRunningState::CALL_RUNNING_STATE_HOLD) != nullptr) {
1060 call = GetOneCallObject(CallRunningState::CALL_RUNNING_STATE_HOLD);
1061 } else {
1062 return false;
1063 }
1064
1065 switch (type) {
1066 case HeadsetButtonService::SHORT_PRESS_EVENT:
1067 if (isRingState) {
1068 call->HangUpCall();
1069 } else {
1070 call->AnswerCall(0);
1071 }
1072 break;
1073 case HeadsetButtonService::LONG_PRESS_EVENT:
1074 if (isRingState) {
1075 std::string str = "";
1076 call->RejectCall(false, str);
1077 } else {
1078 DelayedSingleton<AudioControlManager>::GetInstance()->SetMute(true);
1079 }
1080 break;
1081 default:
1082 return false;
1083 }
1084 return true;
1085 }
1086 #endif
1087 } // namespace Telephony
1088 } // namespace OHOS
1089