1e1c44949Sopenharmony_ci/*
2e1c44949Sopenharmony_ci * Copyright (C) 2021-2022 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_policy.h"
17e1c44949Sopenharmony_ci
18e1c44949Sopenharmony_ci#include "call_dialog.h"
19e1c44949Sopenharmony_ci#include "call_data_base_helper.h"
20e1c44949Sopenharmony_ci#include "call_manager_errors.h"
21e1c44949Sopenharmony_ci#include "call_number_utils.h"
22e1c44949Sopenharmony_ci#include "core_service_client.h"
23e1c44949Sopenharmony_ci#include "ims_conference.h"
24e1c44949Sopenharmony_ci#include "telephony_log_wrapper.h"
25e1c44949Sopenharmony_ci#include "call_control_manager.h"
26e1c44949Sopenharmony_ci#include "call_superprivacy_control_manager.h"
27e1c44949Sopenharmony_ci#include "call_manager_base.h"
28e1c44949Sopenharmony_ci#include "distributed_communication_manager.h"
29e1c44949Sopenharmony_ci
30e1c44949Sopenharmony_cinamespace OHOS {
31e1c44949Sopenharmony_cinamespace Telephony {
32e1c44949Sopenharmony_ciCallPolicy::CallPolicy() {}
33e1c44949Sopenharmony_ci
34e1c44949Sopenharmony_ciCallPolicy::~CallPolicy() {}
35e1c44949Sopenharmony_ci
36e1c44949Sopenharmony_ciint32_t CallPolicy::DialPolicy(std::u16string &number, AppExecFwk::PacMap &extras, bool isEcc)
37e1c44949Sopenharmony_ci{
38e1c44949Sopenharmony_ci    DialType dialType = (DialType)extras.GetIntValue("dialType");
39e1c44949Sopenharmony_ci    if (dialType != DialType::DIAL_CARRIER_TYPE && dialType != DialType::DIAL_VOICE_MAIL_TYPE &&
40e1c44949Sopenharmony_ci        dialType != DialType::DIAL_OTT_TYPE) {
41e1c44949Sopenharmony_ci        TELEPHONY_LOGE("dial type invalid!");
42e1c44949Sopenharmony_ci        return TELEPHONY_ERR_ARGUMENT_INVALID;
43e1c44949Sopenharmony_ci    }
44e1c44949Sopenharmony_ci    int32_t accountId = extras.GetIntValue("accountId");
45e1c44949Sopenharmony_ci    if (dialType == DialType::DIAL_CARRIER_TYPE) {
46e1c44949Sopenharmony_ci        if (!DelayedSingleton<CallNumberUtils>::GetInstance()->SelectAccountId(accountId, extras)) {
47e1c44949Sopenharmony_ci            extras.PutIntValue("accountId", 0);
48e1c44949Sopenharmony_ci            TELEPHONY_LOGE("invalid accountId, select accountId to 0");
49e1c44949Sopenharmony_ci        }
50e1c44949Sopenharmony_ci    }
51e1c44949Sopenharmony_ci    CallType callType = (CallType)extras.GetIntValue("callType");
52e1c44949Sopenharmony_ci    if (IsValidCallType(callType) != TELEPHONY_SUCCESS) {
53e1c44949Sopenharmony_ci        return TELEPHONY_ERR_ARGUMENT_INVALID;
54e1c44949Sopenharmony_ci    }
55e1c44949Sopenharmony_ci    DialScene dialScene = (DialScene)extras.GetIntValue("dialScene");
56e1c44949Sopenharmony_ci    if ((dialScene != DialScene::CALL_NORMAL && dialScene != DialScene::CALL_PRIVILEGED &&
57e1c44949Sopenharmony_ci            dialScene != DialScene::CALL_EMERGENCY)) {
58e1c44949Sopenharmony_ci        TELEPHONY_LOGE("invalid dial scene!");
59e1c44949Sopenharmony_ci        return TELEPHONY_ERR_ARGUMENT_INVALID;
60e1c44949Sopenharmony_ci    }
61e1c44949Sopenharmony_ci    VideoStateType videoState = (VideoStateType)extras.GetIntValue("videoState");
62e1c44949Sopenharmony_ci    if (videoState != VideoStateType::TYPE_VOICE && videoState != VideoStateType::TYPE_VIDEO) {
63e1c44949Sopenharmony_ci        TELEPHONY_LOGE("invalid video state!");
64e1c44949Sopenharmony_ci        return TELEPHONY_ERR_ARGUMENT_INVALID;
65e1c44949Sopenharmony_ci    }
66e1c44949Sopenharmony_ci    if (!isEcc) {
67e1c44949Sopenharmony_ci        if (IsVoiceCallValid(videoState) != TELEPHONY_SUCCESS) {
68e1c44949Sopenharmony_ci            return CALL_ERR_CALL_COUNTS_EXCEED_LIMIT;
69e1c44949Sopenharmony_ci        }
70e1c44949Sopenharmony_ci        if (HasNewCall() != TELEPHONY_SUCCESS) {
71e1c44949Sopenharmony_ci            return CALL_ERR_CALL_COUNTS_EXCEED_LIMIT;
72e1c44949Sopenharmony_ci        }
73e1c44949Sopenharmony_ci        bool hasEccCall = false;
74e1c44949Sopenharmony_ci        if (HasEmergencyCall(hasEccCall) == TELEPHONY_ERR_SUCCESS && hasEccCall) {
75e1c44949Sopenharmony_ci            TELEPHONY_LOGE("during emergency call, calling is prohibited");
76e1c44949Sopenharmony_ci            return CALL_ERR_CALL_COUNTS_EXCEED_LIMIT;
77e1c44949Sopenharmony_ci        }
78e1c44949Sopenharmony_ci    }
79e1c44949Sopenharmony_ci    return SuperPrivacyMode(number, extras, isEcc);
80e1c44949Sopenharmony_ci}
81e1c44949Sopenharmony_ci
82e1c44949Sopenharmony_ciint32_t CallPolicy::SuperPrivacyMode(std::u16string &number, AppExecFwk::PacMap &extras, bool isEcc)
83e1c44949Sopenharmony_ci{
84e1c44949Sopenharmony_ci    int32_t accountId = extras.GetIntValue("accountId");
85e1c44949Sopenharmony_ci    CallType callType = (CallType)extras.GetIntValue("callType");
86e1c44949Sopenharmony_ci    int32_t slotId = extras.GetIntValue("accountId");
87e1c44949Sopenharmony_ci    if (isEcc) {
88e1c44949Sopenharmony_ci        return HasNormalCall(isEcc, slotId, callType);
89e1c44949Sopenharmony_ci    }
90e1c44949Sopenharmony_ci    DialScene dialScene = (DialScene)extras.GetIntValue("dialScene");
91e1c44949Sopenharmony_ci    if (dialScene == DialScene::CALL_EMERGENCY) {
92e1c44949Sopenharmony_ci        return HasNormalCall(isEcc, slotId, callType);
93e1c44949Sopenharmony_ci    }
94e1c44949Sopenharmony_ci    bool currentIsSuperPrivacyMode = DelayedSingleton<CallSuperPrivacyControlManager>::GetInstance()->
95e1c44949Sopenharmony_ci        GetCurrentIsSuperPrivacyMode();
96e1c44949Sopenharmony_ci    TELEPHONY_LOGI("call policy currentIsSuperPrivacyMode:%{public}d", currentIsSuperPrivacyMode);
97e1c44949Sopenharmony_ci    if (currentIsSuperPrivacyMode) {
98e1c44949Sopenharmony_ci        int32_t videoState = extras.GetIntValue("videoState");
99e1c44949Sopenharmony_ci        int32_t dialType = extras.GetIntValue("dialType");
100e1c44949Sopenharmony_ci        int32_t dialScene = extras.GetIntValue("dialScene");
101e1c44949Sopenharmony_ci        int32_t spCallType = extras.GetIntValue("callType");
102e1c44949Sopenharmony_ci        DelayedSingleton<CallDialog>::GetInstance()->DialogConnectPrivpacyModeExtension("SUPER_PRIVACY_MODE",
103e1c44949Sopenharmony_ci            number, accountId, videoState, dialType, dialScene, spCallType, true);
104e1c44949Sopenharmony_ci        return CALL_ERR_DIAL_FAILED;
105e1c44949Sopenharmony_ci    }
106e1c44949Sopenharmony_ci    return HasNormalCall(isEcc, slotId, callType);
107e1c44949Sopenharmony_ci}
108e1c44949Sopenharmony_ciint32_t CallPolicy::HasNormalCall(bool isEcc, int32_t slotId, CallType callType)
109e1c44949Sopenharmony_ci{
110e1c44949Sopenharmony_ci    if (isEcc || callType == CallType::TYPE_SATELLITE) {
111e1c44949Sopenharmony_ci        return TELEPHONY_SUCCESS;
112e1c44949Sopenharmony_ci    }
113e1c44949Sopenharmony_ci    bool hasSimCard = false;
114e1c44949Sopenharmony_ci    DelayedRefSingleton<CoreServiceClient>::GetInstance().HasSimCard(slotId, hasSimCard);
115e1c44949Sopenharmony_ci    if (!hasSimCard) {
116e1c44949Sopenharmony_ci        TELEPHONY_LOGE("Call failed due to no sim card");
117e1c44949Sopenharmony_ci        DelayedSingleton<CallDialog>::GetInstance()->DialogConnectExtension("CALL_FAILED_NO_SIM_CARD");
118e1c44949Sopenharmony_ci        return TELEPHONY_ERR_NO_SIM_CARD;
119e1c44949Sopenharmony_ci    }
120e1c44949Sopenharmony_ci    bool isAirplaneModeOn = false;
121e1c44949Sopenharmony_ci    int32_t ret = GetAirplaneMode(isAirplaneModeOn);
122e1c44949Sopenharmony_ci    if (ret == TELEPHONY_SUCCESS && isAirplaneModeOn) {
123e1c44949Sopenharmony_ci        TELEPHONY_LOGE("Call failed due to isAirplaneModeOn is true");
124e1c44949Sopenharmony_ci        DelayedSingleton<CallDialog>::GetInstance()->DialogConnectExtension("CALL_FAILED_IN_AIRPLANE_MODE");
125e1c44949Sopenharmony_ci        return TELEPHONY_ERR_AIRPLANE_MODE_ON;
126e1c44949Sopenharmony_ci    }
127e1c44949Sopenharmony_ci    sptr<NetworkState> networkState = nullptr;
128e1c44949Sopenharmony_ci    RegServiceState regStatus = RegServiceState::REG_STATE_UNKNOWN;
129e1c44949Sopenharmony_ci    DelayedRefSingleton<CoreServiceClient>::GetInstance().GetNetworkState(slotId, networkState);
130e1c44949Sopenharmony_ci    if (networkState != nullptr) {
131e1c44949Sopenharmony_ci        regStatus = networkState->GetRegStatus();
132e1c44949Sopenharmony_ci    }
133e1c44949Sopenharmony_ci    if (regStatus != RegServiceState::REG_STATE_IN_SERVICE) {
134e1c44949Sopenharmony_ci        TELEPHONY_LOGE("Call failed due to no service");
135e1c44949Sopenharmony_ci        DelayedSingleton<CallDialog>::GetInstance()->DialogConnectExtension("CALL_FAILED_NO_SERVICE");
136e1c44949Sopenharmony_ci        return TELEPHONY_ERR_NETWORK_NOT_IN_SERVICE;
137e1c44949Sopenharmony_ci    }
138e1c44949Sopenharmony_ci    ImsRegInfo info;
139e1c44949Sopenharmony_ci    DelayedRefSingleton<CoreServiceClient>::GetInstance().GetImsRegStatus(slotId, ImsServiceType::TYPE_VOICE, info);
140e1c44949Sopenharmony_ci    bool isImsRegistered = info.imsRegState == ImsRegState::IMS_REGISTERED;
141e1c44949Sopenharmony_ci    bool isCTSimCard = false;
142e1c44949Sopenharmony_ci    bool isRoaming = networkState->IsRoaming();
143e1c44949Sopenharmony_ci    DelayedRefSingleton<CoreServiceClient>::GetInstance().IsCTSimCard(slotId, isCTSimCard);
144e1c44949Sopenharmony_ci    if (isCTSimCard && !isRoaming && !isImsRegistered) {
145e1c44949Sopenharmony_ci        TELEPHONY_LOGE("Call failed due to CT card IMS is UNREGISTERED");
146e1c44949Sopenharmony_ci        DelayedSingleton<CallDialog>::GetInstance()->DialogConnectExtension("CALL_FAILED_CTCARD_NO_IMS", slotId);
147e1c44949Sopenharmony_ci        return CALL_ERR_DIAL_FAILED;
148e1c44949Sopenharmony_ci    }
149e1c44949Sopenharmony_ci    return TELEPHONY_SUCCESS;
150e1c44949Sopenharmony_ci}
151e1c44949Sopenharmony_ci
152e1c44949Sopenharmony_ciint32_t CallPolicy::GetAirplaneMode(bool &isAirplaneModeOn)
153e1c44949Sopenharmony_ci{
154e1c44949Sopenharmony_ci    std::shared_ptr<CallDataBaseHelper> callDataPtr = DelayedSingleton<CallDataBaseHelper>::GetInstance();
155e1c44949Sopenharmony_ci    if (callDataPtr == nullptr) {
156e1c44949Sopenharmony_ci        TELEPHONY_LOGE("callDataPtr is nullptr");
157e1c44949Sopenharmony_ci        return TELEPHONY_ERR_LOCAL_PTR_NULL;
158e1c44949Sopenharmony_ci    }
159e1c44949Sopenharmony_ci    return callDataPtr->GetAirplaneMode(isAirplaneModeOn);
160e1c44949Sopenharmony_ci}
161e1c44949Sopenharmony_ci
162e1c44949Sopenharmony_ciint32_t CallPolicy::IsVoiceCallValid(VideoStateType videoState)
163e1c44949Sopenharmony_ci{
164e1c44949Sopenharmony_ci    if (videoState == VideoStateType::TYPE_VOICE) {
165e1c44949Sopenharmony_ci        sptr<CallBase> ringCall = GetOneCallObject(CallRunningState::CALL_RUNNING_STATE_RINGING);
166e1c44949Sopenharmony_ci        if (ringCall != nullptr && ringCall->GetVideoStateType() == VideoStateType::TYPE_VOICE &&
167e1c44949Sopenharmony_ci            ringCall->GetCallType() != CallType::TYPE_VOIP) {
168e1c44949Sopenharmony_ci            TELEPHONY_LOGE("already has new call ringing!");
169e1c44949Sopenharmony_ci            return CALL_ERR_CALL_COUNTS_EXCEED_LIMIT;
170e1c44949Sopenharmony_ci        }
171e1c44949Sopenharmony_ci    }
172e1c44949Sopenharmony_ci    return TELEPHONY_SUCCESS;
173e1c44949Sopenharmony_ci}
174e1c44949Sopenharmony_ci
175e1c44949Sopenharmony_ciint32_t CallPolicy::IsValidCallType(CallType callType)
176e1c44949Sopenharmony_ci{
177e1c44949Sopenharmony_ci    if (callType != CallType::TYPE_CS && callType != CallType::TYPE_IMS && callType != CallType::TYPE_OTT &&
178e1c44949Sopenharmony_ci        callType != CallType::TYPE_SATELLITE) {
179e1c44949Sopenharmony_ci        TELEPHONY_LOGE("invalid call type!");
180e1c44949Sopenharmony_ci        return CALL_ERR_UNKNOW_CALL_TYPE;
181e1c44949Sopenharmony_ci    }
182e1c44949Sopenharmony_ci    return TELEPHONY_SUCCESS;
183e1c44949Sopenharmony_ci}
184e1c44949Sopenharmony_ci
185e1c44949Sopenharmony_ciint32_t CallPolicy::CanDialMulityCall(AppExecFwk::PacMap &extras, bool isEcc)
186e1c44949Sopenharmony_ci{
187e1c44949Sopenharmony_ci    VideoStateType videoState = (VideoStateType)extras.GetIntValue("videoState");
188e1c44949Sopenharmony_ci    if (videoState == VideoStateType::TYPE_VIDEO && HasCellularCallExist()) {
189e1c44949Sopenharmony_ci        TELEPHONY_LOGE("can not dial video call when any call exist!");
190e1c44949Sopenharmony_ci        return CALL_ERR_DIAL_IS_BUSY;
191e1c44949Sopenharmony_ci    }
192e1c44949Sopenharmony_ci    if (!isEcc && videoState == VideoStateType::TYPE_VOICE && HasVideoCall()) {
193e1c44949Sopenharmony_ci        TELEPHONY_LOGE("can not dial video call when any call exist!");
194e1c44949Sopenharmony_ci        return CALL_ERR_DIAL_IS_BUSY;
195e1c44949Sopenharmony_ci    }
196e1c44949Sopenharmony_ci    if (DelayedSingleton<DistributedCommunicationManager>::GetInstance()->IsConnected() &&
197e1c44949Sopenharmony_ci        DelayedSingleton<DistributedCommunicationManager>::GetInstance()->IsSinkRole() &&
198e1c44949Sopenharmony_ci        HasCellularCallExist()) {
199e1c44949Sopenharmony_ci        TELEPHONY_LOGE("dc-call sink can not dial call when any call exist!");
200e1c44949Sopenharmony_ci        return CALL_ERR_CALL_COUNTS_EXCEED_LIMIT;
201e1c44949Sopenharmony_ci    }
202e1c44949Sopenharmony_ci    return TELEPHONY_SUCCESS;
203e1c44949Sopenharmony_ci}
204e1c44949Sopenharmony_ci
205e1c44949Sopenharmony_cibool CallPolicy::IsSupportVideoCall(AppExecFwk::PacMap &extras)
206e1c44949Sopenharmony_ci{
207e1c44949Sopenharmony_ci    bool isSupportVideoCall = true;
208e1c44949Sopenharmony_ci#ifdef ABILITY_CONFIG_SUPPORT
209e1c44949Sopenharmony_ci    isSupportVideoCall = GetCarrierConfig(ITEM_VIDEO_CALL);
210e1c44949Sopenharmony_ci#endif
211e1c44949Sopenharmony_ci    DialScene dialScene = (DialScene)extras.GetIntValue("dialScene");
212e1c44949Sopenharmony_ci    if (dialScene != DialScene::CALL_NORMAL) {
213e1c44949Sopenharmony_ci        TELEPHONY_LOGW("emergency call not support video upgrade");
214e1c44949Sopenharmony_ci        isSupportVideoCall = false;
215e1c44949Sopenharmony_ci    }
216e1c44949Sopenharmony_ci    return isSupportVideoCall;
217e1c44949Sopenharmony_ci}
218e1c44949Sopenharmony_ci
219e1c44949Sopenharmony_ciint32_t CallPolicy::AnswerCallPolicy(int32_t callId, int32_t videoState)
220e1c44949Sopenharmony_ci{
221e1c44949Sopenharmony_ci    if (videoState != static_cast<int32_t>(VideoStateType::TYPE_VOICE) &&
222e1c44949Sopenharmony_ci        videoState != static_cast<int32_t>(VideoStateType::TYPE_VIDEO)) {
223e1c44949Sopenharmony_ci        TELEPHONY_LOGE("videoState is invalid!");
224e1c44949Sopenharmony_ci        return TELEPHONY_ERR_ARGUMENT_INVALID;
225e1c44949Sopenharmony_ci    }
226e1c44949Sopenharmony_ci    if (!IsCallExist(callId)) {
227e1c44949Sopenharmony_ci        TELEPHONY_LOGE("callId is invalid, callId:%{public}d", callId);
228e1c44949Sopenharmony_ci        return TELEPHONY_ERR_ARGUMENT_INVALID;
229e1c44949Sopenharmony_ci    }
230e1c44949Sopenharmony_ci    TelCallState state = GetCallState(callId);
231e1c44949Sopenharmony_ci    if (state != TelCallState::CALL_STATUS_INCOMING && state != TelCallState::CALL_STATUS_WAITING) {
232e1c44949Sopenharmony_ci        TELEPHONY_LOGE("current call state is:%{public}d, accept call not allowed", state);
233e1c44949Sopenharmony_ci        return CALL_ERR_ILLEGAL_CALL_OPERATION;
234e1c44949Sopenharmony_ci    }
235e1c44949Sopenharmony_ci    return TELEPHONY_SUCCESS;
236e1c44949Sopenharmony_ci}
237e1c44949Sopenharmony_ci
238e1c44949Sopenharmony_ciint32_t CallPolicy::RejectCallPolicy(int32_t callId)
239e1c44949Sopenharmony_ci{
240e1c44949Sopenharmony_ci    if (!IsCallExist(callId)) {
241e1c44949Sopenharmony_ci        TELEPHONY_LOGE("callId is invalid, callId:%{public}d", callId);
242e1c44949Sopenharmony_ci        return TELEPHONY_ERR_ARGUMENT_INVALID;
243e1c44949Sopenharmony_ci    }
244e1c44949Sopenharmony_ci    TelCallState state = GetCallState(callId);
245e1c44949Sopenharmony_ci    if (state != TelCallState::CALL_STATUS_INCOMING && state != TelCallState::CALL_STATUS_WAITING) {
246e1c44949Sopenharmony_ci        TELEPHONY_LOGE("current call state is:%{public}d, reject call not allowed", state);
247e1c44949Sopenharmony_ci        return CALL_ERR_ILLEGAL_CALL_OPERATION;
248e1c44949Sopenharmony_ci    }
249e1c44949Sopenharmony_ci    return TELEPHONY_SUCCESS;
250e1c44949Sopenharmony_ci}
251e1c44949Sopenharmony_ci
252e1c44949Sopenharmony_ciint32_t CallPolicy::HoldCallPolicy(int32_t callId)
253e1c44949Sopenharmony_ci{
254e1c44949Sopenharmony_ci    sptr<CallBase> call = GetOneCallObject(callId);
255e1c44949Sopenharmony_ci    if (call == nullptr) {
256e1c44949Sopenharmony_ci        TELEPHONY_LOGE("GetOneCallObject failed, this callId is invalid! callId:%{public}d", callId);
257e1c44949Sopenharmony_ci        return TELEPHONY_ERR_ARGUMENT_INVALID;
258e1c44949Sopenharmony_ci    }
259e1c44949Sopenharmony_ci    if (call->GetCallRunningState() != CallRunningState::CALL_RUNNING_STATE_ACTIVE) {
260e1c44949Sopenharmony_ci        TELEPHONY_LOGE("this call is not activated! callId:%{public}d", callId);
261e1c44949Sopenharmony_ci        return CALL_ERR_CALL_IS_NOT_ACTIVATED;
262e1c44949Sopenharmony_ci    }
263e1c44949Sopenharmony_ci    return TELEPHONY_SUCCESS;
264e1c44949Sopenharmony_ci}
265e1c44949Sopenharmony_ci
266e1c44949Sopenharmony_ciint32_t CallPolicy::UnHoldCallPolicy(int32_t callId)
267e1c44949Sopenharmony_ci{
268e1c44949Sopenharmony_ci    sptr<CallBase> call = GetOneCallObject(callId);
269e1c44949Sopenharmony_ci    if (call == nullptr) {
270e1c44949Sopenharmony_ci        TELEPHONY_LOGE("GetOneCallObject failed, this callId is invalid! callId:%{public}d", callId);
271e1c44949Sopenharmony_ci        return TELEPHONY_ERR_ARGUMENT_INVALID;
272e1c44949Sopenharmony_ci    }
273e1c44949Sopenharmony_ci    if (call->GetCallRunningState() != CallRunningState::CALL_RUNNING_STATE_HOLD) {
274e1c44949Sopenharmony_ci        TELEPHONY_LOGE("this call is not on holding state! callId:%{public}d", callId);
275e1c44949Sopenharmony_ci        return CALL_ERR_CALL_IS_NOT_ON_HOLDING;
276e1c44949Sopenharmony_ci    }
277e1c44949Sopenharmony_ci    return TELEPHONY_SUCCESS;
278e1c44949Sopenharmony_ci}
279e1c44949Sopenharmony_ci
280e1c44949Sopenharmony_ciint32_t CallPolicy::HangUpPolicy(int32_t callId)
281e1c44949Sopenharmony_ci{
282e1c44949Sopenharmony_ci    if (!IsCallExist(callId)) {
283e1c44949Sopenharmony_ci        TELEPHONY_LOGE("callId is invalid, callId:%{public}d", callId);
284e1c44949Sopenharmony_ci        return TELEPHONY_ERR_ARGUMENT_INVALID;
285e1c44949Sopenharmony_ci    }
286e1c44949Sopenharmony_ci    TelCallState state = GetCallState(callId);
287e1c44949Sopenharmony_ci    if (state == TelCallState::CALL_STATUS_IDLE || state == TelCallState::CALL_STATUS_DISCONNECTING ||
288e1c44949Sopenharmony_ci        state == TelCallState::CALL_STATUS_DISCONNECTED) {
289e1c44949Sopenharmony_ci        TELEPHONY_LOGE("current call state is:%{public}d, hang up call not allowed", state);
290e1c44949Sopenharmony_ci        return CALL_ERR_ILLEGAL_CALL_OPERATION;
291e1c44949Sopenharmony_ci    }
292e1c44949Sopenharmony_ci    return TELEPHONY_SUCCESS;
293e1c44949Sopenharmony_ci}
294e1c44949Sopenharmony_ci
295e1c44949Sopenharmony_ciint32_t CallPolicy::SwitchCallPolicy(int32_t callId)
296e1c44949Sopenharmony_ci{
297e1c44949Sopenharmony_ci    std::list<int32_t> callIdList;
298e1c44949Sopenharmony_ci    if (!IsCallExist(callId)) {
299e1c44949Sopenharmony_ci        TELEPHONY_LOGE("callId is invalid");
300e1c44949Sopenharmony_ci        return TELEPHONY_ERR_ARGUMENT_INVALID;
301e1c44949Sopenharmony_ci    }
302e1c44949Sopenharmony_ci    GetCarrierCallList(callIdList);
303e1c44949Sopenharmony_ci    if (callIdList.size() < onlyTwoCall_) {
304e1c44949Sopenharmony_ci        callIdList.clear();
305e1c44949Sopenharmony_ci        return CALL_ERR_PHONE_CALLS_TOO_FEW;
306e1c44949Sopenharmony_ci    }
307e1c44949Sopenharmony_ci    if (GetCallState(callId) != TelCallState::CALL_STATUS_HOLDING ||
308e1c44949Sopenharmony_ci        IsCallExist(TelCallState::CALL_STATUS_DIALING) || IsCallExist(TelCallState::CALL_STATUS_ALERTING)) {
309e1c44949Sopenharmony_ci        TELEPHONY_LOGE("the call is not on hold, callId:%{public}d", callId);
310e1c44949Sopenharmony_ci        return CALL_ERR_ILLEGAL_CALL_OPERATION;
311e1c44949Sopenharmony_ci    }
312e1c44949Sopenharmony_ci    callIdList.clear();
313e1c44949Sopenharmony_ci    return TELEPHONY_SUCCESS;
314e1c44949Sopenharmony_ci}
315e1c44949Sopenharmony_ci
316e1c44949Sopenharmony_ciint32_t CallPolicy::VideoCallPolicy(int32_t callId)
317e1c44949Sopenharmony_ci{
318e1c44949Sopenharmony_ci    TELEPHONY_LOGI("callid %{public}d", callId);
319e1c44949Sopenharmony_ci    sptr<CallBase> callPtr = CallObjectManager::GetOneCallObject(callId);
320e1c44949Sopenharmony_ci    if (callPtr == nullptr) {
321e1c44949Sopenharmony_ci        TELEPHONY_LOGE("callId is invalid, callId:%{public}d", callId);
322e1c44949Sopenharmony_ci        return TELEPHONY_ERR_ARGUMENT_INVALID;
323e1c44949Sopenharmony_ci    }
324e1c44949Sopenharmony_ci    return TELEPHONY_SUCCESS;
325e1c44949Sopenharmony_ci}
326e1c44949Sopenharmony_ci
327e1c44949Sopenharmony_ciint32_t CallPolicy::StartRttPolicy(int32_t callId)
328e1c44949Sopenharmony_ci{
329e1c44949Sopenharmony_ci    sptr<CallBase> callPtr = CallObjectManager::GetOneCallObject(callId);
330e1c44949Sopenharmony_ci    if (callPtr == nullptr) {
331e1c44949Sopenharmony_ci        TELEPHONY_LOGE("callId is invalid, callId:%{public}d", callId);
332e1c44949Sopenharmony_ci        return CALL_ERR_INVALID_CALLID;
333e1c44949Sopenharmony_ci    }
334e1c44949Sopenharmony_ci    if (callPtr->GetCallType() != CallType::TYPE_IMS) {
335e1c44949Sopenharmony_ci        TELEPHONY_LOGE("calltype is illegal, calltype:%{public}d", callPtr->GetCallType());
336e1c44949Sopenharmony_ci        return CALL_ERR_UNSUPPORTED_NETWORK_TYPE;
337e1c44949Sopenharmony_ci    }
338e1c44949Sopenharmony_ci    TelCallState state = GetCallState(callId);
339e1c44949Sopenharmony_ci    if (state != TelCallState::CALL_STATUS_ACTIVE) {
340e1c44949Sopenharmony_ci        TELEPHONY_LOGE("current call state is:%{public}d, StartRtt not allowed", state);
341e1c44949Sopenharmony_ci        return CALL_ERR_ILLEGAL_CALL_OPERATION;
342e1c44949Sopenharmony_ci    }
343e1c44949Sopenharmony_ci    return TELEPHONY_SUCCESS;
344e1c44949Sopenharmony_ci}
345e1c44949Sopenharmony_ci
346e1c44949Sopenharmony_ciint32_t CallPolicy::StopRttPolicy(int32_t callId)
347e1c44949Sopenharmony_ci{
348e1c44949Sopenharmony_ci    sptr<CallBase> callPtr = CallObjectManager::GetOneCallObject(callId);
349e1c44949Sopenharmony_ci    if (callPtr == nullptr) {
350e1c44949Sopenharmony_ci        TELEPHONY_LOGE("callId is invalid, callId:%{public}d", callId);
351e1c44949Sopenharmony_ci        return CALL_ERR_INVALID_CALLID;
352e1c44949Sopenharmony_ci    }
353e1c44949Sopenharmony_ci    if (callPtr->GetCallType() != CallType::TYPE_IMS) {
354e1c44949Sopenharmony_ci        TELEPHONY_LOGE("calltype is illegal, calltype:%{public}d", callPtr->GetCallType());
355e1c44949Sopenharmony_ci        return CALL_ERR_UNSUPPORTED_NETWORK_TYPE;
356e1c44949Sopenharmony_ci    }
357e1c44949Sopenharmony_ci    TelCallState state = GetCallState(callId);
358e1c44949Sopenharmony_ci    if (state != TelCallState::CALL_STATUS_ACTIVE) {
359e1c44949Sopenharmony_ci        TELEPHONY_LOGE("current call state is:%{public}d, StopRtt not allowed", state);
360e1c44949Sopenharmony_ci        return CALL_ERR_ILLEGAL_CALL_OPERATION;
361e1c44949Sopenharmony_ci    }
362e1c44949Sopenharmony_ci    return TELEPHONY_SUCCESS;
363e1c44949Sopenharmony_ci}
364e1c44949Sopenharmony_ci
365e1c44949Sopenharmony_ciint32_t CallPolicy::IsValidSlotId(int32_t slotId)
366e1c44949Sopenharmony_ci{
367e1c44949Sopenharmony_ci    bool result = DelayedSingleton<CallNumberUtils>::GetInstance()->IsValidSlotId(slotId);
368e1c44949Sopenharmony_ci    if (!result) {
369e1c44949Sopenharmony_ci        TELEPHONY_LOGE("invalid slotId!");
370e1c44949Sopenharmony_ci        return CALL_ERR_INVALID_SLOT_ID;
371e1c44949Sopenharmony_ci    }
372e1c44949Sopenharmony_ci    return TELEPHONY_SUCCESS;
373e1c44949Sopenharmony_ci}
374e1c44949Sopenharmony_ci
375e1c44949Sopenharmony_ciint32_t CallPolicy::EnableVoLtePolicy(int32_t slotId)
376e1c44949Sopenharmony_ci{
377e1c44949Sopenharmony_ci    if (IsValidSlotId(slotId) != TELEPHONY_SUCCESS) {
378e1c44949Sopenharmony_ci        TELEPHONY_LOGE("invalid slotId!");
379e1c44949Sopenharmony_ci        return CALL_ERR_INVALID_SLOT_ID;
380e1c44949Sopenharmony_ci    }
381e1c44949Sopenharmony_ci    return TELEPHONY_SUCCESS;
382e1c44949Sopenharmony_ci}
383e1c44949Sopenharmony_ci
384e1c44949Sopenharmony_ciint32_t CallPolicy::DisableVoLtePolicy(int32_t slotId)
385e1c44949Sopenharmony_ci{
386e1c44949Sopenharmony_ci    if (IsValidSlotId(slotId) != TELEPHONY_SUCCESS) {
387e1c44949Sopenharmony_ci        TELEPHONY_LOGE("invalid slotId!");
388e1c44949Sopenharmony_ci        return CALL_ERR_INVALID_SLOT_ID;
389e1c44949Sopenharmony_ci    }
390e1c44949Sopenharmony_ci    return TELEPHONY_SUCCESS;
391e1c44949Sopenharmony_ci}
392e1c44949Sopenharmony_ci
393e1c44949Sopenharmony_ciint32_t CallPolicy::IsVoLteEnabledPolicy(int32_t slotId)
394e1c44949Sopenharmony_ci{
395e1c44949Sopenharmony_ci    if (IsValidSlotId(slotId) != TELEPHONY_SUCCESS) {
396e1c44949Sopenharmony_ci        TELEPHONY_LOGE("invalid slotId!");
397e1c44949Sopenharmony_ci        return CALL_ERR_INVALID_SLOT_ID;
398e1c44949Sopenharmony_ci    }
399e1c44949Sopenharmony_ci    return TELEPHONY_SUCCESS;
400e1c44949Sopenharmony_ci}
401e1c44949Sopenharmony_ci
402e1c44949Sopenharmony_ciint32_t CallPolicy::VoNRStatePolicy(int32_t slotId, int32_t state)
403e1c44949Sopenharmony_ci{
404e1c44949Sopenharmony_ci    if (IsValidSlotId(slotId) != TELEPHONY_SUCCESS) {
405e1c44949Sopenharmony_ci        TELEPHONY_LOGE("invalid slotId!");
406e1c44949Sopenharmony_ci        return CALL_ERR_INVALID_SLOT_ID;
407e1c44949Sopenharmony_ci    }
408e1c44949Sopenharmony_ci    if (state != static_cast<int32_t>(VoNRState::VONR_STATE_ON) &&
409e1c44949Sopenharmony_ci        state != static_cast<int32_t>(VoNRState::VONR_STATE_OFF)) {
410e1c44949Sopenharmony_ci        TELEPHONY_LOGE("invalid state!");
411e1c44949Sopenharmony_ci        return TELEPHONY_ERR_ARGUMENT_INVALID;
412e1c44949Sopenharmony_ci    }
413e1c44949Sopenharmony_ci    return TELEPHONY_SUCCESS;
414e1c44949Sopenharmony_ci}
415e1c44949Sopenharmony_ci
416e1c44949Sopenharmony_ciint32_t CallPolicy::GetCallWaitingPolicy(int32_t slotId)
417e1c44949Sopenharmony_ci{
418e1c44949Sopenharmony_ci    if (IsValidSlotId(slotId) != TELEPHONY_SUCCESS) {
419e1c44949Sopenharmony_ci        TELEPHONY_LOGE("invalid slotId!");
420e1c44949Sopenharmony_ci        return CALL_ERR_INVALID_SLOT_ID;
421e1c44949Sopenharmony_ci    }
422e1c44949Sopenharmony_ci    return TELEPHONY_SUCCESS;
423e1c44949Sopenharmony_ci}
424e1c44949Sopenharmony_ci
425e1c44949Sopenharmony_ciint32_t CallPolicy::SetCallWaitingPolicy(int32_t slotId)
426e1c44949Sopenharmony_ci{
427e1c44949Sopenharmony_ci    if (IsValidSlotId(slotId) != TELEPHONY_SUCCESS) {
428e1c44949Sopenharmony_ci        TELEPHONY_LOGE("invalid slotId!");
429e1c44949Sopenharmony_ci        return CALL_ERR_INVALID_SLOT_ID;
430e1c44949Sopenharmony_ci    }
431e1c44949Sopenharmony_ci    return TELEPHONY_SUCCESS;
432e1c44949Sopenharmony_ci}
433e1c44949Sopenharmony_ci
434e1c44949Sopenharmony_ciint32_t CallPolicy::GetCallRestrictionPolicy(int32_t slotId)
435e1c44949Sopenharmony_ci{
436e1c44949Sopenharmony_ci    if (IsValidSlotId(slotId) != TELEPHONY_SUCCESS) {
437e1c44949Sopenharmony_ci        TELEPHONY_LOGE("invalid slotId!");
438e1c44949Sopenharmony_ci        return CALL_ERR_INVALID_SLOT_ID;
439e1c44949Sopenharmony_ci    }
440e1c44949Sopenharmony_ci    return TELEPHONY_SUCCESS;
441e1c44949Sopenharmony_ci}
442e1c44949Sopenharmony_ci
443e1c44949Sopenharmony_ciint32_t CallPolicy::SetCallRestrictionPolicy(int32_t slotId)
444e1c44949Sopenharmony_ci{
445e1c44949Sopenharmony_ci    if (IsValidSlotId(slotId) != TELEPHONY_SUCCESS) {
446e1c44949Sopenharmony_ci        TELEPHONY_LOGE("invalid slotId!");
447e1c44949Sopenharmony_ci        return CALL_ERR_INVALID_SLOT_ID;
448e1c44949Sopenharmony_ci    }
449e1c44949Sopenharmony_ci    return TELEPHONY_SUCCESS;
450e1c44949Sopenharmony_ci}
451e1c44949Sopenharmony_ci
452e1c44949Sopenharmony_ciint32_t CallPolicy::GetCallTransferInfoPolicy(int32_t slotId)
453e1c44949Sopenharmony_ci{
454e1c44949Sopenharmony_ci    if (IsValidSlotId(slotId) != TELEPHONY_SUCCESS) {
455e1c44949Sopenharmony_ci        TELEPHONY_LOGE("invalid slotId!");
456e1c44949Sopenharmony_ci        return CALL_ERR_INVALID_SLOT_ID;
457e1c44949Sopenharmony_ci    }
458e1c44949Sopenharmony_ci    return TELEPHONY_SUCCESS;
459e1c44949Sopenharmony_ci}
460e1c44949Sopenharmony_ci
461e1c44949Sopenharmony_ciint32_t CallPolicy::SetCallTransferInfoPolicy(int32_t slotId)
462e1c44949Sopenharmony_ci{
463e1c44949Sopenharmony_ci    if (IsValidSlotId(slotId) != TELEPHONY_SUCCESS) {
464e1c44949Sopenharmony_ci        TELEPHONY_LOGE("invalid slotId!");
465e1c44949Sopenharmony_ci        return CALL_ERR_INVALID_SLOT_ID;
466e1c44949Sopenharmony_ci    }
467e1c44949Sopenharmony_ci    return TELEPHONY_SUCCESS;
468e1c44949Sopenharmony_ci}
469e1c44949Sopenharmony_ci
470e1c44949Sopenharmony_ciint32_t CallPolicy::SetCallPreferenceModePolicy(int32_t slotId)
471e1c44949Sopenharmony_ci{
472e1c44949Sopenharmony_ci    if (IsValidSlotId(slotId) != TELEPHONY_SUCCESS) {
473e1c44949Sopenharmony_ci        TELEPHONY_LOGE("invalid slotId!");
474e1c44949Sopenharmony_ci        return CALL_ERR_INVALID_SLOT_ID;
475e1c44949Sopenharmony_ci    }
476e1c44949Sopenharmony_ci    return TELEPHONY_SUCCESS;
477e1c44949Sopenharmony_ci}
478e1c44949Sopenharmony_ci
479e1c44949Sopenharmony_ciint32_t CallPolicy::GetImsConfigPolicy(int32_t slotId)
480e1c44949Sopenharmony_ci{
481e1c44949Sopenharmony_ci    if (IsValidSlotId(slotId) != TELEPHONY_SUCCESS) {
482e1c44949Sopenharmony_ci        TELEPHONY_LOGE("invalid slotId!");
483e1c44949Sopenharmony_ci        return CALL_ERR_INVALID_SLOT_ID;
484e1c44949Sopenharmony_ci    }
485e1c44949Sopenharmony_ci    return TELEPHONY_SUCCESS;
486e1c44949Sopenharmony_ci}
487e1c44949Sopenharmony_ci
488e1c44949Sopenharmony_ciint32_t CallPolicy::SetImsConfigPolicy(int32_t slotId)
489e1c44949Sopenharmony_ci{
490e1c44949Sopenharmony_ci    if (IsValidSlotId(slotId) != TELEPHONY_SUCCESS) {
491e1c44949Sopenharmony_ci        TELEPHONY_LOGE("invalid slotId!");
492e1c44949Sopenharmony_ci        return CALL_ERR_INVALID_SLOT_ID;
493e1c44949Sopenharmony_ci    }
494e1c44949Sopenharmony_ci    return TELEPHONY_SUCCESS;
495e1c44949Sopenharmony_ci}
496e1c44949Sopenharmony_ci
497e1c44949Sopenharmony_ciint32_t CallPolicy::GetImsFeatureValuePolicy(int32_t slotId)
498e1c44949Sopenharmony_ci{
499e1c44949Sopenharmony_ci    if (IsValidSlotId(slotId) != TELEPHONY_SUCCESS) {
500e1c44949Sopenharmony_ci        TELEPHONY_LOGE("invalid slotId!");
501e1c44949Sopenharmony_ci        return CALL_ERR_INVALID_SLOT_ID;
502e1c44949Sopenharmony_ci    }
503e1c44949Sopenharmony_ci    return TELEPHONY_SUCCESS;
504e1c44949Sopenharmony_ci}
505e1c44949Sopenharmony_ci
506e1c44949Sopenharmony_ciint32_t CallPolicy::SetImsFeatureValuePolicy(int32_t slotId)
507e1c44949Sopenharmony_ci{
508e1c44949Sopenharmony_ci    if (IsValidSlotId(slotId) != TELEPHONY_SUCCESS) {
509e1c44949Sopenharmony_ci        TELEPHONY_LOGE("invalid slotId!");
510e1c44949Sopenharmony_ci        return CALL_ERR_INVALID_SLOT_ID;
511e1c44949Sopenharmony_ci    }
512e1c44949Sopenharmony_ci    return TELEPHONY_SUCCESS;
513e1c44949Sopenharmony_ci}
514e1c44949Sopenharmony_ci
515e1c44949Sopenharmony_ciint32_t CallPolicy::InviteToConferencePolicy(int32_t callId, std::vector<std::string> &numberList)
516e1c44949Sopenharmony_ci{
517e1c44949Sopenharmony_ci    if (!IsCallExist(callId)) {
518e1c44949Sopenharmony_ci        TELEPHONY_LOGE("callId is invalid, callId:%{public}d", callId);
519e1c44949Sopenharmony_ci        return TELEPHONY_ERR_ARGUMENT_INVALID;
520e1c44949Sopenharmony_ci    }
521e1c44949Sopenharmony_ci    // check number legality
522e1c44949Sopenharmony_ci    if (numberList.empty()) {
523e1c44949Sopenharmony_ci        TELEPHONY_LOGE("empty phone number list!");
524e1c44949Sopenharmony_ci        return CALL_ERR_PHONE_NUMBER_EMPTY;
525e1c44949Sopenharmony_ci    }
526e1c44949Sopenharmony_ci    for (size_t index = 0; index < numberList.size(); ++index) {
527e1c44949Sopenharmony_ci        if (numberList[index].empty()) {
528e1c44949Sopenharmony_ci            TELEPHONY_LOGE("empty phone number !");
529e1c44949Sopenharmony_ci            return CALL_ERR_PHONE_NUMBER_EMPTY;
530e1c44949Sopenharmony_ci        }
531e1c44949Sopenharmony_ci        if (numberList[index].length() > kMaxNumberLen) {
532e1c44949Sopenharmony_ci            TELEPHONY_LOGE("phone number too long !");
533e1c44949Sopenharmony_ci            return CALL_ERR_NUMBER_OUT_OF_RANGE;
534e1c44949Sopenharmony_ci        }
535e1c44949Sopenharmony_ci    }
536e1c44949Sopenharmony_ci    if (DelayedSingleton<ImsConference>::GetInstance()->GetMainCall() != callId) {
537e1c44949Sopenharmony_ci        TELEPHONY_LOGE("conference with main callId %{public}d not exist", callId);
538e1c44949Sopenharmony_ci        return CALL_ERR_CONFERENCE_NOT_EXISTS;
539e1c44949Sopenharmony_ci    }
540e1c44949Sopenharmony_ci    return TELEPHONY_SUCCESS;
541e1c44949Sopenharmony_ci}
542e1c44949Sopenharmony_ci
543e1c44949Sopenharmony_ciint32_t CallPolicy::CloseUnFinishedUssdPolicy(int32_t slotId)
544e1c44949Sopenharmony_ci{
545e1c44949Sopenharmony_ci    if (IsValidSlotId(slotId) != TELEPHONY_SUCCESS) {
546e1c44949Sopenharmony_ci        TELEPHONY_LOGE("invalid slotId!");
547e1c44949Sopenharmony_ci        return CALL_ERR_INVALID_SLOT_ID;
548e1c44949Sopenharmony_ci    }
549e1c44949Sopenharmony_ci    return TELEPHONY_SUCCESS;
550e1c44949Sopenharmony_ci}
551e1c44949Sopenharmony_ci} // namespace Telephony
552e1c44949Sopenharmony_ci} // namespace OHOS
553