• 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  * limitations under the License.
13  */
14 
15 #include "ims_call_proxy.h"
16 
17 #include "cellular_call_hisysevent.h"
18 #include "message_option.h"
19 #include "message_parcel.h"
20 #include "telephony_errors.h"
21 
22 namespace OHOS {
23 namespace Telephony {
Dial(const ImsCallInfo & callInfo,CLIRMode mode)24 int32_t ImsCallProxy::Dial(const ImsCallInfo &callInfo, CLIRMode mode)
25 {
26     MessageParcel in;
27     if (!in.WriteInterfaceToken(ImsCallProxy::GetDescriptor())) {
28         TELEPHONY_LOGE("[slot%{public}d]Write descriptor token fail!", callInfo.slotId);
29         CellularCallHiSysEvent::WriteDialCallFaultEvent(callInfo.slotId, INVALID_PARAMETER, callInfo.videoState,
30             TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL, "ims call proxy write descriptor token fail");
31         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
32     }
33     if (!in.WriteRawData((const void *)&callInfo, sizeof(ImsCallInfo))) {
34         TELEPHONY_LOGE("[slot%{public}d]Write callInfo fail!", callInfo.slotId);
35         CellularCallHiSysEvent::WriteDialCallFaultEvent(callInfo.slotId, INVALID_PARAMETER, callInfo.videoState,
36             TELEPHONY_ERR_WRITE_DATA_FAIL, "ims call proxy write data fail");
37         return TELEPHONY_ERR_WRITE_DATA_FAIL;
38     }
39     if (!in.WriteInt32(mode)) {
40         TELEPHONY_LOGE("[slot%{public}d]Write mode fail!", callInfo.slotId);
41         CellularCallHiSysEvent::WriteDialCallFaultEvent(callInfo.slotId, INVALID_PARAMETER, callInfo.videoState,
42             TELEPHONY_ERR_WRITE_DATA_FAIL, "ims call proxy write data fail");
43         return TELEPHONY_ERR_WRITE_DATA_FAIL;
44     }
45     sptr<IRemoteObject> remote = Remote();
46     if (remote == nullptr) {
47         TELEPHONY_LOGE("[slot%{public}d]Remote is null", callInfo.slotId);
48         CellularCallHiSysEvent::WriteDialCallFaultEvent(callInfo.slotId, INVALID_PARAMETER, callInfo.videoState,
49             TELEPHONY_ERR_LOCAL_PTR_NULL, "ims call proxy remote is null");
50         return TELEPHONY_ERR_LOCAL_PTR_NULL;
51     }
52     MessageParcel out;
53     MessageOption option;
54     int32_t error = remote->SendRequest(static_cast<int32_t>(ImsCallInterfaceCode::IMS_DIAL), in, out, option);
55     if (error == ERR_NONE) {
56         return out.ReadInt32();
57     }
58     TELEPHONY_LOGE("[slot%{public}d]SendRequest fail, error:%{public}d", callInfo.slotId, error);
59     CellularCallHiSysEvent::WriteDialCallFaultEvent(callInfo.slotId, INVALID_PARAMETER, callInfo.videoState,
60         static_cast<int32_t>(CallErrorCode::CALL_ERROR_SEND_REQUEST_FAIL), "ims call proxy send request fail");
61     return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
62 }
63 
HangUp(const ImsCallInfo & callInfo)64 int32_t ImsCallProxy::HangUp(const ImsCallInfo &callInfo)
65 {
66     MessageParcel in;
67     if (!in.WriteInterfaceToken(ImsCallProxy::GetDescriptor())) {
68         TELEPHONY_LOGE("[slot%{public}d]Write descriptor token fail!", callInfo.slotId);
69         CellularCallHiSysEvent::WriteHangUpFaultEvent(callInfo.slotId, INVALID_PARAMETER,
70             TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL, "HangUp ims call proxy write descriptor token fail");
71         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
72     }
73     if (!in.WriteRawData((const void *)&callInfo, sizeof(ImsCallInfo))) {
74         TELEPHONY_LOGE("[slot%{public}d]Write callInfo fail!", callInfo.slotId);
75         CellularCallHiSysEvent::WriteHangUpFaultEvent(
76             callInfo.slotId, INVALID_PARAMETER, TELEPHONY_ERR_WRITE_DATA_FAIL, "HangUp ims call proxy write data fail");
77         return TELEPHONY_ERR_WRITE_DATA_FAIL;
78     }
79     sptr<IRemoteObject> remote = Remote();
80     if (remote == nullptr) {
81         TELEPHONY_LOGE("[slot%{public}d]Remote is null", callInfo.slotId);
82         return TELEPHONY_ERR_LOCAL_PTR_NULL;
83     }
84     MessageParcel out;
85     MessageOption option;
86     int32_t error = remote->SendRequest(static_cast<int32_t>(ImsCallInterfaceCode::IMS_HANG_UP), in, out, option);
87     if (error == ERR_NONE) {
88         return out.ReadInt32();
89     }
90     TELEPHONY_LOGE("[slot%{public}d]SendRequest fail, error:%{public}d", callInfo.slotId, error);
91     CellularCallHiSysEvent::WriteHangUpFaultEvent(callInfo.slotId, INVALID_PARAMETER,
92         static_cast<int32_t>(CallErrorCode::CALL_ERROR_SEND_REQUEST_FAIL), "HangUp ims call proxy send request fail");
93     return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
94 }
95 
RejectWithReason(const ImsCallInfo & callInfo,const ImsRejectReason & reason)96 int32_t ImsCallProxy::RejectWithReason(const ImsCallInfo &callInfo, const ImsRejectReason &reason)
97 {
98     MessageParcel in;
99     if (!in.WriteInterfaceToken(ImsCallProxy::GetDescriptor())) {
100         TELEPHONY_LOGE("[slot%{public}d]Write descriptor token fail!", callInfo.slotId);
101         CellularCallHiSysEvent::WriteHangUpFaultEvent(callInfo.slotId, INVALID_PARAMETER,
102             TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL, "Reject ims call proxy write descriptor token fail");
103         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
104     }
105     if (!in.WriteRawData((const void *)&callInfo, sizeof(ImsCallInfo))) {
106         TELEPHONY_LOGE("[slot%{public}d]Write callInfo fail!", callInfo.slotId);
107         CellularCallHiSysEvent::WriteHangUpFaultEvent(callInfo.slotId, INVALID_PARAMETER,
108             TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL, "Reject ims call proxy write data fail");
109         return TELEPHONY_ERR_WRITE_DATA_FAIL;
110     }
111     if (!in.WriteInt32(reason)) {
112         TELEPHONY_LOGE("[slot%{public}d]Write reason fail!", callInfo.slotId);
113         return TELEPHONY_ERR_WRITE_DATA_FAIL;
114     }
115     sptr<IRemoteObject> remote = Remote();
116     if (remote == nullptr) {
117         TELEPHONY_LOGE("[slot%{public}d]Remote is null", callInfo.slotId);
118         return TELEPHONY_ERR_LOCAL_PTR_NULL;
119     }
120     MessageParcel out;
121     MessageOption option;
122     int32_t error = remote->SendRequest(static_cast<int32_t>(ImsCallInterfaceCode::IMS_REJECT_WITH_REASON), in,
123         out, option);
124     if (error == ERR_NONE) {
125         return out.ReadInt32();
126     }
127     TELEPHONY_LOGE("[slot%{public}d]SendRequest fail, error:%{public}d", callInfo.slotId, error);
128     CellularCallHiSysEvent::WriteHangUpFaultEvent(callInfo.slotId, INVALID_PARAMETER,
129         static_cast<int32_t>(CallErrorCode::CALL_ERROR_SEND_REQUEST_FAIL), "Reject ims call proxy send request fail");
130     return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
131 }
132 
Answer(const ImsCallInfo & callInfo)133 int32_t ImsCallProxy::Answer(const ImsCallInfo &callInfo)
134 {
135     MessageParcel in;
136     if (!in.WriteInterfaceToken(ImsCallProxy::GetDescriptor())) {
137         TELEPHONY_LOGE("[slot%{public}d]Write descriptor token fail!", callInfo.slotId);
138         CellularCallHiSysEvent::WriteAnswerCallFaultEvent(callInfo.slotId, INVALID_PARAMETER, callInfo.videoState,
139             TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL, "ims call proxy write descriptor token fail");
140         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
141     }
142     if (!in.WriteRawData((const void *)&callInfo, sizeof(ImsCallInfo))) {
143         TELEPHONY_LOGE("[slot%{public}d]Write callInfo fail!", callInfo.slotId);
144         CellularCallHiSysEvent::WriteAnswerCallFaultEvent(callInfo.slotId, INVALID_PARAMETER, callInfo.videoState,
145             TELEPHONY_ERR_WRITE_DATA_FAIL, "ims call proxy write data fail");
146         return TELEPHONY_ERR_WRITE_DATA_FAIL;
147     }
148     sptr<IRemoteObject> remote = Remote();
149     if (remote == nullptr) {
150         TELEPHONY_LOGE("[slot%{public}d]Remote is null", callInfo.slotId);
151         return TELEPHONY_ERR_LOCAL_PTR_NULL;
152     }
153     MessageParcel out;
154     MessageOption option;
155     int32_t error = remote->SendRequest(static_cast<int32_t>(ImsCallInterfaceCode::IMS_ANSWER), in, out, option);
156     if (error == ERR_NONE) {
157         return out.ReadInt32();
158     }
159     TELEPHONY_LOGE("[slot%{public}d]SendRequest fail, error:%{public}d", callInfo.slotId, error);
160     CellularCallHiSysEvent::WriteAnswerCallFaultEvent(callInfo.slotId, INVALID_PARAMETER, callInfo.videoState,
161         static_cast<int32_t>(CallErrorCode::CALL_ERROR_SEND_REQUEST_FAIL), "ims call proxy send request fail");
162     return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
163 }
164 
HoldCall(int32_t slotId,int32_t callType)165 int32_t ImsCallProxy::HoldCall(int32_t slotId, int32_t callType)
166 {
167     MessageParcel in;
168     int32_t ret = WriteCommonInfo(slotId, __FUNCTION__, in, callType);
169     if (ret != TELEPHONY_SUCCESS) {
170         return ret;
171     }
172     return SendRequest(slotId, in, static_cast<int32_t>(ImsCallInterfaceCode::IMS_HOLD));
173 }
174 
UnHoldCall(int32_t slotId,int32_t callType)175 int32_t ImsCallProxy::UnHoldCall(int32_t slotId, int32_t callType)
176 {
177     MessageParcel in;
178     int32_t ret = WriteCommonInfo(slotId, __FUNCTION__, in, callType);
179     if (ret != TELEPHONY_SUCCESS) {
180         return ret;
181     }
182     return SendRequest(slotId, in, static_cast<int32_t>(ImsCallInterfaceCode::IMS_UN_HOLD));
183 }
184 
SwitchCall(int32_t slotId,int32_t callType)185 int32_t ImsCallProxy::SwitchCall(int32_t slotId, int32_t callType)
186 {
187     MessageParcel in;
188     int32_t ret = WriteCommonInfo(slotId, __FUNCTION__, in, callType);
189     if (ret != TELEPHONY_SUCCESS) {
190         return ret;
191     }
192     return SendRequest(slotId, in, static_cast<int32_t>(ImsCallInterfaceCode::IMS_SWITCH));
193 }
194 
CombineConference(int32_t slotId)195 int32_t ImsCallProxy::CombineConference(int32_t slotId)
196 {
197     MessageParcel in;
198     int32_t ret = WriteCommonInfo(slotId, __FUNCTION__, in);
199     if (ret != TELEPHONY_SUCCESS) {
200         return ret;
201     }
202     return SendRequest(slotId, in, static_cast<int32_t>(ImsCallInterfaceCode::IMS_COMBINE_CONFERENCE));
203 }
204 
InviteToConference(int32_t slotId,const std::vector<std::string> & numberList)205 int32_t ImsCallProxy::InviteToConference(int32_t slotId, const std::vector<std::string> &numberList)
206 {
207     MessageParcel in;
208     int32_t ret = WriteCommonInfo(slotId, __FUNCTION__, in);
209     if (ret != TELEPHONY_SUCCESS) {
210         return ret;
211     }
212     if (!in.WriteStringVector(numberList)) {
213         TELEPHONY_LOGE("[slot%{public}d]Write numberList fail!", slotId);
214         return TELEPHONY_ERR_WRITE_DATA_FAIL;
215     }
216     return SendRequest(slotId, in, static_cast<int32_t>(ImsCallInterfaceCode::IMS_INVITE_TO_CONFERENCE));
217 }
218 
KickOutFromConference(int32_t slotId,int32_t index)219 int32_t ImsCallProxy::KickOutFromConference(int32_t slotId, int32_t index)
220 {
221     MessageParcel in;
222     int32_t ret = WriteCommonInfo(slotId, __FUNCTION__, in);
223     if (ret != TELEPHONY_SUCCESS) {
224         return ret;
225     }
226     if (!in.WriteInt32(index)) {
227         TELEPHONY_LOGE("[slot%{public}d]Write index fail!", slotId);
228         return TELEPHONY_ERR_WRITE_DATA_FAIL;
229     }
230     return SendRequest(slotId, in, static_cast<int32_t>(ImsCallInterfaceCode::IMS_KICK_OUT_CONFERENCE));
231 }
232 
UpdateImsCallMode(const ImsCallInfo & callInfo,ImsCallMode mode)233 int32_t ImsCallProxy::UpdateImsCallMode(const ImsCallInfo &callInfo, ImsCallMode mode)
234 {
235     MessageParcel in;
236     if (!in.WriteInterfaceToken(ImsCallProxy::GetDescriptor())) {
237         TELEPHONY_LOGE("[slot%{public}d]Write descriptor token fail!", callInfo.slotId);
238         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
239     }
240     if (!in.WriteRawData((const void *)&callInfo, sizeof(ImsCallInfo))) {
241         TELEPHONY_LOGE("[slot%{public}d]Write callInfo fail!", callInfo.slotId);
242         return TELEPHONY_ERR_WRITE_DATA_FAIL;
243     }
244     if (!in.WriteInt32(mode)) {
245         TELEPHONY_LOGE("[slot%{public}d]Write mode fail!", callInfo.slotId);
246         return TELEPHONY_ERR_WRITE_DATA_FAIL;
247     }
248     return SendRequest(callInfo.slotId, in, static_cast<int32_t>(ImsCallInterfaceCode::IMS_UPDATE_CALL_MEDIA_MODE));
249 }
250 
GetImsCallsDataRequest(int32_t slotId,int64_t lastCallsDataFlag)251 int32_t ImsCallProxy::GetImsCallsDataRequest(int32_t slotId, int64_t lastCallsDataFlag)
252 {
253     MessageParcel in;
254     int32_t ret = WriteCommonInfo(slotId, __FUNCTION__, in);
255     if (ret != TELEPHONY_SUCCESS) {
256         return ret;
257     }
258     if (!in.WriteInt64(lastCallsDataFlag)) {
259         TELEPHONY_LOGE("[slot%{public}d]Write lastCallsDataFlag fail!", slotId);
260         return TELEPHONY_ERR_WRITE_DATA_FAIL;
261     }
262     return SendRequest(slotId, in, static_cast<int32_t>(ImsCallInterfaceCode::IMS_GET_CALL_DATA));
263 }
264 
GetLastCallFailReason(int32_t slotId)265 int32_t ImsCallProxy::GetLastCallFailReason(int32_t slotId)
266 {
267     MessageParcel in;
268     int32_t ret = WriteCommonInfo(slotId, __FUNCTION__, in);
269     if (ret != TELEPHONY_SUCCESS) {
270         return ret;
271     }
272     return SendRequest(slotId, in, static_cast<int32_t>(ImsCallInterfaceCode::IMS_GET_LAST_CALL_FAIL_REASON));
273 }
274 
StartDtmf(int32_t slotId,char cDtmfCode,int32_t index)275 int32_t ImsCallProxy::StartDtmf(int32_t slotId, char cDtmfCode, int32_t index)
276 {
277     MessageParcel in;
278     int32_t ret = WriteCommonInfo(slotId, __FUNCTION__, in);
279     if (ret != TELEPHONY_SUCCESS) {
280         return ret;
281     }
282     if (!in.WriteInt8(cDtmfCode)) {
283         TELEPHONY_LOGE("[slot%{public}d]Write cDtmfCode fail!", slotId);
284         return TELEPHONY_ERR_WRITE_DATA_FAIL;
285     }
286     if (!in.WriteInt32(index)) {
287         TELEPHONY_LOGE("[slot%{public}d]Write index fail!", slotId);
288         return TELEPHONY_ERR_WRITE_DATA_FAIL;
289     }
290     return SendRequest(slotId, in, static_cast<int32_t>(ImsCallInterfaceCode::IMS_START_DTMF));
291 }
292 
SendDtmf(int32_t slotId,char cDtmfCode,int32_t index)293 int32_t ImsCallProxy::SendDtmf(int32_t slotId, char cDtmfCode, int32_t index)
294 {
295     MessageParcel in;
296     int32_t ret = WriteCommonInfo(slotId, __FUNCTION__, in);
297     if (ret != TELEPHONY_SUCCESS) {
298         return ret;
299     }
300     if (!in.WriteInt8(cDtmfCode)) {
301         TELEPHONY_LOGE("[slot%{public}d]Write cDtmfCode fail!", slotId);
302         return TELEPHONY_ERR_WRITE_DATA_FAIL;
303     }
304     if (!in.WriteInt32(index)) {
305         TELEPHONY_LOGE("[slot%{public}d]Write index fail!", slotId);
306         return TELEPHONY_ERR_WRITE_DATA_FAIL;
307     }
308     return SendRequest(slotId, in, static_cast<int32_t>(ImsCallInterfaceCode::IMS_SEND_DTMF));
309 }
310 
StopDtmf(int32_t slotId,int32_t index)311 int32_t ImsCallProxy::StopDtmf(int32_t slotId, int32_t index)
312 {
313     MessageParcel in;
314     int32_t ret = WriteCommonInfo(slotId, __FUNCTION__, in);
315     if (ret != TELEPHONY_SUCCESS) {
316         return ret;
317     }
318     if (!in.WriteInt32(index)) {
319         TELEPHONY_LOGE("[slot%{public}d]Write index fail!", slotId);
320         return TELEPHONY_ERR_WRITE_DATA_FAIL;
321     }
322     return SendRequest(slotId, in, static_cast<int32_t>(ImsCallInterfaceCode::IMS_STOP_DTMF));
323 }
324 
StartRtt(int32_t slotId,const std::string & msg)325 int32_t ImsCallProxy::StartRtt(int32_t slotId, const std::string &msg)
326 {
327     MessageParcel in;
328     int32_t ret = WriteCommonInfo(slotId, __FUNCTION__, in);
329     if (ret != TELEPHONY_SUCCESS) {
330         return ret;
331     }
332     if (!in.WriteString(msg)) {
333         TELEPHONY_LOGE("[slot%{public}d]Write msg fail!", slotId);
334         return TELEPHONY_ERR_WRITE_DATA_FAIL;
335     }
336     return SendRequest(slotId, in, static_cast<int32_t>(ImsCallInterfaceCode::IMS_START_RTT));
337 }
338 
StopRtt(int32_t slotId)339 int32_t ImsCallProxy::StopRtt(int32_t slotId)
340 {
341     MessageParcel in;
342     int32_t ret = WriteCommonInfo(slotId, __FUNCTION__, in);
343     if (ret != TELEPHONY_SUCCESS) {
344         return ret;
345     }
346     return SendRequest(slotId, in, static_cast<int32_t>(ImsCallInterfaceCode::IMS_STOP_RTT));
347 }
348 
SetDomainPreferenceMode(int32_t slotId,int32_t mode)349 int32_t ImsCallProxy::SetDomainPreferenceMode(int32_t slotId, int32_t mode)
350 {
351     MessageParcel in;
352     int32_t ret = WriteCommonInfo(slotId, __FUNCTION__, in);
353     if (ret != TELEPHONY_SUCCESS) {
354         return ret;
355     }
356     if (!in.WriteInt32(mode)) {
357         TELEPHONY_LOGE("[slot%{public}d]Write mode fail!", slotId);
358         return TELEPHONY_ERR_WRITE_DATA_FAIL;
359     }
360     return SendRequest(slotId, in, static_cast<int32_t>(ImsCallInterfaceCode::IMS_SET_DOMAIN_PREFERENCE_MODE));
361 }
362 
GetDomainPreferenceMode(int32_t slotId)363 int32_t ImsCallProxy::GetDomainPreferenceMode(int32_t slotId)
364 {
365     MessageParcel in;
366     int32_t ret = WriteCommonInfo(slotId, __FUNCTION__, in);
367     if (ret != TELEPHONY_SUCCESS) {
368         return ret;
369     }
370     return SendRequest(slotId, in, static_cast<int32_t>(ImsCallInterfaceCode::IMS_GET_DOMAIN_PREFERENCE_MODE));
371 }
372 
SetImsSwitchStatus(int32_t slotId,int32_t active)373 int32_t ImsCallProxy::SetImsSwitchStatus(int32_t slotId, int32_t active)
374 {
375     MessageParcel in;
376     int32_t ret = WriteCommonInfo(slotId, __FUNCTION__, in);
377     if (ret != TELEPHONY_SUCCESS) {
378         return ret;
379     }
380     if (!in.WriteInt32(active)) {
381         TELEPHONY_LOGE("[slot%{public}d]Write active fail!", slotId);
382         return TELEPHONY_ERR_WRITE_DATA_FAIL;
383     }
384     return SendRequest(slotId, in, static_cast<int32_t>(ImsCallInterfaceCode::IMS_SET_SWITCH_STATUS));
385 }
386 
GetImsSwitchStatus(int32_t slotId)387 int32_t ImsCallProxy::GetImsSwitchStatus(int32_t slotId)
388 {
389     MessageParcel in;
390     int32_t ret = WriteCommonInfo(slotId, __FUNCTION__, in);
391     if (ret != TELEPHONY_SUCCESS) {
392         return ret;
393     }
394     return SendRequest(slotId, in, static_cast<int32_t>(ImsCallInterfaceCode::IMS_GET_SWITCH_STATUS));
395 }
396 
SetImsConfig(ImsConfigItem item,const std::string & value)397 int32_t ImsCallProxy::SetImsConfig(ImsConfigItem item, const std::string &value)
398 {
399     MessageParcel in;
400     if (!in.WriteInterfaceToken(ImsCallProxy::GetDescriptor())) {
401         TELEPHONY_LOGE("Write descriptor token fail!");
402         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
403     }
404     if (!in.WriteInt32(item)) {
405         TELEPHONY_LOGE("Write item fail!");
406         return TELEPHONY_ERR_WRITE_DATA_FAIL;
407     }
408     if (!in.WriteString(value)) {
409         TELEPHONY_LOGE("Write value fail!");
410         return TELEPHONY_ERR_WRITE_DATA_FAIL;
411     }
412     return SendRequest(in, static_cast<int32_t>(ImsCallInterfaceCode::IMS_SET_IMS_CONFIG_STRING));
413 }
414 
SetImsConfig(ImsConfigItem item,int32_t value)415 int32_t ImsCallProxy::SetImsConfig(ImsConfigItem item, int32_t value)
416 {
417     MessageParcel in;
418     if (!in.WriteInterfaceToken(ImsCallProxy::GetDescriptor())) {
419         TELEPHONY_LOGE("Write descriptor token fail!");
420         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
421     }
422     if (!in.WriteInt32(item)) {
423         TELEPHONY_LOGE("Write item fail!");
424         return TELEPHONY_ERR_WRITE_DATA_FAIL;
425     }
426     if (!in.WriteInt32(value)) {
427         TELEPHONY_LOGE("Write value fail!");
428         return TELEPHONY_ERR_WRITE_DATA_FAIL;
429     }
430     return SendRequest(in, static_cast<int32_t>(ImsCallInterfaceCode::IMS_SET_IMS_CONFIG_INT));
431 }
432 
GetImsConfig(ImsConfigItem item)433 int32_t ImsCallProxy::GetImsConfig(ImsConfigItem item)
434 {
435     MessageParcel in;
436     if (!in.WriteInterfaceToken(ImsCallProxy::GetDescriptor())) {
437         TELEPHONY_LOGE("Write descriptor token fail!");
438         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
439     }
440     if (!in.WriteInt32(item)) {
441         TELEPHONY_LOGE("Write item fail!");
442         return TELEPHONY_ERR_WRITE_DATA_FAIL;
443     }
444     return SendRequest(in, static_cast<int32_t>(ImsCallInterfaceCode::IMS_GET_IMS_CONFIG));
445 }
446 
SetImsFeatureValue(FeatureType type,int32_t value)447 int32_t ImsCallProxy::SetImsFeatureValue(FeatureType type, int32_t value)
448 {
449     MessageParcel in;
450     if (!in.WriteInterfaceToken(ImsCallProxy::GetDescriptor())) {
451         TELEPHONY_LOGE("Write descriptor token fail!");
452         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
453     }
454     if (!in.WriteInt32(type)) {
455         TELEPHONY_LOGE("Write type fail!");
456         return TELEPHONY_ERR_WRITE_DATA_FAIL;
457     }
458     if (!in.WriteInt32(value)) {
459         TELEPHONY_LOGE("Write value fail!");
460         return TELEPHONY_ERR_WRITE_DATA_FAIL;
461     }
462     return SendRequest(in, static_cast<int32_t>(ImsCallInterfaceCode::IMS_SET_IMS_FEATURE));
463 }
464 
GetImsFeatureValue(FeatureType type,int32_t & value)465 int32_t ImsCallProxy::GetImsFeatureValue(FeatureType type, int32_t &value)
466 {
467     MessageParcel in;
468     if (!in.WriteInterfaceToken(ImsCallProxy::GetDescriptor())) {
469         TELEPHONY_LOGE("Write descriptor token fail!");
470         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
471     }
472     if (!in.WriteInt32(type)) {
473         TELEPHONY_LOGE("Write type fail!");
474         return TELEPHONY_ERR_WRITE_DATA_FAIL;
475     }
476     return SendRequest(in, static_cast<int32_t>(ImsCallInterfaceCode::IMS_GET_IMS_FEATURE));
477 }
478 
SetMute(int32_t slotId,int32_t mute)479 int32_t ImsCallProxy::SetMute(int32_t slotId, int32_t mute)
480 {
481     MessageParcel in;
482     int32_t ret = WriteCommonInfo(slotId, __FUNCTION__, in);
483     if (ret != TELEPHONY_SUCCESS) {
484         return ret;
485     }
486     if (!in.WriteInt32(mute)) {
487         TELEPHONY_LOGE("[slot%{public}d]Write mute fail!", slotId);
488         return TELEPHONY_ERR_WRITE_DATA_FAIL;
489     }
490     return SendRequest(slotId, in, static_cast<int32_t>(ImsCallInterfaceCode::IMS_SET_MUTE));
491 }
492 
GetMute(int32_t slotId)493 int32_t ImsCallProxy::GetMute(int32_t slotId)
494 {
495     MessageParcel in;
496     int32_t ret = WriteCommonInfo(slotId, __FUNCTION__, in);
497     if (ret != TELEPHONY_SUCCESS) {
498         return ret;
499     }
500     return SendRequest(slotId, in, static_cast<int32_t>(ImsCallInterfaceCode::IMS_GET_MUTE));
501 }
502 
CtrlCamera(const std::u16string & cameraId,int32_t callingUid,int32_t callingPid)503 int32_t ImsCallProxy::CtrlCamera(const std::u16string &cameraId, int32_t callingUid, int32_t callingPid)
504 {
505     MessageParcel in;
506     if (!in.WriteInterfaceToken(ImsCallProxy::GetDescriptor())) {
507         TELEPHONY_LOGE("Write descriptor token fail!");
508         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
509     }
510     if (!in.WriteString16(cameraId)) {
511         TELEPHONY_LOGE("Write cameraId fail!");
512         return TELEPHONY_ERR_WRITE_DATA_FAIL;
513     }
514     if (!in.WriteInt32(callingUid)) {
515         TELEPHONY_LOGE("Write callingUid fail!");
516         return TELEPHONY_ERR_WRITE_DATA_FAIL;
517     }
518     if (!in.WriteInt32(callingPid)) {
519         TELEPHONY_LOGE("Write callingPid fail!");
520         return TELEPHONY_ERR_WRITE_DATA_FAIL;
521     }
522     return SendRequest(in, static_cast<int32_t>(ImsCallInterfaceCode::IMS_CTRL_CAMERA));
523 }
524 
SetPreviewWindow(int32_t x,int32_t y,int32_t z,int32_t width,int32_t height)525 int32_t ImsCallProxy::SetPreviewWindow(int32_t x, int32_t y, int32_t z, int32_t width, int32_t height)
526 {
527     MessageParcel in;
528     if (!in.WriteInterfaceToken(ImsCallProxy::GetDescriptor())) {
529         TELEPHONY_LOGE("Write descriptor token fail!");
530         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
531     }
532     if (!in.WriteInt32(x)) {
533         TELEPHONY_LOGE("Write x fail!");
534         return TELEPHONY_ERR_WRITE_DATA_FAIL;
535     }
536     if (!in.WriteInt32(y)) {
537         TELEPHONY_LOGE("Write y fail!");
538         return TELEPHONY_ERR_WRITE_DATA_FAIL;
539     }
540     if (!in.WriteInt32(z)) {
541         TELEPHONY_LOGE("Write z fail!");
542         return TELEPHONY_ERR_WRITE_DATA_FAIL;
543     }
544     if (!in.WriteInt32(width)) {
545         TELEPHONY_LOGE("Write width fail!");
546         return TELEPHONY_ERR_WRITE_DATA_FAIL;
547     }
548     if (!in.WriteInt32(height)) {
549         TELEPHONY_LOGE("Write height fail!");
550         return TELEPHONY_ERR_WRITE_DATA_FAIL;
551     }
552     return SendRequest(in, static_cast<int32_t>(ImsCallInterfaceCode::IMS_SET_PREVIEW_WINDOW));
553 }
554 
SetDisplayWindow(int32_t x,int32_t y,int32_t z,int32_t width,int32_t height)555 int32_t ImsCallProxy::SetDisplayWindow(int32_t x, int32_t y, int32_t z, int32_t width, int32_t height)
556 {
557     MessageParcel in;
558     if (!in.WriteInterfaceToken(ImsCallProxy::GetDescriptor())) {
559         TELEPHONY_LOGE("Write descriptor token fail!");
560         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
561     }
562     if (!in.WriteInt32(x)) {
563         TELEPHONY_LOGE("Write x fail!");
564         return TELEPHONY_ERR_WRITE_DATA_FAIL;
565     }
566     if (!in.WriteInt32(y)) {
567         TELEPHONY_LOGE("Write y fail!");
568         return TELEPHONY_ERR_WRITE_DATA_FAIL;
569     }
570     if (!in.WriteInt32(z)) {
571         TELEPHONY_LOGE("Write z fail!");
572         return TELEPHONY_ERR_WRITE_DATA_FAIL;
573     }
574     if (!in.WriteInt32(width)) {
575         TELEPHONY_LOGE("Write width fail!");
576         return TELEPHONY_ERR_WRITE_DATA_FAIL;
577     }
578     if (!in.WriteInt32(height)) {
579         TELEPHONY_LOGE("Write height fail!");
580         return TELEPHONY_ERR_WRITE_DATA_FAIL;
581     }
582     return SendRequest(in, static_cast<int32_t>(ImsCallInterfaceCode::IMS_SET_DISPLAY_WINDOW));
583 }
584 
SetCameraZoom(float zoomRatio)585 int32_t ImsCallProxy::SetCameraZoom(float zoomRatio)
586 {
587     MessageParcel in;
588     if (!in.WriteInterfaceToken(ImsCallProxy::GetDescriptor())) {
589         TELEPHONY_LOGE("Write descriptor token fail!");
590         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
591     }
592     if (!in.WriteFloat(zoomRatio)) {
593         TELEPHONY_LOGE("Write zoomRatio fail!");
594         return TELEPHONY_ERR_WRITE_DATA_FAIL;
595     }
596     return SendRequest(in, static_cast<int32_t>(ImsCallInterfaceCode::IMS_SET_CAMERA_ZOOM));
597 }
598 
SetPauseImage(const std::u16string & path)599 int32_t ImsCallProxy::SetPauseImage(const std::u16string &path)
600 {
601     MessageParcel in;
602     if (!in.WriteInterfaceToken(ImsCallProxy::GetDescriptor())) {
603         TELEPHONY_LOGE("Write descriptor token fail!");
604         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
605     }
606     if (!in.WriteString16(path)) {
607         TELEPHONY_LOGE("Write path fail!");
608         return TELEPHONY_ERR_WRITE_DATA_FAIL;
609     }
610     return SendRequest(in, static_cast<int32_t>(ImsCallInterfaceCode::IMS_SET_PAUSE_IMAGE));
611 }
612 
SetDeviceDirection(int32_t rotation)613 int32_t ImsCallProxy::SetDeviceDirection(int32_t rotation)
614 {
615     MessageParcel in;
616     if (!in.WriteInterfaceToken(ImsCallProxy::GetDescriptor())) {
617         TELEPHONY_LOGE("Write descriptor token fail!");
618         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
619     }
620     if (!in.WriteInt32(rotation)) {
621         TELEPHONY_LOGE("Write rotation fail!");
622         return TELEPHONY_ERR_WRITE_DATA_FAIL;
623     }
624     return SendRequest(in, static_cast<int32_t>(ImsCallInterfaceCode::IMS_SET_DEVICE_DIRECTION));
625 }
626 
SetClip(int32_t slotId,int32_t action,int32_t index)627 int32_t ImsCallProxy::SetClip(int32_t slotId, int32_t action, int32_t index)
628 {
629     MessageParcel in;
630     int32_t ret = WriteCommonInfo(slotId, __FUNCTION__, in);
631     if (ret != TELEPHONY_SUCCESS) {
632         return ret;
633     }
634     if (!in.WriteInt32(action)) {
635         TELEPHONY_LOGE("[slot%{public}d]Write action fail!", slotId);
636         return TELEPHONY_ERR_WRITE_DATA_FAIL;
637     }
638     if (!in.WriteInt32(index)) {
639         TELEPHONY_LOGE("[slot%{public}d]Write index fail!", slotId);
640         return TELEPHONY_ERR_WRITE_DATA_FAIL;
641     }
642     return SendRequest(slotId, in, static_cast<int32_t>(ImsCallInterfaceCode::IMS_SET_CLIP));
643 }
644 
GetClip(int32_t slotId,int32_t index)645 int32_t ImsCallProxy::GetClip(int32_t slotId, int32_t index)
646 {
647     MessageParcel in;
648     int32_t ret = WriteCommonInfo(slotId, __FUNCTION__, in);
649     if (ret != TELEPHONY_SUCCESS) {
650         return ret;
651     }
652     if (!in.WriteInt32(index)) {
653         TELEPHONY_LOGE("[slot%{public}d]Write index fail!", slotId);
654         return TELEPHONY_ERR_WRITE_DATA_FAIL;
655     }
656     return SendRequest(slotId, in, static_cast<int32_t>(ImsCallInterfaceCode::IMS_GET_CLIP));
657 }
658 
SetClir(int32_t slotId,int32_t action,int32_t index)659 int32_t ImsCallProxy::SetClir(int32_t slotId, int32_t action, int32_t index)
660 {
661     MessageParcel in;
662     int32_t ret = WriteCommonInfo(slotId, __FUNCTION__, in);
663     if (ret != TELEPHONY_SUCCESS) {
664         return ret;
665     }
666     if (!in.WriteInt32(action)) {
667         TELEPHONY_LOGE("[slot%{public}d]Write action fail!", slotId);
668         return TELEPHONY_ERR_WRITE_DATA_FAIL;
669     }
670     if (!in.WriteInt32(index)) {
671         TELEPHONY_LOGE("[slot%{public}d]Write index fail!", slotId);
672         return TELEPHONY_ERR_WRITE_DATA_FAIL;
673     }
674     return SendRequest(slotId, in, static_cast<int32_t>(ImsCallInterfaceCode::IMS_SET_CLIR));
675 }
676 
GetClir(int32_t slotId,int32_t index)677 int32_t ImsCallProxy::GetClir(int32_t slotId, int32_t index)
678 {
679     MessageParcel in;
680     int32_t ret = WriteCommonInfo(slotId, __FUNCTION__, in);
681     if (ret != TELEPHONY_SUCCESS) {
682         return ret;
683     }
684     if (!in.WriteInt32(index)) {
685         TELEPHONY_LOGE("[slot%{public}d]Write index fail!", slotId);
686         return TELEPHONY_ERR_WRITE_DATA_FAIL;
687     }
688     return SendRequest(slotId, in, static_cast<int32_t>(ImsCallInterfaceCode::IMS_GET_CLIR));
689 }
690 
SetCallTransfer(int32_t slotId,const CallTransferInfo & cfInfo,int32_t classType,int32_t index)691 int32_t ImsCallProxy::SetCallTransfer(int32_t slotId, const CallTransferInfo &cfInfo, int32_t classType, int32_t index)
692 {
693     MessageParcel in;
694     int32_t ret = WriteCommonInfo(slotId, __FUNCTION__, in);
695     if (ret != TELEPHONY_SUCCESS) {
696         return ret;
697     }
698     if (!in.WriteRawData((const void *)&cfInfo, sizeof(CallTransferInfo))) {
699         TELEPHONY_LOGE("[slot%{public}d]Write cfInfo fail!", slotId);
700         return TELEPHONY_ERR_WRITE_DATA_FAIL;
701     }
702     if (!in.WriteInt32(classType)) {
703         TELEPHONY_LOGE("[slot%{public}d]Write classType fail!", slotId);
704         return TELEPHONY_ERR_WRITE_DATA_FAIL;
705     }
706     if (!in.WriteInt32(index)) {
707         TELEPHONY_LOGE("[slot%{public}d]Write index fail!", slotId);
708         return TELEPHONY_ERR_WRITE_DATA_FAIL;
709     }
710     return SendRequest(slotId, in, static_cast<int32_t>(ImsCallInterfaceCode::IMS_SET_CALL_TRANSFER));
711 }
712 
CanSetCallTransferTime(int32_t slotId,bool & result)713 int32_t ImsCallProxy::CanSetCallTransferTime(int32_t slotId, bool &result)
714 {
715     MessageParcel in;
716     int32_t ret = WriteCommonInfo(slotId, __FUNCTION__, in);
717     if (ret != TELEPHONY_SUCCESS) {
718         return ret;
719     }
720     if (!in.WriteBool(result)) {
721         TELEPHONY_LOGE("[slot%{public}d]Write classType fail!", slotId);
722         return TELEPHONY_ERR_WRITE_DATA_FAIL;
723     }
724     MessageParcel out;
725     MessageOption option;
726 
727     sptr<IRemoteObject> remote = Remote();
728     if (remote == nullptr) {
729         TELEPHONY_LOGE("[slot%{public}d]Remote is null", slotId);
730         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
731     }
732 
733     int32_t error = remote->SendRequest(static_cast<int32_t>(ImsCallInterfaceCode::IMS_CAN_SET_CALL_TRANSFER_TIME), in,
734         out, option);
735     if (error == ERR_NONE) {
736         result = out.ReadBool();
737         return out.ReadInt32();
738     }
739     return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
740 }
741 
GetCallTransfer(int32_t slotId,int32_t reason,int32_t index)742 int32_t ImsCallProxy::GetCallTransfer(int32_t slotId, int32_t reason, int32_t index)
743 {
744     MessageParcel in;
745     int32_t ret = WriteCommonInfo(slotId, __FUNCTION__, in);
746     if (ret != TELEPHONY_SUCCESS) {
747         return ret;
748     }
749     if (!in.WriteInt32(reason)) {
750         TELEPHONY_LOGE("[slot%{public}d]Write reason fail!", slotId);
751         return TELEPHONY_ERR_WRITE_DATA_FAIL;
752     }
753     if (!in.WriteInt32(index)) {
754         TELEPHONY_LOGE("[slot%{public}d]Write index fail!", slotId);
755         return TELEPHONY_ERR_WRITE_DATA_FAIL;
756     }
757     return SendRequest(slotId, in, static_cast<int32_t>(ImsCallInterfaceCode::IMS_GET_CALL_TRANSFER));
758 }
759 
SetCallRestriction(int32_t slotId,const std::string & fac,int32_t mode,const std::string & pw,int32_t index)760 int32_t ImsCallProxy::SetCallRestriction(
761     int32_t slotId, const std::string &fac, int32_t mode, const std::string &pw, int32_t index)
762 {
763     MessageParcel in;
764     int32_t ret = WriteCommonInfo(slotId, __FUNCTION__, in);
765     if (ret != TELEPHONY_SUCCESS) {
766         return ret;
767     }
768     if (!in.WriteString(fac)) {
769         TELEPHONY_LOGE("[slot%{public}d]Write fac fail!", slotId);
770         return TELEPHONY_ERR_WRITE_DATA_FAIL;
771     }
772     if (!in.WriteInt32(mode)) {
773         TELEPHONY_LOGE("[slot%{public}d]Write mode fail!", slotId);
774         return TELEPHONY_ERR_WRITE_DATA_FAIL;
775     }
776     if (!in.WriteString(pw)) {
777         TELEPHONY_LOGE("[slot%{public}d]Write pw fail!", slotId);
778         return TELEPHONY_ERR_WRITE_DATA_FAIL;
779     }
780     if (!in.WriteInt32(index)) {
781         TELEPHONY_LOGE("[slot%{public}d]Write index fail!", slotId);
782         return TELEPHONY_ERR_WRITE_DATA_FAIL;
783     }
784     return SendRequest(slotId, in, static_cast<int32_t>(ImsCallInterfaceCode::IMS_SET_CALL_RESTRICTION));
785 }
786 
GetCallRestriction(int32_t slotId,const std::string & fac,int32_t index)787 int32_t ImsCallProxy::GetCallRestriction(int32_t slotId, const std::string &fac, int32_t index)
788 {
789     MessageParcel in;
790     int32_t ret = WriteCommonInfo(slotId, __FUNCTION__, in);
791     if (ret != TELEPHONY_SUCCESS) {
792         return ret;
793     }
794     if (!in.WriteString(fac)) {
795         TELEPHONY_LOGE("[slot%{public}d]Write fac fail!", slotId);
796         return TELEPHONY_ERR_WRITE_DATA_FAIL;
797     }
798     if (!in.WriteInt32(index)) {
799         TELEPHONY_LOGE("[slot%{public}d]Write index fail!", slotId);
800         return TELEPHONY_ERR_WRITE_DATA_FAIL;
801     }
802     return SendRequest(slotId, in, static_cast<int32_t>(ImsCallInterfaceCode::IMS_GET_CALL_RESTRICTION));
803 }
804 
SetCallWaiting(int32_t slotId,bool activate,int32_t classType,int32_t index)805 int32_t ImsCallProxy::SetCallWaiting(int32_t slotId, bool activate, int32_t classType, int32_t index)
806 {
807     MessageParcel in;
808     int32_t ret = WriteCommonInfo(slotId, __FUNCTION__, in);
809     if (ret != TELEPHONY_SUCCESS) {
810         return ret;
811     }
812     if (!in.WriteBool(activate)) {
813         TELEPHONY_LOGE("[slot%{public}d]Write activate fail!", slotId);
814         return TELEPHONY_ERR_WRITE_DATA_FAIL;
815     }
816     if (!in.WriteInt32(classType)) {
817         TELEPHONY_LOGE("[slot%{public}d]Write classType fail!", slotId);
818         return TELEPHONY_ERR_WRITE_DATA_FAIL;
819     }
820     if (!in.WriteInt32(index)) {
821         TELEPHONY_LOGE("[slot%{public}d]Write index fail!", slotId);
822         return TELEPHONY_ERR_WRITE_DATA_FAIL;
823     }
824     return SendRequest(slotId, in, static_cast<int32_t>(ImsCallInterfaceCode::IMS_SET_CALL_WAITING));
825 }
826 
GetCallWaiting(int32_t slotId,int32_t index)827 int32_t ImsCallProxy::GetCallWaiting(int32_t slotId, int32_t index)
828 {
829     MessageParcel in;
830     int32_t ret = WriteCommonInfo(slotId, __FUNCTION__, in);
831     if (ret != TELEPHONY_SUCCESS) {
832         return ret;
833     }
834     if (!in.WriteInt32(index)) {
835         TELEPHONY_LOGE("[slot%{public}d]Write index fail!", slotId);
836         return TELEPHONY_ERR_WRITE_DATA_FAIL;
837     }
838     return SendRequest(slotId, in, static_cast<int32_t>(ImsCallInterfaceCode::IMS_GET_CALL_WAITING));
839 }
840 
SetColr(int32_t slotId,int32_t presentation,int32_t index)841 int32_t ImsCallProxy::SetColr(int32_t slotId, int32_t presentation, int32_t index)
842 {
843     MessageParcel in;
844     int32_t ret = WriteCommonInfo(slotId, __FUNCTION__, in);
845     if (ret != TELEPHONY_SUCCESS) {
846         return ret;
847     }
848     if (!in.WriteInt32(presentation)) {
849         TELEPHONY_LOGE("[slot%{public}d]Write presentation fail!", slotId);
850         return TELEPHONY_ERR_WRITE_DATA_FAIL;
851     }
852     if (!in.WriteInt32(index)) {
853         TELEPHONY_LOGE("[slot%{public}d]Write index fail!", slotId);
854         return TELEPHONY_ERR_WRITE_DATA_FAIL;
855     }
856     return SendRequest(slotId, in, static_cast<int32_t>(ImsCallInterfaceCode::IMS_SET_COLR));
857 }
858 
GetColr(int32_t slotId,int32_t index)859 int32_t ImsCallProxy::GetColr(int32_t slotId, int32_t index)
860 {
861     MessageParcel in;
862     int32_t ret = WriteCommonInfo(slotId, __FUNCTION__, in);
863     if (ret != TELEPHONY_SUCCESS) {
864         return ret;
865     }
866     if (!in.WriteInt32(index)) {
867         TELEPHONY_LOGE("[slot%{public}d]Write index fail!", slotId);
868         return TELEPHONY_ERR_WRITE_DATA_FAIL;
869     }
870     return SendRequest(slotId, in, static_cast<int32_t>(ImsCallInterfaceCode::IMS_GET_COLR));
871 }
872 
SetColp(int32_t slotId,int32_t action,int32_t index)873 int32_t ImsCallProxy::SetColp(int32_t slotId, int32_t action, int32_t index)
874 {
875     MessageParcel in;
876     int32_t ret = WriteCommonInfo(slotId, __FUNCTION__, in);
877     if (ret != TELEPHONY_SUCCESS) {
878         return ret;
879     }
880     if (!in.WriteInt32(action)) {
881         TELEPHONY_LOGE("[slot%{public}d]Write action fail!", slotId);
882         return TELEPHONY_ERR_WRITE_DATA_FAIL;
883     }
884     if (!in.WriteInt32(index)) {
885         TELEPHONY_LOGE("[slot%{public}d]Write index fail!", slotId);
886         return TELEPHONY_ERR_WRITE_DATA_FAIL;
887     }
888     return SendRequest(slotId, in, static_cast<int32_t>(ImsCallInterfaceCode::IMS_SET_COLP));
889 }
890 
GetColp(int32_t slotId,int32_t index)891 int32_t ImsCallProxy::GetColp(int32_t slotId, int32_t index)
892 {
893     MessageParcel in;
894     int32_t ret = WriteCommonInfo(slotId, __FUNCTION__, in);
895     if (ret != TELEPHONY_SUCCESS) {
896         return ret;
897     }
898     if (!in.WriteInt32(index)) {
899         TELEPHONY_LOGE("[slot%{public}d]Write index fail!", slotId);
900         return TELEPHONY_ERR_WRITE_DATA_FAIL;
901     }
902     return SendRequest(slotId, in, static_cast<int32_t>(ImsCallInterfaceCode::IMS_GET_COLP));
903 }
904 
RegisterImsCallCallback(const sptr<ImsCallCallbackInterface> & callback)905 int32_t ImsCallProxy::RegisterImsCallCallback(const sptr<ImsCallCallbackInterface> &callback)
906 {
907     if (callback == nullptr) {
908         TELEPHONY_LOGE("callback is null!");
909         return TELEPHONY_ERR_ARGUMENT_INVALID;
910     }
911     MessageParcel in;
912     if (!in.WriteInterfaceToken(ImsCallProxy::GetDescriptor())) {
913         TELEPHONY_LOGE("Write descriptor token fail!");
914         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
915     }
916     if (!in.WriteRemoteObject(callback->AsObject().GetRefPtr())) {
917         TELEPHONY_LOGE("Write ImsCallCallbackInterface fail!");
918         return TELEPHONY_ERR_WRITE_DATA_FAIL;
919     }
920     return SendRequest(in, static_cast<int32_t>(ImsCallInterfaceCode::IMS_CALL_REGISTER_CALLBACK));
921 }
922 
UpdateImsCapabilities(int32_t slotId,const ImsCapabilityList & imsCapabilityList)923 int32_t ImsCallProxy::UpdateImsCapabilities(int32_t slotId, const ImsCapabilityList &imsCapabilityList)
924 {
925     MessageParcel in;
926     int32_t ret = WriteCommonInfo(slotId, __FUNCTION__, in);
927     if (ret != TELEPHONY_SUCCESS) {
928         return ret;
929     }
930     int32_t imsCapabilitiesSize = static_cast<int32_t>(imsCapabilityList.imsCapabilities.size());
931     if (!in.WriteInt32(imsCapabilitiesSize)) {
932         return TELEPHONY_ERR_WRITE_DATA_FAIL;
933     }
934     for (auto imsCapability : imsCapabilityList.imsCapabilities) {
935         if (!in.WriteInt32(static_cast<int32_t>(imsCapability.imsCapabilityType))) {
936             TELEPHONY_LOGE("[slot%{public}d] Write imsCapabilityType fail!", slotId);
937             return TELEPHONY_ERR_WRITE_DATA_FAIL;
938         }
939         if (!in.WriteInt32(static_cast<int32_t>(imsCapability.imsRadioTech))) {
940             TELEPHONY_LOGE("[slot%{public}d] Write imsRadioTech fail!", slotId);
941             return TELEPHONY_ERR_WRITE_DATA_FAIL;
942         }
943         if (!in.WriteBool(imsCapability.enable)) {
944             TELEPHONY_LOGE("[slot%{public}d] Write enable fail!", slotId);
945             return TELEPHONY_ERR_WRITE_DATA_FAIL;
946         }
947     }
948     return SendRequest(slotId, in, static_cast<int32_t>(ImsCallInterfaceCode::IMS_UPDATE_CAPABILITY));
949 }
950 
GetUtImpuFromNetwork(int32_t slotId,std::string & impu)951 int32_t ImsCallProxy::GetUtImpuFromNetwork(int32_t slotId, std::string &impu)
952 {
953     MessageParcel in;
954     int32_t ret = WriteCommonInfo(slotId, __FUNCTION__, in);
955     if (ret != TELEPHONY_SUCCESS) {
956         return ret;
957     }
958     if (!in.WriteString(impu)) {
959         TELEPHONY_LOGE("[slot%{public}d]Write impu fail!", slotId);
960         return TELEPHONY_ERR_WRITE_DATA_FAIL;
961     }
962     return SendRequest(slotId, in, static_cast<int32_t>(ImsCallInterfaceCode::IMS_GET_IMPU_FROM_NETWORK));
963 }
964 
WriteCommonInfo(int32_t slotId,std::string funcName,MessageParcel & in)965 int32_t ImsCallProxy::WriteCommonInfo(int32_t slotId, std::string funcName, MessageParcel &in)
966 {
967     if (!in.WriteInterfaceToken(ImsCallProxy::GetDescriptor())) {
968         TELEPHONY_LOGE("[slot%{public}d] %{public}s Write descriptor token fail!", slotId, funcName.c_str());
969         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
970     }
971     if (!in.WriteInt32(slotId)) {
972         TELEPHONY_LOGE("[slot%{public}d] %{public}s Write slotId fail!", slotId, funcName.c_str());
973         return TELEPHONY_ERR_WRITE_DATA_FAIL;
974     }
975     return TELEPHONY_SUCCESS;
976 }
977 
WriteCommonInfo(int32_t slotId,std::string funcName,MessageParcel & in,int32_t callType)978 int32_t ImsCallProxy::WriteCommonInfo(int32_t slotId, std::string funcName, MessageParcel &in, int32_t callType)
979 {
980     int32_t ret = WriteCommonInfo(slotId, funcName, in);
981     if (ret != TELEPHONY_SUCCESS) {
982         return ret;
983     }
984     if (!in.WriteInt32(callType)) {
985         TELEPHONY_LOGE("[slot%{public}d] %{public}s Write callType fail!", slotId, funcName.c_str());
986         return TELEPHONY_ERR_WRITE_DATA_FAIL;
987     }
988     return TELEPHONY_SUCCESS;
989 }
990 
SendRequest(MessageParcel & in,int32_t eventId)991 int32_t ImsCallProxy::SendRequest(MessageParcel &in, int32_t eventId)
992 {
993     sptr<IRemoteObject> remote = Remote();
994     if (remote == nullptr) {
995         TELEPHONY_LOGE("Remote is null, eventId:%{public}d", eventId);
996         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
997     }
998 
999     MessageParcel out;
1000     MessageOption option;
1001     int32_t error = remote->SendRequest(eventId, in, out, option);
1002     if (error == ERR_NONE) {
1003         return out.ReadInt32();
1004     }
1005     TELEPHONY_LOGE("SendRequest fail, eventId:%{public}d, error:%{public}d", eventId, error);
1006     return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1007 }
1008 
SendRequest(int32_t slotId,MessageParcel & in,int32_t eventId)1009 int32_t ImsCallProxy::SendRequest(int32_t slotId, MessageParcel &in, int32_t eventId)
1010 {
1011     sptr<IRemoteObject> remote = Remote();
1012     if (remote == nullptr) {
1013         TELEPHONY_LOGE("[slot%{public}d]Remote is null, eventId:%{public}d", slotId, eventId);
1014         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1015     }
1016 
1017     MessageParcel out;
1018     MessageOption option;
1019     int32_t error = remote->SendRequest(eventId, in, out, option);
1020     if (error == ERR_NONE) {
1021         return out.ReadInt32();
1022     }
1023     TELEPHONY_LOGE("[slot%{public}d]SendRequest fail, eventId:%{public}d, error:%{public}d", slotId, eventId, error);
1024     return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
1025 }
1026 } // namespace Telephony
1027 } // namespace OHOS
1028