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
SetVoNRSwitchStatusRequest(int32_t slotId,int32_t state)78 int32_t ConfigRequest::SetVoNRSwitchStatusRequest(int32_t slotId, int32_t state)
79 {
80 auto handle = DelayedSingleton<CellularCallService>::GetInstance()->GetHandler(slotId);
81 if (handle == nullptr) {
82 TELEPHONY_LOGE("SetVoNRSwitchStatusRequest return, error type: handle is nullptr.");
83 return CALL_ERR_RESOURCE_UNAVAILABLE;
84 }
85 TELEPHONY_LOGD("slotId: %{public}d, switchState: %{public}d", slotId, state);
86 CoreManagerInner::GetInstance().SetVoNRSwitch(slotId, state, RadioEvent::RADIO_SET_VONR_SWITCH_STATUS, handle);
87 return TELEPHONY_SUCCESS;
88 }
89
GetImsSwitchStatusRequest(int32_t slotId)90 int32_t ConfigRequest::GetImsSwitchStatusRequest(int32_t slotId)
91 {
92 auto imsCallClient = DelayedSingleton<ImsCallClient>::GetInstance();
93 if (imsCallClient == nullptr || imsCallClient->GetImsCallProxy() == nullptr) {
94 TELEPHONY_LOGE("ImsCallClient is nullptr or ims service SA not exists.");
95 return CALL_ERR_RESOURCE_UNAVAILABLE;
96 }
97 return imsCallClient->GetImsSwitchStatus(slotId);
98 }
99
SetImsConfigRequest(ImsConfigItem item,const std::string & value)100 int32_t ConfigRequest::SetImsConfigRequest(ImsConfigItem item, const std::string &value)
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->SetImsConfig(item, value);
108 }
109
SetImsConfigRequest(ImsConfigItem item,int32_t value)110 int32_t ConfigRequest::SetImsConfigRequest(ImsConfigItem item, int32_t 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
GetImsConfigRequest(ImsConfigItem item)120 int32_t ConfigRequest::GetImsConfigRequest(ImsConfigItem item)
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->GetImsConfig(item);
128 }
129
SetImsFeatureValueRequest(FeatureType type,int32_t value)130 int32_t ConfigRequest::SetImsFeatureValueRequest(FeatureType type, int32_t value)
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->SetImsFeatureValue(type, value);
138 }
139
GetImsFeatureValueRequest(FeatureType type,int32_t & value)140 int32_t ConfigRequest::GetImsFeatureValueRequest(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->GetImsFeatureValue(type, value);
148 }
149
CtrlCameraRequest(const std::u16string & cameraId,int32_t callingUid,int32_t callingPid)150 int32_t ConfigRequest::CtrlCameraRequest(const std::u16string &cameraId, int32_t callingUid, int32_t callingPid)
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->CtrlCamera(cameraId, callingUid, callingPid);
158 }
159
SetPreviewWindowRequest(int32_t x,int32_t y,int32_t z,int32_t width,int32_t height)160 int32_t ConfigRequest::SetPreviewWindowRequest(int32_t x, int32_t y, int32_t z, int32_t width, int32_t height)
161 {
162 auto imsCallClient = DelayedSingleton<ImsCallClient>::GetInstance();
163 if (imsCallClient == nullptr || imsCallClient->GetImsCallProxy() == nullptr) {
164 TELEPHONY_LOGE("ImsCallClient is nullptr or ims service SA not exists.");
165 return CALL_ERR_RESOURCE_UNAVAILABLE;
166 }
167 return imsCallClient->SetPreviewWindow(x, y, z, width, height);
168 }
169
SetDisplayWindowRequest(int32_t x,int32_t y,int32_t z,int32_t width,int32_t height)170 int32_t ConfigRequest::SetDisplayWindowRequest(int32_t x, int32_t y, int32_t z, int32_t width, int32_t height)
171 {
172 auto imsCallClient = DelayedSingleton<ImsCallClient>::GetInstance();
173 if (imsCallClient == nullptr || imsCallClient->GetImsCallProxy() == nullptr) {
174 TELEPHONY_LOGE("ImsCallClient is nullptr or ims service SA not exists.");
175 return CALL_ERR_RESOURCE_UNAVAILABLE;
176 }
177 return imsCallClient->SetDisplayWindow(x, y, z, width, height);
178 }
179
SetCameraZoomRequest(float zoomRatio)180 int32_t ConfigRequest::SetCameraZoomRequest(float zoomRatio)
181 {
182 auto imsCallClient = DelayedSingleton<ImsCallClient>::GetInstance();
183 if (imsCallClient == nullptr || imsCallClient->GetImsCallProxy() == nullptr) {
184 TELEPHONY_LOGE("ImsCallClient is nullptr or ims service SA not exists.");
185 return CALL_ERR_RESOURCE_UNAVAILABLE;
186 }
187 return imsCallClient->SetCameraZoom(zoomRatio);
188 }
189
SetPauseImageRequest(const std::u16string & path)190 int32_t ConfigRequest::SetPauseImageRequest(const std::u16string &path)
191 {
192 auto imsCallClient = DelayedSingleton<ImsCallClient>::GetInstance();
193 if (imsCallClient == nullptr || imsCallClient->GetImsCallProxy() == nullptr) {
194 TELEPHONY_LOGE("ImsCallClient is nullptr or ims service SA not exists.");
195 return CALL_ERR_RESOURCE_UNAVAILABLE;
196 }
197 return imsCallClient->SetPauseImage(path);
198 }
199
SetDeviceDirectionRequest(int32_t rotation)200 int32_t ConfigRequest::SetDeviceDirectionRequest(int32_t rotation)
201 {
202 auto imsCallClient = DelayedSingleton<ImsCallClient>::GetInstance();
203 if (imsCallClient == nullptr || imsCallClient->GetImsCallProxy() == nullptr) {
204 TELEPHONY_LOGE("ImsCallClient is nullptr or ims service SA not exists.");
205 return CALL_ERR_RESOURCE_UNAVAILABLE;
206 }
207 return imsCallClient->SetDeviceDirection(rotation);
208 }
209
SetMuteRequest(int32_t slotId,int32_t mute)210 int32_t ConfigRequest::SetMuteRequest(int32_t slotId, int32_t mute)
211 {
212 if (moduleUtils_.NeedCallImsService()) {
213 TELEPHONY_LOGI("SetMuteRequest, call ims service");
214 if (DelayedSingleton<ImsCallClient>::GetInstance() == nullptr) {
215 TELEPHONY_LOGE("ImsCallClient is nullptr.");
216 return CALL_ERR_RESOURCE_UNAVAILABLE;
217 }
218 return DelayedSingleton<ImsCallClient>::GetInstance()->SetMute(slotId, mute);
219 }
220
221 TELEPHONY_LOGD("SetMuteRequest, ims vendor service does not exist.");
222 auto handle = DelayedSingleton<CellularCallService>::GetInstance()->GetHandler(slotId);
223 if (handle == nullptr) {
224 TELEPHONY_LOGE("SetMuteRequest return, error type: handle is nullptr.");
225 return CALL_ERR_RESOURCE_UNAVAILABLE;
226 }
227 CoreManagerInner::GetInstance().SetMute(slotId, RadioEvent::RADIO_SET_CMUT, mute, handle);
228 return TELEPHONY_SUCCESS;
229 }
230
GetMuteRequest(int32_t slotId)231 int32_t ConfigRequest::GetMuteRequest(int32_t slotId)
232 {
233 if (moduleUtils_.NeedCallImsService()) {
234 TELEPHONY_LOGI("GetMuteRequest, call ims service");
235 if (DelayedSingleton<ImsCallClient>::GetInstance() == nullptr) {
236 TELEPHONY_LOGE("ImsCallClient is nullptr.");
237 return CALL_ERR_RESOURCE_UNAVAILABLE;
238 }
239 return DelayedSingleton<ImsCallClient>::GetInstance()->GetMute(slotId);
240 }
241
242 TELEPHONY_LOGD("GetMuteRequest, ims vendor service does not exist.");
243 auto handle = DelayedSingleton<CellularCallService>::GetInstance()->GetHandler(slotId);
244 if (handle == nullptr) {
245 TELEPHONY_LOGE("GetMuteRequest return, error type: handle is nullptr.");
246 return CALL_ERR_RESOURCE_UNAVAILABLE;
247 }
248 CoreManagerInner::GetInstance().GetMute(slotId, RadioEvent::RADIO_GET_CMUT, handle);
249 return TELEPHONY_SUCCESS;
250 }
251
GetEmergencyCallListRequest(int32_t slotId)252 int32_t ConfigRequest::GetEmergencyCallListRequest(int32_t slotId)
253 {
254 auto handle = DelayedSingleton<CellularCallService>::GetInstance()->GetHandler(slotId);
255 if (handle == nullptr) {
256 TELEPHONY_LOGE("GetEmergencyCallListRequest return, error type: handle is nullptr.");
257 return CALL_ERR_RESOURCE_UNAVAILABLE;
258 }
259 CoreManagerInner::GetInstance().GetEmergencyCallList(slotId, RadioEvent::RADIO_GET_EMERGENCY_CALL_LIST, handle);
260 return TELEPHONY_SUCCESS;
261 }
262
SetEmergencyCallListRequest(int32_t slotId,std::vector<EmergencyCall> & eccVec)263 int32_t ConfigRequest::SetEmergencyCallListRequest(int32_t slotId, std::vector<EmergencyCall> &eccVec)
264 {
265 TELEPHONY_LOGI("SetEmergencyCallListRequest start ");
266 auto handle = DelayedSingleton<CellularCallService>::GetInstance()->GetHandler(slotId);
267 if (handle == nullptr) {
268 TELEPHONY_LOGE("SetEmergencyCallListRequest return, error type: handle is nullptr.");
269 return CALL_ERR_RESOURCE_UNAVAILABLE;
270 }
271 int32_t errorCode = TELEPHONY_ERR_FAIL;
272 errorCode = CoreManagerInner::GetInstance().SetEmergencyCallList(
273 slotId, RadioEvent::RADIO_SET_EMERGENCY_CALL_LIST, eccVec, handle);
274 TELEPHONY_LOGI("SetEmergencyCallListRequest end %{public}d", errorCode);
275 return errorCode;
276 }
277
UpdateImsCapabilities(int32_t slotId,const ImsCapabilityList & imsCapabilityList)278 int32_t ConfigRequest::UpdateImsCapabilities(int32_t slotId, const ImsCapabilityList &imsCapabilityList)
279 {
280 auto imsCallClient = DelayedSingleton<ImsCallClient>::GetInstance();
281 if (imsCallClient == nullptr || imsCallClient->GetImsCallProxy() == nullptr) {
282 TELEPHONY_LOGE("ImsCallClient is nullptr or ims service SA not exists.");
283 return CALL_ERR_RESOURCE_UNAVAILABLE;
284 }
285 for (auto it : imsCapabilityList.imsCapabilities) {
286 TELEPHONY_LOGI("ImsCapabilityType:%{public}d imsRadioTech:%{public}d enable:%{public}d", it.imsCapabilityType,
287 it.imsRadioTech, it.enable);
288 }
289 return imsCallClient->UpdateImsCapabilities(slotId, imsCapabilityList);
290 }
291 } // namespace Telephony
292 } // namespace OHOS
293