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",
124 slotId, info.settingType, info.type);
125 int32_t ret = SetCallTransferInfoPolicy(slotId, info);
126 if (ret != TELEPHONY_SUCCESS) {
127 TELEPHONY_LOGE("Invalid data!");
128 return ret;
129 }
130 if (cellularCallConnectionPtr_ == nullptr) {
131 TELEPHONY_LOGE("cellularCallConnectionPtr_ is nullptr!");
132 return TELEPHONY_ERR_LOCAL_PTR_NULL;
133 }
134 return cellularCallConnectionPtr_->SetCallTransferInfo(info, slotId);
135 }
136
CanSetCallTransferTime(int32_t slotId,bool & result)137 int32_t CallSettingManager::CanSetCallTransferTime(int32_t slotId, bool &result)
138 {
139 TELEPHONY_LOGI("[slot%{public}d] entry", slotId);
140 if (cellularCallConnectionPtr_ == nullptr) {
141 TELEPHONY_LOGE("[slot%{public}d] cellularCallConnectionPtr_ is nullptr!", slotId);
142 return TELEPHONY_ERR_LOCAL_PTR_NULL;
143 }
144 return cellularCallConnectionPtr_->CanSetCallTransferTime(slotId, result);
145 }
146
SetCallPreferenceMode(int32_t slotId,int32_t mode)147 int32_t CallSettingManager::SetCallPreferenceMode(int32_t slotId, int32_t mode)
148 {
149 int32_t preferenceMode = IMS_PS_VOICE_PREFERRED;
150 if (mode != CS_VOICE_ONLY && mode != CS_VOICE_PREFERRED && mode != IMS_PS_VOICE_PREFERRED &&
151 mode != IMS_PS_VOICE_ONLY) {
152 preferenceMode = CS_VOICE_ONLY;
153 }
154 return cellularCallConnectionPtr_->SetCallPreferenceMode(slotId, preferenceMode);
155 }
156
GetImsConfig(int32_t slotId,ImsConfigItem item)157 int32_t CallSettingManager::GetImsConfig(int32_t slotId, ImsConfigItem item)
158 {
159 return cellularCallConnectionPtr_->GetImsConfig(item, slotId);
160 }
161
SetImsConfig(int32_t slotId,ImsConfigItem item,std::u16string & value)162 int32_t CallSettingManager::SetImsConfig(int32_t slotId, ImsConfigItem item, std::u16string &value)
163 {
164 if (item == ITEM_VIDEO_QUALITY || item == ITEM_IMS_SWITCH_STATUS) {
165 int32_t flag = CONFIG_FAILED;
166 bool succ = StrToInt(Str16ToStr8(value), flag);
167 if (succ) {
168 return cellularCallConnectionPtr_->SetImsConfig(item, flag, slotId);
169 }
170 return TELEPHONY_ERR_STRTOINT_FAIL;
171 }
172 return cellularCallConnectionPtr_->SetImsConfig(item, Str16ToStr8(value), slotId);
173 }
174
GetImsFeatureValue(int32_t slotId,FeatureType type)175 int32_t CallSettingManager::GetImsFeatureValue(int32_t slotId, FeatureType type)
176 {
177 if (cellularCallConnectionPtr_ == nullptr) {
178 TELEPHONY_LOGE("cellularCallConnectionPtr_ is nullptr!");
179 return TELEPHONY_ERR_LOCAL_PTR_NULL;
180 }
181 return cellularCallConnectionPtr_->GetImsFeatureValue(type, slotId);
182 }
183
SetImsFeatureValue(int32_t slotId,FeatureType type,int32_t value)184 int32_t CallSettingManager::SetImsFeatureValue(int32_t slotId, FeatureType type, int32_t value)
185 {
186 if (cellularCallConnectionPtr_ == nullptr) {
187 TELEPHONY_LOGE("cellularCallConnectionPtr_ is nullptr!");
188 return TELEPHONY_ERR_LOCAL_PTR_NULL;
189 }
190 return cellularCallConnectionPtr_->SetImsFeatureValue(type, value, slotId);
191 }
192
EnableImsSwitch(int32_t slotId)193 int32_t CallSettingManager::EnableImsSwitch(int32_t slotId)
194 {
195 if (cellularCallConnectionPtr_ == nullptr) {
196 TELEPHONY_LOGE("cellularCallConnectionPtr_ is nullptr!");
197 return TELEPHONY_ERR_LOCAL_PTR_NULL;
198 }
199 return cellularCallConnectionPtr_->SetImsSwitchStatus(slotId, true);
200 }
201
DisableImsSwitch(int32_t slotId)202 int32_t CallSettingManager::DisableImsSwitch(int32_t slotId)
203 {
204 if (cellularCallConnectionPtr_ == nullptr) {
205 TELEPHONY_LOGE("cellularCallConnectionPtr_ is nullptr!");
206 return TELEPHONY_ERR_LOCAL_PTR_NULL;
207 }
208 return cellularCallConnectionPtr_->SetImsSwitchStatus(slotId, false);
209 }
210
IsImsSwitchEnabled(int32_t slotId,bool & enabled)211 int32_t CallSettingManager::IsImsSwitchEnabled(int32_t slotId, bool &enabled)
212 {
213 if (cellularCallConnectionPtr_ == nullptr) {
214 TELEPHONY_LOGE("cellularCallConnectionPtr_ is nullptr!");
215 return TELEPHONY_ERR_LOCAL_PTR_NULL;
216 }
217 return cellularCallConnectionPtr_->GetImsSwitchStatus(slotId, enabled);
218 }
219
SetVoNRState(int32_t slotId,int32_t state)220 int32_t CallSettingManager::SetVoNRState(int32_t slotId, int32_t state)
221 {
222 if (cellularCallConnectionPtr_ == nullptr) {
223 TELEPHONY_LOGE("cellularCallConnectionPtr_ is nullptr!");
224 return TELEPHONY_ERR_LOCAL_PTR_NULL;
225 }
226 return cellularCallConnectionPtr_->SetVoNRState(slotId, state);
227 }
228
GetVoNRState(int32_t slotId,int32_t & state)229 int32_t CallSettingManager::GetVoNRState(int32_t slotId, int32_t &state)
230 {
231 if (cellularCallConnectionPtr_ == nullptr) {
232 TELEPHONY_LOGE("cellularCallConnectionPtr_ is nullptr!");
233 return TELEPHONY_ERR_LOCAL_PTR_NULL;
234 }
235 return cellularCallConnectionPtr_->GetVoNRState(slotId, state);
236 }
237
CloseUnFinishedUssd(int32_t slotId)238 int32_t CallSettingManager::CloseUnFinishedUssd(int32_t slotId)
239 {
240 int32_t ret = CloseUnFinishedUssdPolicy(slotId);
241 if (ret != TELEPHONY_SUCCESS) {
242 TELEPHONY_LOGE("Invalid data!");
243 return ret;
244 }
245 if (cellularCallConnectionPtr_ == nullptr) {
246 TELEPHONY_LOGE("cellularCallConnectionPtr_ is nullptr!");
247 return TELEPHONY_ERR_LOCAL_PTR_NULL;
248 }
249 return cellularCallConnectionPtr_->CloseUnFinishedUssd(slotId);
250 }
251
CallWaitingPolicy(int32_t slotId)252 int32_t CallSettingManager::CallWaitingPolicy(int32_t slotId)
253 {
254 if (!DelayedSingleton<CallNumberUtils>::GetInstance()->IsValidSlotId(slotId)) {
255 TELEPHONY_LOGE("invalid slotId!");
256 return CALL_ERR_INVALID_SLOT_ID;
257 }
258 return TELEPHONY_SUCCESS;
259 }
260
GetCallRestrictionPolicy(int32_t slotId,CallRestrictionType type)261 int32_t CallSettingManager::GetCallRestrictionPolicy(int32_t slotId, CallRestrictionType type)
262 {
263 if (!DelayedSingleton<CallNumberUtils>::GetInstance()->IsValidSlotId(slotId)) {
264 TELEPHONY_LOGE("invalid slotId!");
265 return CALL_ERR_INVALID_SLOT_ID;
266 }
267 if (type < CallRestrictionType::RESTRICTION_TYPE_ALL_INCOMING ||
268 type > CallRestrictionType::RESTRICTION_TYPE_INCOMING_SERVICES) {
269 TELEPHONY_LOGE("invalid restriction type!");
270 return CALL_ERR_INVALID_RESTRICTION_TYPE;
271 }
272 return TELEPHONY_SUCCESS;
273 }
274
SetCallRestrictionPolicy(int32_t slotId,CallRestrictionInfo & info)275 int32_t CallSettingManager::SetCallRestrictionPolicy(int32_t slotId, CallRestrictionInfo &info)
276 {
277 if (!DelayedSingleton<CallNumberUtils>::GetInstance()->IsValidSlotId(slotId)) {
278 TELEPHONY_LOGE("invalid slotId!");
279 return CALL_ERR_INVALID_SLOT_ID;
280 }
281 if (info.fac < CallRestrictionType::RESTRICTION_TYPE_ALL_INCOMING ||
282 info.fac > CallRestrictionType::RESTRICTION_TYPE_INCOMING_SERVICES) {
283 TELEPHONY_LOGE("invalid restriction type!");
284 return CALL_ERR_INVALID_RESTRICTION_TYPE;
285 }
286 if (info.mode != CallRestrictionMode::RESTRICTION_MODE_DEACTIVATION &&
287 info.mode != CallRestrictionMode::RESTRICTION_MODE_ACTIVATION) {
288 TELEPHONY_LOGE("invalid restriction mode!");
289 return CALL_ERR_INVALID_RESTRICTION_MODE;
290 }
291 return TELEPHONY_SUCCESS;
292 }
293
GetCallTransferInfoPolicy(int32_t slotId,CallTransferType type)294 int32_t CallSettingManager::GetCallTransferInfoPolicy(int32_t slotId, CallTransferType type)
295 {
296 if (!DelayedSingleton<CallNumberUtils>::GetInstance()->IsValidSlotId(slotId)) {
297 TELEPHONY_LOGE("invalid slotId!");
298 return CALL_ERR_INVALID_SLOT_ID;
299 }
300 if (type < CallTransferType::TRANSFER_TYPE_UNCONDITIONAL ||
301 type > CallTransferType::TRANSFER_TYPE_NOT_REACHABLE) {
302 TELEPHONY_LOGE("invalid transfer type!");
303 return CALL_ERR_INVALID_TRANSFER_TYPE;
304 }
305 return TELEPHONY_SUCCESS;
306 }
307
SetCallTransferInfoPolicy(int32_t slotId,CallTransferInfo & info)308 int32_t CallSettingManager::SetCallTransferInfoPolicy(int32_t slotId, CallTransferInfo &info)
309 {
310 if (!DelayedSingleton<CallNumberUtils>::GetInstance()->IsValidSlotId(slotId)) {
311 TELEPHONY_LOGE("invalid slotId!");
312 return CALL_ERR_INVALID_SLOT_ID;
313 }
314 if (info.type < CallTransferType::TRANSFER_TYPE_UNCONDITIONAL ||
315 info.type > CallTransferType::TRANSFER_TYPE_NOT_REACHABLE) {
316 TELEPHONY_LOGE("invalid transfer type!");
317 return CALL_ERR_INVALID_TRANSFER_TYPE;
318 }
319 if (info.settingType != CallTransferSettingType::CALL_TRANSFER_DISABLE &&
320 info.settingType != CallTransferSettingType::CALL_TRANSFER_ENABLE &&
321 info.settingType != CallTransferSettingType::CALL_TRANSFER_REGISTRATION &&
322 info.settingType != CallTransferSettingType::CALL_TRANSFER_ERASURE) {
323 TELEPHONY_LOGE("invalid transfer setting type!");
324 return CALL_ERR_INVALID_TRANSFER_SETTING_TYPE;
325 }
326 // if haven't transfer the time from app. The default time was 0.
327 if (std::min(info.startHour, info.endHour) < MIN_HOUR || std::max(info.startHour, info.endHour) > MAX_HOUR ||
328 std::min(info.startMinute, info.startMinute) < MIN_MINUTE ||
329 std::max(info.startMinute, info.endMinute) > MAX_MINUTE) {
330 TELEPHONY_LOGE("invalid transfer time!");
331 return CALL_ERR_INVALID_TRANSFER_TIME;
332 }
333 if (strlen(info.transferNum) > kMaxNumberLen) {
334 TELEPHONY_LOGE("Number out of limit!");
335 return CALL_ERR_NUMBER_OUT_OF_RANGE;
336 }
337 return TELEPHONY_SUCCESS;
338 }
339
CloseUnFinishedUssdPolicy(int32_t slotId)340 int32_t CallSettingManager::CloseUnFinishedUssdPolicy(int32_t slotId)
341 {
342 if (!DelayedSingleton<CallNumberUtils>::GetInstance()->IsValidSlotId(slotId)) {
343 TELEPHONY_LOGE("invalid slotId!");
344 return CALL_ERR_INVALID_SLOT_ID;
345 }
346 return TELEPHONY_SUCCESS;
347 }
348 } // namespace Telephony
349 } // namespace OHOS
350