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 #include "supplement_request_cs.h"
16
17 #include "cellular_call_service.h"
18 #include "radio_event.h"
19 #include "securec.h"
20 #include "telephony_log_wrapper.h"
21 #include "telephony_types.h"
22
23 namespace OHOS {
24 namespace Telephony {
GetClipRequest(int32_t slotId,int32_t index)25 int32_t SupplementRequestCs::GetClipRequest(int32_t slotId, int32_t index)
26 {
27 TELEPHONY_LOGI("[slot%{public}d] entry", slotId);
28 AppExecFwk::InnerEvent::Pointer response = AppExecFwk::InnerEvent::Get(RadioEvent::RADIO_GET_CALL_CLIP, index);
29 if (response == nullptr) {
30 TELEPHONY_LOGE("[slot%{public}d] response is null!", slotId);
31 return TELEPHONY_ERR_LOCAL_PTR_NULL;
32 }
33 response->SetOwner(GetMMIHandler(slotId));
34 return CoreManagerInner::GetInstance().GetClip(slotId, response);
35 }
36
SetClirRequest(int32_t slotId,int32_t action,int32_t index)37 int32_t SupplementRequestCs::SetClirRequest(int32_t slotId, int32_t action, int32_t index)
38 {
39 TELEPHONY_LOGI("[slot%{public}d] entry", slotId);
40 AppExecFwk::InnerEvent::Pointer response = AppExecFwk::InnerEvent::Get(RadioEvent::RADIO_SET_CALL_CLIR, index);
41 if (response == nullptr) {
42 TELEPHONY_LOGE("[slot%{public}d] response is null!", slotId);
43 return TELEPHONY_ERR_LOCAL_PTR_NULL;
44 }
45 response->SetOwner(GetMMIHandler(slotId));
46 return CoreManagerInner::GetInstance().SetClir(slotId, action, response);
47 }
48
GetClirRequest(int32_t slotId,int32_t index)49 int32_t SupplementRequestCs::GetClirRequest(int32_t slotId, int32_t index)
50 {
51 TELEPHONY_LOGI("[slot%{public}d] entry", slotId);
52 AppExecFwk::InnerEvent::Pointer response = AppExecFwk::InnerEvent::Get(RadioEvent::RADIO_GET_CALL_CLIR, index);
53 if (response == nullptr) {
54 TELEPHONY_LOGE("[slot%{public}d] response is null!", slotId);
55 return TELEPHONY_ERR_LOCAL_PTR_NULL;
56 }
57 response->SetOwner(GetMMIHandler(slotId));
58 return CoreManagerInner::GetInstance().GetClir(slotId, response);
59 }
60
GetCallTransferRequest(int32_t slotId,int32_t reason,int32_t index)61 int32_t SupplementRequestCs::GetCallTransferRequest(int32_t slotId, int32_t reason, int32_t index)
62 {
63 TELEPHONY_LOGI("[slot%{public}d] entry", slotId);
64 AppExecFwk::InnerEvent::Pointer response = AppExecFwk::InnerEvent::Get(RadioEvent::RADIO_GET_CALL_FORWARD, index);
65 if (response == nullptr) {
66 TELEPHONY_LOGE("[slot%{public}d] response is null!", slotId);
67 return TELEPHONY_ERR_LOCAL_PTR_NULL;
68 }
69 response->SetOwner(GetMMIHandler(slotId));
70 return CoreManagerInner::GetInstance().GetCallTransferInfo(slotId, reason, response);
71 }
72
SetCallTransferRequest(int32_t slotId,const CallTransferParam & callTransferParam,int32_t index)73 int32_t SupplementRequestCs::SetCallTransferRequest(
74 int32_t slotId, const CallTransferParam &callTransferParam, int32_t index)
75 {
76 TELEPHONY_LOGI("[slot%{public}d] entry", slotId);
77 AppExecFwk::InnerEvent::Pointer response = AppExecFwk::InnerEvent::Get(RadioEvent::RADIO_SET_CALL_FORWARD, index);
78 if (response == nullptr) {
79 TELEPHONY_LOGE("[slot%{public}d] response is null!", slotId);
80 return TELEPHONY_ERR_LOCAL_PTR_NULL;
81 }
82 response->SetOwner(GetMMIHandler(slotId));
83 return CoreManagerInner::GetInstance().SetCallTransferInfo(slotId, callTransferParam, response);
84 }
85
GetCallRestrictionRequest(int32_t slotId,const std::string & fac,int32_t index)86 int32_t SupplementRequestCs::GetCallRestrictionRequest(int32_t slotId, const std::string &fac, int32_t index)
87 {
88 TELEPHONY_LOGI("[slot%{public}d] entry", slotId);
89 AppExecFwk::InnerEvent::Pointer response =
90 AppExecFwk::InnerEvent::Get(RadioEvent::RADIO_GET_CALL_RESTRICTION, index);
91 if (response == nullptr) {
92 TELEPHONY_LOGE("[slot%{public}d] response is null!", slotId);
93 return TELEPHONY_ERR_LOCAL_PTR_NULL;
94 }
95 response->SetOwner(GetMMIHandler(slotId));
96 return CoreManagerInner::GetInstance().GetCallRestriction(slotId, fac, response);
97 }
98
SetCallRestrictionRequest(int32_t slotId,const std::string & fac,int32_t mode,const std::string & pw,int32_t index)99 int32_t SupplementRequestCs::SetCallRestrictionRequest(
100 int32_t slotId, const std::string &fac, int32_t mode, const std::string &pw, int32_t index)
101 {
102 TELEPHONY_LOGI("[slot%{public}d] entry", slotId);
103 CallRestrictionParam callRestrictionParam;
104 callRestrictionParam.mode = mode;
105 callRestrictionParam.fac = fac;
106 size_t cpyLen = strlen(pw.c_str()) + 1;
107 size_t maxCpyLen = sizeof(callRestrictionParam.password);
108 if (strcpy_s(callRestrictionParam.password, cpyLen > maxCpyLen ? maxCpyLen : cpyLen, pw.c_str()) != EOK) {
109 TELEPHONY_LOGE("[slot%{public}d] strcpy_s fail.", slotId);
110 return TELEPHONY_ERR_STRCPY_FAIL;
111 }
112 AppExecFwk::InnerEvent::Pointer response =
113 AppExecFwk::InnerEvent::Get(RadioEvent::RADIO_SET_CALL_RESTRICTION, index);
114 if (response == nullptr) {
115 TELEPHONY_LOGE("[slot%{public}d] response is null!", slotId);
116 return TELEPHONY_ERR_LOCAL_PTR_NULL;
117 }
118 response->SetOwner(GetMMIHandler(slotId));
119 return CoreManagerInner::GetInstance().SetCallRestriction(slotId, callRestrictionParam, response);
120 }
121
SetBarringPasswordRequest(int32_t slotId,const std::string & restrictionType,int32_t index,const char * oldPassword,const char * newPassword)122 int32_t SupplementRequestCs::SetBarringPasswordRequest(int32_t slotId, const std::string &restrictionType,
123 int32_t index, const char *oldPassword, const char *newPassword)
124 {
125 TELEPHONY_LOGI("[slot%{public}d] entry", slotId);
126 AppExecFwk::InnerEvent::Pointer response =
127 AppExecFwk::InnerEvent::Get(RadioEvent::RADIO_SET_CALL_RESTRICTION_PWD, index);
128 if (response == nullptr) {
129 TELEPHONY_LOGE("[slot%{public}d] response is null!", slotId);
130 return TELEPHONY_ERR_LOCAL_PTR_NULL;
131 }
132 response->SetOwner(GetMMIHandler(slotId));
133 return CoreManagerInner::GetInstance().SetBarringPassword(
134 slotId, oldPassword, newPassword, restrictionType, response);
135 }
136
SetCallWaitingRequest(int32_t slotId,bool activate,int32_t classType,int32_t index)137 int32_t SupplementRequestCs::SetCallWaitingRequest(int32_t slotId, bool activate, int32_t classType, int32_t index)
138 {
139 TELEPHONY_LOGI("[slot%{public}d] entry", slotId);
140 AppExecFwk::InnerEvent::Pointer response = AppExecFwk::InnerEvent::Get(RadioEvent::RADIO_SET_CALL_WAIT, index);
141 if (response == nullptr) {
142 TELEPHONY_LOGE("[slot%{public}d] response is null!", slotId);
143 return TELEPHONY_ERR_LOCAL_PTR_NULL;
144 }
145 response->SetOwner(GetMMIHandler(slotId));
146 return CoreManagerInner::GetInstance().SetCallWaiting(slotId, activate, response);
147 }
148
GetCallWaitingRequest(int32_t slotId,int32_t index)149 int32_t SupplementRequestCs::GetCallWaitingRequest(int32_t slotId, int32_t index)
150 {
151 TELEPHONY_LOGI("[slot%{public}d] entry", slotId);
152 AppExecFwk::InnerEvent::Pointer response = AppExecFwk::InnerEvent::Get(RadioEvent::RADIO_GET_CALL_WAIT, index);
153 if (response == nullptr) {
154 TELEPHONY_LOGE("[slot%{public}d] response is null!", slotId);
155 return TELEPHONY_ERR_LOCAL_PTR_NULL;
156 }
157 response->SetOwner(GetMMIHandler(slotId));
158 return CoreManagerInner::GetInstance().GetCallWaiting(slotId, response);
159 }
160
GetMMIHandler(int32_t slotId) const161 std::shared_ptr<CellularCallHandler> SupplementRequestCs::GetMMIHandler(int32_t slotId) const
162 {
163 auto callService = DelayedSingleton<CellularCallService>::GetInstance();
164 if (callService == nullptr) {
165 TELEPHONY_LOGE("[slot%{public}d] error type: callService is nullptr.", slotId);
166 return nullptr;
167 }
168 return callService->GetHandler(slotId);
169 }
170
SendUssdRequest(int32_t slotId,const std::string & msg)171 int32_t SupplementRequestCs::SendUssdRequest(int32_t slotId, const std::string &msg)
172 {
173 TELEPHONY_LOGI("[slot%{public}d] entry", slotId);
174 return CoreManagerInner::GetInstance().SetUssd(slotId, RadioEvent::RADIO_SET_USSD, msg, GetMMIHandler(slotId));
175 }
176
AlterPinPassword(int32_t slotId,std::string newPin,std::string oldPin)177 int32_t SupplementRequestCs::AlterPinPassword(int32_t slotId, std::string newPin, std::string oldPin)
178 {
179 TELEPHONY_LOGD("[slot%{public}d] entry", slotId);
180 LockStatusResponse response = { UNLOCK_FAIL, TELEPHONY_ERROR };
181 int32_t result = CoreManagerInner::GetInstance().AlterPin(slotId, newPin, oldPin, response);
182 TELEPHONY_LOGI("[slot%{public}d] result: %{public}d, remain: %{public}d", slotId, response.result, response.remain);
183 if (result == TELEPHONY_SUCCESS) {
184 std::shared_ptr<CellularCallHandler> ccHandler = GetMMIHandler(slotId);
185 std::shared_ptr<PinPukResponse> pinResData = std::make_shared<PinPukResponse>();
186 pinResData->result = response.result;
187 pinResData->remain = response.remain;
188 AppExecFwk::InnerEvent::Pointer msgEvent =
189 AppExecFwk::InnerEvent::Get(MMIHandlerId::EVENT_SET_UNLOCK_PIN_PUK_ID, pinResData, 0);
190 bool ret = ccHandler->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE);
191 if (!ret) {
192 TELEPHONY_LOGE("[slot%{public}d] SendEvent failed! status update failed", slotId);
193 return TELEPHONY_ERR_FAIL;
194 }
195 return TELEPHONY_SUCCESS;
196 }
197 return TELEPHONY_ERROR;
198 }
199
UnlockPuk(int32_t slotId,std::string newPin,std::string puk)200 int32_t SupplementRequestCs::UnlockPuk(int32_t slotId, std::string newPin, std::string puk)
201 {
202 TELEPHONY_LOGD("[slot%{public}d] entry", slotId);
203 LockStatusResponse response = { UNLOCK_FAIL, TELEPHONY_ERROR };
204 int32_t result = CoreManagerInner::GetInstance().UnlockPuk(slotId, newPin, puk, response);
205 TELEPHONY_LOGI("[slot%{public}d] result: %{public}d, remain: %{public}d", slotId, response.result, response.remain);
206 if (result == TELEPHONY_SUCCESS) {
207 std::shared_ptr<CellularCallHandler> ccHandler = GetMMIHandler(slotId);
208 std::shared_ptr<PinPukResponse> pinResData = std::make_shared<PinPukResponse>();
209 pinResData->result = response.result;
210 pinResData->remain = response.remain;
211 AppExecFwk::InnerEvent::Pointer msgEvent =
212 AppExecFwk::InnerEvent::Get(MMIHandlerId::EVENT_SET_UNLOCK_PIN_PUK_ID, pinResData, 0);
213 bool ret = ccHandler->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE);
214 if (!ret) {
215 TELEPHONY_LOGE("[slot%{public}d] SendEvent failed! status update failed", slotId);
216 return TELEPHONY_ERR_FAIL;
217 }
218 return TELEPHONY_SUCCESS;
219 }
220 return TELEPHONY_ERROR;
221 }
222
AlterPin2Password(int32_t slotId,std::string newPin2,std::string oldPin2)223 int32_t SupplementRequestCs::AlterPin2Password(int32_t slotId, std::string newPin2, std::string oldPin2)
224 {
225 TELEPHONY_LOGD("[slot%{public}d] entry", slotId);
226 LockStatusResponse response = { UNLOCK_FAIL, TELEPHONY_ERROR };
227 int32_t result = CoreManagerInner::GetInstance().AlterPin2(slotId, newPin2, oldPin2, response);
228 TELEPHONY_LOGI("[slot%{public}d] result: %{public}d, remain: %{public}d", slotId, response.result, response.remain);
229 if (result == TELEPHONY_SUCCESS) {
230 std::shared_ptr<CellularCallHandler> ccHandler = GetMMIHandler(slotId);
231 std::shared_ptr<PinPukResponse> pinResData = std::make_shared<PinPukResponse>();
232 pinResData->result = response.result;
233 pinResData->remain = response.remain;
234 AppExecFwk::InnerEvent::Pointer msgEvent =
235 AppExecFwk::InnerEvent::Get(MMIHandlerId::EVENT_SET_UNLOCK_PIN_PUK_ID, pinResData, 0);
236 bool ret = ccHandler->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE);
237 if (!ret) {
238 TELEPHONY_LOGE("[slot%{public}d] SendEvent failed! status update failed", slotId);
239 return TELEPHONY_ERR_FAIL;
240 }
241 return TELEPHONY_SUCCESS;
242 }
243 return TELEPHONY_ERROR;
244 }
245
UnlockPuk2(int32_t slotId,std::string newPin2,std::string puk2)246 int32_t SupplementRequestCs::UnlockPuk2(int32_t slotId, std::string newPin2, std::string puk2)
247 {
248 TELEPHONY_LOGD("[slot%{public}d] entry", slotId);
249 LockStatusResponse response = { UNLOCK_FAIL, TELEPHONY_ERROR };
250 int32_t result = CoreManagerInner::GetInstance().UnlockPuk2(slotId, newPin2, puk2, response);
251 TELEPHONY_LOGI("[slot%{public}d] result: %{public}d, remain: %{public}d", slotId, response.result, response.remain);
252 if (result == TELEPHONY_SUCCESS) {
253 std::shared_ptr<CellularCallHandler> ccHandler = GetMMIHandler(slotId);
254 std::shared_ptr<PinPukResponse> pinResData = std::make_shared<PinPukResponse>();
255 pinResData->result = response.result;
256 pinResData->remain = response.remain;
257 AppExecFwk::InnerEvent::Pointer msgEvent =
258 AppExecFwk::InnerEvent::Get(MMIHandlerId::EVENT_SET_UNLOCK_PIN_PUK_ID, pinResData, 0);
259 bool ret = ccHandler->SendEvent(msgEvent, 0, AppExecFwk::EventQueue::Priority::IMMEDIATE);
260 if (!ret) {
261 TELEPHONY_LOGE("[slot%{public}d] SendEvent failed! status update failed", slotId);
262 return TELEPHONY_ERR_FAIL;
263 }
264 return TELEPHONY_SUCCESS;
265 }
266 return TELEPHONY_ERROR;
267 }
268
CloseUnFinishedUssdRequest(int32_t slotId)269 int32_t SupplementRequestCs::CloseUnFinishedUssdRequest(int32_t slotId)
270 {
271 TELEPHONY_LOGI("[slot%{public}d] entry", slotId);
272 return CoreManagerInner::GetInstance().CloseUnFinishedUssd(
273 slotId, RadioEvent::RADIO_CLOSE_UNFINISHED_USSD, GetMMIHandler(slotId));
274 }
275 } // namespace Telephony
276 } // namespace OHOS
277