1 /*
2 * Copyright (C) 2021 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 "cellular_call_connection_cs.h"
17
18 #include "cellular_call_hisysevent.h"
19 #include "cellular_call_service.h"
20 #include "radio_event.h"
21 #include "standardize_utils.h"
22
23 namespace OHOS {
24 namespace Telephony {
DialRequest(int32_t slotId,const DialRequestStruct & dialRequest)25 int32_t CellularCallConnectionCS::DialRequest(int32_t slotId, const DialRequestStruct &dialRequest)
26 {
27 TELEPHONY_LOGI("CellularCallConnectionCS::DialRequest start.");
28 if (DelayedSingleton<CellularCallService>::GetInstance() == nullptr) {
29 TELEPHONY_LOGE("DialRequest return, error type: GetInstance() is nullptr.");
30 CellularCallHiSysEvent::WriteDialCallFaultEvent(
31 slotId, INVALID_PARAMETER, INVALID_PARAMETER, CALL_ERR_RESOURCE_UNAVAILABLE, "cellular service is nullptr");
32 return CALL_ERR_RESOURCE_UNAVAILABLE;
33 }
34 auto handle = DelayedSingleton<CellularCallService>::GetInstance()->GetHandler(slotId);
35 if (handle == nullptr) {
36 TELEPHONY_LOGE("DialRequest return, error type: handle is nullptr.");
37 CellularCallHiSysEvent::WriteDialCallFaultEvent(slotId, INVALID_PARAMETER, INVALID_PARAMETER,
38 CALL_ERR_RESOURCE_UNAVAILABLE, "cellular service handle is nullptr");
39 return CALL_ERR_RESOURCE_UNAVAILABLE;
40 }
41 UpdateCallNumber(dialRequest.phoneNum);
42 CoreManagerInner::GetInstance().Dial(
43 slotId, RadioEvent::RADIO_DIAL, phoneNumber_, dialRequest.clirMode, handle);
44 phoneNumber_.clear();
45 return TELEPHONY_SUCCESS;
46 }
47
HangUpRequest(int32_t slotId)48 int32_t CellularCallConnectionCS::HangUpRequest(int32_t slotId)
49 {
50 TELEPHONY_LOGI("CellularCallConnectionCS::HangUpRequest start.");
51 if (DelayedSingleton<CellularCallService>::GetInstance() == nullptr) {
52 TELEPHONY_LOGE("HangUpRequest return, error type: GetInstance() is nullptr.");
53 CellularCallHiSysEvent::WriteHangUpFaultEvent(
54 slotId, INVALID_PARAMETER, CALL_ERR_RESOURCE_UNAVAILABLE, "cellular service is nullptr");
55 return CALL_ERR_RESOURCE_UNAVAILABLE;
56 }
57 auto handle = DelayedSingleton<CellularCallService>::GetInstance()->GetHandler(slotId);
58 if (handle == nullptr) {
59 TELEPHONY_LOGE("HangUpRequest return, error type: handle is nullptr.");
60 CellularCallHiSysEvent::WriteHangUpFaultEvent(
61 slotId, INVALID_PARAMETER, CALL_ERR_RESOURCE_UNAVAILABLE, "cellular service handle is nullptr");
62 return CALL_ERR_RESOURCE_UNAVAILABLE;
63 }
64 int32_t index = GetIndex();
65 CoreManagerInner::GetInstance().Hangup(slotId, RadioEvent::RADIO_HANGUP_CONNECT, index, handle);
66 return TELEPHONY_SUCCESS;
67 }
68
AnswerRequest(int32_t slotId)69 int32_t CellularCallConnectionCS::AnswerRequest(int32_t slotId)
70 {
71 TELEPHONY_LOGI("CellularCallConnectionCS::AnswerRequest start.");
72 if (DelayedSingleton<CellularCallService>::GetInstance() == nullptr) {
73 TELEPHONY_LOGE("AnswerRequest return, error type: GetInstance() is nullptr.");
74 CellularCallHiSysEvent::WriteAnswerCallFaultEvent(
75 slotId, INVALID_PARAMETER, INVALID_PARAMETER, CALL_ERR_RESOURCE_UNAVAILABLE, "cellular service is nullptr");
76 return CALL_ERR_RESOURCE_UNAVAILABLE;
77 }
78 auto handle = DelayedSingleton<CellularCallService>::GetInstance()->GetHandler(slotId);
79 if (handle == nullptr) {
80 TELEPHONY_LOGE("AnswerRequest return, error type: handle is nullptr.");
81 CellularCallHiSysEvent::WriteAnswerCallFaultEvent(slotId, INVALID_PARAMETER, INVALID_PARAMETER,
82 CALL_ERR_RESOURCE_UNAVAILABLE, "cellular service handle is nullptr");
83 return CALL_ERR_RESOURCE_UNAVAILABLE;
84 }
85 CoreManagerInner::GetInstance().SetMute(slotId, RadioEvent::RADIO_SET_CMUT, false, handle);
86 CoreManagerInner::GetInstance().Answer(slotId, RadioEvent::RADIO_ACCEPT_CALL, handle);
87 return TELEPHONY_SUCCESS;
88 }
89
RejectRequest(int32_t slotId)90 int32_t CellularCallConnectionCS::RejectRequest(int32_t slotId)
91 {
92 TELEPHONY_LOGI("CellularCallConnectionCS::RejectRequest start.");
93 if (DelayedSingleton<CellularCallService>::GetInstance() == nullptr) {
94 TELEPHONY_LOGE("RejectRequest return, error type: GetInstance() is nullptr.");
95 CellularCallHiSysEvent::WriteHangUpFaultEvent(
96 slotId, INVALID_PARAMETER, CALL_ERR_RESOURCE_UNAVAILABLE, "cellular service is nullptr");
97 return CALL_ERR_RESOURCE_UNAVAILABLE;
98 }
99 auto handle = DelayedSingleton<CellularCallService>::GetInstance()->GetHandler(slotId);
100 if (handle == nullptr) {
101 TELEPHONY_LOGE("RejectRequest return, error type: handle is nullptr.");
102 CellularCallHiSysEvent::WriteHangUpFaultEvent(
103 slotId, INVALID_PARAMETER, CALL_ERR_RESOURCE_UNAVAILABLE, "cellular service handle is nullptr");
104 return CALL_ERR_RESOURCE_UNAVAILABLE;
105 }
106 CoreManagerInner::GetInstance().Reject(slotId, RadioEvent::RADIO_REJECT_CALL, handle);
107 return TELEPHONY_SUCCESS;
108 }
109
HoldRequest(int32_t slotId)110 int32_t CellularCallConnectionCS::HoldRequest(int32_t slotId)
111 {
112 TELEPHONY_LOGI("CellularCallConnectionCS::HoldRequest start.");
113 if (DelayedSingleton<CellularCallService>::GetInstance() == nullptr) {
114 TELEPHONY_LOGE("HoldRequest return, error type: GetInstance() is nullptr.");
115 return CALL_ERR_RESOURCE_UNAVAILABLE;
116 }
117 auto handle = DelayedSingleton<CellularCallService>::GetInstance()->GetHandler(slotId);
118 if (handle == nullptr) {
119 TELEPHONY_LOGE("HoldRequest return, error type: handle is nullptr.");
120 return CALL_ERR_RESOURCE_UNAVAILABLE;
121 }
122 CoreManagerInner::GetInstance().HoldCall(slotId, RadioEvent::RADIO_HOLD_CALL, handle);
123 return TELEPHONY_SUCCESS;
124 }
125
UnHoldCallRequest(int32_t slotId)126 int32_t CellularCallConnectionCS::UnHoldCallRequest(int32_t slotId)
127 {
128 TELEPHONY_LOGI("CellularCallConnectionCS::UnHoldCallRequest start.");
129 if (DelayedSingleton<CellularCallService>::GetInstance() == nullptr) {
130 TELEPHONY_LOGE("UnHoldCallRequest return, error type: GetInstance() is nullptr.");
131 return CALL_ERR_RESOURCE_UNAVAILABLE;
132 }
133 auto handle = DelayedSingleton<CellularCallService>::GetInstance()->GetHandler(slotId);
134 if (handle == nullptr) {
135 TELEPHONY_LOGE("UnHoldCallRequest return, error type: handle is nullptr.");
136 return CALL_ERR_RESOURCE_UNAVAILABLE;
137 }
138 CoreManagerInner::GetInstance().UnHoldCall(slotId, RadioEvent::RADIO_ACTIVE_CALL, handle);
139 return TELEPHONY_SUCCESS;
140 }
141
SwitchCallRequest(int32_t slotId)142 int32_t CellularCallConnectionCS::SwitchCallRequest(int32_t slotId)
143 {
144 TELEPHONY_LOGI("CellularCallConnectionCS::SwitchCallRequest start.");
145 if (DelayedSingleton<CellularCallService>::GetInstance() == nullptr) {
146 TELEPHONY_LOGE("SwitchCallRequest return, error type: GetInstance() is nullptr.");
147 return CALL_ERR_RESOURCE_UNAVAILABLE;
148 }
149 auto handle = DelayedSingleton<CellularCallService>::GetInstance()->GetHandler(slotId);
150 if (handle == nullptr) {
151 TELEPHONY_LOGE("SwitchCallRequest return, error type: handle is nullptr.");
152 return CALL_ERR_RESOURCE_UNAVAILABLE;
153 }
154 CoreManagerInner::GetInstance().SwitchCall(slotId, RadioEvent::RADIO_SWAP_CALL, handle);
155 return TELEPHONY_SUCCESS;
156 }
157
CombineConferenceRequest(int32_t slotId,int32_t voiceCall)158 int32_t CellularCallConnectionCS::CombineConferenceRequest(int32_t slotId, int32_t voiceCall)
159 {
160 TELEPHONY_LOGI("CellularCallConnectionCS::CombineConferenceRequest start.");
161 if (DelayedSingleton<CellularCallService>::GetInstance() == nullptr) {
162 TELEPHONY_LOGE("CombineConferenceRequest return, error type: GetInstance() is nullptr.");
163 return CALL_ERR_RESOURCE_UNAVAILABLE;
164 }
165 auto handle = DelayedSingleton<CellularCallService>::GetInstance()->GetHandler(slotId);
166 if (handle == nullptr) {
167 TELEPHONY_LOGE("CombineConferenceRequest return, error type: handle is nullptr.");
168 return CALL_ERR_RESOURCE_UNAVAILABLE;
169 }
170 CoreManagerInner::GetInstance().CombineConference(slotId, RadioEvent::RADIO_JOIN_CALL, voiceCall, handle);
171 return TELEPHONY_SUCCESS;
172 }
173
SeparateConferenceRequest(int32_t slotId,int32_t index,int32_t voiceCall)174 int32_t CellularCallConnectionCS::SeparateConferenceRequest(int32_t slotId, int32_t index, int32_t voiceCall)
175 {
176 TELEPHONY_LOGI("CellularCallConnectionCS::SeparateConferenceRequest start.");
177 if (DelayedSingleton<CellularCallService>::GetInstance() == nullptr) {
178 TELEPHONY_LOGE("SeparateConferenceRequest return, error type: GetInstance() is nullptr.");
179 return CALL_ERR_RESOURCE_UNAVAILABLE;
180 }
181 auto handle = DelayedSingleton<CellularCallService>::GetInstance()->GetHandler(slotId);
182 if (handle == nullptr) {
183 TELEPHONY_LOGE("SeparateConferenceRequest return, error type: handle is nullptr.");
184 return CALL_ERR_RESOURCE_UNAVAILABLE;
185 }
186 CoreManagerInner::GetInstance().SeparateConference(slotId, RadioEvent::RADIO_SPLIT_CALL, index, voiceCall, handle);
187 return TELEPHONY_SUCCESS;
188 }
189
CallSupplementRequest(int32_t slotId,CallSupplementType type)190 int32_t CellularCallConnectionCS::CallSupplementRequest(int32_t slotId, CallSupplementType type)
191 {
192 TELEPHONY_LOGI("CellularCallConnectionCS::CallSupplementRequest start.");
193 if (DelayedSingleton<CellularCallService>::GetInstance() == nullptr) {
194 TELEPHONY_LOGE("CallSupplementRequest return, error type: GetInstance() is nullptr.");
195 return CALL_ERR_RESOURCE_UNAVAILABLE;
196 }
197 auto handle = DelayedSingleton<CellularCallService>::GetInstance()->GetHandler(slotId);
198 if (handle == nullptr) {
199 TELEPHONY_LOGE("CallSupplementRequest return, error type: handle is nullptr.");
200 return CALL_ERR_RESOURCE_UNAVAILABLE;
201 }
202 CoreManagerInner::GetInstance().CallSupplement(slotId, RadioEvent::RADIO_CALL_SUPPLEMENT, type, handle);
203 return TELEPHONY_SUCCESS;
204 }
205
SendCDMAThreeWayDialRequest(int32_t slotId)206 int32_t CellularCallConnectionCS::SendCDMAThreeWayDialRequest(int32_t slotId)
207 {
208 TELEPHONY_LOGI("CellularCallConnectionCS::SendCDMAThreeWayDialRequest start.");
209 return TELEPHONY_SUCCESS;
210 }
211
SendDtmfRequest(int32_t slotId,char cDtmfCode,int32_t index) const212 int32_t CellularCallConnectionCS::SendDtmfRequest(int32_t slotId, char cDtmfCode, int32_t index) const
213 {
214 TELEPHONY_LOGI("CellularCallConnectionCS::SendDtmfRequest start.");
215 if (DelayedSingleton<CellularCallService>::GetInstance() == nullptr) {
216 TELEPHONY_LOGE("SendDtmfRequest return, error type: GetInstance() is nullptr.");
217 return CALL_ERR_RESOURCE_UNAVAILABLE;
218 }
219 auto handle = DelayedSingleton<CellularCallService>::GetInstance()->GetHandler(slotId);
220 if (handle == nullptr) {
221 TELEPHONY_LOGE("SendDtmfRequest return, error type: handle is nullptr.");
222 return CALL_ERR_RESOURCE_UNAVAILABLE;
223 }
224 CoreManagerInner::GetInstance().SendDTMF(slotId, RadioEvent::RADIO_SEND_DTMF, cDtmfCode, index, handle);
225 return TELEPHONY_SUCCESS;
226 }
227
StartDtmfRequest(int32_t slotId,char cDtmfCode,int32_t index) const228 int32_t CellularCallConnectionCS::StartDtmfRequest(int32_t slotId, char cDtmfCode, int32_t index) const
229 {
230 TELEPHONY_LOGD("CellularCallConnectionCS::StartDtmfRequest start.");
231 if (DelayedSingleton<CellularCallService>::GetInstance() == nullptr) {
232 TELEPHONY_LOGE("StartDtmfRequest return, error type: GetInstance() is nullptr.");
233 return CALL_ERR_RESOURCE_UNAVAILABLE;
234 }
235 auto handle = DelayedSingleton<CellularCallService>::GetInstance()->GetHandler(slotId);
236 if (handle == nullptr) {
237 TELEPHONY_LOGE("StartDtmfRequest return, error type: handle is nullptr.");
238 return CALL_ERR_RESOURCE_UNAVAILABLE;
239 }
240 CoreManagerInner::GetInstance().StartDTMF(slotId, RadioEvent::RADIO_START_DTMF, cDtmfCode, index, handle);
241 return TELEPHONY_SUCCESS;
242 }
243
StopDtmfRequest(int32_t slotId,int32_t index) const244 int32_t CellularCallConnectionCS::StopDtmfRequest(int32_t slotId, int32_t index) const
245 {
246 TELEPHONY_LOGI("CellularCallConnectionCS::StopDtmfRequest start.");
247 if (DelayedSingleton<CellularCallService>::GetInstance() == nullptr) {
248 TELEPHONY_LOGE("StopDtmfRequest return, error type: GetInstance() is nullptr.");
249 return CALL_ERR_RESOURCE_UNAVAILABLE;
250 }
251 auto handle = DelayedSingleton<CellularCallService>::GetInstance()->GetHandler(slotId);
252 if (handle == nullptr) {
253 TELEPHONY_LOGE("StopDtmfRequest return, error type: handle is nullptr.");
254 return CALL_ERR_RESOURCE_UNAVAILABLE;
255 }
256 CoreManagerInner::GetInstance().StopDTMF(slotId, RadioEvent::RADIO_STOP_DTMF, index, handle);
257 return TELEPHONY_SUCCESS;
258 }
259
GetCsCallsDataRequest(int32_t slotId,int64_t lastCallsDataFlag)260 int32_t CellularCallConnectionCS::GetCsCallsDataRequest(int32_t slotId, int64_t lastCallsDataFlag)
261 {
262 TELEPHONY_LOGI("CellularCallConnectionCS::GetCsCallsDataRequest start.");
263 if (DelayedSingleton<CellularCallService>::GetInstance() == nullptr) {
264 TELEPHONY_LOGE("GetCsCallsDataRequest return, error type: GetInstance() is nullptr.");
265 return CALL_ERR_RESOURCE_UNAVAILABLE;
266 }
267 auto handle = DelayedSingleton<CellularCallService>::GetInstance()->GetHandler(slotId);
268 if (handle == nullptr) {
269 TELEPHONY_LOGE("GetCsCallsDataRequest return, error type: handle is nullptr.");
270 return CALL_ERR_RESOURCE_UNAVAILABLE;
271 }
272
273 // Implementation
274 // Optional. Recommended when +CHLD command is implemented.
275 CoreManagerInner::GetInstance().GetCallList(slotId, RadioEvent::RADIO_CURRENT_CALLS, handle);
276 return TELEPHONY_SUCCESS;
277 }
278
GetCallFailReasonRequest(int32_t slotId) const279 int32_t CellularCallConnectionCS::GetCallFailReasonRequest(int32_t slotId) const
280 {
281 TELEPHONY_LOGD("CellularCallConnectionCS::GetCallFailReasonRequest start.");
282 if (DelayedSingleton<CellularCallService>::GetInstance() == nullptr) {
283 TELEPHONY_LOGE("GetCallFailReasonRequest return, error type: GetInstance() is nullptr.");
284 return CALL_ERR_RESOURCE_UNAVAILABLE;
285 }
286 auto handle = DelayedSingleton<CellularCallService>::GetInstance()->GetHandler(slotId);
287 if (handle == nullptr) {
288 TELEPHONY_LOGE("GetCallFailReasonRequest return, error type: handle is nullptr.");
289 return CALL_ERR_RESOURCE_UNAVAILABLE;
290 }
291 CoreManagerInner::GetInstance().GetCallFailReason(slotId, RadioEvent::RADIO_GET_CALL_FAIL_REASON, handle);
292 return TELEPHONY_SUCCESS;
293 }
294
RegisterHandler()295 void CellularCallConnectionCS::RegisterHandler()
296 {
297 DelayedSingleton<CellularCallService>::GetInstance()->RegisterHandler();
298 }
299
ProcessPostDialCallChar(int32_t slotId,char c)300 int32_t CellularCallConnectionCS::ProcessPostDialCallChar(int32_t slotId, char c)
301 {
302 if (StandardizeUtils::IsDtmfKey(c)) {
303 SendDtmfRequest(slotId, c, GetIndex());
304 } else if (StandardizeUtils::IsPauseKey(c)) {
305 SetPostDialCallState(PostDialCallState::POST_DIAL_CALL_PAUSE);
306 auto cellularCallHandle = DelayedSingleton<CellularCallService>::GetInstance()->GetHandler(slotId);
307 if (cellularCallHandle == nullptr) {
308 TELEPHONY_LOGE("SendDtmfRequest return, error type: handle is nullptr.");
309 return CALL_ERR_RESOURCE_UNAVAILABLE;
310 }
311 std::shared_ptr<PostDialData> postDial = std::make_shared<PostDialData>();
312 postDial->callId = GetIndex();
313 postDial->isIms = false;
314 cellularCallHandle->SendEvent(EVENT_EXECUTE_POST_DIAL, postDial, PAUSE_DELAY_TIME);
315 } else if (StandardizeUtils::IsWaitKey(c)) {
316 SetPostDialCallState(PostDialCallState::POST_DIAL_CALL_DELAY);
317 }
318 return TELEPHONY_SUCCESS;
319 }
320 } // namespace Telephony
321 } // namespace OHOS
322