• 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_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 
GetCallTransferInfo(int32_t slotId,CallTransferType type)90 int32_t CallSettingManager::GetCallTransferInfo(int32_t slotId, CallTransferType type)
91 {
92     int32_t ret = GetCallTransferInfoPolicy(slotId, type);
93     if (ret != TELEPHONY_SUCCESS) {
94         TELEPHONY_LOGE("Invalid data!");
95         return ret;
96     }
97     if (cellularCallConnectionPtr_ == nullptr) {
98         TELEPHONY_LOGE("cellularCallConnectionPtr_ is nullptr!");
99         return TELEPHONY_ERR_LOCAL_PTR_NULL;
100     }
101     return cellularCallConnectionPtr_->GetCallTransferInfo(type, slotId);
102 }
103 
SetCallTransferInfo(int32_t slotId,CallTransferInfo & info)104 int32_t CallSettingManager::SetCallTransferInfo(int32_t slotId, CallTransferInfo &info)
105 {
106     TELEPHONY_LOGI(
107         "SetCallTransferInfo: slotId = %{public}d, settingType = %{public}d, type = %{public}d, transferNum = "
108         "%{public}s",
109         slotId, info.settingType, info.type, info.transferNum);
110     int32_t ret = SetCallTransferInfoPolicy(slotId, info);
111     if (ret != TELEPHONY_SUCCESS) {
112         TELEPHONY_LOGE("Invalid data!");
113         return ret;
114     }
115     if (cellularCallConnectionPtr_ == nullptr) {
116         TELEPHONY_LOGE("cellularCallConnectionPtr_ is nullptr!");
117         return TELEPHONY_ERR_LOCAL_PTR_NULL;
118     }
119     return cellularCallConnectionPtr_->SetCallTransferInfo(info, slotId);
120 }
121 
SetCallPreferenceMode(int32_t slotId,int32_t mode)122 int32_t CallSettingManager::SetCallPreferenceMode(int32_t slotId, int32_t mode)
123 {
124     int32_t preferenceMode = IMS_PS_VOICE_PREFERRED;
125     if (mode != CS_VOICE_ONLY && mode != CS_VOICE_PREFERRED && mode != IMS_PS_VOICE_PREFERRED &&
126         mode != IMS_PS_VOICE_ONLY) {
127         preferenceMode = CS_VOICE_ONLY;
128     }
129     return cellularCallConnectionPtr_->SetCallPreferenceMode(slotId, preferenceMode);
130 }
131 
GetImsConfig(int32_t slotId,ImsConfigItem item)132 int32_t CallSettingManager::GetImsConfig(int32_t slotId, ImsConfigItem item)
133 {
134     return cellularCallConnectionPtr_->GetImsConfig(item, slotId);
135 }
136 
SetImsConfig(int32_t slotId,ImsConfigItem item,std::u16string & value)137 int32_t CallSettingManager::SetImsConfig(int32_t slotId, ImsConfigItem item, std::u16string &value)
138 {
139     if (item == ITEM_VIDEO_QUALITY || item == ITEM_IMS_SWITCH_STATUS) {
140         int32_t flag = CONFIG_FAILED;
141         bool succ = StrToInt(Str16ToStr8(value), flag);
142         if (succ) {
143             return cellularCallConnectionPtr_->SetImsConfig(item, flag, slotId);
144         }
145         return TELEPHONY_ERR_STRTOINT_FAIL;
146     }
147     return cellularCallConnectionPtr_->SetImsConfig(item, Str16ToStr8(value), slotId);
148 }
149 
GetImsFeatureValue(int32_t slotId,FeatureType type)150 int32_t CallSettingManager::GetImsFeatureValue(int32_t slotId, FeatureType type)
151 {
152     if (cellularCallConnectionPtr_ == nullptr) {
153         TELEPHONY_LOGE("cellularCallConnectionPtr_ is nullptr!");
154         return TELEPHONY_ERR_LOCAL_PTR_NULL;
155     }
156     return cellularCallConnectionPtr_->GetImsFeatureValue(type, slotId);
157 }
158 
SetImsFeatureValue(int32_t slotId,FeatureType type,int32_t value)159 int32_t CallSettingManager::SetImsFeatureValue(int32_t slotId, FeatureType type, int32_t value)
160 {
161     if (cellularCallConnectionPtr_ == nullptr) {
162         TELEPHONY_LOGE("cellularCallConnectionPtr_ is nullptr!");
163         return TELEPHONY_ERR_LOCAL_PTR_NULL;
164     }
165     return cellularCallConnectionPtr_->SetImsFeatureValue(type, value, slotId);
166 }
167 
EnableImsSwitch(int32_t slotId)168 int32_t CallSettingManager::EnableImsSwitch(int32_t slotId)
169 {
170     if (cellularCallConnectionPtr_ == nullptr) {
171         TELEPHONY_LOGE("cellularCallConnectionPtr_ is nullptr!");
172         return TELEPHONY_ERR_LOCAL_PTR_NULL;
173     }
174     return cellularCallConnectionPtr_->SetImsSwitchStatus(slotId, true);
175 }
176 
DisableImsSwitch(int32_t slotId)177 int32_t CallSettingManager::DisableImsSwitch(int32_t slotId)
178 {
179     if (cellularCallConnectionPtr_ == nullptr) {
180         TELEPHONY_LOGE("cellularCallConnectionPtr_ is nullptr!");
181         return TELEPHONY_ERR_LOCAL_PTR_NULL;
182     }
183     return cellularCallConnectionPtr_->SetImsSwitchStatus(slotId, false);
184 }
185 
IsImsSwitchEnabled(int32_t slotId,bool & enabled)186 int32_t CallSettingManager::IsImsSwitchEnabled(int32_t slotId, bool &enabled)
187 {
188     if (cellularCallConnectionPtr_ == nullptr) {
189         TELEPHONY_LOGE("cellularCallConnectionPtr_ is nullptr!");
190         return TELEPHONY_ERR_LOCAL_PTR_NULL;
191     }
192     return cellularCallConnectionPtr_->GetImsSwitchStatus(slotId, enabled);
193 }
194 
CallWaitingPolicy(int32_t slotId)195 int32_t CallSettingManager::CallWaitingPolicy(int32_t slotId)
196 {
197     if (!DelayedSingleton<CallNumberUtils>::GetInstance()->IsValidSlotId(slotId)) {
198         TELEPHONY_LOGE("invalid slotId!");
199         return CALL_ERR_INVALID_SLOT_ID;
200     }
201     return TELEPHONY_SUCCESS;
202 }
203 
GetCallRestrictionPolicy(int32_t slotId,CallRestrictionType type)204 int32_t CallSettingManager::GetCallRestrictionPolicy(int32_t slotId, CallRestrictionType type)
205 {
206     if (!DelayedSingleton<CallNumberUtils>::GetInstance()->IsValidSlotId(slotId)) {
207         TELEPHONY_LOGE("invalid slotId!");
208         return CALL_ERR_INVALID_SLOT_ID;
209     }
210     if (type < CallRestrictionType::RESTRICTION_TYPE_ALL_INCOMING ||
211         type > CallRestrictionType::RESTRICTION_TYPE_INCOMING_SERVICES) {
212         TELEPHONY_LOGE("invalid restriction type!");
213         return CALL_ERR_INVALID_RESTRICTION_TYPE;
214     }
215     return TELEPHONY_SUCCESS;
216 }
217 
SetCallRestrictionPolicy(int32_t slotId,CallRestrictionInfo & info)218 int32_t CallSettingManager::SetCallRestrictionPolicy(int32_t slotId, CallRestrictionInfo &info)
219 {
220     if (!DelayedSingleton<CallNumberUtils>::GetInstance()->IsValidSlotId(slotId)) {
221         TELEPHONY_LOGE("invalid slotId!");
222         return CALL_ERR_INVALID_SLOT_ID;
223     }
224     if (info.fac < CallRestrictionType::RESTRICTION_TYPE_ALL_INCOMING ||
225         info.fac > CallRestrictionType::RESTRICTION_TYPE_INCOMING_SERVICES) {
226         TELEPHONY_LOGE("invalid restriction type!");
227         return CALL_ERR_INVALID_RESTRICTION_TYPE;
228     }
229     if (info.mode != CallRestrictionMode::RESTRICTION_MODE_DEACTIVATION &&
230         info.mode != CallRestrictionMode::RESTRICTION_MODE_ACTIVATION) {
231         TELEPHONY_LOGE("invalid restriction mode!");
232         return CALL_ERR_INVALID_RESTRICTION_MODE;
233     }
234     return TELEPHONY_SUCCESS;
235 }
236 
GetCallTransferInfoPolicy(int32_t slotId,CallTransferType type)237 int32_t CallSettingManager::GetCallTransferInfoPolicy(int32_t slotId, CallTransferType type)
238 {
239     if (!DelayedSingleton<CallNumberUtils>::GetInstance()->IsValidSlotId(slotId)) {
240         TELEPHONY_LOGE("invalid slotId!");
241         return CALL_ERR_INVALID_SLOT_ID;
242     }
243     if (type < CallTransferType::TRANSFER_TYPE_UNCONDITIONAL ||
244         type > CallTransferType::TRANSFER_TYPE_NOT_REACHABLE) {
245         TELEPHONY_LOGE("invalid transfer type!");
246         return CALL_ERR_INVALID_TRANSFER_TYPE;
247     }
248     return TELEPHONY_SUCCESS;
249 }
250 
SetCallTransferInfoPolicy(int32_t slotId,CallTransferInfo & info)251 int32_t CallSettingManager::SetCallTransferInfoPolicy(int32_t slotId, CallTransferInfo &info)
252 {
253     if (!DelayedSingleton<CallNumberUtils>::GetInstance()->IsValidSlotId(slotId)) {
254         TELEPHONY_LOGE("invalid slotId!");
255         return CALL_ERR_INVALID_SLOT_ID;
256     }
257     if (info.type < CallTransferType::TRANSFER_TYPE_UNCONDITIONAL ||
258         info.type > CallTransferType::TRANSFER_TYPE_NOT_REACHABLE) {
259         TELEPHONY_LOGE("invalid transfer type!");
260         return CALL_ERR_INVALID_TRANSFER_TYPE;
261     }
262     if (info.settingType != CallTransferSettingType::CALL_TRANSFER_DISABLE &&
263         info.settingType != CallTransferSettingType::CALL_TRANSFER_ENABLE &&
264         info.settingType != CallTransferSettingType::CALL_TRANSFER_REGISTRATION &&
265         info.settingType != CallTransferSettingType::CALL_TRANSFER_ERASURE) {
266         TELEPHONY_LOGE("invalid transfer setting type!");
267         return CALL_ERR_INVALID_TRANSFER_SETTING_TYPE;
268     }
269     if (strlen(info.transferNum) > kMaxNumberLen) {
270         TELEPHONY_LOGE("Number out of limit!");
271         return CALL_ERR_NUMBER_OUT_OF_RANGE;
272     }
273     return TELEPHONY_SUCCESS;
274 }
275 } // namespace Telephony
276 } // namespace OHOS
277