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_setting_manager.h"
17
18 #include "call_manager_errors.h"
19 #include "telephony_log_wrapper.h"
20
21 #include "call_number_utils.h"
22
23 namespace OHOS {
24 namespace Telephony {
CallSettingManager()25 CallSettingManager::CallSettingManager()
26 : cellularCallConnectionPtr_(DelayedSingleton<CellularCallConnection>::GetInstance())
27 {}
28
~CallSettingManager()29 CallSettingManager::~CallSettingManager() {}
30
GetCallWaiting(int32_t slotId)31 int32_t CallSettingManager::GetCallWaiting(int32_t slotId)
32 {
33 int32_t ret = CallWaitingPolicy(slotId);
34 if (ret != TELEPHONY_SUCCESS) {
35 TELEPHONY_LOGE("Invalid data!");
36 return ret;
37 }
38 if (cellularCallConnectionPtr_ == nullptr) {
39 TELEPHONY_LOGE("cellularCallConnectionPtr_ is nullptr!");
40 return TELEPHONY_ERR_LOCAL_PTR_NULL;
41 }
42 return cellularCallConnectionPtr_->GetCallWaiting(slotId);
43 }
44
SetCallWaiting(int32_t slotId,bool activate)45 int32_t CallSettingManager::SetCallWaiting(int32_t slotId, bool activate)
46 {
47 int32_t ret = CallWaitingPolicy(slotId);
48 if (ret != TELEPHONY_SUCCESS) {
49 TELEPHONY_LOGE("Invalid data!");
50 return ret;
51 }
52 if (cellularCallConnectionPtr_ == nullptr) {
53 TELEPHONY_LOGE("cellularCallConnectionPtr_ is nullptr!");
54 return TELEPHONY_ERR_LOCAL_PTR_NULL;
55 }
56 return cellularCallConnectionPtr_->SetCallWaiting(activate, slotId);
57 }
58
GetCallRestriction(int32_t slotId,CallRestrictionType type)59 int32_t CallSettingManager::GetCallRestriction(int32_t slotId, CallRestrictionType type)
60 {
61 int32_t ret = GetCallRestrictionPolicy(slotId, type);
62 if (ret != TELEPHONY_SUCCESS) {
63 TELEPHONY_LOGE("Invalid data!");
64 return ret;
65 }
66 if (cellularCallConnectionPtr_ == nullptr) {
67 TELEPHONY_LOGE("cellularCallConnectionPtr_ is nullptr!");
68 return TELEPHONY_ERR_LOCAL_PTR_NULL;
69 }
70 return cellularCallConnectionPtr_->GetCallRestriction(type, slotId);
71 }
72
SetCallRestriction(int32_t slotId,CallRestrictionInfo & info)73 int32_t CallSettingManager::SetCallRestriction(int32_t slotId, CallRestrictionInfo &info)
74 {
75 TELEPHONY_LOGI(
76 "SetCallRestriction: slotId = %{public}d, mode = %{public}d, type = %{public}d",
77 slotId, info.mode, info.fac);
78 int32_t ret = SetCallRestrictionPolicy(slotId, info);
79 if (ret != TELEPHONY_SUCCESS) {
80 TELEPHONY_LOGE("Invalid data!");
81 return ret;
82 }
83 if (cellularCallConnectionPtr_ == nullptr) {
84 TELEPHONY_LOGE("cellularCallConnectionPtr_ is nullptr!");
85 return TELEPHONY_ERR_LOCAL_PTR_NULL;
86 }
87 return cellularCallConnectionPtr_->SetCallRestriction(info, slotId);
88 }
89
SetCallRestrictionPassword(int32_t slotId,CallRestrictionType fac,const char * oldPassword,const char * newPassword)90 int32_t CallSettingManager::SetCallRestrictionPassword(
91 int32_t slotId, CallRestrictionType fac, const char *oldPassword, const char *newPassword)
92 {
93 TELEPHONY_LOGI("slotId = %{public}d, fac = %{public}d", slotId, fac);
94 int32_t ret = GetCallRestrictionPolicy(slotId, fac);
95 if (ret != TELEPHONY_SUCCESS) {
96 TELEPHONY_LOGE("Invalid data!");
97 return ret;
98 }
99 if (cellularCallConnectionPtr_ == nullptr) {
100 TELEPHONY_LOGE("cellularCallConnectionPtr_ is nullptr!");
101 return TELEPHONY_ERR_LOCAL_PTR_NULL;
102 }
103 return cellularCallConnectionPtr_->SetCallRestrictionPassword(slotId, fac, oldPassword, newPassword);
104 }
105
GetCallTransferInfo(int32_t slotId,CallTransferType type)106 int32_t CallSettingManager::GetCallTransferInfo(int32_t slotId, CallTransferType type)
107 {
108 int32_t ret = GetCallTransferInfoPolicy(slotId, type);
109 if (ret != TELEPHONY_SUCCESS) {
110 TELEPHONY_LOGE("Invalid data!");
111 return ret;
112 }
113 if (cellularCallConnectionPtr_ == nullptr) {
114 TELEPHONY_LOGE("cellularCallConnectionPtr_ is nullptr!");
115 return TELEPHONY_ERR_LOCAL_PTR_NULL;
116 }
117 return cellularCallConnectionPtr_->GetCallTransferInfo(type, slotId);
118 }
119
SetCallTransferInfo(int32_t slotId,CallTransferInfo & info)120 int32_t CallSettingManager::SetCallTransferInfo(int32_t slotId, CallTransferInfo &info)
121 {
122 TELEPHONY_LOGI(
123 "SetCallTransferInfo: slotId = %{public}d, settingType = %{public}d, type = %{public}d, transferNum = "
124 "%{public}s",
125 slotId, info.settingType, info.type, info.transferNum);
126 int32_t ret = SetCallTransferInfoPolicy(slotId, info);
127 if (ret != TELEPHONY_SUCCESS) {
128 TELEPHONY_LOGE("Invalid data!");
129 return ret;
130 }
131 if (cellularCallConnectionPtr_ == nullptr) {
132 TELEPHONY_LOGE("cellularCallConnectionPtr_ is nullptr!");
133 return TELEPHONY_ERR_LOCAL_PTR_NULL;
134 }
135 return cellularCallConnectionPtr_->SetCallTransferInfo(info, slotId);
136 }
137
CanSetCallTransferTime(int32_t slotId,bool & result)138 int32_t CallSettingManager::CanSetCallTransferTime(int32_t slotId, bool &result)
139 {
140 TELEPHONY_LOGI("[slot%{public}d] entry", slotId);
141 if (cellularCallConnectionPtr_ == nullptr) {
142 TELEPHONY_LOGE("[slot%{public}d] cellularCallConnectionPtr_ is nullptr!", slotId);
143 return TELEPHONY_ERR_LOCAL_PTR_NULL;
144 }
145 return cellularCallConnectionPtr_->CanSetCallTransferTime(slotId, result);
146 }
147
SetCallPreferenceMode(int32_t slotId,int32_t mode)148 int32_t CallSettingManager::SetCallPreferenceMode(int32_t slotId, int32_t mode)
149 {
150 int32_t preferenceMode = IMS_PS_VOICE_PREFERRED;
151 if (mode != CS_VOICE_ONLY && mode != CS_VOICE_PREFERRED && mode != IMS_PS_VOICE_PREFERRED &&
152 mode != IMS_PS_VOICE_ONLY) {
153 preferenceMode = CS_VOICE_ONLY;
154 }
155 return cellularCallConnectionPtr_->SetCallPreferenceMode(slotId, preferenceMode);
156 }
157
GetImsConfig(int32_t slotId,ImsConfigItem item)158 int32_t CallSettingManager::GetImsConfig(int32_t slotId, ImsConfigItem item)
159 {
160 return cellularCallConnectionPtr_->GetImsConfig(item, slotId);
161 }
162
SetImsConfig(int32_t slotId,ImsConfigItem item,std::u16string & value)163 int32_t CallSettingManager::SetImsConfig(int32_t slotId, ImsConfigItem item, std::u16string &value)
164 {
165 if (item == ITEM_VIDEO_QUALITY || item == ITEM_IMS_SWITCH_STATUS) {
166 int32_t flag = CONFIG_FAILED;
167 bool succ = StrToInt(Str16ToStr8(value), flag);
168 if (succ) {
169 return cellularCallConnectionPtr_->SetImsConfig(item, flag, slotId);
170 }
171 return TELEPHONY_ERR_STRTOINT_FAIL;
172 }
173 return cellularCallConnectionPtr_->SetImsConfig(item, Str16ToStr8(value), slotId);
174 }
175
GetImsFeatureValue(int32_t slotId,FeatureType type)176 int32_t CallSettingManager::GetImsFeatureValue(int32_t slotId, FeatureType type)
177 {
178 if (cellularCallConnectionPtr_ == nullptr) {
179 TELEPHONY_LOGE("cellularCallConnectionPtr_ is nullptr!");
180 return TELEPHONY_ERR_LOCAL_PTR_NULL;
181 }
182 return cellularCallConnectionPtr_->GetImsFeatureValue(type, slotId);
183 }
184
SetImsFeatureValue(int32_t slotId,FeatureType type,int32_t value)185 int32_t CallSettingManager::SetImsFeatureValue(int32_t slotId, FeatureType type, int32_t value)
186 {
187 if (cellularCallConnectionPtr_ == nullptr) {
188 TELEPHONY_LOGE("cellularCallConnectionPtr_ is nullptr!");
189 return TELEPHONY_ERR_LOCAL_PTR_NULL;
190 }
191 return cellularCallConnectionPtr_->SetImsFeatureValue(type, value, slotId);
192 }
193
EnableImsSwitch(int32_t slotId)194 int32_t CallSettingManager::EnableImsSwitch(int32_t slotId)
195 {
196 if (cellularCallConnectionPtr_ == nullptr) {
197 TELEPHONY_LOGE("cellularCallConnectionPtr_ is nullptr!");
198 return TELEPHONY_ERR_LOCAL_PTR_NULL;
199 }
200 return cellularCallConnectionPtr_->SetImsSwitchStatus(slotId, true);
201 }
202
DisableImsSwitch(int32_t slotId)203 int32_t CallSettingManager::DisableImsSwitch(int32_t slotId)
204 {
205 if (cellularCallConnectionPtr_ == nullptr) {
206 TELEPHONY_LOGE("cellularCallConnectionPtr_ is nullptr!");
207 return TELEPHONY_ERR_LOCAL_PTR_NULL;
208 }
209 return cellularCallConnectionPtr_->SetImsSwitchStatus(slotId, false);
210 }
211
IsImsSwitchEnabled(int32_t slotId,bool & enabled)212 int32_t CallSettingManager::IsImsSwitchEnabled(int32_t slotId, bool &enabled)
213 {
214 if (cellularCallConnectionPtr_ == nullptr) {
215 TELEPHONY_LOGE("cellularCallConnectionPtr_ is nullptr!");
216 return TELEPHONY_ERR_LOCAL_PTR_NULL;
217 }
218 return cellularCallConnectionPtr_->GetImsSwitchStatus(slotId, enabled);
219 }
220
SetVoNRState(int32_t slotId,int32_t state)221 int32_t CallSettingManager::SetVoNRState(int32_t slotId, int32_t state)
222 {
223 if (cellularCallConnectionPtr_ == nullptr) {
224 TELEPHONY_LOGE("cellularCallConnectionPtr_ is nullptr!");
225 return TELEPHONY_ERR_LOCAL_PTR_NULL;
226 }
227 return cellularCallConnectionPtr_->SetVoNRState(slotId, state);
228 }
229
GetVoNRState(int32_t slotId,int32_t & state)230 int32_t CallSettingManager::GetVoNRState(int32_t slotId, int32_t &state)
231 {
232 if (cellularCallConnectionPtr_ == nullptr) {
233 TELEPHONY_LOGE("cellularCallConnectionPtr_ is nullptr!");
234 return TELEPHONY_ERR_LOCAL_PTR_NULL;
235 }
236 return cellularCallConnectionPtr_->GetVoNRState(slotId, state);
237 }
238
CloseUnFinishedUssd(int32_t slotId)239 int32_t CallSettingManager::CloseUnFinishedUssd(int32_t slotId)
240 {
241 int32_t ret = CloseUnFinishedUssdPolicy(slotId);
242 if (ret != TELEPHONY_SUCCESS) {
243 TELEPHONY_LOGE("Invalid data!");
244 return ret;
245 }
246 if (cellularCallConnectionPtr_ == nullptr) {
247 TELEPHONY_LOGE("cellularCallConnectionPtr_ is nullptr!");
248 return TELEPHONY_ERR_LOCAL_PTR_NULL;
249 }
250 return cellularCallConnectionPtr_->CloseUnFinishedUssd(slotId);
251 }
252
CallWaitingPolicy(int32_t slotId)253 int32_t CallSettingManager::CallWaitingPolicy(int32_t slotId)
254 {
255 if (!DelayedSingleton<CallNumberUtils>::GetInstance()->IsValidSlotId(slotId)) {
256 TELEPHONY_LOGE("invalid slotId!");
257 return CALL_ERR_INVALID_SLOT_ID;
258 }
259 return TELEPHONY_SUCCESS;
260 }
261
GetCallRestrictionPolicy(int32_t slotId,CallRestrictionType type)262 int32_t CallSettingManager::GetCallRestrictionPolicy(int32_t slotId, CallRestrictionType type)
263 {
264 if (!DelayedSingleton<CallNumberUtils>::GetInstance()->IsValidSlotId(slotId)) {
265 TELEPHONY_LOGE("invalid slotId!");
266 return CALL_ERR_INVALID_SLOT_ID;
267 }
268 if (type < CallRestrictionType::RESTRICTION_TYPE_ALL_INCOMING ||
269 type > CallRestrictionType::RESTRICTION_TYPE_INCOMING_SERVICES) {
270 TELEPHONY_LOGE("invalid restriction type!");
271 return CALL_ERR_INVALID_RESTRICTION_TYPE;
272 }
273 return TELEPHONY_SUCCESS;
274 }
275
SetCallRestrictionPolicy(int32_t slotId,CallRestrictionInfo & info)276 int32_t CallSettingManager::SetCallRestrictionPolicy(int32_t slotId, CallRestrictionInfo &info)
277 {
278 if (!DelayedSingleton<CallNumberUtils>::GetInstance()->IsValidSlotId(slotId)) {
279 TELEPHONY_LOGE("invalid slotId!");
280 return CALL_ERR_INVALID_SLOT_ID;
281 }
282 if (info.fac < CallRestrictionType::RESTRICTION_TYPE_ALL_INCOMING ||
283 info.fac > CallRestrictionType::RESTRICTION_TYPE_INCOMING_SERVICES) {
284 TELEPHONY_LOGE("invalid restriction type!");
285 return CALL_ERR_INVALID_RESTRICTION_TYPE;
286 }
287 if (info.mode != CallRestrictionMode::RESTRICTION_MODE_DEACTIVATION &&
288 info.mode != CallRestrictionMode::RESTRICTION_MODE_ACTIVATION) {
289 TELEPHONY_LOGE("invalid restriction mode!");
290 return CALL_ERR_INVALID_RESTRICTION_MODE;
291 }
292 return TELEPHONY_SUCCESS;
293 }
294
GetCallTransferInfoPolicy(int32_t slotId,CallTransferType type)295 int32_t CallSettingManager::GetCallTransferInfoPolicy(int32_t slotId, CallTransferType type)
296 {
297 if (!DelayedSingleton<CallNumberUtils>::GetInstance()->IsValidSlotId(slotId)) {
298 TELEPHONY_LOGE("invalid slotId!");
299 return CALL_ERR_INVALID_SLOT_ID;
300 }
301 if (type < CallTransferType::TRANSFER_TYPE_UNCONDITIONAL ||
302 type > CallTransferType::TRANSFER_TYPE_NOT_REACHABLE) {
303 TELEPHONY_LOGE("invalid transfer type!");
304 return CALL_ERR_INVALID_TRANSFER_TYPE;
305 }
306 return TELEPHONY_SUCCESS;
307 }
308
SetCallTransferInfoPolicy(int32_t slotId,CallTransferInfo & info)309 int32_t CallSettingManager::SetCallTransferInfoPolicy(int32_t slotId, CallTransferInfo &info)
310 {
311 if (!DelayedSingleton<CallNumberUtils>::GetInstance()->IsValidSlotId(slotId)) {
312 TELEPHONY_LOGE("invalid slotId!");
313 return CALL_ERR_INVALID_SLOT_ID;
314 }
315 if (info.type < CallTransferType::TRANSFER_TYPE_UNCONDITIONAL ||
316 info.type > CallTransferType::TRANSFER_TYPE_NOT_REACHABLE) {
317 TELEPHONY_LOGE("invalid transfer type!");
318 return CALL_ERR_INVALID_TRANSFER_TYPE;
319 }
320 if (info.settingType != CallTransferSettingType::CALL_TRANSFER_DISABLE &&
321 info.settingType != CallTransferSettingType::CALL_TRANSFER_ENABLE &&
322 info.settingType != CallTransferSettingType::CALL_TRANSFER_REGISTRATION &&
323 info.settingType != CallTransferSettingType::CALL_TRANSFER_ERASURE) {
324 TELEPHONY_LOGE("invalid transfer setting type!");
325 return CALL_ERR_INVALID_TRANSFER_SETTING_TYPE;
326 }
327 // if haven't transfer the time from app. The default time was 0.
328 if (std::min(info.startHour, info.endHour) < MIN_HOUR || std::max(info.startHour, info.endHour) > MAX_HOUR ||
329 std::min(info.startMinute, info.startMinute) < MIN_MINUTE ||
330 std::max(info.startMinute, info.endMinute) > MAX_MINUTE) {
331 TELEPHONY_LOGE("invalid transfer time!");
332 return CALL_ERR_INVALID_TRANSFER_TIME;
333 }
334 if (strlen(info.transferNum) > kMaxNumberLen) {
335 TELEPHONY_LOGE("Number out of limit!");
336 return CALL_ERR_NUMBER_OUT_OF_RANGE;
337 }
338 return TELEPHONY_SUCCESS;
339 }
340
CloseUnFinishedUssdPolicy(int32_t slotId)341 int32_t CallSettingManager::CloseUnFinishedUssdPolicy(int32_t slotId)
342 {
343 if (!DelayedSingleton<CallNumberUtils>::GetInstance()->IsValidSlotId(slotId)) {
344 TELEPHONY_LOGE("invalid slotId!");
345 return CALL_ERR_INVALID_SLOT_ID;
346 }
347 return TELEPHONY_SUCCESS;
348 }
349 } // namespace Telephony
350 } // namespace OHOS
351