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 "config_request.h"
17
18 #include "call_manager_errors.h"
19 #include "cellular_call_service.h"
20 #include "ims_call_client.h"
21 #include "radio_event.h"
22
23 namespace OHOS {
24 namespace Telephony {
SetDomainPreferenceModeRequest(int32_t slotId,int32_t mode)25 int32_t ConfigRequest::SetDomainPreferenceModeRequest(int32_t slotId, int32_t mode)
26 {
27 if (moduleUtils_.NeedCallImsService()) {
28 TELEPHONY_LOGI("SetDomainPreferenceModeRequest, call ims service");
29 if (DelayedSingleton<ImsCallClient>::GetInstance() == nullptr) {
30 TELEPHONY_LOGE("ImsCallClient is nullptr.");
31 return CALL_ERR_RESOURCE_UNAVAILABLE;
32 }
33 return DelayedSingleton<ImsCallClient>::GetInstance()->SetDomainPreferenceMode(slotId, mode);
34 }
35
36 TELEPHONY_LOGD("SetDomainPreferenceModeRequest, ims vendor service does not exist.");
37 auto handle = DelayedSingleton<CellularCallService>::GetInstance()->GetHandler(slotId);
38 if (handle == nullptr) {
39 TELEPHONY_LOGE("SetDomainPreferenceModeRequest return, error type: handle is nullptr.");
40 return CALL_ERR_RESOURCE_UNAVAILABLE;
41 }
42 CoreManagerInner::GetInstance().SetCallPreferenceMode(
43 slotId, RadioEvent::RADIO_SET_CALL_PREFERENCE_MODE, mode, handle);
44 return TELEPHONY_SUCCESS;
45 }
46
GetDomainPreferenceModeRequest(int32_t slotId)47 int32_t ConfigRequest::GetDomainPreferenceModeRequest(int32_t slotId)
48 {
49 if (moduleUtils_.NeedCallImsService()) {
50 TELEPHONY_LOGI("GetDomainPreferenceModeRequest, call ims service");
51 if (DelayedSingleton<ImsCallClient>::GetInstance() == nullptr) {
52 TELEPHONY_LOGE("ImsCallClient is nullptr.");
53 return CALL_ERR_RESOURCE_UNAVAILABLE;
54 }
55 return DelayedSingleton<ImsCallClient>::GetInstance()->GetDomainPreferenceMode(slotId);
56 }
57
58 TELEPHONY_LOGD("GetDomainPreferenceModeRequest, ims vendor service does not exist.");
59 auto handle = DelayedSingleton<CellularCallService>::GetInstance()->GetHandler(slotId);
60 if (handle == nullptr) {
61 TELEPHONY_LOGE("GetDomainPreferenceModeRequest return, error type: handle is nullptr.");
62 return CALL_ERR_RESOURCE_UNAVAILABLE;
63 }
64 CoreManagerInner::GetInstance().GetCallPreferenceMode(slotId, RadioEvent::RADIO_GET_CALL_PREFERENCE_MODE, handle);
65 return TELEPHONY_SUCCESS;
66 }
67
SetImsSwitchStatusRequest(int32_t slotId,bool active)68 int32_t ConfigRequest::SetImsSwitchStatusRequest(int32_t slotId, bool active)
69 {
70 auto imsCallClient = DelayedSingleton<ImsCallClient>::GetInstance();
71 if (imsCallClient == nullptr || imsCallClient->GetImsCallProxy() == nullptr) {
72 TELEPHONY_LOGE("ImsCallClient is nullptr or ims service SA not exists.");
73 return CALL_ERR_RESOURCE_UNAVAILABLE;
74 }
75 return imsCallClient->SetImsSwitchStatus(slotId, active);
76 }
77
SetCarrierVtConfigRequest(int32_t slotId,bool active)78 int32_t ConfigRequest::SetCarrierVtConfigRequest(int32_t slotId, bool active)
79 {
80 auto imsCallClient = DelayedSingleton<ImsCallClient>::GetInstance();
81 if (imsCallClient == nullptr || imsCallClient->GetImsCallProxy() == nullptr) {
82 TELEPHONY_LOGE("ImsCallClient is nullptr or ims service SA not exists.");
83 return CALL_ERR_RESOURCE_UNAVAILABLE;
84 }
85 return imsCallClient->SetCarrierVtConfig(slotId, active);
86 }
87
SetVoNRSwitchStatusRequest(int32_t slotId,int32_t state)88 int32_t ConfigRequest::SetVoNRSwitchStatusRequest(int32_t slotId, int32_t state)
89 {
90 auto handle = DelayedSingleton<CellularCallService>::GetInstance()->GetHandler(slotId);
91 if (handle == nullptr) {
92 TELEPHONY_LOGE("SetVoNRSwitchStatusRequest return, error type: handle is nullptr.");
93 return CALL_ERR_RESOURCE_UNAVAILABLE;
94 }
95 TELEPHONY_LOGD("slotId: %{public}d, switchState: %{public}d", slotId, state);
96 CoreManagerInner::GetInstance().SetVoNRSwitch(slotId, state, RadioEvent::RADIO_SET_VONR_SWITCH_STATUS, handle);
97 return TELEPHONY_SUCCESS;
98 }
99
GetImsSwitchStatusRequest(int32_t slotId)100 int32_t ConfigRequest::GetImsSwitchStatusRequest(int32_t slotId)
101 {
102 auto imsCallClient = DelayedSingleton<ImsCallClient>::GetInstance();
103 if (imsCallClient == nullptr || imsCallClient->GetImsCallProxy() == nullptr) {
104 TELEPHONY_LOGE("ImsCallClient is nullptr or ims service SA not exists.");
105 return CALL_ERR_RESOURCE_UNAVAILABLE;
106 }
107 return imsCallClient->GetImsSwitchStatus(slotId);
108 }
109
SetImsConfigRequest(ImsConfigItem item,const std::string & value)110 int32_t ConfigRequest::SetImsConfigRequest(ImsConfigItem item, const std::string &value)
111 {
112 auto imsCallClient = DelayedSingleton<ImsCallClient>::GetInstance();
113 if (imsCallClient == nullptr || imsCallClient->GetImsCallProxy() == nullptr) {
114 TELEPHONY_LOGE("ImsCallClient is nullptr or ims service SA not exists.");
115 return CALL_ERR_RESOURCE_UNAVAILABLE;
116 }
117 return imsCallClient->SetImsConfig(item, value);
118 }
119
SetImsConfigRequest(ImsConfigItem item,int32_t value)120 int32_t ConfigRequest::SetImsConfigRequest(ImsConfigItem item, int32_t value)
121 {
122 auto imsCallClient = DelayedSingleton<ImsCallClient>::GetInstance();
123 if (imsCallClient == nullptr || imsCallClient->GetImsCallProxy() == nullptr) {
124 TELEPHONY_LOGE("ImsCallClient is nullptr or ims service SA not exists.");
125 return CALL_ERR_RESOURCE_UNAVAILABLE;
126 }
127 return imsCallClient->SetImsConfig(item, value);
128 }
129
GetImsConfigRequest(ImsConfigItem item)130 int32_t ConfigRequest::GetImsConfigRequest(ImsConfigItem item)
131 {
132 auto imsCallClient = DelayedSingleton<ImsCallClient>::GetInstance();
133 if (imsCallClient == nullptr || imsCallClient->GetImsCallProxy() == nullptr) {
134 TELEPHONY_LOGE("ImsCallClient is nullptr or ims service SA not exists.");
135 return CALL_ERR_RESOURCE_UNAVAILABLE;
136 }
137 return imsCallClient->GetImsConfig(item);
138 }
139
SetImsFeatureValueRequest(FeatureType type,int32_t value)140 int32_t ConfigRequest::SetImsFeatureValueRequest(FeatureType type, int32_t value)
141 {
142 auto imsCallClient = DelayedSingleton<ImsCallClient>::GetInstance();
143 if (imsCallClient == nullptr || imsCallClient->GetImsCallProxy() == nullptr) {
144 TELEPHONY_LOGE("ImsCallClient is nullptr or ims service SA not exists.");
145 return CALL_ERR_RESOURCE_UNAVAILABLE;
146 }
147 return imsCallClient->SetImsFeatureValue(type, value);
148 }
149
GetImsFeatureValueRequest(FeatureType type,int32_t & value)150 int32_t ConfigRequest::GetImsFeatureValueRequest(FeatureType type, int32_t &value)
151 {
152 auto imsCallClient = DelayedSingleton<ImsCallClient>::GetInstance();
153 if (imsCallClient == nullptr || imsCallClient->GetImsCallProxy() == nullptr) {
154 TELEPHONY_LOGE("ImsCallClient is nullptr or ims service SA not exists.");
155 return CALL_ERR_RESOURCE_UNAVAILABLE;
156 }
157 return imsCallClient->GetImsFeatureValue(type, value);
158 }
159
SetMuteRequest(int32_t slotId,int32_t mute)160 int32_t ConfigRequest::SetMuteRequest(int32_t slotId, int32_t mute)
161 {
162 if (moduleUtils_.NeedCallImsService()) {
163 TELEPHONY_LOGI("SetMuteRequest, call ims service");
164 if (DelayedSingleton<ImsCallClient>::GetInstance() == nullptr) {
165 TELEPHONY_LOGE("ImsCallClient is nullptr.");
166 return CALL_ERR_RESOURCE_UNAVAILABLE;
167 }
168 return DelayedSingleton<ImsCallClient>::GetInstance()->SetMute(slotId, mute);
169 }
170
171 TELEPHONY_LOGD("SetMuteRequest, ims vendor service does not exist.");
172 auto handle = DelayedSingleton<CellularCallService>::GetInstance()->GetHandler(slotId);
173 if (handle == nullptr) {
174 TELEPHONY_LOGE("SetMuteRequest return, error type: handle is nullptr.");
175 return CALL_ERR_RESOURCE_UNAVAILABLE;
176 }
177 CoreManagerInner::GetInstance().SetMute(slotId, RadioEvent::RADIO_SET_CMUT, mute, handle);
178 return TELEPHONY_SUCCESS;
179 }
180
GetMuteRequest(int32_t slotId)181 int32_t ConfigRequest::GetMuteRequest(int32_t slotId)
182 {
183 if (moduleUtils_.NeedCallImsService()) {
184 TELEPHONY_LOGI("GetMuteRequest, call ims service");
185 if (DelayedSingleton<ImsCallClient>::GetInstance() == nullptr) {
186 TELEPHONY_LOGE("ImsCallClient is nullptr.");
187 return CALL_ERR_RESOURCE_UNAVAILABLE;
188 }
189 return DelayedSingleton<ImsCallClient>::GetInstance()->GetMute(slotId);
190 }
191
192 TELEPHONY_LOGD("GetMuteRequest, ims vendor service does not exist.");
193 auto handle = DelayedSingleton<CellularCallService>::GetInstance()->GetHandler(slotId);
194 if (handle == nullptr) {
195 TELEPHONY_LOGE("GetMuteRequest return, error type: handle is nullptr.");
196 return CALL_ERR_RESOURCE_UNAVAILABLE;
197 }
198 CoreManagerInner::GetInstance().GetMute(slotId, RadioEvent::RADIO_GET_CMUT, handle);
199 return TELEPHONY_SUCCESS;
200 }
201
GetEmergencyCallListRequest(int32_t slotId)202 int32_t ConfigRequest::GetEmergencyCallListRequest(int32_t slotId)
203 {
204 auto handle = DelayedSingleton<CellularCallService>::GetInstance()->GetHandler(slotId);
205 if (handle == nullptr) {
206 TELEPHONY_LOGE("GetEmergencyCallListRequest return, error type: handle is nullptr.");
207 return CALL_ERR_RESOURCE_UNAVAILABLE;
208 }
209 CoreManagerInner::GetInstance().GetEmergencyCallList(slotId, RadioEvent::RADIO_GET_EMERGENCY_CALL_LIST, handle);
210 return TELEPHONY_SUCCESS;
211 }
212
SetEmergencyCallListRequest(int32_t slotId,std::vector<EmergencyCall> & eccVec)213 int32_t ConfigRequest::SetEmergencyCallListRequest(int32_t slotId, std::vector<EmergencyCall> &eccVec)
214 {
215 TELEPHONY_LOGD("SetEmergencyCallListRequest start ");
216 auto handle = DelayedSingleton<CellularCallService>::GetInstance()->GetHandler(slotId);
217 if (handle == nullptr) {
218 TELEPHONY_LOGE("SetEmergencyCallListRequest return, error type: handle is nullptr.");
219 return CALL_ERR_RESOURCE_UNAVAILABLE;
220 }
221 int32_t errorCode = TELEPHONY_ERR_FAIL;
222 errorCode = CoreManagerInner::GetInstance().SetEmergencyCallList(
223 slotId, RadioEvent::RADIO_SET_EMERGENCY_CALL_LIST, eccVec, handle);
224 if (errorCode != TELEPHONY_ERR_SUCCESS) {
225 TELEPHONY_LOGE("SetEmergencyCallListRequest end fail, errorCode: %{public}d", errorCode);
226 }
227 return errorCode;
228 }
229
UpdateImsCapabilities(int32_t slotId,const ImsCapabilityList & imsCapabilityList)230 int32_t ConfigRequest::UpdateImsCapabilities(int32_t slotId, const ImsCapabilityList &imsCapabilityList)
231 {
232 auto imsCallClient = DelayedSingleton<ImsCallClient>::GetInstance();
233 if (imsCallClient == nullptr || imsCallClient->GetImsCallProxy() == nullptr) {
234 TELEPHONY_LOGE("ImsCallClient is nullptr or ims service SA not exists.");
235 return CALL_ERR_RESOURCE_UNAVAILABLE;
236 }
237 for (auto it : imsCapabilityList.imsCapabilities) {
238 TELEPHONY_LOGI("ImsCapabilityType:%{public}d imsRadioTech:%{public}d enable:%{public}d", it.imsCapabilityType,
239 it.imsRadioTech, it.enable);
240 }
241 return imsCallClient->UpdateImsCapabilities(slotId, imsCapabilityList);
242 }
243
NotifyOperatorConfigChanged(int32_t slotId,int32_t state)244 int32_t ConfigRequest::NotifyOperatorConfigChanged(int32_t slotId, int32_t state)
245 {
246 auto imsCallClient = DelayedSingleton<ImsCallClient>::GetInstance();
247 if (imsCallClient == nullptr || imsCallClient->GetImsCallProxy() == nullptr) {
248 TELEPHONY_LOGE("ImsCallClient is nullptr or ims service SA not exists.");
249 return CALL_ERR_RESOURCE_UNAVAILABLE;
250 }
251 return imsCallClient->NotifyOperatorConfigChanged(slotId, state);
252 }
253
SetVideoCallWaiting(int32_t slotId,bool activate)254 int32_t ConfigRequest::SetVideoCallWaiting(int32_t slotId, bool activate)
255 {
256 auto imsCallClient = DelayedSingleton<ImsCallClient>::GetInstance();
257 if (imsCallClient == nullptr || imsCallClient->GetImsCallProxy() == nullptr) {
258 TELEPHONY_LOGE("ImsCallClient is nullptr or ims service SA not exists.");
259 return CALL_ERR_RESOURCE_UNAVAILABLE;
260 }
261 imsCallClient->SetVideoCallWaiting(slotId, activate);
262 return TELEPHONY_SUCCESS;
263 }
264 } // namespace Telephony
265 } // namespace OHOS
266