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_service.h"
19 #include "radio_event.h"
20
21 namespace OHOS {
22 namespace Telephony {
DialRequest(int32_t slotId,const DialRequestStruct & dialRequest)23 int32_t CellularCallConnectionCS::DialRequest(int32_t slotId, const DialRequestStruct &dialRequest)
24 {
25 TELEPHONY_LOGE("CellularCallConnectionCS::DialRequest start.");
26 if (DelayedSingleton<CellularCallService>::GetInstance() == nullptr) {
27 TELEPHONY_LOGE("DialRequest return, error type: GetInstance() is nullptr.");
28 return CALL_ERR_RESOURCE_UNAVAILABLE;
29 }
30 auto handle = DelayedSingleton<CellularCallService>::GetInstance()->GetHandler(slotId);
31 if (handle == nullptr) {
32 TELEPHONY_LOGE("DialRequest return, error type: handle is nullptr.");
33 return CALL_ERR_RESOURCE_UNAVAILABLE;
34 }
35 CoreManagerInner::GetInstance().Dial(
36 slotId, RadioEvent::RADIO_DIAL, dialRequest.phoneNum, dialRequest.clirMode, handle);
37 return TELEPHONY_SUCCESS;
38 }
39
HangUpRequest(int32_t slotId)40 int32_t CellularCallConnectionCS::HangUpRequest(int32_t slotId)
41 {
42 TELEPHONY_LOGE("CellularCallConnectionCS::HangUpRequest start.");
43 if (DelayedSingleton<CellularCallService>::GetInstance() == nullptr) {
44 TELEPHONY_LOGE("HangUpRequest return, error type: GetInstance() is nullptr.");
45 return CALL_ERR_RESOURCE_UNAVAILABLE;
46 }
47 auto handle = DelayedSingleton<CellularCallService>::GetInstance()->GetHandler(slotId);
48 if (handle == nullptr) {
49 TELEPHONY_LOGE("HangUpRequest return, error type: handle is nullptr.");
50 return CALL_ERR_RESOURCE_UNAVAILABLE;
51 }
52 int32_t index = GetIndex();
53 CoreManagerInner::GetInstance().Hangup(slotId, RadioEvent::RADIO_HANGUP_CONNECT, index, handle);
54 return TELEPHONY_SUCCESS;
55 }
56
AnswerRequest(int32_t slotId)57 int32_t CellularCallConnectionCS::AnswerRequest(int32_t slotId)
58 {
59 TELEPHONY_LOGE("CellularCallConnectionCS::AnswerRequest start.");
60 if (DelayedSingleton<CellularCallService>::GetInstance() == nullptr) {
61 TELEPHONY_LOGE("AnswerRequest return, error type: GetInstance() is nullptr.");
62 return CALL_ERR_RESOURCE_UNAVAILABLE;
63 }
64 auto handle = DelayedSingleton<CellularCallService>::GetInstance()->GetHandler(slotId);
65 if (handle == nullptr) {
66 TELEPHONY_LOGE("AnswerRequest return, error type: handle is nullptr.");
67 return CALL_ERR_RESOURCE_UNAVAILABLE;
68 }
69 CoreManagerInner::GetInstance().Answer(slotId, RadioEvent::RADIO_ACCEPT_CALL, handle);
70 return TELEPHONY_SUCCESS;
71 }
72
RejectRequest(int32_t slotId)73 int32_t CellularCallConnectionCS::RejectRequest(int32_t slotId)
74 {
75 TELEPHONY_LOGE("CellularCallConnectionCS::RejectRequest start.");
76 if (DelayedSingleton<CellularCallService>::GetInstance() == nullptr) {
77 TELEPHONY_LOGE("RejectRequest return, error type: GetInstance() is nullptr.");
78 return CALL_ERR_RESOURCE_UNAVAILABLE;
79 }
80 auto handle = DelayedSingleton<CellularCallService>::GetInstance()->GetHandler(slotId);
81 if (handle == nullptr) {
82 TELEPHONY_LOGE("RejectRequest return, error type: handle is nullptr.");
83 return CALL_ERR_RESOURCE_UNAVAILABLE;
84 }
85 CoreManagerInner::GetInstance().Reject(slotId, RadioEvent::RADIO_REJECT_CALL, handle);
86 return TELEPHONY_SUCCESS;
87 }
88
HoldRequest(int32_t slotId)89 int32_t CellularCallConnectionCS::HoldRequest(int32_t slotId)
90 {
91 TELEPHONY_LOGE("CellularCallConnectionCS::HoldRequest start.");
92 if (DelayedSingleton<CellularCallService>::GetInstance() == nullptr) {
93 TELEPHONY_LOGE("HoldRequest return, error type: GetInstance() is nullptr.");
94 return CALL_ERR_RESOURCE_UNAVAILABLE;
95 }
96 auto handle = DelayedSingleton<CellularCallService>::GetInstance()->GetHandler(slotId);
97 if (handle == nullptr) {
98 TELEPHONY_LOGE("HoldRequest return, error type: handle is nullptr.");
99 return CALL_ERR_RESOURCE_UNAVAILABLE;
100 }
101 CoreManagerInner::GetInstance().HoldCall(slotId, RadioEvent::RADIO_HOLD_CALL, handle);
102 return TELEPHONY_SUCCESS;
103 }
104
UnHoldCallRequest(int32_t slotId)105 int32_t CellularCallConnectionCS::UnHoldCallRequest(int32_t slotId)
106 {
107 TELEPHONY_LOGE("CellularCallConnectionCS::UnHoldCallRequest start.");
108 if (DelayedSingleton<CellularCallService>::GetInstance() == nullptr) {
109 TELEPHONY_LOGE("UnHoldCallRequest return, error type: GetInstance() is nullptr.");
110 return CALL_ERR_RESOURCE_UNAVAILABLE;
111 }
112 auto handle = DelayedSingleton<CellularCallService>::GetInstance()->GetHandler(slotId);
113 if (handle == nullptr) {
114 TELEPHONY_LOGE("UnHoldCallRequest return, error type: handle is nullptr.");
115 return CALL_ERR_RESOURCE_UNAVAILABLE;
116 }
117 CoreManagerInner::GetInstance().UnHoldCall(slotId, RadioEvent::RADIO_ACTIVE_CALL, handle);
118 return TELEPHONY_SUCCESS;
119 }
120
SwitchCallRequest(int32_t slotId)121 int32_t CellularCallConnectionCS::SwitchCallRequest(int32_t slotId)
122 {
123 TELEPHONY_LOGE("CellularCallConnectionCS::SwitchCallRequest start.");
124 if (DelayedSingleton<CellularCallService>::GetInstance() == nullptr) {
125 TELEPHONY_LOGE("SwitchCallRequest return, error type: GetInstance() is nullptr.");
126 return CALL_ERR_RESOURCE_UNAVAILABLE;
127 }
128 auto handle = DelayedSingleton<CellularCallService>::GetInstance()->GetHandler(slotId);
129 if (handle == nullptr) {
130 TELEPHONY_LOGE("SwitchCallRequest return, error type: handle is nullptr.");
131 return CALL_ERR_RESOURCE_UNAVAILABLE;
132 }
133 CoreManagerInner::GetInstance().SwitchCall(slotId, RadioEvent::RADIO_SWAP_CALL, handle);
134 return TELEPHONY_SUCCESS;
135 }
136
CombineConferenceRequest(int32_t slotId,int32_t voiceCall)137 int32_t CellularCallConnectionCS::CombineConferenceRequest(int32_t slotId, int32_t voiceCall)
138 {
139 TELEPHONY_LOGE("CellularCallConnectionCS::CombineConferenceRequest start.");
140 if (DelayedSingleton<CellularCallService>::GetInstance() == nullptr) {
141 TELEPHONY_LOGE("CombineConferenceRequest return, error type: GetInstance() is nullptr.");
142 return CALL_ERR_RESOURCE_UNAVAILABLE;
143 }
144 auto handle = DelayedSingleton<CellularCallService>::GetInstance()->GetHandler(slotId);
145 if (handle == nullptr) {
146 TELEPHONY_LOGE("CombineConferenceRequest return, error type: handle is nullptr.");
147 return CALL_ERR_RESOURCE_UNAVAILABLE;
148 }
149 CoreManagerInner::GetInstance().CombineConference(slotId, RadioEvent::RADIO_JOIN_CALL, voiceCall, handle);
150 return TELEPHONY_SUCCESS;
151 }
152
SeparateConferenceRequest(int32_t slotId,int32_t index,int32_t voiceCall)153 int32_t CellularCallConnectionCS::SeparateConferenceRequest(int32_t slotId, int32_t index, int32_t voiceCall)
154 {
155 TELEPHONY_LOGE("CellularCallConnectionCS::SeparateConferenceRequest start.");
156 if (DelayedSingleton<CellularCallService>::GetInstance() == nullptr) {
157 TELEPHONY_LOGE("SeparateConferenceRequest return, error type: GetInstance() is nullptr.");
158 return CALL_ERR_RESOURCE_UNAVAILABLE;
159 }
160 auto handle = DelayedSingleton<CellularCallService>::GetInstance()->GetHandler(slotId);
161 if (handle == nullptr) {
162 TELEPHONY_LOGE("SeparateConferenceRequest return, error type: handle is nullptr.");
163 return CALL_ERR_RESOURCE_UNAVAILABLE;
164 }
165 CoreManagerInner::GetInstance().SeparateConference(slotId, RadioEvent::RADIO_SPLIT_CALL, index, voiceCall, handle);
166 return TELEPHONY_SUCCESS;
167 }
168
CallSupplementRequest(int32_t slotId,CallSupplementType type)169 int32_t CellularCallConnectionCS::CallSupplementRequest(int32_t slotId, CallSupplementType type)
170 {
171 TELEPHONY_LOGE("CellularCallConnectionCS::CallSupplementRequest start.");
172 if (DelayedSingleton<CellularCallService>::GetInstance() == nullptr) {
173 TELEPHONY_LOGE("CallSupplementRequest return, error type: GetInstance() is nullptr.");
174 return CALL_ERR_RESOURCE_UNAVAILABLE;
175 }
176 auto handle = DelayedSingleton<CellularCallService>::GetInstance()->GetHandler(slotId);
177 if (handle == nullptr) {
178 TELEPHONY_LOGE("CallSupplementRequest return, error type: handle is nullptr.");
179 return CALL_ERR_RESOURCE_UNAVAILABLE;
180 }
181 CoreManagerInner::GetInstance().CallSupplement(slotId, RadioEvent::RADIO_CALL_SUPPLEMENT, type, handle);
182 return TELEPHONY_SUCCESS;
183 }
184
SendCDMAThreeWayDialRequest(int32_t slotId)185 int32_t CellularCallConnectionCS::SendCDMAThreeWayDialRequest(int32_t slotId)
186 {
187 TELEPHONY_LOGE("CellularCallConnectionCS::SendCDMAThreeWayDialRequest start.");
188 return TELEPHONY_SUCCESS;
189 }
190
SendDtmfRequest(int32_t slotId,char cDtmfCode,int32_t index) const191 int32_t CellularCallConnectionCS::SendDtmfRequest(int32_t slotId, char cDtmfCode, int32_t index) const
192 {
193 TELEPHONY_LOGE("CellularCallConnectionCS::SendDtmfRequest start.");
194 if (DelayedSingleton<CellularCallService>::GetInstance() == nullptr) {
195 TELEPHONY_LOGE("SendDtmfRequest return, error type: GetInstance() is nullptr.");
196 return CALL_ERR_RESOURCE_UNAVAILABLE;
197 }
198 auto handle = DelayedSingleton<CellularCallService>::GetInstance()->GetHandler(slotId);
199 if (handle == nullptr) {
200 TELEPHONY_LOGE("SendDtmfRequest return, error type: handle is nullptr.");
201 return CALL_ERR_RESOURCE_UNAVAILABLE;
202 }
203 CoreManagerInner::GetInstance().SendDTMF(slotId, RadioEvent::RADIO_SEND_DTMF, cDtmfCode, index, handle);
204 return TELEPHONY_SUCCESS;
205 }
206
StartDtmfRequest(int32_t slotId,char cDtmfCode,int32_t index) const207 int32_t CellularCallConnectionCS::StartDtmfRequest(int32_t slotId, char cDtmfCode, int32_t index) const
208 {
209 TELEPHONY_LOGE("CellularCallConnectionCS::StartDtmfRequest start.");
210 if (DelayedSingleton<CellularCallService>::GetInstance() == nullptr) {
211 TELEPHONY_LOGE("StartDtmfRequest return, error type: GetInstance() is nullptr.");
212 return CALL_ERR_RESOURCE_UNAVAILABLE;
213 }
214 auto handle = DelayedSingleton<CellularCallService>::GetInstance()->GetHandler(slotId);
215 if (handle == nullptr) {
216 TELEPHONY_LOGE("StartDtmfRequest return, error type: handle is nullptr.");
217 return CALL_ERR_RESOURCE_UNAVAILABLE;
218 }
219 CoreManagerInner::GetInstance().StartDTMF(slotId, RadioEvent::RADIO_START_DTMF, cDtmfCode, index, handle);
220 return TELEPHONY_SUCCESS;
221 }
222
StopDtmfRequest(int32_t slotId,int32_t index) const223 int32_t CellularCallConnectionCS::StopDtmfRequest(int32_t slotId, int32_t index) const
224 {
225 TELEPHONY_LOGE("CellularCallConnectionCS::StopDtmfRequest start.");
226 if (DelayedSingleton<CellularCallService>::GetInstance() == nullptr) {
227 TELEPHONY_LOGE("StopDtmfRequest return, error type: GetInstance() is nullptr.");
228 return CALL_ERR_RESOURCE_UNAVAILABLE;
229 }
230 auto handle = DelayedSingleton<CellularCallService>::GetInstance()->GetHandler(slotId);
231 if (handle == nullptr) {
232 TELEPHONY_LOGE("StopDtmfRequest return, error type: handle is nullptr.");
233 return CALL_ERR_RESOURCE_UNAVAILABLE;
234 }
235 CoreManagerInner::GetInstance().StopDTMF(slotId, RadioEvent::RADIO_STOP_DTMF, index, handle);
236 return TELEPHONY_SUCCESS;
237 }
238
GetCsCallsDataRequest(int32_t slotId,int64_t lastCallsDataFlag)239 int32_t CellularCallConnectionCS::GetCsCallsDataRequest(int32_t slotId, int64_t lastCallsDataFlag)
240 {
241 TELEPHONY_LOGE("CellularCallConnectionCS::GetCsCallsDataRequest start.");
242 if (DelayedSingleton<CellularCallService>::GetInstance() == nullptr) {
243 TELEPHONY_LOGE("GetCsCallsDataRequest return, error type: GetInstance() is nullptr.");
244 return CALL_ERR_RESOURCE_UNAVAILABLE;
245 }
246 auto handle = DelayedSingleton<CellularCallService>::GetInstance()->GetHandler(slotId);
247 if (handle == nullptr) {
248 TELEPHONY_LOGE("GetCsCallsDataRequest return, error type: handle is nullptr.");
249 return CALL_ERR_RESOURCE_UNAVAILABLE;
250 }
251
252 // Implementation
253 // Optional. Recommended when +CHLD command is implemented.
254 CoreManagerInner::GetInstance().GetCallList(slotId, RadioEvent::RADIO_CURRENT_CALLS, handle);
255 return TELEPHONY_SUCCESS;
256 }
257
GetCallFailReasonRequest(int32_t slotId) const258 int32_t CellularCallConnectionCS::GetCallFailReasonRequest(int32_t slotId) const
259 {
260 TELEPHONY_LOGE("CellularCallConnectionCS::GetCallFailReasonRequest start.");
261 if (DelayedSingleton<CellularCallService>::GetInstance() == nullptr) {
262 TELEPHONY_LOGE("GetCallFailReasonRequest return, error type: GetInstance() is nullptr.");
263 return CALL_ERR_RESOURCE_UNAVAILABLE;
264 }
265 auto handle = DelayedSingleton<CellularCallService>::GetInstance()->GetHandler(slotId);
266 if (handle == nullptr) {
267 TELEPHONY_LOGE("GetCallFailReasonRequest return, error type: handle is nullptr.");
268 return CALL_ERR_RESOURCE_UNAVAILABLE;
269 }
270 CoreManagerInner::GetInstance().GetCallFailReason(slotId, RadioEvent::RADIO_GET_CALL_FAIL_REASON, handle);
271 return TELEPHONY_SUCCESS;
272 }
273
RegisterHandler()274 void CellularCallConnectionCS::RegisterHandler()
275 {
276 DelayedSingleton<CellularCallService>::GetInstance()->RegisterHandler();
277 }
278 } // namespace Telephony
279 } // namespace OHOS
280