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 "supplement_request.h"
17
18 #include "cellular_call_service.h"
19 #include "ims_call_client.h"
20 #include "radio_event.h"
21 #include "telephony_log_wrapper.h"
22 #include "telephony_types.h"
23
24 namespace OHOS {
25 namespace Telephony {
SetClipRequest(int32_t slotId,int32_t action)26 int32_t SupplementRequest::SetClipRequest(int32_t slotId, int32_t action)
27 {
28 TELEPHONY_LOGI("SetClipRequest entry");
29 if (!moduleUtils_.NeedCallImsService()) {
30 TELEPHONY_LOGI("SetClipRequest, NeedCallImsService return false");
31 return TELEPHONY_ERROR;
32 }
33
34 TELEPHONY_LOGI("SetClipRequest, call ims service");
35 if (DelayedSingleton<ImsCallClient>::GetInstance() == nullptr) {
36 TELEPHONY_LOGE("ImsCallClient is nullptr.");
37 return CALL_ERR_RESOURCE_UNAVAILABLE;
38 }
39 return DelayedSingleton<ImsCallClient>::GetInstance()->SetClip(slotId, action);
40 }
41
GetClipRequest(int32_t slotId)42 int32_t SupplementRequest::GetClipRequest(int32_t slotId)
43 {
44 TELEPHONY_LOGI("GetClipRequest entry");
45 if (moduleUtils_.NeedCallImsService()) {
46 TELEPHONY_LOGI("GetClipRequest, call ims service");
47 if (DelayedSingleton<ImsCallClient>::GetInstance() == nullptr) {
48 TELEPHONY_LOGE("ImsCallClient is nullptr.");
49 return CALL_ERR_RESOURCE_UNAVAILABLE;
50 }
51 return DelayedSingleton<ImsCallClient>::GetInstance()->GetClip(slotId);
52 }
53 CoreManagerInner::GetInstance().GetClip(slotId, RadioEvent::RADIO_GET_CALL_CLIP, GetMMIHandler(slotId));
54 return TELEPHONY_SUCCESS;
55 }
56
SetClirRequest(int32_t slotId,int32_t action)57 int32_t SupplementRequest::SetClirRequest(int32_t slotId, int32_t action)
58 {
59 TELEPHONY_LOGI("SetClirRequest entry");
60 if (moduleUtils_.NeedCallImsService()) {
61 TELEPHONY_LOGI("SetClirRequest, call ims service");
62 if (DelayedSingleton<ImsCallClient>::GetInstance() == nullptr) {
63 TELEPHONY_LOGE("ImsCallClient is nullptr.");
64 return CALL_ERR_RESOURCE_UNAVAILABLE;
65 }
66 return DelayedSingleton<ImsCallClient>::GetInstance()->SetClir(slotId, action);
67 }
68 CoreManagerInner::GetInstance().SetClir(slotId, RadioEvent::RADIO_SET_CALL_CLIR, action, GetMMIHandler(slotId));
69 return TELEPHONY_SUCCESS;
70 }
71
GetClirRequest(int32_t slotId)72 int32_t SupplementRequest::GetClirRequest(int32_t slotId)
73 {
74 TELEPHONY_LOGI("GetClirRequest entry");
75 if (moduleUtils_.NeedCallImsService()) {
76 TELEPHONY_LOGI("GetClirRequest, call ims service");
77 if (DelayedSingleton<ImsCallClient>::GetInstance() == nullptr) {
78 TELEPHONY_LOGE("ImsCallClient is nullptr.");
79 return CALL_ERR_RESOURCE_UNAVAILABLE;
80 }
81 return DelayedSingleton<ImsCallClient>::GetInstance()->GetClir(slotId);
82 }
83 CoreManagerInner::GetInstance().GetClir(slotId, RadioEvent::RADIO_GET_CALL_CLIR, GetMMIHandler(slotId));
84 return TELEPHONY_SUCCESS;
85 }
86
GetCallTransferRequest(int32_t slotId,int32_t reason)87 int32_t SupplementRequest::GetCallTransferRequest(int32_t slotId, int32_t reason)
88 {
89 TELEPHONY_LOGI("GetCallTransferRequest entry");
90 if (moduleUtils_.NeedCallImsService()) {
91 TELEPHONY_LOGI("GetCallTransferRequest, call ims service");
92 if (DelayedSingleton<ImsCallClient>::GetInstance() == nullptr) {
93 TELEPHONY_LOGE("ImsCallClient is nullptr.");
94 return CALL_ERR_RESOURCE_UNAVAILABLE;
95 }
96 return DelayedSingleton<ImsCallClient>::GetInstance()->GetCallTransfer(slotId, reason);
97 }
98 CoreManagerInner::GetInstance().GetCallTransferInfo(
99 slotId, RadioEvent::RADIO_GET_CALL_FORWARD, reason, GetMMIHandler(slotId));
100 return TELEPHONY_SUCCESS;
101 }
102
SetCallTransferRequest(int32_t slotId,int32_t action,int32_t reason,const std::string & transferNum,int32_t classType)103 int32_t SupplementRequest::SetCallTransferRequest(
104 int32_t slotId, int32_t action, int32_t reason, const std::string &transferNum, int32_t classType)
105 {
106 TELEPHONY_LOGI("SetCallTransferRequest entry");
107 if (moduleUtils_.NeedCallImsService()) {
108 TELEPHONY_LOGI("SetCallTransferRequest, call ims service");
109 if (DelayedSingleton<ImsCallClient>::GetInstance() == nullptr) {
110 TELEPHONY_LOGE("ImsCallClient is nullptr.");
111 return CALL_ERR_RESOURCE_UNAVAILABLE;
112 }
113 return DelayedSingleton<ImsCallClient>::GetInstance()->SetCallTransfer(
114 slotId, reason, action, transferNum, classType);
115 }
116 CallTransferParam callTransferParam;
117 callTransferParam.mode = action;
118 callTransferParam.reason = reason;
119 callTransferParam.number = transferNum;
120 callTransferParam.classx = classType;
121 CoreManagerInner::GetInstance().SetCallTransferInfo(
122 slotId, RadioEvent::RADIO_SET_CALL_FORWARD, callTransferParam, GetMMIHandler(slotId));
123 return TELEPHONY_SUCCESS;
124 }
125
GetCallRestrictionRequest(int32_t slotId,const std::string & fac)126 int32_t SupplementRequest::GetCallRestrictionRequest(int32_t slotId, const std::string &fac)
127 {
128 TELEPHONY_LOGI("GetCallRestrictionRequest entry");
129 if (moduleUtils_.NeedCallImsService()) {
130 TELEPHONY_LOGI("GetCallRestrictionRequest, call ims service");
131 if (DelayedSingleton<ImsCallClient>::GetInstance() == nullptr) {
132 TELEPHONY_LOGE("ImsCallClient is nullptr.");
133 return CALL_ERR_RESOURCE_UNAVAILABLE;
134 }
135 return DelayedSingleton<ImsCallClient>::GetInstance()->GetCallRestriction(slotId, fac);
136 }
137 CoreManagerInner::GetInstance().GetCallRestriction(
138 slotId, RadioEvent::RADIO_GET_CALL_RESTRICTION, fac, GetMMIHandler(slotId));
139 return TELEPHONY_SUCCESS;
140 }
141
SetCallRestrictionRequest(int32_t slotId,std::string & fac,int32_t mode,std::string & pw)142 int32_t SupplementRequest::SetCallRestrictionRequest(int32_t slotId, std::string &fac, int32_t mode, std::string &pw)
143 {
144 TELEPHONY_LOGI("SetCallRestrictionRequest entry");
145 if (moduleUtils_.NeedCallImsService()) {
146 TELEPHONY_LOGI("SetCallRestrictionRequest, call ims service");
147 if (DelayedSingleton<ImsCallClient>::GetInstance() == nullptr) {
148 TELEPHONY_LOGE("ImsCallClient is nullptr.");
149 return CALL_ERR_RESOURCE_UNAVAILABLE;
150 }
151 return DelayedSingleton<ImsCallClient>::GetInstance()->SetCallRestriction(slotId, fac, mode, pw);
152 }
153 CallRestrictionParam callRestrictionParam;
154 callRestrictionParam.mode = mode;
155 callRestrictionParam.fac = fac;
156 callRestrictionParam.password = pw;
157 CoreManagerInner::GetInstance().SetCallRestriction(
158 slotId, RadioEvent::RADIO_SET_CALL_RESTRICTION, callRestrictionParam, GetMMIHandler(slotId));
159 return TELEPHONY_SUCCESS;
160 }
161
SetCallWaitingRequest(int32_t slotId,bool activate,int32_t classType)162 int32_t SupplementRequest::SetCallWaitingRequest(int32_t slotId, bool activate, int32_t classType)
163 {
164 TELEPHONY_LOGI("SetCallWaitingRequest entry");
165 if (moduleUtils_.NeedCallImsService()) {
166 TELEPHONY_LOGI("SetCallWaitingRequest, call ims service");
167 if (DelayedSingleton<ImsCallClient>::GetInstance() == nullptr) {
168 TELEPHONY_LOGE("ImsCallClient is nullptr.");
169 return CALL_ERR_RESOURCE_UNAVAILABLE;
170 }
171 return DelayedSingleton<ImsCallClient>::GetInstance()->SetCallWaiting(slotId, activate, classType);
172 }
173 CoreManagerInner::GetInstance().SetCallWaiting(
174 slotId, RadioEvent::RADIO_SET_CALL_WAIT, activate, GetMMIHandler(slotId));
175 return TELEPHONY_SUCCESS;
176 }
177
GetCallWaitingRequest(int32_t slotId)178 int32_t SupplementRequest::GetCallWaitingRequest(int32_t slotId)
179 {
180 TELEPHONY_LOGI("GetCallWaitingRequest entry");
181 if (moduleUtils_.NeedCallImsService()) {
182 TELEPHONY_LOGI("GetCallWaitingRequest, call ims service");
183 if (DelayedSingleton<ImsCallClient>::GetInstance() == nullptr) {
184 TELEPHONY_LOGE("ImsCallClient is nullptr.");
185 return CALL_ERR_RESOURCE_UNAVAILABLE;
186 }
187 return DelayedSingleton<ImsCallClient>::GetInstance()->GetCallWaiting(slotId);
188 }
189 CoreManagerInner::GetInstance().GetCallWaiting(slotId, RadioEvent::RADIO_GET_CALL_WAIT, GetMMIHandler(slotId));
190 return TELEPHONY_SUCCESS;
191 }
192
SetColrRequest(int32_t slotId,int32_t presentation)193 int32_t SupplementRequest::SetColrRequest(int32_t slotId, int32_t presentation)
194 {
195 TELEPHONY_LOGI("SetColrRequest entry");
196 if (!moduleUtils_.NeedCallImsService()) {
197 TELEPHONY_LOGI("SetColrRequest, NeedCallImsService return false");
198 return TELEPHONY_ERROR;
199 }
200
201 TELEPHONY_LOGI("SetColrRequest, call ims service");
202 if (DelayedSingleton<ImsCallClient>::GetInstance() == nullptr) {
203 TELEPHONY_LOGE("ImsCallClient is nullptr.");
204 return CALL_ERR_RESOURCE_UNAVAILABLE;
205 }
206 return DelayedSingleton<ImsCallClient>::GetInstance()->SetColr(slotId, presentation);
207 }
208
GetColrRequest(int32_t slotId)209 int32_t SupplementRequest::GetColrRequest(int32_t slotId)
210 {
211 TELEPHONY_LOGI("GetColrRequest entry");
212 if (!moduleUtils_.NeedCallImsService()) {
213 TELEPHONY_LOGI("GetColrRequest, NeedCallImsService return false");
214 return TELEPHONY_ERROR;
215 }
216
217 TELEPHONY_LOGI("GetColrRequest, call ims service");
218 if (DelayedSingleton<ImsCallClient>::GetInstance() == nullptr) {
219 TELEPHONY_LOGE("ImsCallClient is nullptr.");
220 return CALL_ERR_RESOURCE_UNAVAILABLE;
221 }
222 return DelayedSingleton<ImsCallClient>::GetInstance()->GetColr(slotId);
223 }
224
SetColpRequest(int32_t slotId,int32_t action)225 int32_t SupplementRequest::SetColpRequest(int32_t slotId, int32_t action)
226 {
227 TELEPHONY_LOGI("SetColpRequest entry");
228 if (!moduleUtils_.NeedCallImsService()) {
229 TELEPHONY_LOGI("SetColpRequest, NeedCallImsService return false");
230 return TELEPHONY_ERROR;
231 }
232
233 TELEPHONY_LOGI("SetColpRequest, call ims service");
234 if (DelayedSingleton<ImsCallClient>::GetInstance() == nullptr) {
235 TELEPHONY_LOGE("ImsCallClient is nullptr.");
236 return CALL_ERR_RESOURCE_UNAVAILABLE;
237 }
238 return DelayedSingleton<ImsCallClient>::GetInstance()->SetColp(slotId, action);
239 }
240
GetColpRequest(int32_t slotId)241 int32_t SupplementRequest::GetColpRequest(int32_t slotId)
242 {
243 TELEPHONY_LOGI("GetColpRequest entry");
244 if (!moduleUtils_.NeedCallImsService()) {
245 TELEPHONY_LOGI("GetColpRequest, NeedCallImsService return false");
246 return TELEPHONY_ERROR;
247 }
248
249 TELEPHONY_LOGI("GetColpRequest, call ims service");
250 if (DelayedSingleton<ImsCallClient>::GetInstance() == nullptr) {
251 TELEPHONY_LOGE("ImsCallClient is nullptr.");
252 return CALL_ERR_RESOURCE_UNAVAILABLE;
253 }
254 return DelayedSingleton<ImsCallClient>::GetInstance()->GetColp(slotId);
255 }
256
GetMMIHandler(int32_t slotId) const257 std::shared_ptr<CellularCallHandler> SupplementRequest::GetMMIHandler(int32_t slotId) const
258 {
259 auto callService = DelayedSingleton<CellularCallService>::GetInstance();
260 if (callService == nullptr) {
261 TELEPHONY_LOGE("GetMMIHandler return, error type: callService is nullptr.");
262 return nullptr;
263 }
264 return callService->GetHandler(slotId);
265 }
266
SendUssdRequest(int32_t slotId,const std::string & msg)267 int32_t SupplementRequest::SendUssdRequest(int32_t slotId, const std::string &msg)
268 {
269 TELEPHONY_LOGI("SendUssdRequest entry");
270 CoreManagerInner::GetInstance().SetUssd(slotId, RadioEvent::RADIO_SET_USSD, msg, GetMMIHandler(slotId));
271 return TELEPHONY_SUCCESS;
272 }
273
AlterPinPassword(int32_t slotId,std::string newPin,std::string oldPin)274 int32_t SupplementRequest::AlterPinPassword(int32_t slotId, std::string newPin, std::string oldPin)
275 {
276 LockStatusResponse response = { UNLOCK_FAIL, TELEPHONY_ERROR };
277 int32_t result = CoreManagerInner::GetInstance().AlterPin(slotId, newPin, oldPin, response);
278 TELEPHONY_LOGI(
279 "SupplementRequest::AlterPinPassword result: %{public}d, remain: %{public}d", response.result, response.remain);
280 if (result == TELEPHONY_SUCCESS) {
281 std::shared_ptr<CellularCallHandler> ccHandler = GetMMIHandler(slotId);
282 if (ccHandler == nullptr) {
283 TELEPHONY_LOGI("SupplementRequest::AlterPinPassword ccHandler is nullptr.");
284 return TELEPHONY_ERROR;
285 }
286 std::shared_ptr<PinPukResponse> pinResData = std::make_shared<PinPukResponse>();
287 pinResData->result = response.result;
288 pinResData->remain = response.remain;
289 AppExecFwk::InnerEvent::Pointer msgEvent =
290 AppExecFwk::InnerEvent::Get(MMIHandlerId::EVENT_SET_UNLOCK_PIN_PUK_ID, pinResData, 0);
291 ccHandler->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE);
292 return TELEPHONY_SUCCESS;
293 }
294 return TELEPHONY_ERROR;
295 }
296
UnlockPuk(int32_t slotId,std::string newPin,std::string puk)297 int32_t SupplementRequest::UnlockPuk(int32_t slotId, std::string newPin, std::string puk)
298 {
299 LockStatusResponse response = { UNLOCK_FAIL, TELEPHONY_ERROR };
300 int32_t result = CoreManagerInner::GetInstance().UnlockPuk(slotId, newPin, puk, response);
301 TELEPHONY_LOGI(
302 "SupplementRequest::UnlockPuk result: %{public}d, remain: %{public}d", response.result, response.remain);
303 if (result == TELEPHONY_SUCCESS) {
304 std::shared_ptr<CellularCallHandler> ccHandler = GetMMIHandler(slotId);
305 if (ccHandler == nullptr) {
306 TELEPHONY_LOGI("SupplementRequest::UnlockPuk ccHandler is nullptr.");
307 return TELEPHONY_ERROR;
308 }
309 std::shared_ptr<PinPukResponse> pinResData = std::make_shared<PinPukResponse>();
310 pinResData->result = response.result;
311 pinResData->remain = response.remain;
312 AppExecFwk::InnerEvent::Pointer msgEvent =
313 AppExecFwk::InnerEvent::Get(MMIHandlerId::EVENT_SET_UNLOCK_PIN_PUK_ID, pinResData, 0);
314 ccHandler->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE);
315 return TELEPHONY_SUCCESS;
316 }
317 return TELEPHONY_ERROR;
318 }
319
AlterPin2Password(int32_t slotId,std::string newPin2,std::string oldPin2)320 int32_t SupplementRequest::AlterPin2Password(int32_t slotId, std::string newPin2, std::string oldPin2)
321 {
322 LockStatusResponse response = { UNLOCK_FAIL, TELEPHONY_ERROR };
323 int32_t result = CoreManagerInner::GetInstance().AlterPin2(slotId, newPin2, oldPin2, response);
324 TELEPHONY_LOGI("SupplementRequest::AlterPin2Password result: %{public}d, remain: %{public}d", response.result,
325 response.remain);
326 if (result == TELEPHONY_SUCCESS) {
327 std::shared_ptr<CellularCallHandler> ccHandler = GetMMIHandler(slotId);
328 if (ccHandler == nullptr) {
329 TELEPHONY_LOGI("SupplementRequest::AlterPin2Password ccHandler is nullptr.");
330 return TELEPHONY_ERROR;
331 }
332 std::shared_ptr<PinPukResponse> pinResData = std::make_shared<PinPukResponse>();
333 pinResData->result = response.result;
334 pinResData->remain = response.remain;
335 AppExecFwk::InnerEvent::Pointer msgEvent =
336 AppExecFwk::InnerEvent::Get(MMIHandlerId::EVENT_SET_UNLOCK_PIN_PUK_ID, pinResData, 0);
337 ccHandler->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE);
338 return TELEPHONY_SUCCESS;
339 }
340 return TELEPHONY_ERROR;
341 }
342
UnlockPuk2(int32_t slotId,std::string newPin2,std::string puk2)343 int32_t SupplementRequest::UnlockPuk2(int32_t slotId, std::string newPin2, std::string puk2)
344 {
345 LockStatusResponse response = { UNLOCK_FAIL, TELEPHONY_ERROR };
346 int32_t result = CoreManagerInner::GetInstance().UnlockPuk2(slotId, newPin2, puk2, response);
347 TELEPHONY_LOGI(
348 "SupplementRequest::UnlockPuk2 result: %{public}d, remain: %{public}d", response.result, response.remain);
349 if (result == TELEPHONY_SUCCESS) {
350 std::shared_ptr<CellularCallHandler> ccHandler = GetMMIHandler(slotId);
351 if (ccHandler == nullptr) {
352 TELEPHONY_LOGI("SupplementRequest::UnlockPuk2 ccHandler is nullptr.");
353 return TELEPHONY_ERROR;
354 }
355 std::shared_ptr<PinPukResponse> pinResData = std::make_shared<PinPukResponse>();
356 pinResData->result = response.result;
357 pinResData->remain = response.remain;
358 AppExecFwk::InnerEvent::Pointer msgEvent =
359 AppExecFwk::InnerEvent::Get(MMIHandlerId::EVENT_SET_UNLOCK_PIN_PUK_ID, pinResData, 0);
360 ccHandler->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE);
361 return TELEPHONY_SUCCESS;
362 }
363 return TELEPHONY_ERROR;
364 }
365 } // namespace Telephony
366 } // namespace OHOS
367