• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022-2023 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 "ims_call_callback_stub.h"
17 
18 #include "cellular_call_register.h"
19 #include "cellular_call_service.h"
20 #include "ims_call_client.h"
21 #include "ims_error.h"
22 #include "radio_event.h"
23 #include "supplement_request_cs.h"
24 #include "telephony_errors.h"
25 #include "telephony_log_wrapper.h"
26 
27 namespace OHOS {
28 namespace Telephony {
29 const int32_t MAX_SIZE = 10;
30 const int32_t IMS_CALL = 1;
31 
ImsCallCallbackStub()32 ImsCallCallbackStub::ImsCallCallbackStub()
33 {
34     TELEPHONY_LOGI("ImsCallCallbackStub");
35     InitFuncMap();
36 }
37 
InitFuncMap()38 void ImsCallCallbackStub::InitFuncMap()
39 {
40     InitCallBasicFuncMap();
41     InitConfigFuncMap();
42     InitSupplementFuncMap();
43 }
44 
InitCallBasicFuncMap()45 void ImsCallCallbackStub::InitCallBasicFuncMap()
46 {
47     /****************** call basic ******************/
48     requestFuncMap_[static_cast<uint32_t>(ImsCallCallbackInterfaceCode::IMS_DIAL)] =
49         &ImsCallCallbackStub::OnDialResponseInner;
50     requestFuncMap_[static_cast<uint32_t>(ImsCallCallbackInterfaceCode::IMS_HANG_UP)] =
51         &ImsCallCallbackStub::OnHangUpResponseInner;
52     requestFuncMap_[static_cast<uint32_t>(ImsCallCallbackInterfaceCode::IMS_REJECT)] =
53         &ImsCallCallbackStub::OnRejectResponseInner;
54     requestFuncMap_[static_cast<uint32_t>(ImsCallCallbackInterfaceCode::IMS_ANSWER)] =
55         &ImsCallCallbackStub::OnAnswerResponseInner;
56     requestFuncMap_[static_cast<uint32_t>(ImsCallCallbackInterfaceCode::IMS_HOLD)] =
57         &ImsCallCallbackStub::OnHoldCallResponseInner;
58     requestFuncMap_[static_cast<uint32_t>(ImsCallCallbackInterfaceCode::IMS_UN_HOLD)] =
59         &ImsCallCallbackStub::OnUnHoldCallResponseInner;
60     requestFuncMap_[static_cast<uint32_t>(ImsCallCallbackInterfaceCode::IMS_SWITCH)] =
61         &ImsCallCallbackStub::OnSwitchCallResponseInner;
62     requestFuncMap_[static_cast<uint32_t>(ImsCallCallbackInterfaceCode::IMS_CALL_STATE_CHANGE)] =
63         &ImsCallCallbackStub::OnCallStateChangeReportInner;
64     requestFuncMap_[static_cast<uint32_t>(ImsCallCallbackInterfaceCode::IMS_LAST_CALL_FAIL_REASON)] =
65         &ImsCallCallbackStub::OnLastCallFailReasonResponseInner;
66     requestFuncMap_[static_cast<uint32_t>(ImsCallCallbackInterfaceCode::IMS_CALL_CRING)] =
67         &ImsCallCallbackStub::OnCallRingBackReportInner;
68     requestFuncMap_[static_cast<uint32_t>(ImsCallCallbackInterfaceCode::IMS_COMBINE_CONFERENCE)] =
69         &ImsCallCallbackStub::OnCombineConferenceResponseInner;
70     requestFuncMap_[static_cast<uint32_t>(ImsCallCallbackInterfaceCode::IMS_INVITE_TO_CONFERENCE)] =
71         &ImsCallCallbackStub::OnInviteToConferenceResponseInner;
72 }
73 
InitConfigFuncMap()74 void ImsCallCallbackStub::InitConfigFuncMap()
75 {
76     /****************** dtmf rtt ******************/
77     requestFuncMap_[static_cast<uint32_t>(ImsCallCallbackInterfaceCode::IMS_START_DTMF)] =
78         &ImsCallCallbackStub::OnStartDtmfResponseInner;
79     requestFuncMap_[static_cast<uint32_t>(ImsCallCallbackInterfaceCode::IMS_SEND_DTMF)] =
80         &ImsCallCallbackStub::OnSendDtmfResponseInner;
81     requestFuncMap_[static_cast<uint32_t>(ImsCallCallbackInterfaceCode::IMS_STOP_DTMF)] =
82         &ImsCallCallbackStub::OnStopDtmfResponseInner;
83 
84     /****************** ims config ******************/
85     requestFuncMap_[static_cast<uint32_t>(ImsCallCallbackInterfaceCode::IMS_SET_SWITCH_STATUS)] =
86         &ImsCallCallbackStub::OnSetImsSwitchResponseInner;
87     requestFuncMap_[static_cast<uint32_t>(ImsCallCallbackInterfaceCode::IMS_GET_SWITCH_STATUS)] =
88         &ImsCallCallbackStub::OnGetImsSwitchResponseInner;
89     requestFuncMap_[static_cast<uint32_t>(ImsCallCallbackInterfaceCode::IMS_GET_CALLS_DATA)] =
90         &ImsCallCallbackStub::OnGetImsCallsDataResponseInner;
91     requestFuncMap_[static_cast<uint32_t>(ImsCallCallbackInterfaceCode::IMS_SET_MUTE)] =
92         &ImsCallCallbackStub::OnSetMuteResponseInner;
93 }
94 
InitSupplementFuncMap()95 void ImsCallCallbackStub::InitSupplementFuncMap()
96 {
97     /****************** supplement ******************/
98     requestFuncMap_[static_cast<uint32_t>(ImsCallCallbackInterfaceCode::IMS_SET_CALL_CLIP)] =
99         &ImsCallCallbackStub::OnSetClipResponseInner;
100     requestFuncMap_[static_cast<uint32_t>(ImsCallCallbackInterfaceCode::IMS_GET_CALL_CLIP)] =
101         &ImsCallCallbackStub::OnGetClipResponseInner;
102     requestFuncMap_[static_cast<uint32_t>(ImsCallCallbackInterfaceCode::IMS_GET_CALL_CLIR)] =
103         &ImsCallCallbackStub::OnGetClirResponseInner;
104     requestFuncMap_[static_cast<uint32_t>(ImsCallCallbackInterfaceCode::IMS_SET_CALL_CLIR)] =
105         &ImsCallCallbackStub::OnSetClirResponseInner;
106     requestFuncMap_[static_cast<uint32_t>(ImsCallCallbackInterfaceCode::IMS_GET_CALL_FORWARD)] =
107         &ImsCallCallbackStub::OnGetCallTransferResponseInner;
108     requestFuncMap_[static_cast<uint32_t>(ImsCallCallbackInterfaceCode::IMS_SET_CALL_FORWARD)] =
109         &ImsCallCallbackStub::OnSetCallTransferResponseInner;
110     requestFuncMap_[static_cast<uint32_t>(ImsCallCallbackInterfaceCode::IMS_GET_CALL_RESTRICTION)] =
111         &ImsCallCallbackStub::OnGetCallRestrictionResponseInner;
112     requestFuncMap_[static_cast<uint32_t>(ImsCallCallbackInterfaceCode::IMS_SET_CALL_RESTRICTION)] =
113         &ImsCallCallbackStub::OnSetCallRestrictionResponseInner;
114     requestFuncMap_[static_cast<uint32_t>(ImsCallCallbackInterfaceCode::IMS_GET_CALL_WAIT)] =
115         &ImsCallCallbackStub::OnGetCallWaitingResponseInner;
116     requestFuncMap_[static_cast<uint32_t>(ImsCallCallbackInterfaceCode::IMS_SET_CALL_WAIT)] =
117         &ImsCallCallbackStub::OnSetCallWaitingResponseInner;
118     requestFuncMap_[static_cast<uint32_t>(ImsCallCallbackInterfaceCode::IMS_GET_CALL_COLR)] =
119         &ImsCallCallbackStub::OnGetColrResponseInner;
120     requestFuncMap_[static_cast<uint32_t>(ImsCallCallbackInterfaceCode::IMS_SET_CALL_COLR)] =
121         &ImsCallCallbackStub::OnSetColrResponseInner;
122     requestFuncMap_[static_cast<uint32_t>(ImsCallCallbackInterfaceCode::IMS_SET_CALL_COLP)] =
123         &ImsCallCallbackStub::OnSetColpResponseInner;
124     requestFuncMap_[static_cast<uint32_t>(ImsCallCallbackInterfaceCode::IMS_GET_CALL_COLP)] =
125         &ImsCallCallbackStub::OnGetColpResponseInner;
126 }
127 
~ImsCallCallbackStub()128 ImsCallCallbackStub::~ImsCallCallbackStub()
129 {
130     requestFuncMap_.clear();
131 }
132 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)133 int32_t ImsCallCallbackStub::OnRemoteRequest(
134     uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
135 {
136     std::u16string myDescriptor = ImsCallCallbackStub::GetDescriptor();
137     std::u16string remoteDescriptor = data.ReadInterfaceToken();
138     if (myDescriptor != remoteDescriptor) {
139         TELEPHONY_LOGE("descriptor checked fail");
140         return TELEPHONY_ERR_DESCRIPTOR_MISMATCH;
141     }
142     auto itFunc = requestFuncMap_.find(code);
143     if (itFunc != requestFuncMap_.end()) {
144         auto requestFunc = itFunc->second;
145         if (requestFunc != nullptr) {
146             return (this->*requestFunc)(data, reply);
147         }
148     }
149     TELEPHONY_LOGI("Function not found, need check.");
150     return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
151 }
152 
OnDialResponseInner(MessageParcel & data,MessageParcel & reply)153 int32_t ImsCallCallbackStub::OnDialResponseInner(MessageParcel &data, MessageParcel &reply)
154 {
155     int32_t slotId = data.ReadInt32();
156     auto info = static_cast<const HRilRadioResponseInfo *>(data.ReadRawData(sizeof(HRilRadioResponseInfo)));
157     if (info == nullptr) {
158         TELEPHONY_LOGE("[slot%{public}d] info is null.", slotId);
159         return TELEPHONY_ERR_ARGUMENT_INVALID;
160     }
161     reply.WriteInt32(DialResponse(slotId, *info));
162     return TELEPHONY_SUCCESS;
163 }
164 
OnHangUpResponseInner(MessageParcel & data,MessageParcel & reply)165 int32_t ImsCallCallbackStub::OnHangUpResponseInner(MessageParcel &data, MessageParcel &reply)
166 {
167     int32_t slotId = data.ReadInt32();
168     auto info = static_cast<const HRilRadioResponseInfo *>(data.ReadRawData(sizeof(HRilRadioResponseInfo)));
169     if (info == nullptr) {
170         TELEPHONY_LOGE("[slot%{public}d] info is null.", slotId);
171         return TELEPHONY_ERR_ARGUMENT_INVALID;
172     }
173     reply.WriteInt32(HangUpResponse(slotId, *info));
174     return TELEPHONY_SUCCESS;
175 }
176 
OnRejectResponseInner(MessageParcel & data,MessageParcel & reply)177 int32_t ImsCallCallbackStub::OnRejectResponseInner(MessageParcel &data, MessageParcel &reply)
178 {
179     int32_t slotId = data.ReadInt32();
180     auto info = static_cast<const HRilRadioResponseInfo *>(data.ReadRawData(sizeof(HRilRadioResponseInfo)));
181     if (info == nullptr) {
182         TELEPHONY_LOGE("[slot%{public}d] info is null.", slotId);
183         return TELEPHONY_ERR_ARGUMENT_INVALID;
184     }
185     reply.WriteInt32(RejectWithReasonResponse(slotId, *info));
186     return TELEPHONY_SUCCESS;
187 }
188 
OnAnswerResponseInner(MessageParcel & data,MessageParcel & reply)189 int32_t ImsCallCallbackStub::OnAnswerResponseInner(MessageParcel &data, MessageParcel &reply)
190 {
191     int32_t slotId = data.ReadInt32();
192     auto info = static_cast<const HRilRadioResponseInfo *>(data.ReadRawData(sizeof(HRilRadioResponseInfo)));
193     if (info == nullptr) {
194         TELEPHONY_LOGE("[slot%{public}d] info is null.", slotId);
195         return TELEPHONY_ERR_ARGUMENT_INVALID;
196     }
197     reply.WriteInt32(AnswerResponse(slotId, *info));
198     return TELEPHONY_SUCCESS;
199 }
200 
OnHoldCallResponseInner(MessageParcel & data,MessageParcel & reply)201 int32_t ImsCallCallbackStub::OnHoldCallResponseInner(MessageParcel &data, MessageParcel &reply)
202 {
203     int32_t slotId = data.ReadInt32();
204     auto info = static_cast<const HRilRadioResponseInfo *>(data.ReadRawData(sizeof(HRilRadioResponseInfo)));
205     if (info == nullptr) {
206         TELEPHONY_LOGE("[slot%{public}d] info is null.", slotId);
207         return TELEPHONY_ERR_ARGUMENT_INVALID;
208     }
209     reply.WriteInt32(HoldCallResponse(slotId, *info));
210     return TELEPHONY_SUCCESS;
211 }
212 
OnUnHoldCallResponseInner(MessageParcel & data,MessageParcel & reply)213 int32_t ImsCallCallbackStub::OnUnHoldCallResponseInner(MessageParcel &data, MessageParcel &reply)
214 {
215     int32_t slotId = data.ReadInt32();
216     auto info = static_cast<const HRilRadioResponseInfo *>(data.ReadRawData(sizeof(HRilRadioResponseInfo)));
217     if (info == nullptr) {
218         TELEPHONY_LOGE("[slot%{public}d] info is null.", slotId);
219         return TELEPHONY_ERR_ARGUMENT_INVALID;
220     }
221     reply.WriteInt32(UnHoldCallResponse(slotId, *info));
222     return TELEPHONY_SUCCESS;
223 }
224 
OnSwitchCallResponseInner(MessageParcel & data,MessageParcel & reply)225 int32_t ImsCallCallbackStub::OnSwitchCallResponseInner(MessageParcel &data, MessageParcel &reply)
226 {
227     int32_t slotId = data.ReadInt32();
228     auto info = static_cast<const HRilRadioResponseInfo *>(data.ReadRawData(sizeof(HRilRadioResponseInfo)));
229     if (info == nullptr) {
230         TELEPHONY_LOGE("[slot%{public}d] info is null.", slotId);
231         return TELEPHONY_ERR_ARGUMENT_INVALID;
232     }
233     reply.WriteInt32(SwitchCallResponse(slotId, *info));
234     return TELEPHONY_SUCCESS;
235 }
236 
OnStartDtmfResponseInner(MessageParcel & data,MessageParcel & reply)237 int32_t ImsCallCallbackStub::OnStartDtmfResponseInner(MessageParcel &data, MessageParcel &reply)
238 {
239     int32_t slotId = data.ReadInt32();
240     auto info = static_cast<const HRilRadioResponseInfo *>(data.ReadRawData(sizeof(HRilRadioResponseInfo)));
241     if (info == nullptr) {
242         TELEPHONY_LOGE("[slot%{public}d] info is null.", slotId);
243         return TELEPHONY_ERR_ARGUMENT_INVALID;
244     }
245     reply.WriteInt32(StartDtmfResponse(slotId, *info));
246     return TELEPHONY_SUCCESS;
247 }
248 
OnSendDtmfResponseInner(MessageParcel & data,MessageParcel & reply)249 int32_t ImsCallCallbackStub::OnSendDtmfResponseInner(MessageParcel &data, MessageParcel &reply)
250 {
251     int32_t slotId = data.ReadInt32();
252     int32_t callIndex = data.ReadInt32();
253     auto info = static_cast<const HRilRadioResponseInfo *>(data.ReadRawData(sizeof(HRilRadioResponseInfo)));
254     if (info == nullptr) {
255         TELEPHONY_LOGE("[slot%{public}d] info is null.", slotId);
256         return TELEPHONY_ERR_ARGUMENT_INVALID;
257     }
258     reply.WriteInt32(SendDtmfResponse(slotId, *info, callIndex));
259     return TELEPHONY_SUCCESS;
260 }
261 
OnStopDtmfResponseInner(MessageParcel & data,MessageParcel & reply)262 int32_t ImsCallCallbackStub::OnStopDtmfResponseInner(MessageParcel &data, MessageParcel &reply)
263 {
264     int32_t slotId = data.ReadInt32();
265     auto info = static_cast<const HRilRadioResponseInfo *>(data.ReadRawData(sizeof(HRilRadioResponseInfo)));
266     if (info == nullptr) {
267         TELEPHONY_LOGE("[slot%{public}d] info is null.", slotId);
268         return TELEPHONY_ERR_ARGUMENT_INVALID;
269     }
270     reply.WriteInt32(StopDtmfResponse(slotId, *info));
271     return TELEPHONY_SUCCESS;
272 }
273 
OnCallStateChangeReportInner(MessageParcel & data,MessageParcel & reply)274 int32_t ImsCallCallbackStub::OnCallStateChangeReportInner(MessageParcel &data, MessageParcel &reply)
275 {
276     int32_t slotId = data.ReadInt32();
277     reply.WriteInt32(CallStateChangeReport(slotId));
278     return TELEPHONY_SUCCESS;
279 }
280 
OnSetImsSwitchResponseInner(MessageParcel & data,MessageParcel & reply)281 int32_t ImsCallCallbackStub::OnSetImsSwitchResponseInner(MessageParcel &data, MessageParcel &reply)
282 {
283     int32_t slotId = data.ReadInt32();
284     auto info = static_cast<const HRilRadioResponseInfo *>(data.ReadRawData(sizeof(HRilRadioResponseInfo)));
285     if (info == nullptr) {
286         TELEPHONY_LOGE("[slot%{public}d] info is null.", slotId);
287         return TELEPHONY_ERR_ARGUMENT_INVALID;
288     }
289     reply.WriteInt32(SetImsSwitchResponse(slotId, *info));
290     return TELEPHONY_SUCCESS;
291 }
292 
OnGetImsSwitchResponseInner(MessageParcel & data,MessageParcel & reply)293 int32_t ImsCallCallbackStub::OnGetImsSwitchResponseInner(MessageParcel &data, MessageParcel &reply)
294 {
295     int32_t slotId = data.ReadInt32();
296     auto info = static_cast<const HRilRadioResponseInfo *>(data.ReadRawData(sizeof(HRilRadioResponseInfo)));
297     if (info == nullptr) {
298         TELEPHONY_LOGE("[slot%{public}d] info is null.", slotId);
299         int32_t active = data.ReadInt32();
300         reply.WriteInt32(GetImsSwitchResponse(slotId, active));
301         return TELEPHONY_SUCCESS;
302     }
303     reply.WriteInt32(GetImsSwitchResponse(slotId, *info));
304     return TELEPHONY_SUCCESS;
305 }
306 
OnGetImsCallsDataResponseInner(MessageParcel & data,MessageParcel & reply)307 int32_t ImsCallCallbackStub::OnGetImsCallsDataResponseInner(MessageParcel &data, MessageParcel &reply)
308 {
309     int32_t slotId = data.ReadInt32();
310     auto info = static_cast<const HRilRadioResponseInfo *>(data.ReadRawData(sizeof(HRilRadioResponseInfo)));
311     if (info == nullptr) {
312         TELEPHONY_LOGE("[slot%{public}d] info is null.", slotId);
313         auto callList = std::make_shared<ImsCurrentCallList>();
314         callList->callSize = data.ReadInt32();
315         callList->flag = data.ReadInt32();
316         int32_t len = data.ReadInt32();
317         if (len < 0 || len > MAX_SIZE) {
318             TELEPHONY_LOGE("ImsCallCallbackStub::OnGetImsCallsDataResponseInner callSize error");
319             return TELEPHONY_ERR_FAIL;
320         }
321         for (int32_t i = 0; i < len; i++) {
322             ImsCurrentCall call;
323             call.index = data.ReadInt32();
324             call.dir = data.ReadInt32();
325             call.state = data.ReadInt32();
326             call.mode = data.ReadInt32();
327             call.mpty = data.ReadInt32();
328             call.voiceDomain = data.ReadInt32();
329             call.callType = static_cast<ImsCallType>(data.ReadInt32());
330             data.ReadString(call.number);
331             call.type = data.ReadInt32();
332             data.ReadString(call.alpha);
333             callList->calls.push_back(call);
334         }
335         reply.WriteInt32(GetImsCallsDataResponse(slotId, *callList));
336         return TELEPHONY_SUCCESS;
337     }
338     reply.WriteInt32(GetImsCallsDataResponse(slotId, *info));
339     return TELEPHONY_SUCCESS;
340 }
341 
OnSetMuteResponseInner(MessageParcel & data,MessageParcel & reply)342 int32_t ImsCallCallbackStub::OnSetMuteResponseInner(MessageParcel &data, MessageParcel &reply)
343 {
344     int32_t slotId = data.ReadInt32();
345     auto info = static_cast<const MuteControlResponse *>(data.ReadRawData(sizeof(MuteControlResponse)));
346     if (info == nullptr) {
347         TELEPHONY_LOGE("[slot%{public}d] info is null.", slotId);
348         return TELEPHONY_ERR_ARGUMENT_INVALID;
349     }
350     reply.WriteInt32(SetMuteResponse(slotId, *info));
351     return TELEPHONY_SUCCESS;
352 }
353 
OnCallRingBackReportInner(MessageParcel & data,MessageParcel & reply)354 int32_t ImsCallCallbackStub::OnCallRingBackReportInner(MessageParcel &data, MessageParcel &reply)
355 {
356     int32_t slotId = data.ReadInt32();
357     auto info = static_cast<const RingbackVoice *>(data.ReadRawData(sizeof(RingbackVoice)));
358     if (info == nullptr) {
359         TELEPHONY_LOGE("[slot%{public}d] info is null.", slotId);
360         return TELEPHONY_ERR_ARGUMENT_INVALID;
361     }
362     reply.WriteInt32(CallRingBackReport(slotId, *info));
363     return TELEPHONY_SUCCESS;
364 }
365 
OnLastCallFailReasonResponseInner(MessageParcel & data,MessageParcel & reply)366 int32_t ImsCallCallbackStub::OnLastCallFailReasonResponseInner(MessageParcel &data, MessageParcel &reply)
367 {
368     int32_t slotId = data.ReadInt32();
369     DisconnectedDetails details;
370     details.reason = static_cast<const DisconnectedReason>(data.ReadInt32());
371     details.message = data.ReadString();
372     reply.WriteInt32(LastCallFailReasonResponse(slotId, details));
373     return TELEPHONY_SUCCESS;
374 }
375 
OnSetClipResponseInner(MessageParcel & data,MessageParcel & reply)376 int32_t ImsCallCallbackStub::OnSetClipResponseInner(MessageParcel &data, MessageParcel &reply)
377 {
378     int32_t slotId = data.ReadInt32();
379     SsBaseResult resultInfo;
380     resultInfo.index = data.ReadInt32();
381     resultInfo.result = data.ReadInt32();
382     resultInfo.reason = data.ReadInt32();
383     resultInfo.message = data.ReadString();
384     if (resultInfo.index == INVALID_INDEX) {
385         reply.WriteInt32(TELEPHONY_SUCCESS);
386     } else {
387         reply.WriteInt32(SetClipResponse(slotId, resultInfo));
388     }
389     return TELEPHONY_SUCCESS;
390 }
391 
OnGetClipResponseInner(MessageParcel & data,MessageParcel & reply)392 int32_t ImsCallCallbackStub::OnGetClipResponseInner(MessageParcel &data, MessageParcel &reply)
393 {
394     int32_t slotId = data.ReadInt32();
395     GetClipResult result;
396     result.result.index = data.ReadInt32();
397     result.result.result = data.ReadInt32();
398     result.result.reason = data.ReadInt32();
399     result.result.message = data.ReadString();
400     result.action = data.ReadInt32();
401     result.clipStat = data.ReadInt32();
402     if (result.result.index == INVALID_INDEX) {
403         reply.WriteInt32(TELEPHONY_SUCCESS);
404     } else {
405         reply.WriteInt32(GetClipResponse(slotId, result));
406     }
407     return TELEPHONY_SUCCESS;
408 }
409 
OnGetClirResponseInner(MessageParcel & data,MessageParcel & reply)410 int32_t ImsCallCallbackStub::OnGetClirResponseInner(MessageParcel &data, MessageParcel &reply)
411 {
412     int32_t slotId = data.ReadInt32();
413     GetClirResult result;
414     result.result.index = data.ReadInt32();
415     result.result.result = data.ReadInt32();
416     result.result.reason = data.ReadInt32();
417     result.result.message = data.ReadString();
418     result.action = data.ReadInt32();
419     result.clirStat = data.ReadInt32();
420     if (result.result.index == INVALID_INDEX) {
421         reply.WriteInt32(TELEPHONY_SUCCESS);
422     } else {
423         reply.WriteInt32(GetClirResponse(slotId, result));
424     }
425     return TELEPHONY_SUCCESS;
426 }
427 
OnSetClirResponseInner(MessageParcel & data,MessageParcel & reply)428 int32_t ImsCallCallbackStub::OnSetClirResponseInner(MessageParcel &data, MessageParcel &reply)
429 {
430     int32_t slotId = data.ReadInt32();
431     SsBaseResult resultInfo;
432     resultInfo.index = data.ReadInt32();
433     resultInfo.result = data.ReadInt32();
434     resultInfo.reason = data.ReadInt32();
435     resultInfo.message = data.ReadString();
436     if (resultInfo.index == INVALID_INDEX) {
437         reply.WriteInt32(TELEPHONY_SUCCESS);
438     } else {
439         reply.WriteInt32(SetClirResponse(slotId, resultInfo));
440     }
441     return TELEPHONY_SUCCESS;
442 }
443 
OnGetCallTransferResponseInner(MessageParcel & data,MessageParcel & reply)444 int32_t ImsCallCallbackStub::OnGetCallTransferResponseInner(MessageParcel &data, MessageParcel &reply)
445 {
446     int32_t slotId = data.ReadInt32();
447     auto cFQueryList = std::make_shared<CallForwardQueryInfoList>();
448     cFQueryList->result.index = data.ReadInt32();
449     cFQueryList->result.result = data.ReadInt32();
450     cFQueryList->result.reason = data.ReadInt32();
451     data.ReadString(cFQueryList->result.message);
452     cFQueryList->callSize = data.ReadInt32();
453     cFQueryList->flag = data.ReadInt32();
454     int32_t len = data.ReadInt32();
455     if (len < 0 || len > MAX_SIZE) {
456         TELEPHONY_LOGE("ImsCallCallbackStub::OnGetCallTransferResponseInner callSize error");
457         return TELEPHONY_ERR_FAIL;
458     }
459     for (int32_t i = 0; i < len; i++) {
460         CallForwardQueryResult call;
461         call.serial = data.ReadInt32();
462         call.result = data.ReadInt32();
463         call.status = data.ReadInt32();
464         call.classx = data.ReadInt32();
465         data.ReadString(call.number);
466         call.type = data.ReadInt32();
467         call.reason = data.ReadInt32();
468         call.time = data.ReadInt32();
469         call.startHour = data.ReadInt32();
470         call.startMinute = data.ReadInt32();
471         call.endHour = data.ReadInt32();
472         call.endMinute = data.ReadInt32();
473         cFQueryList->calls.push_back(call);
474     }
475     if (cFQueryList->result.index == INVALID_INDEX) {
476         reply.WriteInt32(TELEPHONY_SUCCESS);
477     } else {
478         reply.WriteInt32(GetCallTransferResponse(slotId, *cFQueryList));
479     }
480     return TELEPHONY_SUCCESS;
481 }
482 
OnSetCallTransferResponseInner(MessageParcel & data,MessageParcel & reply)483 int32_t ImsCallCallbackStub::OnSetCallTransferResponseInner(MessageParcel &data, MessageParcel &reply)
484 {
485     int32_t slotId = data.ReadInt32();
486     SsBaseResult resultInfo;
487     resultInfo.index = data.ReadInt32();
488     resultInfo.result = data.ReadInt32();
489     resultInfo.reason = data.ReadInt32();
490     resultInfo.message = data.ReadString();
491     if (resultInfo.index == INVALID_INDEX) {
492         reply.WriteInt32(TELEPHONY_SUCCESS);
493     } else {
494         reply.WriteInt32(SetCallTransferResponse(slotId, resultInfo));
495     }
496     return TELEPHONY_SUCCESS;
497 }
498 
OnGetCallRestrictionResponseInner(MessageParcel & data,MessageParcel & reply)499 int32_t ImsCallCallbackStub::OnGetCallRestrictionResponseInner(MessageParcel &data, MessageParcel &reply)
500 {
501     int32_t slotId = data.ReadInt32();
502     CallRestrictionResult result;
503     result.result.index = data.ReadInt32();
504     result.result.result = data.ReadInt32();
505     result.result.reason = data.ReadInt32();
506     result.result.message = data.ReadString();
507     result.status = data.ReadInt32();
508     result.classCw = data.ReadInt32();
509     if (result.result.index == INVALID_INDEX) {
510         reply.WriteInt32(TELEPHONY_SUCCESS);
511     } else {
512         reply.WriteInt32(GetCallRestrictionResponse(slotId, result));
513     }
514     return TELEPHONY_SUCCESS;
515 }
516 
OnSetCallRestrictionResponseInner(MessageParcel & data,MessageParcel & reply)517 int32_t ImsCallCallbackStub::OnSetCallRestrictionResponseInner(MessageParcel &data, MessageParcel &reply)
518 {
519     int32_t slotId = data.ReadInt32();
520     SsBaseResult resultInfo;
521     resultInfo.index = data.ReadInt32();
522     resultInfo.result = data.ReadInt32();
523     resultInfo.reason = data.ReadInt32();
524     resultInfo.message = data.ReadString();
525     if (resultInfo.index == INVALID_INDEX) {
526         reply.WriteInt32(TELEPHONY_SUCCESS);
527     } else {
528         reply.WriteInt32(SetCallRestrictionResponse(slotId, resultInfo));
529     }
530     return TELEPHONY_SUCCESS;
531 }
532 
OnGetCallWaitingResponseInner(MessageParcel & data,MessageParcel & reply)533 int32_t ImsCallCallbackStub::OnGetCallWaitingResponseInner(MessageParcel &data, MessageParcel &reply)
534 {
535     int32_t slotId = data.ReadInt32();
536     CallWaitResult result;
537     result.result.index = data.ReadInt32();
538     result.result.result = data.ReadInt32();
539     result.result.reason = data.ReadInt32();
540     result.result.message = data.ReadString();
541     result.status = data.ReadInt32();
542     result.classCw = data.ReadInt32();
543     if (result.result.index == INVALID_INDEX) {
544         reply.WriteInt32(TELEPHONY_SUCCESS);
545     } else {
546         reply.WriteInt32(GetCallWaitingResponse(slotId, result));
547     }
548     return TELEPHONY_SUCCESS;
549 }
550 
OnSetCallWaitingResponseInner(MessageParcel & data,MessageParcel & reply)551 int32_t ImsCallCallbackStub::OnSetCallWaitingResponseInner(MessageParcel &data, MessageParcel &reply)
552 {
553     int32_t slotId = data.ReadInt32();
554     SsBaseResult resultInfo;
555     resultInfo.index = data.ReadInt32();
556     resultInfo.result = data.ReadInt32();
557     resultInfo.reason = data.ReadInt32();
558     resultInfo.message = data.ReadString();
559     if (resultInfo.index == INVALID_INDEX) {
560         reply.WriteInt32(TELEPHONY_SUCCESS);
561     } else {
562         reply.WriteInt32(SetCallWaitingResponse(slotId, resultInfo));
563     }
564     return TELEPHONY_SUCCESS;
565 }
566 
OnSetColrResponseInner(MessageParcel & data,MessageParcel & reply)567 int32_t ImsCallCallbackStub::OnSetColrResponseInner(MessageParcel &data, MessageParcel &reply)
568 {
569     int32_t slotId = data.ReadInt32();
570     SsBaseResult resultInfo;
571     resultInfo.index = data.ReadInt32();
572     resultInfo.result = data.ReadInt32();
573     resultInfo.reason = data.ReadInt32();
574     resultInfo.message = data.ReadString();
575     if (resultInfo.index == INVALID_INDEX) {
576         reply.WriteInt32(TELEPHONY_SUCCESS);
577     } else {
578         reply.WriteInt32(SetColrResponse(slotId, resultInfo));
579     }
580     return TELEPHONY_SUCCESS;
581 }
582 
OnGetColrResponseInner(MessageParcel & data,MessageParcel & reply)583 int32_t ImsCallCallbackStub::OnGetColrResponseInner(MessageParcel &data, MessageParcel &reply)
584 {
585     int32_t slotId = data.ReadInt32();
586     GetColrResult result;
587     result.result.index = data.ReadInt32();
588     result.result.result = data.ReadInt32();
589     result.result.reason = data.ReadInt32();
590     result.result.message = data.ReadString();
591     result.action = data.ReadInt32();
592     result.colrStat = data.ReadInt32();
593     if (result.result.index == INVALID_INDEX) {
594         reply.WriteInt32(TELEPHONY_SUCCESS);
595     } else {
596         reply.WriteInt32(GetColrResponse(slotId, result));
597     }
598     return TELEPHONY_SUCCESS;
599 }
600 
OnSetColpResponseInner(MessageParcel & data,MessageParcel & reply)601 int32_t ImsCallCallbackStub::OnSetColpResponseInner(MessageParcel &data, MessageParcel &reply)
602 {
603     int32_t slotId = data.ReadInt32();
604     SsBaseResult resultInfo;
605     resultInfo.index = data.ReadInt32();
606     resultInfo.result = data.ReadInt32();
607     resultInfo.reason = data.ReadInt32();
608     resultInfo.message = data.ReadString();
609     if (resultInfo.index == INVALID_INDEX) {
610         reply.WriteInt32(TELEPHONY_SUCCESS);
611     } else {
612         reply.WriteInt32(SetColpResponse(slotId, resultInfo));
613     }
614     return TELEPHONY_SUCCESS;
615 }
616 
OnGetColpResponseInner(MessageParcel & data,MessageParcel & reply)617 int32_t ImsCallCallbackStub::OnGetColpResponseInner(MessageParcel &data, MessageParcel &reply)
618 {
619     int32_t slotId = data.ReadInt32();
620     GetColpResult result;
621     result.result.index = data.ReadInt32();
622     result.result.result = data.ReadInt32();
623     result.result.reason = data.ReadInt32();
624     result.result.message = data.ReadString();
625     result.action = data.ReadInt32();
626     result.colpStat = data.ReadInt32();
627     if (result.result.index == INVALID_INDEX) {
628         reply.WriteInt32(TELEPHONY_SUCCESS);
629     } else {
630         reply.WriteInt32(GetColpResponse(slotId, result));
631     }
632     return TELEPHONY_SUCCESS;
633 }
634 
OnCombineConferenceResponseInner(MessageParcel & data,MessageParcel & reply)635 int32_t ImsCallCallbackStub::OnCombineConferenceResponseInner(MessageParcel &data, MessageParcel &reply)
636 {
637     int32_t slotId = data.ReadInt32();
638     auto info = static_cast<const HRilRadioResponseInfo *>(data.ReadRawData(sizeof(HRilRadioResponseInfo)));
639     if (info == nullptr) {
640         TELEPHONY_LOGE("[slot%{public}d] info is null.", slotId);
641         return TELEPHONY_ERR_ARGUMENT_INVALID;
642     }
643     reply.WriteInt32(CombineConferenceResponse(slotId, *info));
644     return TELEPHONY_SUCCESS;
645 }
646 
OnInviteToConferenceResponseInner(MessageParcel & data,MessageParcel & reply)647 int32_t ImsCallCallbackStub::OnInviteToConferenceResponseInner(MessageParcel &data, MessageParcel &reply)
648 {
649     int32_t slotId = data.ReadInt32();
650     auto info = static_cast<const HRilRadioResponseInfo *>(data.ReadRawData(sizeof(HRilRadioResponseInfo)));
651     if (info == nullptr) {
652         TELEPHONY_LOGE("[slot%{public}d] info is null.", slotId);
653         return TELEPHONY_ERR_ARGUMENT_INVALID;
654     }
655     reply.WriteInt32(InviteToConferenceResponse(slotId, *info));
656     return TELEPHONY_SUCCESS;
657 }
658 
DialResponse(int32_t slotId,const HRilRadioResponseInfo & info)659 int32_t ImsCallCallbackStub::DialResponse(int32_t slotId, const HRilRadioResponseInfo &info)
660 {
661     TELEPHONY_LOGI("[slot%{public}d] entry", slotId);
662     return SendEvent(slotId, RadioEvent::RADIO_DIAL, info);
663 }
664 
HangUpResponse(int32_t slotId,const HRilRadioResponseInfo & info)665 int32_t ImsCallCallbackStub::HangUpResponse(int32_t slotId, const HRilRadioResponseInfo &info)
666 {
667     TELEPHONY_LOGI("[slot%{public}d] entry", slotId);
668     return SendEvent(slotId, RadioEvent::RADIO_HANGUP_CONNECT, info);
669 }
670 
RejectWithReasonResponse(int32_t slotId,const HRilRadioResponseInfo & info)671 int32_t ImsCallCallbackStub::RejectWithReasonResponse(int32_t slotId, const HRilRadioResponseInfo &info)
672 {
673     TELEPHONY_LOGI("[slot%{public}d] entry", slotId);
674     return SendEvent(slotId, RadioEvent::RADIO_REJECT_CALL, info);
675 }
676 
AnswerResponse(int32_t slotId,const HRilRadioResponseInfo & info)677 int32_t ImsCallCallbackStub::AnswerResponse(int32_t slotId, const HRilRadioResponseInfo &info)
678 {
679     TELEPHONY_LOGI("[slot%{public}d] entry", slotId);
680     return SendEvent(slotId, RadioEvent::RADIO_ACCEPT_CALL, info);
681 }
682 
HoldCallResponse(int32_t slotId,const HRilRadioResponseInfo & info)683 int32_t ImsCallCallbackStub::HoldCallResponse(int32_t slotId, const HRilRadioResponseInfo &info)
684 {
685     TELEPHONY_LOGI("[slot%{public}d] entry", slotId);
686     return SendEvent(slotId, RadioEvent::RADIO_HOLD_CALL, info);
687 }
688 
UnHoldCallResponse(int32_t slotId,const HRilRadioResponseInfo & info)689 int32_t ImsCallCallbackStub::UnHoldCallResponse(int32_t slotId, const HRilRadioResponseInfo &info)
690 {
691     TELEPHONY_LOGI("[slot%{public}d] entry", slotId);
692     return SendEvent(slotId, RadioEvent::RADIO_ACTIVE_CALL, info);
693 }
694 
SwitchCallResponse(int32_t slotId,const HRilRadioResponseInfo & info)695 int32_t ImsCallCallbackStub::SwitchCallResponse(int32_t slotId, const HRilRadioResponseInfo &info)
696 {
697     TELEPHONY_LOGI("[slot%{public}d] entry", slotId);
698     return SendEvent(slotId, RadioEvent::RADIO_SWAP_CALL, info);
699 }
700 
StartDtmfResponse(int32_t slotId,const HRilRadioResponseInfo & info)701 int32_t ImsCallCallbackStub::StartDtmfResponse(int32_t slotId, const HRilRadioResponseInfo &info)
702 {
703     TELEPHONY_LOGI("[slot%{public}d] entry", slotId);
704     return SendEvent(slotId, RadioEvent::RADIO_START_DTMF, info);
705 }
706 
SendDtmfResponse(int32_t slotId,const HRilRadioResponseInfo & info,int32_t callIndex)707 int32_t ImsCallCallbackStub::SendDtmfResponse(int32_t slotId, const HRilRadioResponseInfo &info, int32_t callIndex)
708 {
709     TELEPHONY_LOGI("[slot%{public}d] entry", slotId);
710     auto handler = DelayedSingleton<ImsCallClient>::GetInstance()->GetHandler(slotId);
711     if (handler == nullptr) {
712         TELEPHONY_LOGE("[slot%{public}d] handler is null", slotId);
713         return TELEPHONY_ERR_LOCAL_PTR_NULL;
714     }
715     std::shared_ptr<HRilRadioResponseInfo> responseInfo = std::make_shared<HRilRadioResponseInfo>();
716 
717     *responseInfo = info;
718     responseInfo->flag = callIndex;
719     AppExecFwk::InnerEvent::Pointer response =
720         AppExecFwk::InnerEvent::Get(RadioEvent::RADIO_SEND_DTMF, responseInfo, IMS_CALL);
721     bool ret = handler->SendEvent(response);
722     if (!ret) {
723         TELEPHONY_LOGE("[slot%{public}d] SendEvent failed!", slotId);
724         return TELEPHONY_ERR_FAIL;
725     }
726     return TELEPHONY_SUCCESS;
727 }
728 
StopDtmfResponse(int32_t slotId,const HRilRadioResponseInfo & info)729 int32_t ImsCallCallbackStub::StopDtmfResponse(int32_t slotId, const HRilRadioResponseInfo &info)
730 {
731     TELEPHONY_LOGI("[slot%{public}d] entry", slotId);
732     return SendEvent(slotId, RadioEvent::RADIO_STOP_DTMF, info);
733 }
734 
CallStateChangeReport(int32_t slotId)735 int32_t ImsCallCallbackStub::CallStateChangeReport(int32_t slotId)
736 {
737     TELEPHONY_LOGI("[slot%{public}d] entry", slotId);
738     auto handler = DelayedSingleton<ImsCallClient>::GetInstance()->GetHandler(slotId);
739     if (handler == nullptr) {
740         TELEPHONY_LOGE("[slot%{public}d] handler is null", slotId);
741         return TELEPHONY_ERR_LOCAL_PTR_NULL;
742     }
743 
744     bool ret = handler->SendEvent(RadioEvent::RADIO_IMS_CALL_STATUS_INFO);
745     if (!ret) {
746         TELEPHONY_LOGE("[slot%{public}d] SendEvent failed!", slotId);
747         return TELEPHONY_ERR_FAIL;
748     }
749     return TELEPHONY_SUCCESS;
750 }
751 
GetImsCallsDataResponse(int32_t slotId,const HRilRadioResponseInfo & info)752 int32_t ImsCallCallbackStub::GetImsCallsDataResponse(int32_t slotId, const HRilRadioResponseInfo &info)
753 {
754     TELEPHONY_LOGI("[slot%{public}d] entry", slotId);
755     return SendEvent(slotId, RadioEvent::RADIO_IMS_GET_CALL_DATA, info);
756 }
757 
GetImsCallsDataResponse(int32_t slotId,const ImsCurrentCallList & callList)758 int32_t ImsCallCallbackStub::GetImsCallsDataResponse(int32_t slotId, const ImsCurrentCallList &callList)
759 {
760     TELEPHONY_LOGI("[slot%{public}d] entry", slotId);
761     auto handler = DelayedSingleton<ImsCallClient>::GetInstance()->GetHandler(slotId);
762     if (handler == nullptr) {
763         TELEPHONY_LOGE("[slot%{public}d] handler is null", slotId);
764         return TELEPHONY_ERR_LOCAL_PTR_NULL;
765     }
766     auto imsCurrentCallList = std::make_shared<ImsCurrentCallList>();
767     *imsCurrentCallList = callList;
768     bool ret = handler->SendEvent(RadioEvent::RADIO_IMS_GET_CALL_DATA, imsCurrentCallList);
769     if (!ret) {
770         TELEPHONY_LOGE("[slot%{public}d] SendEvent failed!", slotId);
771         return TELEPHONY_ERR_FAIL;
772     }
773     return TELEPHONY_SUCCESS;
774 }
775 
SetImsSwitchResponse(int32_t slotId,const HRilRadioResponseInfo & info)776 int32_t ImsCallCallbackStub::SetImsSwitchResponse(int32_t slotId, const HRilRadioResponseInfo &info)
777 {
778     TELEPHONY_LOGI("[slot%{public}d] entry", slotId);
779     return SendEvent(slotId, RadioEvent::RADIO_SET_IMS_SWITCH_STATUS, info);
780 }
781 
GetImsSwitchResponse(int32_t slotId,const HRilRadioResponseInfo & info)782 int32_t ImsCallCallbackStub::GetImsSwitchResponse(int32_t slotId, const HRilRadioResponseInfo &info)
783 {
784     TELEPHONY_LOGI("[slot%{public}d] entry", slotId);
785     return SendEvent(slotId, RadioEvent::RADIO_GET_IMS_SWITCH_STATUS, info);
786 }
787 
GetImsSwitchResponse(int32_t slotId,int32_t active)788 int32_t ImsCallCallbackStub::GetImsSwitchResponse(int32_t slotId, int32_t active)
789 {
790     TELEPHONY_LOGI("[slot%{public}d] entry active:%{public}d", slotId, active);
791     auto handler = DelayedSingleton<ImsCallClient>::GetInstance()->GetHandler(slotId);
792     if (handler == nullptr || handler.get() == nullptr) {
793         TELEPHONY_LOGE("[slot%{public}d] handler is null", slotId);
794         return TELEPHONY_ERR_LOCAL_PTR_NULL;
795     }
796     handler->SendEvent(RadioEvent::RADIO_GET_IMS_SWITCH_STATUS, active);
797     return TELEPHONY_SUCCESS;
798 }
799 
SetMuteResponse(int32_t slotId,const MuteControlResponse & response)800 int32_t ImsCallCallbackStub::SetMuteResponse(int32_t slotId, const MuteControlResponse &response)
801 {
802     TELEPHONY_LOGI("[slot%{public}d] entry", slotId);
803     return TELEPHONY_SUCCESS;
804 }
805 
CallRingBackReport(int32_t slotId,const RingbackVoice & info)806 int32_t ImsCallCallbackStub::CallRingBackReport(int32_t slotId, const RingbackVoice &info)
807 {
808     TELEPHONY_LOGI("[slot%{public}d] entry", slotId);
809     auto handler = DelayedSingleton<ImsCallClient>::GetInstance()->GetHandler(slotId);
810     if (handler == nullptr) {
811         TELEPHONY_LOGE("[slot%{public}d] handler is null", slotId);
812         return TELEPHONY_ERR_LOCAL_PTR_NULL;
813     }
814     auto ringbackVoice = std::make_shared<RingbackVoice>();
815     *ringbackVoice = info;
816     bool ret = handler->SendEvent(RadioEvent::RADIO_CALL_RINGBACK_VOICE, ringbackVoice);
817     if (!ret) {
818         TELEPHONY_LOGE("[slot%{public}d] SendEvent failed!", slotId);
819         return TELEPHONY_ERR_FAIL;
820     }
821     return TELEPHONY_SUCCESS;
822 }
823 
LastCallFailReasonResponse(int32_t slotId,const DisconnectedDetails & details)824 int32_t ImsCallCallbackStub::LastCallFailReasonResponse(int32_t slotId, const DisconnectedDetails &details)
825 {
826     TELEPHONY_LOGI("[slot%{public}d] entry, reason is %{public}d", slotId, details.reason);
827     auto handler = DelayedSingleton<ImsCallClient>::GetInstance()->GetHandler(slotId);
828     if (handler == nullptr) {
829         TELEPHONY_LOGE("[slot%{public}d] handler is null", slotId);
830         return TELEPHONY_ERR_LOCAL_PTR_NULL;
831     }
832     std::shared_ptr<DisconnectedDetails> detailsInfo = std::make_shared<DisconnectedDetails>();
833     detailsInfo->reason = details.reason;
834     detailsInfo->message = details.message;
835     CellularCallConfig config;
836     auto vecReasonInfo = config.GetImsCallDisconnectResoninfoMappingConfig(slotId);
837     for (auto reasonInfo : vecReasonInfo) {
838         char *p = nullptr;
839         char *ptr = nullptr;
840         ptr = strtok_r((char *)(reasonInfo.c_str()), "|", &p);
841         int32_t tmpReason = (int32_t)std::atoi(ptr);
842         int flag = false;
843         while (tmpReason == static_cast<int32_t>(detailsInfo->reason)) {
844             ptr = strtok_r(nullptr, "|", &p);
845             if (ptr == nullptr) {
846                 break;
847             }
848             if (!flag) {
849                 detailsInfo->message = ptr;
850                 flag = true;
851             } else {
852                 detailsInfo->reason = static_cast<DisconnectedReason>(std::atoi(ptr));
853             }
854         }
855         if (flag) {
856             break;
857         }
858     }
859     bool ret = handler->SendEvent(RadioEvent::RADIO_GET_CALL_FAIL_REASON, detailsInfo);
860     if (!ret) {
861         TELEPHONY_LOGE("[slot%{public}d] SendEvent failed!", slotId);
862         return TELEPHONY_ERR_FAIL;
863     }
864     return TELEPHONY_SUCCESS;
865 }
866 
SetClipResponse(int32_t slotId,const SsBaseResult & resultInfo)867 int32_t ImsCallCallbackStub::SetClipResponse(int32_t slotId, const SsBaseResult &resultInfo)
868 {
869     TELEPHONY_LOGI("[slot%{public}d] entry", slotId);
870     return SendEvent(slotId, RadioEvent::RADIO_SET_CALL_CLIP, resultInfo);
871 }
872 
GetClipResponse(int32_t slotId,const GetClipResult & result)873 int32_t ImsCallCallbackStub::GetClipResponse(int32_t slotId, const GetClipResult &result)
874 {
875     TELEPHONY_LOGI("[slot%{public}d] entry", slotId);
876     // CS fall back when IMS return failed
877     if (result.result.result == IMS_ERROR_UT_CS_FALLBACK) {
878         SupplementRequestCs supplementRequest;
879         return supplementRequest.GetClipRequest(slotId, result.result.index);
880     }
881     auto handler = DelayedSingleton<ImsCallClient>::GetInstance()->GetHandler(slotId);
882     if (handler == nullptr) {
883         TELEPHONY_LOGE("[slot%{public}d] handler is null", slotId);
884         return TELEPHONY_ERR_LOCAL_PTR_NULL;
885     }
886     auto clipResponse = std::make_shared<GetClipResult>();
887     clipResponse->action = result.action;
888     clipResponse->clipStat = result.clipStat;
889     clipResponse->result.index = result.result.index;
890     clipResponse->result.result = result.result.result;
891     clipResponse->result.reason = result.result.reason;
892     clipResponse->result.message = result.result.message;
893     AppExecFwk::InnerEvent::Pointer response =
894         AppExecFwk::InnerEvent::Get(RadioEvent::RADIO_GET_CALL_CLIP, clipResponse, result.result.index);
895     bool ret = handler->SendEvent(response);
896     if (!ret) {
897         TELEPHONY_LOGE("[slot%{public}d] SendEvent failed!", slotId);
898         return TELEPHONY_ERR_FAIL;
899     }
900     return TELEPHONY_SUCCESS;
901 }
902 
GetClirResponse(int32_t slotId,const GetClirResult & result)903 int32_t ImsCallCallbackStub::GetClirResponse(int32_t slotId, const GetClirResult &result)
904 {
905     TELEPHONY_LOGI("[slot%{public}d] entry", slotId);
906     // CS fall back when IMS return failed
907     if (result.result.result == IMS_ERROR_UT_CS_FALLBACK) {
908         SupplementRequestCs supplementRequest;
909         return supplementRequest.GetClirRequest(slotId, result.result.index);
910     }
911     auto handler = DelayedSingleton<ImsCallClient>::GetInstance()->GetHandler(slotId);
912     if (handler == nullptr) {
913         TELEPHONY_LOGE("[slot%{public}d] handler is null", slotId);
914         return TELEPHONY_ERR_LOCAL_PTR_NULL;
915     }
916     auto clirResponse = std::make_shared<GetClirResult>();
917     clirResponse->action = result.action;
918     clirResponse->clirStat = result.clirStat;
919     clirResponse->result.index = result.result.index;
920     clirResponse->result.result = result.result.result;
921     clirResponse->result.reason = result.result.reason;
922     clirResponse->result.message = result.result.message;
923     AppExecFwk::InnerEvent::Pointer response =
924         AppExecFwk::InnerEvent::Get(RadioEvent::RADIO_GET_CALL_CLIR, clirResponse, result.result.index);
925     bool ret = handler->SendEvent(response);
926     if (!ret) {
927         TELEPHONY_LOGE("[slot%{public}d] SendEvent failed!", slotId);
928         return TELEPHONY_ERR_FAIL;
929     }
930     return TELEPHONY_SUCCESS;
931 }
932 
SetClirResponse(int32_t slotId,const SsBaseResult & resultInfo)933 int32_t ImsCallCallbackStub::SetClirResponse(int32_t slotId, const SsBaseResult &resultInfo)
934 {
935     TELEPHONY_LOGI("[slot%{public}d] entry", slotId);
936     // CS fall back when IMS return failed
937     if (resultInfo.result == IMS_ERROR_UT_CS_FALLBACK) {
938         SupplementRequestCs supplementRequest;
939         SsRequestCommand ss;
940         int32_t ret = GetSsRequestCommand(slotId, resultInfo.index, ss);
941         if (ret != TELEPHONY_SUCCESS) {
942             TELEPHONY_LOGI("[slot%{public}d] cs fall back error since haven't found the ss command", slotId);
943             return ret;
944         }
945         return supplementRequest.SetClirRequest(slotId, ss.clirAction, resultInfo.index);
946     }
947     return SendEvent(slotId, RadioEvent::RADIO_SET_CALL_CLIR, resultInfo);
948 }
949 
GetCallTransferResponse(int32_t slotId,const CallForwardQueryInfoList & cFQueryList)950 int32_t ImsCallCallbackStub::GetCallTransferResponse(int32_t slotId, const CallForwardQueryInfoList &cFQueryList)
951 {
952     TELEPHONY_LOGI("[slot%{public}d] entry", slotId);
953     // CS fall back when IMS return failed
954     if (cFQueryList.result.result == IMS_ERROR_UT_CS_FALLBACK) {
955         SsRequestCommand ss;
956         int32_t ret = GetSsRequestCommand(slotId, cFQueryList.result.index, ss);
957         if (ret != TELEPHONY_SUCCESS) {
958             TELEPHONY_LOGI("[slot%{public}d] cs fall back error since haven't found the ss command", slotId);
959             return ret;
960         }
961         SupplementRequestCs supplementRequest;
962         return supplementRequest.GetCallTransferRequest(slotId, ss.cfReason, cFQueryList.result.index);
963     }
964     auto handler = DelayedSingleton<ImsCallClient>::GetInstance()->GetHandler(slotId);
965     if (handler == nullptr) {
966         TELEPHONY_LOGE("[slot%{public}d] handler is null", slotId);
967         return TELEPHONY_ERR_LOCAL_PTR_NULL;
968     }
969     auto callTransferResponse = std::make_shared<CallForwardQueryInfoList>();
970     BuildCallForwardInfo(cFQueryList, *callTransferResponse);
971     AppExecFwk::InnerEvent::Pointer response =
972         AppExecFwk::InnerEvent::Get(RadioEvent::RADIO_GET_CALL_FORWARD, callTransferResponse, cFQueryList.result.index);
973     bool ret = handler->SendEvent(response);
974     if (!ret) {
975         TELEPHONY_LOGE("[slot%{public}d] SendEvent failed!", slotId);
976         return TELEPHONY_ERR_FAIL;
977     }
978     return TELEPHONY_SUCCESS;
979 }
980 
SetCallTransferResponse(int32_t slotId,const SsBaseResult & resultInfo)981 int32_t ImsCallCallbackStub::SetCallTransferResponse(int32_t slotId, const SsBaseResult &resultInfo)
982 {
983     TELEPHONY_LOGI("[slot%{public}d] entry", slotId);
984     // CS fall back when IMS return failed
985     if (resultInfo.result == IMS_ERROR_UT_CS_FALLBACK) {
986         SsRequestCommand ss;
987         int32_t ret = GetSsRequestCommand(slotId, resultInfo.index, ss);
988         if (ret != TELEPHONY_SUCCESS) {
989             TELEPHONY_LOGI("[slot%{public}d] cs fall back error since haven't found the ss command", slotId);
990             return ret;
991         }
992         SupplementRequestCs supplementRequest;
993         CallTransferParam callTransferParam;
994         callTransferParam.mode = ss.cfAction;
995         callTransferParam.reason = ss.cfReason;
996         callTransferParam.number = ss.number;
997         callTransferParam.classx = ss.classType;
998         return supplementRequest.SetCallTransferRequest(slotId, callTransferParam, resultInfo.index);
999     }
1000     return SendEvent(slotId, RadioEvent::RADIO_SET_CALL_FORWARD, resultInfo);
1001 }
1002 
GetCallRestrictionResponse(int32_t slotId,const CallRestrictionResult & result)1003 int32_t ImsCallCallbackStub::GetCallRestrictionResponse(int32_t slotId, const CallRestrictionResult &result)
1004 {
1005     TELEPHONY_LOGI("[slot%{public}d] entry", slotId);
1006     if (result.result.result == IMS_ERROR_UT_CS_FALLBACK) {
1007         SsRequestCommand ss;
1008         int32_t ret = GetSsRequestCommand(slotId, result.result.index, ss);
1009         if (ret != TELEPHONY_SUCCESS) {
1010             TELEPHONY_LOGI("[slot%{public}d] cs fall back error since haven't found the ss command", slotId);
1011             return ret;
1012         }
1013         const std::string fac = ss.facility;
1014         SupplementRequestCs supplementRequest;
1015         return supplementRequest.GetCallRestrictionRequest(slotId, fac, result.result.index);
1016     }
1017     auto handler = DelayedSingleton<ImsCallClient>::GetInstance()->GetHandler(slotId);
1018     if (handler == nullptr) {
1019         TELEPHONY_LOGE("[slot%{public}d] handler is null", slotId);
1020         return TELEPHONY_ERR_LOCAL_PTR_NULL;
1021     }
1022     auto callRestrictionResponse = std::make_shared<CallRestrictionResult>();
1023     callRestrictionResponse->status = result.status;
1024     callRestrictionResponse->classCw = result.classCw;
1025     callRestrictionResponse->result.result = result.result.result;
1026     callRestrictionResponse->result.index = result.result.index;
1027     callRestrictionResponse->result.reason = result.result.reason;
1028     callRestrictionResponse->result.message = result.result.message;
1029     AppExecFwk::InnerEvent::Pointer response = AppExecFwk::InnerEvent::Get(
1030         RadioEvent::RADIO_GET_CALL_RESTRICTION, callRestrictionResponse, result.result.index);
1031     bool ret = handler->SendEvent(response);
1032     if (!ret) {
1033         TELEPHONY_LOGE("[slot%{public}d] SendEvent failed!", slotId);
1034         return TELEPHONY_ERR_FAIL;
1035     }
1036     return TELEPHONY_SUCCESS;
1037 }
1038 
SetCallRestrictionResponse(int32_t slotId,const SsBaseResult & resultInfo)1039 int32_t ImsCallCallbackStub::SetCallRestrictionResponse(int32_t slotId, const SsBaseResult &resultInfo)
1040 {
1041     TELEPHONY_LOGI("[slot%{public}d] entry", slotId);
1042     // CS fall back when IMS return failed
1043     if (resultInfo.result == IMS_ERROR_UT_CS_FALLBACK) {
1044         SsRequestCommand ss;
1045         int32_t ret = GetSsRequestCommand(slotId, resultInfo.index, ss);
1046         if (ret != TELEPHONY_SUCCESS) {
1047             TELEPHONY_LOGI("[slot%{public}d] cs fall bacK error since haven't found the ss command", slotId);
1048             return ret;
1049         }
1050         SupplementRequestCs supplementRequest;
1051         return supplementRequest.SetCallRestrictionRequest(
1052             slotId, ss.facility, ss.enable, ss.password, resultInfo.index);
1053     }
1054     return SendEvent(slotId, RadioEvent::RADIO_SET_CALL_RESTRICTION, resultInfo);
1055 }
1056 
GetCallWaitingResponse(int32_t slotId,const CallWaitResult & result)1057 int32_t ImsCallCallbackStub::GetCallWaitingResponse(int32_t slotId, const CallWaitResult &result)
1058 {
1059     TELEPHONY_LOGI("[slot%{public}d] entry", slotId);
1060     // CS fall back when IMS return failed
1061     if (result.result.result == IMS_ERROR_UT_CS_FALLBACK) {
1062         SupplementRequestCs supplementRequest;
1063         return supplementRequest.GetCallWaitingRequest(slotId, result.result.index);
1064     }
1065     auto handler = DelayedSingleton<ImsCallClient>::GetInstance()->GetHandler(slotId);
1066     if (handler == nullptr) {
1067         TELEPHONY_LOGE("[slot%{public}d] handler is null", slotId);
1068         return TELEPHONY_ERR_LOCAL_PTR_NULL;
1069     }
1070     auto callWaitResponse = std::make_shared<CallWaitResult>();
1071     callWaitResponse->status = result.status;
1072     callWaitResponse->classCw = result.classCw;
1073     callWaitResponse->result.result = result.result.result;
1074     callWaitResponse->result.index = result.result.index;
1075     callWaitResponse->result.reason = result.result.reason;
1076     callWaitResponse->result.message = result.result.message;
1077     AppExecFwk::InnerEvent::Pointer response =
1078         AppExecFwk::InnerEvent::Get(RadioEvent::RADIO_GET_CALL_WAIT, callWaitResponse, result.result.index);
1079     bool ret = handler->SendEvent(response);
1080     if (!ret) {
1081         TELEPHONY_LOGE("[slot%{public}d] SendEvent failed!", slotId);
1082         return TELEPHONY_ERR_FAIL;
1083     }
1084     return TELEPHONY_SUCCESS;
1085 }
1086 
SetCallWaitingResponse(int32_t slotId,const SsBaseResult & resultInfo)1087 int32_t ImsCallCallbackStub::SetCallWaitingResponse(int32_t slotId, const SsBaseResult &resultInfo)
1088 {
1089     TELEPHONY_LOGI("[slot%{public}d] entry", slotId);
1090     // CS fall back when IMS return failed
1091     if (resultInfo.result == IMS_ERROR_UT_CS_FALLBACK) {
1092         SsRequestCommand ss;
1093         int32_t ret = GetSsRequestCommand(slotId, resultInfo.index, ss);
1094         if (ret != TELEPHONY_SUCCESS) {
1095             TELEPHONY_LOGI("[slot%{public}d] cs fall back error since haven't found the ss command", slotId);
1096             return ret;
1097         }
1098         SupplementRequestCs supplementRequest;
1099         return supplementRequest.SetCallWaitingRequest(slotId, ss.enable, ss.classType, resultInfo.index);
1100     }
1101     return SendEvent(slotId, RadioEvent::RADIO_SET_CALL_WAIT, resultInfo);
1102 }
1103 
SetColrResponse(int32_t slotId,const SsBaseResult & resultInfo)1104 int32_t ImsCallCallbackStub::SetColrResponse(int32_t slotId, const SsBaseResult &resultInfo)
1105 {
1106     TELEPHONY_LOGI("[slot%{public}d] entry", slotId);
1107     return SendEvent(slotId, RadioEvent::RADIO_IMS_SET_COLR, resultInfo);
1108 }
1109 
GetColrResponse(int32_t slotId,const GetColrResult & result)1110 int32_t ImsCallCallbackStub::GetColrResponse(int32_t slotId, const GetColrResult &result)
1111 {
1112     TELEPHONY_LOGI("[slot%{public}d] entry", slotId);
1113     auto handler = DelayedSingleton<ImsCallClient>::GetInstance()->GetHandler(slotId);
1114     if (handler == nullptr) {
1115         TELEPHONY_LOGE("[slot%{public}d] handler is null", slotId);
1116         return TELEPHONY_ERR_LOCAL_PTR_NULL;
1117     }
1118     auto colrResponse = std::make_shared<GetColrResult>();
1119     colrResponse->action = result.action;
1120     colrResponse->colrStat = result.colrStat;
1121     colrResponse->result.result = result.result.result;
1122     colrResponse->result.index = result.result.index;
1123     colrResponse->result.reason = result.result.reason;
1124     colrResponse->result.message = result.result.message;
1125     AppExecFwk::InnerEvent::Pointer response =
1126         AppExecFwk::InnerEvent::Get(RadioEvent::RADIO_IMS_GET_COLR, colrResponse, result.result.index);
1127     bool ret = handler->SendEvent(response);
1128     if (!ret) {
1129         TELEPHONY_LOGE("[slot%{public}d] SendEvent failed!", slotId);
1130         return TELEPHONY_ERR_FAIL;
1131     }
1132     return TELEPHONY_SUCCESS;
1133 }
1134 
SetColpResponse(int32_t slotId,const SsBaseResult & resultInfo)1135 int32_t ImsCallCallbackStub::SetColpResponse(int32_t slotId, const SsBaseResult &resultInfo)
1136 {
1137     TELEPHONY_LOGI("[slot%{public}d] entry", slotId);
1138     return SendEvent(slotId, RadioEvent::RADIO_IMS_SET_COLP, resultInfo);
1139 }
1140 
GetColpResponse(int32_t slotId,const GetColpResult & result)1141 int32_t ImsCallCallbackStub::GetColpResponse(int32_t slotId, const GetColpResult &result)
1142 {
1143     TELEPHONY_LOGI("[slot%{public}d] entry", slotId);
1144     auto handler = DelayedSingleton<ImsCallClient>::GetInstance()->GetHandler(slotId);
1145     if (handler == nullptr) {
1146         TELEPHONY_LOGE("[slot%{public}d] handler is null", slotId);
1147         return TELEPHONY_ERR_LOCAL_PTR_NULL;
1148     }
1149     auto colpResponse = std::make_shared<GetColpResult>();
1150     colpResponse->action = result.action;
1151     colpResponse->colpStat = result.colpStat;
1152     colpResponse->result.result = result.result.result;
1153     colpResponse->result.index = result.result.index;
1154     colpResponse->result.reason = result.result.reason;
1155     colpResponse->result.message = result.result.message;
1156     AppExecFwk::InnerEvent::Pointer response =
1157         AppExecFwk::InnerEvent::Get(RadioEvent::RADIO_IMS_GET_COLP, colpResponse, result.result.index);
1158     bool ret = handler->SendEvent(response);
1159     if (!ret) {
1160         TELEPHONY_LOGE("[slot%{public}d] SendEvent failed!", slotId);
1161         return TELEPHONY_ERR_FAIL;
1162     }
1163     return TELEPHONY_SUCCESS;
1164 }
1165 
CombineConferenceResponse(int32_t slotId,const HRilRadioResponseInfo & info)1166 int32_t ImsCallCallbackStub::CombineConferenceResponse(int32_t slotId, const HRilRadioResponseInfo &info)
1167 {
1168     TELEPHONY_LOGI("[slot%{public}d] entry", slotId);
1169     return SendEvent(slotId, RadioEvent::RADIO_COMBINE_CALL, info);
1170 }
1171 
InviteToConferenceResponse(int32_t slotId,const HRilRadioResponseInfo & info)1172 int32_t ImsCallCallbackStub::InviteToConferenceResponse(int32_t slotId, const HRilRadioResponseInfo &info)
1173 {
1174     TELEPHONY_LOGI("[slot%{public}d] entry", slotId);
1175     return SendEvent(slotId, RadioEvent::RADIO_JOIN_CALL, info);
1176 }
1177 
GetSsRequestCommand(int32_t slotId,int32_t index,SsRequestCommand & ss)1178 int32_t ImsCallCallbackStub::GetSsRequestCommand(int32_t slotId, int32_t index, SsRequestCommand &ss)
1179 {
1180     auto handler = DelayedSingleton<CellularCallService>::GetInstance()->GetHandler(slotId);
1181     if (handler == nullptr) {
1182         TELEPHONY_LOGE("[slot%{public}d] handler is null!", slotId);
1183         return TELEPHONY_ERR_LOCAL_PTR_NULL;
1184     }
1185     return handler->GetSsRequestCommand(index, ss);
1186 }
1187 
BuildCallForwardInfo(const CallForwardQueryInfoList & cFQueryList,CallForwardQueryInfoList & cFQueryResultList)1188 void ImsCallCallbackStub::BuildCallForwardInfo(
1189     const CallForwardQueryInfoList &cFQueryList, CallForwardQueryInfoList &cFQueryResultList)
1190 {
1191     cFQueryResultList.callSize = cFQueryList.callSize;
1192     for (auto info : cFQueryList.calls) {
1193         CallForwardQueryResult call;
1194         call.serial = info.serial;
1195         call.result = info.result;
1196         call.status = info.status;
1197         call.classx = info.classx;
1198         call.number = info.number;
1199         call.type = info.type;
1200         call.reason = info.reason;
1201         call.time = info.time;
1202         call.startHour = info.startHour;
1203         call.startMinute = info.startMinute;
1204         call.endHour = info.endHour;
1205         call.endMinute = info.endMinute;
1206         cFQueryResultList.calls.push_back(call);
1207     }
1208     cFQueryResultList.result.result = cFQueryList.result.result;
1209     cFQueryResultList.result.index = cFQueryList.result.index;
1210     cFQueryResultList.result.reason = cFQueryList.result.reason;
1211     cFQueryResultList.result.message = cFQueryList.result.message;
1212 }
1213 
SendEvent(int32_t slotId,int32_t eventId,const HRilRadioResponseInfo & info)1214 int32_t ImsCallCallbackStub::SendEvent(int32_t slotId, int32_t eventId, const HRilRadioResponseInfo &info)
1215 {
1216     auto handler = DelayedSingleton<ImsCallClient>::GetInstance()->GetHandler(slotId);
1217     if (handler == nullptr) {
1218         TELEPHONY_LOGE("[slot%{public}d] handler is null", slotId);
1219         return TELEPHONY_ERR_LOCAL_PTR_NULL;
1220     }
1221     std::shared_ptr<HRilRadioResponseInfo> responseInfo = std::make_shared<HRilRadioResponseInfo>();
1222     *responseInfo = info;
1223     bool ret = handler->SendEvent(eventId, responseInfo);
1224     if (!ret) {
1225         TELEPHONY_LOGE("[slot%{public}d] SendEvent failed!", slotId);
1226         return TELEPHONY_ERR_FAIL;
1227     }
1228     return TELEPHONY_SUCCESS;
1229 }
1230 
SendEvent(int32_t slotId,int32_t eventId,const SsBaseResult & resultInfo)1231 int32_t ImsCallCallbackStub::SendEvent(int32_t slotId, int32_t eventId, const SsBaseResult &resultInfo)
1232 {
1233     auto handler = DelayedSingleton<ImsCallClient>::GetInstance()->GetHandler(slotId);
1234     if (handler == nullptr) {
1235         TELEPHONY_LOGE("[slot%{public}d] handler is null", slotId);
1236         return TELEPHONY_ERR_LOCAL_PTR_NULL;
1237     }
1238     auto ssResponseInfo = std::make_shared<SsBaseResult>();
1239     ssResponseInfo->result = resultInfo.result;
1240     ssResponseInfo->index = resultInfo.index;
1241     ssResponseInfo->reason = resultInfo.reason;
1242     ssResponseInfo->message = resultInfo.message;
1243     AppExecFwk::InnerEvent::Pointer response = AppExecFwk::InnerEvent::Get(eventId, ssResponseInfo, resultInfo.index);
1244     bool ret = handler->SendEvent(response);
1245     if (!ret) {
1246         TELEPHONY_LOGE("[slot%{public}d] SendEvent failed!", slotId);
1247         return TELEPHONY_ERR_FAIL;
1248     }
1249     return TELEPHONY_SUCCESS;
1250 }
1251 } // namespace Telephony
1252 } // namespace OHOS
1253