1e1c44949Sopenharmony_ci/*
2e1c44949Sopenharmony_ci * Copyright (C) 2021-2024 Huawei Device Co., Ltd.
3e1c44949Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4e1c44949Sopenharmony_ci * you may not use this file except in compliance with the License.
5e1c44949Sopenharmony_ci * You may obtain a copy of the License at
6e1c44949Sopenharmony_ci *
7e1c44949Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8e1c44949Sopenharmony_ci *
9e1c44949Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10e1c44949Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11e1c44949Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12e1c44949Sopenharmony_ci * See the License for the specific language governing permissions and
13e1c44949Sopenharmony_ci * limitations under the License.
14e1c44949Sopenharmony_ci */
15e1c44949Sopenharmony_ci
16e1c44949Sopenharmony_ci#include "call_control_manager.h"
17e1c44949Sopenharmony_ci#include "cpp/task_ext.h"
18e1c44949Sopenharmony_ci#include <securec.h>
19e1c44949Sopenharmony_ci#include "csignal"
20e1c44949Sopenharmony_ci#include <string_ex.h>
21e1c44949Sopenharmony_ci
22e1c44949Sopenharmony_ci#include "audio_control_manager.h"
23e1c44949Sopenharmony_ci#include "bluetooth_call_manager.h"
24e1c44949Sopenharmony_ci#include "call_ability_report_proxy.h"
25e1c44949Sopenharmony_ci#include "call_connect_ability.h"
26e1c44949Sopenharmony_ci#include "call_dialog.h"
27e1c44949Sopenharmony_ci#include "call_manager_errors.h"
28e1c44949Sopenharmony_ci#include "call_manager_hisysevent.h"
29e1c44949Sopenharmony_ci#include "call_number_utils.h"
30e1c44949Sopenharmony_ci#include "call_records_manager.h"
31e1c44949Sopenharmony_ci#include "call_request_event_handler_helper.h"
32e1c44949Sopenharmony_ci#include "call_state_report_proxy.h"
33e1c44949Sopenharmony_ci#include "cellular_call_connection.h"
34e1c44949Sopenharmony_ci#include "common_type.h"
35e1c44949Sopenharmony_ci#include "ims_call.h"
36e1c44949Sopenharmony_ci#include "iservice_registry.h"
37e1c44949Sopenharmony_ci#include "reject_call_sms.h"
38e1c44949Sopenharmony_ci#include "report_call_info_handler.h"
39e1c44949Sopenharmony_ci#include "satellite_call_control.h"
40e1c44949Sopenharmony_ci#include "telephony_log_wrapper.h"
41e1c44949Sopenharmony_ci#include "video_control_manager.h"
42e1c44949Sopenharmony_ci#include "audio_device_manager.h"
43e1c44949Sopenharmony_ci#include "distributed_call_manager.h"
44e1c44949Sopenharmony_ci#include "call_superprivacy_control_manager.h"
45e1c44949Sopenharmony_ci#include "distributed_communication_manager.h"
46e1c44949Sopenharmony_ci#include "call_voice_assistant_manager.h"
47e1c44949Sopenharmony_ci
48e1c44949Sopenharmony_cinamespace OHOS {
49e1c44949Sopenharmony_cinamespace Telephony {
50e1c44949Sopenharmony_cibool CallControlManager::alarmSeted = false;
51e1c44949Sopenharmony_ciconstexpr int32_t CRS_TYPE = 2;
52e1c44949Sopenharmony_ciconst uint64_t DISCONNECT_DELAY_TIME = 1000000;
53e1c44949Sopenharmony_cistatic const int32_t SATCOMM_UID = 1096;
54e1c44949Sopenharmony_ciusing namespace OHOS::EventFwk;
55e1c44949Sopenharmony_ciCallControlManager::CallControlManager()
56e1c44949Sopenharmony_ci    : callStateListenerPtr_(nullptr), CallRequestHandlerPtr_(nullptr), incomingCallWakeup_(nullptr),
57e1c44949Sopenharmony_ci      missedCallNotification_(nullptr), callSettingManagerPtr_(nullptr)
58e1c44949Sopenharmony_ci{
59e1c44949Sopenharmony_ci    dialSrcInfo_.callId = ERR_ID;
60e1c44949Sopenharmony_ci    dialSrcInfo_.number = "";
61e1c44949Sopenharmony_ci    extras_.Clear();
62e1c44949Sopenharmony_ci    dialSrcInfo_.isDialing = false;
63e1c44949Sopenharmony_ci}
64e1c44949Sopenharmony_ci
65e1c44949Sopenharmony_ciCallControlManager::~CallControlManager()
66e1c44949Sopenharmony_ci{
67e1c44949Sopenharmony_ci    if (statusChangeListener_ != nullptr) {
68e1c44949Sopenharmony_ci        auto samgrProxy = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
69e1c44949Sopenharmony_ci        if (samgrProxy != nullptr) {
70e1c44949Sopenharmony_ci            samgrProxy->UnSubscribeSystemAbility(COMMON_EVENT_SERVICE_ID, statusChangeListener_);
71e1c44949Sopenharmony_ci            samgrProxy->UnSubscribeSystemAbility(COMMON_EVENT_SERVICE_ID, pageStateChangeListener_);
72e1c44949Sopenharmony_ci            samgrProxy->UnSubscribeSystemAbility(COMMON_EVENT_SERVICE_ID, satcommEventListener_);
73e1c44949Sopenharmony_ci            samgrProxy->UnSubscribeSystemAbility(COMMON_EVENT_SERVICE_ID, superPrivacyEventListener_);
74e1c44949Sopenharmony_ci            pageStateChangeListener_ = nullptr;
75e1c44949Sopenharmony_ci            statusChangeListener_ = nullptr;
76e1c44949Sopenharmony_ci            satcommEventListener_ = nullptr;
77e1c44949Sopenharmony_ci            superPrivacyEventListener_ = nullptr;
78e1c44949Sopenharmony_ci        }
79e1c44949Sopenharmony_ci    }
80e1c44949Sopenharmony_ci}
81e1c44949Sopenharmony_ci
82e1c44949Sopenharmony_cibool CallControlManager::Init()
83e1c44949Sopenharmony_ci{
84e1c44949Sopenharmony_ci    callStateListenerPtr_ = std::make_unique<CallStateListener>();
85e1c44949Sopenharmony_ci    if (callStateListenerPtr_ == nullptr) {
86e1c44949Sopenharmony_ci        TELEPHONY_LOGE("callStateListenerPtr_ is null");
87e1c44949Sopenharmony_ci        return false;
88e1c44949Sopenharmony_ci    }
89e1c44949Sopenharmony_ci    CallRequestHandlerPtr_ = std::make_unique<CallRequestHandler>();
90e1c44949Sopenharmony_ci    if (CallRequestHandlerPtr_ == nullptr) {
91e1c44949Sopenharmony_ci        TELEPHONY_LOGE("CallRequestHandlerPtr_ is null");
92e1c44949Sopenharmony_ci        return false;
93e1c44949Sopenharmony_ci    }
94e1c44949Sopenharmony_ci    CallRequestHandlerPtr_->Init();
95e1c44949Sopenharmony_ci    incomingCallWakeup_ = std::make_shared<IncomingCallWakeup>();
96e1c44949Sopenharmony_ci    if (incomingCallWakeup_ == nullptr) {
97e1c44949Sopenharmony_ci        TELEPHONY_LOGE("incomingCallWakeup_ is null");
98e1c44949Sopenharmony_ci        return false;
99e1c44949Sopenharmony_ci    }
100e1c44949Sopenharmony_ci    missedCallNotification_ = std::make_shared<MissedCallNotification>();
101e1c44949Sopenharmony_ci    if (missedCallNotification_ == nullptr) {
102e1c44949Sopenharmony_ci        TELEPHONY_LOGE("missedCallNotification_ is null");
103e1c44949Sopenharmony_ci        return false;
104e1c44949Sopenharmony_ci    }
105e1c44949Sopenharmony_ci    callSettingManagerPtr_ = std::make_unique<CallSettingManager>();
106e1c44949Sopenharmony_ci    if (callSettingManagerPtr_ == nullptr) {
107e1c44949Sopenharmony_ci        TELEPHONY_LOGE("callSettingManagerPtr_ is nullptr!");
108e1c44949Sopenharmony_ci        return false;
109e1c44949Sopenharmony_ci    }
110e1c44949Sopenharmony_ci    if (BroadcastSubscriber() != TELEPHONY_SUCCESS) {
111e1c44949Sopenharmony_ci        TELEPHONY_LOGE("BroadcastSubscriber failed!");
112e1c44949Sopenharmony_ci        return false;
113e1c44949Sopenharmony_ci    }
114e1c44949Sopenharmony_ci    DelayedSingleton<AudioControlManager>::GetInstance()->Init();
115e1c44949Sopenharmony_ci    CallStateObserve();
116e1c44949Sopenharmony_ci    DelayedSingleton<CallSuperPrivacyControlManager>::GetInstance()->RegisterSuperPrivacyMode();
117e1c44949Sopenharmony_ci    DelayedSingleton<CallStateReportProxy>::GetInstance()->UpdateCallStateForVoIPOrRestart();
118e1c44949Sopenharmony_ci    return true;
119e1c44949Sopenharmony_ci}
120e1c44949Sopenharmony_ci
121e1c44949Sopenharmony_ciint32_t CallControlManager::DialCall(std::u16string &number, AppExecFwk::PacMap &extras)
122e1c44949Sopenharmony_ci{
123e1c44949Sopenharmony_ci    sptr<CallBase> callObjectPtr = nullptr;
124e1c44949Sopenharmony_ci    std::string accountNumber(Str16ToStr8(number));
125e1c44949Sopenharmony_ci    int32_t ret = NumberLegalityCheck(accountNumber);
126e1c44949Sopenharmony_ci    if (ret != TELEPHONY_SUCCESS) {
127e1c44949Sopenharmony_ci        TELEPHONY_LOGE("Invalid number!");
128e1c44949Sopenharmony_ci        return ret;
129e1c44949Sopenharmony_ci    }
130e1c44949Sopenharmony_ci    bool isEcc = false;
131e1c44949Sopenharmony_ci    DelayedSingleton<CallNumberUtils>::GetInstance()->CheckNumberIsEmergency(
132e1c44949Sopenharmony_ci        accountNumber, extras.GetIntValue("accountId"), isEcc);
133e1c44949Sopenharmony_ci    if (isEcc) {
134e1c44949Sopenharmony_ci        extras.PutIntValue("dialScene", (int32_t)DialScene::CALL_EMERGENCY);
135e1c44949Sopenharmony_ci    }
136e1c44949Sopenharmony_ci    ret = DelayedSingleton<SatelliteCallControl>::GetInstance()->IsSatelliteSwitchEnable();
137e1c44949Sopenharmony_ci    if (ret == TELEPHONY_SUCCESS) {
138e1c44949Sopenharmony_ci        ret = DelayedSingleton<SatelliteCallControl>::GetInstance()->IsAllowedSatelliteDialCall();
139e1c44949Sopenharmony_ci        if (ret != TELEPHONY_SUCCESS) {
140e1c44949Sopenharmony_ci            return ret;
141e1c44949Sopenharmony_ci        } else {
142e1c44949Sopenharmony_ci            extras.PutIntValue("callType", (int32_t)CallType::TYPE_SATELLITE);
143e1c44949Sopenharmony_ci        }
144e1c44949Sopenharmony_ci    }
145e1c44949Sopenharmony_ci    ret = CanDial(number, extras, isEcc);
146e1c44949Sopenharmony_ci    if (ret != TELEPHONY_SUCCESS) {
147e1c44949Sopenharmony_ci        TELEPHONY_LOGE("can dial policy result:%{public}d", ret);
148e1c44949Sopenharmony_ci        return ret;
149e1c44949Sopenharmony_ci    }
150e1c44949Sopenharmony_ci    if (!IsSupportVideoCall(extras)) {
151e1c44949Sopenharmony_ci        extras.PutIntValue("videoState", (int32_t)VideoStateType::TYPE_VOICE);
152e1c44949Sopenharmony_ci    }
153e1c44949Sopenharmony_ci    VideoStateType videoState = (VideoStateType)extras.GetIntValue("videoState");
154e1c44949Sopenharmony_ci    if (videoState == VideoStateType::TYPE_VIDEO) {
155e1c44949Sopenharmony_ci        extras.PutIntValue("callType", (int32_t)CallType::TYPE_IMS);
156e1c44949Sopenharmony_ci    }
157e1c44949Sopenharmony_ci    // temporarily save dial information
158e1c44949Sopenharmony_ci    PackageDialInformation(extras, accountNumber, isEcc);
159e1c44949Sopenharmony_ci    if (CallRequestHandlerPtr_ == nullptr) {
160e1c44949Sopenharmony_ci        TELEPHONY_LOGE("CallRequestHandlerPtr_ is nullptr!");
161e1c44949Sopenharmony_ci        return TELEPHONY_ERR_LOCAL_PTR_NULL;
162e1c44949Sopenharmony_ci    }
163e1c44949Sopenharmony_ci    ret = CallRequestHandlerPtr_->DialCall();
164e1c44949Sopenharmony_ci    if (ret != TELEPHONY_SUCCESS) {
165e1c44949Sopenharmony_ci        TELEPHONY_LOGE("DialCall failed!");
166e1c44949Sopenharmony_ci        return ret;
167e1c44949Sopenharmony_ci    }
168e1c44949Sopenharmony_ci    return TELEPHONY_SUCCESS;
169e1c44949Sopenharmony_ci}
170e1c44949Sopenharmony_ci
171e1c44949Sopenharmony_ciint32_t CallControlManager::CanDial(std::u16string &number, AppExecFwk::PacMap &extras, bool isEcc)
172e1c44949Sopenharmony_ci{
173e1c44949Sopenharmony_ci    int32_t ret = DialPolicy(number, extras, isEcc);
174e1c44949Sopenharmony_ci    if (ret != TELEPHONY_SUCCESS) {
175e1c44949Sopenharmony_ci        TELEPHONY_LOGE("dial policy result:%{public}d", ret);
176e1c44949Sopenharmony_ci        return ret;
177e1c44949Sopenharmony_ci    }
178e1c44949Sopenharmony_ci    ret = CanDialMulityCall(extras, isEcc);
179e1c44949Sopenharmony_ci    if (ret != TELEPHONY_SUCCESS) {
180e1c44949Sopenharmony_ci        TELEPHONY_LOGE("dial policy result:%{public}d", ret);
181e1c44949Sopenharmony_ci        return ret;
182e1c44949Sopenharmony_ci    }
183e1c44949Sopenharmony_ci    return TELEPHONY_SUCCESS;
184e1c44949Sopenharmony_ci}
185e1c44949Sopenharmony_ci
186e1c44949Sopenharmony_civoid CallControlManager::PackageDialInformation(AppExecFwk::PacMap &extras, std::string accountNumber, bool isEcc)
187e1c44949Sopenharmony_ci{
188e1c44949Sopenharmony_ci    std::lock_guard<std::mutex> lock(mutex_);
189e1c44949Sopenharmony_ci    dialSrcInfo_.callId = ERR_ID;
190e1c44949Sopenharmony_ci    dialSrcInfo_.number = accountNumber;
191e1c44949Sopenharmony_ci    dialSrcInfo_.isDialing = true;
192e1c44949Sopenharmony_ci    dialSrcInfo_.isEcc = isEcc;
193e1c44949Sopenharmony_ci    dialSrcInfo_.callType = (CallType)extras.GetIntValue("callType");
194e1c44949Sopenharmony_ci    dialSrcInfo_.accountId = extras.GetIntValue("accountId");
195e1c44949Sopenharmony_ci    dialSrcInfo_.dialType = (DialType)extras.GetIntValue("dialType");
196e1c44949Sopenharmony_ci    dialSrcInfo_.videoState = (VideoStateType)extras.GetIntValue("videoState");
197e1c44949Sopenharmony_ci    dialSrcInfo_.originalCallType = (int32_t)extras.GetIntValue("videoState");
198e1c44949Sopenharmony_ci    dialSrcInfo_.bundleName = extras.GetStringValue("bundleName");
199e1c44949Sopenharmony_ci    extras_.Clear();
200e1c44949Sopenharmony_ci    extras_ = extras;
201e1c44949Sopenharmony_ci}
202e1c44949Sopenharmony_ci
203e1c44949Sopenharmony_ciint32_t CallControlManager::AnswerCall(int32_t callId, int32_t videoState)
204e1c44949Sopenharmony_ci{
205e1c44949Sopenharmony_ci    sptr<CallBase> call = GetOneCallObject(CallRunningState::CALL_RUNNING_STATE_RINGING);
206e1c44949Sopenharmony_ci    if (call == nullptr) {
207e1c44949Sopenharmony_ci        TELEPHONY_LOGE("call is nullptr");
208e1c44949Sopenharmony_ci        CallManagerHisysevent::WriteAnswerCallFaultEvent(
209e1c44949Sopenharmony_ci            INVALID_PARAMETER, callId, videoState, TELEPHONY_ERR_LOCAL_PTR_NULL, "call is nullptr");
210e1c44949Sopenharmony_ci        return TELEPHONY_ERR_LOCAL_PTR_NULL;
211e1c44949Sopenharmony_ci    }
212e1c44949Sopenharmony_ci    if (callId == INVALID_CALLID) {
213e1c44949Sopenharmony_ci        callId = call->GetCallID();
214e1c44949Sopenharmony_ci    }
215e1c44949Sopenharmony_ci    call = GetOneCallObject(callId);
216e1c44949Sopenharmony_ci    if (call == nullptr) {
217e1c44949Sopenharmony_ci        TELEPHONY_LOGE("call is nullptr");
218e1c44949Sopenharmony_ci        return TELEPHONY_ERR_LOCAL_PTR_NULL;
219e1c44949Sopenharmony_ci    }
220e1c44949Sopenharmony_ci    if (call->GetCrsType() == CRS_TYPE && static_cast<VideoStateType>(videoState) != VideoStateType::TYPE_VIDEO) {
221e1c44949Sopenharmony_ci        DelayedSingleton<AudioProxy>::GetInstance()->SetSpeakerDevActive(false);
222e1c44949Sopenharmony_ci    }
223e1c44949Sopenharmony_ci    if (CurrentIsSuperPrivacyMode(callId, videoState)) {
224e1c44949Sopenharmony_ci        return TELEPHONY_SUCCESS;
225e1c44949Sopenharmony_ci    }
226e1c44949Sopenharmony_ci    call->SetAnsweredCall(true);
227e1c44949Sopenharmony_ci    AnswerHandlerForSatelliteOrVideoCall(call, videoState);
228e1c44949Sopenharmony_ci    TELEPHONY_LOGI("report answered state");
229e1c44949Sopenharmony_ci    NotifyCallStateUpdated(call, TelCallState::CALL_STATUS_INCOMING, TelCallState::CALL_STATUS_ANSWERED);
230e1c44949Sopenharmony_ci    CarrierAndVoipConflictProcess(callId, TelCallState::CALL_STATUS_ANSWERED);
231e1c44949Sopenharmony_ci    if (VoIPCallState_ != CallStateToApp::CALL_STATE_IDLE) {
232e1c44949Sopenharmony_ci        TELEPHONY_LOGW("VoIP call is active, waiting for VoIP to disconnect");
233e1c44949Sopenharmony_ci        AnsweredCallQueue_.hasCall = true;
234e1c44949Sopenharmony_ci        AnsweredCallQueue_.callId = callId;
235e1c44949Sopenharmony_ci        AnsweredCallQueue_.videoState = videoState;
236e1c44949Sopenharmony_ci        return TELEPHONY_SUCCESS;
237e1c44949Sopenharmony_ci    }
238e1c44949Sopenharmony_ci    int32_t ret = AnswerCallPolicy(callId, videoState);
239e1c44949Sopenharmony_ci    if (ret != TELEPHONY_SUCCESS) {
240e1c44949Sopenharmony_ci        TELEPHONY_LOGE("AnswerCallPolicy failed!");
241e1c44949Sopenharmony_ci        CallManagerHisysevent::WriteAnswerCallFaultEvent(
242e1c44949Sopenharmony_ci            INVALID_PARAMETER, callId, videoState, ret, "AnswerCallPolicy failed");
243e1c44949Sopenharmony_ci        return ret;
244e1c44949Sopenharmony_ci    }
245e1c44949Sopenharmony_ci    if (CallRequestHandlerPtr_ == nullptr) {
246e1c44949Sopenharmony_ci        TELEPHONY_LOGE("CallRequestHandlerPtr_ is nullptr!");
247e1c44949Sopenharmony_ci        return TELEPHONY_ERR_LOCAL_PTR_NULL;
248e1c44949Sopenharmony_ci    }
249e1c44949Sopenharmony_ci    ret = CallRequestHandlerPtr_->AnswerCall(callId, videoState);
250e1c44949Sopenharmony_ci    if (ret != TELEPHONY_SUCCESS) {
251e1c44949Sopenharmony_ci        TELEPHONY_LOGE("AnswerCall failed!");
252e1c44949Sopenharmony_ci        return ret;
253e1c44949Sopenharmony_ci    }
254e1c44949Sopenharmony_ci    return TELEPHONY_SUCCESS;
255e1c44949Sopenharmony_ci}
256e1c44949Sopenharmony_ci
257e1c44949Sopenharmony_cibool CallControlManager::CurrentIsSuperPrivacyMode(int32_t callId, int32_t videoState)
258e1c44949Sopenharmony_ci{
259e1c44949Sopenharmony_ci    bool currentIsSuperPrivacyMode = DelayedSingleton<CallSuperPrivacyControlManager>::GetInstance()->
260e1c44949Sopenharmony_ci        GetCurrentIsSuperPrivacyMode();
261e1c44949Sopenharmony_ci    TELEPHONY_LOGI("call policy answer currentIsSuperPrivacyMode:%{public}d", currentIsSuperPrivacyMode);
262e1c44949Sopenharmony_ci    if (currentIsSuperPrivacyMode) {
263e1c44949Sopenharmony_ci        DelayedSingleton<AudioControlManager>::GetInstance()->MuteRinger();
264e1c44949Sopenharmony_ci        DelayedSingleton<CallDialog>::GetInstance()->DialogConnectAnswerPrivpacyModeExtension("SUPER_PRIVACY_MODE",
265e1c44949Sopenharmony_ci            callId, videoState, true);
266e1c44949Sopenharmony_ci        return true;
267e1c44949Sopenharmony_ci    }
268e1c44949Sopenharmony_ci    return false;
269e1c44949Sopenharmony_ci}
270e1c44949Sopenharmony_ci
271e1c44949Sopenharmony_civoid CallControlManager::AnswerHandlerForSatelliteOrVideoCall(sptr<CallBase> &call, int32_t videoState)
272e1c44949Sopenharmony_ci{
273e1c44949Sopenharmony_ci    if (call == nullptr) {
274e1c44949Sopenharmony_ci        TELEPHONY_LOGE("call is nullptr");
275e1c44949Sopenharmony_ci        return;
276e1c44949Sopenharmony_ci    }
277e1c44949Sopenharmony_ci    if (call->GetCallType() == CallType::TYPE_IMS && videoState != static_cast<int32_t>(call->GetVideoStateType())) {
278e1c44949Sopenharmony_ci        call->SetVideoStateType(static_cast<VideoStateType>(videoState));
279e1c44949Sopenharmony_ci        sptr<IMSCall> imsCall = reinterpret_cast<IMSCall *>(call.GetRefPtr());
280e1c44949Sopenharmony_ci        imsCall->InitVideoCall();
281e1c44949Sopenharmony_ci        TELEPHONY_LOGI("videoState has changed");
282e1c44949Sopenharmony_ci    }
283e1c44949Sopenharmony_ci    if (call->GetCallType() == CallType::TYPE_SATELLITE) {
284e1c44949Sopenharmony_ci        sptr<CallBase> foregroundSatelliteCall =
285e1c44949Sopenharmony_ci            CallObjectManager::GetOneCallObject(CallRunningState::CALL_RUNNING_STATE_ACTIVE);
286e1c44949Sopenharmony_ci        if (foregroundSatelliteCall != nullptr) {
287e1c44949Sopenharmony_ci            CallRequestHandlerPtr_->HangUpCall(foregroundSatelliteCall->GetCallID());
288e1c44949Sopenharmony_ci        }
289e1c44949Sopenharmony_ci    }
290e1c44949Sopenharmony_ci}
291e1c44949Sopenharmony_ci
292e1c44949Sopenharmony_ciint32_t CallControlManager::CarrierAndVoipConflictProcess(int32_t callId, TelCallState callState)
293e1c44949Sopenharmony_ci{
294e1c44949Sopenharmony_ci    if (callState != TelCallState::CALL_STATUS_ANSWERED) {
295e1c44949Sopenharmony_ci        TELEPHONY_LOGI("voip calls should be handled with only when a carrier call is answered");
296e1c44949Sopenharmony_ci        return TELEPHONY_SUCCESS;
297e1c44949Sopenharmony_ci    }
298e1c44949Sopenharmony_ci    sptr<CallBase> call = GetOneCallObject(callId);
299e1c44949Sopenharmony_ci    if (call == nullptr) {
300e1c44949Sopenharmony_ci        TELEPHONY_LOGE("CarrierAndVoipConflictProcess, call is nullptr!");
301e1c44949Sopenharmony_ci        return TELEPHONY_ERR_LOCAL_PTR_NULL;
302e1c44949Sopenharmony_ci    }
303e1c44949Sopenharmony_ci    if (call->GetCallType() == CallType::TYPE_CS ||
304e1c44949Sopenharmony_ci        call->GetCallType() == CallType::TYPE_IMS ||
305e1c44949Sopenharmony_ci        call->GetCallType() == CallType::TYPE_SATELLITE) {
306e1c44949Sopenharmony_ci        std::list<int32_t> voipCallIdList;
307e1c44949Sopenharmony_ci        int32_t ret = GetVoipCallList(voipCallIdList);
308e1c44949Sopenharmony_ci        if (ret != TELEPHONY_SUCCESS) {
309e1c44949Sopenharmony_ci            TELEPHONY_LOGE("GetVoipCallList failed!");
310e1c44949Sopenharmony_ci            return ret;
311e1c44949Sopenharmony_ci        }
312e1c44949Sopenharmony_ci        for (auto voipCallId : voipCallIdList) {
313e1c44949Sopenharmony_ci            sptr<CallBase> voipCall = GetOneCallObject(voipCallId);
314e1c44949Sopenharmony_ci            TelCallState voipCallState = voipCall->GetTelCallState();
315e1c44949Sopenharmony_ci            if (voipCallState == TelCallState::CALL_STATUS_INCOMING) {
316e1c44949Sopenharmony_ci                TELEPHONY_LOGI("the system is rejecting a voip call, callId = %{public}d", voipCall->GetCallID());
317e1c44949Sopenharmony_ci                ret = RejectCall(voipCallId, true, u"CarrierAndVoipConflictProcess");
318e1c44949Sopenharmony_ci            } else if (voipCallState == TelCallState::CALL_STATUS_DIALING) {
319e1c44949Sopenharmony_ci                TELEPHONY_LOGI("the system is hanging up a voip call, callId = %{public}d", voipCall->GetCallID());
320e1c44949Sopenharmony_ci                ret = HangUpCall(voipCallId);
321e1c44949Sopenharmony_ci            }
322e1c44949Sopenharmony_ci            if (ret != TELEPHONY_SUCCESS) {
323e1c44949Sopenharmony_ci                TELEPHONY_LOGE("CarrierAndVoipConflictProcess failed!");
324e1c44949Sopenharmony_ci                return ret;
325e1c44949Sopenharmony_ci            }
326e1c44949Sopenharmony_ci        }
327e1c44949Sopenharmony_ci        return TELEPHONY_SUCCESS;
328e1c44949Sopenharmony_ci    }
329e1c44949Sopenharmony_ci    return TELEPHONY_SUCCESS;
330e1c44949Sopenharmony_ci}
331e1c44949Sopenharmony_ci
332e1c44949Sopenharmony_ciint32_t CallControlManager::RejectCall(int32_t callId, bool rejectWithMessage, std::u16string textMessage)
333e1c44949Sopenharmony_ci{
334e1c44949Sopenharmony_ci    if (CallRequestHandlerPtr_ == nullptr) {
335e1c44949Sopenharmony_ci        TELEPHONY_LOGE("CallRequestHandlerPtr_ is nullptr!");
336e1c44949Sopenharmony_ci        return TELEPHONY_ERR_LOCAL_PTR_NULL;
337e1c44949Sopenharmony_ci    }
338e1c44949Sopenharmony_ci
339e1c44949Sopenharmony_ci    if (callId == INVALID_CALLID) {
340e1c44949Sopenharmony_ci        sptr<CallBase> call = GetOneCallObject(CallRunningState::CALL_RUNNING_STATE_RINGING);
341e1c44949Sopenharmony_ci        if (call == nullptr) {
342e1c44949Sopenharmony_ci            TELEPHONY_LOGE("call is nullptr");
343e1c44949Sopenharmony_ci            CallManagerHisysevent::WriteHangUpFaultEvent(
344e1c44949Sopenharmony_ci                INVALID_PARAMETER, callId, TELEPHONY_ERR_LOCAL_PTR_NULL, "Reject call is nullptr");
345e1c44949Sopenharmony_ci            return TELEPHONY_ERR_LOCAL_PTR_NULL;
346e1c44949Sopenharmony_ci        }
347e1c44949Sopenharmony_ci        callId = call->GetCallID();
348e1c44949Sopenharmony_ci    }
349e1c44949Sopenharmony_ci
350e1c44949Sopenharmony_ci    int32_t ret = RejectCallPolicy(callId);
351e1c44949Sopenharmony_ci    if (ret != TELEPHONY_SUCCESS) {
352e1c44949Sopenharmony_ci        TELEPHONY_LOGE("RejectCallPolicy failed!");
353e1c44949Sopenharmony_ci        CallManagerHisysevent::WriteHangUpFaultEvent(INVALID_PARAMETER, callId, ret, "Reject RejectCallPolicy failed");
354e1c44949Sopenharmony_ci        return ret;
355e1c44949Sopenharmony_ci    }
356e1c44949Sopenharmony_ci    std::string messageStr(Str16ToStr8(textMessage));
357e1c44949Sopenharmony_ci    ret = CallRequestHandlerPtr_->RejectCall(callId, rejectWithMessage, messageStr);
358e1c44949Sopenharmony_ci    if (ret != TELEPHONY_SUCCESS) {
359e1c44949Sopenharmony_ci        TELEPHONY_LOGE("RejectCall failed!");
360e1c44949Sopenharmony_ci        return ret;
361e1c44949Sopenharmony_ci    }
362e1c44949Sopenharmony_ci    return TELEPHONY_SUCCESS;
363e1c44949Sopenharmony_ci}
364e1c44949Sopenharmony_ci
365e1c44949Sopenharmony_ciint32_t CallControlManager::HangUpCall(int32_t callId)
366e1c44949Sopenharmony_ci{
367e1c44949Sopenharmony_ci    if (callId == INVALID_CALLID) {
368e1c44949Sopenharmony_ci        std::vector<CallRunningState> callRunningStateVec;
369e1c44949Sopenharmony_ci        callRunningStateVec.push_back(CallRunningState::CALL_RUNNING_STATE_ACTIVE);
370e1c44949Sopenharmony_ci        callRunningStateVec.push_back(CallRunningState::CALL_RUNNING_STATE_DIALING);
371e1c44949Sopenharmony_ci        callRunningStateVec.push_back(CallRunningState::CALL_RUNNING_STATE_CONNECTING);
372e1c44949Sopenharmony_ci        callRunningStateVec.push_back(CallRunningState::CALL_RUNNING_STATE_HOLD);
373e1c44949Sopenharmony_ci
374e1c44949Sopenharmony_ci        for (auto &state : callRunningStateVec) {
375e1c44949Sopenharmony_ci            sptr<CallBase> call = GetOneCallObject(state);
376e1c44949Sopenharmony_ci            if (call != nullptr) {
377e1c44949Sopenharmony_ci                callId = call->GetCallID();
378e1c44949Sopenharmony_ci                break;
379e1c44949Sopenharmony_ci            }
380e1c44949Sopenharmony_ci        }
381e1c44949Sopenharmony_ci
382e1c44949Sopenharmony_ci        if (callId == INVALID_CALLID) {
383e1c44949Sopenharmony_ci            TELEPHONY_LOGE("callId is INVALID_CALLID!");
384e1c44949Sopenharmony_ci            CallManagerHisysevent::WriteHangUpFaultEvent(
385e1c44949Sopenharmony_ci                INVALID_PARAMETER, callId, TELEPHONY_ERR_LOCAL_PTR_NULL, "HangUp callId is INVALID_CALLID");
386e1c44949Sopenharmony_ci            return TELEPHONY_ERR_ARGUMENT_INVALID;
387e1c44949Sopenharmony_ci        }
388e1c44949Sopenharmony_ci    }
389e1c44949Sopenharmony_ci
390e1c44949Sopenharmony_ci    if (CallRequestHandlerPtr_ == nullptr) {
391e1c44949Sopenharmony_ci        TELEPHONY_LOGE("CallRequestHandlerPtr_ is nullptr!");
392e1c44949Sopenharmony_ci        return TELEPHONY_ERR_LOCAL_PTR_NULL;
393e1c44949Sopenharmony_ci    }
394e1c44949Sopenharmony_ci    int32_t ret = HangUpPolicy(callId);
395e1c44949Sopenharmony_ci    if (ret != TELEPHONY_SUCCESS) {
396e1c44949Sopenharmony_ci        TELEPHONY_LOGE("HangUpPolicy failed!");
397e1c44949Sopenharmony_ci        CallManagerHisysevent::WriteHangUpFaultEvent(INVALID_PARAMETER, callId, ret, "HangUp HangUpPolicy failed");
398e1c44949Sopenharmony_ci        return ret;
399e1c44949Sopenharmony_ci    }
400e1c44949Sopenharmony_ci    auto callRequestEventHandler = DelayedSingleton<CallRequestEventHandlerHelper>::GetInstance();
401e1c44949Sopenharmony_ci    if (callRequestEventHandler->HasPendingMo(callId)) {
402e1c44949Sopenharmony_ci        callRequestEventHandler->SetPendingMo(false, -1);
403e1c44949Sopenharmony_ci        callRequestEventHandler->SetPendingHangup(true, callId);
404e1c44949Sopenharmony_ci        TELEPHONY_LOGI("HangUpCall before dialingHandle,hangup after CLCC");
405e1c44949Sopenharmony_ci        return TELEPHONY_SUCCESS;
406e1c44949Sopenharmony_ci    }
407e1c44949Sopenharmony_ci    ret = CallRequestHandlerPtr_->HangUpCall(callId);
408e1c44949Sopenharmony_ci    if (ret != TELEPHONY_SUCCESS) {
409e1c44949Sopenharmony_ci        TELEPHONY_LOGE("HangUpCall failed!");
410e1c44949Sopenharmony_ci        return ret;
411e1c44949Sopenharmony_ci    }
412e1c44949Sopenharmony_ci    return TELEPHONY_SUCCESS;
413e1c44949Sopenharmony_ci}
414e1c44949Sopenharmony_ci
415e1c44949Sopenharmony_ciint32_t CallControlManager::GetCallState()
416e1c44949Sopenharmony_ci{
417e1c44949Sopenharmony_ci    CallStateToApp callState = CallStateToApp::CALL_STATE_UNKNOWN;
418e1c44949Sopenharmony_ci    if (!HasCellularCallExist()) {
419e1c44949Sopenharmony_ci        callState = CallStateToApp::CALL_STATE_IDLE;
420e1c44949Sopenharmony_ci    } else {
421e1c44949Sopenharmony_ci        callState = CallStateToApp::CALL_STATE_OFFHOOK;
422e1c44949Sopenharmony_ci        bool hasRingingCall = false;
423e1c44949Sopenharmony_ci        if ((HasRingingCall(hasRingingCall) == TELEPHONY_SUCCESS) && hasRingingCall) {
424e1c44949Sopenharmony_ci            callState = CallStateToApp::CALL_STATE_RINGING;
425e1c44949Sopenharmony_ci        }
426e1c44949Sopenharmony_ci    }
427e1c44949Sopenharmony_ci    return static_cast<int32_t>(callState);
428e1c44949Sopenharmony_ci}
429e1c44949Sopenharmony_ci
430e1c44949Sopenharmony_ciint32_t CallControlManager::HoldCall(int32_t callId)
431e1c44949Sopenharmony_ci{
432e1c44949Sopenharmony_ci    int32_t ret = HoldCallPolicy(callId);
433e1c44949Sopenharmony_ci    if (ret != TELEPHONY_SUCCESS) {
434e1c44949Sopenharmony_ci        TELEPHONY_LOGE("HoldCall failed!");
435e1c44949Sopenharmony_ci        return ret;
436e1c44949Sopenharmony_ci    }
437e1c44949Sopenharmony_ci    if (CallRequestHandlerPtr_ == nullptr) {
438e1c44949Sopenharmony_ci        TELEPHONY_LOGE("CallRequestHandlerPtr_ is nullptr!");
439e1c44949Sopenharmony_ci        return TELEPHONY_ERR_LOCAL_PTR_NULL;
440e1c44949Sopenharmony_ci    }
441e1c44949Sopenharmony_ci    ret = CallRequestHandlerPtr_->HoldCall(callId);
442e1c44949Sopenharmony_ci    if (ret != TELEPHONY_SUCCESS) {
443e1c44949Sopenharmony_ci        TELEPHONY_LOGE("HoldCall failed!");
444e1c44949Sopenharmony_ci        return ret;
445e1c44949Sopenharmony_ci    }
446e1c44949Sopenharmony_ci    return TELEPHONY_SUCCESS;
447e1c44949Sopenharmony_ci}
448e1c44949Sopenharmony_ci
449e1c44949Sopenharmony_ciint32_t CallControlManager::UnHoldCall(const int32_t callId)
450e1c44949Sopenharmony_ci{
451e1c44949Sopenharmony_ci    int32_t ret = UnHoldCallPolicy(callId);
452e1c44949Sopenharmony_ci    if (ret != TELEPHONY_SUCCESS) {
453e1c44949Sopenharmony_ci        TELEPHONY_LOGE("UnHoldCall failed!");
454e1c44949Sopenharmony_ci        return ret;
455e1c44949Sopenharmony_ci    }
456e1c44949Sopenharmony_ci    if (CallRequestHandlerPtr_ == nullptr) {
457e1c44949Sopenharmony_ci        TELEPHONY_LOGE("CallRequestHandlerPtr_ is nullptr!");
458e1c44949Sopenharmony_ci        return TELEPHONY_ERR_LOCAL_PTR_NULL;
459e1c44949Sopenharmony_ci    }
460e1c44949Sopenharmony_ci    ret = CallRequestHandlerPtr_->UnHoldCall(callId);
461e1c44949Sopenharmony_ci    if (ret != TELEPHONY_SUCCESS) {
462e1c44949Sopenharmony_ci        TELEPHONY_LOGE("UnHoldCall failed!");
463e1c44949Sopenharmony_ci        return ret;
464e1c44949Sopenharmony_ci    }
465e1c44949Sopenharmony_ci    return TELEPHONY_SUCCESS;
466e1c44949Sopenharmony_ci}
467e1c44949Sopenharmony_ci
468e1c44949Sopenharmony_ci// swap two calls state, turn active call into holding, and turn holding call into active
469e1c44949Sopenharmony_ciint32_t CallControlManager::SwitchCall(int32_t callId)
470e1c44949Sopenharmony_ci{
471e1c44949Sopenharmony_ci    int32_t ret = SwitchCallPolicy(callId);
472e1c44949Sopenharmony_ci    if (ret != TELEPHONY_SUCCESS) {
473e1c44949Sopenharmony_ci        TELEPHONY_LOGE("SwitchCall failed!");
474e1c44949Sopenharmony_ci        return ret;
475e1c44949Sopenharmony_ci    }
476e1c44949Sopenharmony_ci    if (CallRequestHandlerPtr_ == nullptr) {
477e1c44949Sopenharmony_ci        TELEPHONY_LOGE("CallRequestHandlerPtr_ is nullptr!");
478e1c44949Sopenharmony_ci        return TELEPHONY_ERR_LOCAL_PTR_NULL;
479e1c44949Sopenharmony_ci    }
480e1c44949Sopenharmony_ci    ret = CallRequestHandlerPtr_->SwitchCall(callId);
481e1c44949Sopenharmony_ci    if (ret != TELEPHONY_SUCCESS) {
482e1c44949Sopenharmony_ci        TELEPHONY_LOGE("SwitchCall failed!");
483e1c44949Sopenharmony_ci        return ret;
484e1c44949Sopenharmony_ci    }
485e1c44949Sopenharmony_ci    return TELEPHONY_SUCCESS;
486e1c44949Sopenharmony_ci}
487e1c44949Sopenharmony_ci
488e1c44949Sopenharmony_cibool CallControlManager::HasCall()
489e1c44949Sopenharmony_ci{
490e1c44949Sopenharmony_ci    return HasCellularCallExist();
491e1c44949Sopenharmony_ci}
492e1c44949Sopenharmony_ci
493e1c44949Sopenharmony_ciint32_t CallControlManager::IsNewCallAllowed(bool &enabled)
494e1c44949Sopenharmony_ci{
495e1c44949Sopenharmony_ci    return IsNewCallAllowedCreate(enabled);
496e1c44949Sopenharmony_ci}
497e1c44949Sopenharmony_ci
498e1c44949Sopenharmony_ciint32_t CallControlManager::IsRinging(bool &enabled)
499e1c44949Sopenharmony_ci{
500e1c44949Sopenharmony_ci    return HasRingingCall(enabled);
501e1c44949Sopenharmony_ci}
502e1c44949Sopenharmony_ci
503e1c44949Sopenharmony_ciint32_t CallControlManager::HasEmergency(bool &enabled)
504e1c44949Sopenharmony_ci{
505e1c44949Sopenharmony_ci    return HasEmergencyCall(enabled);
506e1c44949Sopenharmony_ci}
507e1c44949Sopenharmony_ci
508e1c44949Sopenharmony_cibool CallControlManager::NotifyNewCallCreated(sptr<CallBase> &callObjectPtr)
509e1c44949Sopenharmony_ci{
510e1c44949Sopenharmony_ci    if (callObjectPtr == nullptr) {
511e1c44949Sopenharmony_ci        TELEPHONY_LOGE("callObjectPtr is null!");
512e1c44949Sopenharmony_ci        return false;
513e1c44949Sopenharmony_ci    }
514e1c44949Sopenharmony_ci    if (callStateListenerPtr_ != nullptr) {
515e1c44949Sopenharmony_ci        callStateListenerPtr_->NewCallCreated(callObjectPtr);
516e1c44949Sopenharmony_ci    }
517e1c44949Sopenharmony_ci    return true;
518e1c44949Sopenharmony_ci}
519e1c44949Sopenharmony_ci
520e1c44949Sopenharmony_cibool CallControlManager::NotifyCallDestroyed(const DisconnectedDetails &details)
521e1c44949Sopenharmony_ci{
522e1c44949Sopenharmony_ci    if (callStateListenerPtr_ != nullptr) {
523e1c44949Sopenharmony_ci        callStateListenerPtr_->CallDestroyed(details);
524e1c44949Sopenharmony_ci        return true;
525e1c44949Sopenharmony_ci    }
526e1c44949Sopenharmony_ci    return false;
527e1c44949Sopenharmony_ci}
528e1c44949Sopenharmony_ci
529e1c44949Sopenharmony_cibool CallControlManager::NotifyCallStateUpdated(
530e1c44949Sopenharmony_ci    sptr<CallBase> &callObjectPtr, TelCallState priorState, TelCallState nextState)
531e1c44949Sopenharmony_ci{
532e1c44949Sopenharmony_ci    if (callObjectPtr == nullptr) {
533e1c44949Sopenharmony_ci        TELEPHONY_LOGE("callObjectPtr is null!");
534e1c44949Sopenharmony_ci        return false;
535e1c44949Sopenharmony_ci    }
536e1c44949Sopenharmony_ci    if (callStateListenerPtr_ != nullptr) {
537e1c44949Sopenharmony_ci        TELEPHONY_LOGI("NotifyCallStateUpdated priorState:%{public}d,nextState:%{public}d", priorState, nextState);
538e1c44949Sopenharmony_ci        callStateListenerPtr_->CallStateUpdated(callObjectPtr, priorState, nextState);
539e1c44949Sopenharmony_ci        if (callObjectPtr->GetCallType() == CallType::TYPE_VOIP) {
540e1c44949Sopenharmony_ci            return true;
541e1c44949Sopenharmony_ci        }
542e1c44949Sopenharmony_ci        if (priorState == TelCallState::CALL_STATUS_DIALING &&
543e1c44949Sopenharmony_ci            (nextState == TelCallState::CALL_STATUS_ALERTING || nextState == TelCallState::CALL_STATUS_ACTIVE)) {
544e1c44949Sopenharmony_ci            TELEPHONY_LOGI("call is actived, now check and switch call to distributed audio device");
545e1c44949Sopenharmony_ci            DelayedSingleton<AudioDeviceManager>::GetInstance()->CheckAndSwitchDistributedAudioDevice();
546e1c44949Sopenharmony_ci        } else if ((priorState == TelCallState::CALL_STATUS_ACTIVE &&
547e1c44949Sopenharmony_ci            nextState == TelCallState::CALL_STATUS_DISCONNECTED) ||
548e1c44949Sopenharmony_ci            (priorState == TelCallState::CALL_STATUS_DISCONNECTING &&
549e1c44949Sopenharmony_ci            nextState == TelCallState::CALL_STATUS_DISCONNECTED)) {
550e1c44949Sopenharmony_ci            bool hasHoldCall = false;
551e1c44949Sopenharmony_ci            if ((HasHoldCall(hasHoldCall) == TELEPHONY_SUCCESS) && !hasHoldCall) {
552e1c44949Sopenharmony_ci                TELEPHONY_LOGI("call is disconnected, clear distributed call state");
553e1c44949Sopenharmony_ci                DelayedSingleton<AudioDeviceManager>::GetInstance()->OnActivedCallDisconnected();
554e1c44949Sopenharmony_ci            }
555e1c44949Sopenharmony_ci        } else if (priorState == TelCallState::CALL_STATUS_WAITING &&
556e1c44949Sopenharmony_ci            nextState == TelCallState::CALL_STATUS_ACTIVE) {
557e1c44949Sopenharmony_ci            if (DelayedSingleton<DistributedCallManager>::GetInstance()->IsDCallDeviceSwitchedOn()) {
558e1c44949Sopenharmony_ci                TELEPHONY_LOGI("answer multi-line call, need switch again.");
559e1c44949Sopenharmony_ci                DelayedSingleton<AudioDeviceManager>::GetInstance()->CheckAndSwitchDistributedAudioDevice();
560e1c44949Sopenharmony_ci            }
561e1c44949Sopenharmony_ci        }
562e1c44949Sopenharmony_ci        return true;
563e1c44949Sopenharmony_ci    }
564e1c44949Sopenharmony_ci    return false;
565e1c44949Sopenharmony_ci}
566e1c44949Sopenharmony_ci
567e1c44949Sopenharmony_cibool CallControlManager::NotifyIncomingCallAnswered(sptr<CallBase> &callObjectPtr)
568e1c44949Sopenharmony_ci{
569e1c44949Sopenharmony_ci    if (callObjectPtr == nullptr) {
570e1c44949Sopenharmony_ci        TELEPHONY_LOGE("callObjectPtr is null!");
571e1c44949Sopenharmony_ci        return false;
572e1c44949Sopenharmony_ci    }
573e1c44949Sopenharmony_ci    if (callStateListenerPtr_ != nullptr) {
574e1c44949Sopenharmony_ci        callStateListenerPtr_->IncomingCallActivated(callObjectPtr);
575e1c44949Sopenharmony_ci        TELEPHONY_LOGI("call is answered, now check and switch call to distributed audio device");
576e1c44949Sopenharmony_ci        DelayedSingleton<AudioDeviceManager>::GetInstance()->CheckAndSwitchDistributedAudioDevice();
577e1c44949Sopenharmony_ci        return true;
578e1c44949Sopenharmony_ci    }
579e1c44949Sopenharmony_ci    return false;
580e1c44949Sopenharmony_ci}
581e1c44949Sopenharmony_ci
582e1c44949Sopenharmony_cibool CallControlManager::NotifyIncomingCallRejected(
583e1c44949Sopenharmony_ci    sptr<CallBase> &callObjectPtr, bool isSendSms, std::string content)
584e1c44949Sopenharmony_ci{
585e1c44949Sopenharmony_ci    if (callObjectPtr == nullptr) {
586e1c44949Sopenharmony_ci        TELEPHONY_LOGE("callObjectPtr is null!");
587e1c44949Sopenharmony_ci        return false;
588e1c44949Sopenharmony_ci    }
589e1c44949Sopenharmony_ci    if (callStateListenerPtr_ != nullptr) {
590e1c44949Sopenharmony_ci        callStateListenerPtr_->IncomingCallHungUp(callObjectPtr, isSendSms, content);
591e1c44949Sopenharmony_ci        return true;
592e1c44949Sopenharmony_ci    }
593e1c44949Sopenharmony_ci    return false;
594e1c44949Sopenharmony_ci}
595e1c44949Sopenharmony_ci
596e1c44949Sopenharmony_cibool CallControlManager::NotifyCallEventUpdated(CallEventInfo &info)
597e1c44949Sopenharmony_ci{
598e1c44949Sopenharmony_ci    if (callStateListenerPtr_ != nullptr) {
599e1c44949Sopenharmony_ci        callStateListenerPtr_->CallEventUpdated(info);
600e1c44949Sopenharmony_ci        return true;
601e1c44949Sopenharmony_ci    }
602e1c44949Sopenharmony_ci    return false;
603e1c44949Sopenharmony_ci}
604e1c44949Sopenharmony_ci
605e1c44949Sopenharmony_ciint32_t CallControlManager::StartDtmf(int32_t callId, char str)
606e1c44949Sopenharmony_ci{
607e1c44949Sopenharmony_ci    sptr<CallBase> call = GetOneCallObject(callId);
608e1c44949Sopenharmony_ci    if (call == nullptr) {
609e1c44949Sopenharmony_ci        return TELEPHONY_ERR_ARGUMENT_INVALID;
610e1c44949Sopenharmony_ci    }
611e1c44949Sopenharmony_ci    if (!call->IsAliveState()) {
612e1c44949Sopenharmony_ci        return CALL_ERR_CALL_STATE_MISMATCH_OPERATION;
613e1c44949Sopenharmony_ci    }
614e1c44949Sopenharmony_ci
615e1c44949Sopenharmony_ci    int32_t ret = call->StartDtmf(str);
616e1c44949Sopenharmony_ci    if (ret != TELEPHONY_SUCCESS) {
617e1c44949Sopenharmony_ci        TELEPHONY_LOGE("StartDtmf failed, return:%{public}d", ret);
618e1c44949Sopenharmony_ci    }
619e1c44949Sopenharmony_ci    ffrt::submit([str]() {
620e1c44949Sopenharmony_ci        DelayedSingleton<AudioControlManager>::GetInstance()->PlayDtmfTone(str);
621e1c44949Sopenharmony_ci    });
622e1c44949Sopenharmony_ci    return ret;
623e1c44949Sopenharmony_ci}
624e1c44949Sopenharmony_ci
625e1c44949Sopenharmony_ciint32_t CallControlManager::StopDtmf(int32_t callId)
626e1c44949Sopenharmony_ci{
627e1c44949Sopenharmony_ci    sptr<CallBase> call = GetOneCallObject(callId);
628e1c44949Sopenharmony_ci    if (call == nullptr) {
629e1c44949Sopenharmony_ci        return TELEPHONY_ERR_ARGUMENT_INVALID;
630e1c44949Sopenharmony_ci    }
631e1c44949Sopenharmony_ci    if (!call->IsAliveState()) {
632e1c44949Sopenharmony_ci        return CALL_ERR_CALL_STATE_MISMATCH_OPERATION;
633e1c44949Sopenharmony_ci    }
634e1c44949Sopenharmony_ci
635e1c44949Sopenharmony_ci    int32_t ret = call->StopDtmf();
636e1c44949Sopenharmony_ci    if (ret != TELEPHONY_SUCCESS) {
637e1c44949Sopenharmony_ci        TELEPHONY_LOGE("StopDtmf failed, return:%{public}d", ret);
638e1c44949Sopenharmony_ci    }
639e1c44949Sopenharmony_ci    DelayedSingleton<AudioControlManager>::GetInstance()->StopDtmfTone();
640e1c44949Sopenharmony_ci    return ret;
641e1c44949Sopenharmony_ci}
642e1c44949Sopenharmony_ci
643e1c44949Sopenharmony_ciint32_t CallControlManager::PostDialProceed(int32_t callId, bool proceed)
644e1c44949Sopenharmony_ci{
645e1c44949Sopenharmony_ci    sptr<CallBase> call = GetOneCallObject(callId);
646e1c44949Sopenharmony_ci    if (call == nullptr) {
647e1c44949Sopenharmony_ci        return TELEPHONY_ERR_ARGUMENT_INVALID;
648e1c44949Sopenharmony_ci    }
649e1c44949Sopenharmony_ci    if (!call->IsAliveState()) {
650e1c44949Sopenharmony_ci        return CALL_ERR_CALL_STATE_MISMATCH_OPERATION;
651e1c44949Sopenharmony_ci    }
652e1c44949Sopenharmony_ci
653e1c44949Sopenharmony_ci    int32_t ret = call->PostDialProceed(proceed);
654e1c44949Sopenharmony_ci    if (ret != TELEPHONY_SUCCESS) {
655e1c44949Sopenharmony_ci        TELEPHONY_LOGE("PostDialProceed failed, return:%{public}d", ret);
656e1c44949Sopenharmony_ci    }
657e1c44949Sopenharmony_ci    return ret;
658e1c44949Sopenharmony_ci}
659e1c44949Sopenharmony_ci
660e1c44949Sopenharmony_ciint32_t CallControlManager::GetCallWaiting(int32_t slotId)
661e1c44949Sopenharmony_ci{
662e1c44949Sopenharmony_ci    int32_t ret = CallPolicy::GetCallWaitingPolicy(slotId);
663e1c44949Sopenharmony_ci    if (ret != TELEPHONY_SUCCESS) {
664e1c44949Sopenharmony_ci        TELEPHONY_LOGE("GetCallWaiting failed!");
665e1c44949Sopenharmony_ci        return ret;
666e1c44949Sopenharmony_ci    }
667e1c44949Sopenharmony_ci    if (callSettingManagerPtr_ != nullptr) {
668e1c44949Sopenharmony_ci        return callSettingManagerPtr_->GetCallWaiting(slotId);
669e1c44949Sopenharmony_ci    } else {
670e1c44949Sopenharmony_ci        TELEPHONY_LOGE("callSettingManagerPtr_ is nullptr!");
671e1c44949Sopenharmony_ci        return TELEPHONY_ERR_LOCAL_PTR_NULL;
672e1c44949Sopenharmony_ci    }
673e1c44949Sopenharmony_ci}
674e1c44949Sopenharmony_ci
675e1c44949Sopenharmony_ciint32_t CallControlManager::SetCallWaiting(int32_t slotId, bool activate)
676e1c44949Sopenharmony_ci{
677e1c44949Sopenharmony_ci    int32_t ret = CallPolicy::SetCallWaitingPolicy(slotId);
678e1c44949Sopenharmony_ci    if (ret != TELEPHONY_SUCCESS) {
679e1c44949Sopenharmony_ci        TELEPHONY_LOGE("SetCallWaiting failed!");
680e1c44949Sopenharmony_ci        return ret;
681e1c44949Sopenharmony_ci    }
682e1c44949Sopenharmony_ci    if (callSettingManagerPtr_ != nullptr) {
683e1c44949Sopenharmony_ci        return callSettingManagerPtr_->SetCallWaiting(slotId, activate);
684e1c44949Sopenharmony_ci    } else {
685e1c44949Sopenharmony_ci        TELEPHONY_LOGE("callSettingManagerPtr_ is nullptr!");
686e1c44949Sopenharmony_ci        return TELEPHONY_ERR_LOCAL_PTR_NULL;
687e1c44949Sopenharmony_ci    }
688e1c44949Sopenharmony_ci}
689e1c44949Sopenharmony_ci
690e1c44949Sopenharmony_ciint32_t CallControlManager::GetCallRestriction(int32_t slotId, CallRestrictionType type)
691e1c44949Sopenharmony_ci{
692e1c44949Sopenharmony_ci    int32_t ret = CallPolicy::GetCallRestrictionPolicy(slotId);
693e1c44949Sopenharmony_ci    if (ret != TELEPHONY_SUCCESS) {
694e1c44949Sopenharmony_ci        TELEPHONY_LOGE("GetCallRestriction failed!");
695e1c44949Sopenharmony_ci        return ret;
696e1c44949Sopenharmony_ci    }
697e1c44949Sopenharmony_ci    if (callSettingManagerPtr_ != nullptr) {
698e1c44949Sopenharmony_ci        return callSettingManagerPtr_->GetCallRestriction(slotId, type);
699e1c44949Sopenharmony_ci    } else {
700e1c44949Sopenharmony_ci        TELEPHONY_LOGE("callSettingManagerPtr_ is nullptr!");
701e1c44949Sopenharmony_ci        return TELEPHONY_ERR_LOCAL_PTR_NULL;
702e1c44949Sopenharmony_ci    }
703e1c44949Sopenharmony_ci}
704e1c44949Sopenharmony_ci
705e1c44949Sopenharmony_ciint32_t CallControlManager::SetCallRestriction(int32_t slotId, CallRestrictionInfo &info)
706e1c44949Sopenharmony_ci{
707e1c44949Sopenharmony_ci    int32_t ret = CallPolicy::SetCallRestrictionPolicy(slotId);
708e1c44949Sopenharmony_ci    if (ret != TELEPHONY_SUCCESS) {
709e1c44949Sopenharmony_ci        TELEPHONY_LOGE("SetCallRestriction failed!");
710e1c44949Sopenharmony_ci        return ret;
711e1c44949Sopenharmony_ci    }
712e1c44949Sopenharmony_ci    if (callSettingManagerPtr_ != nullptr) {
713e1c44949Sopenharmony_ci        return callSettingManagerPtr_->SetCallRestriction(slotId, info);
714e1c44949Sopenharmony_ci    } else {
715e1c44949Sopenharmony_ci        TELEPHONY_LOGE("callSettingManagerPtr_ is nullptr!");
716e1c44949Sopenharmony_ci        return TELEPHONY_ERR_LOCAL_PTR_NULL;
717e1c44949Sopenharmony_ci    }
718e1c44949Sopenharmony_ci}
719e1c44949Sopenharmony_ci
720e1c44949Sopenharmony_ciint32_t CallControlManager::SetCallRestrictionPassword(
721e1c44949Sopenharmony_ci    int32_t slotId, CallRestrictionType fac, const char *oldPassword, const char *newPassword)
722e1c44949Sopenharmony_ci{
723e1c44949Sopenharmony_ci    int32_t ret = CallPolicy::SetCallRestrictionPolicy(slotId);
724e1c44949Sopenharmony_ci    if (ret != TELEPHONY_SUCCESS) {
725e1c44949Sopenharmony_ci        TELEPHONY_LOGE("policy check failed!");
726e1c44949Sopenharmony_ci        return ret;
727e1c44949Sopenharmony_ci    }
728e1c44949Sopenharmony_ci    if (callSettingManagerPtr_ != nullptr) {
729e1c44949Sopenharmony_ci        return callSettingManagerPtr_->SetCallRestrictionPassword(slotId, fac, oldPassword, newPassword);
730e1c44949Sopenharmony_ci    } else {
731e1c44949Sopenharmony_ci        TELEPHONY_LOGE("callSettingManagerPtr_ is nullptr!");
732e1c44949Sopenharmony_ci        return TELEPHONY_ERR_LOCAL_PTR_NULL;
733e1c44949Sopenharmony_ci    }
734e1c44949Sopenharmony_ci}
735e1c44949Sopenharmony_ci
736e1c44949Sopenharmony_ciint32_t CallControlManager::GetCallTransferInfo(int32_t slotId, CallTransferType type)
737e1c44949Sopenharmony_ci{
738e1c44949Sopenharmony_ci    int32_t ret = CallPolicy::GetCallTransferInfoPolicy(slotId);
739e1c44949Sopenharmony_ci    if (ret != TELEPHONY_SUCCESS) {
740e1c44949Sopenharmony_ci        TELEPHONY_LOGE("GetCallTransferInfo failed!");
741e1c44949Sopenharmony_ci        return ret;
742e1c44949Sopenharmony_ci    }
743e1c44949Sopenharmony_ci    if (callSettingManagerPtr_ != nullptr) {
744e1c44949Sopenharmony_ci        return callSettingManagerPtr_->GetCallTransferInfo(slotId, type);
745e1c44949Sopenharmony_ci    } else {
746e1c44949Sopenharmony_ci        TELEPHONY_LOGE("callSettingManagerPtr_ is nullptr!");
747e1c44949Sopenharmony_ci        return TELEPHONY_ERR_LOCAL_PTR_NULL;
748e1c44949Sopenharmony_ci    }
749e1c44949Sopenharmony_ci}
750e1c44949Sopenharmony_ci
751e1c44949Sopenharmony_ciint32_t CallControlManager::SetCallTransferInfo(int32_t slotId, CallTransferInfo &info)
752e1c44949Sopenharmony_ci{
753e1c44949Sopenharmony_ci    int32_t ret = CallPolicy::SetCallTransferInfoPolicy(slotId);
754e1c44949Sopenharmony_ci    if (ret != TELEPHONY_SUCCESS) {
755e1c44949Sopenharmony_ci        TELEPHONY_LOGE("SetCallTransferInfo failed!");
756e1c44949Sopenharmony_ci        return ret;
757e1c44949Sopenharmony_ci    }
758e1c44949Sopenharmony_ci    if (callSettingManagerPtr_ != nullptr) {
759e1c44949Sopenharmony_ci        return callSettingManagerPtr_->SetCallTransferInfo(slotId, info);
760e1c44949Sopenharmony_ci    } else {
761e1c44949Sopenharmony_ci        TELEPHONY_LOGE("callSettingManagerPtr_ is nullptr!");
762e1c44949Sopenharmony_ci        return TELEPHONY_ERR_LOCAL_PTR_NULL;
763e1c44949Sopenharmony_ci    }
764e1c44949Sopenharmony_ci}
765e1c44949Sopenharmony_ci
766e1c44949Sopenharmony_ciint32_t CallControlManager::CanSetCallTransferTime(int32_t slotId, bool &result)
767e1c44949Sopenharmony_ci{
768e1c44949Sopenharmony_ci    int32_t ret = CallPolicy::SetCallTransferInfoPolicy(slotId);
769e1c44949Sopenharmony_ci    if (ret != TELEPHONY_SUCCESS) {
770e1c44949Sopenharmony_ci        TELEPHONY_LOGE("[slot%{public}d] failed!", slotId);
771e1c44949Sopenharmony_ci        return ret;
772e1c44949Sopenharmony_ci    }
773e1c44949Sopenharmony_ci    if (callSettingManagerPtr_ != nullptr) {
774e1c44949Sopenharmony_ci        return callSettingManagerPtr_->CanSetCallTransferTime(slotId, result);
775e1c44949Sopenharmony_ci    } else {
776e1c44949Sopenharmony_ci        TELEPHONY_LOGE("[slot%{public}d]  callSettingManagerPtr_ is nullptr!", slotId);
777e1c44949Sopenharmony_ci        return TELEPHONY_ERR_LOCAL_PTR_NULL;
778e1c44949Sopenharmony_ci    }
779e1c44949Sopenharmony_ci}
780e1c44949Sopenharmony_ci
781e1c44949Sopenharmony_ciint32_t CallControlManager::SetCallPreferenceMode(int32_t slotId, int32_t mode)
782e1c44949Sopenharmony_ci{
783e1c44949Sopenharmony_ci    int32_t ret = CallPolicy::SetCallPreferenceModePolicy(slotId);
784e1c44949Sopenharmony_ci    if (ret != TELEPHONY_SUCCESS) {
785e1c44949Sopenharmony_ci        TELEPHONY_LOGE("SetCallPreferenceMode failed!");
786e1c44949Sopenharmony_ci        return ret;
787e1c44949Sopenharmony_ci    }
788e1c44949Sopenharmony_ci    if (callSettingManagerPtr_ != nullptr) {
789e1c44949Sopenharmony_ci        return callSettingManagerPtr_->SetCallPreferenceMode(slotId, mode);
790e1c44949Sopenharmony_ci    } else {
791e1c44949Sopenharmony_ci        TELEPHONY_LOGE("callSettingManagerPtr_ is nullptr!");
792e1c44949Sopenharmony_ci        return TELEPHONY_ERR_LOCAL_PTR_NULL;
793e1c44949Sopenharmony_ci    }
794e1c44949Sopenharmony_ci}
795e1c44949Sopenharmony_ci
796e1c44949Sopenharmony_ci/**
797e1c44949Sopenharmony_ci * start a telephone conference by merging three-way calls,steps as follows:
798e1c44949Sopenharmony_ci * 1.A call B: A<---->B,set holding
799e1c44949Sopenharmony_ci * 2.A call C: A<---->C, active
800e1c44949Sopenharmony_ci * 3.A initial merge request by CombineConference
801e1c44949Sopenharmony_ci * @param mainCallId:active call id
802e1c44949Sopenharmony_ci */
803e1c44949Sopenharmony_ciint32_t CallControlManager::CombineConference(int32_t mainCallId)
804e1c44949Sopenharmony_ci{
805e1c44949Sopenharmony_ci    sptr<CallBase> mainCall = GetOneCallObject(mainCallId);
806e1c44949Sopenharmony_ci    if (mainCall == nullptr) {
807e1c44949Sopenharmony_ci        TELEPHONY_LOGE("GetOneCallObject failed, mainCallId:%{public}d", mainCallId);
808e1c44949Sopenharmony_ci        return TELEPHONY_ERR_ARGUMENT_INVALID;
809e1c44949Sopenharmony_ci    }
810e1c44949Sopenharmony_ci    if (mainCall->GetTelCallState() != TelCallState::CALL_STATUS_ACTIVE) {
811e1c44949Sopenharmony_ci        TELEPHONY_LOGE("mainCall state should be active ");
812e1c44949Sopenharmony_ci        return CALL_ERR_CALL_STATE_MISMATCH_OPERATION;
813e1c44949Sopenharmony_ci    }
814e1c44949Sopenharmony_ci    if (!CallObjectManager::IsCallExist(mainCall->GetCallType(), TelCallState::CALL_STATUS_HOLDING)) {
815e1c44949Sopenharmony_ci        TELEPHONY_LOGE("callType:%{public}d,callState:CALL_STATUS_HOLDING is not exist!", mainCall->GetCallType());
816e1c44949Sopenharmony_ci        return CALL_ERR_CALL_STATE_MISMATCH_OPERATION;
817e1c44949Sopenharmony_ci    }
818e1c44949Sopenharmony_ci    int32_t ret = mainCall->CanCombineConference();
819e1c44949Sopenharmony_ci    if (ret != TELEPHONY_SUCCESS) {
820e1c44949Sopenharmony_ci        TELEPHONY_LOGE("CanCombineConference failed");
821e1c44949Sopenharmony_ci        return ret;
822e1c44949Sopenharmony_ci    }
823e1c44949Sopenharmony_ci    if (CallRequestHandlerPtr_ == nullptr) {
824e1c44949Sopenharmony_ci        TELEPHONY_LOGE("CallRequestHandlerPtr_ is nullptr!");
825e1c44949Sopenharmony_ci        return TELEPHONY_ERR_LOCAL_PTR_NULL;
826e1c44949Sopenharmony_ci    }
827e1c44949Sopenharmony_ci    ret = CallRequestHandlerPtr_->CombineConference(mainCallId);
828e1c44949Sopenharmony_ci    if (ret != TELEPHONY_SUCCESS) {
829e1c44949Sopenharmony_ci        TELEPHONY_LOGE("CombineConference failed!");
830e1c44949Sopenharmony_ci    }
831e1c44949Sopenharmony_ci    return ret;
832e1c44949Sopenharmony_ci}
833e1c44949Sopenharmony_ci
834e1c44949Sopenharmony_ciint32_t CallControlManager::SeparateConference(int32_t callId)
835e1c44949Sopenharmony_ci{
836e1c44949Sopenharmony_ci    sptr<CallBase> call = GetOneCallObject(callId);
837e1c44949Sopenharmony_ci    if (call == nullptr) {
838e1c44949Sopenharmony_ci        TELEPHONY_LOGE("GetOneCallObject failed, callId:%{public}d", callId);
839e1c44949Sopenharmony_ci        return TELEPHONY_ERR_ARGUMENT_INVALID;
840e1c44949Sopenharmony_ci    }
841e1c44949Sopenharmony_ci    int32_t ret = call->CanSeparateConference();
842e1c44949Sopenharmony_ci    if (ret != TELEPHONY_SUCCESS) {
843e1c44949Sopenharmony_ci        TELEPHONY_LOGE("CanSeparateConference failed");
844e1c44949Sopenharmony_ci        return ret;
845e1c44949Sopenharmony_ci    }
846e1c44949Sopenharmony_ci    if (CallRequestHandlerPtr_ == nullptr) {
847e1c44949Sopenharmony_ci        TELEPHONY_LOGE("CallRequestHandlerPtr_ is nullptr!");
848e1c44949Sopenharmony_ci        return TELEPHONY_ERR_LOCAL_PTR_NULL;
849e1c44949Sopenharmony_ci    }
850e1c44949Sopenharmony_ci    ret = CallRequestHandlerPtr_->SeparateConference(callId);
851e1c44949Sopenharmony_ci    if (ret != TELEPHONY_SUCCESS) {
852e1c44949Sopenharmony_ci        TELEPHONY_LOGE("SeparateConference failed!");
853e1c44949Sopenharmony_ci        return ret;
854e1c44949Sopenharmony_ci    }
855e1c44949Sopenharmony_ci    return TELEPHONY_SUCCESS;
856e1c44949Sopenharmony_ci}
857e1c44949Sopenharmony_ci
858e1c44949Sopenharmony_ciint32_t CallControlManager::KickOutFromConference(int32_t callId)
859e1c44949Sopenharmony_ci{
860e1c44949Sopenharmony_ci    sptr<CallBase> call = GetOneCallObject(callId);
861e1c44949Sopenharmony_ci    if (call == nullptr) {
862e1c44949Sopenharmony_ci        TELEPHONY_LOGE("GetOneCallObject failed, callId:%{public}d", callId);
863e1c44949Sopenharmony_ci        return TELEPHONY_ERR_ARGUMENT_INVALID;
864e1c44949Sopenharmony_ci    }
865e1c44949Sopenharmony_ci    int32_t ret = call->CanKickOutFromConference();
866e1c44949Sopenharmony_ci    if (ret != TELEPHONY_SUCCESS) {
867e1c44949Sopenharmony_ci        TELEPHONY_LOGE("CanKickOutFromConference failed");
868e1c44949Sopenharmony_ci        return ret;
869e1c44949Sopenharmony_ci    }
870e1c44949Sopenharmony_ci    if (CallRequestHandlerPtr_ == nullptr) {
871e1c44949Sopenharmony_ci        TELEPHONY_LOGE("CallRequestHandlerPtr_ is nullptr!");
872e1c44949Sopenharmony_ci        return TELEPHONY_ERR_LOCAL_PTR_NULL;
873e1c44949Sopenharmony_ci    }
874e1c44949Sopenharmony_ci    ret = CallRequestHandlerPtr_->KickOutFromConference(callId);
875e1c44949Sopenharmony_ci    if (ret != TELEPHONY_SUCCESS) {
876e1c44949Sopenharmony_ci        TELEPHONY_LOGE("KickOutFromConference failed!");
877e1c44949Sopenharmony_ci        return ret;
878e1c44949Sopenharmony_ci    }
879e1c44949Sopenharmony_ci    return TELEPHONY_SUCCESS;
880e1c44949Sopenharmony_ci}
881e1c44949Sopenharmony_ci
882e1c44949Sopenharmony_ciint32_t CallControlManager::GetMainCallId(int32_t callId, int32_t &mainCallId)
883e1c44949Sopenharmony_ci{
884e1c44949Sopenharmony_ci    sptr<CallBase> call = GetOneCallObject(callId);
885e1c44949Sopenharmony_ci    if (call == nullptr) {
886e1c44949Sopenharmony_ci        TELEPHONY_LOGE("GetMainCallId failed! callId:%{public}d", callId);
887e1c44949Sopenharmony_ci        return TELEPHONY_ERR_ARGUMENT_INVALID;
888e1c44949Sopenharmony_ci    }
889e1c44949Sopenharmony_ci    return call->GetMainCallId(mainCallId);
890e1c44949Sopenharmony_ci}
891e1c44949Sopenharmony_ci
892e1c44949Sopenharmony_ciint32_t CallControlManager::GetSubCallIdList(int32_t callId, std::vector<std::u16string> &callIdList)
893e1c44949Sopenharmony_ci{
894e1c44949Sopenharmony_ci    sptr<CallBase> call = GetOneCallObject(callId);
895e1c44949Sopenharmony_ci    if (call == nullptr) {
896e1c44949Sopenharmony_ci        TELEPHONY_LOGE("GetSubCallIdList failed! callId:%{public}d", callId);
897e1c44949Sopenharmony_ci        return TELEPHONY_ERR_ARGUMENT_INVALID;
898e1c44949Sopenharmony_ci    }
899e1c44949Sopenharmony_ci    return call->GetSubCallIdList(callIdList);
900e1c44949Sopenharmony_ci}
901e1c44949Sopenharmony_ci
902e1c44949Sopenharmony_ciint32_t CallControlManager::GetCallIdListForConference(int32_t callId, std::vector<std::u16string> &callIdList)
903e1c44949Sopenharmony_ci{
904e1c44949Sopenharmony_ci    sptr<CallBase> call = GetOneCallObject(callId);
905e1c44949Sopenharmony_ci    if (call == nullptr) {
906e1c44949Sopenharmony_ci        TELEPHONY_LOGE("GetCallIdListForConference failed! callId:%{public}d", callId);
907e1c44949Sopenharmony_ci        return TELEPHONY_ERR_ARGUMENT_INVALID;
908e1c44949Sopenharmony_ci    }
909e1c44949Sopenharmony_ci    return call->GetCallIdListForConference(callIdList);
910e1c44949Sopenharmony_ci}
911e1c44949Sopenharmony_ci
912e1c44949Sopenharmony_ciint32_t CallControlManager::GetImsConfig(int32_t slotId, ImsConfigItem item)
913e1c44949Sopenharmony_ci{
914e1c44949Sopenharmony_ci    int32_t ret = CallPolicy::GetImsConfigPolicy(slotId);
915e1c44949Sopenharmony_ci    if (ret != TELEPHONY_SUCCESS) {
916e1c44949Sopenharmony_ci        TELEPHONY_LOGE("GetImsConfig failed!");
917e1c44949Sopenharmony_ci        return ret;
918e1c44949Sopenharmony_ci    }
919e1c44949Sopenharmony_ci    if (callSettingManagerPtr_ != nullptr) {
920e1c44949Sopenharmony_ci        return callSettingManagerPtr_->GetImsConfig(slotId, item);
921e1c44949Sopenharmony_ci    } else {
922e1c44949Sopenharmony_ci        TELEPHONY_LOGE("callSettingManagerPtr_ is nullptr!");
923e1c44949Sopenharmony_ci        return TELEPHONY_ERR_LOCAL_PTR_NULL;
924e1c44949Sopenharmony_ci    }
925e1c44949Sopenharmony_ci}
926e1c44949Sopenharmony_ci
927e1c44949Sopenharmony_ciint32_t CallControlManager::SetImsConfig(int32_t slotId, ImsConfigItem item, std::u16string &value)
928e1c44949Sopenharmony_ci{
929e1c44949Sopenharmony_ci    int32_t ret = CallPolicy::SetImsConfigPolicy(slotId);
930e1c44949Sopenharmony_ci    if (ret != TELEPHONY_SUCCESS) {
931e1c44949Sopenharmony_ci        TELEPHONY_LOGE("SetImsConfig failed!");
932e1c44949Sopenharmony_ci        return ret;
933e1c44949Sopenharmony_ci    }
934e1c44949Sopenharmony_ci    if (callSettingManagerPtr_ != nullptr) {
935e1c44949Sopenharmony_ci        return callSettingManagerPtr_->SetImsConfig(slotId, item, value);
936e1c44949Sopenharmony_ci    } else {
937e1c44949Sopenharmony_ci        TELEPHONY_LOGE("callSettingManagerPtr_ is nullptr!");
938e1c44949Sopenharmony_ci        return TELEPHONY_ERR_LOCAL_PTR_NULL;
939e1c44949Sopenharmony_ci    }
940e1c44949Sopenharmony_ci}
941e1c44949Sopenharmony_ci
942e1c44949Sopenharmony_ciint32_t CallControlManager::GetImsFeatureValue(int32_t slotId, FeatureType type)
943e1c44949Sopenharmony_ci{
944e1c44949Sopenharmony_ci    int32_t ret = CallPolicy::GetImsFeatureValuePolicy(slotId);
945e1c44949Sopenharmony_ci    if (ret != TELEPHONY_SUCCESS) {
946e1c44949Sopenharmony_ci        TELEPHONY_LOGE("GetImsFeatureValue failed!");
947e1c44949Sopenharmony_ci        return ret;
948e1c44949Sopenharmony_ci    }
949e1c44949Sopenharmony_ci    if (callSettingManagerPtr_ != nullptr) {
950e1c44949Sopenharmony_ci        return callSettingManagerPtr_->GetImsFeatureValue(slotId, type);
951e1c44949Sopenharmony_ci    } else {
952e1c44949Sopenharmony_ci        TELEPHONY_LOGE("callSettingManagerPtr_ is nullptr!");
953e1c44949Sopenharmony_ci        return TELEPHONY_ERR_LOCAL_PTR_NULL;
954e1c44949Sopenharmony_ci    }
955e1c44949Sopenharmony_ci}
956e1c44949Sopenharmony_ci
957e1c44949Sopenharmony_ciint32_t CallControlManager::SetImsFeatureValue(int32_t slotId, FeatureType type, int32_t value)
958e1c44949Sopenharmony_ci{
959e1c44949Sopenharmony_ci    int32_t ret = CallPolicy::SetImsFeatureValuePolicy(slotId);
960e1c44949Sopenharmony_ci    if (ret != TELEPHONY_SUCCESS) {
961e1c44949Sopenharmony_ci        TELEPHONY_LOGE("SetImsFeatureValue failed!");
962e1c44949Sopenharmony_ci        return ret;
963e1c44949Sopenharmony_ci    }
964e1c44949Sopenharmony_ci    if (callSettingManagerPtr_ != nullptr) {
965e1c44949Sopenharmony_ci        return callSettingManagerPtr_->SetImsFeatureValue(slotId, type, value);
966e1c44949Sopenharmony_ci    } else {
967e1c44949Sopenharmony_ci        TELEPHONY_LOGE("callSettingManagerPtr_ is nullptr!");
968e1c44949Sopenharmony_ci        return TELEPHONY_ERR_LOCAL_PTR_NULL;
969e1c44949Sopenharmony_ci    }
970e1c44949Sopenharmony_ci}
971e1c44949Sopenharmony_ci
972e1c44949Sopenharmony_ciint32_t CallControlManager::EnableImsSwitch(int32_t slotId)
973e1c44949Sopenharmony_ci{
974e1c44949Sopenharmony_ci    int32_t ret = CallPolicy::EnableVoLtePolicy(slotId);
975e1c44949Sopenharmony_ci    if (ret != TELEPHONY_SUCCESS) {
976e1c44949Sopenharmony_ci        TELEPHONY_LOGE("EnableImsSwitch failed!");
977e1c44949Sopenharmony_ci        return ret;
978e1c44949Sopenharmony_ci    }
979e1c44949Sopenharmony_ci    if (callSettingManagerPtr_ != nullptr) {
980e1c44949Sopenharmony_ci        return callSettingManagerPtr_->EnableImsSwitch(slotId);
981e1c44949Sopenharmony_ci    } else {
982e1c44949Sopenharmony_ci        TELEPHONY_LOGE("callSettingManagerPtr_ is nullptr!");
983e1c44949Sopenharmony_ci        return TELEPHONY_ERR_LOCAL_PTR_NULL;
984e1c44949Sopenharmony_ci    }
985e1c44949Sopenharmony_ci}
986e1c44949Sopenharmony_ci
987e1c44949Sopenharmony_ciint32_t CallControlManager::DisableImsSwitch(int32_t slotId)
988e1c44949Sopenharmony_ci{
989e1c44949Sopenharmony_ci    int32_t ret = CallPolicy::DisableVoLtePolicy(slotId);
990e1c44949Sopenharmony_ci    if (ret != TELEPHONY_SUCCESS) {
991e1c44949Sopenharmony_ci        TELEPHONY_LOGE("DisableImsSwitch failed!");
992e1c44949Sopenharmony_ci        return ret;
993e1c44949Sopenharmony_ci    }
994e1c44949Sopenharmony_ci    if (callSettingManagerPtr_ != nullptr) {
995e1c44949Sopenharmony_ci        return callSettingManagerPtr_->DisableImsSwitch(slotId);
996e1c44949Sopenharmony_ci    } else {
997e1c44949Sopenharmony_ci        TELEPHONY_LOGE("callSettingManagerPtr_ is nullptr!");
998e1c44949Sopenharmony_ci        return TELEPHONY_ERR_LOCAL_PTR_NULL;
999e1c44949Sopenharmony_ci    }
1000e1c44949Sopenharmony_ci}
1001e1c44949Sopenharmony_ci
1002e1c44949Sopenharmony_ciint32_t CallControlManager::IsImsSwitchEnabled(int32_t slotId, bool &enabled)
1003e1c44949Sopenharmony_ci{
1004e1c44949Sopenharmony_ci    int32_t ret = CallPolicy::IsVoLteEnabledPolicy(slotId);
1005e1c44949Sopenharmony_ci    if (ret != TELEPHONY_SUCCESS) {
1006e1c44949Sopenharmony_ci        TELEPHONY_LOGE("IsImsSwitchEnabled failed!");
1007e1c44949Sopenharmony_ci        return ret;
1008e1c44949Sopenharmony_ci    }
1009e1c44949Sopenharmony_ci    if (callSettingManagerPtr_ != nullptr) {
1010e1c44949Sopenharmony_ci        return callSettingManagerPtr_->IsImsSwitchEnabled(slotId, enabled);
1011e1c44949Sopenharmony_ci    } else {
1012e1c44949Sopenharmony_ci        TELEPHONY_LOGE("callSettingManagerPtr_ is nullptr!");
1013e1c44949Sopenharmony_ci        return TELEPHONY_ERR_LOCAL_PTR_NULL;
1014e1c44949Sopenharmony_ci    }
1015e1c44949Sopenharmony_ci}
1016e1c44949Sopenharmony_ci
1017e1c44949Sopenharmony_ciint32_t CallControlManager::SetVoNRState(int32_t slotId, int32_t state)
1018e1c44949Sopenharmony_ci{
1019e1c44949Sopenharmony_ci    int32_t ret = CallPolicy::VoNRStatePolicy(slotId, state);
1020e1c44949Sopenharmony_ci    if (ret != TELEPHONY_SUCCESS) {
1021e1c44949Sopenharmony_ci        TELEPHONY_LOGE("SetVoNRState failed!");
1022e1c44949Sopenharmony_ci        return ret;
1023e1c44949Sopenharmony_ci    }
1024e1c44949Sopenharmony_ci    if (callSettingManagerPtr_ != nullptr) {
1025e1c44949Sopenharmony_ci        return callSettingManagerPtr_->SetVoNRState(slotId, state);
1026e1c44949Sopenharmony_ci    } else {
1027e1c44949Sopenharmony_ci        TELEPHONY_LOGE("callSettingManagerPtr_ is nullptr!");
1028e1c44949Sopenharmony_ci        return TELEPHONY_ERR_LOCAL_PTR_NULL;
1029e1c44949Sopenharmony_ci    }
1030e1c44949Sopenharmony_ci}
1031e1c44949Sopenharmony_ci
1032e1c44949Sopenharmony_ciint32_t CallControlManager::GetVoNRState(int32_t slotId, int32_t &state)
1033e1c44949Sopenharmony_ci{
1034e1c44949Sopenharmony_ci    int32_t ret = CallPolicy::IsValidSlotId(slotId);
1035e1c44949Sopenharmony_ci    if (ret != TELEPHONY_SUCCESS) {
1036e1c44949Sopenharmony_ci        TELEPHONY_LOGE("SetVoNRState failed!");
1037e1c44949Sopenharmony_ci        return ret;
1038e1c44949Sopenharmony_ci    }
1039e1c44949Sopenharmony_ci    if (callSettingManagerPtr_ != nullptr) {
1040e1c44949Sopenharmony_ci        ret = callSettingManagerPtr_->GetVoNRState(slotId, state);
1041e1c44949Sopenharmony_ci        if (ret == TELEPHONY_SUCCESS) {
1042e1c44949Sopenharmony_ci            ret = CallPolicy::VoNRStatePolicy(slotId, state);
1043e1c44949Sopenharmony_ci        }
1044e1c44949Sopenharmony_ci        return ret;
1045e1c44949Sopenharmony_ci    } else {
1046e1c44949Sopenharmony_ci        TELEPHONY_LOGE("callSettingManagerPtr_ is nullptr!");
1047e1c44949Sopenharmony_ci        return TELEPHONY_ERR_LOCAL_PTR_NULL;
1048e1c44949Sopenharmony_ci    }
1049e1c44949Sopenharmony_ci}
1050e1c44949Sopenharmony_ci
1051e1c44949Sopenharmony_ciint32_t CallControlManager::UpdateImsCallMode(int32_t callId, ImsCallMode mode)
1052e1c44949Sopenharmony_ci{
1053e1c44949Sopenharmony_ci    return TELEPHONY_SUCCESS;
1054e1c44949Sopenharmony_ci}
1055e1c44949Sopenharmony_ci
1056e1c44949Sopenharmony_ciint32_t CallControlManager::StartRtt(int32_t callId, std::u16string &msg)
1057e1c44949Sopenharmony_ci{
1058e1c44949Sopenharmony_ci    int32_t ret = CallPolicy::StartRttPolicy(callId);
1059e1c44949Sopenharmony_ci    if (ret != TELEPHONY_SUCCESS) {
1060e1c44949Sopenharmony_ci        TELEPHONY_LOGE("NO IMS call,can not StartRtt!");
1061e1c44949Sopenharmony_ci        return ret;
1062e1c44949Sopenharmony_ci    }
1063e1c44949Sopenharmony_ci    if (CallRequestHandlerPtr_ == nullptr) {
1064e1c44949Sopenharmony_ci        TELEPHONY_LOGE("CallRequestHandlerPtr_ is nullptr!");
1065e1c44949Sopenharmony_ci        return TELEPHONY_ERR_LOCAL_PTR_NULL;
1066e1c44949Sopenharmony_ci    }
1067e1c44949Sopenharmony_ci    ret = CallRequestHandlerPtr_->StartRtt(callId, msg);
1068e1c44949Sopenharmony_ci    if (ret != TELEPHONY_SUCCESS) {
1069e1c44949Sopenharmony_ci        TELEPHONY_LOGE("StartRtt failed!");
1070e1c44949Sopenharmony_ci        return ret;
1071e1c44949Sopenharmony_ci    }
1072e1c44949Sopenharmony_ci    return TELEPHONY_SUCCESS;
1073e1c44949Sopenharmony_ci}
1074e1c44949Sopenharmony_ci
1075e1c44949Sopenharmony_ciint32_t CallControlManager::StopRtt(int32_t callId)
1076e1c44949Sopenharmony_ci{
1077e1c44949Sopenharmony_ci    int32_t ret = CallPolicy::StopRttPolicy(callId);
1078e1c44949Sopenharmony_ci    if (ret != TELEPHONY_SUCCESS) {
1079e1c44949Sopenharmony_ci        TELEPHONY_LOGE("NO IMS call,no need StopRtt!");
1080e1c44949Sopenharmony_ci        return ret;
1081e1c44949Sopenharmony_ci    }
1082e1c44949Sopenharmony_ci    if (CallRequestHandlerPtr_ == nullptr) {
1083e1c44949Sopenharmony_ci        TELEPHONY_LOGE("CallRequestHandlerPtr_ is nullptr!");
1084e1c44949Sopenharmony_ci        return TELEPHONY_ERR_LOCAL_PTR_NULL;
1085e1c44949Sopenharmony_ci    }
1086e1c44949Sopenharmony_ci    ret = CallRequestHandlerPtr_->StopRtt(callId);
1087e1c44949Sopenharmony_ci    if (ret != TELEPHONY_SUCCESS) {
1088e1c44949Sopenharmony_ci        TELEPHONY_LOGE("StopRtt failed!");
1089e1c44949Sopenharmony_ci        return ret;
1090e1c44949Sopenharmony_ci    }
1091e1c44949Sopenharmony_ci    return TELEPHONY_SUCCESS;
1092e1c44949Sopenharmony_ci}
1093e1c44949Sopenharmony_ci
1094e1c44949Sopenharmony_ciint32_t CallControlManager::JoinConference(int32_t callId, std::vector<std::u16string> &numberList)
1095e1c44949Sopenharmony_ci{
1096e1c44949Sopenharmony_ci    if (CallRequestHandlerPtr_ == nullptr) {
1097e1c44949Sopenharmony_ci        TELEPHONY_LOGE("CallRequestHandlerPtr_ is nullptr!");
1098e1c44949Sopenharmony_ci        return TELEPHONY_ERR_LOCAL_PTR_NULL;
1099e1c44949Sopenharmony_ci    }
1100e1c44949Sopenharmony_ci    std::vector<std::string> phoneNumberList(numberList.size());
1101e1c44949Sopenharmony_ci    for (size_t index = 0; index < numberList.size(); ++index) {
1102e1c44949Sopenharmony_ci        phoneNumberList[index] = Str16ToStr8(numberList[index]);
1103e1c44949Sopenharmony_ci    }
1104e1c44949Sopenharmony_ci    int32_t ret = CallPolicy::InviteToConferencePolicy(callId, phoneNumberList);
1105e1c44949Sopenharmony_ci    if (ret != TELEPHONY_SUCCESS) {
1106e1c44949Sopenharmony_ci        TELEPHONY_LOGE("check InviteToConference Policy failed!");
1107e1c44949Sopenharmony_ci        return ret;
1108e1c44949Sopenharmony_ci    }
1109e1c44949Sopenharmony_ci    ret = CallRequestHandlerPtr_->JoinConference(callId, phoneNumberList);
1110e1c44949Sopenharmony_ci    if (ret != TELEPHONY_SUCCESS) {
1111e1c44949Sopenharmony_ci        TELEPHONY_LOGE("JoinConference failed!");
1112e1c44949Sopenharmony_ci        return ret;
1113e1c44949Sopenharmony_ci    }
1114e1c44949Sopenharmony_ci    return TELEPHONY_SUCCESS;
1115e1c44949Sopenharmony_ci}
1116e1c44949Sopenharmony_ci
1117e1c44949Sopenharmony_ciint32_t CallControlManager::SetMuted(bool isMute)
1118e1c44949Sopenharmony_ci{
1119e1c44949Sopenharmony_ci    sptr<CallBase> call = CallObjectManager::GetForegroundLiveCall();
1120e1c44949Sopenharmony_ci    if (call == nullptr) {
1121e1c44949Sopenharmony_ci        return CALL_ERR_AUDIO_SETTING_MUTE_FAILED;
1122e1c44949Sopenharmony_ci    }
1123e1c44949Sopenharmony_ci
1124e1c44949Sopenharmony_ci    if (call->GetCallType() == CallType::TYPE_VOIP) {
1125e1c44949Sopenharmony_ci        TELEPHONY_LOGI("SetMute by voip");
1126e1c44949Sopenharmony_ci        return call->SetMute(isMute, call->GetSlotId());
1127e1c44949Sopenharmony_ci    }
1128e1c44949Sopenharmony_ci    if (call->GetCallType() == CallType::TYPE_IMS
1129e1c44949Sopenharmony_ci        || call->GetCallType() == CallType::TYPE_CS) {
1130e1c44949Sopenharmony_ci        TELEPHONY_LOGI("SetMute by ims or cs,isMute = %{public}d", isMute);
1131e1c44949Sopenharmony_ci        call->SetMute(isMute, call->GetSlotId());
1132e1c44949Sopenharmony_ci    }
1133e1c44949Sopenharmony_ci
1134e1c44949Sopenharmony_ci    return DelayedSingleton<AudioControlManager>::GetInstance()->SetMute(isMute);
1135e1c44949Sopenharmony_ci}
1136e1c44949Sopenharmony_ci
1137e1c44949Sopenharmony_ciint32_t CallControlManager::MuteRinger()
1138e1c44949Sopenharmony_ci{
1139e1c44949Sopenharmony_ci    CallVoiceAssistantManager::GetInstance()->MuteRinger();
1140e1c44949Sopenharmony_ci    return DelayedSingleton<AudioControlManager>::GetInstance()->MuteRinger();
1141e1c44949Sopenharmony_ci}
1142e1c44949Sopenharmony_ci
1143e1c44949Sopenharmony_ciint32_t CallControlManager::SetAudioDevice(const AudioDevice &audioDevice)
1144e1c44949Sopenharmony_ci{
1145e1c44949Sopenharmony_ci    return DelayedSingleton<AudioControlManager>::GetInstance()->SetAudioDevice(audioDevice, true);
1146e1c44949Sopenharmony_ci}
1147e1c44949Sopenharmony_ci
1148e1c44949Sopenharmony_ciint32_t CallControlManager::ControlCamera(std::u16string cameraId, int32_t callingUid, int32_t callingPid)
1149e1c44949Sopenharmony_ci{
1150e1c44949Sopenharmony_ci    return TELEPHONY_SUCCESS;
1151e1c44949Sopenharmony_ci}
1152e1c44949Sopenharmony_ci
1153e1c44949Sopenharmony_ciint32_t CallControlManager::SetPreviewWindow(VideoWindow &window)
1154e1c44949Sopenharmony_ci{
1155e1c44949Sopenharmony_ci    return TELEPHONY_SUCCESS;
1156e1c44949Sopenharmony_ci}
1157e1c44949Sopenharmony_ci
1158e1c44949Sopenharmony_ciint32_t CallControlManager::SetDisplayWindow(VideoWindow &window)
1159e1c44949Sopenharmony_ci{
1160e1c44949Sopenharmony_ci    return TELEPHONY_SUCCESS;
1161e1c44949Sopenharmony_ci}
1162e1c44949Sopenharmony_ci
1163e1c44949Sopenharmony_ciint32_t CallControlManager::SetCameraZoom(float zoomRatio)
1164e1c44949Sopenharmony_ci{
1165e1c44949Sopenharmony_ci    return TELEPHONY_SUCCESS;
1166e1c44949Sopenharmony_ci}
1167e1c44949Sopenharmony_ci
1168e1c44949Sopenharmony_ciint32_t CallControlManager::SetPausePicture(std::u16string path)
1169e1c44949Sopenharmony_ci{
1170e1c44949Sopenharmony_ci    return TELEPHONY_SUCCESS;
1171e1c44949Sopenharmony_ci}
1172e1c44949Sopenharmony_ci
1173e1c44949Sopenharmony_ciint32_t CallControlManager::SetDeviceDirection(int32_t rotation)
1174e1c44949Sopenharmony_ci{
1175e1c44949Sopenharmony_ci    return TELEPHONY_SUCCESS;
1176e1c44949Sopenharmony_ci}
1177e1c44949Sopenharmony_ci
1178e1c44949Sopenharmony_ciint32_t CallControlManager::IsEmergencyPhoneNumber(std::u16string &number, int32_t slotId, bool &enabled)
1179e1c44949Sopenharmony_ci{
1180e1c44949Sopenharmony_ci    if (IsValidSlotId(slotId)) {
1181e1c44949Sopenharmony_ci        return CALL_ERR_INVALID_SLOT_ID;
1182e1c44949Sopenharmony_ci    }
1183e1c44949Sopenharmony_ci    return DelayedSingleton<CallNumberUtils>::GetInstance()->CheckNumberIsEmergency(
1184e1c44949Sopenharmony_ci        Str16ToStr8(number), slotId, enabled);
1185e1c44949Sopenharmony_ci}
1186e1c44949Sopenharmony_ci
1187e1c44949Sopenharmony_ciint32_t CallControlManager::FormatPhoneNumber(
1188e1c44949Sopenharmony_ci    std::u16string &number, std::u16string &countryCode, std::u16string &formatNumber)
1189e1c44949Sopenharmony_ci{
1190e1c44949Sopenharmony_ci    std::string tmpStr("");
1191e1c44949Sopenharmony_ci    int32_t ret = DelayedSingleton<CallNumberUtils>::GetInstance()->FormatPhoneNumber(
1192e1c44949Sopenharmony_ci        Str16ToStr8(number), Str16ToStr8(countryCode), tmpStr);
1193e1c44949Sopenharmony_ci    formatNumber = Str8ToStr16(tmpStr);
1194e1c44949Sopenharmony_ci    return ret;
1195e1c44949Sopenharmony_ci}
1196e1c44949Sopenharmony_ci
1197e1c44949Sopenharmony_ciint32_t CallControlManager::FormatPhoneNumberToE164(
1198e1c44949Sopenharmony_ci    std::u16string &number, std::u16string &countryCode, std::u16string &formatNumber)
1199e1c44949Sopenharmony_ci{
1200e1c44949Sopenharmony_ci    std::string tmpStr("");
1201e1c44949Sopenharmony_ci    int32_t ret = DelayedSingleton<CallNumberUtils>::GetInstance()->FormatPhoneNumberToE164(
1202e1c44949Sopenharmony_ci        Str16ToStr8(number), Str16ToStr8(countryCode), tmpStr);
1203e1c44949Sopenharmony_ci    formatNumber = Str8ToStr16(tmpStr);
1204e1c44949Sopenharmony_ci    return ret;
1205e1c44949Sopenharmony_ci}
1206e1c44949Sopenharmony_ci
1207e1c44949Sopenharmony_ciint32_t CallControlManager::CloseUnFinishedUssd(int32_t slotId)
1208e1c44949Sopenharmony_ci{
1209e1c44949Sopenharmony_ci    int32_t ret = CallPolicy::CloseUnFinishedUssdPolicy(slotId);
1210e1c44949Sopenharmony_ci    if (ret != TELEPHONY_SUCCESS) {
1211e1c44949Sopenharmony_ci        TELEPHONY_LOGE("CloseUnFinishedUssd failed!");
1212e1c44949Sopenharmony_ci        return ret;
1213e1c44949Sopenharmony_ci    }
1214e1c44949Sopenharmony_ci    if (callSettingManagerPtr_ != nullptr) {
1215e1c44949Sopenharmony_ci        return callSettingManagerPtr_->CloseUnFinishedUssd(slotId);
1216e1c44949Sopenharmony_ci    } else {
1217e1c44949Sopenharmony_ci        TELEPHONY_LOGE("callSettingManagerPtr_ is nullptr!");
1218e1c44949Sopenharmony_ci        return TELEPHONY_ERR_LOCAL_PTR_NULL;
1219e1c44949Sopenharmony_ci    }
1220e1c44949Sopenharmony_ci}
1221e1c44949Sopenharmony_ci
1222e1c44949Sopenharmony_civoid CallControlManager::GetDialParaInfo(DialParaInfo &info)
1223e1c44949Sopenharmony_ci{
1224e1c44949Sopenharmony_ci    std::lock_guard<std::mutex> lock(mutex_);
1225e1c44949Sopenharmony_ci    info = dialSrcInfo_;
1226e1c44949Sopenharmony_ci}
1227e1c44949Sopenharmony_ci
1228e1c44949Sopenharmony_civoid CallControlManager::GetDialParaInfo(DialParaInfo &info, AppExecFwk::PacMap &extras)
1229e1c44949Sopenharmony_ci{
1230e1c44949Sopenharmony_ci    std::lock_guard<std::mutex> lock(mutex_);
1231e1c44949Sopenharmony_ci    info = dialSrcInfo_;
1232e1c44949Sopenharmony_ci    extras = extras_;
1233e1c44949Sopenharmony_ci}
1234e1c44949Sopenharmony_ci
1235e1c44949Sopenharmony_civoid CallControlManager::handler()
1236e1c44949Sopenharmony_ci{
1237e1c44949Sopenharmony_ci    alarmSeted = false;
1238e1c44949Sopenharmony_ci    TELEPHONY_LOGE("handle DisconnectAbility");
1239e1c44949Sopenharmony_ci    if (!CallObjectManager::HasCallExist()) {
1240e1c44949Sopenharmony_ci        DelayedSingleton<CallConnectAbility>::GetInstance()->DisconnectAbility();
1241e1c44949Sopenharmony_ci    }
1242e1c44949Sopenharmony_ci}
1243e1c44949Sopenharmony_ci
1244e1c44949Sopenharmony_cibool CallControlManager::cancel(ffrt::task_handle &handle)
1245e1c44949Sopenharmony_ci{
1246e1c44949Sopenharmony_ci    if (handle != nullptr) {
1247e1c44949Sopenharmony_ci        TELEPHONY_LOGI("skip disconnect ability task");
1248e1c44949Sopenharmony_ci        int ret = ffrt::skip(handle);
1249e1c44949Sopenharmony_ci        if (ret != TELEPHONY_SUCCESS) {
1250e1c44949Sopenharmony_ci            TELEPHONY_LOGE("skip task failed, ret = %{public}d", ret);
1251e1c44949Sopenharmony_ci            return false;
1252e1c44949Sopenharmony_ci        }
1253e1c44949Sopenharmony_ci    }
1254e1c44949Sopenharmony_ci    return true;
1255e1c44949Sopenharmony_ci}
1256e1c44949Sopenharmony_ci
1257e1c44949Sopenharmony_civoid CallControlManager::ConnectCallUiService(bool shouldConnect)
1258e1c44949Sopenharmony_ci{
1259e1c44949Sopenharmony_ci    if (shouldConnect) {
1260e1c44949Sopenharmony_ci        if (alarmSeted) {
1261e1c44949Sopenharmony_ci            if (!cancel(disconnectHandle)) {
1262e1c44949Sopenharmony_ci                return;
1263e1c44949Sopenharmony_ci            }
1264e1c44949Sopenharmony_ci            alarmSeted = false;
1265e1c44949Sopenharmony_ci        }
1266e1c44949Sopenharmony_ci        DelayedSingleton<CallConnectAbility>::GetInstance()->ConnectAbility();
1267e1c44949Sopenharmony_ci        shouldDisconnect = false;
1268e1c44949Sopenharmony_ci    } else {
1269e1c44949Sopenharmony_ci        shouldDisconnect = true;
1270e1c44949Sopenharmony_ci        if (!alarmSeted) {
1271e1c44949Sopenharmony_ci            TELEPHONY_LOGI("submit delay disconnect ability");
1272e1c44949Sopenharmony_ci            disconnectHandle = ffrt::submit_h([&]() {
1273e1c44949Sopenharmony_ci                handler();
1274e1c44949Sopenharmony_ci            }, {}, {}, ffrt::task_attr().delay(DISCONNECT_DELAY_TIME));
1275e1c44949Sopenharmony_ci            alarmSeted = true;
1276e1c44949Sopenharmony_ci        }  else {
1277e1c44949Sopenharmony_ci            if (!cancel(disconnectHandle)) {
1278e1c44949Sopenharmony_ci                return;
1279e1c44949Sopenharmony_ci            }
1280e1c44949Sopenharmony_ci            TELEPHONY_LOGI("submit delay disconnect ability");
1281e1c44949Sopenharmony_ci            disconnectHandle = ffrt::submit_h([&]() {
1282e1c44949Sopenharmony_ci                handler();
1283e1c44949Sopenharmony_ci            }, {}, {}, ffrt::task_attr().delay(DISCONNECT_DELAY_TIME));
1284e1c44949Sopenharmony_ci        }
1285e1c44949Sopenharmony_ci    }
1286e1c44949Sopenharmony_ci}
1287e1c44949Sopenharmony_ci
1288e1c44949Sopenharmony_cibool CallControlManager::ShouldDisconnectService()
1289e1c44949Sopenharmony_ci{
1290e1c44949Sopenharmony_ci    return shouldDisconnect;
1291e1c44949Sopenharmony_ci}
1292e1c44949Sopenharmony_ci
1293e1c44949Sopenharmony_ciint32_t CallControlManager::RemoveMissedIncomingCallNotification()
1294e1c44949Sopenharmony_ci{
1295e1c44949Sopenharmony_ci    int32_t ret = DelayedSingleton<CallRecordsManager>::GetInstance()->RemoveMissedIncomingCallNotification();
1296e1c44949Sopenharmony_ci    if (ret != TELEPHONY_SUCCESS) {
1297e1c44949Sopenharmony_ci        TELEPHONY_LOGE("RemoveMissedIncomingCallNotification failed!");
1298e1c44949Sopenharmony_ci        return ret;
1299e1c44949Sopenharmony_ci    }
1300e1c44949Sopenharmony_ci    return TELEPHONY_SUCCESS;
1301e1c44949Sopenharmony_ci}
1302e1c44949Sopenharmony_ci
1303e1c44949Sopenharmony_ciint32_t CallControlManager::SetVoIPCallState(int32_t state)
1304e1c44949Sopenharmony_ci{
1305e1c44949Sopenharmony_ci    TELEPHONY_LOGI("VoIP state is %{public}d", state);
1306e1c44949Sopenharmony_ci    VoIPCallState_ = (CallStateToApp)state;
1307e1c44949Sopenharmony_ci    std::string identity = IPCSkeleton::ResetCallingIdentity();
1308e1c44949Sopenharmony_ci    DelayedSingleton<CallStateReportProxy>::GetInstance()->UpdateCallStateForVoIPOrRestart();
1309e1c44949Sopenharmony_ci    CallVoiceAssistantManager::GetInstance()->UpdateVoipCallState(state);
1310e1c44949Sopenharmony_ci    IPCSkeleton::SetCallingIdentity(identity);
1311e1c44949Sopenharmony_ci    if (VoIPCallState_ == CallStateToApp::CALL_STATE_ANSWERED) {
1312e1c44949Sopenharmony_ci        TELEPHONY_LOGI("VoIP answered the call, should hangup all calls");
1313e1c44949Sopenharmony_ci        std::list<sptr<CallBase>> allCallList = CallObjectManager::GetAllCallList();
1314e1c44949Sopenharmony_ci        for (auto call : allCallList) {
1315e1c44949Sopenharmony_ci            int32_t ret = HangUpCall(call->GetCallID());
1316e1c44949Sopenharmony_ci            if (ret != TELEPHONY_SUCCESS) {
1317e1c44949Sopenharmony_ci                return ret;
1318e1c44949Sopenharmony_ci            }
1319e1c44949Sopenharmony_ci        }
1320e1c44949Sopenharmony_ci    }
1321e1c44949Sopenharmony_ci    if (VoIPCallState_ == CallStateToApp::CALL_STATE_OFFHOOK) {
1322e1c44949Sopenharmony_ci        HangUpVoipCall();
1323e1c44949Sopenharmony_ci    }
1324e1c44949Sopenharmony_ci    if (VoIPCallState_ == CallStateToApp::CALL_STATE_IDLE) {
1325e1c44949Sopenharmony_ci            TELEPHONY_LOGI("VoIP call state is not active");
1326e1c44949Sopenharmony_ci            if (AnsweredCallQueue_.hasCall) {
1327e1c44949Sopenharmony_ci                AnsweredCallQueue_.hasCall = false;
1328e1c44949Sopenharmony_ci                return AnswerCall(AnsweredCallQueue_.callId, AnsweredCallQueue_.videoState);
1329e1c44949Sopenharmony_ci        }
1330e1c44949Sopenharmony_ci    }
1331e1c44949Sopenharmony_ci    return TELEPHONY_SUCCESS;
1332e1c44949Sopenharmony_ci}
1333e1c44949Sopenharmony_ci
1334e1c44949Sopenharmony_ciint32_t CallControlManager::HangUpVoipCall()
1335e1c44949Sopenharmony_ci{
1336e1c44949Sopenharmony_ci    std::list<sptr<CallBase>> allCallList = CallObjectManager::GetAllCallList();
1337e1c44949Sopenharmony_ci    for (auto call : allCallList) {
1338e1c44949Sopenharmony_ci        if (call != nullptr && call->GetCallType() == CallType::TYPE_VOIP) {
1339e1c44949Sopenharmony_ci            if (call->GetTelCallState() == TelCallState::CALL_STATUS_ACTIVE) {
1340e1c44949Sopenharmony_ci                TELEPHONY_LOGI("the voip call with callId %{public}d is active, no need to hangup", call->GetCallID());
1341e1c44949Sopenharmony_ci                continue;
1342e1c44949Sopenharmony_ci            }
1343e1c44949Sopenharmony_ci            TELEPHONY_LOGI("HangUp VoipCall callId %{public}d", call->GetCallID());
1344e1c44949Sopenharmony_ci            int32_t ret = HangUpCall(call->GetCallID());
1345e1c44949Sopenharmony_ci            if (ret != TELEPHONY_SUCCESS) {
1346e1c44949Sopenharmony_ci                TELEPHONY_LOGE("hangup voip call %{public}d failed!", call->GetCallID());
1347e1c44949Sopenharmony_ci                return ret;
1348e1c44949Sopenharmony_ci            }
1349e1c44949Sopenharmony_ci        }
1350e1c44949Sopenharmony_ci    }
1351e1c44949Sopenharmony_ci    return TELEPHONY_SUCCESS;
1352e1c44949Sopenharmony_ci}
1353e1c44949Sopenharmony_ci
1354e1c44949Sopenharmony_ciint32_t CallControlManager::GetVoIPCallState(int32_t &state)
1355e1c44949Sopenharmony_ci{
1356e1c44949Sopenharmony_ci    state = (int32_t)VoIPCallState_;
1357e1c44949Sopenharmony_ci    return TELEPHONY_SUCCESS;
1358e1c44949Sopenharmony_ci}
1359e1c44949Sopenharmony_ci
1360e1c44949Sopenharmony_civoid CallControlManager::CallStateObserve()
1361e1c44949Sopenharmony_ci{
1362e1c44949Sopenharmony_ci    if (callStateListenerPtr_ == nullptr) {
1363e1c44949Sopenharmony_ci        TELEPHONY_LOGE("callStateListenerPtr_ is null");
1364e1c44949Sopenharmony_ci        return;
1365e1c44949Sopenharmony_ci    }
1366e1c44949Sopenharmony_ci    std::shared_ptr<RejectCallSms> hangUpSmsPtr = std::make_shared<RejectCallSms>();
1367e1c44949Sopenharmony_ci    if (hangUpSmsPtr == nullptr) {
1368e1c44949Sopenharmony_ci        TELEPHONY_LOGE("hangUpSmsPtr is null");
1369e1c44949Sopenharmony_ci        return;
1370e1c44949Sopenharmony_ci    }
1371e1c44949Sopenharmony_ci    callStateListenerPtr_->AddOneObserver(DelayedSingleton<CallAbilityReportProxy>::GetInstance());
1372e1c44949Sopenharmony_ci    callStateListenerPtr_->AddOneObserver(DelayedSingleton<CallStateReportProxy>::GetInstance());
1373e1c44949Sopenharmony_ci    callStateListenerPtr_->AddOneObserver(DelayedSingleton<AudioControlManager>::GetInstance());
1374e1c44949Sopenharmony_ci    callStateListenerPtr_->AddOneObserver(hangUpSmsPtr);
1375e1c44949Sopenharmony_ci    callStateListenerPtr_->AddOneObserver(missedCallNotification_);
1376e1c44949Sopenharmony_ci    callStateListenerPtr_->AddOneObserver(incomingCallWakeup_);
1377e1c44949Sopenharmony_ci    callStateListenerPtr_->AddOneObserver(DelayedSingleton<CallRecordsManager>::GetInstance());
1378e1c44949Sopenharmony_ci    callStateListenerPtr_->AddOneObserver(DelayedSingleton<DistributedCommunicationManager>::GetInstance());
1379e1c44949Sopenharmony_ci    callStateListenerPtr_->AddOneObserver(CallVoiceAssistantManager::GetInstance());
1380e1c44949Sopenharmony_ci}
1381e1c44949Sopenharmony_ci
1382e1c44949Sopenharmony_ciint32_t CallControlManager::AddCallLogAndNotification(sptr<CallBase> &callObjectPtr)
1383e1c44949Sopenharmony_ci{
1384e1c44949Sopenharmony_ci    if (callObjectPtr == nullptr) {
1385e1c44949Sopenharmony_ci        TELEPHONY_LOGE("callObjectPtr is null");
1386e1c44949Sopenharmony_ci        return TELEPHONY_ERR_LOCAL_PTR_NULL;
1387e1c44949Sopenharmony_ci    }
1388e1c44949Sopenharmony_ci    callObjectPtr->SetAnswerType(CallAnswerType::CALL_ANSWER_MISSED);
1389e1c44949Sopenharmony_ci    DelayedSingleton<CallRecordsManager>::GetInstance()
1390e1c44949Sopenharmony_ci        ->CallStateUpdated(callObjectPtr, TelCallState::CALL_STATUS_INCOMING, TelCallState::CALL_STATUS_DISCONNECTED);
1391e1c44949Sopenharmony_ci    if (missedCallNotification_ == nullptr) {
1392e1c44949Sopenharmony_ci        TELEPHONY_LOGE("missedCallNotification is null");
1393e1c44949Sopenharmony_ci        return TELEPHONY_ERR_LOCAL_PTR_NULL;
1394e1c44949Sopenharmony_ci    }
1395e1c44949Sopenharmony_ci    missedCallNotification_->PublishMissedCallEvent(callObjectPtr);
1396e1c44949Sopenharmony_ci    missedCallNotification_->PublishMissedCallNotification(callObjectPtr);
1397e1c44949Sopenharmony_ci    return TELEPHONY_SUCCESS;
1398e1c44949Sopenharmony_ci}
1399e1c44949Sopenharmony_ci
1400e1c44949Sopenharmony_ciint32_t CallControlManager::AddBlockLogAndNotification(sptr<CallBase> &callObjectPtr)
1401e1c44949Sopenharmony_ci{
1402e1c44949Sopenharmony_ci    if (callObjectPtr == nullptr) {
1403e1c44949Sopenharmony_ci        TELEPHONY_LOGE("callObjectPtr is null");
1404e1c44949Sopenharmony_ci        return TELEPHONY_ERR_LOCAL_PTR_NULL;
1405e1c44949Sopenharmony_ci    }
1406e1c44949Sopenharmony_ci    callObjectPtr->SetAnswerType(CallAnswerType::CALL_ANSWER_BLOCKED);
1407e1c44949Sopenharmony_ci    DelayedSingleton<CallRecordsManager>::GetInstance()
1408e1c44949Sopenharmony_ci        ->CallStateUpdated(callObjectPtr, TelCallState::CALL_STATUS_INCOMING, TelCallState::CALL_STATUS_DISCONNECTED);
1409e1c44949Sopenharmony_ci    if (missedCallNotification_ == nullptr) {
1410e1c44949Sopenharmony_ci        TELEPHONY_LOGE("missedCallNotification is null");
1411e1c44949Sopenharmony_ci        return TELEPHONY_ERR_LOCAL_PTR_NULL;
1412e1c44949Sopenharmony_ci    }
1413e1c44949Sopenharmony_ci    missedCallNotification_->PublishBlockedCallEvent(callObjectPtr);
1414e1c44949Sopenharmony_ci    return TELEPHONY_SUCCESS;
1415e1c44949Sopenharmony_ci}
1416e1c44949Sopenharmony_ci
1417e1c44949Sopenharmony_ciint32_t CallControlManager::NumberLegalityCheck(std::string &number)
1418e1c44949Sopenharmony_ci{
1419e1c44949Sopenharmony_ci    if (number.empty()) {
1420e1c44949Sopenharmony_ci        TELEPHONY_LOGE("phone number is NULL!");
1421e1c44949Sopenharmony_ci        return CALL_ERR_PHONE_NUMBER_EMPTY;
1422e1c44949Sopenharmony_ci    }
1423e1c44949Sopenharmony_ci    if (number.length() > kMaxNumberLen) {
1424e1c44949Sopenharmony_ci        TELEPHONY_LOGE(
1425e1c44949Sopenharmony_ci            "the number length exceeds limit,len:%{public}zu,maxLen:%{public}d", number.length(), kMaxNumberLen);
1426e1c44949Sopenharmony_ci        return CALL_ERR_NUMBER_OUT_OF_RANGE;
1427e1c44949Sopenharmony_ci    }
1428e1c44949Sopenharmony_ci    return TELEPHONY_SUCCESS;
1429e1c44949Sopenharmony_ci}
1430e1c44949Sopenharmony_ci
1431e1c44949Sopenharmony_civoid CallControlManager::AcquireIncomingLock()
1432e1c44949Sopenharmony_ci{
1433e1c44949Sopenharmony_ci    if (incomingCallWakeup_ == nullptr) {
1434e1c44949Sopenharmony_ci        return;
1435e1c44949Sopenharmony_ci    }
1436e1c44949Sopenharmony_ci    incomingCallWakeup_->AcquireIncomingLock();
1437e1c44949Sopenharmony_ci}
1438e1c44949Sopenharmony_ci
1439e1c44949Sopenharmony_civoid CallControlManager::ReleaseIncomingLock()
1440e1c44949Sopenharmony_ci{
1441e1c44949Sopenharmony_ci    if (incomingCallWakeup_ == nullptr) {
1442e1c44949Sopenharmony_ci        return;
1443e1c44949Sopenharmony_ci    }
1444e1c44949Sopenharmony_ci    incomingCallWakeup_->ReleaseIncomingLock();
1445e1c44949Sopenharmony_ci}
1446e1c44949Sopenharmony_ci
1447e1c44949Sopenharmony_ciCallControlManager::SystemAbilityListener::SystemAbilityListener(std::shared_ptr<CallBroadcastSubscriber> subscriberPtr)
1448e1c44949Sopenharmony_ci    : subscriberPtr_(subscriberPtr)
1449e1c44949Sopenharmony_ci{}
1450e1c44949Sopenharmony_ci
1451e1c44949Sopenharmony_civoid CallControlManager::SystemAbilityListener::OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId)
1452e1c44949Sopenharmony_ci{
1453e1c44949Sopenharmony_ci    if (systemAbilityId != COMMON_EVENT_SERVICE_ID) {
1454e1c44949Sopenharmony_ci        TELEPHONY_LOGE("systemAbilityId is not COMMON_EVENT_SERVICE_ID");
1455e1c44949Sopenharmony_ci        return;
1456e1c44949Sopenharmony_ci    }
1457e1c44949Sopenharmony_ci
1458e1c44949Sopenharmony_ci    if (subscriberPtr_ == nullptr) {
1459e1c44949Sopenharmony_ci        TELEPHONY_LOGE("CallControlManager::OnAddSystemAbility subscriberPtr is nullptr");
1460e1c44949Sopenharmony_ci        return;
1461e1c44949Sopenharmony_ci    }
1462e1c44949Sopenharmony_ci    std::string identity = IPCSkeleton::ResetCallingIdentity();
1463e1c44949Sopenharmony_ci    bool subscribeResult = EventFwk::CommonEventManager::SubscribeCommonEvent(subscriberPtr_);
1464e1c44949Sopenharmony_ci    IPCSkeleton::SetCallingIdentity(identity);
1465e1c44949Sopenharmony_ci    TELEPHONY_LOGI("CallControlManager::OnAddSystemAbility subscribeResult = %{public}d", subscribeResult);
1466e1c44949Sopenharmony_ci}
1467e1c44949Sopenharmony_ci
1468e1c44949Sopenharmony_civoid CallControlManager::SystemAbilityListener::OnRemoveSystemAbility(
1469e1c44949Sopenharmony_ci    int32_t systemAbilityId, const std::string &deviceId)
1470e1c44949Sopenharmony_ci{
1471e1c44949Sopenharmony_ci    if (systemAbilityId != COMMON_EVENT_SERVICE_ID) {
1472e1c44949Sopenharmony_ci        TELEPHONY_LOGE("systemAbilityId is not COMMON_EVENT_SERVICE_ID");
1473e1c44949Sopenharmony_ci        return;
1474e1c44949Sopenharmony_ci    }
1475e1c44949Sopenharmony_ci
1476e1c44949Sopenharmony_ci    if (subscriberPtr_ == nullptr) {
1477e1c44949Sopenharmony_ci        TELEPHONY_LOGE("CallControlManager::OnRemoveSystemAbility subscriberPtr is nullptr");
1478e1c44949Sopenharmony_ci        return;
1479e1c44949Sopenharmony_ci    }
1480e1c44949Sopenharmony_ci    std::string identity = IPCSkeleton::ResetCallingIdentity();
1481e1c44949Sopenharmony_ci    bool subscribeResult = EventFwk::CommonEventManager::UnSubscribeCommonEvent(subscriberPtr_);
1482e1c44949Sopenharmony_ci    IPCSkeleton::SetCallingIdentity(identity);
1483e1c44949Sopenharmony_ci    TELEPHONY_LOGI("CallControlManager::OnRemoveSystemAbility subscribeResult = %{public}d", subscribeResult);
1484e1c44949Sopenharmony_ci}
1485e1c44949Sopenharmony_ci
1486e1c44949Sopenharmony_ciint32_t CallControlManager::BroadcastSubscriber()
1487e1c44949Sopenharmony_ci{
1488e1c44949Sopenharmony_ci    EventFwk::MatchingSkills matchingSkills;
1489e1c44949Sopenharmony_ci    matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_SIM_STATE_CHANGED);
1490e1c44949Sopenharmony_ci    matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_BLUETOOTH_REMOTEDEVICE_NAME_UPDATE);
1491e1c44949Sopenharmony_ci    matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_USER_SWITCHED);
1492e1c44949Sopenharmony_ci    EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills);
1493e1c44949Sopenharmony_ci    subscriberInfo.SetThreadMode(EventFwk::CommonEventSubscribeInfo::COMMON);
1494e1c44949Sopenharmony_ci    std::shared_ptr<CallBroadcastSubscriber> subscriberPtr = std::make_shared<CallBroadcastSubscriber>(subscriberInfo);
1495e1c44949Sopenharmony_ci    if (subscriberPtr == nullptr) {
1496e1c44949Sopenharmony_ci        TELEPHONY_LOGE("CallControlManager::BroadcastSubscriber subscriberPtr is nullptr");
1497e1c44949Sopenharmony_ci        return TELEPHONY_ERROR;
1498e1c44949Sopenharmony_ci    }
1499e1c44949Sopenharmony_ci
1500e1c44949Sopenharmony_ci    EventFwk::MatchingSkills matchingSkill;
1501e1c44949Sopenharmony_ci    matchingSkill.AddEvent("event.custom.contacts.PAGE_STATE_CHANGE");
1502e1c44949Sopenharmony_ci    EventFwk::CommonEventSubscribeInfo subscriberInfomation(matchingSkill);
1503e1c44949Sopenharmony_ci    subscriberInfomation.SetThreadMode(EventFwk::CommonEventSubscribeInfo::COMMON);
1504e1c44949Sopenharmony_ci    subscriberInfomation.SetPermission("ohos.permission.SET_TELEPHONY_STATE");
1505e1c44949Sopenharmony_ci    std::shared_ptr<CallBroadcastSubscriber> subscriber =
1506e1c44949Sopenharmony_ci        std::make_shared<CallBroadcastSubscriber>(subscriberInfomation);
1507e1c44949Sopenharmony_ci    if (subscriber == nullptr) {
1508e1c44949Sopenharmony_ci        TELEPHONY_LOGE("CallControlManager::BroadcastSubscriber subscriber is nullptr");
1509e1c44949Sopenharmony_ci        return TELEPHONY_ERROR;
1510e1c44949Sopenharmony_ci    }
1511e1c44949Sopenharmony_ci
1512e1c44949Sopenharmony_ci    EventFwk::MatchingSkills matchingSkills_;
1513e1c44949Sopenharmony_ci    matchingSkills.AddEvent("usual.event.thermal.satcomm.HIGH_TEMP_LEVEL");
1514e1c44949Sopenharmony_ci    EventFwk::CommonEventSubscribeInfo subscriberInfo_(matchingSkills_);
1515e1c44949Sopenharmony_ci    subscriberInfo_.SetThreadMode(EventFwk::CommonEventSubscribeInfo::COMMON);
1516e1c44949Sopenharmony_ci    subscriberInfo_.SetPublisherUid(SATCOMM_UID);
1517e1c44949Sopenharmony_ci    std::shared_ptr<CallBroadcastSubscriber> subscriberPtr_ =
1518e1c44949Sopenharmony_ci        std::make_shared<CallBroadcastSubscriber>(subscriberInfo_);
1519e1c44949Sopenharmony_ci    if (subscriberPtr_ == nullptr) {
1520e1c44949Sopenharmony_ci        TELEPHONY_LOGE("CallControlManager::BroadcastSubscriber subscriberPtr_ is nullptr");
1521e1c44949Sopenharmony_ci        return TELEPHONY_ERROR;
1522e1c44949Sopenharmony_ci    }
1523e1c44949Sopenharmony_ci
1524e1c44949Sopenharmony_ci    EventFwk::MatchingSkills matchingSkill_;
1525e1c44949Sopenharmony_ci    matchingSkill_.AddEvent("usual.event.SUPER_PRIVACY_MODE");
1526e1c44949Sopenharmony_ci    EventFwk::CommonEventSubscribeInfo subscriberInfos_(matchingSkill_);
1527e1c44949Sopenharmony_ci    subscriberInfos_.SetPublisherBundleName("com.settings");
1528e1c44949Sopenharmony_ci    subscriberInfos_.SetPermission("ohos.permission.SET_TELEPHONY_STATE");
1529e1c44949Sopenharmony_ci    subscriberInfos_.SetThreadMode(EventFwk::CommonEventSubscribeInfo::COMMON);
1530e1c44949Sopenharmony_ci    std::shared_ptr<CallBroadcastSubscriber> subscriberPtrs_ =
1531e1c44949Sopenharmony_ci        std::make_shared<CallBroadcastSubscriber>(subscriberInfos_);
1532e1c44949Sopenharmony_ci    if (subscriberPtrs_ == nullptr) {
1533e1c44949Sopenharmony_ci        TELEPHONY_LOGE("CallControlManager::BroadcastSubscriber subscriberPtrs_ is nullptr");
1534e1c44949Sopenharmony_ci        return TELEPHONY_ERROR;
1535e1c44949Sopenharmony_ci    }
1536e1c44949Sopenharmony_ci
1537e1c44949Sopenharmony_ci    // if SubscribeCommonEvent fail, register statusChangeListener to SubscribeCommonEvent again
1538e1c44949Sopenharmony_ci    auto samgrProxy = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
1539e1c44949Sopenharmony_ci    if (samgrProxy == nullptr) {
1540e1c44949Sopenharmony_ci        TELEPHONY_LOGE("samgrProxy is nullptr");
1541e1c44949Sopenharmony_ci        return TELEPHONY_ERROR;
1542e1c44949Sopenharmony_ci    }
1543e1c44949Sopenharmony_ci    statusChangeListener_ = new (std::nothrow) SystemAbilityListener(subscriberPtr);
1544e1c44949Sopenharmony_ci    if (statusChangeListener_ == nullptr) {
1545e1c44949Sopenharmony_ci        TELEPHONY_LOGE("statusChangeListener_ is nullptr");
1546e1c44949Sopenharmony_ci        return TELEPHONY_ERROR;
1547e1c44949Sopenharmony_ci    }
1548e1c44949Sopenharmony_ci    pageStateChangeListener_ = new (std::nothrow) SystemAbilityListener(subscriber);
1549e1c44949Sopenharmony_ci    if (pageStateChangeListener_ == nullptr) {
1550e1c44949Sopenharmony_ci        TELEPHONY_LOGE("pageStateChangeListener_ is nullptr");
1551e1c44949Sopenharmony_ci        return TELEPHONY_ERROR;
1552e1c44949Sopenharmony_ci    }
1553e1c44949Sopenharmony_ci    satcommEventListener_ =
1554e1c44949Sopenharmony_ci        new (std::nothrow) SystemAbilityListener(subscriberPtr_);
1555e1c44949Sopenharmony_ci    if (satcommEventListener_ == nullptr) {
1556e1c44949Sopenharmony_ci        TELEPHONY_LOGE("satcommEventListener_ is nullptr");
1557e1c44949Sopenharmony_ci        return TELEPHONY_ERROR;
1558e1c44949Sopenharmony_ci    }
1559e1c44949Sopenharmony_ci    superPrivacyEventListener_ =
1560e1c44949Sopenharmony_ci        new (std::nothrow) SystemAbilityListener(subscriberPtrs_);
1561e1c44949Sopenharmony_ci    if (superPrivacyEventListener_ == nullptr) {
1562e1c44949Sopenharmony_ci        TELEPHONY_LOGE("superPrivacyEventListener_ is nullptr");
1563e1c44949Sopenharmony_ci        return TELEPHONY_ERROR;
1564e1c44949Sopenharmony_ci    }
1565e1c44949Sopenharmony_ci    int32_t ret = samgrProxy->SubscribeSystemAbility(COMMON_EVENT_SERVICE_ID, statusChangeListener_);
1566e1c44949Sopenharmony_ci    TELEPHONY_LOGI("CallControlManager::BroadcastSubscriber statusChangeListener_ ret: %{public}d", ret);
1567e1c44949Sopenharmony_ci    ret = samgrProxy->SubscribeSystemAbility(COMMON_EVENT_SERVICE_ID, pageStateChangeListener_);
1568e1c44949Sopenharmony_ci    TELEPHONY_LOGI("CallControlManager::BroadcastSubscriber pageStateChangeListener_ ret: %{public}d", ret);
1569e1c44949Sopenharmony_ci    ret = samgrProxy->SubscribeSystemAbility(COMMON_EVENT_SERVICE_ID, satcommEventListener_);
1570e1c44949Sopenharmony_ci    TELEPHONY_LOGI("CallControlManager::BroadcastSubscriber satcommEventListener_ ret: %{public}d", ret);
1571e1c44949Sopenharmony_ci    ret = samgrProxy->SubscribeSystemAbility(COMMON_EVENT_SERVICE_ID, superPrivacyEventListener_);
1572e1c44949Sopenharmony_ci    TELEPHONY_LOGI("CallControlManager::BroadcastSubscriber superPrivacyEventListener_ ret: %{public}d", ret);
1573e1c44949Sopenharmony_ci    return TELEPHONY_SUCCESS;
1574e1c44949Sopenharmony_ci}
1575e1c44949Sopenharmony_ci
1576e1c44949Sopenharmony_ci#ifdef ABILITY_MEDIA_SUPPORT
1577e1c44949Sopenharmony_cibool CallControlManager::onButtonDealing(HeadsetButtonService::ButtonEvent type)
1578e1c44949Sopenharmony_ci{
1579e1c44949Sopenharmony_ci    bool isRingState = false;
1580e1c44949Sopenharmony_ci    sptr<CallBase> call = nullptr;
1581e1c44949Sopenharmony_ci
1582e1c44949Sopenharmony_ci    if (GetOneCallObject(CallRunningState::CALL_RUNNING_STATE_RINGING) != nullptr) {
1583e1c44949Sopenharmony_ci        call = GetOneCallObject(CallRunningState::CALL_RUNNING_STATE_RINGING);
1584e1c44949Sopenharmony_ci        isRingState = true;
1585e1c44949Sopenharmony_ci    } else if (GetOneCallObject(CallRunningState::CALL_RUNNING_STATE_DIALING) != nullptr) {
1586e1c44949Sopenharmony_ci        call = GetOneCallObject(CallRunningState::CALL_RUNNING_STATE_DIALING);
1587e1c44949Sopenharmony_ci    } else if (GetOneCallObject(CallRunningState::CALL_RUNNING_STATE_ACTIVE) != nullptr) {
1588e1c44949Sopenharmony_ci        call = GetOneCallObject(CallRunningState::CALL_RUNNING_STATE_ACTIVE);
1589e1c44949Sopenharmony_ci    } else if (GetOneCallObject(CallRunningState::CALL_RUNNING_STATE_HOLD) != nullptr) {
1590e1c44949Sopenharmony_ci        call = GetOneCallObject(CallRunningState::CALL_RUNNING_STATE_HOLD);
1591e1c44949Sopenharmony_ci    } else {
1592e1c44949Sopenharmony_ci        return false;
1593e1c44949Sopenharmony_ci    }
1594e1c44949Sopenharmony_ci
1595e1c44949Sopenharmony_ci    switch (type) {
1596e1c44949Sopenharmony_ci        case HeadsetButtonService::SHORT_PRESS_EVENT:
1597e1c44949Sopenharmony_ci            if (isRingState) {
1598e1c44949Sopenharmony_ci                call->HangUpCall();
1599e1c44949Sopenharmony_ci            } else {
1600e1c44949Sopenharmony_ci                call->AnswerCall(0);
1601e1c44949Sopenharmony_ci            }
1602e1c44949Sopenharmony_ci            break;
1603e1c44949Sopenharmony_ci        case HeadsetButtonService::LONG_PRESS_EVENT:
1604e1c44949Sopenharmony_ci            if (isRingState) {
1605e1c44949Sopenharmony_ci                std::string str = "";
1606e1c44949Sopenharmony_ci                call->RejectCall(false, str);
1607e1c44949Sopenharmony_ci            } else {
1608e1c44949Sopenharmony_ci                DelayedSingleton<AudioControlManager>::GetInstance()->SetMute(true);
1609e1c44949Sopenharmony_ci            }
1610e1c44949Sopenharmony_ci            break;
1611e1c44949Sopenharmony_ci        default:
1612e1c44949Sopenharmony_ci            return false;
1613e1c44949Sopenharmony_ci    }
1614e1c44949Sopenharmony_ci    return true;
1615e1c44949Sopenharmony_ci}
1616e1c44949Sopenharmony_ci#endif
1617e1c44949Sopenharmony_ci} // namespace Telephony
1618e1c44949Sopenharmony_ci} // namespace OHOS
1619