• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021-2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "call_policy.h"
17 
18 #include "call_manager_errors.h"
19 #include "telephony_log_wrapper.h"
20 #include "ims_conference.h"
21 
22 #include "call_number_utils.h"
23 
24 namespace OHOS {
25 namespace Telephony {
CallPolicy()26 CallPolicy::CallPolicy() {}
27 
~CallPolicy()28 CallPolicy::~CallPolicy() {}
29 
DialPolicy(std::u16string & number,AppExecFwk::PacMap & extras,bool isEcc)30 int32_t CallPolicy::DialPolicy(std::u16string &number, AppExecFwk::PacMap &extras, bool isEcc)
31 {
32     DialType dialType = (DialType)extras.GetIntValue("dialType");
33     if (dialType != DialType::DIAL_CARRIER_TYPE && dialType != DialType::DIAL_VOICE_MAIL_TYPE &&
34         dialType != DialType::DIAL_OTT_TYPE) {
35         TELEPHONY_LOGE("dial type invalid!");
36         return CALL_ERR_UNKNOW_DIAL_TYPE;
37     }
38     if (dialType == DialType::DIAL_CARRIER_TYPE) {
39         int32_t accountId = extras.GetIntValue("accountId");
40         if (!DelayedSingleton<CallNumberUtils>::GetInstance()->IsValidSlotId(accountId)) {
41             TELEPHONY_LOGE("invalid accountId!");
42             return CALL_ERR_INVALID_SLOT_ID;
43         }
44     }
45     CallType callType = (CallType)extras.GetIntValue("callType");
46     if (callType != CallType::TYPE_CS && callType != CallType::TYPE_IMS && callType != CallType::TYPE_OTT) {
47         TELEPHONY_LOGE("invalid call type!");
48         return CALL_ERR_UNKNOW_CALL_TYPE;
49     }
50     DialScene dialScene = (DialScene)extras.GetIntValue("dialScene");
51     if ((dialScene != DialScene::CALL_NORMAL && dialScene != DialScene::CALL_PRIVILEGED &&
52             dialScene != DialScene::CALL_EMERGENCY) ||
53         (dialScene == DialScene::CALL_NORMAL && isEcc) || (dialScene == DialScene::CALL_EMERGENCY && (!isEcc)) ||
54         (dialType == DialType::DIAL_VOICE_MAIL_TYPE && dialScene == DialScene::CALL_EMERGENCY)) {
55         TELEPHONY_LOGE("invalid dial scene!");
56         return CALL_ERR_INVALID_DIAL_SCENE;
57     }
58     VideoStateType videoState = (VideoStateType)extras.GetIntValue("videoState");
59     if (videoState != VideoStateType::TYPE_VOICE && videoState != VideoStateType::TYPE_VIDEO) {
60         TELEPHONY_LOGE("invalid video state!");
61         return CALL_ERR_INVALID_VIDEO_STATE;
62     }
63     return HasNewCall();
64 }
65 
AnswerCallPolicy(int32_t callId,int32_t videoState)66 int32_t CallPolicy::AnswerCallPolicy(int32_t callId, int32_t videoState)
67 {
68     if (videoState != static_cast<int32_t>(VideoStateType::TYPE_VOICE) &&
69         videoState != static_cast<int32_t>(VideoStateType::TYPE_VIDEO)) {
70         TELEPHONY_LOGE("videoState is invalid!");
71         return TELEPHONY_ERR_ARGUMENT_INVALID;
72     }
73     if (!IsCallExist(callId)) {
74         TELEPHONY_LOGE("callId is invalid, callId:%{public}d", callId);
75         return TELEPHONY_ERR_ARGUMENT_INVALID;
76     }
77     TelCallState state = GetCallState(callId);
78     if (state != TelCallState::CALL_STATUS_INCOMING && state != TelCallState::CALL_STATUS_WAITING) {
79         TELEPHONY_LOGE("current call state is:%{public}d, accept call not allowed", state);
80         return CALL_ERR_ILLEGAL_CALL_OPERATION;
81     }
82     return TELEPHONY_SUCCESS;
83 }
84 
RejectCallPolicy(int32_t callId)85 int32_t CallPolicy::RejectCallPolicy(int32_t callId)
86 {
87     if (!IsCallExist(callId)) {
88         TELEPHONY_LOGE("callId is invalid, callId:%{public}d", callId);
89         return TELEPHONY_ERR_ARGUMENT_INVALID;
90     }
91     TelCallState state = GetCallState(callId);
92     if (state != TelCallState::CALL_STATUS_INCOMING && state != TelCallState::CALL_STATUS_WAITING) {
93         TELEPHONY_LOGE("current call state is:%{public}d, reject call not allowed", state);
94         return CALL_ERR_ILLEGAL_CALL_OPERATION;
95     }
96     return TELEPHONY_SUCCESS;
97 }
98 
HoldCallPolicy(int32_t callId)99 int32_t CallPolicy::HoldCallPolicy(int32_t callId)
100 {
101     sptr<CallBase> call = GetOneCallObject(callId);
102     if (call == nullptr) {
103         TELEPHONY_LOGE("GetOneCallObject failed, this callId is invalid! callId:%{public}d", callId);
104         return TELEPHONY_ERR_ARGUMENT_INVALID;
105     }
106     if (call->GetCallRunningState() != CallRunningState::CALL_RUNNING_STATE_ACTIVE) {
107         TELEPHONY_LOGE("this call is not activated! callId:%{public}d", callId);
108         return CALL_ERR_CALL_IS_NOT_ACTIVATED;
109     }
110     return TELEPHONY_SUCCESS;
111 }
112 
UnHoldCallPolicy(int32_t callId)113 int32_t CallPolicy::UnHoldCallPolicy(int32_t callId)
114 {
115     sptr<CallBase> call = GetOneCallObject(callId);
116     if (call == nullptr) {
117         TELEPHONY_LOGE("GetOneCallObject failed, this callId is invalid! callId:%{public}d", callId);
118         return TELEPHONY_ERR_ARGUMENT_INVALID;
119     }
120     if (call->GetCallRunningState() != CallRunningState::CALL_RUNNING_STATE_HOLD) {
121         TELEPHONY_LOGE("this call is not on holding state! callId:%{public}d", callId);
122         return CALL_ERR_CALL_IS_NOT_ON_HOLDING;
123     }
124     return TELEPHONY_SUCCESS;
125 }
126 
HangUpPolicy(int32_t callId)127 int32_t CallPolicy::HangUpPolicy(int32_t callId)
128 {
129     if (!IsCallExist(callId)) {
130         TELEPHONY_LOGE("callId is invalid, callId:%{public}d", callId);
131         return TELEPHONY_ERR_ARGUMENT_INVALID;
132     }
133     TelCallState state = GetCallState(callId);
134     if (state == TelCallState::CALL_STATUS_IDLE || state == TelCallState::CALL_STATUS_DISCONNECTING ||
135         state == TelCallState::CALL_STATUS_DISCONNECTED) {
136         TELEPHONY_LOGE("current call state is:%{public}d, hang up call not allowed", state);
137         return CALL_ERR_ILLEGAL_CALL_OPERATION;
138     }
139     return TELEPHONY_SUCCESS;
140 }
141 
SwitchCallPolicy(int32_t callId)142 int32_t CallPolicy::SwitchCallPolicy(int32_t callId)
143 {
144     std::list<int32_t> callIdList;
145     if (!IsCallExist(callId)) {
146         TELEPHONY_LOGE("callId is invalid");
147         return TELEPHONY_ERR_ARGUMENT_INVALID;
148     }
149     GetCarrierCallList(callIdList);
150     if (callIdList.size() < onlyTwoCall_) {
151         callIdList.clear();
152         return CALL_ERR_PHONE_CALLS_TOO_FEW;
153     }
154     if (GetCallState(callId) != TelCallState::CALL_STATUS_HOLDING ||
155         IsCallExist(TelCallState::CALL_STATUS_DIALING) || IsCallExist(TelCallState::CALL_STATUS_ALERTING)) {
156         TELEPHONY_LOGE("the call is not on hold, callId:%{public}d", callId);
157         return CALL_ERR_ILLEGAL_CALL_OPERATION;
158     }
159     callIdList.clear();
160     return TELEPHONY_SUCCESS;
161 }
162 
UpdateCallMediaModePolicy(int32_t callId,ImsCallMode mode)163 int32_t CallPolicy::UpdateCallMediaModePolicy(int32_t callId, ImsCallMode mode)
164 {
165     TELEPHONY_LOGI("callid %{public}d, mode:%{public}d", callId, mode);
166     sptr<CallBase> callPtr = CallObjectManager::GetOneCallObject(callId);
167     if (callPtr == nullptr) {
168         TELEPHONY_LOGE("callId is invalid, callId:%{public}d", callId);
169         return TELEPHONY_ERR_ARGUMENT_INVALID;
170     }
171     if (callPtr->GetCallType() != CallType::TYPE_IMS && callPtr->GetCallType() != CallType::TYPE_OTT) {
172         TELEPHONY_LOGE("calltype is illegal, calltype:%{public}d", callPtr->GetCallType());
173         return CALL_ERR_VIDEO_ILLEGAL_CALL_TYPE;
174     }
175     return TELEPHONY_SUCCESS;
176 }
177 
StartRttPolicy(int32_t callId)178 int32_t CallPolicy::StartRttPolicy(int32_t callId)
179 {
180     sptr<CallBase> callPtr = CallObjectManager::GetOneCallObject(callId);
181     if (callPtr == nullptr) {
182         TELEPHONY_LOGE("callId is invalid, callId:%{public}d", callId);
183         return CALL_ERR_INVALID_CALLID;
184     }
185     if (callPtr->GetCallType() != CallType::TYPE_IMS) {
186         TELEPHONY_LOGE("calltype is illegal, calltype:%{public}d", callPtr->GetCallType());
187         return CALL_ERR_UNSUPPORTED_NETWORK_TYPE;
188     }
189     TelCallState state = GetCallState(callId);
190     if (state != TelCallState::CALL_STATUS_ACTIVE) {
191         TELEPHONY_LOGE("current call state is:%{public}d, StartRtt not allowed", state);
192         return CALL_ERR_ILLEGAL_CALL_OPERATION;
193     }
194     return TELEPHONY_SUCCESS;
195 }
196 
StopRttPolicy(int32_t callId)197 int32_t CallPolicy::StopRttPolicy(int32_t callId)
198 {
199     sptr<CallBase> callPtr = CallObjectManager::GetOneCallObject(callId);
200     if (callPtr == nullptr) {
201         TELEPHONY_LOGE("callId is invalid, callId:%{public}d", callId);
202         return CALL_ERR_INVALID_CALLID;
203     }
204     if (callPtr->GetCallType() != CallType::TYPE_IMS) {
205         TELEPHONY_LOGE("calltype is illegal, calltype:%{public}d", callPtr->GetCallType());
206         return CALL_ERR_UNSUPPORTED_NETWORK_TYPE;
207     }
208     TelCallState state = GetCallState(callId);
209     if (state != TelCallState::CALL_STATUS_ACTIVE) {
210         TELEPHONY_LOGE("current call state is:%{public}d, StopRtt not allowed", state);
211         return CALL_ERR_ILLEGAL_CALL_OPERATION;
212     }
213     return TELEPHONY_SUCCESS;
214 }
215 
IsValidSlotId(int32_t slotId)216 int32_t CallPolicy::IsValidSlotId(int32_t slotId)
217 {
218     bool result = DelayedSingleton<CallNumberUtils>::GetInstance()->IsValidSlotId(slotId);
219     if (!result) {
220         TELEPHONY_LOGE("invalid slotId!");
221         return CALL_ERR_INVALID_SLOT_ID;
222     }
223     return TELEPHONY_SUCCESS;
224 }
225 
EnableVoLtePolicy(int32_t slotId)226 int32_t CallPolicy::EnableVoLtePolicy(int32_t slotId)
227 {
228     if (IsValidSlotId(slotId) != TELEPHONY_SUCCESS) {
229         TELEPHONY_LOGE("invalid slotId!");
230         return CALL_ERR_INVALID_SLOT_ID;
231     }
232     return TELEPHONY_SUCCESS;
233 }
234 
DisableVoLtePolicy(int32_t slotId)235 int32_t CallPolicy::DisableVoLtePolicy(int32_t slotId)
236 {
237     if (IsValidSlotId(slotId) != TELEPHONY_SUCCESS) {
238         TELEPHONY_LOGE("invalid slotId!");
239         return CALL_ERR_INVALID_SLOT_ID;
240     }
241     return TELEPHONY_SUCCESS;
242 }
243 
IsVoLteEnabledPolicy(int32_t slotId)244 int32_t CallPolicy::IsVoLteEnabledPolicy(int32_t slotId)
245 {
246     if (IsValidSlotId(slotId) != TELEPHONY_SUCCESS) {
247         TELEPHONY_LOGE("invalid slotId!");
248         return CALL_ERR_INVALID_SLOT_ID;
249     }
250     return TELEPHONY_SUCCESS;
251 }
252 
GetCallWaitingPolicy(int32_t slotId)253 int32_t CallPolicy::GetCallWaitingPolicy(int32_t slotId)
254 {
255     if (IsValidSlotId(slotId) != TELEPHONY_SUCCESS) {
256         TELEPHONY_LOGE("invalid slotId!");
257         return CALL_ERR_INVALID_SLOT_ID;
258     }
259     return TELEPHONY_SUCCESS;
260 }
261 
SetCallWaitingPolicy(int32_t slotId)262 int32_t CallPolicy::SetCallWaitingPolicy(int32_t slotId)
263 {
264     if (IsValidSlotId(slotId) != TELEPHONY_SUCCESS) {
265         TELEPHONY_LOGE("invalid slotId!");
266         return CALL_ERR_INVALID_SLOT_ID;
267     }
268     return TELEPHONY_SUCCESS;
269 }
270 
GetCallRestrictionPolicy(int32_t slotId)271 int32_t CallPolicy::GetCallRestrictionPolicy(int32_t slotId)
272 {
273     if (IsValidSlotId(slotId) != TELEPHONY_SUCCESS) {
274         TELEPHONY_LOGE("invalid slotId!");
275         return CALL_ERR_INVALID_SLOT_ID;
276     }
277     return TELEPHONY_SUCCESS;
278 }
279 
SetCallRestrictionPolicy(int32_t slotId)280 int32_t CallPolicy::SetCallRestrictionPolicy(int32_t slotId)
281 {
282     if (IsValidSlotId(slotId) != TELEPHONY_SUCCESS) {
283         TELEPHONY_LOGE("invalid slotId!");
284         return CALL_ERR_INVALID_SLOT_ID;
285     }
286     return TELEPHONY_SUCCESS;
287 }
288 
GetCallTransferInfoPolicy(int32_t slotId)289 int32_t CallPolicy::GetCallTransferInfoPolicy(int32_t slotId)
290 {
291     if (IsValidSlotId(slotId) != TELEPHONY_SUCCESS) {
292         TELEPHONY_LOGE("invalid slotId!");
293         return CALL_ERR_INVALID_SLOT_ID;
294     }
295     return TELEPHONY_SUCCESS;
296 }
297 
SetCallTransferInfoPolicy(int32_t slotId)298 int32_t CallPolicy::SetCallTransferInfoPolicy(int32_t slotId)
299 {
300     if (IsValidSlotId(slotId) != TELEPHONY_SUCCESS) {
301         TELEPHONY_LOGE("invalid slotId!");
302         return CALL_ERR_INVALID_SLOT_ID;
303     }
304     return TELEPHONY_SUCCESS;
305 }
306 
SetCallPreferenceModePolicy(int32_t slotId)307 int32_t CallPolicy::SetCallPreferenceModePolicy(int32_t slotId)
308 {
309     if (IsValidSlotId(slotId) != TELEPHONY_SUCCESS) {
310         TELEPHONY_LOGE("invalid slotId!");
311         return CALL_ERR_INVALID_SLOT_ID;
312     }
313     return TELEPHONY_SUCCESS;
314 }
315 
GetImsConfigPolicy(int32_t slotId)316 int32_t CallPolicy::GetImsConfigPolicy(int32_t slotId)
317 {
318     if (IsValidSlotId(slotId) != TELEPHONY_SUCCESS) {
319         TELEPHONY_LOGE("invalid slotId!");
320         return CALL_ERR_INVALID_SLOT_ID;
321     }
322     return TELEPHONY_SUCCESS;
323 }
324 
SetImsConfigPolicy(int32_t slotId)325 int32_t CallPolicy::SetImsConfigPolicy(int32_t slotId)
326 {
327     if (IsValidSlotId(slotId) != TELEPHONY_SUCCESS) {
328         TELEPHONY_LOGE("invalid slotId!");
329         return CALL_ERR_INVALID_SLOT_ID;
330     }
331     return TELEPHONY_SUCCESS;
332 }
333 
GetImsFeatureValuePolicy(int32_t slotId)334 int32_t CallPolicy::GetImsFeatureValuePolicy(int32_t slotId)
335 {
336     if (IsValidSlotId(slotId) != TELEPHONY_SUCCESS) {
337         TELEPHONY_LOGE("invalid slotId!");
338         return CALL_ERR_INVALID_SLOT_ID;
339     }
340     return TELEPHONY_SUCCESS;
341 }
342 
SetImsFeatureValuePolicy(int32_t slotId)343 int32_t CallPolicy::SetImsFeatureValuePolicy(int32_t slotId)
344 {
345     if (IsValidSlotId(slotId) != TELEPHONY_SUCCESS) {
346         TELEPHONY_LOGE("invalid slotId!");
347         return CALL_ERR_INVALID_SLOT_ID;
348     }
349     return TELEPHONY_SUCCESS;
350 }
351 
InviteToConferencePolicy(int32_t callId,std::vector<std::string> & numberList)352 int32_t CallPolicy::InviteToConferencePolicy(int32_t callId, std::vector<std::string> &numberList)
353 {
354     if (!IsCallExist(callId)) {
355         TELEPHONY_LOGE("callId is invalid, callId:%{public}d", callId);
356         return TELEPHONY_ERR_ARGUMENT_INVALID;
357     }
358     // check number legality
359     if (numberList.empty()) {
360         TELEPHONY_LOGE("empty phone number list!");
361         return CALL_ERR_PHONE_NUMBER_EMPTY;
362     }
363     for (size_t index = 0; index < numberList.size(); ++index) {
364         if (numberList[index].empty()) {
365             TELEPHONY_LOGE("empty phone number !");
366             return CALL_ERR_PHONE_NUMBER_EMPTY;
367         }
368         if (numberList[index].length() > kMaxNumberLen) {
369             TELEPHONY_LOGE("phone number too long !");
370             return CALL_ERR_NUMBER_OUT_OF_RANGE;
371         }
372     }
373     if (DelayedSingleton<ImsConference>::GetInstance()->GetMainCall() != callId) {
374         TELEPHONY_LOGE("conference with main callId %{public}d not exist", callId);
375         return CALL_ERR_CONFERENCE_NOT_EXISTS;
376     }
377     return TELEPHONY_SUCCESS;
378 }
379 } // namespace Telephony
380 } // namespace OHOS
381