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
SetMuteRequest(int32_t slotId,int32_t mute)150 int32_t ConfigRequest::SetMuteRequest(int32_t slotId, int32_t mute)
151 {
152 if (moduleUtils_.NeedCallImsService()) {
153 TELEPHONY_LOGI("SetMuteRequest, call ims service");
154 if (DelayedSingleton<ImsCallClient>::GetInstance() == nullptr) {
155 TELEPHONY_LOGE("ImsCallClient is nullptr.");
156 return CALL_ERR_RESOURCE_UNAVAILABLE;
157 }
158 return DelayedSingleton<ImsCallClient>::GetInstance()->SetMute(slotId, mute);
159 }
160
161 TELEPHONY_LOGD("SetMuteRequest, ims vendor service does not exist.");
162 auto handle = DelayedSingleton<CellularCallService>::GetInstance()->GetHandler(slotId);
163 if (handle == nullptr) {
164 TELEPHONY_LOGE("SetMuteRequest return, error type: handle is nullptr.");
165 return CALL_ERR_RESOURCE_UNAVAILABLE;
166 }
167 CoreManagerInner::GetInstance().SetMute(slotId, RadioEvent::RADIO_SET_CMUT, mute, handle);
168 return TELEPHONY_SUCCESS;
169 }
170
GetMuteRequest(int32_t slotId)171 int32_t ConfigRequest::GetMuteRequest(int32_t slotId)
172 {
173 if (moduleUtils_.NeedCallImsService()) {
174 TELEPHONY_LOGI("GetMuteRequest, call ims service");
175 if (DelayedSingleton<ImsCallClient>::GetInstance() == nullptr) {
176 TELEPHONY_LOGE("ImsCallClient is nullptr.");
177 return CALL_ERR_RESOURCE_UNAVAILABLE;
178 }
179 return DelayedSingleton<ImsCallClient>::GetInstance()->GetMute(slotId);
180 }
181
182 TELEPHONY_LOGD("GetMuteRequest, ims vendor service does not exist.");
183 auto handle = DelayedSingleton<CellularCallService>::GetInstance()->GetHandler(slotId);
184 if (handle == nullptr) {
185 TELEPHONY_LOGE("GetMuteRequest return, error type: handle is nullptr.");
186 return CALL_ERR_RESOURCE_UNAVAILABLE;
187 }
188 CoreManagerInner::GetInstance().GetMute(slotId, RadioEvent::RADIO_GET_CMUT, handle);
189 return TELEPHONY_SUCCESS;
190 }
191
GetEmergencyCallListRequest(int32_t slotId)192 int32_t ConfigRequest::GetEmergencyCallListRequest(int32_t slotId)
193 {
194 auto handle = DelayedSingleton<CellularCallService>::GetInstance()->GetHandler(slotId);
195 if (handle == nullptr) {
196 TELEPHONY_LOGE("GetEmergencyCallListRequest return, error type: handle is nullptr.");
197 return CALL_ERR_RESOURCE_UNAVAILABLE;
198 }
199 CoreManagerInner::GetInstance().GetEmergencyCallList(slotId, RadioEvent::RADIO_GET_EMERGENCY_CALL_LIST, handle);
200 return TELEPHONY_SUCCESS;
201 }
202
SetEmergencyCallListRequest(int32_t slotId,std::vector<EmergencyCall> & eccVec)203 int32_t ConfigRequest::SetEmergencyCallListRequest(int32_t slotId, std::vector<EmergencyCall> &eccVec)
204 {
205 TELEPHONY_LOGD("SetEmergencyCallListRequest start ");
206 auto handle = DelayedSingleton<CellularCallService>::GetInstance()->GetHandler(slotId);
207 if (handle == nullptr) {
208 TELEPHONY_LOGE("SetEmergencyCallListRequest return, error type: handle is nullptr.");
209 return CALL_ERR_RESOURCE_UNAVAILABLE;
210 }
211 int32_t errorCode = TELEPHONY_ERR_FAIL;
212 errorCode = CoreManagerInner::GetInstance().SetEmergencyCallList(
213 slotId, RadioEvent::RADIO_SET_EMERGENCY_CALL_LIST, eccVec, handle);
214 if (errorCode != TELEPHONY_ERR_SUCCESS) {
215 TELEPHONY_LOGE("SetEmergencyCallListRequest end fail, errorCode: %{public}d", errorCode);
216 }
217 return errorCode;
218 }
219
UpdateImsCapabilities(int32_t slotId,const ImsCapabilityList & imsCapabilityList)220 int32_t ConfigRequest::UpdateImsCapabilities(int32_t slotId, const ImsCapabilityList &imsCapabilityList)
221 {
222 auto imsCallClient = DelayedSingleton<ImsCallClient>::GetInstance();
223 if (imsCallClient == nullptr || imsCallClient->GetImsCallProxy() == nullptr) {
224 TELEPHONY_LOGE("ImsCallClient is nullptr or ims service SA not exists.");
225 return CALL_ERR_RESOURCE_UNAVAILABLE;
226 }
227 for (auto it : imsCapabilityList.imsCapabilities) {
228 TELEPHONY_LOGI("ImsCapabilityType:%{public}d imsRadioTech:%{public}d enable:%{public}d", it.imsCapabilityType,
229 it.imsRadioTech, it.enable);
230 }
231 return imsCallClient->UpdateImsCapabilities(slotId, imsCapabilityList);
232 }
233 } // namespace Telephony
234 } // namespace OHOS
235